List of usage examples for org.eclipse.swt.widgets Composite setBackground
public void setBackground(Color color)
From source file:WidgetTest2.java
public static Composite createComposite(Composite parent) { /** * Composite ** */ // Create new Composite instance final Composite composite = new Composite(parent, 0); // Get properties from the containing composite composite.setBackground(parent.getBackground()); composite.setForeground(parent.getForeground()); composite.setFont(parent.getFont()); // Set position and size composite.setBounds(X, Y, WIDTH, HEIGHT); return composite; }
From source file:ControlEditorTestTwo.java
/** * Creates the main window's contents// w w w .j ava2 s. c o m * * @param shell the main window */ private void createContents(final Shell shell) { color = new Color(shell.getDisplay(), 255, 0, 0); // Create a composite that will be the parent of the editor final Composite composite = new Composite(shell, SWT.NONE); composite.setBackground(color); composite.setBounds(0, 0, 300, 100); // Create the editor ControlEditor editor = new ControlEditor(composite); // Create the control associated with the editor Button button = new Button(composite, SWT.PUSH); button.setText("Change Color..."); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { ColorDialog dialog = new ColorDialog(shell); if (color != null) dialog.setRGB(color.getRGB()); RGB rgb = dialog.open(); if (rgb != null) { if (color != null) color.dispose(); color = new Color(shell.getDisplay(), rgb); composite.setBackground(color); } } }); // Place the editor along the bottom of the parent composite editor.grabHorizontal = true; editor.verticalAlignment = SWT.BOTTOM; Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT); editor.minimumHeight = size.y; editor.setEditor(button); }
From source file:ControlEditorTest.java
/** * Creates the main window's contents/*www . java 2 s . com*/ * * @param shell the main window */ private void createContents(final Shell shell) { color = new Color(shell.getDisplay(), 255, 0, 0); // Create a composite that will be the parent of the editor final Composite composite = new Composite(shell, SWT.NONE); composite.setBackground(color); composite.setBounds(0, 0, 300, 100); // Create the editor ControlEditor editor = new ControlEditor(composite); // Create the control associated with the editor final Text text = new Text(composite, SWT.BORDER); text.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { RGB rgb = (RGB) COLORS.get(text.getText()); if (rgb != null) { if (color != null) color.dispose(); color = new Color(shell.getDisplay(), rgb); composite.setBackground(color); } } }); // Place the editor in the top middle of the parent composite editor.horizontalAlignment = SWT.CENTER; editor.verticalAlignment = SWT.TOP; Point size = text.computeSize(SWT.DEFAULT, SWT.DEFAULT); editor.minimumWidth = size.x; editor.minimumHeight = size.y; editor.setEditor(text); }
From source file:SharedMenu.java
private void menu() { shell.setLayout(new GridLayout(2, true)); final Composite composite1 = new Composite(shell, SWT.BORDER); composite1.setBackground(display.getSystemColor(SWT.COLOR_BLACK)); final Composite composite2 = new Composite(shell, SWT.BORDER); composite2.setBackground(display.getSystemColor(SWT.COLOR_BLUE)); Menu menu = new Menu(composite1); MenuItem menuItem = new MenuItem(menu, SWT.PUSH); menuItem.setText("Popup menu"); menuItem.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { System.out.println("Menu item is disposed."); }/* w w w .j a v a 2 s . c o m*/ }); menuItem.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { System.out.println("Dispsoing ..."); //composite2.setMenu(null); composite2.dispose(); } }); composite1.setMenu(menu); composite2.setMenu(menu); }
From source file:FocusTraversal.java
private void init() { shell.setLayout(new RowLayout()); Composite composite1 = new Composite(shell, SWT.BORDER); composite1.setLayout(new RowLayout()); composite1.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); Button button1 = new Button(composite1, SWT.PUSH); button1.setText("Button1"); List list = new List(composite1, SWT.MULTI | SWT.BORDER); list.setItems(new String[] { "Item-1", "Item-2", "Item-3" }); Button radioButton1 = new Button(composite1, SWT.RADIO); radioButton1.setText("radio-1"); Button radioButton2 = new Button(composite1, SWT.RADIO); radioButton2.setText("radio-2"); Composite composite2 = new Composite(shell, SWT.BORDER); composite2.setLayout(new RowLayout()); composite2.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); Button button2 = new Button(composite2, SWT.PUSH); button2.setText("Button2"); final Canvas canvas = new Canvas(composite2, SWT.NULL); canvas.setSize(50, 50);/*from ww w. ja va2 s .c om*/ canvas.setBackground(display.getSystemColor(SWT.COLOR_YELLOW)); Combo combo = new Combo(composite2, SWT.DROP_DOWN); combo.add("combo"); combo.select(0); canvas.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { GC gc = new GC(canvas); // Erase background first. Rectangle rect = canvas.getClientArea(); gc.fillRectangle(rect.x, rect.y, rect.width, rect.height); Font font = new Font(display, "Arial", 32, SWT.BOLD); gc.setFont(font); gc.drawString("" + e.character, 15, 10); gc.dispose(); font.dispose(); } public void keyReleased(KeyEvent e) { } }); canvas.addTraverseListener(new TraverseListener() { public void keyTraversed(TraverseEvent e) { if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) e.doit = true; } }); composite1.setTabList(new Control[] { button1, list }); composite2.setTabList(new Control[] { button2, canvas, combo }); shell.setTabList(new Control[] { composite2, composite1 }); }
From source file:org.talend.dataprofiler.chart.util.HideSeriesChartDialog.java
private Composite createUtilityControl(Composite parent) { Composite comp = new Composite(parent, SWT.BORDER); comp.setLayout(new RowLayout()); comp.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY)); if (isCountAvgNull) { XYDataset dataset = chart.getXYPlot().getDataset(); int count = dataset.getSeriesCount(); for (int i = 0; i < count; i++) { Button checkBtn = new Button(comp, SWT.CHECK); checkBtn.setText(dataset.getSeriesKey(i).toString()); checkBtn.setSelection(true); checkBtn.addSelectionListener(listener); checkBtn.setData(SERIES_KEY_ID, i); }/*from w w w . jav a 2s. c o m*/ } if (isMinMaxDate) { CategoryPlot plot = (CategoryPlot) chart.getPlot(); CategoryDataset dataset = plot.getDataset(); int count = dataset.getRowCount(); for (int i = 0; i < count; i++) { Button checkBtn = new Button(comp, SWT.CHECK); checkBtn.setText(dataset.getRowKey(i).toString()); checkBtn.setSelection(true); checkBtn.addSelectionListener(listener); checkBtn.setData(SERIES_KEY_ID, i); } } return comp; }
From source file:eu.stratosphere.addons.visualization.swt.SWTGateToolTip.java
public SWTGateToolTip(Shell parent, ManagementGate managementGate, int x, int y) { super(parent, x, y); int height;/* w w w. j a v a 2 s. c o m*/ this.managementGate = managementGate; if (managementGate.isInputGate()) { setTitle("Input Gate " + managementGate.getIndex()); } else { setTitle("Output Gate " + managementGate.getIndex()); } final Color backgroundColor = getShell().getBackground(); final Color foregroundColor = getShell().getForeground(); final GateVisualizationData gateVisualizationData = (GateVisualizationData) managementGate.getAttachment(); if (gateVisualizationData.isProfilingEnabled()) { this.chart = createChart(gateVisualizationData, backgroundColor); this.chart.setLayoutData(new GridData(GridData.FILL_BOTH)); height = 200; } else { this.chart = null; height = 100; } final Composite tableComposite = new Composite(getShell(), SWT.NONE); tableComposite.setBackground(backgroundColor); tableComposite.setForeground(foregroundColor); final GridLayout tableGridLayout = new GridLayout(2, false); tableGridLayout.marginHeight = 0; tableGridLayout.marginLeft = 0; tableComposite.setLayout(tableGridLayout); // Channel type ChannelType channelType; if (managementGate.isInputGate()) { channelType = managementGate.getVertex().getGroupVertex().getBackwardEdge(managementGate.getIndex()) .getChannelType(); } else { channelType = managementGate.getVertex().getGroupVertex().getForwardEdge(managementGate.getIndex()) .getChannelType(); } final Label channelTypeTextLabel = new Label(tableComposite, SWT.NONE); channelTypeTextLabel.setBackground(backgroundColor); channelTypeTextLabel.setForeground(foregroundColor); channelTypeTextLabel.setText("Channel type:"); this.channelTypeLabel = new Label(tableComposite, SWT.NONE); this.channelTypeLabel.setBackground(backgroundColor); this.channelTypeLabel.setForeground(foregroundColor); this.channelTypeLabel.setText(channelType.toString()); if (!this.managementGate.isInputGate()) { final ManagementGroupEdge groupEdge = this.managementGate.getVertex().getGroupVertex() .getForwardEdge(this.managementGate.getIndex()); final GroupEdgeVisualizationData groupEdgeVisualizationData = (GroupEdgeVisualizationData) groupEdge .getAttachment(); if (groupEdgeVisualizationData.isIOBottleneck()) { this.warningComposite = createWarningComposite(WARNINGTEXT, SWT.ICON_WARNING); height += ICONSIZE; } else { this.warningComposite = null; } } else { this.warningComposite = null; } getShell().setSize(WIDTH, height); finishInstantiation(x, y, WIDTH, false); }
From source file:ControlSizeLocation.java
private void init() { GridLayout gridLayout = new GridLayout(2, true); shell.setLayout(gridLayout);/*from w w w.jav a2s . c om*/ Composite left = new Composite(shell, SWT.NULL); left.setLayout(new GridLayout()); //left.setLayout(new FillLayout()); left.setLayoutData(new GridData(GridData.FILL_BOTH)); left.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); button = new Button(left, SWT.PUSH); button.setText("Button"); button.setLayoutData(new GridData()); Composite right = new Composite(shell, SWT.NULL); right.setLayout(new GridLayout(4, true)); right.setLayoutData(new GridData(GridData.FILL_BOTH)); Label label = new Label(right, SWT.NULL); label.setText("X"); label = new Label(right, SWT.NULL); label.setText("Y"); label = new Label(right, SWT.NULL); label.setText("Width"); label = new Label(right, SWT.NULL); label.setText("Height"); x = new Text(right, SWT.BORDER); y = new Text(right, SWT.BORDER); w = new Text(right, SWT.BORDER); h = new Text(right, SWT.BORDER); SelectionListener selectionListener = new SelectionListener() { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.widget; if (b == get) { System.out.println("------------------------------"); System.out.println("getBounds: " + button.getBounds()); System.out.println("getLocation: " + button.getLocation()); System.out.println("getSize: " + button.getSize()); } else if (b == set) { int vx = getNumber(x); int vy = getNumber(y); int vw = getNumber(w); int vh = getNumber(h); if (vx != -1 && vy != -1) { if (vw != -1 && vh != -1) { Rectangle rectangle = new Rectangle(vx, vy, vw, vh); button.setBounds(rectangle); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println("# setBounds: " + rectangle); } else { Point point = new Point(vx, vy); button.setLocation(point); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println("# setLocation: " + point); } } else if (vw != -1 && vh != -1) { Point point = new Point(vw, vh); button.setSize(point); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); System.out.println("# setSize: " + point); } } } public void widgetDefaultSelected(SelectionEvent e) { // TODO Auto-generated method stub } }; get = new Button(right, SWT.PUSH); get.setText("Get"); get.addSelectionListener(selectionListener); set = new Button(right, SWT.PUSH); set.setText("Set"); set.addSelectionListener(selectionListener); }
From source file:eu.stratosphere.addons.visualization.swt.SWTInstanceToolTip.java
public SWTInstanceToolTip(Shell parent, final SWTToolTipCommandReceiver commandReceiver, NetworkNode networkNode, int x, int y) { super(parent, x, y); this.networkNode = networkNode; final Color backgroundColor = getShell().getBackground(); final Color foregroundColor = getShell().getForeground(); boolean isProfilingEnabled = false; final InstanceVisualizationData instanceVisualizationData = (InstanceVisualizationData) networkNode .getAttachment();/* w w w . j a va 2s.c o m*/ if (instanceVisualizationData != null) { isProfilingEnabled = instanceVisualizationData.isProfilingEnabledForJob(); } int height; // Set the title setTitle(networkNode.getName()); // Only create chart if profiling is enabled if (isProfilingEnabled) { this.cpuChart = createCPUChart(instanceVisualizationData, backgroundColor); this.cpuChart.setLayoutData(new GridData(GridData.FILL_BOTH)); this.memoryChart = createMemoryChart(instanceVisualizationData, backgroundColor); this.memoryChart.setLayoutData(new GridData(GridData.FILL_BOTH)); this.networkChart = createNetworkChart(instanceVisualizationData, backgroundColor); this.networkChart.setLayoutData(new GridData(GridData.FILL_BOTH)); height = 460; } else { this.cpuChart = null; this.memoryChart = null; this.networkChart = null; height = 75; } // Available instance actions final Composite instanceActionComposite = new Composite(getShell(), SWT.NONE); instanceActionComposite.setLayout(new RowLayout(SWT.HORIZONTAL)); instanceActionComposite.setBackground(backgroundColor); instanceActionComposite.setForeground(foregroundColor); final Button killInstanceButton = new Button(instanceActionComposite, SWT.PUSH); final String instanceName = this.networkNode.getName(); killInstanceButton.setText("Kill instance..."); killInstanceButton.setEnabled(this.networkNode.isLeafNode()); killInstanceButton.addListener(SWT.Selection, new Listener() { @Override public void handleEvent(Event arg0) { commandReceiver.killInstance(instanceName); } }); getShell().setSize(WIDTH, height); finishInstantiation(x, y, WIDTH, false); }
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 ava2 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); }