use of org.eclipse.swt.events.PaintListener in project pentaho-kettle by pentaho.
the class EnterOptionsDialog method addLookTab.
private void addLookTab() {
int h = 40;
// ////////////////////////
// START OF LOOK TAB///
// /
wLookTab = new CTabItem(wTabFolder, SWT.NONE);
wLookTab.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.LookAndFeel.Label"));
sLookComp = new ScrolledComposite(wTabFolder, SWT.V_SCROLL | SWT.H_SCROLL);
sLookComp.setLayout(new FillLayout());
wLookComp = new Composite(sLookComp, SWT.NONE);
props.setLook(wLookComp);
FormLayout lookLayout = new FormLayout();
lookLayout.marginWidth = 3;
lookLayout.marginHeight = 3;
wLookComp.setLayout(lookLayout);
// Fixed font
int nr = 0;
Label wlFFont = new Label(wLookComp, SWT.RIGHT);
wlFFont.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.FixedWidthFont.Label"));
props.setLook(wlFFont);
FormData fdlFFont = new FormData();
fdlFFont.left = new FormAttachment(0, 0);
fdlFFont.right = new FormAttachment(middle, -margin);
fdlFFont.top = new FormAttachment(0, nr * h + margin + 10);
wlFFont.setLayoutData(fdlFFont);
wdFFont = new Button(wLookComp, SWT.PUSH | SWT.CENTER);
props.setLook(wdFFont);
FormData fddFFont = layoutResetOptionButton(wdFFont);
fddFFont.right = new FormAttachment(100, 0);
fddFFont.top = new FormAttachment(0, nr * h + margin);
fddFFont.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wdFFont.setLayoutData(fddFFont);
wdFFont.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
fixedFontData = new FontData(PropsUI.getInstance().getFixedFont().getName(), PropsUI.getInstance().getFixedFont().getHeight(), PropsUI.getInstance().getFixedFont().getStyle());
fixedFont.dispose();
fixedFont = new Font(display, fixedFontData);
wFFont.redraw();
}
});
wbFFont = new Button(wLookComp, SWT.PUSH);
props.setLook(wbFFont);
FormData fdbFFont = layoutEditOptionButton(wbFFont);
fdbFFont.right = new FormAttachment(wdFFont, -margin);
fdbFFont.top = new FormAttachment(0, nr * h + margin);
fdbFFont.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wbFFont.setLayoutData(fdbFFont);
wbFFont.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
FontDialog fd = new FontDialog(shell);
fd.setFontList(new FontData[] { fixedFontData });
FontData newfd = fd.open();
if (newfd != null) {
fixedFontData = newfd;
fixedFont.dispose();
fixedFont = new Font(display, fixedFontData);
wFFont.redraw();
}
}
});
wFFont = new Canvas(wLookComp, SWT.BORDER);
props.setLook(wFFont);
FormData fdFFont = new FormData();
fdFFont.left = new FormAttachment(middle, 0);
fdFFont.right = new FormAttachment(wbFFont, -margin);
fdFFont.top = new FormAttachment(0, margin);
fdFFont.bottom = new FormAttachment(0, h);
wFFont.setLayoutData(fdFFont);
wFFont.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent pe) {
pe.gc.setFont(fixedFont);
Rectangle max = wFFont.getBounds();
String name = fixedFontData.getName() + " - " + fixedFontData.getHeight();
Point size = pe.gc.textExtent(name);
pe.gc.drawText(name, (max.width - size.x) / 2, (max.height - size.y) / 2, true);
}
});
// Graph font
nr++;
Label wlGFont = new Label(wLookComp, SWT.RIGHT);
wlGFont.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.GraphFont.Label"));
props.setLook(wlGFont);
FormData fdlGFont = new FormData();
fdlGFont.left = new FormAttachment(0, 0);
fdlGFont.right = new FormAttachment(middle, -margin);
fdlGFont.top = new FormAttachment(0, nr * h + margin + 10);
wlGFont.setLayoutData(fdlGFont);
wdGFont = new Button(wLookComp, SWT.PUSH);
props.setLook(wdGFont);
FormData fddGFont = layoutResetOptionButton(wdGFont);
fddGFont.right = new FormAttachment(100, 0);
fddGFont.top = new FormAttachment(0, nr * h + margin);
fddGFont.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wdGFont.setLayoutData(fddGFont);
wdGFont.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
graphFont.dispose();
graphFontData = props.getDefaultFontData();
graphFont = new Font(display, graphFontData);
wGFont.redraw();
}
});
wbGFont = new Button(wLookComp, SWT.PUSH);
props.setLook(wbGFont);
FormData fdbGFont = layoutEditOptionButton(wbGFont);
fdbGFont.right = new FormAttachment(wdGFont, -margin);
fdbGFont.top = new FormAttachment(0, nr * h + margin);
fdbGFont.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wbGFont.setLayoutData(fdbGFont);
wbGFont.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
FontDialog fd = new FontDialog(shell);
fd.setFontList(new FontData[] { graphFontData });
FontData newfd = fd.open();
if (newfd != null) {
graphFontData = newfd;
graphFont.dispose();
graphFont = new Font(display, graphFontData);
wGFont.redraw();
}
}
});
wGFont = new Canvas(wLookComp, SWT.BORDER);
props.setLook(wGFont);
FormData fdGFont = new FormData();
fdGFont.left = new FormAttachment(middle, 0);
fdGFont.right = new FormAttachment(wbGFont, -margin);
fdGFont.top = new FormAttachment(0, nr * h + margin);
fdGFont.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wGFont.setLayoutData(fdGFont);
wGFont.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent pe) {
pe.gc.setFont(graphFont);
Rectangle max = wGFont.getBounds();
String name = graphFontData.getName() + " - " + graphFontData.getHeight();
Point size = pe.gc.textExtent(name);
pe.gc.drawText(name, (max.width - size.x) / 2, (max.height - size.y) / 2, true);
}
});
// Note font
nr++;
Label wlNFont = new Label(wLookComp, SWT.RIGHT);
wlNFont.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.NoteFont.Label"));
props.setLook(wlNFont);
FormData fdlNFont = new FormData();
fdlNFont.left = new FormAttachment(0, 0);
fdlNFont.right = new FormAttachment(middle, -margin);
fdlNFont.top = new FormAttachment(0, nr * h + margin + 10);
wlNFont.setLayoutData(fdlNFont);
wdNFont = new Button(wLookComp, SWT.PUSH);
props.setLook(wdNFont);
FormData fddNFont = layoutResetOptionButton(wdNFont);
fddNFont.right = new FormAttachment(100, 0);
fddNFont.top = new FormAttachment(0, nr * h + margin);
fddNFont.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wdNFont.setLayoutData(fddNFont);
wdNFont.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
noteFontData = props.getDefaultFontData();
noteFont.dispose();
noteFont = new Font(display, noteFontData);
wNFont.redraw();
}
});
wbNFont = new Button(wLookComp, SWT.PUSH);
props.setLook(wbNFont);
FormData fdbNFont = layoutEditOptionButton(wbNFont);
fdbNFont.right = new FormAttachment(wdNFont, -margin);
fdbNFont.top = new FormAttachment(0, nr * h + margin);
fdbNFont.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wbNFont.setLayoutData(fdbNFont);
wbNFont.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
FontDialog fd = new FontDialog(shell);
fd.setFontList(new FontData[] { noteFontData });
FontData newfd = fd.open();
if (newfd != null) {
noteFontData = newfd;
noteFont.dispose();
noteFont = new Font(display, noteFontData);
wNFont.redraw();
}
}
});
wNFont = new Canvas(wLookComp, SWT.BORDER);
props.setLook(wNFont);
FormData fdNFont = new FormData();
fdNFont.left = new FormAttachment(middle, 0);
fdNFont.right = new FormAttachment(wbNFont, -margin);
fdNFont.top = new FormAttachment(0, nr * h + margin);
fdNFont.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wNFont.setLayoutData(fdNFont);
wNFont.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent pe) {
pe.gc.setFont(noteFont);
Rectangle max = wNFont.getBounds();
String name = noteFontData.getName() + " - " + noteFontData.getHeight();
Point size = pe.gc.textExtent(name);
pe.gc.drawText(name, (max.width - size.x) / 2, (max.height - size.y) / 2, true);
}
});
// Background color
nr++;
Label wlBGColor = new Label(wLookComp, SWT.RIGHT);
wlBGColor.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.BackgroundColor.Label"));
props.setLook(wlBGColor);
FormData fdlBGColor = new FormData();
fdlBGColor.left = new FormAttachment(0, 0);
fdlBGColor.right = new FormAttachment(middle, -margin);
fdlBGColor.top = new FormAttachment(0, nr * h + margin + 10);
wlBGColor.setLayoutData(fdlBGColor);
wdBGcolor = new Button(wLookComp, SWT.PUSH);
props.setLook(wdBGcolor);
FormData fddBGColor = layoutResetOptionButton(wdBGcolor);
// to the right of the
fddBGColor.right = new FormAttachment(100, 0);
// dialog
fddBGColor.top = new FormAttachment(0, nr * h + margin);
fddBGColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wdBGcolor.setLayoutData(fddBGColor);
wdBGcolor.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
background.dispose();
backgroundRGB = new RGB(ConstUI.COLOR_BACKGROUND_RED, ConstUI.COLOR_BACKGROUND_GREEN, ConstUI.COLOR_BACKGROUND_BLUE);
background = new Color(display, backgroundRGB);
wBGColor.setBackground(background);
wBGColor.redraw();
}
});
wbBGColor = new Button(wLookComp, SWT.PUSH);
props.setLook(wbBGColor);
FormData fdbBGColor = layoutEditOptionButton(wbBGColor);
// to the
fdbBGColor.right = new FormAttachment(wdBGcolor, -margin);
// left of
// the
// "default"
// button
fdbBGColor.top = new FormAttachment(0, nr * h + margin);
fdbBGColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wbBGColor.setLayoutData(fdbBGColor);
wbBGColor.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
ColorDialog cd = new ColorDialog(shell);
cd.setRGB(props.getBackgroundRGB());
RGB newbg = cd.open();
if (newbg != null) {
backgroundRGB = newbg;
background.dispose();
background = new Color(display, backgroundRGB);
wBGColor.setBackground(background);
wBGColor.redraw();
}
}
});
wBGColor = new Canvas(wLookComp, SWT.BORDER);
props.setLook(wBGColor);
wBGColor.setBackground(background);
FormData fdBGColor = new FormData();
fdBGColor.left = new FormAttachment(middle, 0);
fdBGColor.right = new FormAttachment(wbBGColor, -margin);
fdBGColor.top = new FormAttachment(0, nr * h + margin);
fdBGColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wBGColor.setLayoutData(fdBGColor);
// Graph background color
nr++;
Label wlGrColor = new Label(wLookComp, SWT.RIGHT);
wlGrColor.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.BackgroundColorGraph.Label"));
props.setLook(wlGrColor);
FormData fdlGrColor = new FormData();
fdlGrColor.left = new FormAttachment(0, 0);
fdlGrColor.right = new FormAttachment(middle, -margin);
fdlGrColor.top = new FormAttachment(0, nr * h + margin + 10);
wlGrColor.setLayoutData(fdlGrColor);
wdGrColor = new Button(wLookComp, SWT.PUSH);
props.setLook(wdGrColor);
FormData fddGrColor = layoutResetOptionButton(wdGrColor);
fddGrColor.right = new FormAttachment(100, 0);
fddGrColor.top = new FormAttachment(0, nr * h + margin);
fddGrColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wdGrColor.setLayoutData(fddGrColor);
wdGrColor.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
graphColor.dispose();
graphColorRGB = new RGB(ConstUI.COLOR_GRAPH_RED, ConstUI.COLOR_GRAPH_GREEN, ConstUI.COLOR_GRAPH_BLUE);
graphColor = new Color(display, graphColorRGB);
wGrColor.setBackground(graphColor);
wGrColor.redraw();
}
});
wbGrColor = new Button(wLookComp, SWT.PUSH);
props.setLook(wbGrColor);
FormData fdbGrColor = layoutEditOptionButton(wbGrColor);
fdbGrColor.right = new FormAttachment(wdGrColor, -margin);
fdbGrColor.top = new FormAttachment(0, nr * h + margin);
fdbGrColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wbGrColor.setLayoutData(fdbGrColor);
wbGrColor.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
ColorDialog cd = new ColorDialog(shell);
cd.setRGB(props.getGraphColorRGB());
RGB newbg = cd.open();
if (newbg != null) {
graphColorRGB = newbg;
graphColor.dispose();
graphColor = new Color(display, graphColorRGB);
wGrColor.setBackground(graphColor);
wGrColor.redraw();
}
}
});
wGrColor = new Canvas(wLookComp, SWT.BORDER);
props.setLook(wGrColor);
wGrColor.setBackground(graphColor);
FormData fdGrColor = new FormData();
fdGrColor.left = new FormAttachment(middle, 0);
fdGrColor.right = new FormAttachment(wbGrColor, -margin);
fdGrColor.top = new FormAttachment(0, nr * h + margin);
fdGrColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wGrColor.setLayoutData(fdGrColor);
// Tab selected color
nr++;
Label wlTabColor = new Label(wLookComp, SWT.RIGHT);
wlTabColor.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.TabColor.Label"));
props.setLook(wlTabColor);
FormData fdlTabColor = new FormData();
fdlTabColor.left = new FormAttachment(0, 0);
fdlTabColor.right = new FormAttachment(middle, -margin);
fdlTabColor.top = new FormAttachment(0, nr * h + margin + 10);
wlTabColor.setLayoutData(fdlTabColor);
wdTabColor = new Button(wLookComp, SWT.PUSH | SWT.CENTER);
props.setLook(wdTabColor);
FormData fddTabColor = layoutResetOptionButton(wdTabColor);
fddTabColor.right = new FormAttachment(100, 0);
fddTabColor.top = new FormAttachment(0, nr * h + margin);
fddTabColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wdTabColor.setLayoutData(fddTabColor);
wdTabColor.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
tabColor.dispose();
tabColorRGB = new RGB(ConstUI.COLOR_TAB_RED, ConstUI.COLOR_TAB_GREEN, ConstUI.COLOR_TAB_BLUE);
tabColor = new Color(display, tabColorRGB);
wTabColor.setBackground(tabColor);
wTabColor.redraw();
}
});
wbTabColor = new Button(wLookComp, SWT.PUSH);
props.setLook(wbTabColor);
FormData fdbTabColor = layoutEditOptionButton(wbTabColor);
fdbTabColor.right = new FormAttachment(wdTabColor, -margin);
fdbTabColor.top = new FormAttachment(0, nr * h + margin);
fdbTabColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wbTabColor.setLayoutData(fdbTabColor);
wbTabColor.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
ColorDialog cd = new ColorDialog(shell);
cd.setRGB(props.getTabColorRGB());
RGB newbg = cd.open();
if (newbg != null) {
tabColorRGB = newbg;
tabColor.dispose();
tabColor = new Color(display, tabColorRGB);
wTabColor.setBackground(tabColor);
wTabColor.redraw();
}
}
});
wTabColor = new Canvas(wLookComp, SWT.BORDER);
props.setLook(wTabColor);
wTabColor.setBackground(tabColor);
FormData fdTabColor = new FormData();
fdTabColor.left = new FormAttachment(middle, 0);
fdTabColor.right = new FormAttachment(wbTabColor, -margin);
fdTabColor.top = new FormAttachment(0, nr * h + margin);
fdTabColor.bottom = new FormAttachment(0, (nr + 1) * h + margin);
wTabColor.setLayoutData(fdTabColor);
// Iconsize line
Label wlIconsize = new Label(wLookComp, SWT.RIGHT);
wlIconsize.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.IconSize.Label"));
props.setLook(wlIconsize);
FormData fdlIconsize = new FormData();
fdlIconsize.left = new FormAttachment(0, 0);
fdlIconsize.right = new FormAttachment(middle, -margin);
fdlIconsize.top = new FormAttachment(wTabColor, margin);
wlIconsize.setLayoutData(fdlIconsize);
wIconsize = new Text(wLookComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wIconsize.setText(Integer.toString(props.getIconSize()));
props.setLook(wIconsize);
FormData fdIconsize = new FormData();
fdIconsize.left = new FormAttachment(middle, 0);
fdIconsize.right = new FormAttachment(100, -margin);
fdIconsize.top = new FormAttachment(wTabColor, margin);
wIconsize.setLayoutData(fdIconsize);
// LineWidth line
Label wlLineWidth = new Label(wLookComp, SWT.RIGHT);
wlLineWidth.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.LineWidth.Label"));
props.setLook(wlLineWidth);
FormData fdlLineWidth = new FormData();
fdlLineWidth.left = new FormAttachment(0, 0);
fdlLineWidth.right = new FormAttachment(middle, -margin);
fdlLineWidth.top = new FormAttachment(wIconsize, margin);
wlLineWidth.setLayoutData(fdlLineWidth);
wLineWidth = new Text(wLookComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wLineWidth.setText(Integer.toString(props.getLineWidth()));
props.setLook(wLineWidth);
FormData fdLineWidth = new FormData();
fdLineWidth.left = new FormAttachment(middle, 0);
fdLineWidth.right = new FormAttachment(100, -margin);
fdLineWidth.top = new FormAttachment(wIconsize, margin);
wLineWidth.setLayoutData(fdLineWidth);
// ShadowSize line
Label wlShadowSize = new Label(wLookComp, SWT.RIGHT);
wlShadowSize.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.ShadowSize.Label"));
props.setLook(wlShadowSize);
FormData fdlShadowSize = new FormData();
fdlShadowSize.left = new FormAttachment(0, 0);
fdlShadowSize.right = new FormAttachment(middle, -margin);
fdlShadowSize.top = new FormAttachment(wLineWidth, margin);
wlShadowSize.setLayoutData(fdlShadowSize);
wShadowSize = new Text(wLookComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wShadowSize.setText(Integer.toString(props.getShadowSize()));
props.setLook(wShadowSize);
FormData fdShadowSize = new FormData();
fdShadowSize.left = new FormAttachment(middle, 0);
fdShadowSize.right = new FormAttachment(100, -margin);
fdShadowSize.top = new FormAttachment(wLineWidth, margin);
wShadowSize.setLayoutData(fdShadowSize);
// MiddlePct line
Label wlMiddlePct = new Label(wLookComp, SWT.RIGHT);
wlMiddlePct.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.DialogMiddlePercentage.Label"));
props.setLook(wlMiddlePct);
FormData fdlMiddlePct = new FormData();
fdlMiddlePct.left = new FormAttachment(0, 0);
fdlMiddlePct.right = new FormAttachment(middle, -margin);
fdlMiddlePct.top = new FormAttachment(wShadowSize, margin);
wlMiddlePct.setLayoutData(fdlMiddlePct);
wMiddlePct = new Text(wLookComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wMiddlePct.setText(Integer.toString(props.getMiddlePct()));
props.setLook(wMiddlePct);
FormData fdMiddlePct = new FormData();
fdMiddlePct.left = new FormAttachment(middle, 0);
fdMiddlePct.right = new FormAttachment(100, -margin);
fdMiddlePct.top = new FormAttachment(wShadowSize, margin);
wMiddlePct.setLayoutData(fdMiddlePct);
// GridSize line
Label wlGridSize = new Label(wLookComp, SWT.RIGHT);
wlGridSize.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.GridSize.Label"));
wlGridSize.setToolTipText(BaseMessages.getString(PKG, "EnterOptionsDialog.GridSize.ToolTip"));
props.setLook(wlGridSize);
FormData fdlGridSize = new FormData();
fdlGridSize.left = new FormAttachment(0, 0);
fdlGridSize.right = new FormAttachment(middle, -margin);
fdlGridSize.top = new FormAttachment(wMiddlePct, margin);
wlGridSize.setLayoutData(fdlGridSize);
wGridSize = new Text(wLookComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wGridSize.setText(Integer.toString(props.getCanvasGridSize()));
wGridSize.setToolTipText(BaseMessages.getString(PKG, "EnterOptionsDialog.GridSize.ToolTip"));
props.setLook(wGridSize);
FormData fdGridSize = new FormData();
fdGridSize.left = new FormAttachment(middle, 0);
fdGridSize.right = new FormAttachment(100, -margin);
fdGridSize.top = new FormAttachment(wMiddlePct, margin);
wGridSize.setLayoutData(fdGridSize);
// Show Canvas Grid
Label wlShowCanvasGrid = new Label(wLookComp, SWT.RIGHT);
wlShowCanvasGrid.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.ShowCanvasGrid.Label"));
wlShowCanvasGrid.setToolTipText(BaseMessages.getString(PKG, "EnterOptionsDialog.ShowCanvasGrid.ToolTip"));
props.setLook(wlShowCanvasGrid);
FormData fdlShowCanvasGrid = new FormData();
fdlShowCanvasGrid.left = new FormAttachment(0, 0);
fdlShowCanvasGrid.right = new FormAttachment(middle, -margin);
fdlShowCanvasGrid.top = new FormAttachment(wGridSize, margin);
wlShowCanvasGrid.setLayoutData(fdlShowCanvasGrid);
wShowCanvasGrid = new Button(wLookComp, SWT.CHECK);
props.setLook(wShowCanvasGrid);
wShowCanvasGrid.setSelection(props.isShowCanvasGridEnabled());
FormData fdShowCanvasGrid = new FormData();
fdShowCanvasGrid.left = new FormAttachment(middle, 0);
fdShowCanvasGrid.right = new FormAttachment(100, -margin);
fdShowCanvasGrid.top = new FormAttachment(wGridSize, margin);
wShowCanvasGrid.setLayoutData(fdShowCanvasGrid);
// Enable anti-aliasing
Label wlAntiAlias = new Label(wLookComp, SWT.RIGHT);
wlAntiAlias.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.CanvasAntiAliasing.Label"));
props.setLook(wlAntiAlias);
FormData fdlAntiAlias = new FormData();
fdlAntiAlias.left = new FormAttachment(0, 0);
fdlAntiAlias.top = new FormAttachment(wShowCanvasGrid, margin);
fdlAntiAlias.right = new FormAttachment(middle, -margin);
wlAntiAlias.setLayoutData(fdlAntiAlias);
wAntiAlias = new Button(wLookComp, SWT.CHECK);
props.setLook(wAntiAlias);
wAntiAlias.setSelection(props.isAntiAliasingEnabled());
FormData fdAntiAlias = new FormData();
fdAntiAlias.left = new FormAttachment(middle, 0);
fdAntiAlias.top = new FormAttachment(wShowCanvasGrid, margin);
fdAntiAlias.right = new FormAttachment(100, 0);
wAntiAlias.setLayoutData(fdAntiAlias);
// Enable anti-aliasing
Label wlIndicateSlowSteps = new Label(wLookComp, SWT.RIGHT);
wlIndicateSlowSteps.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.CanvasIndicateSlowSteps.Label"));
props.setLook(wlIndicateSlowSteps);
FormData fdlIndicateSlowSteps = new FormData();
fdlIndicateSlowSteps.left = new FormAttachment(0, 0);
fdlIndicateSlowSteps.top = new FormAttachment(wAntiAlias, margin);
fdlIndicateSlowSteps.right = new FormAttachment(middle, -margin);
wlIndicateSlowSteps.setLayoutData(fdlIndicateSlowSteps);
wIndicateSlowSteps = new Button(wLookComp, SWT.CHECK);
props.setLook(wIndicateSlowSteps);
wIndicateSlowSteps.setSelection(props.isIndicateSlowTransStepsEnabled());
wIndicateSlowSteps.setToolTipText(BaseMessages.getString(PKG, "EnterOptionsDialog.CanvasIndicateSlowSteps.Tooltip"));
FormData fdIndicateSlowSteps = new FormData();
fdIndicateSlowSteps.left = new FormAttachment(middle, 0);
fdIndicateSlowSteps.top = new FormAttachment(wAntiAlias, margin);
fdIndicateSlowSteps.right = new FormAttachment(100, 0);
wIndicateSlowSteps.setLayoutData(fdIndicateSlowSteps);
// Show original look
Label wlOriginalLook = new Label(wLookComp, SWT.RIGHT);
wlOriginalLook.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.UseOSLook.Label"));
props.setLook(wlOriginalLook);
FormData fdlOriginalLook = new FormData();
fdlOriginalLook.left = new FormAttachment(0, 0);
fdlOriginalLook.top = new FormAttachment(wIndicateSlowSteps, margin);
fdlOriginalLook.right = new FormAttachment(middle, -margin);
wlOriginalLook.setLayoutData(fdlOriginalLook);
wOriginalLook = new Button(wLookComp, SWT.CHECK);
props.setLook(wOriginalLook);
wOriginalLook.setSelection(props.isOSLookShown());
FormData fdOriginalLook = new FormData();
fdOriginalLook.left = new FormAttachment(middle, 0);
fdOriginalLook.top = new FormAttachment(wIndicateSlowSteps, margin);
fdOriginalLook.right = new FormAttachment(100, 0);
wOriginalLook.setLayoutData(fdOriginalLook);
// Show branding graphics
Label wlBranding = new Label(wLookComp, SWT.RIGHT);
wlBranding.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.Branding.Label"));
props.setLook(wlBranding);
FormData fdlBranding = new FormData();
fdlBranding.left = new FormAttachment(0, 0);
fdlBranding.top = new FormAttachment(wOriginalLook, margin);
fdlBranding.right = new FormAttachment(middle, -margin);
wlBranding.setLayoutData(fdlBranding);
wBranding = new Button(wLookComp, SWT.CHECK);
props.setLook(wBranding);
wBranding.setSelection(props.isBrandingActive());
FormData fdBranding = new FormData();
fdBranding.left = new FormAttachment(middle, 0);
fdBranding.top = new FormAttachment(wOriginalLook, margin);
fdBranding.right = new FormAttachment(100, 0);
wBranding.setLayoutData(fdBranding);
// DefaultLocale line
Label wlDefaultLocale = new Label(wLookComp, SWT.RIGHT);
wlDefaultLocale.setText(BaseMessages.getString(PKG, "EnterOptionsDialog.DefaultLocale.Label"));
props.setLook(wlDefaultLocale);
FormData fdlDefaultLocale = new FormData();
fdlDefaultLocale.left = new FormAttachment(0, 0);
fdlDefaultLocale.right = new FormAttachment(middle, -margin);
fdlDefaultLocale.top = new FormAttachment(wBranding, margin);
wlDefaultLocale.setLayoutData(fdlDefaultLocale);
wDefaultLocale = new Combo(wLookComp, SWT.SINGLE | SWT.READ_ONLY | SWT.LEFT | SWT.BORDER);
wDefaultLocale.setItems(GlobalMessages.localeDescr);
wDefaultLocale.setEnabled(!Const.isRunningOnWebspoonMode());
props.setLook(wDefaultLocale);
FormData fdDefaultLocale = new FormData();
fdDefaultLocale.left = new FormAttachment(middle, 0);
fdDefaultLocale.right = new FormAttachment(100, -margin);
fdDefaultLocale.top = new FormAttachment(wBranding, margin);
wDefaultLocale.setLayoutData(fdDefaultLocale);
// language selections...
int idxDefault = Const.indexOfString(LanguageChoice.getInstance().getDefaultLocale().toString(), GlobalMessages.localeCodes);
if (idxDefault >= 0) {
wDefaultLocale.select(idxDefault);
}
fdLookComp = new FormData();
fdLookComp.left = new FormAttachment(0, 0);
fdLookComp.right = new FormAttachment(100, 0);
fdLookComp.top = new FormAttachment(0, 0);
fdLookComp.bottom = new FormAttachment(100, 100);
wLookComp.setLayoutData(fdLookComp);
wLookComp.pack();
Rectangle bounds = wLookComp.getBounds();
sLookComp.setContent(wLookComp);
sLookComp.setExpandHorizontal(true);
sLookComp.setExpandVertical(true);
sLookComp.setMinWidth(bounds.width);
sLookComp.setMinHeight(bounds.height);
wLookTab.setControl(sLookComp);
// ///////////////////////////////////////////////////////////
// / END OF LOOK TAB
// ///////////////////////////////////////////////////////////
}
use of org.eclipse.swt.events.PaintListener 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.PaintListener 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();
}
});
}
use of org.eclipse.swt.events.PaintListener in project pentaho-kettle by pentaho.
the class StepPerformanceSnapShotDialog method open.
public void open() {
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
props.setLook(shell);
shell.setText(BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.Title"));
shell.setImage(GUIResource.getInstance().getImageLogoSmall());
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
// 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
//
dataList = new org.eclipse.swt.widgets.List(shell, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.LEFT | SWT.BORDER);
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(props.getMiddlePct() / 2, Const.MARGIN);
fdDataList.top = new FormAttachment(0, 0);
fdDataList.bottom = new FormAttachment(30, 0);
dataList.setLayoutData(fdDataList);
stepsList = new org.eclipse.swt.widgets.List(shell, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.LEFT | SWT.BORDER);
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(props.getMiddlePct() / 2, Const.MARGIN);
fdStepsList.top = new FormAttachment(dataList, Const.MARGIN);
fdStepsList.bottom = new FormAttachment(100, Const.MARGIN);
stepsList.setLayoutData(fdStepsList);
canvas = new Canvas(shell, SWT.NONE);
props.setLook(canvas);
FormData fdCanvas = new FormData();
fdCanvas.left = new FormAttachment(props.getMiddlePct() / 2, 0);
fdCanvas.right = new FormAttachment(100, 0);
fdCanvas.top = new FormAttachment(0, 0);
fdCanvas.bottom = new FormAttachment(100, 0);
canvas.setLayoutData(fdCanvas);
shell.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent event) {
updateGraph();
}
});
shell.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) {
event.gc.drawImage(image, 0, 0);
}
}
});
// Refresh automatically every 5 seconds as well.
//
Timer timer = new Timer("step performance snapshot dialog Timer");
timer.schedule(new TimerTask() {
public void run() {
updateGraph();
}
}, 0, 5000);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
Aggregations