use of org.eclipse.swt.events.PaintEvent in project eclipse.platform.releng by eclipse.
the class ConfigurationBlock method highlight.
protected void highlight(final Composite parent, final Label labelControl, final Combo comboBox, final int color) {
class HighlightPainter implements PaintListener {
private int fColor = color;
@Override
public void paintControl(PaintEvent e) {
if (((GridData) labelControl.getLayoutData()).exclude) {
parent.removePaintListener(this);
labelControl.setData(null);
return;
}
int GAP = 7;
int ARROW = 3;
Rectangle l = labelControl.getBounds();
Point c = comboBox.getLocation();
e.gc.setForeground(e.display.getSystemColor(fColor));
int x2 = c.x - GAP;
int y = l.y + l.height / 2 + 1;
e.gc.drawLine(l.x + l.width + GAP, y, x2, y);
e.gc.drawLine(x2 - ARROW, y - ARROW, x2, y);
e.gc.drawLine(x2 - ARROW, y + ARROW, x2, y);
}
}
Object data = labelControl.getData();
if (data == null) {
if (color != HIGHLIGHT_NONE) {
PaintListener painter = new HighlightPainter();
parent.addPaintListener(painter);
labelControl.setData(painter);
} else {
return;
}
} else {
if (color == HIGHLIGHT_NONE) {
parent.removePaintListener((PaintListener) data);
labelControl.setData(null);
} else if (color != ((HighlightPainter) data).fColor) {
((HighlightPainter) data).fColor = color;
} else {
return;
}
}
parent.redraw();
parent.update();
}
use of org.eclipse.swt.events.PaintEvent in project polymap4-core by Polymap4.
the class ColorChooser method drawColorBoxMarker.
private void drawColorBoxMarker(Composite panelBody, int x, int y) {
int adjustedX = x - 10;
if (adjustedX < 0) {
adjustedX = 0;
}
int adjustedY = y - 10;
if (adjustedY < 0) {
adjustedY = 0;
}
colorBoxMarker.setBounds(adjustedX, adjustedY, 20, 20);
colorBoxMarker.setForeground(panelBody.getDisplay().getSystemColor(SWT.COLOR_WHITE));
colorBoxMarker.setBackground(null);
colorBoxMarker.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
e.gc.setForeground(panelBody.getDisplay().getSystemColor(SWT.COLOR_BLACK));
e.gc.drawOval(1, 1, 18, 18);
e.gc.setForeground(panelBody.getDisplay().getSystemColor(SWT.COLOR_WHITE));
e.gc.drawOval(2, 2, 16, 16);
e.gc.drawOval(3, 3, 14, 14);
e.gc.setForeground(panelBody.getDisplay().getSystemColor(SWT.COLOR_BLACK));
e.gc.drawOval(4, 4, 12, 12);
}
});
}
use of org.eclipse.swt.events.PaintEvent in project polymap4-core by Polymap4.
the class ColorChooser method setColorBoxColor.
private void setColorBoxColor(Composite panelBody, RGB rgb) {
Integer[][] colorBoxColors = new Integer[COLORBOX_WIDTH][COLORBOX_HEIGHT];
if (rgb == null) {
rgb = getDefaultRGB();
}
Color color = new Color(panelBody.getDisplay(), rgb);
float[] hsb = new float[3];
java.awt.Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb);
int rgbValue;
float saturationFilter = hsb[1] == 0.0 ? 0.0f : 1.0f;
float newS, newB;
BufferedImage bi = new BufferedImage(COLORBOX_WIDTH, COLORBOX_HEIGHT, BufferedImage.TYPE_INT_RGB);
boolean markerSet = false;
int markerPosX = 0, markerPosY = 0;
for (int w = 0; w < COLORBOX_WIDTH; w += 1) {
for (int h = COLORBOX_HEIGHT - 1; h >= 0; h -= 1) {
newS = saturationFilter * Double.valueOf((double) w / COLORBOX_WIDTH).floatValue();
newB = Double.valueOf((double) h / COLORBOX_HEIGHT).floatValue();
rgbValue = java.awt.Color.HSBtoRGB(hsb[0], newS, newB);
colorBoxColors[w][h] = rgbValue;
if (!markerSet && Math.abs(newS - hsb[1]) <= 0.01 && Math.abs(newB - hsb[2]) <= 0.01) {
if (colorBox.getBounds().contains(w, h)) {
markerPosX = w;
markerPosY = h;
markerSet = true;
}
}
bi.setRGB(w, h, rgbValue);
}
}
final PaletteData palette = new PaletteData(0xff0000, 0xff00, 0xff);
DataBuffer dataBuffer = bi.getData().getDataBuffer();
int[] data = ((DataBufferInt) dataBuffer).getData();
ImageData imageData = new ImageData(bi.getWidth(), bi.getHeight(), 24, palette);
imageData.setPixels(0, 0, data.length, data, 0);
if (colorBoxImage != null) {
colorBoxImage.dispose();
}
colorBoxImage = new Image(Display.getDefault(), imageData);
GC gc = new GC(colorBox);
gc.drawImage(colorBoxImage, 0, 0);
gc.dispose();
int finalMarkerPosX = markerPosX, finalMarkerPosY = markerPosY;
colorBoxMarker.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
drawColorBoxMarker(panelBody, finalMarkerPosX, finalMarkerPosY);
}
});
}
use of org.eclipse.swt.events.PaintEvent in project netxms by netxms.
the class ServiceAvailability method createPartControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
final Composite clientArea = new Composite(parent, SWT.NONE);
colors = new ColorCache(clientArea);
GridLayout layout = new GridLayout();
layout.numColumns = 4;
clientArea.setLayout(layout);
dayChart = createChart(clientArea, Messages.get().ServiceAvailability_Today);
weekChart = createChart(clientArea, Messages.get().ServiceAvailability_ThisWeek);
monthChart = createChart(clientArea, Messages.get().ServiceAvailability_ThisMonth);
Canvas legend = new Canvas(clientArea, SWT.NONE);
legend.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
paintLegend(e.gc);
}
});
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
legend.setLayoutData(gd);
listener = new SessionListener() {
@Override
public void notificationHandler(final SessionNotification n) {
if (!clientArea.isDisposed() && (n.getCode() == SessionNotification.OBJECT_CHANGED) && (n.getSubCode() == object.getObjectId())) {
clientArea.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
object = (ServiceContainer) n.getObject();
refresh();
}
});
}
}
};
ConsoleSharedData.getSession().addListener(listener);
}
use of org.eclipse.swt.events.PaintEvent in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class ASTWidget method setupCanvas.
private void setupCanvas() {
resizeCanvas();
canvas.setBackground(WHITE);
canvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(final PaintEvent e) {
if (lastControl != null) {
adjustView(lastControl);
}
if (root != null) {
root.visit(node -> {
if (node.data().getFirst().isVisible()) {
if (node.parent() != null) {
drawArrowFromParent(e.gc, node);
}
return NodeVisitor.AfterVisitBehaviour.Continue;
}
return NodeVisitor.AfterVisitBehaviour.Abort;
});
}
}
});
}
Aggregations