use of org.eclipse.swt.widgets.Canvas in project yamcs-studio by yamcs.
the class OPIColorDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
var parent_Composite = (Composite) super.createDialogArea(parent);
var mainComposite = new Composite(parent_Composite, SWT.None);
mainComposite.setLayout(new GridLayout(2, false));
var gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.heightHint = 300;
mainComposite.setLayoutData(gridData);
var leftComposite = new Composite(mainComposite, SWT.None);
leftComposite.setLayout(new GridLayout(1, false));
var gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.widthHint = 220;
leftComposite.setLayoutData(gd);
createLabel(leftComposite, "Choose from Predefined Colors:");
preDefinedColorsViewer = createPredefinedColorsTableViewer(leftComposite);
preDefinedColorsViewer.setInput(MediaService.getInstance().getAllPredefinedColors());
var rightComposite = new Composite(mainComposite, SWT.None);
rightComposite.setLayout(new GridLayout(1, false));
gd = new GridData(SWT.LEFT, SWT.BEGINNING, true, true);
rightComposite.setLayoutData(gd);
createLabel(rightComposite, "");
var colorDialogButton = new Button(rightComposite, SWT.PUSH);
colorDialogButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
colorDialogButton.setText("Choose from Color Dialog");
colorDialogButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
var dialog = new ColorDialog(Display.getCurrent().getActiveShell());
dialog.setRGB(opiColor.getRGBValue());
var rgb = dialog.open();
if (rgb != null) {
opiColor.setColorValue(rgb);
preDefinedColorsViewer.setSelection(null);
setRGBEditValue(rgb);
outputTextLabel.setText(opiColor.getColorName());
colorCanvas.setBackground(CustomMediaFactory.getInstance().getColor(opiColor.getRGBValue()));
}
}
});
createRGBEditGroup(rightComposite);
var group = new Group(rightComposite, SWT.None);
group.setLayoutData(new GridData(SWT.FILL, SWT.END, true, true));
group.setLayout(new GridLayout(3, false));
group.setText("Output");
colorCanvas = new Canvas(group, SWT.BORDER);
colorCanvas.setBackground(CustomMediaFactory.getInstance().getColor(opiColor.getRGBValue()));
gd = new GridData(SWT.LEFT, SWT.TOP, false, false);
gd.widthHint = 30;
gd.heightHint = 30;
colorCanvas.setLayoutData(gd);
outputTextLabel = new Label(group, SWT.None);
outputTextLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
outputTextLabel.setText(opiColor.getColorName());
if (opiColor.isPreDefined()) {
preDefinedColorsViewer.setSelection(new StructuredSelection(opiColor));
} else {
preDefinedColorsViewer.setSelection(null);
}
return parent_Composite;
}
use of org.eclipse.swt.widgets.Canvas in project dbeaver by dbeaver.
the class ERDOutlinePage method createControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createControl(Composite parent) {
// create canvas and lws
overview = new Canvas(parent, SWT.NONE);
LightweightSystem lws = new LightweightSystem(overview);
// create thumbnail
thumbnail = new ScrollableThumbnail((Viewport) rootEditPart.getFigure());
thumbnail.setBorder(new MarginBorder(3));
thumbnail.setSource(rootEditPart.getLayer(LayerConstants.PRINTABLE_LAYERS));
lws.setContents(thumbnail);
}
use of org.eclipse.swt.widgets.Canvas in project pentaho-kettle by pentaho.
the class JobMetricsDelegate method setupContent.
public void setupContent() {
if (metricsComposite.isDisposed()) {
return;
}
//
for (Control control : metricsComposite.getChildren()) {
if (!control.isDisposed()) {
control.dispose();
}
}
emptyGraph = false;
canvas = new Canvas(metricsComposite, SWT.NONE);
spoon.props.setLook(canvas);
FormData fdCanvas = new FormData();
fdCanvas.left = new FormAttachment(0, 0);
fdCanvas.right = new FormAttachment(100, 0);
fdCanvas.top = new FormAttachment(0, 0);
fdCanvas.bottom = new FormAttachment(100, 0);
canvas.setLayoutData(fdCanvas);
metricsComposite.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent event) {
updateGraph();
}
});
metricsComposite.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
if (image != null) {
image.dispose();
}
}
});
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
if (jobGraph.job != null && (jobGraph.job.isFinished() || jobGraph.job.isStopped())) {
refreshImage(event.gc);
if (!Const.isRunningOnWebspoonMode()) {
if (image != null && !image.isDisposed()) {
event.gc.drawImage(image, 0, 0);
}
}
} else {
Rectangle bounds = canvas.getBounds();
if (bounds.width <= 0 || bounds.height <= 0) {
return;
}
event.gc.setForeground(GUIResource.getInstance().getColorWhite());
event.gc.setBackground(GUIResource.getInstance().getColorWhite());
event.gc.fillRectangle(new Rectangle(0, 0, bounds.width, bounds.height));
event.gc.setForeground(GUIResource.getInstance().getColorBlack());
String metricsMessage = BaseMessages.getString(PKG, "JobMetricsDelegate.JobIsNotRunning.Message");
org.eclipse.swt.graphics.Point extent = event.gc.textExtent(metricsMessage);
event.gc.drawText(metricsMessage, (bounds.width - extent.x) / 2, (bounds.height - extent.y) / 2);
}
}
});
// Refresh automatically every 5 seconds as well.
//
final Timer timer = new Timer("JobMetricsDelegate Timer");
timer.schedule(new TimerTask() {
public void run() {
updateGraph();
}
}, 0, 5000);
// When the tab is closed, we remove the update timer
//
jobMetricsTab.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent arg0) {
timer.cancel();
}
});
if (Const.isRunningOnWebspoonMode()) {
// When the browser tab/window is closed, we remove the update timer
jobMetricsTab.getDisplay().disposeExec(new Runnable() {
@Override
public void run() {
timer.cancel();
}
});
}
// Show tool tips with details...
//
canvas.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent event) {
if (drawAreas == null) {
return;
}
for (int i = drawAreas.size() - 1; i >= 0; i--) {
MetricsDrawArea drawArea = drawAreas.get(i);
if (drawArea.getArea().contains(event.x, event.y)) {
MetricsDuration duration = drawArea.getDuration();
if (duration == null) {
continue;
}
System.out.println(duration.toString());
LoggingObjectInterface loggingObject = LoggingRegistry.getInstance().getLoggingObject(duration.getLogChannelId());
if (loggingObject == null) {
return;
}
System.out.println(loggingObject.getObjectType() + " : " + loggingObject.getObjectName());
}
}
}
});
canvas.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent arg0) {
// force a refresh
lastRefreshTime = 0;
}
});
}
use of org.eclipse.swt.widgets.Canvas in project pentaho-kettle by pentaho.
the class EnterPrintDialog method open.
public int open() {
Shell parent = getParent();
Display display = parent.getDisplay();
retval = SWT.OK;
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.SHEET | SWT.RESIZE | SWT.MAX | SWT.MIN);
props.setLook(shell);
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
shell.setText(BaseMessages.getString(PKG, "EnterPrintDialog.Title"));
int middle = props.getMiddlePct();
int margin = Const.MARGIN;
// Canvas
wlCanvas = new Label(shell, SWT.NONE);
wlCanvas.setText(BaseMessages.getString(PKG, "EnterPrintDialog.PrintArea.Label"));
props.setLook(wlCanvas);
fdlCanvas = new FormData();
fdlCanvas.left = new FormAttachment(0, 0);
fdlCanvas.top = new FormAttachment(0, margin);
wlCanvas.setLayoutData(fdlCanvas);
wCanvas = new Canvas(shell, SWT.BORDER);
props.setLook(wCanvas);
wCanvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent pe) {
repaint(pe.gc, pe.width, pe.height);
}
});
fdCanvas = new FormData();
fdCanvas.left = new FormAttachment(0, 0);
fdCanvas.top = new FormAttachment(wlCanvas, margin);
fdCanvas.right = new FormAttachment(100, 0);
fdCanvas.bottom = new FormAttachment(100, -220);
wCanvas.setLayoutData(fdCanvas);
// Rows
wlRows = new Label(shell, SWT.NONE);
wlRows.setText(BaseMessages.getString(PKG, "EnterPrintDialog.Rows.Label"));
props.setLook(wlRows);
fdlRows = new FormData();
fdlRows.left = new FormAttachment(0, 0);
fdlRows.right = new FormAttachment(middle, -margin);
fdlRows.top = new FormAttachment(wCanvas, margin);
wlRows.setLayoutData(fdlRows);
wRows = new Slider(shell, SWT.HORIZONTAL);
wRows.setIncrement(1);
wRows.setMinimum(1);
wRows.setMaximum(11);
wRows.setThumb(1);
wRows.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent se) {
Slider sl = (Slider) se.widget;
nrrows = sl.getSelection();
wCanvas.redraw();
}
});
props.setLook(wRows);
fdRows = new FormData();
fdRows.left = new FormAttachment(middle, 0);
fdRows.top = new FormAttachment(wCanvas, margin);
fdRows.right = new FormAttachment(100, 0);
wRows.setLayoutData(fdRows);
// Cols
wlCols = new Label(shell, SWT.NONE);
wlCols.setText(BaseMessages.getString(PKG, "EnterPrintDialog.Cols.Label"));
props.setLook(wlCols);
fdlCols = new FormData();
fdlCols.left = new FormAttachment(0, 0);
fdlCols.right = new FormAttachment(middle, -margin);
fdlCols.top = new FormAttachment(wRows, margin);
wlCols.setLayoutData(fdlCols);
wCols = new Slider(shell, SWT.HORIZONTAL);
wCols.setIncrement(1);
wCols.setMinimum(1);
wCols.setMaximum(11);
wCols.setThumb(1);
wCols.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent se) {
Slider sl = (Slider) se.widget;
nrcols = sl.getSelection();
wCanvas.redraw();
}
});
props.setLook(wCols);
fdCols = new FormData();
fdCols.left = new FormAttachment(middle, 0);
fdCols.top = new FormAttachment(wRows, margin);
fdCols.right = new FormAttachment(100, 0);
wCols.setLayoutData(fdCols);
// Scale
wlScale = new Label(shell, SWT.NONE);
wlScale.setText(BaseMessages.getString(PKG, "EnterPrintDialog.Scaling.Label"));
props.setLook(wlScale);
fdlScale = new FormData();
fdlScale.left = new FormAttachment(0, 0);
fdlScale.right = new FormAttachment(middle, -margin);
fdlScale.top = new FormAttachment(wCols, margin);
wlScale.setLayoutData(fdlScale);
wScale = new Slider(shell, SWT.HORIZONTAL);
wScale.setIncrement(10);
wScale.setMinimum(10);
wScale.setMaximum(500);
wScale.setThumb(10);
wScale.setPageIncrement(25);
wScale.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent se) {
Slider sl = (Slider) se.widget;
scale = sl.getSelection();
wCanvas.redraw();
}
});
props.setLook(wScale);
fdScale = new FormData();
fdScale.left = new FormAttachment(middle, 0);
fdScale.top = new FormAttachment(wCols, margin);
fdScale.right = new FormAttachment(100, 0);
wScale.setLayoutData(fdScale);
// Left
wlLeft = new Label(shell, SWT.NONE);
wlLeft.setText(BaseMessages.getString(PKG, "EnterPrintDialog.LeftMargin.Label"));
props.setLook(wlLeft);
fdlLeft = new FormData();
fdlLeft.left = new FormAttachment(0, 0);
fdlLeft.right = new FormAttachment(middle, -margin);
fdlLeft.top = new FormAttachment(wScale, margin);
wlLeft.setLayoutData(fdlLeft);
wLeft = new Text(shell, SWT.BORDER);
wLeft.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
Text w = (Text) e.widget;
leftMargin = Const.toDouble(w.getText(), 0.00);
}
});
props.setLook(wLeft);
fdLeft = new FormData();
fdLeft.left = new FormAttachment(middle, 0);
fdLeft.top = new FormAttachment(wScale, margin);
fdLeft.right = new FormAttachment(100, 0);
wLeft.setLayoutData(fdLeft);
// Right
wlRight = new Label(shell, SWT.NONE);
wlRight.setText(BaseMessages.getString(PKG, "EnterPrintDialog.RightMargin.Label"));
props.setLook(wlRight);
fdlRight = new FormData();
fdlRight.left = new FormAttachment(0, 0);
fdlRight.right = new FormAttachment(middle, -margin);
fdlRight.top = new FormAttachment(wLeft, margin);
wlRight.setLayoutData(fdlRight);
wRight = new Text(shell, SWT.BORDER);
wRight.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
Text w = (Text) e.widget;
rightMargin = Const.toDouble(w.getText(), 0.00);
}
});
props.setLook(wRight);
fdRight = new FormData();
fdRight.left = new FormAttachment(middle, 0);
fdRight.top = new FormAttachment(wLeft, margin);
fdRight.right = new FormAttachment(100, 0);
wRight.setLayoutData(fdRight);
// Top
wlTop = new Label(shell, SWT.NONE);
wlTop.setText(BaseMessages.getString(PKG, "EnterPrintDialog.TopMargin.Label"));
props.setLook(wlTop);
fdlTop = new FormData();
fdlTop.left = new FormAttachment(0, 0);
fdlTop.right = new FormAttachment(middle, -margin);
fdlTop.top = new FormAttachment(wRight, margin);
wlTop.setLayoutData(fdlTop);
wTop = new Text(shell, SWT.BORDER);
wTop.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
Text w = (Text) e.widget;
topMargin = Const.toDouble(w.getText(), 0.00);
}
});
props.setLook(wTop);
fdTop = new FormData();
fdTop.left = new FormAttachment(middle, 0);
fdTop.top = new FormAttachment(wRight, margin);
fdTop.right = new FormAttachment(100, 0);
wTop.setLayoutData(fdTop);
// Bottom
wlBottom = new Label(shell, SWT.NONE);
wlBottom.setText(BaseMessages.getString(PKG, "EnterPrintDialog.BottomMargin.Label"));
props.setLook(wlBottom);
fdlBottom = new FormData();
fdlBottom.left = new FormAttachment(0, 0);
fdlBottom.right = new FormAttachment(middle, -margin);
fdlBottom.top = new FormAttachment(wTop, margin);
wlBottom.setLayoutData(fdlBottom);
wBottom = new Text(shell, SWT.BORDER);
wBottom.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
Text w = (Text) e.widget;
bottomMargin = Const.toDouble(w.getText(), 0.00);
}
});
props.setLook(wBottom);
fdBottom = new FormData();
fdBottom.left = new FormAttachment(middle, 0);
fdBottom.top = new FormAttachment(wTop, margin);
fdBottom.right = new FormAttachment(100, 0);
wBottom.setLayoutData(fdBottom);
// Some buttons
wOK = new Button(shell, SWT.PUSH);
wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
fdOK = new FormData();
fdOK.left = new FormAttachment(33, 0);
fdOK.bottom = new FormAttachment(100, 0);
wOK.setLayoutData(fdOK);
fdCancel = new FormData();
fdCancel.left = new FormAttachment(66, 0);
fdCancel.bottom = new FormAttachment(100, 0);
wCancel.setLayoutData(fdCancel);
// Add listeners
lsCancel = new Listener() {
public void handleEvent(Event e) {
cancel();
}
};
lsOK = new Listener() {
public void handleEvent(Event e) {
ok();
}
};
wOK.addListener(SWT.Selection, lsOK);
wCancel.addListener(SWT.Selection, lsCancel);
// Detect [X] or ALT-F4 or something that kills this window...
shell.addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent e) {
cancel();
}
});
getData();
BaseStepDialog.setSize(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return retval;
}
use of org.eclipse.swt.widgets.Canvas in project pentaho-kettle by pentaho.
the class Sleak method create.
public void create(Composite parent) {
list = new List(parent, SWT.BORDER | SWT.V_SCROLL);
list.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
refreshObject();
}
});
text = new Text(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
canvas = new Canvas(parent, SWT.BORDER);
canvas.addListener(SWT.Paint, new Listener() {
public void handleEvent(Event event) {
paintCanvas(event);
}
});
check = new Button(parent, SWT.CHECK);
check.setText("Stack");
check.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
toggleStackTrace();
}
});
start = new Button(parent, SWT.PUSH);
start.setText("Snap");
start.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
refreshAll();
}
});
stop = new Button(parent, SWT.PUSH);
stop.setText("Diff");
stop.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
refreshDifference();
}
});
label = new Label(parent, SWT.BORDER);
label.setText("0 object(s)");
parent.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event e) {
layout();
}
});
check.setSelection(false);
text.setVisible(false);
layout();
}
Aggregations