use of org.eclipse.swt.events.PaintEvent in project watchdog by TestRoots.
the class EditorListener method listenToEditorScrolling.
private void listenToEditorScrolling() {
styledText = (StyledText) editor.getAdapter(Control.class);
if (styledText == null) {
return;
}
// creates a listener for when the user moves the caret (cursor)
caretListener = new CaretListener() {
@Override
public void caretMoved(CaretEvent event) {
WatchDogEventType.CARET_MOVED.process(editor);
// cursor place changed
}
};
styledText.addCaretListener(caretListener);
// creates a listener for redraws of the view, e.g. when scrolled
paintListener = new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
WatchDogEventType.PAINT.process(editor);
}
};
styledText.addPaintListener(paintListener);
focusListener = new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
}
@Override
public void focusGained(FocusEvent e) {
WatchDogEventType.ACTIVE_FOCUS.process(editor);
}
};
styledText.addFocusListener(focusListener);
}
use of org.eclipse.swt.events.PaintEvent in project hale by halestudio.
the class HaleSplash method init.
@Override
public void init(Shell splash) {
IProduct product = Platform.getProduct();
if (product != null) {
/*
* Using a custom property for the foreground color, because when
* using the one defined in IProductConstants, it is overriden when
* recreating a run configuration from the product.
*/
String foregroundColorString = product.getProperty(PRODUCT_PROP_SPLASH_FONT_COLOR);
int foregroundColorInteger;
try {
foregroundColorInteger = Integer.parseInt(foregroundColorString, 16);
} catch (Exception ex) {
// off white
foregroundColorInteger = 0xD2D7FF;
}
/*
* Foreground color will be overriden in super.init(...), that's why
* we have to set it in getContent() - store it here for later
* access.
*/
customFontColor = new RGB((foregroundColorInteger & 0xFF0000) >> 16, (foregroundColorInteger & 0xFF00) >> 8, foregroundColorInteger & 0xFF);
}
super.init(splash);
if (product != null) {
// get application version
Version haleVersion = Version.parseVersion(Display.getAppVersion());
// classified as development version if a qualifier other than
// RELEASE is given
boolean developmentVersion = haleVersion.getQualifier() != null && !haleVersion.getQualifier().isEmpty() && !haleVersion.getQualifier().equalsIgnoreCase("RELEASE");
if (!developmentVersion) {
// strip qualifier for RELEASE
haleVersion = new Version(haleVersion.getMajor(), haleVersion.getMinor(), haleVersion.getMicro());
}
StringBuilder versionStringBuilder = new StringBuilder();
versionStringBuilder.append(haleVersion.toString());
if (developmentVersion) {
// add revision information
String revisionString = product.getProperty(PRODUCT_PROP_REVISION);
if (revisionString != null && !revisionString.isEmpty()) {
versionStringBuilder.insert(0, '\n');
versionStringBuilder.insert(0, revisionString);
versionStringBuilder.insert(0, "Revision ");
}
}
// add version tag
String versionTagString = product.getProperty(PRODUCT_PROP_VERSION_TAG);
if (versionTagString != null && !versionTagString.isEmpty()) {
versionStringBuilder.append('-');
versionStringBuilder.append(versionTagString);
}
// add copyright notice
String copyrightString = product.getProperty(PRODUCT_PROP_COPYRIGHT);
if (copyrightString != null && !copyrightString.isEmpty()) {
versionStringBuilder.append(' ');
versionStringBuilder.append(copyrightString);
}
final String versionString = versionStringBuilder.toString();
getContent().addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
// computed version string location
Point extent = e.gc.textExtent(versionString);
if (versionStringFont == null) {
// find fitting font
Font customFont = null;
while (extent.x >= e.width || extent.y > MAX_HEIGHT) {
FontData[] orgFont = e.gc.getFont().getFontData();
// minimum font size
if (orgFont[0].getHeight() <= MIN_SIZE) {
break;
}
FontData fd = new FontData(orgFont[0].toString());
fd.setHeight(orgFont[0].getHeight() - 1);
if (customFont != null) {
// dispose previous custom font
customFont.dispose();
}
customFont = new Font(e.display, fd);
e.gc.setFont(customFont);
extent = e.gc.textExtent(versionString);
}
if (customFont != null) {
versionStringFont = customFont;
}
}
e.gc.setForeground(getForeground());
e.gc.drawText(versionString, (e.width - extent.x) / 2, e.height - extent.y - BOTTOM_MARGIN, true);
}
});
}
}
use of org.eclipse.swt.events.PaintEvent in project pentaho-kettle by pentaho.
the class StarModelDialog method addModelTab.
private void addModelTab() {
wModelTab = new CTabItem(wTabFolder, SWT.NONE);
wModelTab.setText(BaseMessages.getString(PKG, "StarModelDialog.ModelTab.Label"));
Composite wModelComp = new Composite(wTabFolder, SWT.NONE);
props.setLook(wModelComp);
FormLayout transLayout = new FormLayout();
transLayout.marginWidth = Const.MARGIN;
transLayout.marginHeight = Const.MARGIN;
wModelComp.setLayout(transLayout);
// Model name:
//
Label wlModelName = new Label(wModelComp, SWT.RIGHT);
wlModelName.setText(BaseMessages.getString(PKG, "StarModelDialog.ModelName.Label"));
props.setLook(wlModelName);
FormData fdlJobname = new FormData();
fdlJobname.left = new FormAttachment(0, 0);
fdlJobname.right = new FormAttachment(middle, -margin);
fdlJobname.top = new FormAttachment(0, margin);
wlModelName.setLayoutData(fdlJobname);
wModelName = new Text(wModelComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wModelName);
FormData fdJobname = new FormData();
fdJobname.left = new FormAttachment(middle, 0);
fdJobname.top = new FormAttachment(0, margin);
fdJobname.right = new FormAttachment(100, 0);
wModelName.setLayoutData(fdJobname);
Control lastControl = wModelName;
// Model description
//
Label wlModelDescription = new Label(wModelComp, SWT.RIGHT);
wlModelDescription.setText(BaseMessages.getString(PKG, "StarModelDialog.ModelDescription.Label"));
props.setLook(wlModelDescription);
FormData fdlJobFilename = new FormData();
fdlJobFilename.left = new FormAttachment(0, 0);
fdlJobFilename.right = new FormAttachment(middle, -margin);
fdlJobFilename.top = new FormAttachment(lastControl, margin);
wlModelDescription.setLayoutData(fdlJobFilename);
wModelDescription = new Text(wModelComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wModelDescription);
FormData fdJobFilename = new FormData();
fdJobFilename.left = new FormAttachment(middle, 0);
fdJobFilename.top = new FormAttachment(lastControl, margin);
fdJobFilename.right = new FormAttachment(100, 0);
wModelDescription.setLayoutData(fdJobFilename);
lastControl = wModelDescription;
canvas = new Canvas(wModelComp, SWT.BORDER);
FormData fdCanvas = new FormData();
fdCanvas.left = new FormAttachment(0, 0);
fdCanvas.right = new FormAttachment(100, 0);
fdCanvas.top = new FormAttachment(lastControl, 3 * margin);
fdCanvas.bottom = new FormAttachment(100, -margin);
canvas.setLayoutData(fdCanvas);
canvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent paintEvent) {
drawLogicalModel(logicalModel, canvas, paintEvent);
}
});
FormData fdModelComp = new FormData();
fdModelComp.left = new FormAttachment(0, 0);
fdModelComp.top = new FormAttachment(0, 0);
fdModelComp.right = new FormAttachment(100, 0);
fdModelComp.bottom = new FormAttachment(100, 0);
wModelComp.setLayoutData(fdModelComp);
wModelTab.setControl(wModelComp);
}
use of org.eclipse.swt.events.PaintEvent in project pentaho-kettle by pentaho.
the class TransMetricsDelegate 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(final PaintEvent event) {
if (transGraph.trans != null && transGraph.trans.isFinished()) {
refreshImage(event.gc);
if (!Const.isRunningOnWebspoonMode() && 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, "TransMetricsDelegate.TransformationIsNotRunning.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("TransMetricsDelegate Timer");
timer.schedule(new TimerTask() {
public void run() {
updateGraph();
}
}, 0, 5000);
// When the tab is closed, we remove the update timer
//
transMetricsTab.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
transGraph.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) {
continue;
}
System.out.println(loggingObject.getObjectType() + " : " + loggingObject.getObjectName());
}
}
}
});
/*
* canvas.addControlListener(new ControlAdapter() {
*
* @Override public void controlResized(ControlEvent arg0) { lastRefreshTime=0; // force a refresh } });
*/
}
use of org.eclipse.swt.events.PaintEvent in project pentaho-kettle by pentaho.
the class TransPerfDelegate method setupContent.
public void setupContent() {
// early to make sure it won't happen (see PDI-5009)
if (!transGraph.isRunning() || transGraph.trans == null || !transGraph.trans.getTransMeta().isCapturingStepPerformanceSnapShots()) {
showEmptyGraph();
// TODO: display help text and rerty button
return;
}
if (perfComposite.isDisposed()) {
return;
}
//
for (Control control : perfComposite.getChildren()) {
if (!control.isDisposed()) {
control.dispose();
}
}
emptyGraph = false;
this.title = transGraph.trans.getTransMeta().getName();
this.timeDifference = transGraph.trans.getTransMeta().getStepPerformanceCapturingDelay();
this.stepPerformanceSnapShots = transGraph.trans.getStepPerformanceSnapShots();
//
while (this.stepPerformanceSnapShots == null || stepPerformanceSnapShots.isEmpty()) {
this.stepPerformanceSnapShots = transGraph.trans.getStepPerformanceSnapShots();
try {
Thread.sleep(100L);
} catch (InterruptedException e) {
// Ignore errors
}
}
Set<String> stepsSet = stepPerformanceSnapShots.keySet();
steps = stepsSet.toArray(new String[stepsSet.size()]);
Arrays.sort(steps);
// Display 2 lists with the data types and the steps on the left side.
// Then put a canvas with the graph on the right side
//
Label dataListLabel = new Label(perfComposite, SWT.NONE);
dataListLabel.setText(BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.Metrics.Label"));
spoon.props.setLook(dataListLabel);
FormData fdDataListLabel = new FormData();
fdDataListLabel.left = new FormAttachment(0, 0);
fdDataListLabel.right = new FormAttachment(spoon.props.getMiddlePct() / 2, Const.MARGIN);
fdDataListLabel.top = new FormAttachment(0, Const.MARGIN + 5);
dataListLabel.setLayoutData(fdDataListLabel);
dataList = new org.eclipse.swt.widgets.List(perfComposite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.LEFT | SWT.BORDER);
spoon.props.setLook(dataList);
dataList.setItems(dataChoices);
dataList.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
//
if (dataList.getSelectionCount() > 1 && stepsList.getSelectionCount() > 1) {
stepsList.setSelection(stepsList.getSelectionIndices()[0]);
}
updateGraph();
}
});
FormData fdDataList = new FormData();
fdDataList.left = new FormAttachment(0, 0);
fdDataList.right = new FormAttachment(spoon.props.getMiddlePct() / 2, Const.MARGIN);
fdDataList.top = new FormAttachment(dataListLabel, Const.MARGIN);
fdDataList.bottom = new FormAttachment(40, Const.MARGIN);
dataList.setLayoutData(fdDataList);
Label stepsListLabel = new Label(perfComposite, SWT.NONE);
stepsListLabel.setText(BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.Steps.Label"));
spoon.props.setLook(stepsListLabel);
FormData fdStepsListLabel = new FormData();
fdStepsListLabel.left = new FormAttachment(0, 0);
fdStepsListLabel.right = new FormAttachment(spoon.props.getMiddlePct() / 2, Const.MARGIN);
fdStepsListLabel.top = new FormAttachment(dataList, Const.MARGIN);
stepsListLabel.setLayoutData(fdStepsListLabel);
stepsList = new org.eclipse.swt.widgets.List(perfComposite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.LEFT | SWT.BORDER);
spoon.props.setLook(stepsList);
stepsList.setItems(steps);
stepsList.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
//
if (dataList.getSelectionCount() > 1 && stepsList.getSelectionCount() > 1) {
dataList.setSelection(dataList.getSelectionIndices()[0]);
}
updateGraph();
}
});
FormData fdStepsList = new FormData();
fdStepsList.left = new FormAttachment(0, 0);
fdStepsList.right = new FormAttachment(spoon.props.getMiddlePct() / 2, Const.MARGIN);
fdStepsList.top = new FormAttachment(stepsListLabel, Const.MARGIN);
fdStepsList.bottom = new FormAttachment(100, Const.MARGIN);
stepsList.setLayoutData(fdStepsList);
canvas = new Canvas(perfComposite, SWT.NONE);
spoon.props.setLook(canvas);
FormData fdCanvas = new FormData();
fdCanvas.left = new FormAttachment(spoon.props.getMiddlePct() / 2, Const.MARGIN);
fdCanvas.right = new FormAttachment(100, 0);
fdCanvas.top = new FormAttachment(0, Const.MARGIN);
fdCanvas.bottom = new FormAttachment(100, 0);
canvas.setLayoutData(fdCanvas);
perfComposite.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent event) {
updateGraph();
}
});
perfComposite.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent event) {
if (image != null) {
image.dispose();
}
}
});
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
if (image != null && !image.isDisposed()) {
event.gc.drawImage(image, 0, 0);
}
}
});
// Refresh automatically every 5 seconds as well.
//
final Timer timer = new Timer("TransPerfDelegate Timer");
timer.schedule(new TimerTask() {
public void run() {
updateGraph();
}
}, 0, 5000);
// When the tab is closed, we remove the update timer
//
transPerfTab.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent arg0) {
timer.cancel();
}
});
}
Aggregations