List of usage examples for org.eclipse.swt.widgets Label Label
public Label(Composite parent, int style)
From source file:org.eclipse.swt.examples.ole.win32.OLEExample.java
public void open(Display display) { Shell shell = new Shell(display); shell.setText("OLE Example"); shell.setLayout(new FillLayout()); Composite parent = new Composite(shell, SWT.NONE); parent.setLayout(new GridLayout(4, true)); Composite buttons = new Composite(parent, SWT.NONE); buttons.setLayout(new GridLayout()); GridData gridData = new GridData(SWT.BEGINNING, SWT.FILL, false, false); buttons.setLayoutData(gridData);/* w w w . ja v a2 s. c o m*/ Composite displayArea = new Composite(parent, SWT.BORDER); displayArea.setLayout(new FillLayout()); displayArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); Button excelButton = new Button(buttons, SWT.RADIO); excelButton.setText("New Excel Sheet"); excelButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { if (((Button) e.widget).getSelection()) newClientSite("Excel.Sheet"); })); Button mediaPlayerButton = new Button(buttons, SWT.RADIO); mediaPlayerButton.setText("New MPlayer"); mediaPlayerButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { if (((Button) e.widget).getSelection()) newClientSite("MPlayer"); })); Button powerPointButton = new Button(buttons, SWT.RADIO); powerPointButton.setText("New PowerPoint Slide"); powerPointButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { if (((Button) e.widget).getSelection()) newClientSite("PowerPoint.Slide"); })); Button wordButton = new Button(buttons, SWT.RADIO); wordButton.setText("New Word Document"); wordButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { if (((Button) e.widget).getSelection()) newClientSite("Word.Document"); })); new Label(buttons, SWT.NONE); Button openButton = new Button(buttons, SWT.RADIO); openButton.setText("Open file..."); openButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { if (((Button) e.widget).getSelection()) fileOpen(); })); new Label(buttons, SWT.NONE); closeButton = new Button(buttons, SWT.RADIO); closeButton.setText("Close file"); closeButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { if (((Button) e.widget).getSelection()) disposeClient(); })); closeButton.setSelection(true); oleFrame = new OleFrame(displayArea, SWT.NONE); addFileMenu(oleFrame); shell.setSize(800, 600); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }
From source file:AddressBook.java
/** * Creates the page contents/*from ww w. j av a 2s .co m*/ * * @param parent * the parent composite */ public void createControl(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); composite.setLayout(new GridLayout(2, false)); // Create the label and text field for first name new Label(composite, SWT.LEFT).setText("First Name:"); final Text first = new Text(composite, SWT.BORDER); first.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Create the label and text field for last name new Label(composite, SWT.LEFT).setText("Last Name:"); final Text last = new Text(composite, SWT.BORDER); last.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Add the handler to update the first name based on input first.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { firstName = first.getText(); setPageComplete(firstName.length() > 0 && lastName.length() > 0); } }); // Add the handler to update the last name based on input last.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent event) { lastName = last.getText(); setPageComplete(firstName.length() > 0 && lastName.length() > 0); } }); setControl(composite); }
From source file:ClipboardExample.java
void createFileTransfer(Composite copyParent, Composite pasteParent) { // File Transfer Label l = new Label(copyParent, SWT.NONE); l.setText("FileTransfer:"); //$NON-NLS-1$ Composite c = new Composite(copyParent, SWT.NONE); c.setLayout(new GridLayout(2, false)); GridData data = new GridData(GridData.FILL_HORIZONTAL); c.setLayoutData(data);/*from w w w. j a va 2s . c o m*/ copyFileTable = new Table(c, SWT.MULTI | SWT.BORDER); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; data.horizontalSpan = 2; copyFileTable.setLayoutData(data); Button b = new Button(c, SWT.PUSH); b.setText("Select file(s)"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI); String result = dialog.open(); if (result != null && result.length() > 0) { // copyFileTable.removeAll(); String separator = System.getProperty("file.separator"); String path = dialog.getFilterPath(); String[] names = dialog.getFileNames(); for (int i = 0; i < names.length; i++) { TableItem item = new TableItem(copyFileTable, SWT.NONE); item.setText(path + separator + names[i]); } } } }); b = new Button(c, SWT.PUSH); b.setText("Select directory"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN); String result = dialog.open(); if (result != null && result.length() > 0) { // copyFileTable.removeAll(); TableItem item = new TableItem(copyFileTable, SWT.NONE); item.setText(result); } } }); b = new Button(copyParent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { TableItem[] items = copyFileTable.getItems(); if (items.length > 0) { status.setText(""); String[] data = new String[items.length]; for (int i = 0; i < data.length; i++) { data[i] = items[i].getText(); } clipboard.setContents(new Object[] { data }, new Transfer[] { FileTransfer.getInstance() }); } else { status.setText("nothing to copy"); } } }); l = new Label(pasteParent, SWT.NONE); l.setText("FileTransfer:"); //$NON-NLS-1$ pasteFileTable = new Table(pasteParent, SWT.MULTI | SWT.BORDER); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; pasteFileTable.setLayoutData(data); b = new Button(pasteParent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String[] data = (String[]) clipboard.getContents(FileTransfer.getInstance()); if (data != null && data.length > 0) { status.setText(""); pasteFileTable.removeAll(); for (int i = 0; i < data.length; i++) { TableItem item = new TableItem(pasteFileTable, SWT.NONE); item.setText(data[i]); } } else { status.setText("nothing to paste"); } } }); }
From source file:AddressBookDemo.java
private void createLine(Composite parent, int ncol) { Label line = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.BOLD); GridData gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.horizontalSpan = ncol;//from ww w . j av a 2 s. com line.setLayoutData(gridData); }
From source file:org.eclipse.swt.examples.layoutexample.FormLayoutTab.java
/** * Creates the control widgets.// w ww .j a va 2s . c o m */ @Override void createControlWidgets() { /* Controls the margins and spacing of the FormLayout */ Group marginGroup = new Group(controlGroup, SWT.NONE); marginGroup.setText(LayoutExample.getResourceString("Margins_Spacing")); marginGroup.setLayout(new GridLayout(2, false)); marginGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); new Label(marginGroup, SWT.NONE).setText("marginWidth"); marginWidth = new Spinner(marginGroup, SWT.BORDER); marginWidth.setSelection(0); marginWidth.addSelectionListener(selectionListener); new Label(marginGroup, SWT.NONE).setText("marginHeight"); marginHeight = new Spinner(marginGroup, SWT.BORDER); marginHeight.setSelection(0); marginHeight.addSelectionListener(selectionListener); new Label(marginGroup, SWT.NONE).setText("marginLeft"); marginLeft = new Spinner(marginGroup, SWT.BORDER); marginLeft.setSelection(0); marginLeft.addSelectionListener(selectionListener); new Label(marginGroup, SWT.NONE).setText("marginRight"); marginRight = new Spinner(marginGroup, SWT.BORDER); marginRight.setSelection(0); marginRight.addSelectionListener(selectionListener); new Label(marginGroup, SWT.NONE).setText("marginTop"); marginTop = new Spinner(marginGroup, SWT.BORDER); marginTop.setSelection(0); marginTop.addSelectionListener(selectionListener); new Label(marginGroup, SWT.NONE).setText("marginBottom"); marginBottom = new Spinner(marginGroup, SWT.BORDER); marginBottom.setSelection(0); marginBottom.addSelectionListener(selectionListener); new Label(marginGroup, SWT.NONE).setText("spacing"); spacing = new Spinner(marginGroup, SWT.BORDER); spacing.setSelection(0); spacing.addSelectionListener(selectionListener); /* Add common controls */ super.createControlWidgets(); }
From source file:org.eclipse.swt.examples.clipboard.ClipboardExample.java
void createHTMLTransfer(Composite copyParent, Composite pasteParent) { // HTML Transfer Label l = new Label(copyParent, SWT.NONE); l.setText("HTMLTransfer:"); //$NON-NLS-1$ final Text copyHtmlText = new Text(copyParent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); copyHtmlText.setText("<b>Hello World</b>"); GridData data = new GridData(GridData.FILL_BOTH); data.widthHint = HSIZE;//from w w w.j av a 2 s. c o m data.heightHint = VSIZE; copyHtmlText.setLayoutData(data); Button b = new Button(copyParent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(widgetSelectedAdapter(e -> { String textData = copyHtmlText.getText(); if (textData.length() > 0) { status.setText(""); clipboard.setContents(new Object[] { textData }, new Transfer[] { HTMLTransfer.getInstance() }); } else { status.setText("No HTML to copy"); } })); l = new Label(pasteParent, SWT.NONE); l.setText("HTMLTransfer:"); //$NON-NLS-1$ final Text pasteHtmlText = new Text(pasteParent, SWT.READ_ONLY | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); data = new GridData(GridData.FILL_BOTH); data.widthHint = HSIZE; data.heightHint = VSIZE; pasteHtmlText.setLayoutData(data); b = new Button(pasteParent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(widgetSelectedAdapter(e -> { String textData = (String) clipboard.getContents(HTMLTransfer.getInstance()); if (textData != null && textData.length() > 0) { status.setText(""); pasteHtmlText.setText("start paste>" + textData + "<end paste"); } else { status.setText("No HTML to paste"); } })); }
From source file:GraphicsExample.java
void createToolBar(final Composite parent) { final Display display = parent.getDisplay(); toolBar = new ToolBar(parent, SWT.FLAT); Listener toolBarListener = new Listener() { public void handleEvent(Event event) { switch (event.type) { case SWT.Selection: { if (event.widget == playItem) { animate = true;//from w w w . j a va2 s . c o m playItem.setEnabled(!animate); pauseItem.setEnabled(animate); } else if (event.widget == pauseItem) { animate = false; playItem.setEnabled(!animate); pauseItem.setEnabled(animate); } else if (event.widget == backItem) { final ToolItem toolItem = (ToolItem) event.widget; final ToolBar toolBar = toolItem.getParent(); Rectangle toolItemBounds = toolItem.getBounds(); Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y)); backMenu.setLocation(point.x, point.y + toolItemBounds.height); backMenu.setVisible(true); } } break; } } }; playItem = new ToolItem(toolBar, SWT.PUSH); playItem.setText(getResourceString("Play")); //$NON-NLS-1$ playItem.setImage(loadImage(display, "play.gif")); //$NON-NLS-1$ playItem.addListener(SWT.Selection, toolBarListener); pauseItem = new ToolItem(toolBar, SWT.PUSH); pauseItem.setText(getResourceString("Pause")); //$NON-NLS-1$ pauseItem.setImage(loadImage(display, "pause.gif")); //$NON-NLS-1$ pauseItem.addListener(SWT.Selection, toolBarListener); backItem = new ToolItem(toolBar, SWT.PUSH); backItem.setText(getResourceString("Background")); //$NON-NLS-1$ backItem.addListener(SWT.Selection, toolBarListener); String[] names = new String[] { getResourceString("White"), //$NON-NLS-1$ getResourceString("Black"), //$NON-NLS-1$ getResourceString("Red"), //$NON-NLS-1$ getResourceString("Green"), //$NON-NLS-1$ getResourceString("Blue"), //$NON-NLS-1$ getResourceString("CustomColor"), //$NON-NLS-1$ }; Color[] colors = new Color[] { display.getSystemColor(SWT.COLOR_WHITE), display.getSystemColor(SWT.COLOR_BLACK), display.getSystemColor(SWT.COLOR_RED), display.getSystemColor(SWT.COLOR_GREEN), display.getSystemColor(SWT.COLOR_BLUE), null, }; backMenu = new Menu(parent); Listener listener = new Listener() { public void handleEvent(Event event) { MenuItem item = (MenuItem) event.widget; if (customMI == item) { ColorDialog dialog = new ColorDialog(parent.getShell()); RGB rgb = dialog.open(); if (rgb == null) return; if (customColor != null) customColor.dispose(); customColor = new Color(display, rgb); if (customImage != null) customImage.dispose(); customImage = createImage(display, customColor); item.setData(new Object[] { customColor, customImage }); item.setImage(customImage); } tabBackground = (Object[]) item.getData(); backItem.setImage((Image) tabBackground[1]); canvas.redraw(); } }; for (int i = 0; i < names.length; i++) { MenuItem item = new MenuItem(backMenu, SWT.NONE); item.setText(names[i]); item.addListener(SWT.Selection, listener); Image image = null; if (colors[i] != null) { image = createImage(display, colors[i]); images.addElement(image); item.setImage(image); } else { // custom menu item customMI = item; } item.setData(new Object[] { colors[i], image }); if (tabBackground == null) { tabBackground = (Object[]) item.getData(); backItem.setImage((Image) tabBackground[1]); } } dbItem = new ToolItem(toolBar, SWT.CHECK); dbItem.setText(getResourceString("DoubleBuffer")); //$NON-NLS-1$ dbItem.setImage(loadImage(display, "db.gif")); //$NON-NLS-1$ ToolItem separator = new ToolItem(toolBar, SWT.SEPARATOR); Composite comp = new Composite(toolBar, SWT.NONE); GridData data; GridLayout layout = new GridLayout(1, false); layout.verticalSpacing = 0; layout.marginWidth = layout.marginHeight = 3; comp.setLayout(layout); timerSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP); data = new GridData(SWT.CENTER, SWT.CENTER, false, false); timerSpinner.setLayoutData(data); Label label = new Label(comp, SWT.NONE); label.setText(getResourceString("Animation")); //$NON-NLS-1$ data = new GridData(SWT.CENTER, SWT.CENTER, false, false); label.setLayoutData(data); timerSpinner.setMaximum(1000); timerSpinner.setSelection(TIMER); timerSpinner.setSelection(TIMER); separator.setControl(comp); separator.setWidth(comp.computeSize(SWT.DEFAULT, SWT.DEFAULT).x); }
From source file:org.eclipse.swt.examples.layoutexample.GridLayoutTab.java
/** * Creates the control widgets./*from w w w.j a va2 s . c om*/ */ @Override void createControlWidgets() { /* Controls the columns in the GridLayout */ Group columnGroup = new Group(controlGroup, SWT.NONE); columnGroup.setText(LayoutExample.getResourceString("Columns")); columnGroup.setLayout(new GridLayout(2, false)); columnGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); new Label(columnGroup, SWT.NONE).setText("numColumns"); numColumns = new Spinner(columnGroup, SWT.BORDER); numColumns.setMinimum(1); numColumns.addSelectionListener(selectionListener); makeColumnsEqualWidth = new Button(columnGroup, SWT.CHECK); makeColumnsEqualWidth.setText("makeColumnsEqualWidth"); makeColumnsEqualWidth.addSelectionListener(selectionListener); makeColumnsEqualWidth.setEnabled(false); makeColumnsEqualWidth.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)); /* Controls the margins and spacing of the GridLayout */ Group marginGroup = new Group(controlGroup, SWT.NONE); marginGroup.setText(LayoutExample.getResourceString("Margins_Spacing")); marginGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); marginGroup.setLayout(new GridLayout(2, false)); new Label(marginGroup, SWT.NONE).setText("marginWidth"); marginWidth = new Spinner(marginGroup, SWT.BORDER); marginWidth.setSelection(5); marginWidth.addSelectionListener(selectionListener); new Label(marginGroup, SWT.NONE).setText("marginHeight"); marginHeight = new Spinner(marginGroup, SWT.BORDER); marginHeight.setSelection(5); marginHeight.addSelectionListener(selectionListener); new Label(marginGroup, SWT.NONE).setText("marginLeft"); marginLeft = new Spinner(marginGroup, SWT.BORDER); marginLeft.setSelection(0); marginLeft.addSelectionListener(selectionListener); new Label(marginGroup, SWT.NONE).setText("marginRight"); marginRight = new Spinner(marginGroup, SWT.BORDER); marginRight.setSelection(0); marginRight.addSelectionListener(selectionListener); new Label(marginGroup, SWT.NONE).setText("marginTop"); marginTop = new Spinner(marginGroup, SWT.BORDER); marginTop.setSelection(0); marginTop.addSelectionListener(selectionListener); new Label(marginGroup, SWT.NONE).setText("marginBottom"); marginBottom = new Spinner(marginGroup, SWT.BORDER); marginBottom.setSelection(0); marginBottom.addSelectionListener(selectionListener); new Label(marginGroup, SWT.NONE).setText("horizontalSpacing"); horizontalSpacing = new Spinner(marginGroup, SWT.BORDER); horizontalSpacing.setSelection(5); horizontalSpacing.addSelectionListener(selectionListener); new Label(marginGroup, SWT.NONE).setText("verticalSpacing"); verticalSpacing = new Spinner(marginGroup, SWT.BORDER); verticalSpacing.setSelection(5); verticalSpacing.addSelectionListener(selectionListener); /* Add common controls */ super.createControlWidgets(); controlGroup.pack(); }
From source file:ImageAnalyzer.java
void createWidgets() { // Add the widgets to the shell in a grid layout. GridLayout layout = new GridLayout(); layout.marginHeight = 0;//from ww w . j a v a 2s . c o m layout.numColumns = 2; shell.setLayout(layout); // Separate the menu bar from the rest of the widgets. Label separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL); GridData gridData = new GridData(); gridData.horizontalSpan = 2; gridData.horizontalAlignment = GridData.FILL; separator.setLayoutData(gridData); // Add a composite to contain some control widgets across the top. Composite controls = new Composite(shell, SWT.NULL); RowLayout rowLayout = new RowLayout(); rowLayout.marginTop = 0; rowLayout.marginBottom = 5; rowLayout.spacing = 8; controls.setLayout(rowLayout); gridData = new GridData(); gridData.horizontalSpan = 2; controls.setLayoutData(gridData); // Combo to change the background. Group group = new Group(controls, SWT.NULL); group.setLayout(new RowLayout()); group.setText("Background"); backgroundCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY); backgroundCombo.setItems(new String[] { "None", "White", "Black", "Red", "Green", "Blue" }); backgroundCombo.select(backgroundCombo.indexOf("White")); backgroundCombo.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { changeBackground(); } }); // Combo to change the x scale. String[] values = { "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9", "1", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2", "3", "4", "5", "6", "7", "8", "9", "10", }; group = new Group(controls, SWT.NULL); group.setLayout(new RowLayout()); group.setText("X_scale"); scaleXCombo = new Combo(group, SWT.DROP_DOWN); for (int i = 0; i < values.length; i++) { scaleXCombo.add(values[i]); } scaleXCombo.select(scaleXCombo.indexOf("1")); scaleXCombo.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { scaleX(); } }); // Combo to change the y scale. group = new Group(controls, SWT.NULL); group.setLayout(new RowLayout()); group.setText("Y_scale"); scaleYCombo = new Combo(group, SWT.DROP_DOWN); for (int i = 0; i < values.length; i++) { scaleYCombo.add(values[i]); } scaleYCombo.select(scaleYCombo.indexOf("1")); scaleYCombo.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { scaleY(); } }); // Combo to change the alpha value. group = new Group(controls, SWT.NULL); group.setLayout(new RowLayout()); group.setText("Alpha_K"); alphaCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY); for (int i = 0; i <= 255; i += 5) { alphaCombo.add(String.valueOf(i)); } alphaCombo.select(alphaCombo.indexOf("255")); alphaCombo.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { alpha(); } }); // Check box to request incremental display. group = new Group(controls, SWT.NULL); group.setLayout(new RowLayout()); group.setText("Display"); incrementalCheck = new Button(group, SWT.CHECK); incrementalCheck.setText("Incremental"); incrementalCheck.setSelection(incremental); incrementalCheck.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { incremental = ((Button) event.widget).getSelection(); } }); // Check box to request transparent display. transparentCheck = new Button(group, SWT.CHECK); transparentCheck.setText("Transparent"); transparentCheck.setSelection(transparent); transparentCheck.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { transparent = ((Button) event.widget).getSelection(); if (image != null) { imageCanvas.redraw(); } } }); // Check box to request mask display. maskCheck = new Button(group, SWT.CHECK); maskCheck.setText("Mask"); maskCheck.setSelection(showMask); maskCheck.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { showMask = ((Button) event.widget).getSelection(); if (image != null) { imageCanvas.redraw(); } } }); // Check box to request background display. backgroundCheck = new Button(group, SWT.CHECK); backgroundCheck.setText("Background"); backgroundCheck.setSelection(showBackground); backgroundCheck.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { showBackground = ((Button) event.widget).getSelection(); } }); // Group the animation buttons. group = new Group(controls, SWT.NULL); group.setLayout(new RowLayout()); group.setText("Animation"); // Push button to display the previous image in a multi-image file. previousButton = new Button(group, SWT.PUSH); previousButton.setText("Previous"); previousButton.setEnabled(false); previousButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { previous(); } }); // Push button to display the next image in a multi-image file. nextButton = new Button(group, SWT.PUSH); nextButton.setText("Next"); nextButton.setEnabled(false); nextButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { next(); } }); // Push button to toggle animation of a multi-image file. animateButton = new Button(group, SWT.PUSH); animateButton.setText("Animate"); animateButton.setEnabled(false); animateButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { animate(); } }); // Label to show the image file type. typeLabel = new Label(shell, SWT.NULL); typeLabel.setText("Type_initial"); typeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Canvas to show the image. imageCanvas = new Canvas(shell, SWT.V_SCROLL | SWT.H_SCROLL | SWT.NO_REDRAW_RESIZE); imageCanvas.setBackground(whiteColor); imageCanvas.setCursor(crossCursor); gridData = new GridData(); gridData.verticalSpan = 15; gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.grabExcessVerticalSpace = true; imageCanvas.setLayoutData(gridData); imageCanvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent event) { if (image != null) paintImage(event); } }); imageCanvas.addMouseMoveListener(new MouseMoveListener() { public void mouseMove(MouseEvent event) { if (image != null) { showColorAt(event.x, event.y); } } }); // Set up the image canvas scroll bars. ScrollBar horizontal = imageCanvas.getHorizontalBar(); horizontal.setVisible(true); horizontal.setMinimum(0); horizontal.setEnabled(false); horizontal.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { scrollHorizontally((ScrollBar) event.widget); } }); ScrollBar vertical = imageCanvas.getVerticalBar(); vertical.setVisible(true); vertical.setMinimum(0); vertical.setEnabled(false); vertical.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { scrollVertically((ScrollBar) event.widget); } }); // Label to show the image size. sizeLabel = new Label(shell, SWT.NULL); sizeLabel.setText("Size_initial"); sizeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the image depth. depthLabel = new Label(shell, SWT.NULL); depthLabel.setText("Depth_initial"); depthLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the transparent pixel. transparentPixelLabel = new Label(shell, SWT.NULL); transparentPixelLabel.setText("Transparent_pixel_initial"); transparentPixelLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the time to load. timeToLoadLabel = new Label(shell, SWT.NULL); timeToLoadLabel.setText("Time_to_load_initial"); timeToLoadLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Separate the animation fields from the rest of the fields. separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL); separator.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the logical screen size for animation. screenSizeLabel = new Label(shell, SWT.NULL); screenSizeLabel.setText("Animation_size_initial"); screenSizeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the background pixel. backgroundPixelLabel = new Label(shell, SWT.NULL); backgroundPixelLabel.setText("Background_pixel_initial"); backgroundPixelLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the image location (x, y). locationLabel = new Label(shell, SWT.NULL); locationLabel.setText("Image_location_initial"); locationLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the image disposal method. disposalMethodLabel = new Label(shell, SWT.NULL); disposalMethodLabel.setText("Disposal_initial"); disposalMethodLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the image delay time. delayTimeLabel = new Label(shell, SWT.NULL); delayTimeLabel.setText("Delay_initial"); delayTimeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the background pixel. repeatCountLabel = new Label(shell, SWT.NULL); repeatCountLabel.setText("Repeats_initial"); repeatCountLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Separate the animation fields from the palette. separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL); separator.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show if the image has a direct or indexed palette. paletteLabel = new Label(shell, SWT.NULL); paletteLabel.setText("Palette_initial"); paletteLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Canvas to show the image's palette. paletteCanvas = new Canvas(shell, SWT.BORDER | SWT.V_SCROLL | SWT.NO_REDRAW_RESIZE); paletteCanvas.setFont(fixedWidthFont); paletteCanvas.getVerticalBar().setVisible(true); gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; GC gc = new GC(paletteLabel); paletteWidth = gc.stringExtent("Max_length_string").x; gc.dispose(); gridData.widthHint = paletteWidth; gridData.heightHint = 16 * 11; // show at least 16 colors paletteCanvas.setLayoutData(gridData); paletteCanvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent event) { if (image != null) paintPalette(event); } }); // Set up the palette canvas scroll bar. vertical = paletteCanvas.getVerticalBar(); vertical.setVisible(true); vertical.setMinimum(0); vertical.setIncrement(10); vertical.setEnabled(false); vertical.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { scrollPalette((ScrollBar) event.widget); } }); // Sash to see more of image or image data. sash = new Sash(shell, SWT.HORIZONTAL); gridData = new GridData(); gridData.horizontalSpan = 2; gridData.horizontalAlignment = GridData.FILL; sash.setLayoutData(gridData); sash.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { if (event.detail != SWT.DRAG) { ((GridData) paletteCanvas.getLayoutData()).heightHint = SWT.DEFAULT; Rectangle paletteCanvasBounds = paletteCanvas.getBounds(); int minY = paletteCanvasBounds.y + 20; Rectangle dataLabelBounds = dataLabel.getBounds(); int maxY = statusLabel.getBounds().y - dataLabelBounds.height - 20; if (event.y > minY && event.y < maxY) { Rectangle oldSash = sash.getBounds(); sash.setBounds(event.x, event.y, event.width, event.height); int diff = event.y - oldSash.y; Rectangle bounds = imageCanvas.getBounds(); imageCanvas.setBounds(bounds.x, bounds.y, bounds.width, bounds.height + diff); bounds = paletteCanvasBounds; paletteCanvas.setBounds(bounds.x, bounds.y, bounds.width, bounds.height + diff); bounds = dataLabelBounds; dataLabel.setBounds(bounds.x, bounds.y + diff, bounds.width, bounds.height); bounds = dataText.getBounds(); dataText.setBounds(bounds.x, bounds.y + diff, bounds.width, bounds.height - diff); // shell.layout(true); } } } }); // Label to show data-specific fields. dataLabel = new Label(shell, SWT.NULL); dataLabel.setText("Pixel_data_initial"); gridData = new GridData(); gridData.horizontalSpan = 2; gridData.horizontalAlignment = GridData.FILL; dataLabel.setLayoutData(gridData); // Text to show a dump of the data. dataText = new StyledText(shell, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL); dataText.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); dataText.setFont(fixedWidthFont); gridData = new GridData(); gridData.horizontalSpan = 2; gridData.horizontalAlignment = GridData.FILL; gridData.verticalAlignment = GridData.FILL; gridData.heightHint = 128; gridData.grabExcessVerticalSpace = true; dataText.setLayoutData(gridData); dataText.addMouseListener(new MouseAdapter() { public void mouseDown(MouseEvent event) { if (image != null && event.button == 1) { showColorForData(); } } }); dataText.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent event) { if (image != null) { showColorForData(); } } }); // Label to show status and cursor location in image. statusLabel = new Label(shell, SWT.NULL); statusLabel.setText(""); gridData = new GridData(); gridData.horizontalSpan = 2; gridData.horizontalAlignment = GridData.FILL; statusLabel.setLayoutData(gridData); }
From source file:com.android.ddmuilib.HeapPanel.java
/** * Create our control(s)./*w w w .j ava 2s.co m*/ */ @Override protected Control createControl(Composite parent) { mDisplay = parent.getDisplay(); GridLayout gl; mTop = new Composite(parent, SWT.NONE); mTop.setLayout(new GridLayout(1, false)); mTop.setLayoutData(new GridData(GridData.FILL_BOTH)); mUpdateStatus = new Label(mTop, SWT.NONE); setUpdateStatus(NOT_SELECTED); Composite summarySection = new Composite(mTop, SWT.NONE); summarySection.setLayout(gl = new GridLayout(2, false)); gl.marginHeight = gl.marginWidth = 0; mHeapSummary = createSummaryTable(summarySection); mGcButton = new Button(summarySection, SWT.PUSH); mGcButton.setText("Cause GC"); mGcButton.setEnabled(false); mGcButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Client client = getCurrentClient(); if (client != null) { client.executeGarbageCollector(); } } }); Composite comboSection = new Composite(mTop, SWT.NONE); gl = new GridLayout(2, false); gl.marginHeight = gl.marginWidth = 0; comboSection.setLayout(gl); Label displayLabel = new Label(comboSection, SWT.NONE); displayLabel.setText("Display: "); mDisplayMode = new Combo(comboSection, SWT.READ_ONLY); mDisplayMode.setEnabled(false); mDisplayMode.add("Stats"); if (DISPLAY_HEAP_BITMAP) { mDisplayMode.add("Linear"); if (DISPLAY_HILBERT_BITMAP) { mDisplayMode.add("Hilbert"); } } // the base of the displays. mDisplayBase = new Composite(mTop, SWT.NONE); mDisplayBase.setLayoutData(new GridData(GridData.FILL_BOTH)); mDisplayStack = new StackLayout(); mDisplayBase.setLayout(mDisplayStack); // create the statistics display mStatisticsBase = new Composite(mDisplayBase, SWT.NONE); //mStatisticsBase.setLayoutData(new GridData(GridData.FILL_BOTH)); mStatisticsBase.setLayout(gl = new GridLayout(1, false)); gl.marginHeight = gl.marginWidth = 0; mDisplayStack.topControl = mStatisticsBase; mStatisticsTable = createDetailedTable(mStatisticsBase); mStatisticsTable.setLayoutData(new GridData(GridData.FILL_BOTH)); createChart(); //create the linear composite mLinearBase = new Composite(mDisplayBase, SWT.NONE); //mLinearBase.setLayoutData(new GridData()); gl = new GridLayout(1, false); gl.marginHeight = gl.marginWidth = 0; mLinearBase.setLayout(gl); { mLinearHeapImage = new Label(mLinearBase, SWT.NONE); mLinearHeapImage.setLayoutData(new GridData()); mLinearHeapImage.setImage(ImageLoader.createPlaceHolderArt(mDisplay, PLACEHOLDER_LINEAR_H_SIZE, PLACEHOLDER_LINEAR_V_SIZE, mDisplay.getSystemColor(SWT.COLOR_BLUE))); // create a composite to contain the bottom part (legend) Composite bottomSection = new Composite(mLinearBase, SWT.NONE); gl = new GridLayout(1, false); gl.marginHeight = gl.marginWidth = 0; bottomSection.setLayout(gl); createLegend(bottomSection); } /* mScrolledComposite = new ScrolledComposite(mTop, SWT.H_SCROLL | SWT.V_SCROLL); mScrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); mScrolledComposite.setExpandHorizontal(true); mScrolledComposite.setExpandVertical(true); mScrolledComposite.setContent(mDisplayBase); */ // create the hilbert display. mHilbertBase = new Composite(mDisplayBase, SWT.NONE); //mHilbertBase.setLayoutData(new GridData()); gl = new GridLayout(2, false); gl.marginHeight = gl.marginWidth = 0; mHilbertBase.setLayout(gl); if (DISPLAY_HILBERT_BITMAP) { mHilbertHeapImage = new Label(mHilbertBase, SWT.NONE); mHilbertHeapImage.setLayoutData(new GridData()); mHilbertHeapImage.setImage(ImageLoader.createPlaceHolderArt(mDisplay, PLACEHOLDER_HILBERT_SIZE, PLACEHOLDER_HILBERT_SIZE, mDisplay.getSystemColor(SWT.COLOR_BLUE))); // create a composite to contain the right part (legend + zoom) Composite rightSection = new Composite(mHilbertBase, SWT.NONE); gl = new GridLayout(1, false); gl.marginHeight = gl.marginWidth = 0; rightSection.setLayout(gl); Composite zoomComposite = new Composite(rightSection, SWT.NONE); gl = new GridLayout(2, false); zoomComposite.setLayout(gl); Label l = new Label(zoomComposite, SWT.NONE); l.setText("Zoom:"); mZoom = new Combo(zoomComposite, SWT.READ_ONLY); for (int z : ZOOMS) { mZoom.add(String.format("%1$d%%", z)); //$NON-NLS-1$ } mZoom.select(0); mZoom.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { setLegendText(mZoom.getSelectionIndex()); Client client = getCurrentClient(); if (client != null) { renderHeapData(client.getClientData(), 1, true); mTop.pack(); } } }); createLegend(rightSection); } mHilbertBase.pack(); mLayout = new Composite[] { mStatisticsBase, mLinearBase, mHilbertBase }; mDisplayMode.select(0); mDisplayMode.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { int index = mDisplayMode.getSelectionIndex(); Client client = getCurrentClient(); if (client != null) { if (index == 0) { fillDetailedTable(client, true /* forceRedraw */); } else { renderHeapData(client.getClientData(), index - 1, true /* forceRedraw */); } } mDisplayStack.topControl = mLayout[index]; //mScrolledComposite.setMinSize(mDisplayStack.topControl.computeSize(SWT.DEFAULT, // SWT.DEFAULT)); mDisplayBase.layout(); //mScrolledComposite.redraw(); } }); //mScrolledComposite.setMinSize(mDisplayStack.topControl.computeSize(SWT.DEFAULT, // SWT.DEFAULT)); mDisplayBase.layout(); //mScrolledComposite.redraw(); return mTop; }