List of usage examples for org.eclipse.swt.widgets Button setText
public void setText(String text)
From source file:HoverHelp.java
/** * Creates the example/*from w ww . j av a2 s . c o m*/ */ public void createPartControl(Composite frame) { final ToolTipHandler tooltip = new ToolTipHandler(frame.getShell()); GridLayout layout = new GridLayout(); layout.numColumns = 3; frame.setLayout(layout); ToolBar bar = new ToolBar(frame, SWT.BORDER); for (int i = 0; i < 5; i++) { ToolItem item = new ToolItem(bar, SWT.PUSH); item.setText(getResourceString("ToolItem.text", new Object[] { new Integer(i) })); item.setData("TIP_TEXT", getResourceString("ToolItem.tooltip", new Object[] { item.getText() })); item.setData("TIP_HELPTEXTHANDLER", new ToolTipHelpTextHandler() { public String getHelpText(Widget widget) { Item item = (Item) widget; return getResourceString("ToolItem.help", new Object[] { item.getText() }); } }); } GridData gridData = new GridData(); gridData.horizontalSpan = 3; bar.setLayoutData(gridData); tooltip.activateHoverHelp(bar); Table table = new Table(frame, SWT.BORDER); for (int i = 0; i < 4; i++) { TableItem item = new TableItem(table, SWT.PUSH); item.setText(getResourceString("Item", new Object[] { new Integer(i) })); item.setData("TIP_IMAGE", images[hhiInformation]); item.setText(getResourceString("TableItem.text", new Object[] { new Integer(i) })); item.setData("TIP_TEXT", getResourceString("TableItem.tooltip", new Object[] { item.getText() })); item.setData("TIP_HELPTEXTHANDLER", new ToolTipHelpTextHandler() { public String getHelpText(Widget widget) { Item item = (Item) widget; return getResourceString("TableItem.help", new Object[] { item.getText() }); } }); } table.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL)); tooltip.activateHoverHelp(table); Tree tree = new Tree(frame, SWT.BORDER); for (int i = 0; i < 4; i++) { TreeItem item = new TreeItem(tree, SWT.PUSH); item.setText(getResourceString("Item", new Object[] { new Integer(i) })); item.setData("TIP_IMAGE", images[hhiWarning]); item.setText(getResourceString("TreeItem.text", new Object[] { new Integer(i) })); item.setData("TIP_TEXT", getResourceString("TreeItem.tooltip", new Object[] { item.getText() })); item.setData("TIP_HELPTEXTHANDLER", new ToolTipHelpTextHandler() { public String getHelpText(Widget widget) { Item item = (Item) widget; return getResourceString("TreeItem.help", new Object[] { item.getText() }); } }); } tree.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL)); tooltip.activateHoverHelp(tree); Button button = new Button(frame, SWT.PUSH); button.setText(getResourceString("Hello.text")); button.setData("TIP_TEXT", getResourceString("Hello.tooltip")); tooltip.activateHoverHelp(button); }
From source file:org.eclipse.swt.examples.hoverhelp.HoverHelp.java
/** * Creates the example// ww w . ja v a2s .c om */ public void createPartControl(Composite frame) { final ToolTipHandler tooltip = new ToolTipHandler(frame.getShell()); GridLayout layout = new GridLayout(); layout.numColumns = 3; frame.setLayout(layout); String platform = SWT.getPlatform(); String helpKey = "F1"; if (platform.equals("gtk")) helpKey = "Ctrl+F1"; if (platform.equals("cocoa")) helpKey = "Help"; ToolBar bar = new ToolBar(frame, SWT.BORDER); for (int i = 0; i < 5; i++) { ToolItem item = new ToolItem(bar, SWT.PUSH); item.setText(getResourceString("ToolItem.text", new Object[] { Integer.valueOf(i) })); item.setData("TIP_TEXT", getResourceString("ToolItem.tooltip", new Object[] { item.getText(), helpKey })); item.setData("TIP_HELPTEXTHANDLER", (ToolTipHelpTextHandler) widget -> { Item item1 = (Item) widget; return getResourceString("ToolItem.help", new Object[] { item1.getText() }); }); } GridData gridData = new GridData(); gridData.horizontalSpan = 3; bar.setLayoutData(gridData); tooltip.activateHoverHelp(bar); Table table = new Table(frame, SWT.BORDER); for (int i = 0; i < 4; i++) { TableItem item = new TableItem(table, SWT.PUSH); item.setText(getResourceString("Item", new Object[] { Integer.valueOf(i) })); item.setData("TIP_IMAGE", images[hhiInformation]); item.setText(getResourceString("TableItem.text", new Object[] { Integer.valueOf(i) })); item.setData("TIP_TEXT", getResourceString("TableItem.tooltip", new Object[] { item.getText(), helpKey })); item.setData("TIP_HELPTEXTHANDLER", (ToolTipHelpTextHandler) widget -> { Item item1 = (Item) widget; return getResourceString("TableItem.help", new Object[] { item1.getText() }); }); } table.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL)); tooltip.activateHoverHelp(table); Tree tree = new Tree(frame, SWT.BORDER); for (int i = 0; i < 4; i++) { TreeItem item = new TreeItem(tree, SWT.PUSH); item.setText(getResourceString("Item", new Object[] { Integer.valueOf(i) })); item.setData("TIP_IMAGE", images[hhiWarning]); item.setText(getResourceString("TreeItem.text", new Object[] { Integer.valueOf(i) })); item.setData("TIP_TEXT", getResourceString("TreeItem.tooltip", new Object[] { item.getText(), helpKey })); item.setData("TIP_HELPTEXTHANDLER", (ToolTipHelpTextHandler) widget -> { Item item1 = (Item) widget; return getResourceString("TreeItem.help", new Object[] { item1.getText() }); }); } tree.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL)); tooltip.activateHoverHelp(tree); Button button = new Button(frame, SWT.PUSH); button.setText(getResourceString("Hello.text")); button.setData("TIP_TEXT", getResourceString("Hello.tooltip")); tooltip.activateHoverHelp(button); }
From source file:eu.stratosphere.addons.visualization.swt.SWTVertexToolTip.java
public SWTVertexToolTip(Shell parent, final SWTToolTipCommandReceiver commandReceiver, ManagementVertex managementVertex, int x, int y) { super(parent, x, y); this.managementVertex = managementVertex; final VertexVisualizationData vertexVisualizationData = (VertexVisualizationData) managementVertex .getAttachment();/*from w w w . j a v a 2 s . c o m*/ int height; final Color backgroundColor = getShell().getBackground(); final Color foregroundColor = getShell().getForeground(); // Set the title final String taskName = managementVertex.getName() + " (" + (managementVertex.getIndexInGroup() + 1) + " of " + managementVertex.getNumberOfVerticesInGroup() + ")"; setTitle(taskName); // Only create chart if profiling is enabled if (vertexVisualizationData.isProfilingEnabledForJob()) { this.threadChart = createThreadChart(vertexVisualizationData, backgroundColor); this.threadChart.setLayoutData(new GridData(GridData.FILL_BOTH)); height = 240; // should be 265 when cancel button is enabled } else { this.threadChart = null; height = 125; } final Composite tableComposite = new Composite(getShell(), SWT.NONE); tableComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); tableComposite.setBackground(backgroundColor); tableComposite.setForeground(foregroundColor); final GridLayout tableGridLayout = new GridLayout(3, false); tableGridLayout.marginHeight = 0; tableGridLayout.marginLeft = 0; tableComposite.setLayout(tableGridLayout); final GridData gridData1 = new GridData(); gridData1.horizontalSpan = 2; gridData1.grabExcessHorizontalSpace = true; gridData1.widthHint = 200; final GridData gridData2 = new GridData(); gridData2.grabExcessHorizontalSpace = true; // Instance type final Label instanceTypeTextLabel = new Label(tableComposite, SWT.NONE); instanceTypeTextLabel.setBackground(backgroundColor); instanceTypeTextLabel.setForeground(foregroundColor); instanceTypeTextLabel.setText("Instance type:"); this.instanceTypeLabel = new Label(tableComposite, SWT.NONE); this.instanceTypeLabel.setBackground(backgroundColor); this.instanceTypeLabel.setForeground(foregroundColor); this.instanceTypeLabel.setText(this.managementVertex.getInstanceType()); this.instanceTypeLabel.setLayoutData(gridData1); // Instance ID final Label instanceIDTextLabel = new Label(tableComposite, SWT.NONE); instanceIDTextLabel.setBackground(backgroundColor); instanceIDTextLabel.setForeground(foregroundColor); instanceIDTextLabel.setText("Instance ID:"); this.instanceIDLabel = new Label(tableComposite, SWT.NONE); this.instanceIDLabel.setBackground(backgroundColor); this.instanceIDLabel.setForeground(foregroundColor); this.instanceIDLabel.setText(this.managementVertex.getInstanceName()); this.instanceIDLabel.setLayoutData(gridData2); final Button switchToInstanceButton = new Button(tableComposite, SWT.PUSH); switchToInstanceButton.setText("Switch to instance..."); switchToInstanceButton.setEnabled(vertexVisualizationData.isProfilingEnabledForJob()); switchToInstanceButton.setVisible(false); /* * final String instanceName = this.managementVertex.getInstanceName(); * switchToInstanceButton.addListener(SWT.Selection, new Listener() { * @Override * public void handleEvent(Event arg0) { * commandReceiver.switchToInstance(instanceName); * } * }); */ // Execution state final Label executionStateTextLabel = new Label(tableComposite, SWT.NONE); executionStateTextLabel.setBackground(backgroundColor); executionStateTextLabel.setForeground(foregroundColor); executionStateTextLabel.setText("Execution state:"); this.executionStateLabel = new Label(tableComposite, SWT.NONE); this.executionStateLabel.setBackground(backgroundColor); this.executionStateLabel.setForeground(foregroundColor); this.executionStateLabel.setText(this.managementVertex.getExecutionState().toString()); this.executionStateLabel.setLayoutData(gridData1); final ManagementGroupVertex groupVertex = this.managementVertex.getGroupVertex(); final GroupVertexVisualizationData groupVertexVisualizationData = (GroupVertexVisualizationData) groupVertex .getAttachment(); if (groupVertexVisualizationData.isCPUBottleneck()) { this.warningComposite = createWarningComposite(WARNINGTEXT, SWT.ICON_WARNING); height += ICONSIZE; } else { this.warningComposite = null; } // Available task actions final Composite taskActionComposite = new Composite(getShell(), SWT.NONE); taskActionComposite.setLayout(new RowLayout(SWT.HORIZONTAL)); taskActionComposite.setBackground(backgroundColor); taskActionComposite.setForeground(foregroundColor); /* * final Button cancelTaskButton = new Button(taskActionComposite, SWT.PUSH); * final ManagementVertexID vertexID = this.managementVertex.getID(); * cancelTaskButton.setText("Cancel task"); * cancelTaskButton.setEnabled(this.managementVertex.getExecutionState() == ExecutionState.RUNNING); * cancelTaskButton.addListener(SWT.Selection, new Listener() { * @Override * public void handleEvent(Event arg0) { * commandReceiver.cancelTask(vertexID, taskName); * } * }); */ getShell().setSize(WIDTH, height); finishInstantiation(x, y, WIDTH, false); }
From source file:org.mwc.debrief.dis.views.DisListenerView.java
private Button createButton(Composite composite, String label, int horizontalSpan) { Button button = new Button(composite, SWT.PUSH); GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false); gd.horizontalSpan = horizontalSpan;//from w w w . ja v a2 s . com button.setLayoutData(gd); button.setText(label); return button; }
From source file:eu.stratosphere.nephele.visualization.swt.SWTVertexToolTip.java
public SWTVertexToolTip(Shell parent, final SWTToolTipCommandReceiver commandReceiver, ManagementVertex managementVertex, int x, int y) { super(parent, x, y); this.managementVertex = managementVertex; final VertexVisualizationData vertexVisualizationData = (VertexVisualizationData) managementVertex .getAttachment();// ww w .j av a 2s . c o m int height; final Color backgroundColor = getShell().getBackground(); final Color foregroundColor = getShell().getForeground(); // Set the title final String taskName = managementVertex.getName() + " (" + (managementVertex.getIndexInGroup() + 1) + " of " + managementVertex.getNumberOfVerticesInGroup() + ")"; setTitle(taskName); // Only create chart if profiling is enabled if (vertexVisualizationData.isProfilingEnabledForJob()) { this.threadChart = createThreadChart(vertexVisualizationData, backgroundColor); this.threadChart.setLayoutData(new GridData(GridData.FILL_BOTH)); height = 240; // should be 265 when cancel button is enabled } else { this.threadChart = null; height = 125; } final Composite tableComposite = new Composite(getShell(), SWT.NONE); tableComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); tableComposite.setBackground(backgroundColor); tableComposite.setForeground(foregroundColor); final GridLayout tableGridLayout = new GridLayout(3, false); tableGridLayout.marginHeight = 0; tableGridLayout.marginLeft = 0; tableComposite.setLayout(tableGridLayout); final GridData gridData1 = new GridData(); gridData1.horizontalSpan = 2; gridData1.grabExcessHorizontalSpace = true; gridData1.widthHint = 200; final GridData gridData2 = new GridData(); gridData2.grabExcessHorizontalSpace = true; // Instance type final Label instanceTypeTextLabel = new Label(tableComposite, SWT.NONE); instanceTypeTextLabel.setBackground(backgroundColor); instanceTypeTextLabel.setForeground(foregroundColor); instanceTypeTextLabel.setText("Instance type:"); this.instanceTypeLabel = new Label(tableComposite, SWT.NONE); this.instanceTypeLabel.setBackground(backgroundColor); this.instanceTypeLabel.setForeground(foregroundColor); this.instanceTypeLabel.setText(this.managementVertex.getInstanceType()); this.instanceTypeLabel.setLayoutData(gridData1); // Instance ID final Label instanceIDTextLabel = new Label(tableComposite, SWT.NONE); instanceIDTextLabel.setBackground(backgroundColor); instanceIDTextLabel.setForeground(foregroundColor); instanceIDTextLabel.setText("Instance ID:"); this.instanceIDLabel = new Label(tableComposite, SWT.NONE); this.instanceIDLabel.setBackground(backgroundColor); this.instanceIDLabel.setForeground(foregroundColor); this.instanceIDLabel.setText(this.managementVertex.getInstanceName()); this.instanceIDLabel.setLayoutData(gridData2); final Button switchToInstanceButton = new Button(tableComposite, SWT.PUSH); switchToInstanceButton.setText("Switch to instance..."); switchToInstanceButton.setEnabled(vertexVisualizationData.isProfilingEnabledForJob()); switchToInstanceButton.setVisible(false); /* * final String instanceName = this.managementVertex.getInstanceName(); * switchToInstanceButton.addListener(SWT.Selection, new Listener() { * @Override * public void handleEvent(Event arg0) { * commandReceiver.switchToInstance(instanceName); * } * }); */ // Execution state final Label executionStateTextLabel = new Label(tableComposite, SWT.NONE); executionStateTextLabel.setBackground(backgroundColor); executionStateTextLabel.setForeground(foregroundColor); executionStateTextLabel.setText("Execution state:"); this.executionStateLabel = new Label(tableComposite, SWT.NONE); this.executionStateLabel.setBackground(backgroundColor); this.executionStateLabel.setForeground(foregroundColor); this.executionStateLabel.setText(this.managementVertex.getExecutionState().toString()); this.executionStateLabel.setLayoutData(gridData1); // Checkpoint state final Label checkpointStateTextLabel = new Label(tableComposite, SWT.NONE); checkpointStateTextLabel.setBackground(backgroundColor); checkpointStateTextLabel.setForeground(foregroundColor); checkpointStateTextLabel.setText("Checkpoint state:"); this.checkpointStateLabel = new Label(tableComposite, SWT.NONE); this.checkpointStateLabel.setBackground(backgroundColor); this.checkpointStateLabel.setForeground(foregroundColor); this.checkpointStateLabel.setText(this.managementVertex.getCheckpointState().toString()); this.checkpointStateLabel.setLayoutData(gridData1); final ManagementGroupVertex groupVertex = this.managementVertex.getGroupVertex(); final GroupVertexVisualizationData groupVertexVisualizationData = (GroupVertexVisualizationData) groupVertex .getAttachment(); if (groupVertexVisualizationData.isCPUBottleneck()) { this.warningComposite = createWarningComposite(WARNINGTEXT, SWT.ICON_WARNING); height += ICONSIZE; } else { this.warningComposite = null; } // Available task actions final Composite taskActionComposite = new Composite(getShell(), SWT.NONE); taskActionComposite.setLayout(new RowLayout(SWT.HORIZONTAL)); taskActionComposite.setBackground(backgroundColor); taskActionComposite.setForeground(foregroundColor); /* * final Button cancelTaskButton = new Button(taskActionComposite, SWT.PUSH); * final ManagementVertexID vertexID = this.managementVertex.getID(); * cancelTaskButton.setText("Cancel task"); * cancelTaskButton.setEnabled(this.managementVertex.getExecutionState() == ExecutionState.RUNNING); * cancelTaskButton.addListener(SWT.Selection, new Listener() { * @Override * public void handleEvent(Event arg0) { * commandReceiver.cancelTask(vertexID, taskName); * } * }); */ getShell().setSize(WIDTH, height); finishInstantiation(x, y, WIDTH, false); }
From source file:org.jfree.experimental.chart.swt.editor.SWTAxisEditor.java
/** * Standard constructor: builds a composite for displaying/editing * the properties of the specified axis. * * @param parent The parent composite.//ww w. j a v a 2 s. c om * @param style The SWT style of the SwtAxisEditor. * @param axis the axis whose properties are to be displayed/edited * in the composite. */ public SWTAxisEditor(Composite parent, int style, Axis axis) { super(parent, style); this.labelFont = SWTUtils.toSwtFontData(getDisplay(), axis.getLabelFont(), true); this.labelPaintColor = SWTUtils.toSwtColor(getDisplay(), axis.getLabelPaint()); this.tickLabelFont = SWTUtils.toSwtFontData(getDisplay(), axis.getTickLabelFont(), true); this.tickLabelPaintColor = SWTUtils.toSwtColor(getDisplay(), axis.getTickLabelPaint()); FillLayout layout = new FillLayout(SWT.VERTICAL); layout.marginHeight = layout.marginWidth = 4; this.setLayout(layout); Group general = new Group(this, SWT.NONE); general.setLayout(new GridLayout(3, false)); general.setText(localizationResources.getString("General")); // row 1 new Label(general, SWT.NONE).setText(localizationResources.getString("Label")); this.label = new Text(general, SWT.BORDER); if (axis.getLabel() != null) { this.label.setText(axis.getLabel()); } this.label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); new Label(general, SWT.NONE).setText(""); //empty cell // row 2 new Label(general, SWT.NONE).setText(localizationResources.getString("Font")); this.labelFontField = new Text(general, SWT.BORDER); this.labelFontField.setText(this.labelFont.toString()); this.labelFontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); Button selectFontButton = new Button(general, SWT.PUSH); selectFontButton.setText(localizationResources.getString("Select...")); selectFontButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog FontDialog dlg = new FontDialog(getShell()); dlg.setText(localizationResources.getString("Font_Selection")); dlg.setFontList(new FontData[] { SWTAxisEditor.this.labelFont }); if (dlg.open() != null) { // Dispose of any fonts we have created if (SWTAxisEditor.this.font != null) { SWTAxisEditor.this.font.dispose(); } // Create the new font and set it into the title // label SWTAxisEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList()); //label.setFont( font ); SWTAxisEditor.this.labelFontField.setText(SWTAxisEditor.this.font.getFontData()[0].toString()); SWTAxisEditor.this.labelFont = SWTAxisEditor.this.font.getFontData()[0]; } } }); // row 3 new Label(general, SWT.NONE).setText(localizationResources.getString("Paint")); // Use a colored text field to show the color final SWTPaintCanvas colorCanvas = new SWTPaintCanvas(general, SWT.NONE, this.labelPaintColor); GridData canvasGridData = new GridData(SWT.FILL, SWT.CENTER, true, false); canvasGridData.heightHint = 20; colorCanvas.setLayoutData(canvasGridData); Button selectColorButton = new Button(general, SWT.PUSH); selectColorButton.setText(localizationResources.getString("Select...")); selectColorButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog ColorDialog dlg = new ColorDialog(getShell()); dlg.setText(localizationResources.getString("Title_Color")); dlg.setRGB(SWTAxisEditor.this.labelPaintColor.getRGB()); RGB rgb = dlg.open(); if (rgb != null) { // create the new color and set it to the // SwtPaintCanvas SWTAxisEditor.this.labelPaintColor = new Color(getDisplay(), rgb); colorCanvas.setColor(SWTAxisEditor.this.labelPaintColor); } } }); Group other = new Group(this, SWT.NONE); FillLayout tabLayout = new FillLayout(); tabLayout.marginHeight = tabLayout.marginWidth = 4; other.setLayout(tabLayout); other.setText(localizationResources.getString("Other")); this.otherTabs = new TabFolder(other, SWT.NONE); TabItem item1 = new TabItem(this.otherTabs, SWT.NONE); item1.setText(" " + localizationResources.getString("Ticks") + " "); Composite ticks = new Composite(this.otherTabs, SWT.NONE); ticks.setLayout(new GridLayout(3, false)); this.showTickLabelsCheckBox = new Button(ticks, SWT.CHECK); this.showTickLabelsCheckBox.setText(localizationResources.getString("Show_tick_labels")); this.showTickLabelsCheckBox.setSelection(axis.isTickLabelsVisible()); this.showTickLabelsCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); new Label(ticks, SWT.NONE).setText(localizationResources.getString("Tick_label_font")); this.tickLabelFontField = new Text(ticks, SWT.BORDER); this.tickLabelFontField.setText(this.tickLabelFont.toString()); //tickLabelFontField.setFont(SwtUtils.toSwtFontData(getDisplay(), // axis.getTickLabelFont())); this.tickLabelFontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); Button selectTickLabelFontButton = new Button(ticks, SWT.PUSH); selectTickLabelFontButton.setText(localizationResources.getString("Select...")); selectTickLabelFontButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the font-change dialog FontDialog dlg = new FontDialog(getShell()); dlg.setText(localizationResources.getString("Font_Selection")); dlg.setFontList(new FontData[] { SWTAxisEditor.this.tickLabelFont }); if (dlg.open() != null) { // Dispose of any fonts we have created if (SWTAxisEditor.this.font != null) { SWTAxisEditor.this.font.dispose(); } // Create the new font and set it into the title // label SWTAxisEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList()); //tickLabelFontField.setFont(font); SWTAxisEditor.this.tickLabelFontField .setText(SWTAxisEditor.this.font.getFontData()[0].toString()); SWTAxisEditor.this.tickLabelFont = SWTAxisEditor.this.font.getFontData()[0]; } } }); this.showTickMarksCheckBox = new Button(ticks, SWT.CHECK); this.showTickMarksCheckBox.setText(localizationResources.getString("Show_tick_marks")); this.showTickMarksCheckBox.setSelection(axis.isTickMarksVisible()); this.showTickMarksCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); item1.setControl(ticks); }
From source file:com.rcp.wbw.demo.editor.SWTAxisEditor.java
/** * Standard constructor: builds a composite for displaying/editing * the properties of the specified axis. * /* www . j a v a2s.c o m*/ * @param parent * The parent composite. * @param style * The SWT style of the SwtAxisEditor. * @param axis * the axis whose properties are to be displayed/edited * in the composite. */ public SWTAxisEditor(Composite parent, int style, Axis axis) { super(parent, style); this.labelFont = SWTUtils.toSwtFontData(getDisplay(), axis.getLabelFont(), true); this.labelPaintColor = SWTUtils.toSwtColor(getDisplay(), axis.getLabelPaint()); this.tickLabelFont = SWTUtils.toSwtFontData(getDisplay(), axis.getTickLabelFont(), true); this.tickLabelPaintColor = SWTUtils.toSwtColor(getDisplay(), axis.getTickLabelPaint()); FillLayout layout = new FillLayout(SWT.VERTICAL); layout.marginHeight = layout.marginWidth = 4; setLayout(layout); Group general = new Group(this, SWT.NONE); general.setLayout(new GridLayout(3, false)); general.setText(localizationResources.getString("General")); // row 1 new Label(general, SWT.NONE).setText(localizationResources.getString("Label")); this.label = new Text(general, SWT.BORDER); if (axis.getLabel() != null) { this.label.setText(axis.getLabel()); } this.label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); new Label(general, SWT.NONE).setText(""); // empty cell // row 2 new Label(general, SWT.NONE).setText(localizationResources.getString("Font")); this.labelFontField = new Text(general, SWT.BORDER); this.labelFontField.setText(this.labelFont.toString()); this.labelFontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); Button selectFontButton = new Button(general, SWT.PUSH); selectFontButton.setText(localizationResources.getString("Select...")); selectFontButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog FontDialog dlg = new FontDialog(getShell()); dlg.setText(localizationResources.getString("Font_Selection")); dlg.setFontList(new FontData[] { SWTAxisEditor.this.labelFont }); if (dlg.open() != null) { // Dispose of any fonts we have created if (SWTAxisEditor.this.font != null) { SWTAxisEditor.this.font.dispose(); } // Create the new font and set it into the title // label SWTAxisEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList()); // label.setFont(font); SWTAxisEditor.this.labelFontField.setText(SWTAxisEditor.this.font.getFontData()[0].toString()); SWTAxisEditor.this.labelFont = SWTAxisEditor.this.font.getFontData()[0]; } } }); // row 3 new Label(general, SWT.NONE).setText(localizationResources.getString("Paint")); // Use a colored text field to show the color final SWTPaintCanvas colorCanvas = new SWTPaintCanvas(general, SWT.NONE, this.labelPaintColor); GridData canvasGridData = new GridData(SWT.FILL, SWT.CENTER, true, false); canvasGridData.heightHint = 20; colorCanvas.setLayoutData(canvasGridData); Button selectColorButton = new Button(general, SWT.PUSH); selectColorButton.setText(localizationResources.getString("Select...")); selectColorButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the color-change dialog ColorDialog dlg = new ColorDialog(getShell()); dlg.setText(localizationResources.getString("Title_Color")); dlg.setRGB(SWTAxisEditor.this.labelPaintColor.getRGB()); RGB rgb = dlg.open(); if (rgb != null) { // create the new color and set it to the // SwtPaintCanvas SWTAxisEditor.this.labelPaintColor = new Color(getDisplay(), rgb); colorCanvas.setColor(SWTAxisEditor.this.labelPaintColor); } } }); Group other = new Group(this, SWT.NONE); FillLayout tabLayout = new FillLayout(); tabLayout.marginHeight = tabLayout.marginWidth = 4; other.setLayout(tabLayout); other.setText(localizationResources.getString("Other")); this.otherTabs = new TabFolder(other, SWT.NONE); TabItem item1 = new TabItem(this.otherTabs, SWT.NONE); item1.setText(" " + localizationResources.getString("Ticks") + " "); Composite ticks = new Composite(this.otherTabs, SWT.NONE); ticks.setLayout(new GridLayout(3, false)); this.showTickLabelsCheckBox = new Button(ticks, SWT.CHECK); this.showTickLabelsCheckBox.setText(localizationResources.getString("Show_tick_labels")); this.showTickLabelsCheckBox.setSelection(axis.isTickLabelsVisible()); this.showTickLabelsCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); new Label(ticks, SWT.NONE).setText(localizationResources.getString("Tick_label_font")); this.tickLabelFontField = new Text(ticks, SWT.BORDER); this.tickLabelFontField.setText(this.tickLabelFont.toString()); // tickLabelFontField.setFont(SwtUtils.toSwtFontData(getDisplay(), // axis.getTickLabelFont())); this.tickLabelFontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); Button selectTickLabelFontButton = new Button(ticks, SWT.PUSH); selectTickLabelFontButton.setText(localizationResources.getString("Select...")); selectTickLabelFontButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the font-change dialog FontDialog dlg = new FontDialog(getShell()); dlg.setText(localizationResources.getString("Font_Selection")); dlg.setFontList(new FontData[] { SWTAxisEditor.this.tickLabelFont }); if (dlg.open() != null) { // Dispose of any fonts we have created if (SWTAxisEditor.this.font != null) { SWTAxisEditor.this.font.dispose(); } // Create the new font and set it into the title // label SWTAxisEditor.this.font = new Font(getShell().getDisplay(), dlg.getFontList()); // tickLabelFontField.setFont(font); SWTAxisEditor.this.tickLabelFontField .setText(SWTAxisEditor.this.font.getFontData()[0].toString()); SWTAxisEditor.this.tickLabelFont = SWTAxisEditor.this.font.getFontData()[0]; } } }); this.showTickMarksCheckBox = new Button(ticks, SWT.CHECK); this.showTickMarksCheckBox.setText(localizationResources.getString("Show_tick_marks")); this.showTickMarksCheckBox.setSelection(axis.isTickMarksVisible()); this.showTickMarksCheckBox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); item1.setControl(ticks); }
From source file:SWTImageViewer.java
public void open() { shell = new Shell(viewer.shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.RESIZE); shell.setText("Print preview"); shell.setLayout(new GridLayout(4, false)); final Button buttonSelectPrinter = new Button(shell, SWT.PUSH); buttonSelectPrinter.setText("Select a printer"); buttonSelectPrinter.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { PrintDialog dialog = new PrintDialog(shell); // Prompts the printer dialog to let the user select a printer. PrinterData printerData = dialog.open(); if (printerData == null) // the user cancels the dialog return; // Loads the printer. final Printer printer = new Printer(printerData); setPrinter(printer, Double.parseDouble(combo.getItem(combo.getSelectionIndex()))); }//from w ww.ja v a 2 s.com }); new Label(shell, SWT.NULL).setText("Margin in inches: "); combo = new Combo(shell, SWT.READ_ONLY); combo.add("0.5"); combo.add("1.0"); combo.add("1.5"); combo.add("2.0"); combo.add("2.5"); combo.add("3.0"); combo.select(1); combo.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { double value = Double.parseDouble(combo.getItem(combo.getSelectionIndex())); setPrinter(printer, value); } }); final Button buttonPrint = new Button(shell, SWT.PUSH); buttonPrint.setText("Print"); buttonPrint.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { if (printer == null) viewer.print(); else viewer.print(printer, margin); shell.dispose(); } }); canvas = new Canvas(shell, SWT.BORDER); GridData gridData = new GridData(GridData.FILL_BOTH); gridData.horizontalSpan = 4; canvas.setLayoutData(gridData); canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { int canvasBorder = 20; if (printer == null || printer.isDisposed()) return; Rectangle rectangle = printer.getBounds(); Point canvasSize = canvas.getSize(); double viewScaleFactor = (canvasSize.x - canvasBorder * 2) * 1.0 / rectangle.width; viewScaleFactor = Math.min(viewScaleFactor, (canvasSize.y - canvasBorder * 2) * 1.0 / rectangle.height); int offsetX = (canvasSize.x - (int) (viewScaleFactor * rectangle.width)) / 2; int offsetY = (canvasSize.y - (int) (viewScaleFactor * rectangle.height)) / 2; e.gc.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE)); // draws the page layout e.gc.fillRectangle(offsetX, offsetY, (int) (viewScaleFactor * rectangle.width), (int) (viewScaleFactor * rectangle.height)); // draws the margin. e.gc.setLineStyle(SWT.LINE_DASH); e.gc.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK)); int marginOffsetX = offsetX + (int) (viewScaleFactor * margin.left); int marginOffsetY = offsetY + (int) (viewScaleFactor * margin.top); e.gc.drawRectangle(marginOffsetX, marginOffsetY, (int) (viewScaleFactor * (margin.right - margin.left)), (int) (viewScaleFactor * (margin.bottom - margin.top))); if (viewer.image != null) { int imageWidth = viewer.image.getBounds().width; int imageHeight = viewer.image.getBounds().height; double dpiScaleFactorX = printer.getDPI().x * 1.0 / shell.getDisplay().getDPI().x; double dpiScaleFactorY = printer.getDPI().y * 1.0 / shell.getDisplay().getDPI().y; double imageSizeFactor = Math.min(1, (margin.right - margin.left) * 1.0 / (dpiScaleFactorX * imageWidth)); imageSizeFactor = Math.min(imageSizeFactor, (margin.bottom - margin.top) * 1.0 / (dpiScaleFactorY * imageHeight)); e.gc.drawImage(viewer.image, 0, 0, imageWidth, imageHeight, marginOffsetX, marginOffsetY, (int) (dpiScaleFactorX * imageSizeFactor * imageWidth * viewScaleFactor), (int) (dpiScaleFactorY * imageSizeFactor * imageHeight * viewScaleFactor)); } } }); shell.setSize(400, 400); shell.open(); setPrinter(null, 1.0); // Set up the event loop. while (!shell.isDisposed()) { if (!shell.getDisplay().readAndDispatch()) { // If no more entries in event queue shell.getDisplay().sleep(); } } }
From source file:org.eclipse.swt.examples.controlexample.ShellTab.java
/** * Handle the Create button selection event. * * @param event org.eclipse.swt.events.SelectionEvent *//*from w ww .j av a 2 s .com*/ public void createButtonSelected(SelectionEvent event) { /* * Remember the example shells so they * can be disposed by the user. */ if (shellCount >= shells.length) { Shell[] newShells = new Shell[shells.length + 4]; System.arraycopy(shells, 0, newShells, 0, shells.length); shells = newShells; } /* Compute the shell style */ int style = SWT.NONE; if (noTrimButton.getSelection()) style |= SWT.NO_TRIM; if (noMoveButton.getSelection()) style |= SWT.NO_MOVE; if (closeButton.getSelection()) style |= SWT.CLOSE; if (titleButton.getSelection()) style |= SWT.TITLE; if (minButton.getSelection()) style |= SWT.MIN; if (maxButton.getSelection()) style |= SWT.MAX; if (borderButton.getSelection()) style |= SWT.BORDER; if (resizeButton.getSelection()) style |= SWT.RESIZE; if (onTopButton.getSelection()) style |= SWT.ON_TOP; if (toolButton.getSelection()) style |= SWT.TOOL; if (sheetButton.getSelection()) style |= SWT.SHEET; if (modelessButton.getSelection()) style |= SWT.MODELESS; if (primaryModalButton.getSelection()) style |= SWT.PRIMARY_MODAL; if (applicationModalButton.getSelection()) style |= SWT.APPLICATION_MODAL; if (systemModalButton.getSelection()) style |= SWT.SYSTEM_MODAL; /* Create the shell with or without a parent */ if (noParentButton.getSelection()) { shells[shellCount] = new Shell(style); } else { shells[shellCount] = new Shell(shell, style); } final Shell currentShell = shells[shellCount]; currentShell.setBackgroundMode(SWT.INHERIT_DEFAULT); final Button button = new Button(currentShell, SWT.CHECK); button.setBounds(20, 20, 120, 30); button.setText(ControlExample.getResourceString("FullScreen")); button.addSelectionListener(widgetSelectedAdapter(e -> currentShell.setFullScreen(button.getSelection()))); Button close = new Button(currentShell, SWT.PUSH); close.setBounds(160, 20, 120, 30); close.setText(ControlExample.getResourceString("Close")); close.addListener(SWT.Selection, event1 -> { currentShell.dispose(); shellCount--; }); /* Set the size, title, and image, and open the shell */ currentShell.setSize(300, 100); currentShell.setText(ControlExample.getResourceString("Title") + shellCount); if (imageButton.getSelection()) currentShell.setImage(instance.images[ControlExample.ciTarget]); if (backgroundImageButton.getSelection()) currentShell.setBackgroundImage(instance.images[ControlExample.ciBackground]); hookListeners(currentShell); currentShell.open(); shellCount++; }
From source file:ReservationData.java
protected Control createContents(Composite parent) { Button button = new Button(parent, SWT.PUSH); button.setText("Make a reservation"); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { ReservationWizard wizard = new ReservationWizard(); WizardDialog dialog = new WizardDialog(getShell(), wizard); dialog.setBlockOnOpen(true); int returnCode = dialog.open(); if (returnCode == Dialog.OK) System.out.println(wizard.data); else/*ww w .j a v a 2 s. c o m*/ System.out.println("Cancelled"); } }); return button; }