Bug 572002: Adapt use of SWTs Color to current recommendation
- Change to Color constructors without Device
- Remove calls to Color.dispose
- Remove ColorManager, it is unnecessary now
Change-Id: I4d39a5750ae9f5fd82ac11234723169ffb0dfbb9
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/ColorManager.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/ColorManager.java
deleted file mode 100644
index e52dce9..0000000
--- a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/ColorManager.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*=============================================================================#
- # Copyright (c) 2005, 2021 Stephan Wahlbrink and others.
- #
- # This program and the accompanying materials are made available under the
- # terms of the Eclipse Public License 2.0 which is available at
- # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
- # which is available at https://www.apache.org/licenses/LICENSE-2.0.
- #
- # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
- #
- # Contributors:
- # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
- #=============================================================================*/
-
-package org.eclipse.statet.ecommons.ui;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-
-import org.eclipse.statet.jcommons.lang.Disposable;
-
-
-public class ColorManager implements Disposable {
-
-
- protected Map<String, RGB> fKeyTable= new HashMap<>(10);
- protected Map<Display, Map<RGB, Color>> fDisplayTable= new HashMap<>(2);
-
-
- /**
- * Flag which tells if the colors are automatically disposed when
- * the current display gets disposed.
- */
- private final boolean fAutoDisposeOnDisplayDispose;
-
- private final Listener fDisposeListener = new Listener() {
- @Override
- public void handleEvent(final Event event) {
- dispose(event.display);
- }
- };
-
-
- /**
- * Creates a new Java color manager which automatically
- * disposes the allocated colors when the current display
- * gets disposed.
- */
- public ColorManager() {
- this(true);
- }
-
- /**
- * Creates a new Java color manager.
- *
- * @param autoDisposeOnDisplayDispose if <code>true</code> the color manager
- * automatically disposes all managed colors when the current display gets disposed
- * and all calls to {@link org.eclipse.jface.text.source.ISharedTextColors#dispose()} are ignored.
- */
- private ColorManager(final boolean autoDisposeOnDisplayDispose) {
- fAutoDisposeOnDisplayDispose = autoDisposeOnDisplayDispose;
- }
-
-
- @Override
- public void dispose() {
- for (final Display display : fDisplayTable.keySet()) {
- final Display ref = display;
- display.asyncExec(new Runnable() {
- @Override
- public void run() {
- dispose(ref);
- }
- });
- }
- }
-
- private void dispose(final Display display) {
- display.removeListener(SWT.Dispose, fDisposeListener);
- final Map<RGB, Color> colorTable = fDisplayTable.remove(display);
- if (colorTable != null) {
- for (final Color color : colorTable.values()) {
- if (color != null && !color.isDisposed()) {
- color.dispose();
- }
- }
- }
- }
-
- public Color getColor(final RGB rgb) {
- if (rgb == null) {
- return null;
- }
-
- final Display display = Display.getCurrent();
- Map<RGB, Color> colorTable = fDisplayTable.get(display);
- if (colorTable == null) {
- colorTable= new HashMap<>(10);
- fDisplayTable.put(display, colorTable);
- if (fAutoDisposeOnDisplayDispose) {
- display.addListener(SWT.Dispose, fDisposeListener);
- }
- }
-
- Color color = colorTable.get(rgb);
- if (color == null) {
- color = new Color(Display.getCurrent(), rgb);
- colorTable.put(rgb, color);
- }
- return color;
- }
-
- public Color getColor(final String key) {
- if (key == null) {
- return null;
- }
-
- final RGB rgb = fKeyTable.get(key);
- return getColor(rgb);
- }
-
- public void bindColor(final String key, final RGB rgb) {
- fKeyTable.put(key, rgb);
- }
-
-}
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/SharedUIResources.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/SharedUIResources.java
index 40f7b9d..2a87bc9 100644
--- a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/SharedUIResources.java
+++ b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/SharedUIResources.java
@@ -97,18 +97,6 @@
public static final String LOCTOOLD_PIN_PAGE_IMAGE_ID = UIMiscellanyPlugin.BUNDLE_ID + "/image/loctoold/pin_page"; //$NON-NLS-1$
- public static final String GRAPHICS_BACKGROUND_COLOR_ID = "graphics.background"; //$NON-NLS-1$
-
-
- /**
- * A shared color manager.
- *
- * @return the color manager
- */
- public static ColorManager getColors() {
- return UIMiscellanyPlugin.getInstance().getColorManager();
- }
-
/**
* The image registry of ECommonsUI
*
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/AlphaSelector.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/AlphaSelector.java
index 4137f47..8314f6e 100644
--- a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/AlphaSelector.java
+++ b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/AlphaSelector.java
@@ -31,25 +31,24 @@
import org.eclipse.statet.ecommons.collections.FastList;
import org.eclipse.statet.ecommons.graphics.core.ColorDef;
-import org.eclipse.statet.ecommons.ui.SharedUIResources;
import org.eclipse.statet.ecommons.ui.util.LayoutUtils;
public class AlphaSelector extends Canvas implements IObjValueWidget<Float> {
- private static final Float DEFAULT_VALUE = new Float(1f);
+ private static final Float DEFAULT_VALUE= new Float(1f);
- private static final Color G_BACKGROUND = SharedUIResources.getColors().getColor(SharedUIResources.GRAPHICS_BACKGROUND_COLOR_ID);
-
- private static final ColorDef DEFAULT_BASE = new ColorDef(0, 0, 0);
+ private static final ColorDef DEFAULT_BASE= new ColorDef(0, 0, 0);
- private final static class Data {
+ private static final class Data {
private final int size;
private final float factor;
+ private final Color backgroundColor;
+
private final ColorDef baseColor;
private final int alphaX0;
@@ -59,21 +58,22 @@
private final int y1;
- public Data(final int size, final ColorDef baseColor) {
- this.size = size;
- this.baseColor = baseColor;
- factor = size - 1;
+ public Data(final int size, final Color backgroundColor, final ColorDef baseColor) {
+ this.size= size;
+ this.backgroundColor= backgroundColor;
+ this.baseColor= baseColor;
+ this.factor= size - 1;
- alphaX0 = 1;
- alphaX1 = alphaX0 + Math.round(size * 0.15f);
+ this.alphaX0= 1;
+ this.alphaX1= this.alphaX0 + Math.round(size * 0.15f);
- y0 = 1;
- y1 = y0 + size;
+ this.y0= 1;
+ this.y1= this.y0 + size;
}
public int alpha_y_255(final int y) {
- final int v = 255 - Math.round(((y - y0) / factor) * 255f);
+ final int v= 255 - Math.round(((y - this.y0) / this.factor) * 255f);
if (v <= 0) {
return 0;
}
@@ -84,11 +84,11 @@
}
public int alpha_255_y(final int v) {
- return y0 + Math.round((v / 255f) * factor);
+ return this.y0 + Math.round((v / 255f) * this.factor);
}
public float alpha_y_01(final int y) {
- final float v = 1f - ((y - y0) / factor);
+ final float v= 1f - ((y - this.y0) / this.factor);
if (v <= 0f) {
return 0f;
}
@@ -99,44 +99,40 @@
}
public int alpha_01_y(final float v) {
- return y0 + Math.round(((1f - v) * factor));
+ return this.y0 + Math.round(((1f - v) * this.factor));
}
public int getBaseMax() {
- return Math.max(baseColor.getRed(), Math.max(baseColor.getGreen(), baseColor.getBlue()));
+ return Math.max(this.baseColor.getRed(), Math.max(this.baseColor.getGreen(), this.baseColor.getBlue()));
}
public Image createImage(final Display display) {
- final Image image = new Image(display, alphaX1 + 1, y1 + 1);
- final GC gc = new GC(image);
+ final Image image= new Image(display, this.alphaX1 + 1, this.y1 + 1);
+ final GC gc= new GC(image);
gc.setAdvanced(false);
- gc.setBackground(G_BACKGROUND);
+ gc.setBackground(this.backgroundColor);
gc.fillRectangle(0, 0, image.getImageData().width, image.getImageData().height);
// prim
- if (baseColor.equalsRGB(DEFAULT_BASE)) {
- final int x1 = alphaX1 - 1;
- for (int y = y0; y < y1; y++) {
- final int alpha255 = 255 - alpha_y_255(y);
- final Color color = new Color(display, alpha255, alpha255, alpha255);
- gc.setForeground(color);
- gc.drawLine(alphaX0, y, x1, y);
- color.dispose();
+ if (this.baseColor.equalsRGB(DEFAULT_BASE)) {
+ final int x1= this.alphaX1 - 1;
+ for (int y= this.y0; y < this.y1; y++) {
+ final int alpha255= 255 - alpha_y_255(y);
+ gc.setForeground(new Color(alpha255, alpha255, alpha255));
+ gc.drawLine(this.alphaX0, y, x1, y);
}
}
else {
- final int x1 = alphaX1 - 1;
- for (int y = y0; y < y1; y++) {
- final int alpha255 = alpha_y_255(y);
- final int white = 255 - alpha255;
- final Color color = new Color(display,
- white + (baseColor.getRed() * alpha255) / 255,
- white + (baseColor.getGreen() * alpha255) / 255,
- white + (baseColor.getBlue() * alpha255) / 255 );
- gc.setForeground(color);
- gc.drawLine(alphaX0, y, x1, y);
- color.dispose();
+ final int x1= this.alphaX1 - 1;
+ for (int y= this.y0; y < this.y1; y++) {
+ final int alpha255= alpha_y_255(y);
+ final int white= 255 - alpha255;
+ gc.setForeground(new Color(
+ white + (this.baseColor.getRed() * alpha255) / 255,
+ white + (this.baseColor.getGreen() * alpha255) / 255,
+ white + (this.baseColor.getBlue() * alpha255) / 255 ));
+ gc.drawLine(this.alphaX0, y, x1, y);
}
}
@@ -150,32 +146,32 @@
private class SWTListener implements PaintListener, Listener {
- private static final int TRACK_ALPHA = 1;
+ private static final int TRACK_ALPHA= 1;
- private Data fData;
+ private Data data;
- private Image fImage;
+ private Image image;
- private int fMouseState;
+ private int mouseState;
@Override
public void handleEvent(final Event event) {
- final Data data = fData;
+ final Data data= this.data;
switch (event.type) {
case SWT.MouseDown:
if (data != null && event.y >= data.y0 && event.y < data.y1
&& event.x >= data.alphaX0 && event.x < data.alphaX1) {
doSetValue(Float.valueOf(data.alpha_y_01(event.y)), event.time, 0);
- fMouseState = TRACK_ALPHA;
+ this.mouseState= TRACK_ALPHA;
}
return;
case SWT.MouseUp:
- fMouseState = 0;
+ this.mouseState= 0;
return;
case SWT.MouseMove:
if (data != null) {
- switch (fMouseState) {
+ switch (this.mouseState) {
case TRACK_ALPHA:
doSetValue(Float.valueOf(data.alpha_y_01(event.y)), event.time, 0);
break;
@@ -183,61 +179,61 @@
}
return;
case SWT.Dispose:
- if (fImage != null) {
- fImage.dispose();
- fImage = null;
+ if (this.image != null) {
+ this.image.dispose();
+ this.image= null;
}
}
}
private int computeSize(int width, final int height) {
- width = Math.round(width / 0.15f);
+ width= Math.round(width / 0.15f);
return Math.min(width - 2, height - 2);
}
@Override
public void paintControl(final PaintEvent e) {
- final Rectangle clientArea = getClientArea();
- int size = computeSize(clientArea.width, clientArea.height);
- if (fSize > 0 && fSize < size) {
- size = fSize;
+ final Rectangle clientArea= getClientArea();
+ int size= computeSize(clientArea.width, clientArea.height);
+ if (AlphaSelector.this.size > 0 && AlphaSelector.this.size < size) {
+ size= AlphaSelector.this.size;
}
- if (fData == null || fData.size != size || !fData.baseColor.equalsRGB(fBaseColor)) {
- if (fImage != null) {
- fImage.dispose();
- fImage = null;
+ if (this.data == null || this.data.size != size || !this.data.baseColor.equalsRGB(AlphaSelector.this.baseColor)) {
+ if (this.image != null) {
+ this.image.dispose();
+ this.image= null;
}
- fData = new Data(size, fBaseColor);
+ this.data= new Data(size, AlphaSelector.this.backgroundColor, AlphaSelector.this.baseColor);
}
- final GC gc = e.gc;
+ final GC gc= e.gc;
gc.setAdvanced(false);
- gc.setBackground(G_BACKGROUND);
+ gc.setBackground(AlphaSelector.this.backgroundColor);
gc.fillRectangle(clientArea);
// if (fImage == null) {
- if (fImage != null) {
- fImage.dispose();
- fImage = null;
+ if (this.image != null) {
+ this.image.dispose();
+ this.image= null;
}
- fImage = fData.createImage(e.display);
+ this.image= this.data.createImage(e.display);
// }
- gc.drawImage(fImage, 0, 0);
+ gc.drawImage(this.image, 0, 0);
gc.setLineWidth(1);
gc.setAdvanced(true);
gc.setAntialias(SWT.ON);
- { final float alpha = fValue.floatValue();
- final int y = fData.alpha_01_y(alpha);
+ { final float alpha= AlphaSelector.this.value.floatValue();
+ final int y= this.data.alpha_01_y(alpha);
gc.setForeground(e.display.getSystemColor(SWT.COLOR_BLACK));
- gc.drawLine(fData.alphaX0 - 1, y, fData.alphaX1, y);
- if (255 * (1f - alpha) + (fData.getBaseMax() * alpha) < 127) {
+ gc.drawLine(this.data.alphaX0 - 1, y, this.data.alphaX1, y);
+ if (255 * (1f - alpha) + (this.data.getBaseMax() * alpha) < 127) {
gc.setForeground(e.display.getSystemColor(SWT.COLOR_WHITE));
- gc.drawLine(fData.alphaX0, y, fData.alphaX1 - 1, y);
+ gc.drawLine(this.data.alphaX0, y, this.data.alphaX1 - 1, y);
}
}
}
@@ -245,19 +241,23 @@
}
- private int fSize = 8 + LayoutUtils.defaultHSpacing() * 30;
+ private int size= 8 + LayoutUtils.defaultHSpacing() * 30;
- private Float fValue = DEFAULT_VALUE;
+ private Float value= DEFAULT_VALUE;
- private final FastList<IObjValueListener<Float>> fValueListeners= (FastList) new FastList<>(IObjValueListener.class);
+ private final FastList<IObjValueListener<Float>> valueListeners= (FastList) new FastList<>(IObjValueListener.class);
- private ColorDef fBaseColor = DEFAULT_BASE;
+ private ColorDef baseColor= DEFAULT_BASE;
+
+ private Color backgroundColor;
- public AlphaSelector(final Composite parent) {
+ public AlphaSelector(final Composite parent, final Color backgroundColor) {
super(parent, SWT.DOUBLE_BUFFERED);
- final SWTListener listener = new SWTListener();
+ this.backgroundColor= backgroundColor;
+
+ final SWTListener listener= new SWTListener();
addPaintListener(listener);
addListener(SWT.MouseDown, listener);
addListener(SWT.MouseUp, listener);
@@ -267,25 +267,25 @@
public void setSize(final int size) {
- fSize = size;
+ this.size= size;
}
public void setBaseColor(final ColorDef color) {
- fBaseColor = (color != null) ? color : DEFAULT_BASE;
+ this.baseColor= (color != null) ? color : DEFAULT_BASE;
redraw();
}
private boolean doSetValue(final Float newValue, final int time, final int flags) {
- if (fValue.equals(newValue) && flags == 0 && fValue != DEFAULT_VALUE) {
+ if (this.value.equals(newValue) && flags == 0 && this.value != DEFAULT_VALUE) {
return false;
}
- final IObjValueListener<Float>[] listeners = fValueListeners.toArray();
+ final IObjValueListener<Float>[] listeners= this.valueListeners.toArray();
final ObjValueEvent<Float> event= new ObjValueEvent<>(this, time, 0,
- fValue, newValue, flags);
+ this.value, newValue, flags);
- fValue = newValue;
- for (int i = 0; i < listeners.length; i++) {
- event.newValue = newValue;
+ this.value= newValue;
+ for (int i= 0; i < listeners.length; i++) {
+ event.newValue= newValue;
listeners[i].valueChanged(event);
}
if (!isDisposed()) {
@@ -297,11 +297,11 @@
@Override
public Point computeSize(final int wHint, final int hHint, final boolean changed) {
- int width = 2 + Math.round(fSize * 0.15f);
- int height = 2 + fSize;
- final int border = getBorderWidth();
- width += border * 2;
- height += border * 2;
+ int width= 2 + Math.round(this.size * 0.15f);
+ int height= 2 + this.size;
+ final int border= getBorderWidth();
+ width+= border * 2;
+ height+= border * 2;
return new Point(width, height);
}
@@ -318,12 +318,12 @@
@Override
public void addValueListener(final IObjValueListener<Float> listener) {
- fValueListeners.add(listener);
+ this.valueListeners.add(listener);
}
@Override
public void removeValueListener(final IObjValueListener<Float> listener) {
- fValueListeners.remove(listener);
+ this.valueListeners.remove(listener);
}
@Override
@@ -331,7 +331,7 @@
if (idx != 0) {
throw new IllegalArgumentException("idx: " + idx); //$NON-NLS-1$
}
- return fValue;
+ return this.value;
}
@Override
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/ColorPalette.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/ColorPalette.java
index 4ffe458..18440fe 100644
--- a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/ColorPalette.java
+++ b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/ColorPalette.java
@@ -36,22 +36,18 @@
import org.eclipse.statet.ecommons.collections.FastList;
import org.eclipse.statet.ecommons.graphics.core.ColorDef;
import org.eclipse.statet.ecommons.graphics.core.ColorRefDef;
-import org.eclipse.statet.ecommons.ui.SharedUIResources;
import org.eclipse.statet.ecommons.ui.util.LayoutUtils;
public class ColorPalette extends Canvas implements IObjValueWidget<ColorDef> {
- private static final LineAttributes SELECTION1 = new LineAttributes(1f, SWT.CAP_FLAT, SWT.JOIN_MITER, SWT.LINE_CUSTOM, new float[] { 1f, 1f }, 0f, 10f);
- private static final LineAttributes SELECTION2 = new LineAttributes(1f, SWT.CAP_FLAT, SWT.JOIN_MITER, SWT.LINE_CUSTOM, new float[] { 1f, 1f }, 1f, 10f);
-
- private static final Color G_BACKGROUND = SharedUIResources.getColors().getColor(SharedUIResources.GRAPHICS_BACKGROUND_COLOR_ID);
- private static final ColorDef G_BACKGROUND_DEF = new ColorDef(G_BACKGROUND.getRed(), G_BACKGROUND.getGreen(), G_BACKGROUND.getBlue());
+ private static final LineAttributes SELECTION1= new LineAttributes(1f, SWT.CAP_FLAT, SWT.JOIN_MITER, SWT.LINE_CUSTOM, new float[] { 1f, 1f }, 0f, 10f);
+ private static final LineAttributes SELECTION2= new LineAttributes(1f, SWT.CAP_FLAT, SWT.JOIN_MITER, SWT.LINE_CUSTOM, new float[] { 1f, 1f }, 1f, 10f);
private class SWTListener implements Listener, PaintListener {
- private boolean fDoubleClick;
+ private boolean doubleClick;
@Override
public void handleEvent(final Event event) {
@@ -62,42 +58,42 @@
checkCursor();
return;
case SWT.FocusIn:
- fHasFocus = true;
+ ColorPalette.this.hasFocus= true;
redraw();
return;
case SWT.FocusOut:
- fHasFocus = false;
+ ColorPalette.this.hasFocus= false;
redraw();
return;
case SWT.Selection:
redraw();
return;
case SWT.MouseHover:
- idx = getColorIdx(event.x, event.y);
+ idx= getColorIdx(event.x, event.y);
if (idx >= 0) {
- setToolTipText(fColors.get(idx).toString());
+ setToolTipText(ColorPalette.this.colors.get(idx).toString());
}
else {
setToolTipText(""); //$NON-NLS-1$
}
return;
case SWT.MouseDown:
- fDoubleClick = false;
- idx = getColorIdx(event.x, event.y);
+ this.doubleClick= false;
+ idx= getColorIdx(event.x, event.y);
if (idx >= 0) {
- fCursorIdx = idx;
+ ColorPalette.this.cursorIdx= idx;
if (!doSetColor(idx, event.time, 0)) {
- fDoubleClick = true;
+ this.doubleClick= true;
redraw();
}
}
return;
case SWT.MouseDoubleClick:
- if (fDoubleClick) {
- fDoubleClick = false;
- idx = getColorIdx(event.x, event.y);
- if (idx >= 0 && idx == fSelectionIdx) {
- fCursorIdx = idx;
+ if (this.doubleClick) {
+ this.doubleClick= false;
+ idx= getColorIdx(event.x, event.y);
+ if (idx >= 0 && idx == ColorPalette.this.selectionIdx) {
+ ColorPalette.this.cursorIdx= idx;
if (!doSetColor(idx, event.time, ObjValueEvent.DEFAULT_SELECTION)) {
redraw();
}
@@ -108,37 +104,37 @@
switch (event.keyCode) {
case SWT.ARROW_LEFT:
if (event.stateMask == 0) {
- fCursorIdx--;
+ ColorPalette.this.cursorIdx--;
checkCursor();
redraw();
}
return;
case SWT.ARROW_RIGHT:
if (event.stateMask == 0) {
- fCursorIdx++;
+ ColorPalette.this.cursorIdx++;
checkCursor();
redraw();
}
return;
case SWT.ARROW_UP:
- if (event.stateMask == 0 && fCursorIdx >= fColumnCount) {
- fCursorIdx -= fColumnCount;
+ if (event.stateMask == 0 && ColorPalette.this.cursorIdx >= ColorPalette.this.columnCount) {
+ ColorPalette.this.cursorIdx -= ColorPalette.this.columnCount;
checkCursor();
redraw();
}
return;
case SWT.ARROW_DOWN:
- if (event.stateMask == 0 && fCursorIdx < fColors.size() - fColumnCount) {
- fCursorIdx += fColumnCount;
+ if (event.stateMask == 0 && ColorPalette.this.cursorIdx < ColorPalette.this.colors.size() - ColorPalette.this.columnCount) {
+ ColorPalette.this.cursorIdx+= ColorPalette.this.columnCount;
checkCursor();
redraw();
}
return;
case SWT.CR:
- doSetColor(fCursorIdx, event.time, ObjValueEvent.DEFAULT_SELECTION);
+ doSetColor(ColorPalette.this.cursorIdx, event.time, ObjValueEvent.DEFAULT_SELECTION);
return;
case ' ':
- doSetColor(fCursorIdx, event.time, 0);
+ doSetColor(ColorPalette.this.cursorIdx, event.time, 0);
return;
default:
return;
@@ -150,68 +146,67 @@
case SWT.TRAVERSE_ARROW_NEXT:
case SWT.TRAVERSE_ARROW_PREVIOUS:
case SWT.TRAVERSE_RETURN:
- event.doit = false;
+ event.doit= false;
return;
}
- event.doit = true;
+ event.doit= true;
}
}
@Override
public void paintControl(final PaintEvent e) {
- final int count = fColors.size();
- if (count == 0 || fColumnCount == 0) {
+ final int count= ColorPalette.this.colors.size();
+ if (count == 0 || ColorPalette.this.columnCount == 0) {
return;
}
- final Rectangle clientArea = getClientArea();
- int idx = getVerticalBar().getSelection() * fColumnCount;
+ final Rectangle clientArea= getClientArea();
+ int idx= getVerticalBar().getSelection() * ColorPalette.this.columnCount;
- final GC gc = e.gc;
- final Display display = getDisplay();
- int column = 0;
- int x = 1, y = 1;
+ final GC gc= e.gc;
+ final Display display= getDisplay();
+ int column= 0;
+ int x= 1, y= 1;
while (idx < count) {
- final ColorDef colorDef = fColors.get(idx);
- final Color color = new Color(display, colorDef.getRed(), colorDef.getGreen(), colorDef.getBlue());
- gc.setBackground(color);
- gc.fillRectangle(x, y, fSize - 1, fSize - 1);
- color.dispose();
+ final ColorDef colorDef= ColorPalette.this.colors.get(idx);
+ gc.setBackground(
+ new Color(colorDef.getRed(), colorDef.getGreen(), colorDef.getBlue()) );
+ gc.fillRectangle(x, y, ColorPalette.this.size - 1, ColorPalette.this.size - 1);
- if (idx == fSelectionIdx) {
+ if (idx == ColorPalette.this.selectionIdx) {
gc.setLineStyle(SWT.LINE_SOLID);
gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
- gc.drawRectangle(x - 1, y - 1, fSize, fSize);
+ gc.drawRectangle(x - 1, y - 1, ColorPalette.this.size, ColorPalette.this.size);
gc.setForeground(getBackground());
- gc.drawRectangle(x, y, fSize - 2, fSize - 2);
+ gc.drawRectangle(x, y, ColorPalette.this.size - 2, ColorPalette.this.size - 2);
}
else if (idx == count - 1
- && Math.abs(colorDef.getRed() - G_BACKGROUND_DEF.getRed()) < 8
- && Math.abs(colorDef.getGreen() - G_BACKGROUND_DEF.getGreen()) < 8
- && Math.abs(colorDef.getBlue() - G_BACKGROUND_DEF.getBlue()) < 8) {
+ && Math.abs(colorDef.getRed() - ColorPalette.this.backgroundColor.getRed()) < 8
+ && Math.abs(colorDef.getGreen() - ColorPalette.this.backgroundColor.getGreen()) < 8
+ && Math.abs(colorDef.getBlue() - ColorPalette.this.backgroundColor.getBlue()) < 8) {
gc.setLineStyle(SWT.LINE_SOLID);
gc.setForeground(display.getSystemColor(SWT.COLOR_DARK_GRAY));
- gc.drawRectangle(x - 1, y - 1, fSize, fSize);
+ gc.drawRectangle(x - 1, y - 1, ColorPalette.this.size, ColorPalette.this.size);
gc.setForeground(getBackground());
- gc.drawRectangle(x, y, fSize - 2, fSize - 2);
+ gc.drawRectangle(x, y, ColorPalette.this.size - 2, ColorPalette.this.size - 2);
}
- if (idx == fCursorIdx && fHasFocus) {
+ if (idx == ColorPalette.this.cursorIdx && ColorPalette.this.hasFocus) {
gc.setLineAttributes(SELECTION1);
gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
- gc.drawRectangle(x, y, fSize - 2, fSize - 2);
+ gc.drawRectangle(x, y, ColorPalette.this.size - 2, ColorPalette.this.size - 2);
gc.setLineAttributes(SELECTION2);
gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
- gc.drawRectangle(x, y, fSize - 2, fSize - 2);
+ gc.drawRectangle(x, y, ColorPalette.this.size - 2, ColorPalette.this.size - 2);
}
idx++;
column++;
- if (column < fColumnCount) {
- x += fSize;
+ if (column < ColorPalette.this.columnCount) {
+ x+= ColorPalette.this.size;
}
else {
- column = 0;
- x = 0;
- y += fSize;
+ column= 0;
+ x= 0;
+ y+= ColorPalette.this.size;
if (y > clientArea.height) {
break;
}
@@ -222,28 +217,32 @@
}
- private final int fSize;
+ private final int size;
- private boolean fHasFocus;
+ private boolean hasFocus;
- private List<? extends ColorDef> fColors = Collections.emptyList();
+ private List<? extends ColorDef> colors= Collections.emptyList();
- private int fSelectionIdx = -1;
- private int fCursorIdx = 0;
+ private int selectionIdx= -1;
+ private int cursorIdx= 0;
- private int fColumnCount;
- private int fVisibleRowCount;
+ private int columnCount;
+ private int visibleRowCount;
- private final FastList<IObjValueListener<ColorDef>> fValueListeners= (FastList) new FastList<>(IObjValueListener.class);
+ private final FastList<IObjValueListener<ColorDef>> valueListeners= (FastList) new FastList<>(IObjValueListener.class);
+
+ private final Color backgroundColor;
- public ColorPalette(final Composite parent) {
+ public ColorPalette(final Composite parent, final Color backgroundColor) {
super(parent, SWT.V_SCROLL);
- fSize = 8 + LayoutUtils.defaultHSpacing() * 2;
+ this.backgroundColor= backgroundColor;
+
+ this.size= 8 + LayoutUtils.defaultHSpacing() * 2;
getVerticalBar().setVisible(true);
- final SWTListener listener = new SWTListener();
+ final SWTListener listener= new SWTListener();
addPaintListener(listener);
addListener(SWT.Resize, listener);
addListener(SWT.FocusIn, listener);
@@ -260,63 +259,63 @@
public void setColors(final List<? extends ColorDef> colors) {
- fColors = colors;
+ this.colors= colors;
updateScroll();
checkCursor();
}
private void checkCursor() {
- if (fColors.isEmpty()) {
- fCursorIdx = -1;
+ if (this.colors.isEmpty()) {
+ this.cursorIdx= -1;
return;
}
- if (fCursorIdx < 0) {
- fCursorIdx = getVerticalBar().getSelection() * fColumnCount;
+ if (this.cursorIdx < 0) {
+ this.cursorIdx= getVerticalBar().getSelection() * this.columnCount;
}
- if (fCursorIdx >= fColors.size()) {
- fCursorIdx = fColors.size() - 1;
+ if (this.cursorIdx >= this.colors.size()) {
+ this.cursorIdx= this.colors.size() - 1;
}
- if (fColumnCount == 0) {
+ if (this.columnCount == 0) {
return;
}
- final int row = fCursorIdx / fColumnCount;
- final int topRow = getVerticalBar().getSelection();
+ final int row= this.cursorIdx / this.columnCount;
+ final int topRow= getVerticalBar().getSelection();
if (row < topRow) {
getVerticalBar().setSelection(row);
}
- else if (row >= topRow + fVisibleRowCount) {
- getVerticalBar().setSelection(row - fVisibleRowCount + 1);
+ else if (row >= topRow + this.visibleRowCount) {
+ getVerticalBar().setSelection(row - this.visibleRowCount + 1);
}
}
private void updateScroll() {
- final ScrollBar bar = getVerticalBar();
- final int count = fColors.size();
- final Rectangle clientArea = getClientArea();
- fColumnCount = (clientArea.width - 1) / fSize;
- if (count == 0 || fColumnCount == 0) {
+ final ScrollBar bar= getVerticalBar();
+ final int count= this.colors.size();
+ final Rectangle clientArea= getClientArea();
+ this.columnCount= (clientArea.width - 1) / this.size;
+ if (count == 0 || this.columnCount == 0) {
bar.setEnabled(false);
bar.setValues(0, 0, 1, 1, 1, 1);
return;
}
- final int rows = (count + fColumnCount - 1) / fColumnCount;
- fVisibleRowCount = (clientArea.height - 1) / fSize;
- if (rows <= fVisibleRowCount) {
+ final int rows= (count + this.columnCount - 1) / this.columnCount;
+ this.visibleRowCount= (clientArea.height - 1) / this.size;
+ if (rows <= this.visibleRowCount) {
bar.setEnabled(false);
bar.setValues(0, 0, 1, 1, 1, 1);
return;
}
bar.setEnabled(true);
- bar.setValues(0, 0, rows, fVisibleRowCount, 1, fVisibleRowCount);
+ bar.setValues(0, 0, rows, this.visibleRowCount, 1, this.visibleRowCount);
}
@Override
public Point computeSize(final int wHint, final int hHint, final boolean changed) {
checkWidget();
- final int width = (wHint >= 0) ? wHint : (1 + fSize * 10);
- final int height = (hHint >= 0) ? hHint : (1 + fSize * 9);
- final Rectangle trimmed = computeTrim(0, 0, width, height);
+ final int width= (wHint >= 0) ? wHint : (1 + this.size * 10);
+ final int height= (hHint >= 0) ? hHint : (1 + this.size * 9);
+ final Rectangle trimmed= computeTrim(0, 0, width, height);
return new Point(trimmed.width, trimmed.height);
}
@@ -326,12 +325,12 @@
}
public int getColorIdx(final int x, final int y) {
- final int count = fColors.size();
- if (count == 0 || fColumnCount == 0) {
+ final int count= this.colors.size();
+ if (count == 0 || this.columnCount == 0) {
return -1;
}
- int idx = (getVerticalBar().getSelection() + ((y - 1) / fSize)) * fColumnCount;
- idx += ((x - 1) / fSize);
+ int idx= (getVerticalBar().getSelection() + ((y - 1) / this.size)) * this.columnCount;
+ idx+= ((x - 1) / this.size);
return (idx < count) ? idx : -1;
}
@@ -347,27 +346,27 @@
@Override
public void addValueListener(final IObjValueListener<ColorDef> listener) {
- fValueListeners.add(listener);
+ this.valueListeners.add(listener);
}
@Override
public void removeValueListener(final IObjValueListener<ColorDef> listener) {
- fValueListeners.remove(listener);
+ this.valueListeners.remove(listener);
}
private boolean doSetColor(final int idx, final int time, final int flags) {
- final ColorDef oldValue = (fSelectionIdx >= 0) ? fColors.get(fSelectionIdx) : null;
- final ColorDef newValue = (idx >= 0) ? fColors.get(idx) : null;
+ final ColorDef oldValue= (this.selectionIdx >= 0) ? this.colors.get(this.selectionIdx) : null;
+ final ColorDef newValue= (idx >= 0) ? this.colors.get(idx) : null;
if (oldValue == newValue && flags == 0) {
return false;
}
- final IObjValueListener<ColorDef>[] listeners = fValueListeners.toArray();
+ final IObjValueListener<ColorDef>[] listeners= this.valueListeners.toArray();
final ObjValueEvent<ColorDef> event= new ObjValueEvent<>(this, time, 0,
oldValue, newValue, flags);
- fSelectionIdx = idx;
- for (int i = 0; i < listeners.length; i++) {
- event.newValue = newValue;
+ this.selectionIdx= idx;
+ for (int i= 0; i < listeners.length; i++) {
+ event.newValue= newValue;
listeners[i].valueChanged(event);
}
if (!isDisposed()) {
@@ -381,7 +380,7 @@
if (idx != 0) {
throw new IllegalArgumentException("idx: " + idx); //$NON-NLS-1$
}
- return (fSelectionIdx >= 0) ? fColors.get(fSelectionIdx) : null;
+ return (this.selectionIdx >= 0) ? this.colors.get(this.selectionIdx) : null;
}
@Override
@@ -390,25 +389,25 @@
throw new IllegalArgumentException("idx: " + idx); //$NON-NLS-1$
}
if (value != null) {
- for (int i = 0; i < fColors.size(); i++) {
- final ColorDef c = fColors.get(i);
+ for (int i= 0; i < this.colors.size(); i++) {
+ final ColorDef c= this.colors.get(i);
if (c.equals(value)) {
setValue(i);
return;
}
}
if (value instanceof ColorRefDef) {
- final ColorDef ref = ((ColorRefDef) value).getRef();
- for (int i = 0; i < fColors.size(); i++) {
- final ColorDef c = fColors.get(i);
+ final ColorDef ref= ((ColorRefDef) value).getRef();
+ for (int i= 0; i < this.colors.size(); i++) {
+ final ColorDef c= this.colors.get(i);
if (c.equals(ref)) {
setValue(i);
return;
}
}
}
- for (int i = 0; i < fColors.size(); i++) {
- final ColorDef c = fColors.get(i);
+ for (int i= 0; i < this.colors.size(); i++) {
+ final ColorDef c= this.colors.get(i);
if (c.equalsRGB(value)) {
setValue(i);
return;
@@ -419,9 +418,9 @@
}
public void setValue(final int idx) {
- fCursorIdx = idx;
+ this.cursorIdx= idx;
checkCursor();
- if (fSelectionIdx != idx) {
+ if (this.selectionIdx != idx) {
if (doSetColor(idx, 0, 0)) {
return;
}
@@ -433,22 +432,22 @@
if (idx != 0) {
throw new IllegalArgumentException("idx: " + idx); //$NON-NLS-1$
}
- int colorIdx = -1;
- for (int i = 0; i < fColors.size(); i++) {
- final ColorDef c = fColors.get(i);
+ int colorIdx= -1;
+ for (int i= 0; i < this.colors.size(); i++) {
+ final ColorDef c= this.colors.get(i);
if (c.equals(value)) {
- colorIdx = i;
+ colorIdx= i;
break;
}
if (colorIdx == -1 && c.equalsRGB(value)) {
- colorIdx = i;
+ colorIdx= i;
}
}
if (colorIdx >= 0) {
- fCursorIdx = colorIdx;
+ this.cursorIdx= colorIdx;
checkCursor();
redraw();
}
}
-}
\ No newline at end of file
+}
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/HSVSelector.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/HSVSelector.java
index cb45cf2..c911611 100644
--- a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/HSVSelector.java
+++ b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/HSVSelector.java
@@ -33,16 +33,15 @@
import org.eclipse.statet.ecommons.collections.FastList;
import org.eclipse.statet.ecommons.graphics.core.ColorDef;
import org.eclipse.statet.ecommons.graphics.core.HSVColorDef;
-import org.eclipse.statet.ecommons.ui.SharedUIResources;
import org.eclipse.statet.ecommons.ui.util.LayoutUtils;
public class HSVSelector extends Canvas implements IObjValueWidget<ColorDef> {
/*
- * s = saturation, v = value
- * triangle: Psv = (x11, y11), (x01, y01), (x10, y10)
- * equation of lines: a * x + b * y + c = 0
+ * s= saturation, v= value
+ * triangle: Psv= (x11, y11), (x01, y01), (x10, y10)
+ * equation of lines: a * x + b * y + c= 0
*/
@@ -60,60 +59,58 @@
return value;
}
- private static final Color G_BACKGROUND = SharedUIResources.getColors().getColor(SharedUIResources.GRAPHICS_BACKGROUND_COLOR_ID);
-
- private static final HSVColorDef DEFAULT_VALUE = new HSVColorDef(0f, 1f, 1f);
+ private static final HSVColorDef DEFAULT_VALUE= new HSVColorDef(0f, 1f, 1f);
private static Color createColor(final Device device, float hue, final float saturation, final float value) {
float r, g, b;
if (saturation == 0) {
- r = g = b = value;
+ r= g= b= value;
}
else {
if (hue == 1) {
- hue = 0;
+ hue= 0;
}
- hue *= 6;
- final int i = (int) hue;
- final float f = hue - i;
- final float p = value * (1 - saturation);
- final float q = value * (1 - saturation * f);
- final float t = value * (1 - saturation * (1 - f));
+ hue *= 6;
+ final int i= (int) hue;
+ final float f= hue - i;
+ final float p= value * (1 - saturation);
+ final float q= value * (1 - saturation * f);
+ final float t= value * (1 - saturation * (1 - f));
switch(i) {
case 0:
- r = value;
- g = t;
- b = p;
+ r= value;
+ g= t;
+ b= p;
break;
case 1:
- r = q;
- g = value;
- b = p;
+ r= q;
+ g= value;
+ b= p;
break;
case 2:
- r = p;
- g = value;
- b = t;
+ r= p;
+ g= value;
+ b= t;
break;
case 3:
- r = p;
- g = q;
- b = value;
+ r= p;
+ g= q;
+ b= value;
break;
case 4:
- r = t;
- g = p;
- b = value;
+ r= t;
+ g= p;
+ b= value;
break;
case 5:
default:
- r = value;
- g = p;
- b = q;
+ r= value;
+ g= p;
+ b= q;
break;
}
}
- return new Color(device, (int) (r * 255 + 0.5), (int) (g * 255 + 0.5), (int) (b * 255 + 0.5));
+ return new Color((int) (r * 255 + 0.5), (int) (g * 255 + 0.5), (int) (b * 255 + 0.5));
}
private static void plotPoint(final GC gc, final int x, final int y, final Color color) {
@@ -128,25 +125,27 @@
if (color != null) {
gc.setForeground(color);
}
- final float m = - a / b;
- final float t = - c / b;
- for (int x = xMin; x <= xMax; x++) {
- final float y = m * x + t;
+ final float m= - a / b;
+ final float t= - c / b;
+ for (int x= xMin; x <= xMax; x++) {
+ final float y= m * x + t;
gc.drawPoint(x, Math.round(y));
}
}
- private final static class Data {
+ private static final class Data {
- private final static float TRIANGLE_RATIO = 0.78f;
- private final static float TRIANGLE_ALPHA = -1f;
+ private final static float TRIANGLE_RATIO= 0.78f;
+ private final static float TRIANGLE_ALPHA= -1f;
private final int size;
private final int center;
private final float outer;
private final float inner;
+ private final Color backgroundColor;
+
private final float h;
private final float xh1;
@@ -160,36 +159,38 @@
private final float y10;
- public Data(final int size, final float hue) {
- this.size = size;
- center = size / 2;
- outer = center;
- inner = (int) (outer * TRIANGLE_RATIO);
+ public Data(final int size, final Color backgroundColor, final float hue) {
+ this.size= size;
+ this.center= size / 2;
+ this.outer= this.center;
+ this.inner= (int) (this.outer * TRIANGLE_RATIO);
- h = hue;
+ this.backgroundColor= backgroundColor;
+
+ this.h= hue;
float[] xy1;
- xy1 = hue_xy1(h);
- xh1 = xy1[0];
- yh1 = xy1[1];
+ xy1= hue_xy1(this.h);
+ this.xh1= xy1[0];
+ this.yh1= xy1[1];
- x11 = center + inner * xh1;
- y11 = center + inner * yh1;
- xy1 = hue_xy1(h + 1.0/3.0);
- x01 = center + inner * xy1[0];
- y01 = center + inner * xy1[1];
- xy1 = hue_xy1(h - 1.0/3.0);
- x10 = center + inner * xy1[0];
- y10 = center + inner * xy1[1];
+ this.x11= this.center + this.inner * this.xh1;
+ this.y11= this.center + this.inner * this.yh1;
+ xy1= hue_xy1(this.h + 1.0/3.0);
+ this.x01= this.center + this.inner * xy1[0];
+ this.y01= this.center + this.inner * xy1[1];
+ xy1= hue_xy1(this.h - 1.0/3.0);
+ this.x10= this.center + this.inner * xy1[0];
+ this.y10= this.center + this.inner * xy1[1];
}
public final int x0(final int x) {
- return (x - center);
+ return (x - this.center);
}
public final int y0(final int y) {
- return (y - center);
+ return (y - this.center);
}
public final float xy0_d(final int x0, final int y0) {
@@ -197,94 +198,92 @@
}
public final float xy0_hue(final int x0, final int y0) {
- float hue = (float) (Math.atan2(y0, x0) / (2 * Math.PI));
- hue += 0.25f;
+ float hue= (float) (Math.atan2(y0, x0) / (2 * Math.PI));
+ hue+= 0.25f;
if (hue < 0) {
- hue += 1f;
+ hue+= 1f;
}
return hue;
}
public final float[] hue_xy1(final double hue) {
- final double a = (hue - 0.25) * (2 * Math.PI);
+ final double a= (hue - 0.25) * (2 * Math.PI);
return new float[] { (float) Math.cos(a), (float) Math.sin(a) };
}
public HSVColorDef svColor(final int x, final int y) {
- final float a_01_11 = (y11 - y01);
- final float b_01_11 = -(x11 - x01);
- final float c_01_11 = -(a_01_11 * x11 + b_01_11 * y11);
+ final float a_01_11= (this.y11 - this.y01);
+ final float b_01_11= -(this.x11 - this.x01);
+ final float c_01_11= -(a_01_11 * this.x11 + b_01_11 * this.y11);
- final float av = (y - y10);
- final float bv = -(x - x10);
- final float cv = -(av * x + bv * y);
+ final float av= (y - this.y10);
+ final float bv= -(x - this.x10);
+ final float cv= -(av * x + bv * y);
final float s;
final float v;
if (a_01_11 < -4f || a_01_11 > 4f) {
- final float yq = (av / a_01_11 * c_01_11 - cv) / (bv - (av / a_01_11 * b_01_11));
+ final float yq= (av / a_01_11 * c_01_11 - cv) / (bv - (av / a_01_11 * b_01_11));
- s = (yq - y01) / a_01_11;
- v = (y - y10) / (yq - y10);
+ s= (yq - this.y01) / a_01_11;
+ v= (y - this.y10) / (yq - this.y10);
}
else {
- final float yq = (a_01_11 / av * cv - c_01_11) / (b_01_11 - (a_01_11 / av * bv));
- final float xq = - (bv * yq + cv) / av;
+ final float yq= (a_01_11 / av * cv - c_01_11) / (b_01_11 - (a_01_11 / av * bv));
+ final float xq= - (bv * yq + cv) / av;
- s = (xq - x01) / (x11 - x01);
- v = (x - x10) / (xq - x10);
+ s= (xq - this.x01) / (this.x11 - this.x01);
+ v= (x - this.x10) / (xq - this.x10);
}
- return new HSVColorDef(h, save01(s), save01(v));
+ return new HSVColorDef(this.h, save01(s), save01(v));
}
public int[] sv_xy(final float s, final float v) {
- final float xq = x01 + s * (x11 - x01);
- final float yq = y01 + s * (y11 - y01);
+ final float xq= this.x01 + s * (this.x11 - this.x01);
+ final float yq= this.y01 + s * (this.y11 - this.y01);
- final float x = x10 + v * (xq - x10);
- final float y = y10 + v * (yq - y10);
+ final float x= this.x10 + v * (xq - this.x10);
+ final float y= this.y10 + v * (yq - this.y10);
return new int[] { Math.round(x), Math.round(y) };
}
private Image createBaseImage(final Display display) {
- final Image image = new Image(display, size, size);
- final GC gc = new GC(image);
- gc.setBackground(G_BACKGROUND);
- gc.fillRectangle(0, 0, size, size);
+ final Image image= new Image(display, this.size, this.size);
+ final GC gc= new GC(image);
+ gc.setBackground(this.backgroundColor);
+ gc.fillRectangle(0, 0, this.size, this.size);
gc.setAdvanced(true);
gc.setAntialias(SWT.OFF);
- int currentAlpha = 255;
+ int currentAlpha= 255;
- final float in = inner + 1;
- for (int y = 0; y < size; y++) {
- for (int x = 0; x < size; x++) {
- final int x0 = x0(x);
- final int y0 = y0(y);
- final float d = xy0_d(x0, y0);
- { float a = outer - d;
+ final float in= this.inner + 1;
+ for (int y= 0; y < this.size; y++) {
+ for (int x= 0; x < this.size; x++) {
+ final int x0= x0(x);
+ final int y0= y0(y);
+ final float d= xy0_d(x0, y0);
+ { float a= this.outer - d;
if (a < 0) {
continue;
}
if (a > 1) {
- a = d - in;
+ a= d - in;
if (a < 0) {
continue;
}
if (a > 1) {
- a = 1;
+ a= 1;
}
}
- final int alpha = (int) (a * 255);
+ final int alpha= (int) (a * 255);
if (alpha != currentAlpha) {
- gc.setAlpha(currentAlpha = alpha);
+ gc.setAlpha(currentAlpha= alpha);
}
}
- final Color color = createColor(display, xy0_hue(x0, y0), 1f, 1f);
- gc.setForeground(color);
+ gc.setForeground(createColor(display, xy0_hue(x0, y0), 1f, 1f));
gc.drawPoint(x, y);
- color.dispose();
}
}
gc.dispose();
@@ -292,120 +291,118 @@
}
private Image createFullImage(final Display display) {
- final Image image = new Image(display, getBaseImage(this, display), SWT.IMAGE_COPY);
- if (h < 0) {
+ final Image image= new Image(display, getBaseImage(this, display), SWT.IMAGE_COPY);
+ if (this.h < 0) {
return image;
}
- final GC gc = new GC(image);
+ final GC gc= new GC(image);
gc.setAdvanced(true);
gc.setAntialias(SWT.OFF);
- int currentAlpha = 255;
+ int currentAlpha= 255;
- final int xMin = Math.min((int) Math.ceil(x11), Math.min((int) Math.ceil(x01), (int) Math.ceil(x10))) - 1;
- final int xMax = Math.max((int) Math.floor(x11), Math.max((int) Math.floor(x01), (int) Math.floor(x10))) + 1;
- final int yMin = Math.min((int) Math.ceil(y11), Math.min((int) Math.ceil(y01), (int) Math.ceil(y10))) - 1;
- final int yMax = Math.max((int) Math.floor(y11), Math.max((int) Math.floor(y01), (int) Math.floor(y10))) + 1;
+ final int xMin= Math.min((int) Math.ceil(this.x11), Math.min((int) Math.ceil(this.x01), (int) Math.ceil(this.x10))) - 1;
+ final int xMax= Math.max((int) Math.floor(this.x11), Math.max((int) Math.floor(this.x01), (int) Math.floor(this.x10))) + 1;
+ final int yMin= Math.min((int) Math.ceil(this.y11), Math.min((int) Math.ceil(this.y01), (int) Math.ceil(this.y10))) - 1;
+ final int yMax= Math.max((int) Math.floor(this.y11), Math.max((int) Math.floor(this.y01), (int) Math.floor(this.y10))) + 1;
final float a_01_11, b_01_11, c_01_11;
- { final float a = (y11 - y01);
- final float b = -(x11 - x01);
- final float d = distance(a, b);
- a_01_11 = a / d;
- b_01_11 = b / d;
- c_01_11 = -(a * x11 + b * y11) / d;
+ { final float a= (this.y11 - this.y01);
+ final float b= -(this.x11 - this.x01);
+ final float d= distance(a, b);
+ a_01_11= a / d;
+ b_01_11= b / d;
+ c_01_11= -(a * this.x11 + b * this.y11) / d;
}
final float a_10_01, b_10_01, c_10_01;
- { final float a = (y01 - y10);
- final float b = -(x01 - x10);
- final float d = distance(a, b);
- a_10_01 = a / d;
- b_10_01 = b / d;
- c_10_01 = -(a * x01 + b * y01) / d;
+ { final float a= (this.y01 - this.y10);
+ final float b= -(this.x01 - this.x10);
+ final float d= distance(a, b);
+ a_10_01= a / d;
+ b_10_01= b / d;
+ c_10_01= -(a * this.x01 + b * this.y01) / d;
}
final float a_11_10, b_11_10, c_11_10;
- { final float a = (y10 - y11);
- final float b = -(x10 - x11);
- final float d = distance(a, b);
- a_11_10 = a / d;
- b_11_10 = b / d;
- c_11_10 = -(a * x10 + b * y10) / d;
+ { final float a= (this.y10 - this.y11);
+ final float b= -(this.x10 - this.x11);
+ final float d= distance(a, b);
+ a_11_10= a / d;
+ b_11_10= b / d;
+ c_11_10= -(a * this.x10 + b * this.y10) / d;
}
- for (int y = yMin; y <= yMax; y++) {
- final float av = (y - y10);
- final float av_as_cs = av / a_01_11 * c_01_11;
- final float av_as_bs = av / a_01_11 * b_01_11;
- for (int x = xMin; x <= xMax; x++) {
- float min = 0f;
- { final float d = (a_01_11 * x + b_01_11 *y + c_01_11);
+ for (int y= yMin; y <= yMax; y++) {
+ final float av= (y - this.y10);
+ final float av_as_cs= av / a_01_11 * c_01_11;
+ final float av_as_bs= av / a_01_11 * b_01_11;
+ for (int x= xMin; x <= xMax; x++) {
+ float min= 0f;
+ { final float d= (a_01_11 * x + b_01_11 *y + c_01_11);
if (d < 0f) {
if (d < TRIANGLE_ALPHA) {
continue;
}
if (d < min) {
- min = d;
+ min= d;
}
}
}
- { final float d = (a_10_01 * x + b_10_01 *y + c_10_01);
+ { final float d= (a_10_01 * x + b_10_01 *y + c_10_01);
if (d < 0f) {
if (d < TRIANGLE_ALPHA) {
continue;
}
if (d < min) {
- min = d;
+ min= d;
}
}
}
- { final float d = (a_11_10 * x + b_11_10 *y + c_11_10);
+ { final float d= (a_11_10 * x + b_11_10 *y + c_11_10);
if (d < 0f) {
if (d < TRIANGLE_ALPHA) {
continue;
}
if (d < min) {
- min = d;
+ min= d;
}
}
}
final float s;
final float v;
- { final float bv = -(x - x10);
- final float cv = -(av * x + bv * y);
+ { final float bv= -(x - this.x10);
+ final float cv= -(av * x + bv * y);
if (a_01_11 < -4f || a_01_11 > 4f) {
- final float yq = (av_as_cs - cv) / (bv - (av_as_bs));
+ final float yq= (av_as_cs - cv) / (bv - (av_as_bs));
- s = (yq - y01) / a_01_11;
- v = (y - y10) / (yq - y10);
+ s= (yq - this.y01) / a_01_11;
+ v= (y - this.y10) / (yq - this.y10);
}
else {
- final float yq = (a_01_11 / av * cv - c_01_11) / (b_01_11 - (a_01_11 / av * bv));
- final float xq = - (bv * yq + cv) / av;
+ final float yq= (a_01_11 / av * cv - c_01_11) / (b_01_11 - (a_01_11 / av * bv));
+ final float xq= - (bv * yq + cv) / av;
- s = (xq - x01) / (x11 - x01);
- v = (x - x10) / (xq - x10);
+ s= (xq - this.x01) / (this.x11 - this.x01);
+ v= (x - this.x10) / (xq - this.x10);
}
}
// final float xq, yq;
-// { final float bv = -(x - x10);
-// final float cv = -(av * x + bv * y);
+// { final float bv= -(x - x10);
+// final float cv= -(av * x + bv * y);
//
-// yq = (av_as_cs - cv) / (bv - av_as_bs);
-// xq = - (b_01_11 * yq + c_01_11) / a_01_11;
+// yq= (av_as_cs - cv) / (bv - av_as_bs);
+// xq= - (b_01_11 * yq + c_01_11) / a_01_11;
// }
//
-// final float s = (xq - x01) / (x11 - x01);
-// final float v = (x - x10) / (xq - x10);
+// final float s= (xq - x01) / (x11 - x01);
+// final float v= (x - x10) / (xq - x10);
- { final int alpha = (min >= 0f) ? 255 : (int) ((1f+min) * 255);
+ { final int alpha= (min >= 0f) ? 255 : (int) ((1f+min) * 255);
if (alpha != currentAlpha) {
- gc.setAlpha(currentAlpha = alpha);
+ gc.setAlpha(currentAlpha= alpha);
}
}
- final Color color = createColor(display, h, save01(s), save01(v));
- gc.setForeground(color);
+ gc.setForeground(createColor(display, this.h, save01(s), save01(v)));
gc.drawPoint(x, y);
- color.dispose();
}
}
@@ -414,23 +411,23 @@
}
public void drawTriangle(final GC gc) {
- final int[] xy = new int[6];
- xy[0] = Math.round(x11);
- xy[1] = Math.round(y11);
- xy[2] = Math.round(x01);
- xy[3] = Math.round(y01);
- xy[4] = Math.round(x10);
- xy[5] = Math.round(y10);
+ final int[] xy= new int[6];
+ xy[0]= Math.round(this.x11);
+ xy[1]= Math.round(this.y11);
+ xy[2]= Math.round(this.x01);
+ xy[3]= Math.round(this.y01);
+ xy[4]= Math.round(this.x10);
+ xy[5]= Math.round(this.y10);
gc.drawPolygon(xy);
}
}
- private static final Image[] BASE_CACHE = new Image[10];
+ private static final Image[] BASE_CACHE= new Image[10];
private static Image getBaseImage(final Data data, final Display display) {
- for (int i = 0; i < BASE_CACHE.length; i++) {
+ for (int i= 0; i < BASE_CACHE.length; i++) {
if (BASE_CACHE[i] == null) {
break;
}
@@ -442,7 +439,7 @@
BASE_CACHE[BASE_CACHE.length - 1].dispose();
}
System.arraycopy(BASE_CACHE, 0, BASE_CACHE, 1, BASE_CACHE.length - 1);
- BASE_CACHE[0] = data.createBaseImage(display);
+ BASE_CACHE[0]= data.createBaseImage(display);
return BASE_CACHE[0];
}
@@ -450,46 +447,46 @@
private class SWTListener implements PaintListener, Listener {
- private static final int TRACK_HUE = 1;
- private static final int TRACK_SV = 2;
+ private static final int TRACK_HUE= 1;
+ private static final int TRACK_SV= 2;
- private Data fData;
+ private Data data;
- private Image fImage;
+ private Image image;
- private int fMouseState;
+ private int mouseState;
@Override
public void handleEvent(final Event event) {
- final Data data = fData;
+ final Data data= this.data;
switch (event.type) {
case SWT.MouseDown:
if (data != null) {
- final int x0 = data.x0(event.x);
- final int y0 = data.y0(event.y);
- final float d = data.xy0_d(x0, y0);
+ final int x0= data.x0(event.x);
+ final int y0= data.y0(event.y);
+ final float d= data.xy0_d(x0, y0);
if (d > data.inner) {
doSetValue(new HSVColorDef(data.xy0_hue(x0, y0),
- fValue.getSaturation(), fValue.getValue()),
+ HSVSelector.this.value.getSaturation(), HSVSelector.this.value.getValue()),
event.time, 0 );
- fMouseState = TRACK_HUE;
+ this.mouseState= TRACK_HUE;
}
else {
doSetValue(data.svColor(event.x, event.y), event.time, 0);
- fMouseState = TRACK_SV;
+ this.mouseState= TRACK_SV;
}
}
return;
case SWT.MouseUp:
- fMouseState = 0;
+ this.mouseState= 0;
return;
case SWT.MouseMove:
if (data != null) {
- switch (fMouseState) {
+ switch (this.mouseState) {
case TRACK_HUE:
doSetValue(new HSVColorDef(data.xy0_hue(data.x0(event.x), data.y0(event.y)),
- fValue.getSaturation(), fValue.getValue()),
+ HSVSelector.this.value.getSaturation(), HSVSelector.this.value.getValue()),
event.time, 0 );
break;
case TRACK_SV:
@@ -503,65 +500,69 @@
@Override
public void paintControl(final PaintEvent e) {
- final Rectangle clientArea = getClientArea();
- int size = Math.min(clientArea.width, clientArea.height);
- if (fSize > 0 && fSize < size) {
- size = fSize;
+ final Rectangle clientArea= getClientArea();
+ int size= Math.min(clientArea.width, clientArea.height);
+ if (HSVSelector.this.size > 0 && HSVSelector.this.size < size) {
+ size= HSVSelector.this.size;
}
- if (fData == null || fData.size != size || fData.h != fValue.getHue()) {
- if (fImage != null) {
- fImage.dispose();
- fImage = null;
+ if (this.data == null || this.data.size != size || this.data.h != HSVSelector.this.value.getHue()) {
+ if (this.image != null) {
+ this.image.dispose();
+ this.image= null;
}
- fData = new Data(size, fValue.getHue());
+ this.data= new Data(size, HSVSelector.this.backgroundColor, HSVSelector.this.value.getHue());
}
- final GC gc = e.gc;
+ final GC gc= e.gc;
gc.setAdvanced(true);
gc.setAntialias(SWT.OFF);
- final int currentAlpha = 255;
+ final int currentAlpha= 255;
gc.setAlpha(currentAlpha);
- gc.setBackground(G_BACKGROUND);
+ gc.setBackground(HSVSelector.this.backgroundColor);
gc.fillRectangle(clientArea);
- if (fImage == null) {
- fImage = fData.createFullImage(e.display);
+ if (this.image == null) {
+ this.image= this.data.createFullImage(e.display);
}
- gc.drawImage(fImage, 0, 0);
+ gc.drawImage(this.image, 0, 0);
gc.setLineWidth(1);
gc.setAntialias(SWT.ON);
gc.setForeground(e.display.getSystemColor(SWT.COLOR_BLACK));
- gc.drawLine(Math.round(fData.center + fData.outer * fData.xh1),
- Math.round(fData.center + fData.outer * fData.yh1),
- Math.round(fData.x11),
- Math.round(fData.y11) );
+ gc.drawLine(Math.round(this.data.center + this.data.outer * this.data.xh1),
+ Math.round(this.data.center + this.data.outer * this.data.yh1),
+ Math.round(this.data.x11),
+ Math.round(this.data.y11) );
- if (fValue.getValue() < 0.50) {
+ if (HSVSelector.this.value.getValue() < 0.50) {
gc.setForeground(e.display.getSystemColor(SWT.COLOR_WHITE));
}
- final int[] xy = fData.sv_xy(fValue.getSaturation(), fValue.getValue());
+ final int[] xy= this.data.sv_xy(HSVSelector.this.value.getSaturation(), HSVSelector.this.value.getValue());
gc.drawOval(xy[0] - 1, xy[1] - 1, 3, 3);
}
}
- private int fSize = 8 + LayoutUtils.defaultHSpacing() * 30;
+ private int size= 8 + LayoutUtils.defaultHSpacing() * 30;
- private HSVColorDef fValue = DEFAULT_VALUE;
+ private HSVColorDef value= DEFAULT_VALUE;
- private final FastList<IObjValueListener<ColorDef>> fValueListeners= (FastList) new FastList<>(IObjValueListener.class);
+ private final FastList<IObjValueListener<ColorDef>> valueListeners= (FastList) new FastList<>(IObjValueListener.class);
+
+ private Color backgroundColor;
- public HSVSelector(final Composite parent) {
+ public HSVSelector(final Composite parent, final Color backgroundColor) {
super(parent, SWT.DOUBLE_BUFFERED);
- final SWTListener listener = new SWTListener();
+ this.backgroundColor= backgroundColor;
+
+ final SWTListener listener= new SWTListener();
addPaintListener(listener);
addListener(SWT.MouseDown, listener);
addListener(SWT.MouseUp, listener);
@@ -570,20 +571,20 @@
public void setSize(final int size) {
- fSize = size;
+ this.size= size;
}
private boolean doSetValue(final HSVColorDef newValue, final int time, final int flags) {
- if (fValue.equals(newValue) && flags == 0 && fValue != DEFAULT_VALUE) {
+ if (this.value.equals(newValue) && flags == 0 && this.value != DEFAULT_VALUE) {
return false;
}
- final IObjValueListener<ColorDef>[] listeners = fValueListeners.toArray();
+ final IObjValueListener<ColorDef>[] listeners= this.valueListeners.toArray();
final ObjValueEvent<ColorDef> event= new ObjValueEvent<>(this, time, 0,
- fValue, newValue, flags);
+ this.value, newValue, flags);
- fValue = newValue;
- for (int i = 0; i < listeners.length; i++) {
- event.newValue = newValue;
+ this.value= newValue;
+ for (int i= 0; i < listeners.length; i++) {
+ event.newValue= newValue;
listeners[i].valueChanged(event);
}
if (!isDisposed()) {
@@ -595,11 +596,11 @@
@Override
public Point computeSize(final int wHint, final int hHint, final boolean changed) {
- int width = fSize;
- int height = fSize;
- final int border = getBorderWidth();
- width += border * 2;
- height += border * 2;
+ int width= this.size;
+ int height= this.size;
+ final int border= getBorderWidth();
+ width+= border * 2;
+ height+= border * 2;
return new Point(width, height);
}
@@ -616,12 +617,12 @@
@Override
public void addValueListener(final IObjValueListener<ColorDef> listener) {
- fValueListeners.add(listener);
+ this.valueListeners.add(listener);
}
@Override
public void removeValueListener(final IObjValueListener<ColorDef> listener) {
- fValueListeners.remove(listener);
+ this.valueListeners.remove(listener);
}
@Override
@@ -629,7 +630,7 @@
if (idx != 0) {
throw new IllegalArgumentException("idx: " + idx); //$NON-NLS-1$
}
- return fValue;
+ return this.value;
}
@Override
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/RGBSelector.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/RGBSelector.java
index bae3f87..530b0a0 100644
--- a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/RGBSelector.java
+++ b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/RGBSelector.java
@@ -32,27 +32,26 @@
import org.eclipse.statet.ecommons.collections.FastList;
import org.eclipse.statet.ecommons.graphics.core.ColorDef;
import org.eclipse.statet.ecommons.graphics.core.HSVColorDef;
-import org.eclipse.statet.ecommons.ui.SharedUIResources;
import org.eclipse.statet.ecommons.ui.util.LayoutUtils;
public class RGBSelector extends Canvas implements IObjValueWidget<ColorDef> {
- private static final byte RED = 0x0;
- private static final byte GREEN = 0x1;
- private static final byte BLUE = 0x2;
+ private static final byte RED= 0x0;
+ private static final byte GREEN= 0x1;
+ private static final byte BLUE= 0x2;
- private static final ColorDef DEFAULT_VALUE = new HSVColorDef(1, 0, 0);
-
- private static final Color G_BACKGROUND = SharedUIResources.getColors().getColor(SharedUIResources.GRAPHICS_BACKGROUND_COLOR_ID);
+ private static final ColorDef DEFAULT_VALUE= new HSVColorDef(1, 0, 0);
- private final static class Data {
+ private static final class Data {
private final int size;
private final float factor;
+ private final Color backgroundColor;
+
private final int primX0;
private final int primX1;
@@ -63,23 +62,25 @@
private final int y1;
- public Data(final int size) {
- this.size = size;
- factor = size - 1;
+ public Data(final int size, final Color backgroundColor) {
+ this.size= size;
+ this.factor= size - 1;
- primX0 = 1;
- primX1 = primX0 + Math.round(size * 0.15f);
+ this.backgroundColor= backgroundColor;
- rectX0 = primX1 + LayoutUtils.defaultHSpacing();
- rectX1 = rectX0 + size;
+ this.primX0= 1;
+ this.primX1= this.primX0 + Math.round(size * 0.15f);
- y0 = 1;
- y1 = y0 + size;
+ this.rectX0= this.primX1 + LayoutUtils.defaultHSpacing();
+ this.rectX1= this.rectX0 + size;
+
+ this.y0= 1;
+ this.y1= this.y0 + size;
}
public int prim_y_255(final int y) {
- final int v = 255 - Math.round(((y - y0) / factor) * 255f);
+ final int v= 255 - Math.round(((y - this.y0) / this.factor) * 255f);
if (v <= 0) {
return 0;
}
@@ -90,7 +91,7 @@
}
public int rect_x_255(final int x) {
- final int v = Math.round(((x - rectX0) / factor) * 255f);
+ final int v= Math.round(((x - this.rectX0) / this.factor) * 255f);
if (v <= 0) {
return 0;
}
@@ -101,7 +102,7 @@
}
public int rect_y_255(final int y) {
- final int v = 255 - Math.round(((y - y0) / factor) * 255f);
+ final int v= 255 - Math.round(((y - this.y0) / this.factor) * 255f);
if (v <= 0) {
return 0;
}
@@ -112,46 +113,42 @@
}
public int prim_255_y(final int v) {
- return y0 + Math.round(((255 - v) / 255f) * factor);
+ return this.y0 + Math.round(((255 - v) / 255f) * this.factor);
}
public int rect_255_x(final int v) {
- return rectX0 + Math.round((v / 255f) * factor);
+ return this.rectX0 + Math.round((v / 255f) * this.factor);
}
public int rect_255_y(final int v) {
- return y0 + Math.round(((255 - v) / 255f) * factor);
+ return this.y0 + Math.round(((255 - v) / 255f) * this.factor);
}
public Image createImage(final Display display, final byte primColor, final int primValue, final byte xColor, final byte yColor) {
- final Image image = new Image(display, rectX1 + 1, y1 + 1);
- final GC gc = new GC(image);
+ final Image image= new Image(display, this.rectX1 + 1, this.y1 + 1);
+ final GC gc= new GC(image);
gc.setAdvanced(false);
- gc.setBackground(G_BACKGROUND);
+ gc.setBackground(this.backgroundColor);
gc.fillRectangle(0, 0, image.getImageData().width, image.getImageData().height);
// prim
- final int[] rgb = new int[3];
- { final int x1 = primX1 - 1;
- for (int y = y0; y < y1; y++) {
- rgb[primColor] = prim_y_255(y);
- final Color color = new Color(display, rgb[0], rgb[1], rgb[2]);
- gc.setForeground(color);
- gc.drawLine(primX0, y, x1, y);
- color.dispose();
+ final int[] rgb= new int[3];
+ { final int x1= this.primX1 - 1;
+ for (int y= this.y0; y < this.y1; y++) {
+ rgb[primColor]= prim_y_255(y);
+ gc.setForeground(new Color(rgb[0], rgb[1], rgb[2]));
+ gc.drawLine(this.primX0, y, x1, y);
}
}
// rect
- rgb[primColor] = primValue;
- for (int y = y0; y < y1; y++) {
- rgb[yColor] = rect_y_255(y);
- for (int x = rectX0; x < rectX1; x++) {
- rgb[xColor] = rect_x_255(x);
- final Color color = new Color(display, rgb[0], rgb[1], rgb[2]);
- gc.setForeground(color);
+ rgb[primColor]= primValue;
+ for (int y= this.y0; y < this.y1; y++) {
+ rgb[yColor]= rect_y_255(y);
+ for (int x= this.rectX0; x < this.rectX1; x++) {
+ rgb[xColor]= rect_x_255(x);
+ gc.setForeground(new Color(rgb[0], rgb[1], rgb[2]));
gc.drawPoint(x, y);
- color.dispose();
}
}
@@ -165,119 +162,119 @@
private class SWTListener implements PaintListener, Listener {
- private static final int TRACK_PRIM = 1;
- private static final int TRACK_RECT = 2;
+ private static final int TRACK_PRIM= 1;
+ private static final int TRACK_RECT= 2;
- private Data fData;
+ private Data data;
- private Image fImage;
- private int fImagePrim;
- private int fImagePrimValue;
+ private Image image;
+ private int imagePrim;
+ private int imagePrimValue;
- private int fMouseState;
+ private int mouseState;
@Override
public void handleEvent(final Event event) {
- final Data data = fData;
+ final Data data= this.data;
switch (event.type) {
case SWT.MouseDown:
if (data != null && event.y >= data.y0 && event.y < data.y1) {
if (event.x >= data.primX0 && event.x < data.primX1) {
- doSetValue(createColor(fCurrentPrim, data.prim_y_255(event.y)),
+ doSetValue(createColor(RGBSelector.this.currentPrim, data.prim_y_255(event.y)),
event.time, 0 );
- fMouseState = TRACK_PRIM;
+ this.mouseState= TRACK_PRIM;
}
else if (event.x >= data.rectX0 && event.x < data.rectX1) {
- doSetValue(createColor(fCurrentRectX, data.rect_x_255(event.x),
- fCurrentRectY, data.rect_y_255(event.y)),
+ doSetValue(createColor(RGBSelector.this.currentRectX, data.rect_x_255(event.x),
+ RGBSelector.this.currentRectY, data.rect_y_255(event.y)),
event.time, 0 );
- fMouseState = TRACK_RECT;
+ this.mouseState= TRACK_RECT;
}
}
return;
case SWT.MouseUp:
- fMouseState = 0;
+ this.mouseState= 0;
return;
case SWT.MouseMove:
if (data != null) {
- switch (fMouseState) {
+ switch (this.mouseState) {
case TRACK_PRIM:
- doSetValue(createColor(fCurrentPrim, data.prim_y_255(event.y)),
+ doSetValue(createColor(RGBSelector.this.currentPrim, data.prim_y_255(event.y)),
event.time, 0 );
break;
case TRACK_RECT:
- doSetValue(createColor(fCurrentRectX, data.rect_x_255(event.x),
- fCurrentRectY, data.rect_y_255(event.y)),
+ doSetValue(createColor(RGBSelector.this.currentRectX, data.rect_x_255(event.x),
+ RGBSelector.this.currentRectY, data.rect_y_255(event.y)),
event.time, 0 );
break;
}
}
return;
case SWT.Dispose:
- if (fImage != null) {
- fImage.dispose();
- fImage = null;
+ if (this.image != null) {
+ this.image.dispose();
+ this.image= null;
}
}
}
private int computeSize(int width, final int height) {
width -= LayoutUtils.defaultHSpacing();
- width = Math.round(width / 1.15f);
+ width= Math.round(width / 1.15f);
return Math.min(width - 2, height - 2);
}
@Override
public void paintControl(final PaintEvent e) {
- final Rectangle clientArea = getClientArea();
- int size = computeSize(clientArea.width, clientArea.height);
- if (fSize > 0 && fSize < size) {
- size = fSize;
+ final Rectangle clientArea= getClientArea();
+ int size= computeSize(clientArea.width, clientArea.height);
+ if (RGBSelector.this.size > 0 && RGBSelector.this.size < size) {
+ size= RGBSelector.this.size;
}
- if (fData == null || fData.size != size) {
- fData = new Data(size);
+ if (this.data == null || this.data.size != size) {
+ this.data= new Data(size, RGBSelector.this.backgroundColor);
}
- final GC gc = e.gc;
+ final GC gc= e.gc;
gc.setAdvanced(true);
gc.setAntialias(SWT.OFF);
- final int currentAlpha = 255;
+ final int currentAlpha= 255;
gc.setAlpha(currentAlpha);
- gc.setBackground(G_BACKGROUND);
+ gc.setBackground(RGBSelector.this.backgroundColor);
gc.fillRectangle(clientArea);
- final int primValue = getComponent(fCurrentPrim);
- if (fImage == null || fImagePrim != fCurrentPrim || fImagePrimValue != primValue) {
- if (fImage != null) {
- fImage.dispose();
+ final int primValue= getComponent(RGBSelector.this.currentPrim);
+ if (this.image == null || this.imagePrim != RGBSelector.this.currentPrim || this.imagePrimValue != primValue) {
+ if (this.image != null) {
+ this.image.dispose();
}
- fImage = fData.createImage(e.display, fCurrentPrim, primValue,
- fCurrentRectX, fCurrentRectY );
- fImagePrim = fCurrentPrim;
- fImagePrimValue = primValue;
+ this.image= this.data.createImage(e.display, RGBSelector.this.currentPrim, primValue,
+ RGBSelector.this.currentRectX, RGBSelector.this.currentRectY );
+ this.imagePrim= RGBSelector.this.currentPrim;
+ this.imagePrimValue= primValue;
}
- gc.drawImage(fImage, 0, 0);
+ gc.drawImage(this.image, 0, 0);
gc.setLineWidth(1);
gc.setAdvanced(true);
gc.setAntialias(SWT.ON);
- { final int y = fData.prim_255_y(primValue);
+ { final int y= this.data.prim_255_y(primValue);
gc.setForeground(e.display.getSystemColor(SWT.COLOR_BLACK));
- gc.drawLine(fData.primX0 - 1, y, fData.primX1, y);
+ gc.drawLine(this.data.primX0 - 1, y, this.data.primX1, y);
if (primValue < 127) {
gc.setForeground(e.display.getSystemColor(SWT.COLOR_WHITE));
- gc.drawLine(fData.primX0, y, fData.primX1 - 1, y);
+ gc.drawLine(this.data.primX0, y, this.data.primX1 - 1, y);
}
}
- { final int x = fData.rect_255_x(getComponent(fCurrentRectX));
- final int y = fData.rect_255_y(getComponent(fCurrentRectY));
+ { final int x= this.data.rect_255_x(getComponent(RGBSelector.this.currentRectX));
+ final int y= this.data.rect_255_y(getComponent(RGBSelector.this.currentRectY));
gc.setForeground(e.display.getSystemColor(
- (Math.max(Math.max(fValue.getRed(), fValue.getGreen()), fValue.getBlue()) < 127) ? SWT.COLOR_WHITE : SWT.COLOR_BLACK ));
+ (Math.max(Math.max(RGBSelector.this.value.getRed(), RGBSelector.this.value.getGreen()), RGBSelector.this.value.getBlue()) < 127) ? SWT.COLOR_WHITE : SWT.COLOR_BLACK ));
gc.drawOval(x - 1, y - 1, 3, 3);
}
}
@@ -285,23 +282,27 @@
}
- private int fSize = 8 + LayoutUtils.defaultHSpacing() * 30;
+ private int size= 8 + LayoutUtils.defaultHSpacing() * 30;
- private ColorDef fValue = DEFAULT_VALUE;
+ private ColorDef value= DEFAULT_VALUE;
- private byte fCurrentPrim;
- private byte fCurrentRectX;
- private byte fCurrentRectY;
+ private byte currentPrim;
+ private byte currentRectX;
+ private byte currentRectY;
- private final FastList<IObjValueListener<ColorDef>> fValueListeners= (FastList) new FastList<>(IObjValueListener.class);
+ private final FastList<IObjValueListener<ColorDef>> valueListeners= (FastList) new FastList<>(IObjValueListener.class);
+
+ private Color backgroundColor;
- public RGBSelector(final Composite parent) {
+ public RGBSelector(final Composite parent, final Color backgroundColor) {
super(parent, SWT.DOUBLE_BUFFERED);
+ this.backgroundColor= backgroundColor;
+
setPrimary(RED);
- final SWTListener listener = new SWTListener();
+ final SWTListener listener= new SWTListener();
addPaintListener(listener);
addListener(SWT.MouseDown, listener);
addListener(SWT.MouseUp, listener);
@@ -311,46 +312,46 @@
public void setSize(final int size) {
- fSize = size;
+ this.size= size;
}
private int getComponent(final byte c) {
switch (c) {
case RED:
- return fValue.getRed();
+ return this.value.getRed();
case GREEN:
- return fValue.getGreen();
+ return this.value.getGreen();
case BLUE:
- return fValue.getBlue();
+ return this.value.getBlue();
default:
throw new IllegalArgumentException();
}
}
private ColorDef createColor(final byte color, final int value) {
- final int[] rgb = new int[] { fValue.getRed(), fValue.getGreen(), fValue.getBlue() };
- rgb[color] = value;
+ final int[] rgb= new int[] { this.value.getRed(), this.value.getGreen(), this.value.getBlue() };
+ rgb[color]= value;
return new ColorDef(rgb[0], rgb[1], rgb[2]);
}
private ColorDef createColor(final byte change1, final int value1, final byte change2, final int value2) {
- final int[] rgb = new int[] { fValue.getRed(), fValue.getGreen(), fValue.getBlue() };
- rgb[change1] = value1;
- rgb[change2] = value2;
+ final int[] rgb= new int[] { this.value.getRed(), this.value.getGreen(), this.value.getBlue() };
+ rgb[change1]= value1;
+ rgb[change2]= value2;
return new ColorDef(rgb[0], rgb[1], rgb[2]);
}
private boolean doSetValue(final ColorDef newValue, final int time, final int flags) {
- if (fValue.equals(newValue) && flags == 0 && fValue != DEFAULT_VALUE) {
+ if (this.value.equals(newValue) && flags == 0 && this.value != DEFAULT_VALUE) {
return false;
}
- final IObjValueListener<ColorDef>[] listeners = fValueListeners.toArray();
+ final IObjValueListener<ColorDef>[] listeners= this.valueListeners.toArray();
final ObjValueEvent<ColorDef> event= new ObjValueEvent<>(this, time, 0,
- fValue, newValue, flags);
+ this.value, newValue, flags);
- fValue = newValue;
- for (int i = 0; i < listeners.length; i++) {
- event.newValue = newValue;
+ this.value= newValue;
+ for (int i= 0; i < listeners.length; i++) {
+ event.newValue= newValue;
listeners[i].valueChanged(event);
}
if (!isDisposed()) {
@@ -362,11 +363,11 @@
@Override
public Point computeSize(final int wHint, final int hHint, final boolean changed) {
- int width = 2 + Math.round(fSize * 1.15f) + LayoutUtils.defaultHSpacing();
- int height = 2 + fSize;
- final int border = getBorderWidth();
- width += border * 2;
- height += border * 2;
+ int width= 2 + Math.round(this.size * 1.15f) + LayoutUtils.defaultHSpacing();
+ int height= 2 + this.size;
+ final int border= getBorderWidth();
+ width+= border * 2;
+ height+= border * 2;
return new Point(width, height);
}
@@ -383,12 +384,12 @@
@Override
public void addValueListener(final IObjValueListener<ColorDef> listener) {
- fValueListeners.add(listener);
+ this.valueListeners.add(listener);
}
@Override
public void removeValueListener(final IObjValueListener<ColorDef> listener) {
- fValueListeners.remove(listener);
+ this.valueListeners.remove(listener);
}
@Override
@@ -396,7 +397,7 @@
if (idx != 0) {
throw new IllegalArgumentException("idx: " + idx); //$NON-NLS-1$
}
- return fValue;
+ return this.value;
}
@Override
@@ -415,19 +416,19 @@
public void setPrimary(final int color) {
switch (color) {
case RED:
- fCurrentPrim = RED;
- fCurrentRectX = GREEN;
- fCurrentRectY = BLUE;
+ this.currentPrim= RED;
+ this.currentRectX= GREEN;
+ this.currentRectY= BLUE;
break;
case GREEN:
- fCurrentPrim = GREEN;
- fCurrentRectX = BLUE;
- fCurrentRectY = RED;
+ this.currentPrim= GREEN;
+ this.currentRectX= BLUE;
+ this.currentRectY= RED;
break;
case BLUE:
- fCurrentPrim = BLUE;
- fCurrentRectX = RED;
- fCurrentRectY = GREEN;
+ this.currentPrim= BLUE;
+ this.currentRectX= RED;
+ this.currentRectY= GREEN;
break;
default:
throw new IllegalArgumentException();
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/WaScale.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/WaScale.java
index eb3334e..b7f3480 100644
--- a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/WaScale.java
+++ b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/components/WaScale.java
@@ -41,6 +41,7 @@
import org.eclipse.statet.jcommons.collections.ImCollections;
import org.eclipse.statet.ecommons.collections.FastList;
+import org.eclipse.statet.ecommons.ui.swt.ColorUtils;
import org.eclipse.statet.internal.ecommons.ui.UIMiscellanyPlugin;
@@ -684,11 +685,8 @@
Color color;
final Display display = getDisplay();
if (focus) {
- final RGB color1 = getBackground().getRGB();
- final RGB color2 = display.getSystemColor(SWT.COLOR_LIST_SELECTION).getRGB();
- final RGB rgb = new RGB((color1.red + color2.red) / 2,
- (color1.green + color2.green) / 2, (color1.blue + color2.blue) / 2);
- color = UIMiscellanyPlugin.getInstance().getColorManager().getColor(rgb);
+ color= ColorUtils.blend(getBackground(),
+ display.getSystemColor(SWT.COLOR_LIST_SELECTION), 0.5f );
}
else {
color = display.getSystemColor(SWT.COLOR_GRAY);
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/dialogs/ToolPopup.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/dialogs/ToolPopup.java
index 9d1305e..e03eb39 100644
--- a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/dialogs/ToolPopup.java
+++ b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/dialogs/ToolPopup.java
@@ -41,7 +41,6 @@
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.statet.ecommons.ui.SharedUIResources;
import org.eclipse.statet.ecommons.ui.util.LayoutUtils;
import org.eclipse.statet.ecommons.ui.util.UIAccess;
@@ -49,16 +48,13 @@
public class ToolPopup {
- private static final Color G_BACKGROUND = SharedUIResources.getColors().getColor(SharedUIResources.GRAPHICS_BACKGROUND_COLOR_ID);
-
-
private class SWTListener implements Listener {
@Override
public void handleEvent(final Event event) {
switch (event.type) {
case SWT.Deactivate:
- if (fIgnoreActivation == 0) {
+ if (ToolPopup.this.ignoreActivation == 0) {
close();
}
return;
@@ -66,17 +62,17 @@
dispose();
return;
case SWT.Selection:
- if (event.widget == fOKButton) {
+ if (event.widget == ToolPopup.this.okButton) {
onOK();
close();
return;
}
- if (event.widget == fCancelButton) {
+ if (event.widget == ToolPopup.this.cancelButton) {
close();
return;
}
- if (event.widget == fTabFolder) {
- tabSelected(getTab(fTabFolder.getSelection()));
+ if (event.widget == ToolPopup.this.tabFolder) {
+ tabSelected(getTab(ToolPopup.this.tabFolder.getSelection()));
return;
}
}
@@ -87,35 +83,35 @@
public static class ToolTab {
- private final String fKey;
+ private final String key;
- private final ToolPopup fParent;
- private final CTabItem fTabItem;
- private Composite fComposite;
+ private final ToolPopup parent;
+ private final CTabItem tabItem;
+ private Composite composite;
public ToolTab(final String key, final ToolPopup parent,
final String name, final String tooltip) {
- fKey = key;
- fParent = parent;
- fTabItem = new CTabItem(parent.fTabFolder, SWT.NONE);
- fTabItem.setText(name);
- fTabItem.setToolTipText(tooltip);
- parent.fToolTabs.add(this);
+ this.key= key;
+ this.parent= parent;
+ this.tabItem= new CTabItem(parent.tabFolder, SWT.NONE);
+ this.tabItem.setText(name);
+ this.tabItem.setToolTipText(tooltip);
+ parent.toolTabs.add(this);
}
public ToolPopup getParent() {
- return fParent;
+ return this.parent;
}
public CTabItem getTabItem() {
- return fTabItem;
+ return this.tabItem;
}
protected Composite create() {
- final Composite composite = new Composite(fParent.getTabFolder(), SWT.NONE);
- fTabItem.setControl(composite);
- composite.setBackground(G_BACKGROUND);
+ final Composite composite= new Composite(this.parent.getTabFolder(), SWT.NONE);
+ this.tabItem.setControl(composite);
+ composite.setBackground(getParent().getGraphicBackgroundColor());
return composite;
}
@@ -123,8 +119,8 @@
}
protected void performOK() {
- fParent.onOK();
- fParent.close();
+ this.parent.onOK();
+ this.parent.close();
}
}
@@ -132,7 +128,7 @@
protected static abstract class PreviewCanvas extends Canvas implements PaintListener {
- private static final int DEFAULT_WIDTH = 50;
+ private static final int DEFAULT_WIDTH= 50;
public PreviewCanvas(final Composite parent) {
@@ -144,13 +140,13 @@
@Override
public void paintControl(final PaintEvent e) {
- final GC gc = e.gc;
+ final GC gc= e.gc;
gc.setForeground(e.display.getSystemColor(SWT.COLOR_DARK_GRAY));
- final Rectangle size = getClientArea();
- final int width = Math.min(DEFAULT_WIDTH, size.width / 2);
- final int height = size.height - 7;
- final int x0 = size.x;
- final int y0 = size.y + (size.height - height) / 2;
+ final Rectangle size= getClientArea();
+ final int width= Math.min(DEFAULT_WIDTH, size.width / 2);
+ final int height= size.height - 7;
+ final int x0= size.x;
+ final int y0= size.y + (size.height - height) / 2;
gc.drawRectangle(x0, y0, width, height);
gc.drawRectangle(x0 + width, y0, width, height);
@@ -165,11 +161,11 @@
@Override
public Point computeSize(final int wHint, final int hHint, final boolean changed) {
- int width = 1 + DEFAULT_WIDTH * 2;
+ int width= 1 + DEFAULT_WIDTH * 2;
if (wHint != -1 && wHint < width) {
- width = Math.max(width / 2, wHint);
+ width= Math.max(width / 2, wHint);
}
- final int height = (hHint != -1) ? hHint : (4 + LayoutUtils.defaultHSpacing());
+ final int height= (hHint != -1) ? hHint : (4 + LayoutUtils.defaultHSpacing());
return new Point(width, height);
}
@@ -179,16 +175,18 @@
}
- private Shell fShell;
+ private Shell shell;
- private CTabFolder fTabFolder;
+ private CTabFolder tabFolder;
- private Button fOKButton;
- private Button fCancelButton;
+ private Button okButton;
+ private Button cancelButton;
- private final List<ToolTab> fToolTabs= new ArrayList<>();
+ private final List<ToolTab> toolTabs= new ArrayList<>();
- private int fIgnoreActivation;
+ private int ignoreActivation;
+
+ private Color graphicBackgroundColor;
public ToolPopup() {
@@ -198,132 +196,138 @@
protected void open(final Shell parent, final Rectangle position) {
create(parent);
- final Point size = fShell.getSize();
- final Display display = fShell.getDisplay();
- final Monitor monitor = DialogUtils.getClosestMonitor(display, position);
- final Rectangle clientArea = monitor.getClientArea();
+ final Point size= this.shell.getSize();
+ final Display display= this.shell.getDisplay();
+ final Monitor monitor= DialogUtils.getClosestMonitor(display, position);
+ final Rectangle clientArea= monitor.getClientArea();
- final Rectangle bounds = new Rectangle(position.x , position.y - size.y, size.x, size.y);
+ final Rectangle bounds= new Rectangle(position.x , position.y - size.y, size.x, size.y);
if (bounds.y < 0) {
- bounds.y = position.y + position.height;
+ bounds.y= position.y + position.height;
}
Geometry.moveInside(bounds, clientArea);
- fShell.setBounds(bounds);
+ this.shell.setBounds(bounds);
selectTab(getBestTab());
- fShell.open();
+ this.shell.open();
}
public boolean isActive() {
- return (UIAccess.isOkToUse(fShell) && fShell.isVisible());
+ return (UIAccess.isOkToUse(this.shell) && this.shell.isVisible());
}
public void close() {
- if (UIAccess.isOkToUse(fShell)) {
- fShell.close();
+ if (UIAccess.isOkToUse(this.shell)) {
+ this.shell.close();
}
dispose();
}
public void dispose() {
- if (fShell != null) {
- if (!fShell.isDisposed()) {
- fShell.dispose();
+ if (this.shell != null) {
+ if (!this.shell.isDisposed()) {
+ this.shell.dispose();
}
onDispose();
- fShell = null;
+ this.shell= null;
}
}
private void create(final Shell parent) {
- if (UIAccess.isOkToUse(fShell)) {
- if (fShell.getParent() == parent) {
+ if (UIAccess.isOkToUse(this.shell)) {
+ if (this.shell.getParent() == parent) {
return;
}
dispose();
}
- fToolTabs.clear();
+ this.toolTabs.clear();
- fShell = new Shell(parent, SWT.ON_TOP | SWT.TOOL); // SWT.RESIZE
- fShell.setText("Color");
- fShell.setFont(JFaceResources.getDialogFont());
- fShell.setSize(320, 300);
+ this.shell= new Shell(parent, SWT.ON_TOP | SWT.TOOL); // SWT.RESIZE
+ this.shell.setText("Color");
+ this.shell.setFont(JFaceResources.getDialogFont());
+ this.shell.setSize(320, 300);
- { final GridLayout gl = new GridLayout();
- gl.marginHeight = 0;
- gl.marginWidth = 0;
- gl.horizontalSpacing = 0;
- gl.verticalSpacing = 0;
- fShell.setLayout(gl);
+ { final GridLayout gl= new GridLayout();
+ gl.marginHeight= 0;
+ gl.marginWidth= 0;
+ gl.horizontalSpacing= 0;
+ gl.verticalSpacing= 0;
+ this.shell.setLayout(gl);
}
- final SWTListener listener = new SWTListener();
+ final SWTListener listener= new SWTListener();
parent.addListener(SWT.Dispose, listener);
- fShell.addListener(SWT.Deactivate, listener);
+ this.shell.addListener(SWT.Deactivate, listener);
- fShell.setBackground(fShell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
- fShell.setBackgroundMode(SWT.INHERIT_FORCE);
+ this.shell.setBackground(this.shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ this.shell.setBackgroundMode(SWT.INHERIT_FORCE);
- fTabFolder = new CTabFolder(fShell, SWT.BOTTOM | SWT.FLAT);
- fTabFolder.setSimple(true);
- fTabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- fTabFolder.setSelectionBackground(G_BACKGROUND);
+ this.graphicBackgroundColor= this.shell.getDisplay().getSystemColor(SWT.COLOR_GRAY);
- addTabs(fTabFolder);
+ this.tabFolder= new CTabFolder(this.shell, SWT.BOTTOM | SWT.FLAT);
+ this.tabFolder.setSimple(true);
+ this.tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ this.tabFolder.setSelectionBackground(this.graphicBackgroundColor);
- final Composite commonBar = new Composite(fShell, SWT.NONE);
+ addTabs(this.tabFolder);
+
+ final Composite commonBar= new Composite(this.shell, SWT.NONE);
commonBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
commonBar.setLayout(LayoutUtils.newContentGrid(3));
-// final Composite status = new Composite(commonBar, SWT.NONE);
+// final Composite status= new Composite(commonBar, SWT.NONE);
// status.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
addStatusControls(commonBar);
- fOKButton = new Button(commonBar, SWT.PUSH | SWT.FLAT);
- fOKButton.setText(IDialogConstants.OK_LABEL);
- fOKButton.setFont(fShell.getFont());
- fOKButton.addListener(SWT.Selection, listener);
+ this.okButton= new Button(commonBar, SWT.PUSH | SWT.FLAT);
+ this.okButton.setText(IDialogConstants.OK_LABEL);
+ this.okButton.setFont(this.shell.getFont());
+ this.okButton.addListener(SWT.Selection, listener);
- fCancelButton = new Button(commonBar, SWT.PUSH | SWT.FLAT);
- fCancelButton.setText(IDialogConstants.CANCEL_LABEL);
- fCancelButton.setFont(fShell.getFont());
- fCancelButton.addListener(SWT.Selection, listener);
+ this.cancelButton= new Button(commonBar, SWT.PUSH | SWT.FLAT);
+ this.cancelButton.setText(IDialogConstants.CANCEL_LABEL);
+ this.cancelButton.setFont(this.shell.getFont());
+ this.cancelButton.addListener(SWT.Selection, listener);
- { final Point size = fOKButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
- size.x = Math.max(size.x, fCancelButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
- { final GridData gd = new GridData(SWT.FILL, SWT.FILL);
- gd.widthHint = size.x;
- gd.heightHint = size.y - 2;
- fOKButton.setLayoutData(gd);
+ { final Point size= this.okButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
+ size.x= Math.max(size.x, this.cancelButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
+ { final GridData gd= new GridData(SWT.FILL, SWT.FILL);
+ gd.widthHint= size.x;
+ gd.heightHint= size.y - 2;
+ this.okButton.setLayoutData(gd);
}
- { final GridData gd = new GridData(SWT.FILL, SWT.FILL);
- gd.widthHint = size.x;
- gd.heightHint = size.y - 2;
- fCancelButton.setLayoutData(gd);
+ { final GridData gd= new GridData(SWT.FILL, SWT.FILL);
+ gd.widthHint= size.x;
+ gd.heightHint= size.y - 2;
+ this.cancelButton.setLayoutData(gd);
}
}
- fTabFolder.addListener(SWT.Selection, listener);
- fShell.setDefaultButton(fOKButton);
+ this.tabFolder.addListener(SWT.Selection, listener);
+ this.shell.setDefaultButton(this.okButton);
- fShell.pack();
+ this.shell.pack();
}
public Shell getShell() {
- return fShell;
+ return this.shell;
+ }
+
+ public Color getGraphicBackgroundColor() {
+ return this.graphicBackgroundColor;
}
protected CTabFolder getTabFolder() {
- return fTabFolder;
+ return this.tabFolder;
}
protected ToolTab getTab(final String key) {
- for (final ToolTab tab : fToolTabs) {
- if (tab.fKey == key) {
+ for (final ToolTab tab : this.toolTabs) {
+ if (tab.key == key) {
return tab;
}
}
@@ -331,8 +335,8 @@
}
protected ToolTab getTab(final CTabItem item) {
- for (final ToolTab tab : fToolTabs) {
- if (tab.fTabItem == item) {
+ for (final ToolTab tab : this.toolTabs) {
+ if (tab.tabItem == item) {
return tab;
}
}
@@ -351,17 +355,17 @@
protected void selectTab(final ToolTab tab) {
if (tab != null) {
- final CTabItem tabItem = tab.getTabItem();
- fTabFolder.setSelection(tabItem);
+ final CTabItem tabItem= tab.getTabItem();
+ this.tabFolder.setSelection(tabItem);
tabSelected(tab);
- final Display display = fShell.getDisplay();
- final Control focusControl = display.getFocusControl();
+ final Display display= this.shell.getDisplay();
+ final Control focusControl= display.getFocusControl();
display.asyncExec(new Runnable() {
@Override
public void run() {
- if (UIAccess.isOkToUse(fTabFolder)
- && fTabFolder.getSelection() == tabItem
+ if (UIAccess.isOkToUse(ToolPopup.this.tabFolder)
+ && ToolPopup.this.tabFolder.getSelection() == tabItem
&& display.getFocusControl() == focusControl) {
tabItem.getControl().setFocus();
}
@@ -378,16 +382,16 @@
}
public void beginIgnoreActivation() {
- fIgnoreActivation++;
+ this.ignoreActivation++;
}
public void endIgnoreActivation() {
- fIgnoreActivation--;
+ this.ignoreActivation--;
}
protected void onDispose() {
- fTabFolder = null;
- fToolTabs.clear();
+ this.tabFolder= null;
+ this.toolTabs.clear();
}
protected void onOK() {
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/swt/ColorUtils.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/swt/ColorUtils.java
new file mode 100644
index 0000000..7b911d2
--- /dev/null
+++ b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/swt/ColorUtils.java
@@ -0,0 +1,66 @@
+/*=============================================================================#
+ # Copyright (c) 2021 Stephan Wahlbrink and others.
+ #
+ # This program and the accompanying materials are made available under the
+ # terms of the Eclipse Public License 2.0 which is available at
+ # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
+ # which is available at https://www.apache.org/licenses/LICENSE-2.0.
+ #
+ # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
+ #
+ # Contributors:
+ # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
+ #=============================================================================*/
+
+package org.eclipse.statet.ecommons.ui.swt;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+
+import org.eclipse.statet.jcommons.lang.NonNullByDefault;
+
+
+@NonNullByDefault
+public class ColorUtils {
+
+
+ private static int blend(final int v1, final int v2, final float ratio) {
+ final int b= Math.round(ratio * v1 + (1 - ratio) * v2);
+ return Math.min(255, b);
+ }
+
+ /**
+ * Blends the two colors according to the specified ratio.
+ *
+ * @param c1 the first color
+ * @param c2 the second color
+ * @param ratio of the first color in the blend (0-1)
+ * @return the RGB value of the blended color
+ */
+ public static RGB blend(final RGB c1, final RGB c2, final float ratio) {
+ return new RGB(
+ blend(c1.red, c2.red, ratio),
+ blend(c1.green, c2.green, ratio),
+ blend(c1.blue, c2.blue, ratio) );
+ }
+
+ /**
+ * Blends the two colors according to the specified ratio.
+ *
+ * @param c1 the first color
+ * @param c2 the second color
+ * @param ratio of the first color in the blend (0-1)
+ * @return the blended color
+ */
+ public static Color blend(final Color c1, final Color c2, final float ratio) {
+ return new Color(
+ blend(c1.getRed(), c2.getRed(), ratio),
+ blend(c1.getGreen(), c2.getGreen(), ratio),
+ blend(c1.getBlue(), c2.getBlue(), ratio) );
+ }
+
+
+ private ColorUtils() {
+ }
+
+}
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/util/UIAccess.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/util/UIAccess.java
index 13f3692..f4e36fc 100644
--- a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/util/UIAccess.java
+++ b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/util/UIAccess.java
@@ -21,8 +21,6 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
@@ -33,8 +31,6 @@
import org.eclipse.statet.jcommons.lang.NonNullByDefault;
-import org.eclipse.statet.ecommons.ui.ColorManager;
-
/**
* Access to UI resources from other threads.
@@ -114,18 +110,6 @@
return null;
}
- public static Color getColor(final ColorManager colorManager, final RGB rgb) {
- final AtomicReference<Color> colorRef= new AtomicReference<>();
- getDisplay().syncExec(new Runnable() {
-
- @Override
- public void run() {
- colorRef.set(colorManager.getColor(rgb));
- }
- });
- return colorRef.get();
- }
-
public static interface CheckedRunnable {
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/viewers/breadcrumb/BreadcrumbViewer.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/viewers/breadcrumb/BreadcrumbViewer.java
index ce6cf85..f0dad6f 100644
--- a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/viewers/breadcrumb/BreadcrumbViewer.java
+++ b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/ecommons/ui/viewers/breadcrumb/BreadcrumbViewer.java
@@ -43,7 +43,6 @@
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
@@ -54,6 +53,8 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Widget;
+import org.eclipse.statet.ecommons.ui.swt.ColorUtils;
+
/**
* A breadcrumb viewer shows a the parent chain of its input element in a list. Each breadcrumb item
@@ -71,40 +72,6 @@
private static final boolean IS_GTK= "gtk".equals(SWT.getPlatform()); //$NON-NLS-1$
- /**
- * Tests the source RGB for range.
- *
- * COPY OF: org.eclipse.ui.forms.FormColors
- *
- * @param rgb the tested RGB
- * @param from range start (excluding the value itself)
- * @param to tange end (excluding the value itself)
- * @return <code>true</code> if at least two of the primary colors in the
- * source RGB are within the provided range, <code>false</code>
- * otherwise.
- */
- static RGB blend(final RGB c1, final RGB c2, final int ratio) {
- final int r= blend(c1.red, c2.red, ratio);
- final int g= blend(c1.green, c2.green, ratio);
- final int b= blend(c1.blue, c2.blue, ratio);
- return new RGB(r, g, b);
- }
-
- /**
- * Blends two primary color components based on the provided ratio.
- *
- * COPY OF: org.eclipse.ui.forms.FormColors
- *
- * @param v1 first component
- * @param v2 second component
- * @param ratio percentage of the first component in the blend
- * @return
- */
- private static int blend(final int v1, final int v2, final int ratio) {
- final int b= (ratio * v1 + (100 - ratio) * v2) / 100;
- return Math.min(255, b);
- }
-
private final Composite container;
@@ -802,12 +769,12 @@
final GC gc= new GC(result);
- final Color colorC= createColor(SWT.COLOR_WIDGET_BACKGROUND, SWT.COLOR_LIST_BACKGROUND, 35, display);
- final Color colorD= createColor(SWT.COLOR_WIDGET_BACKGROUND, SWT.COLOR_LIST_BACKGROUND, 45, display);
- final Color colorE= createColor(SWT.COLOR_WIDGET_BACKGROUND, SWT.COLOR_LIST_BACKGROUND, 80, display);
- final Color colorF= createColor(SWT.COLOR_WIDGET_BACKGROUND, SWT.COLOR_LIST_BACKGROUND, 70, display);
- final Color colorG= createColor(SWT.COLOR_WIDGET_BACKGROUND, SWT.COLOR_WHITE, 45, display);
- final Color colorH= createColor(SWT.COLOR_WIDGET_NORMAL_SHADOW, SWT.COLOR_LIST_BACKGROUND, 35, display);
+ final Color colorC= createColor(SWT.COLOR_WIDGET_BACKGROUND, SWT.COLOR_LIST_BACKGROUND, 0.35f, display);
+ final Color colorD= createColor(SWT.COLOR_WIDGET_BACKGROUND, SWT.COLOR_LIST_BACKGROUND, 0.45f, display);
+ final Color colorE= createColor(SWT.COLOR_WIDGET_BACKGROUND, SWT.COLOR_LIST_BACKGROUND, 0.80f, display);
+ final Color colorF= createColor(SWT.COLOR_WIDGET_BACKGROUND, SWT.COLOR_LIST_BACKGROUND, 0.70f, display);
+ final Color colorG= createColor(SWT.COLOR_WIDGET_BACKGROUND, SWT.COLOR_WHITE, 0.45f, display);
+ final Color colorH= createColor(SWT.COLOR_WIDGET_NORMAL_SHADOW, SWT.COLOR_LIST_BACKGROUND, 0.35f, display);
try {
drawLine(width, 0, colorC, gc);
@@ -824,15 +791,9 @@
drawLine(width, height - 2, colorG, gc);
drawLine(width, height - 1, colorH, gc);
- } finally {
+ }
+ finally {
gc.dispose();
-
- colorC.dispose();
- colorD.dispose();
- colorE.dispose();
- colorF.dispose();
- colorG.dispose();
- colorH.dispose();
}
return result;
@@ -843,13 +804,9 @@
gc.drawLine(0, position, width, position);
}
- private Color createColor(final int color1, final int color2, final int ratio, final Display display) {
- final RGB rgb1= display.getSystemColor(color1).getRGB();
- final RGB rgb2= display.getSystemColor(color2).getRGB();
-
- final RGB blend= blend(rgb2, rgb1, ratio);
-
- return new Color(display, blend);
+ private Color createColor(final int color1, final int color2, final float ratio,
+ final Display display) {
+ return ColorUtils.blend(display.getSystemColor(color2), display.getSystemColor(color1), ratio);
}
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/internal/ecommons/ui/AccessibleArrowImage.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/internal/ecommons/ui/AccessibleArrowImage.java
index 1086e2d..1c362ab 100644
--- a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/internal/ecommons/ui/AccessibleArrowImage.java
+++ b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/internal/ecommons/ui/AccessibleArrowImage.java
@@ -21,7 +21,8 @@
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.themes.ColorUtil;
+
+import org.eclipse.statet.ecommons.ui.swt.ColorUtils;
/**
@@ -77,9 +78,9 @@
final ImageData imageData= image.getImageData();
final int foreground = imageData.palette.getPixel(
- ColorUtil.blend(fForegroundColor, fBackgroundColor, 80) );
+ ColorUtils.blend(fForegroundColor, fBackgroundColor, 0.80f) );
final int aliasing = imageData.palette.getPixel(
- ColorUtil.blend(fForegroundColor, fBackgroundColor, 60) );
+ ColorUtils.blend(fForegroundColor, fBackgroundColor, 0.60f) );
final int size1 = fSize - 1;
int xOffset = 0;
diff --git a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/internal/ecommons/ui/UIMiscellanyPlugin.java b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/internal/ecommons/ui/UIMiscellanyPlugin.java
index 7618bd3..259ca37 100644
--- a/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/internal/ecommons/ui/UIMiscellanyPlugin.java
+++ b/ecommons/org.eclipse.statet.ecommons.uimisc/src/org/eclipse/statet/internal/ecommons/ui/UIMiscellanyPlugin.java
@@ -29,13 +29,11 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.PaletteData;
-import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.statet.jcommons.lang.Disposable;
-import org.eclipse.statet.ecommons.ui.ColorManager;
import org.eclipse.statet.ecommons.ui.SharedUIResources;
import org.eclipse.statet.ecommons.ui.util.ImageDescriptorRegistry;
import org.eclipse.statet.ecommons.ui.util.ImageRegistryUtil;
@@ -75,7 +73,6 @@
private final List<Disposable> disposables= new ArrayList<>();
- private ColorManager colorManager;
private ImageDescriptorRegistry imageDescriptorRegistry;
@@ -97,29 +94,12 @@
@Override
public void stop(final BundleContext context) throws Exception {
try {
- final ColorManager colorManager;
synchronized (this) {
this.started = false;
- colorManager = this.colorManager;
- this.colorManager = null;
this.imageDescriptorRegistry = null;
}
- final Display display = UIAccess.getDisplay();
- if (display != null && !display.isDisposed()) {
- display.asyncExec(new Runnable() {
- @Override
- public void run() {
- if (colorManager != null) {
- try {
- colorManager.dispose();
- }
- catch (final Exception e) {}
- }
- }
- });
- }
for (final Disposable listener : this.disposables) {
try {
listener.dispose();
@@ -232,8 +212,8 @@
final Color border = display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
final Color background = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
- final Color hotRed = new Color(display, new RGB(252, 160, 160));
- final Color hotYellow = new Color(display, new RGB(252, 232, 160));
+ final Color hotRed = new Color(252, 160, 160);
+ final Color hotYellow = new Color(252, 232, 160);
final Color transparent = display.getSystemColor(SWT.COLOR_MAGENTA);
final PaletteData palette = new PaletteData(transparent.getRGB(),
@@ -367,43 +347,10 @@
reg.put(SharedUIResources.LOCTOOL_DOWN_H_IMAGE_ID, image);
}
-
- hotRed.dispose();
- hotYellow.dispose();
}
});
}
-
- public synchronized ColorManager getColorManager() {
- if (this.colorManager == null) {
- if (!this.started) {
- throw new IllegalStateException("Plug-in is not started.");
- }
- this.colorManager = createColorManager();
- }
- return this.colorManager;
- }
-
- private ColorManager createColorManager() {
- final ColorManager manager = new ColorManager();
- final Display display = Display.getDefault();
- final Runnable runnable = new Runnable() {
- @Override
- public void run() {
- final Color color = display.getSystemColor(SWT.COLOR_GRAY);
- manager.bindColor(SharedUIResources.GRAPHICS_BACKGROUND_COLOR_ID, color.getRGB());
- }
- };
- if (display.getThread() == Thread.currentThread()) {
- runnable.run();
- }
- else {
- display.asyncExec(runnable);
- }
- return manager;
- }
-
public synchronized ImageDescriptorRegistry getImageDescriptorRegistry() {
if (this.imageDescriptorRegistry == null) {
if (!this.started) {