List of usage examples for org.eclipse.swt.widgets Display getCurrent
public static Display getCurrent()
From source file:GetInput.java
/** * Creates the main window's contents/* ww w .j av a2 s . c om*/ * * @param parent the main window * @return Control */ protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1, false)); // Create a label to display what the user typed in final Label label = new Label(composite, SWT.NONE); label.setText("This will display the user input from InputDialog"); // Create the button to launch the error dialog Button show = new Button(composite, SWT.PUSH); show.setText("Get Input"); show.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(), "", "Enter 5-8 characters", label.getText(), new LengthValidator()); if (dlg.open() == Window.OK) { // User clicked OK; update the label with the input label.setText(dlg.getValue()); } } }); parent.pack(); return composite; }
From source file:ShowError.java
/** * Creates the main window's contents/*from ww w .jav a 2 s . c o m*/ * * @param parent the main window * @return Control */ protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(1, false)); // Create a big text box to accept error text final Text text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL); text.setLayoutData(new GridData(GridData.FILL_BOTH)); // Create the button to launch the error dialog Button show = new Button(composite, SWT.PUSH); show.setText("Show Error"); show.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { // Create the required Status object Status status = new Status(IStatus.ERROR, "My Plug-in ID", 0, "Status Error Message", null); // Display the dialog ErrorDialog.openError(Display.getCurrent().getActiveShell(), "JFace Error", text.getText(), status); } }); return composite; }
From source file:org.eclipse.swt.examples.graphics.CustomFontTab.java
public CustomFontTab(GraphicsExample example) { super(example); // create list of fonts for this platform FontData[] fontData = Display.getCurrent().getFontList(null, true); fontNames = new ArrayList<>(); for (FontData element : fontData) { // remove duplicates and sort String nextName = element.getName(); if (!fontNames.contains(nextName)) { int j = 0; while (j < fontNames.size() && nextName.compareTo(fontNames.get(j)) > 0) { j++;//from w w w .j a v a 2 s . c o m } fontNames.add(j, nextName); } } fontStyles = new String[] { GraphicsExample.getResourceString("Regular"), //$NON-NLS-1$ GraphicsExample.getResourceString("Italic"), //$NON-NLS-1$ GraphicsExample.getResourceString("Bold"), //$NON-NLS-1$ GraphicsExample.getResourceString("BoldItalic") //$NON-NLS-1$ }; styleValues = new int[] { SWT.NORMAL, SWT.ITALIC, SWT.BOLD, SWT.BOLD | SWT.ITALIC }; }
From source file:org.eclipse.swt.snippets.Snippet348.java
static Shell createShell() { final Shell shell = new Shell(SWT.SHELL_TRIM); shell.setText("Snippet 348"); createMenuBar(shell);// w ww . jav a 2 s . co m shell.addDisposeListener(e -> { Display d = Display.getCurrent(); Menu bar = d.getMenuBar(); boolean hasAppMenuBar = (bar != null); if (!hasAppMenuBar) { shell.getMenuBar().dispose(); Shell[] shells = d.getShells(); if ((shells.length == 1) && (shells[0] == shell)) { if (!d.isDisposed()) d.dispose(); } } }); return shell; }
From source file:AsciiTable.java
/** * Creates the font/*from ww w . j a va 2 s. c o m*/ */ private void createFont() { // Create a font that will display the range // of characters. "Terminal" works well in // Windows font = new Font(Display.getCurrent(), "Terminal", 10, SWT.NORMAL); }
From source file:Snippet158.java
protected int[] getTypeIds() { if (ids == null) { Display display = Display.getCurrent(); int widgetClass = OS.topLevelShellWidgetClass(); shellHandle = OS.XtAppCreateShell(null, null, widgetClass, display.xDisplay, null, 0); OS.XtSetMappedWhenManaged(shellHandle, false); OS.XtRealizeWidget(shellHandle); ids = new int[840]; names = new String[840]; for (int i = 0; i < ids.length; i++) { ids[i] = i + i;/*from w w w. jav a2 s . c om*/ names[i] = getNameFromId(i + 1); } } return ids; }
From source file:eu.hydrologis.jgrass.charting.datamodels.MultiXYTimeChartCreator.java
/** * Make a composite with the plot of the supplied chartdata. There are several HINT* variables * that can be set to tweak and configure the plot. * // ww w . ja va 2 s . c o m * @param parentComposite * @param chartData */ public void makePlot(Composite parentComposite, NumericChartData chartData) { final int tabNums = chartData.getTabItemNumbers(); if (tabNums == 0) { return; } Shell dummyShell = null; // try { // dummyShell = PlatformUI.getWorkbench().getDisplay().getActiveShell(); // } catch (Exception e) { dummyShell = new Shell(Display.getCurrent(), SWT.None); // } /* * wrapping panel needed in the case of hide checks */ TabFolder tabFolder = null; if (tabNums > 1) { tabFolder = new TabFolder(parentComposite, SWT.BORDER); tabFolder.setLayout(new GridLayout()); tabFolder.setLayoutData( new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); } for (int i = 0; i < tabNums; i++) { NumericChartDataItem chartItem = chartData.getChartDataItem(i); int chartNums = chartItem.chartSeriesData.size(); /* * are there data to create the lower chart panel */ List<LinkedHashMap<String, Integer>> series = new ArrayList<LinkedHashMap<String, Integer>>(); List<XYPlot> plots = new ArrayList<XYPlot>(); List<JFreeChart> charts = new ArrayList<JFreeChart>(); for (int j = 0; j < chartNums; j++) { final LinkedHashMap<String, Integer> chartSeries = new LinkedHashMap<String, Integer>(); XYPlot chartPlot = null; JGrassChart chart = null; double[][][] cLD = chartItem.chartSeriesData.get(j); if (M_HINT_CREATE_CHART[i][j]) { final String[] cT = chartItem.seriesNames.get(j); final String title = chartItem.chartTitles.get(j); final String xT = chartItem.chartXLabels.get(j); final String yT = chartItem.chartYLabels.get(j); if (M_HINT_CHART_TYPE[i][j] == XYLINECHART) { chart = new JGrassXYLineChart(cT, cLD); } else if (M_HINT_CHART_TYPE[i][j] == XYBARCHART) { chart = new JGrassXYBarChart(cT, cLD, HINT_barwidth); } else if (M_HINT_CHART_TYPE[i][j] == TIMEYLINECHART) { chart = new JGrassXYTimeLineChart(cT, cLD, Minute.class); ((JGrassXYTimeLineChart) chart).setTimeAxisFormat(TIMEFORMAT); } else if (M_HINT_CHART_TYPE[i][j] == TIMEYBARCHART) { chart = new JGrassXYTimeBarChart(cT, cLD, Minute.class, HINT_barwidth); ((JGrassXYTimeBarChart) chart).setTimeAxisFormat(TIMEFORMAT); } else if (M_HINT_CHART_TYPE[i][j] == XYPOINTCHART) { chart = new JGrassXYLineChart(cT, cLD); ((JGrassXYLineChart) chart).toggleLineShapesDisplay(false, true); } else if (M_HINT_CHART_TYPE[i][j] == TIMEXYPOINTCHART) { chart = new JGrassXYTimeLineChart(cT, cLD, Minute.class); ((JGrassXYTimeLineChart) chart).setTimeAxisFormat(TIMEFORMAT); ((JGrassXYTimeLineChart) chart).toggleLineShapesDisplay(false, true); } else { chart = new JGrassXYLineChart(cT, cLD); } final Composite p1Composite = new Composite(dummyShell, SWT.None); p1Composite.setLayout(new FillLayout()); p1Composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); chart.makeChartPanel(p1Composite, title, xT, yT, null, true, true, true, true); chartPlot = (XYPlot) chart.getPlot(); XYItemRenderer renderer = chartPlot.getRenderer(); chartPlot.setDomainGridlinesVisible(HINT_doDomainGridVisible); chartPlot.setRangeGridlinesVisible(HINT_doRangeGridVisible); if (HINT_doDisplayToolTips) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); } if (!M_HINT_CHARTORIENTATION_UP[i][j]) { chartPlot.getRangeAxis().setInverted(true); } if (M_HINT_CHARTSERIESCOLOR != null) { final XYItemRenderer rend = renderer; for (int k = 0; k < cLD.length; k++) { rend.setSeriesPaint(k, M_HINT_CHARTSERIESCOLOR[i][j][k]); } } chart.toggleFilledShapeDisplay(HINT_doDisplayBaseShapes, HINT_doFillBaseShapes, true); for (int k = 0; k < cT.length; k++) { chartSeries.put(cT[k], k); } series.add(chartSeries); chartPlot.setNoDataMessage("No data available"); chartPlot.setNoDataMessagePaint(Color.red); plots.add(chartPlot); charts.add(chart.getChart(title, xT, yT, null, true, HINT_doDisplayToolTips, true)); chartsList.add(chart); /* * add annotations? */ if (chartItem.annotationsOnChart.size() > 0) { LinkedHashMap<String, double[]> annotations = chartItem.annotationsOnChart.get(j); if (annotations.size() > 0) { Set<String> keys = annotations.keySet(); for (String key : keys) { double[] c = annotations.get(key); XYPointerAnnotation ann = new XYPointerAnnotation(key, c[0], c[1], HINT_AnnotationArrowAngle); ann.setTextAnchor(HINT_AnnotationTextAncor); ann.setPaint(HINT_AnnotationTextColor); ann.setArrowPaint(HINT_AnnotationArrowColor); // ann.setArrowLength(15); renderer.addAnnotation(ann); // Marker currentEnd = new ValueMarker(c[0]); // currentEnd.setPaint(Color.red); // currentEnd.setLabel(""); // currentEnd.setLabelAnchor(RectangleAnchor.TOP_RIGHT); // currentEnd.setLabelTextAnchor(TextAnchor.TOP_LEFT); // chartPlot.addDomainMarker(currentEnd); // Drawable cd = new LineDrawer(Color.red, new BasicStroke(1.0f)); // XYAnnotation bestBid = new XYDrawableAnnotation(c[0], c[1]/2.0, // 0, c[1], // cd); // chartPlot.addAnnotation(bestBid); // pointer.setFont(new Font("SansSerif", Font.PLAIN, 9)); } } } } } JFreeChart theChart = null; if (plots.size() > 1) { ValueAxis domainAxis = null; if (M_HINT_CHART_TYPE[i][0] == ChartCreator.TIMEYBARCHART || M_HINT_CHART_TYPE[i][0] == ChartCreator.TIMEYLINECHART) { domainAxis = (plots.get(0)).getDomainAxis(); } else { domainAxis = new NumberAxis(chartItem.chartXLabels.get(0)); } final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(domainAxis); plot.setGap(10.0); // add the subplots... for (int k = 0; k < plots.size(); k++) { XYPlot tmpPlot = plots.get(k); if (HINT_labelInsets != null) { tmpPlot.getRangeAxis().setLabelInsets(HINT_labelInsets); } plot.add(tmpPlot, k + 1); } plot.setOrientation(PlotOrientation.VERTICAL); theChart = new JFreeChart(chartItem.bigTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true); } else if (plots.size() == 1) { theChart = new JFreeChart(chartItem.chartTitles.get(0), JFreeChart.DEFAULT_TITLE_FONT, plots.get(0), true); } else { return; } /* * create the chart composite */ Composite tmp; if (tabNums > 1 && tabFolder != null) { tmp = new Composite(tabFolder, SWT.None); } else { tmp = new Composite(parentComposite, SWT.None); } tmp.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); tmp.setLayout(new GridLayout()); final ChartComposite frame = new ChartComposite(tmp, SWT.None, theChart, 680, 420, 300, 200, 700, 500, false, true, // properties true, // save true, // print true, // zoom true // tooltips ); // public static final boolean DEFAULT_BUFFER_USED = false; // public static final int DEFAULT_WIDTH = 680; // public static final int DEFAULT_HEIGHT = 420; // public static final int DEFAULT_MINIMUM_DRAW_WIDTH = 300; // public static final int DEFAULT_MINIMUM_DRAW_HEIGHT = 200; // public static final int DEFAULT_MAXIMUM_DRAW_WIDTH = 800; // public static final int DEFAULT_MAXIMUM_DRAW_HEIGHT = 600; // public static final int DEFAULT_ZOOM_TRIGGER_DISTANCE = 10; frame.setLayoutData( new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); frame.setLayout(new FillLayout()); frame.setDisplayToolTips(HINT_doDisplayToolTips); frame.setHorizontalAxisTrace(HINT_doHorizontalAxisTrace); frame.setVerticalAxisTrace(HINT_doVerticalAxisTrace); frame.setDomainZoomable(HINT_doDomainZoomable); frame.setRangeZoomable(HINT_doRangeZoomable); if (tabNums > 1 && tabFolder != null) { final TabItem item = new TabItem(tabFolder, SWT.NONE); item.setText(chartData.getChartDataItem(i).chartStringExtra); item.setControl(tmp); } /* * create the hide toggling part */ for (int j = 0; j < plots.size(); j++) { if (M_HINT_CREATE_TOGGLEHIDESERIES[i][j]) { final LinkedHashMap<Button, Integer> allButtons = new LinkedHashMap<Button, Integer>(); Group checksComposite = new Group(tmp, SWT.None); checksComposite.setText(""); RowLayout rowLayout = new RowLayout(); rowLayout.wrap = true; rowLayout.type = SWT.HORIZONTAL; checksComposite.setLayout(rowLayout); checksComposite .setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); final XYItemRenderer renderer = plots.get(j).getRenderer(); Set<String> lTitles = series.get(j).keySet(); for (final String title : lTitles) { final Button b = new Button(checksComposite, SWT.CHECK); b.setText(title); b.setSelection(true); final int index = series.get(j).get(title); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { boolean visible = renderer.getItemVisible(index, 0); renderer.setSeriesVisible(index, new Boolean(!visible)); } }); allButtons.put(b, index); } /* * toggle all and none */ if (HINT_doToggleTuttiButton) { Composite allchecksComposite = new Composite(tmp, SWT.None); RowLayout allrowLayout = new RowLayout(); allrowLayout.wrap = true; allrowLayout.type = SWT.HORIZONTAL; allchecksComposite.setLayout(allrowLayout); allchecksComposite .setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); final Button tuttiButton = new Button(allchecksComposite, SWT.BORDER | SWT.PUSH); tuttiButton.setText("Tutti"); tuttiButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Set<Button> set = allButtons.keySet(); for (Button button : set) { button.setSelection(true); int i = allButtons.get(button); if (renderer != null) { renderer.setSeriesVisible(i, new Boolean(true)); } } } }); final Button noneButton = new Button(allchecksComposite, SWT.BORDER | SWT.PUSH); noneButton.setText("Nessuno"); noneButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Set<Button> set = allButtons.keySet(); for (Button button : set) { button.setSelection(false); int i = allButtons.get(button); if (renderer != null) { renderer.setSeriesVisible(i, new Boolean(false)); } } } }); } } } } }
From source file:CalculatorMichaelSchmidt.java
@Override protected Control createDialogArea(final Composite parent) { Composite container = (Composite) super.createDialogArea(parent); final GridLayout calculatorGridLayout = new GridLayout(); calculatorGridLayout.marginRight = 5; calculatorGridLayout.marginLeft = 5; calculatorGridLayout.marginBottom = 5; calculatorGridLayout.marginTop = 5;/*from ww w.j ava2 s .c om*/ calculatorGridLayout.marginWidth = 10; calculatorGridLayout.marginHeight = 2; calculatorGridLayout.numColumns = 4; calculatorGridLayout.verticalSpacing = 2; calculatorGridLayout.makeColumnsEqualWidth = true; calculatorGridLayout.horizontalSpacing = 2; container.setLayout(calculatorGridLayout); // The display. Note that it has a limit of 30 characters, // much greater than the length of a double-precision number. displayText = new Text(container, SWT.RIGHT | SWT.BORDER); displayText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); displayText.setEditable(false); displayText.setDoubleClickEnabled(false); displayText.setTextLimit(30); displayText.setText(displayString); displayText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 4, 1)); final Button msButton = new Button(container, SWT.NONE); msButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateMemory('S'); } }); msButton.setToolTipText("Save value to Memory"); msButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); msButton.setText("MS"); final Button mcButton = new Button(container, SWT.NONE); mcButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('D'); } }); mcButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); mcButton.setToolTipText("Clear Memory"); mcButton.setText("MC"); final Button clearButton = new Button(container, SWT.NONE); clearButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('C'); } }); clearButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); clearButton.setToolTipText("Clear all Calculator Registers"); clearButton.setText("C"); final Button ceButton = new Button(container, SWT.NONE); ceButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('E'); } }); ceButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); ceButton.setToolTipText("Clear Entry"); ceButton.setText("CE"); final Button memAddButton = new Button(container, SWT.NONE); memAddButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateMemory('+'); } }); memAddButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); memAddButton.setToolTipText("Add value to Memory"); memAddButton.setText("M+"); final Button mrButton = new Button(container, SWT.NONE); mrButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('R'); } }); mrButton.setToolTipText("Recall value in Memory"); mrButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); mrButton.setText("MR"); final Button backButton = new Button(container, SWT.NONE); backButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('B'); } }); backButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); backButton.setToolTipText("Backspace"); backButton.setText("BACK"); final Button divideButton = new Button(container, SWT.NONE); divideButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateCalc('/'); } }); divideButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); divideButton.setToolTipText("Divide"); divideButton.setText("/"); final Button memSubtractButton = new Button(container, SWT.NONE); memSubtractButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateMemory('-'); } }); memSubtractButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); memSubtractButton.setToolTipText("Subtract value from Memory"); memSubtractButton.setText("M-"); final Button inverseButton = new Button(container, SWT.NONE); inverseButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('I'); } }); inverseButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); inverseButton.setToolTipText("Inverse of value"); inverseButton.setText("1/X"); final Button sqrtButton = new Button(container, SWT.NONE); sqrtButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('Q'); } }); sqrtButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); sqrtButton.setToolTipText("Square Root of value"); sqrtButton.setText("SQRT"); final Button multiplyButton = new Button(container, SWT.NONE); multiplyButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateCalc('*'); } }); multiplyButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); multiplyButton.setToolTipText("Multiply"); multiplyButton.setText("*"); final Button num7Button = new Button(container, SWT.NONE); num7Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('7'); } }); num7Button.setToolTipText("Numeric Pad"); num7Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num7Button.setText("7"); final Button num8Button = new Button(container, SWT.NONE); num8Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('8'); } }); num8Button.setToolTipText("Numeric Pad"); num8Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num8Button.setText("8"); final Button num9Button = new Button(container, SWT.NONE); num9Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('9'); } }); num9Button.setToolTipText("Numeric Pad"); num9Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num9Button.setText("9"); final Button SubtractButton = new Button(container, SWT.NONE); SubtractButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateCalc('-'); } }); SubtractButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); SubtractButton.setToolTipText("Subtract"); SubtractButton.setText("-"); final Button num4Button = new Button(container, SWT.NONE); num4Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('4'); } }); num4Button.setToolTipText("Numeric Pad"); num4Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num4Button.setText("4"); final Button num5Button = new Button(container, SWT.NONE); num5Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('5'); } }); num5Button.setToolTipText("Numeric Pad"); num5Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num5Button.setText("5"); final Button num6Button = new Button(container, SWT.NONE); num6Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('6'); } }); num6Button.setToolTipText("Numeric Pad"); num6Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num6Button.setText("6"); final Button AdditionButton = new Button(container, SWT.NONE); AdditionButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateCalc('+'); } }); AdditionButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); AdditionButton.setToolTipText("Add"); AdditionButton.setText("+"); final Button num1Button = new Button(container, SWT.NONE); num1Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('1'); } }); num1Button.setCapture(true); num1Button.setToolTipText("Numeric Pad"); num1Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num1Button.setText("1"); final Button num2Button = new Button(container, SWT.NONE); num2Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('2'); } }); num2Button.setToolTipText("Numeric Pad"); num2Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num2Button.setText("2"); final Button num3Button = new Button(container, SWT.NONE); num3Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('3'); } }); num3Button.setToolTipText("Numeric Pad"); num3Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num3Button.setText("3"); final Button equalsButton = new Button(container, SWT.NONE); equalsButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateCalc('='); } }); equalsButton.setToolTipText("Equals (get result)"); equalsButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 2)); equalsButton.setText("="); final Button num0Button = new Button(container, SWT.NONE); num0Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('0'); } }); num0Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num0Button.setToolTipText("Numeric Pad"); num0Button.setText("0"); final Button decimalButton = new Button(container, SWT.NONE); decimalButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('.'); } }); decimalButton.setToolTipText("Numeric Pad"); decimalButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); decimalButton.setText("."); final Button signButton = new Button(container, SWT.NONE); signButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('-'); } }); signButton.setToolTipText("Change sign of value"); signButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); signButton.setText("+/-"); new Label(container, SWT.NONE); // return container; }
From source file:code.google.gclogviewer.GCLogViewer.java
private void createShell() { shell = new Shell(SWT.SHELL_TRIM | SWT.APPLICATION_MODAL); shell.setText(SHELL_TITLE);/* ww w. j a va 2 s . c o m*/ shell.setBackground(new Color(Display.getCurrent(), 255, 255, 255)); shell.setMaximized(false); shell.setToolTipText( "A free open source tool to visualize data produced by the Java VM options -Xloggc:<file>"); Monitor primary = shell.getDisplay().getPrimaryMonitor(); Rectangle bounds = primary.getBounds(); shell.setSize(new Point(bounds.width - 100, bounds.height - 100)); Rectangle rect = shell.getBounds(); int x = bounds.x + (bounds.width - rect.width) / 2; int y = bounds.y + (bounds.height - rect.height) / 2; shell.setLocation(x, y); GridLayout layout = new GridLayout(); layout.numColumns = 1; shell.setLayout(layout); menuBar = new Menu(shell, SWT.BAR); fileMenuHeader = new MenuItem(menuBar, SWT.CASCADE); fileMenuHeader.setText("&File"); toolsMenuItem = new MenuItem(menuBar, SWT.CASCADE); toolsMenuItem.setText("&Tools"); backToHomeMenuItem = new MenuItem(menuBar, SWT.CASCADE); backToHomeMenuItem.setText("Back To Home"); backToHomeMenuItem.setEnabled(false); backToHomeMenuItem.addSelectionListener(new BackToHomeListener()); exitMenuItem = new MenuItem(menuBar, SWT.CASCADE); exitMenuItem.setText("&Exit"); exitMenuItem.addSelectionListener(new ExitListener()); fileMenu = new Menu(shell, SWT.DROP_DOWN); fileMenuHeader.setMenu(fileMenu); fileOpenMenuItem = new MenuItem(fileMenu, SWT.PUSH); fileOpenMenuItem.setText("&Open log file..."); fileOpenMenuItem.addSelectionListener(new OpenFileListener()); toolsMenu = new Menu(shell, SWT.DROP_DOWN); toolsMenuItem.setMenu(toolsMenu); compareLogMenuItem = new MenuItem(toolsMenu, SWT.PUSH); compareLogMenuItem.setText("Compare GC Log"); compareLogMenuItem.setEnabled(false); compareLogMenuItem.addSelectionListener(new CompareLogListener()); memoryLeakDetectionMenuItem = new MenuItem(toolsMenu, SWT.PUSH); memoryLeakDetectionMenuItem.setText("Memory Leak Detection"); memoryLeakDetectionMenuItem.setEnabled(false); memoryLeakDetectionMenuItem.addSelectionListener(new MemoryLeakDetectionListener()); gcTuningMenuItem = new MenuItem(toolsMenu, SWT.PUSH); gcTuningMenuItem.setText("Data for GC Tuning"); gcTuningMenuItem.setEnabled(false); gcTuningMenuItem.addSelectionListener(new DataForGCTuningListener()); exportToPDFMenuItem = new MenuItem(toolsMenu, SWT.PUSH); exportToPDFMenuItem.setText("Export to PDF"); exportToPDFMenuItem.setEnabled(false); shell.setMenuBar(menuBar); createSummary(); createGCTrendGroup(); createMemoryTrendGroup(); createProgressBar(); // Info Grid GridData infoGrid = new GridData(GridData.FILL_BOTH); final Label runtimeLabel = new Label(summary, SWT.NONE); runtimeLabel.setText("Run time: "); runtimeLabel.setLayoutData(infoGrid); runtimedataLabel = new Label(summary, SWT.NONE); runtimedataLabel.setText("xxx seconds"); runtimedataLabel.setLayoutData(infoGrid); final Label gctypeLabel = new Label(summary, SWT.NONE); gctypeLabel.setText("GC Type: "); gctypeLabel.setLayoutData(infoGrid); gctypedataLabel = new Label(summary, SWT.NONE); gctypedataLabel.setText("xxx"); gctypedataLabel.setLayoutData(infoGrid); final Label throughputLabel = new Label(summary, SWT.NONE); throughputLabel.setText("Throughput: "); throughputLabel.setLayoutData(infoGrid); throughputdataLabel = new Label(summary, SWT.NONE); throughputdataLabel.setText("xx%"); throughputdataLabel.setLayoutData(infoGrid); final Label emptyLabel = new Label(summary, SWT.NONE); emptyLabel.setText(" "); emptyLabel.setLayoutData(infoGrid); final Label emptyDataLabel = new Label(summary, SWT.NONE); emptyDataLabel.setText(" "); emptyDataLabel.setLayoutData(infoGrid); // YGC Grid GridData ygcInfoGrid = new GridData(GridData.FILL_BOTH); final Label ygcLabel = new Label(summary, SWT.NONE); ygcLabel.setText("YGC: "); ygcLabel.setLayoutData(ygcInfoGrid); ygcDataLabel = new Label(summary, SWT.NONE); ygcDataLabel.setText("xxx"); ygcDataLabel.setLayoutData(ygcInfoGrid); final Label ygctLabel = new Label(summary, SWT.NONE); ygctLabel.setText("YGCT: "); ygctLabel.setLayoutData(ygcInfoGrid); ygctDataLabel = new Label(summary, SWT.NONE); ygctDataLabel.setText("xxx seconds"); ygctDataLabel.setLayoutData(ygcInfoGrid); final Label avgYGCTLabel = new Label(summary, SWT.NONE); avgYGCTLabel.setText("Avg YGCT: "); avgYGCTLabel.setLayoutData(ygcInfoGrid); avgYGCTDataLabel = new Label(summary, SWT.NONE); avgYGCTDataLabel.setText("xxx seconds"); avgYGCTDataLabel.setLayoutData(ygcInfoGrid); final Label avgYGCRateLabel = new Label(summary, SWT.NONE); avgYGCRateLabel.setText("Avg YGCRate: "); avgYGCRateLabel.setLayoutData(ygcInfoGrid); avgYGCRateDataLabel = new Label(summary, SWT.NONE); avgYGCRateDataLabel.setText("xxx seconds"); avgYGCRateDataLabel.setLayoutData(ygcInfoGrid); // CMS Grid GridData cmsgcInfoGrid = new GridData(GridData.FILL_BOTH); cmsgcInfoGrid.exclude = true; final Label cmsgcLabel = new Label(summary, SWT.NONE); cmsgcLabel.setText("CMSGC: "); cmsgcLabel.setLayoutData(cmsgcInfoGrid); cmsgcDataLabel = new Label(summary, SWT.NONE); cmsgcDataLabel.setText("xxx"); cmsgcDataLabel.setLayoutData(cmsgcInfoGrid); final Label cmsgctLabel = new Label(summary, SWT.NONE); cmsgctLabel.setText("CMSGCT: "); cmsgctLabel.setLayoutData(cmsgcInfoGrid); cmsgctDataLabel = new Label(summary, SWT.NONE); cmsgctDataLabel.setText("xxx seconds"); cmsgctDataLabel.setLayoutData(cmsgcInfoGrid); final Label avgCMSGCTLabel = new Label(summary, SWT.NONE); avgCMSGCTLabel.setText("Avg CMSGCT: "); avgCMSGCTLabel.setLayoutData(cmsgcInfoGrid); avgCMSGCTDataLabel = new Label(summary, SWT.NONE); avgCMSGCTDataLabel.setText("xxx seconds"); avgCMSGCTDataLabel.setLayoutData(cmsgcInfoGrid); final Label avgCMSGCRateLabel = new Label(summary, SWT.NONE); avgCMSGCRateLabel.setText("Avg CMSGCRate: "); avgCMSGCRateLabel.setLayoutData(cmsgcInfoGrid); avgCMSGCRateDataLabel = new Label(summary, SWT.NONE); avgCMSGCRateDataLabel.setText("xxx seconds"); avgCMSGCRateDataLabel.setLayoutData(cmsgcInfoGrid); // LDS & PTOS Grid GridData ldsAndPTOSGrid = new GridData(GridData.FILL_BOTH); ldsAndPTOSGrid.exclude = true; final Label avgYGCLDSLabel = new Label(summary, SWT.NONE); avgYGCLDSLabel.setText("AVG YGCLDS: "); avgYGCLDSLabel.setLayoutData(ldsAndPTOSGrid); avgYGCLDSDataLabel = new Label(summary, SWT.NONE); avgYGCLDSDataLabel.setText("xxx(K)"); avgYGCLDSDataLabel.setLayoutData(ldsAndPTOSGrid); final Label avgFGCLDSLabel = new Label(summary, SWT.NONE); avgFGCLDSLabel.setText("AVG FGCLDS: "); avgFGCLDSLabel.setLayoutData(ldsAndPTOSGrid); avgFGCLDSDataLabel = new Label(summary, SWT.NONE); avgFGCLDSDataLabel.setText("xxx(K)"); avgFGCLDSDataLabel.setLayoutData(ldsAndPTOSGrid); final Label avgPTOSLabel = new Label(summary, SWT.NONE); avgPTOSLabel.setText("AVG PTOS: "); avgPTOSLabel.setLayoutData(ldsAndPTOSGrid); avgPTOSDataLabel = new Label(summary, SWT.NONE); avgPTOSDataLabel.setText("xx%"); avgPTOSDataLabel.setLayoutData(ldsAndPTOSGrid); final Label emptyLabel2 = new Label(summary, SWT.NONE); emptyLabel2.setText(" "); emptyLabel2.setLayoutData(ldsAndPTOSGrid); final Label emptyDataLabel2 = new Label(summary, SWT.NONE); emptyDataLabel2.setText(" "); emptyDataLabel2.setLayoutData(ldsAndPTOSGrid); // FGC Grid GridData fgcInfoGrid = new GridData(GridData.FILL_BOTH); final Label fgcLabel = new Label(summary, SWT.NONE); fgcLabel.setText("FGC: "); fgcLabel.setLayoutData(fgcInfoGrid); fgcDataLabel = new Label(summary, SWT.NONE); fgcDataLabel.setText("xxx"); fgcDataLabel.setLayoutData(fgcInfoGrid); final Label fgctLabel = new Label(summary, SWT.NONE); fgctLabel.setText("FGCT: "); fgctLabel.setLayoutData(fgcInfoGrid); fgctDataLabel = new Label(summary, SWT.NONE); fgctDataLabel.setText("xxx seconds"); fgctDataLabel.setLayoutData(fgcInfoGrid); final Label avgFGCTLabel = new Label(summary, SWT.NONE); avgFGCTLabel.setText("Avg FGCT: "); avgFGCTLabel.setLayoutData(fgcInfoGrid); avgFGCTDataLabel = new Label(summary, SWT.NONE); avgFGCTDataLabel.setText("xxx seconds"); avgFGCTDataLabel.setLayoutData(fgcInfoGrid); final Label avgFGCRateLabel = new Label(summary, SWT.NONE); avgFGCRateLabel.setText("Avg FGCRate: "); avgFGCRateLabel.setLayoutData(fgcInfoGrid); avgFGCRateDataLabel = new Label(summary, SWT.NONE); avgFGCRateDataLabel.setText("xxx seconds"); avgFGCRateDataLabel.setLayoutData(fgcInfoGrid); }
From source file:GraphicsExample.java
boolean checkAdvancedGraphics() { if (advanceGraphicsInit) return advanceGraphics; advanceGraphicsInit = true;//from w w w . ja v a2 s .c om Display display = Display.getCurrent(); try { Path path = new Path(display); path.dispose(); } catch (SWTException e) { Shell shell = display.getActiveShell(), newShell = null; if (shell == null) shell = newShell = new Shell(display); MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK); dialog.setText("Warning"); //$NON-NLS-1$ dialog.setMessage("LibNotFound"); //$NON-NLS-1$ dialog.open(); if (newShell != null) newShell.dispose(); return false; } return advanceGraphics = true; }