mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Remove ColorEditor and use ColorSelector instead
This commit is contained in:
parent
c63a200ba9
commit
e9c33c53c8
3 changed files with 18 additions and 143 deletions
|
@ -16,12 +16,8 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
|
||||
import org.eclipse.cdt.internal.ui.dialogs.StatusUtil;
|
||||
import org.eclipse.cdt.internal.ui.util.PixelConverter;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.jface.preference.ColorSelector;
|
||||
import org.eclipse.jface.preference.PreferenceConverter;
|
||||
import org.eclipse.jface.preference.PreferencePage;
|
||||
import org.eclipse.swt.SWT;
|
||||
|
@ -42,6 +38,13 @@ import org.eclipse.swt.widgets.Text;
|
|||
import org.eclipse.ui.IWorkbench;
|
||||
import org.eclipse.ui.IWorkbenchPreferencePage;
|
||||
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.dialogs.StatusInfo;
|
||||
import org.eclipse.cdt.internal.ui.dialogs.StatusUtil;
|
||||
import org.eclipse.cdt.internal.ui.util.PixelConverter;
|
||||
|
||||
/**
|
||||
* AbstractPreferencePage
|
||||
*/
|
||||
|
@ -97,7 +100,7 @@ public abstract class AbstractPreferencePage extends PreferencePage implements I
|
|||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
}
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
ColorEditor editor = (ColorEditor) e.widget.getData();
|
||||
ColorSelector editor = (ColorSelector) e.widget.getData();
|
||||
PreferenceConverter.setValue(fOverlayStore, (String) fColorButtons.get(editor), editor.getColorValue());
|
||||
}
|
||||
};
|
||||
|
@ -273,7 +276,7 @@ public abstract class AbstractPreferencePage extends PreferencePage implements I
|
|||
gd.horizontalIndent = indentation;
|
||||
labelControl.setLayoutData(gd);
|
||||
|
||||
ColorEditor editor = new ColorEditor(composite);
|
||||
ColorSelector editor = new ColorSelector(composite);
|
||||
Button button = editor.getButton();
|
||||
button.setData(editor);
|
||||
|
||||
|
@ -302,7 +305,7 @@ public abstract class AbstractPreferencePage extends PreferencePage implements I
|
|||
|
||||
Iterator e = fColorButtons.keySet().iterator();
|
||||
while (e.hasNext()) {
|
||||
ColorEditor c = (ColorEditor) e.next();
|
||||
ColorSelector c = (ColorSelector) e.next();
|
||||
String key = (String) fColorButtons.get(c);
|
||||
RGB rgb = PreferenceConverter.getColor(fOverlayStore, key);
|
||||
c.setColorValue(rgb);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* QNX Software System
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.preferences;
|
||||
|
||||
|
@ -16,6 +17,7 @@ import java.io.IOException;
|
|||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.jface.preference.ColorSelector;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.preference.PreferenceConverter;
|
||||
import org.eclipse.jface.resource.JFaceResources;
|
||||
|
@ -78,7 +80,7 @@ public class CEditorPreferencePage extends AbstractPreferencePage implements IWo
|
|||
private CTextTools fCTextTools;
|
||||
|
||||
protected List fList;
|
||||
protected ColorEditor fForegroundColorEditor;
|
||||
protected ColorSelector fForegroundColorEditor;
|
||||
protected Button fBoldCheckBox;
|
||||
protected PreviewSourceViewer fPreviewViewer;
|
||||
|
||||
|
@ -87,7 +89,7 @@ public class CEditorPreferencePage extends AbstractPreferencePage implements IWo
|
|||
|
||||
private List fAppearanceColorList;
|
||||
|
||||
private ColorEditor fAppearanceColorEditor;
|
||||
private ColorSelector fAppearanceColorEditor;
|
||||
|
||||
private Button fAppearanceColorDefault;
|
||||
|
||||
|
@ -237,7 +239,7 @@ public class CEditorPreferencePage extends AbstractPreferencePage implements IWo
|
|||
gd.horizontalAlignment = GridData.BEGINNING;
|
||||
label.setLayoutData(gd);
|
||||
|
||||
fForegroundColorEditor = new ColorEditor(stylesComposite);
|
||||
fForegroundColorEditor = new ColorSelector(stylesComposite);
|
||||
Button foregroundColorButton = fForegroundColorEditor.getButton();
|
||||
gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.horizontalAlignment = GridData.BEGINNING;
|
||||
|
@ -386,7 +388,7 @@ public class CEditorPreferencePage extends AbstractPreferencePage implements IWo
|
|||
gd.horizontalAlignment = GridData.BEGINNING;
|
||||
l.setLayoutData(gd);
|
||||
|
||||
fAppearanceColorEditor = new ColorEditor(stylesComposite);
|
||||
fAppearanceColorEditor = new ColorSelector(stylesComposite);
|
||||
Button foregroundColorButton = fAppearanceColorEditor.getButton();
|
||||
gd = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gd.horizontalAlignment = GridData.BEGINNING;
|
||||
|
@ -549,6 +551,7 @@ public class CEditorPreferencePage extends AbstractPreferencePage implements IWo
|
|||
|
||||
super.performDefaults();
|
||||
|
||||
handleAppearanceColorListSelection();
|
||||
handleListSelection();
|
||||
|
||||
fCEditorHoverConfigurationBlock.performDefaults();
|
||||
|
|
|
@ -1,131 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000 2005 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* QNX Software System
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.preferences;
|
||||
|
||||
import org.eclipse.jface.resource.JFaceResources;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.accessibility.AccessibleAdapter;
|
||||
import org.eclipse.swt.accessibility.AccessibleEvent;
|
||||
import org.eclipse.swt.events.DisposeEvent;
|
||||
import org.eclipse.swt.events.DisposeListener;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.RGB;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.ColorDialog;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
/**
|
||||
* A "button" of a certain color determined by the color picker.
|
||||
*/
|
||||
public class ColorEditor {
|
||||
|
||||
private Point fExtent;
|
||||
protected Image fImage;
|
||||
protected RGB fColorValue;
|
||||
protected Color fColor;
|
||||
protected Button fButton;
|
||||
|
||||
public ColorEditor(Composite parent) {
|
||||
|
||||
fButton= new Button(parent, SWT.PUSH);
|
||||
fExtent= computeImageSize(parent);
|
||||
fImage= new Image(parent.getDisplay(), fExtent.x, fExtent.y);
|
||||
|
||||
GC gc= new GC(fImage);
|
||||
gc.setBackground(fButton.getBackground());
|
||||
gc.fillRectangle(0, 0, fExtent.x, fExtent.y);
|
||||
gc.dispose();
|
||||
|
||||
fButton.getAccessible().addAccessibleListener(
|
||||
new AccessibleAdapter() {
|
||||
public void getName(AccessibleEvent e) {
|
||||
e.result = JFaceResources.getString("ColorSelector.Name"); //$NON-NLS-1$
|
||||
}});
|
||||
|
||||
fButton.setImage(fImage);
|
||||
fButton.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
ColorDialog colorDialog= new ColorDialog(fButton.getShell());
|
||||
colorDialog.setRGB(fColorValue);
|
||||
RGB newColor = colorDialog.open();
|
||||
if (newColor != null) {
|
||||
fColorValue= newColor;
|
||||
updateColorImage();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fButton.addDisposeListener(new DisposeListener() {
|
||||
public void widgetDisposed(DisposeEvent event) {
|
||||
if (fImage != null) {
|
||||
fImage.dispose();
|
||||
fImage= null;
|
||||
}
|
||||
if (fColor != null) {
|
||||
fColor.dispose();
|
||||
fColor= null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public RGB getColorValue() {
|
||||
return fColorValue;
|
||||
}
|
||||
|
||||
public void setColorValue(RGB rgb) {
|
||||
fColorValue= rgb;
|
||||
updateColorImage();
|
||||
}
|
||||
|
||||
public Button getButton() {
|
||||
return fButton;
|
||||
}
|
||||
|
||||
protected void updateColorImage() {
|
||||
|
||||
Display display= fButton.getDisplay();
|
||||
|
||||
GC gc= new GC(fImage);
|
||||
gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
|
||||
gc.drawRectangle(0, 2, fExtent.x - 1, fExtent.y - 4);
|
||||
|
||||
if (fColor != null)
|
||||
fColor.dispose();
|
||||
|
||||
fColor= new Color(display, fColorValue);
|
||||
gc.setBackground(fColor);
|
||||
gc.fillRectangle(1, 3, fExtent.x - 2, fExtent.y - 5);
|
||||
gc.dispose();
|
||||
|
||||
fButton.setImage(fImage);
|
||||
}
|
||||
|
||||
protected Point computeImageSize(Control window) {
|
||||
GC gc= new GC(window);
|
||||
Font f= JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT);
|
||||
gc.setFont(f);
|
||||
int height= gc.getFontMetrics().getHeight();
|
||||
gc.dispose();
|
||||
Point p= new Point(height * 3 - 6, height);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Reference in a new issue