List of usage examples for org.eclipse.swt.widgets Button setBackground
public void setBackground(Color color)
From source file:Snippet134.java
public static void main(String[] args) { final Display display = new Display(); // Shell must be created with style SWT.NO_TRIM final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP); shell.setBackground(display.getSystemColor(SWT.COLOR_RED)); // define a region that looks like a key hole Region region = new Region(); region.add(circle(67, 67, 67));/*w w w . j a v a2s. c o m*/ region.subtract(circle(20, 67, 50)); region.subtract(new int[] { 67, 50, 55, 105, 79, 105 }); // define the shape of the shell using setRegion shell.setRegion(region); Rectangle size = region.getBounds(); shell.setSize(size.width, size.height); // add ability to move shell around Listener l = new Listener() { Point origin; public void handleEvent(Event e) { switch (e.type) { case SWT.MouseDown: origin = new Point(e.x, e.y); break; case SWT.MouseUp: origin = null; break; case SWT.MouseMove: if (origin != null) { Point p = display.map(shell, null, e.x, e.y); shell.setLocation(p.x - origin.x, p.y - origin.y); } break; } } }; shell.addListener(SWT.MouseDown, l); shell.addListener(SWT.MouseUp, l); shell.addListener(SWT.MouseMove, l); // add ability to close shell Button b = new Button(shell, SWT.PUSH); b.setBackground(shell.getBackground()); b.setText("close"); b.pack(); b.setLocation(10, 68); b.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { shell.close(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } region.dispose(); display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet134.java
public static void main(String[] args) { final Display display = new Display(); //Shell must be created with style SWT.NO_TRIM final Shell shell = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP); shell.setText("Snippet 134"); shell.setBackground(display.getSystemColor(SWT.COLOR_RED)); //define a region that looks like a key hole Region region = new Region(); region.add(circle(67, 67, 67));/*from w ww. j a v a 2s .c om*/ region.subtract(circle(20, 67, 50)); region.subtract(new int[] { 67, 50, 55, 105, 79, 105 }); //define the shape of the shell using setRegion shell.setRegion(region); Rectangle size = region.getBounds(); shell.setSize(size.width, size.height); //add ability to move shell around Listener l = new Listener() { /** The x/y of the MouseDown, relative to top-left of the shell. */ Point origin; @Override public void handleEvent(Event e) { switch (e.type) { case SWT.MouseDown: Point point = shell.toDisplay(e.x, e.y); Point loc = shell.getLocation(); origin = new Point(point.x - loc.x, point.y - loc.y); break; case SWT.MouseUp: origin = null; break; case SWT.MouseMove: if (origin != null) { Point p = display.map(shell, null, e.x, e.y); shell.setLocation(p.x - origin.x, p.y - origin.y); } break; } } }; shell.addListener(SWT.MouseDown, l); shell.addListener(SWT.MouseUp, l); shell.addListener(SWT.MouseMove, l); //add ability to close shell Button b = new Button(shell, SWT.PUSH); b.setBackground(shell.getBackground()); b.setText("close"); b.pack(); b.setLocation(10, 68); b.addListener(SWT.Selection, e -> shell.close()); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } region.dispose(); display.dispose(); }
From source file:MouseTrackExample.java
public MouseTrackExample() { d = new Display(); s = new Shell(d); s.setSize(250, 200);// w ww .ja va2 s.co m s.setText("A MouseTrackListener Example"); final Button b = new Button(s, SWT.PUSH); b.setText("Push Me"); b.setBounds(20, 50, 55, 25); s.open(); final Color oldColor = b.getBackground(); b.addMouseTrackListener(new MouseTrackAdapter() { public void mouseEnter(MouseEvent e) { b.setBackground(new Color(d, 0, 153, 153)); } public void mouseExit(MouseEvent e) { b.setBackground(oldColor); } }); while (!s.isDisposed()) { if (!d.readAndDispatch()) d.sleep(); } d.dispose(); }
From source file:org.pentaho.di.ui.spoon.trans.TransPerfDelegate.java
/** * Tell the user that the transformation is not running or that there is no monitoring configured. *//*from ww w .j a va2 s . c o m*/ private void showEmptyGraph() { if (perfComposite.isDisposed()) { return; } emptyGraph = true; Label label = new Label(perfComposite, SWT.CENTER); label.setText(BaseMessages.getString(PKG, "TransLog.Dialog.PerformanceMonitoringNotEnabled.Message")); label.setBackground(perfComposite.getBackground()); label.setFont(GUIResource.getInstance().getFontMedium()); FormData fdLabel = new FormData(); fdLabel.left = new FormAttachment(5, 0); fdLabel.right = new FormAttachment(95, 0); fdLabel.top = new FormAttachment(5, 0); label.setLayoutData(fdLabel); Button button = new Button(perfComposite, SWT.CENTER); button.setText(BaseMessages.getString(PKG, "TransLog.Dialog.PerformanceMonitoring.Button")); button.setBackground(perfComposite.getBackground()); button.setFont(GUIResource.getInstance().getFontMedium()); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { TransGraph.editProperties(spoon.getActiveTransformation(), spoon, spoon.rep, true, TransDialog.Tabs.MONITOR_TAB); } }); FormData fdButton = new FormData(); fdButton.left = new FormAttachment(40, 0); fdButton.right = new FormAttachment(60, 0); fdButton.top = new FormAttachment(label, 5); button.setLayoutData(fdButton); perfComposite.layout(true, true); }
From source file:at.ac.tuwien.inso.subcat.ui.widgets.TrendView.java
public TrendView(Composite parent, int style) { super(parent, style); initCharts();/*w ww .ja va2 s. c o m*/ setLayout(new FillLayout()); SashForm sashForm = new SashForm(this, SWT.VERTICAL); timeChart = new TimeChartControlPanel<SelectedChart>(sashForm, SWT.BORDER); timeChart.addChartSelectionEntry("Trend View", SelectedChart.LINE); timeChart.addChartSelectionEntry("Bar View", SelectedChart.BAR); timeChart.addChartSelectionEntry("Both", SelectedChart.BOTH); JFreeChart chart = createChart(SelectedChart.LINE); setChart(chart); scrolledComposite = new ScrolledComposite(sashForm, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); scrolledComposite.setLayout(new FillLayout()); optionComposite = new Composite(scrolledComposite, SWT.NONE); optionComposite.setLayout(new GridLayout(3, false)); scrolledComposite.setContent(optionComposite); scrolledComposite.setMinSize(optionComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); scrolledComposite.setExpandVertical(true); scrolledComposite.setExpandHorizontal(true); scrolledComposite.setAlwaysShowScrollBars(false); // Signals: boxListener = new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { Button button = (Button) e.getSource(); ChartIdentifier boxData = (ChartIdentifier) button.getData(); assert (boxData != null); boolean checked = button.getSelection(); if (boxData.paint == null) { boxData.paint = drawingSupplier.getNextPaint(); } if (checked) { java.awt.Color paintColor = (java.awt.Color) boxData.paint; Color color = new Color(null, paintColor.getRed(), paintColor.getGreen(), paintColor.getBlue()); button.setBackground(color); } else { button.setBackground(null); } for (TrendViewListener listener : listeners) { listener.optionSelected(boxData, checked); } } @Override public void widgetDefaultSelected(SelectionEvent e) { } }; comboListener = new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { Combo combo = (Combo) e.getSource(); DropDownData data = (DropDownData) combo.getData(); assert (data != null); DropDownConfig config = data.getConfig(); for (TrendViewListener listener : listeners) { listener.comboChanged(config); } } @Override public void widgetDefaultSelected(SelectionEvent e) { } }; }
From source file:at.ac.tuwien.inso.subcat.ui.widgets.TrendChart.java
public TrendChart(Composite parent, int style) { super(parent, style); initCharts();// w ww. ja v a 2 s . c o m setLayout(new FillLayout()); SashForm sashForm = new SashForm(this, SWT.VERTICAL); timeChart = new TimeChartControlPanel<SelectedChart>(sashForm, SWT.BORDER); timeChart.addChartSelectionEntry("Trend View", SelectedChart.LINE); timeChart.addChartSelectionEntry("Bar View", SelectedChart.BAR); timeChart.addChartSelectionEntry("Both", SelectedChart.BOTH); JFreeChart chart = createChart(SelectedChart.LINE); setChart(chart); scrolledComposite = new ScrolledComposite(sashForm, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); scrolledComposite.setLayout(new FillLayout()); optionComposite = new Composite(scrolledComposite, SWT.NONE); optionComposite.setLayout(new GridLayout(3, false)); scrolledComposite.setContent(optionComposite); scrolledComposite.setMinSize(optionComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); scrolledComposite.setExpandVertical(true); scrolledComposite.setExpandHorizontal(true); scrolledComposite.setAlwaysShowScrollBars(false); // Signals: boxListener = new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { Button button = (Button) e.getSource(); ChartIdentifier boxData = (ChartIdentifier) button.getData(); assert (boxData != null); boolean checked = button.getSelection(); if (boxData.paint == null) { boxData.paint = drawingSupplier.getNextPaint(); } if (checked) { java.awt.Color paintColor = (java.awt.Color) boxData.paint; Color color = new Color(null, paintColor.getRed(), paintColor.getGreen(), paintColor.getBlue()); button.setBackground(color); } else { button.setBackground(null); } for (TrendChartListener listener : listeners) { listener.optionSelected(boxData, checked); } } @Override public void widgetDefaultSelected(SelectionEvent e) { } }; comboListener = new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { Combo combo = (Combo) e.getSource(); DropDownData data = (DropDownData) combo.getData(); assert (data != null); DropDownConfig config = data.getConfig(); for (TrendChartListener listener : listeners) { listener.comboChanged(config); } } @Override public void widgetDefaultSelected(SelectionEvent e) { } }; }