List of usage examples for org.eclipse.swt.custom StyledText StyledText
public StyledText(Composite parent, int style)
From source file:org.eclipse.swt.snippets.Snippet365.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet365 - Transparent Background"); RowLayout layout = new RowLayout(SWT.VERTICAL); layout.spacing = 20;//from ww w.jav a2 s . c o m layout.marginWidth = 10; layout.marginHeight = 10; shell.setLayout(layout); // Standard color background for Shell // shell.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); // Gradient background for Shell shell.addListener(SWT.Resize, event -> { Rectangle rect = shell.getClientArea(); Image newImage = new Image(display, Math.max(1, rect.width), 1); GC gc = new GC(newImage); gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE)); gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN)); gc.fillGradientRectangle(rect.x, rect.y, rect.width, 1, false); gc.dispose(); shell.setBackgroundImage(newImage); if (oldImage != null) oldImage.dispose(); oldImage = newImage; }); // Transparent buttonCheckBox = new Button(shell, SWT.CHECK | SWT.None); buttonCheckBox.setText("SET TRANSPARENT"); buttonCheckBox.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); buttonCheckBox.setSelection(false); buttonCheckBox.addSelectionListener(widgetSelectedAdapter(e -> { boolean transparent = ((Button) e.getSource()).getSelection(); if (transparent) { // ContainerGroup containerGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); canvas.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); composite.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); tabFolder.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); for (TabItem item : tabFolder.getItems()) { item.getControl().setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); } // Native nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); toolBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); coolBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); label.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); link.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); scale.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); radio.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); check.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); group.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); sash.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); slider.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); list.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); // Custom customGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); cLabel.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); cTab.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT)); gradientCTab.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT)); sashForm.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT)); for (Control control : sashForm.getChildren()) { control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TRANSPARENT)); } // Default push.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); combo.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); progressBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); dateTime.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); ccombo.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); text.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); styledText.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); expandBar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); table.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); tree.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); // ItemGroup itemGroup.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT)); } else { // Native nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); toolBar.setBackground(null); coolBar.setBackground(null); label.setBackground(null); link.setBackground(null); scale.setBackground(null); RGB rgb = display.getSystemColor(SWT.COLOR_CYAN).getRGB(); radio.setBackground(new Color(display, new RGBA(rgb.red, rgb.blue, rgb.green, 255))); check.setBackgroundImage(getBackgroundImage(display)); group.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); sash.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN)); slider.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); list.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); text.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); // ContainerGroup containerGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); canvas.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); composite.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); tabFolder.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); for (TabItem item : tabFolder.getItems()) { item.getControl().setBackground(display.getSystemColor(SWT.COLOR_CYAN)); } // Custom customGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); cLabel.setBackground((Color) null); styledText.setBackground((Color) null); sashForm.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); for (Control control : sashForm.getChildren()) { control.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); } cTab.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); gradientCTab.setBackground(new Color[] { display.getSystemColor(SWT.COLOR_RED), display.getSystemColor(SWT.COLOR_WHITE) }, new int[] { 90 }, true); // Default defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); push.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); combo.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); ccombo.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); dateTime.setBackground(null); progressBar.setBackground(null); expandBar.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); table.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); tree.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); // ItemGroup itemGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); } })); // ContainerGroup containerGroup = new Composite(shell, SWT.NONE); containerGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); containerGroup.setToolTipText("CONTAINER"); layout = new RowLayout(); layout.spacing = 20; containerGroup.setLayout(layout); // Native nativeGroup = new Composite(shell, SWT.NONE); nativeGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); nativeGroup.setToolTipText("NATIVE"); layout = new RowLayout(); layout.spacing = 20; nativeGroup.setLayout(layout); // Custom customGroup = new Composite(shell, SWT.NONE); customGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); customGroup.setToolTipText("CUSTOM"); layout = new RowLayout(); layout.spacing = 20; customGroup.setLayout(layout); // AsDesigned defaultBackgroundGroup = new Composite(shell, SWT.NONE); defaultBackgroundGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); defaultBackgroundGroup.setToolTipText("Default Background"); layout = new RowLayout(); layout.spacing = 20; defaultBackgroundGroup.setLayout(layout); // ItemGroup itemGroup = new Composite(shell, SWT.NONE); itemGroup.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); itemGroup.setToolTipText("ITEM"); layout = new RowLayout(); layout.spacing = 20; itemGroup.setLayout(layout); // Label label = new Label(nativeGroup, SWT.NONE); label.setText("Label"); // Radio button radio = new Button(nativeGroup, SWT.RADIO); radio.setText("Radio Button"); radio.setSelection(true); radio.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); // Checkbox button with image check = new Button(nativeGroup, SWT.CHECK); check.setText("CheckBox Image"); check.setSelection(true); check.setBackgroundImage(getBackgroundImage(display)); // Push Button push = new Button(defaultBackgroundGroup, SWT.PUSH); push.setText("Push Button"); // Toolbar toolBar = new ToolBar(nativeGroup, SWT.FLAT); toolBar.pack(); ToolItem item = new ToolItem(toolBar, SWT.PUSH); item.setText("ToolBar_Item"); // Coolbar coolBar = new CoolBar(nativeGroup, SWT.BORDER); for (int i = 0; i < 2; i++) { CoolItem item2 = new CoolItem(coolBar, SWT.NONE); Button button = new Button(coolBar, SWT.PUSH); button.setText("Button " + i); Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT); item2.setPreferredSize(item2.computeSize(size.x, size.y)); item2.setControl(button); } // Scale scale = new Scale(nativeGroup, SWT.None); scale.setMaximum(100); scale.setSelection(20); // Link link = new Link(nativeGroup, SWT.NONE); link.setText("<a>Sample link</a>"); // List list = new List(nativeGroup, SWT.BORDER); list.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); list.add("List_one"); list.add("List_two"); list.add("List_three"); list.add("List_four"); // Canvas canvas = new Canvas(containerGroup, SWT.NONE); canvas.setToolTipText("Canvas"); canvas.addPaintListener(e -> { GC gc = e.gc; gc.setForeground(display.getSystemColor(SWT.COLOR_RED)); gc.drawRectangle(e.x + 1, e.y + 1, e.width - 2, e.height - 2); gc.drawArc(2, 2, e.width - 4, e.height - 4, 0, 360); }); // Composite composite = new Composite(containerGroup, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); composite.setToolTipText("Composite"); // TabFolder tabFolder = new TabFolder(containerGroup, SWT.BORDER); tabFolder.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); for (int i = 0; i < 2; i++) { TabItem tabItem = new TabItem(tabFolder, SWT.NONE); tabItem.setText("TabItem " + i); Label label = new Label(tabFolder, SWT.PUSH); label.setText("Page " + i); tabItem.setControl(label); tabItem.getControl().setBackground(display.getSystemColor(SWT.COLOR_CYAN)); } tabFolder.pack(); // Group group = new Group(containerGroup, SWT.NONE); group.setText("Group"); // Sash sash = new Sash(containerGroup, SWT.HORIZONTAL | SWT.BORDER); sash.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN)); sash.setLayoutData(new RowData(100, 100)); sash.setToolTipText("Sash"); // SashForm sashForm = new SashForm(containerGroup, SWT.HORIZONTAL | SWT.BORDER); Label leftLabel = new Label(sashForm, SWT.NONE); leftLabel.setText("SashForm\nLeft\n...\n...\n...\n...\n..."); Label rightLabel = new Label(sashForm, SWT.NONE); rightLabel.setText("SashForm\nRight\n...\n...\n...\n...\n..."); // DateTime dateTime = new DateTime(defaultBackgroundGroup, SWT.NONE); dateTime.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); // Text text = new Text(nativeGroup, SWT.BORDER); text.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); text.setText("text"); // ProgressBar progressBar = new ProgressBar(defaultBackgroundGroup, SWT.NONE); progressBar.setMaximum(100); progressBar.setSelection(80); // Combo combo = new Combo(defaultBackgroundGroup, SWT.BORDER); combo.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); combo.add("combo"); combo.setText("combo"); // Slider slider = new Slider(nativeGroup, SWT.HORIZONTAL | SWT.BORDER); slider.setSelection(20); slider.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); // CCombo ccombo = new CCombo(defaultBackgroundGroup, SWT.BORDER); ccombo.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); ccombo.add("ccombo"); ccombo.setText("ccombo"); // CLable cLabel = new CLabel(customGroup, SWT.NONE); cLabel.setText("CLabel"); // Text styledText = new StyledText(customGroup, SWT.BORDER); styledText.setFont(new Font(display, "Tahoma", 18, SWT.BOLD | SWT.ITALIC)); styledText.setForeground(display.getSystemColor(SWT.COLOR_DARK_BLUE)); styledText.setText("Styled Text"); styledText.append("\n"); styledText.append("Example_string"); styledText.append("\n"); styledText.append("One_Two"); styledText.append("\n"); styledText.append("Two_Three"); // CTabFolder cTab = new CTabFolder(containerGroup, SWT.BORDER); for (int i = 0; i < 2; i++) { CTabItem cTabItem = new CTabItem(cTab, SWT.CLOSE, i); cTabItem.setText("CTabItem " + (i + 1)); } cTab.setSelection(0); // Gradient CTabFolder gradientCTab = new CTabFolder(customGroup, SWT.BORDER); gradientCTab.setBackground( new Color[] { display.getSystemColor(SWT.COLOR_WHITE), display.getSystemColor(SWT.COLOR_RED) }, new int[] { 90 }, true); for (int i = 0; i < 2; i++) { CTabItem cTabItem = new CTabItem(gradientCTab, SWT.CLOSE, i); cTabItem.setText("CTabItem " + (i + 1)); } gradientCTab.setSelection(0); // Table table = new Table(itemGroup, SWT.V_SCROLL); table.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); table.setLinesVisible(true); table.setHeaderVisible(true); TableItem tableItem = new TableItem(table, SWT.NONE); tableItem.setText("TableItem - One"); tableItem = new TableItem(table, SWT.NONE); tableItem.setText("TableItem - Two"); // Tree tree = new Tree(itemGroup, SWT.NONE); TreeItem treeItem = new TreeItem(tree, SWT.NONE); treeItem.setText("Parent"); TreeItem childItem = new TreeItem(treeItem, SWT.NONE); childItem.setText("Child1"); childItem = new TreeItem(treeItem, SWT.NONE); childItem.setText("Child2"); treeItem.setExpanded(true); tree.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); // ExpandBar expandBar = new ExpandBar(itemGroup, SWT.V_SCROLL); expandBar.setBackground(display.getSystemColor(SWT.COLOR_CYAN)); for (int i = 1; i <= 2; i++) { ExpandItem item1 = new ExpandItem(expandBar, SWT.NONE, 0); item1.setText("Expand_Bar_Entry " + i); item1.setExpanded(true); item1.setHeight(20); } shell.open(); shell.pack(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:TextEditor.java
void createStyledText() { initializeColors();//from ww w .java 2s . com text = new StyledText(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); GridData spec = new GridData(); spec.horizontalAlignment = GridData.FILL; spec.grabExcessHorizontalSpace = true; spec.verticalAlignment = GridData.FILL; spec.grabExcessVerticalSpace = true; text.setLayoutData(spec); text.addExtendedModifyListener(new ExtendedModifyListener() { public void modifyText(ExtendedModifyEvent e) { handleExtendedModify(e); } }); }
From source file:org.eclipse.swt.examples.texteditor.TextEditor.java
public Shell open(Display display) { this.display = display; initResources();/*from w w w . j a v a2s. c o m*/ shell = new Shell(display); shell.setText(getResourceString("Window_title")); //$NON-NLS-1$ styledText = new StyledText(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); createMenuBar(); createToolBar(); createPopup(); statusBar = new Label(shell, SWT.NONE); installListeners(); updateToolBar(); updateStatusBar(); shell.setSize(1000, 700); shell.open(); return shell; }
From source file:org.eclipse.swt.examples.accessibility.ControlsWithAccessibleNamesExample.java
public static void main(String[] args) { display = new Display(); shell = new Shell(display); shell.setLayout(new GridLayout(4, true)); shell.setText("Override Accessibility Test"); largeImage = new Image(display, ControlsWithAccessibleNamesExample.class.getResourceAsStream("run_wiz.gif")); smallImage = new Image(display, ControlsWithAccessibleNamesExample.class.getResourceAsStream("run.gif")); ImageData source = smallImage.getImageData(); ImageData mask = source.getTransparencyMask(); transparentImage = new Image(display, source, mask); new Label(shell, SWT.NONE).setText("Use Platform Name"); new Label(shell, SWT.NONE).setText("Override Platform Name"); new Label(shell, SWT.NONE).setText("Use Platform Name"); new Label(shell, SWT.NONE).setText("Override Platform Name"); AccessibleAdapter overrideAccessibleAdapter = new AccessibleAdapter() { @Override/*from www. j a v a 2s . c om*/ public void getName(AccessibleEvent e) { Control control = ((Accessible) e.getSource()).getControl(); if (e.childID == ACC.CHILDID_SELF) { e.result = "Overriding Platform Name For " + control.getData("name") + " (was " + e.result + ")"; } else { e.result = "Overriding Platform Name For " + control.getData("child") + ": " + e.childID + " (was " + e.result + ")"; } } @Override public void getHelp(AccessibleEvent e) { Control control = ((Accessible) e.getSource()).getControl(); if (e.childID == ACC.CHILDID_SELF) { e.result = "Overriding Platform Help For " + control.getData("name") + " (was " + e.result + ")"; } else { e.result = "Overriding Platform Help For " + control.getData("child") + ": " + e.childID + " (was " + e.result + ")"; } } }; // Shell shell; shell.setData("name", "Shell"); shell.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Label label, overrideLabel; label = new Label(shell, SWT.BORDER); label.setText("Label"); label.setToolTipText("Label ToolTip"); overrideLabel = new Label(shell, SWT.BORDER); overrideLabel.setText("Label"); overrideLabel.setToolTipText("Label ToolTip"); overrideLabel.setData("name", "Label"); overrideLabel.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Label imageLabel, overrideImageLabel; imageLabel = new Label(shell, SWT.BORDER); imageLabel.setImage(largeImage); imageLabel.setToolTipText("Image Label ToolTip"); overrideImageLabel = new Label(shell, SWT.BORDER); overrideImageLabel.setImage(largeImage); overrideImageLabel.setToolTipText("Image Label ToolTip"); overrideImageLabel.setData("name", "Image Label"); overrideImageLabel.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Button button, overrideButton; button = new Button(shell, SWT.PUSH); button.setText("Button"); button.setToolTipText("Button ToolTip"); overrideButton = new Button(shell, SWT.PUSH); overrideButton.setText("Button"); overrideButton.setToolTipText("Button ToolTip"); overrideButton.setData("name", "Button"); overrideButton.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Button imageButton, overrideImageButton; imageButton = new Button(shell, SWT.PUSH); imageButton.setImage(smallImage); imageButton.setToolTipText("Image Button ToolTip"); overrideImageButton = new Button(shell, SWT.PUSH); overrideImageButton.setImage(smallImage); overrideImageButton.setToolTipText("Image Button ToolTip"); overrideImageButton.setData("name", "Image Button"); overrideImageButton.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Combo combo, overrideCombo; combo = new Combo(shell, SWT.BORDER); for (int i = 0; i < 5; i++) { combo.add("item" + i); } combo.setText("Combo"); combo.setToolTipText("Combo ToolTip"); overrideCombo = new Combo(shell, SWT.BORDER); for (int i = 0; i < 5; i++) { overrideCombo.add("item" + i); } overrideCombo.setText("Combo"); overrideCombo.setToolTipText("Combo ToolTip"); overrideCombo.setData("name", "Combo"); overrideCombo.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Spinner spinner, overrideSpinner; spinner = new Spinner(shell, SWT.BORDER); spinner.setSelection(5); spinner.setToolTipText("Spinner ToolTip"); overrideSpinner = new Spinner(shell, SWT.BORDER); overrideSpinner.setSelection(5); overrideSpinner.setToolTipText("Spinner ToolTip"); overrideSpinner.setData("name", "Spinner"); overrideSpinner.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Text text, overrideText; text = new Text(shell, SWT.SINGLE | SWT.BORDER); text.setText("Contents of single-line Text"); overrideText = new Text(shell, SWT.SINGLE | SWT.BORDER); overrideText.setText("Contents of single-line Text"); overrideText.setData("name", "Text"); overrideText.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Text multiLineText, overrideMultiLineText; multiLineText = new Text(shell, SWT.MULTI | SWT.BORDER); multiLineText.setText("Contents of multi-line Text\nLine 2\nLine 3\nLine 4"); overrideMultiLineText = new Text(shell, SWT.MULTI | SWT.BORDER); overrideMultiLineText.setText("Contents of multi-line Text\nLine 2\nLine 3\nLine 4"); overrideMultiLineText.setData("name", "MultiLineText"); overrideMultiLineText.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // List list, overrideList; list = new List(shell, SWT.SINGLE | SWT.BORDER); list.setItems("Item0", "Item1", "Item2"); overrideList = new List(shell, SWT.SINGLE | SWT.BORDER); overrideList.setItems("Item0", "Item1", "Item2"); overrideList.setData("name", "List"); overrideList.setData("child", "List Item"); overrideList.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Table table, overrideTable; table = new Table(shell, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); table.setHeaderVisible(true); table.setLinesVisible(true); for (int col = 0; col < 3; col++) { TableColumn column = new TableColumn(table, SWT.NONE); column.setText("Col " + col); column.pack(); } for (int row = 0; row < 3; row++) { TableItem item = new TableItem(table, SWT.NONE); item.setText(new String[] { "C0R" + row, "C1R" + row, "C2R" + row }); } overrideTable = new Table(shell, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); overrideTable.setHeaderVisible(true); overrideTable.setLinesVisible(true); for (int col = 0; col < 3; col++) { TableColumn column = new TableColumn(overrideTable, SWT.NONE); column.setText("Col " + col); column.pack(); } for (int row = 0; row < 3; row++) { TableItem item = new TableItem(overrideTable, SWT.NONE); item.setText(new String[] { "C0R" + row, "C1R" + row, "C2R" + row }); } overrideTable.setData("name", "Table"); overrideTable.setData("child", "Table Item"); overrideTable.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Tree tree, overrideTree; tree = new Tree(shell, SWT.BORDER | SWT.MULTI); for (int i = 0; i < 3; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText("Item" + i); for (int j = 0; j < 4; j++) { new TreeItem(item, SWT.NONE).setText("Item" + i + j); } } overrideTree = new Tree(shell, SWT.BORDER | SWT.MULTI); for (int i = 0; i < 3; i++) { TreeItem item = new TreeItem(overrideTree, SWT.NONE); item.setText("Item" + i); for (int j = 0; j < 4; j++) { new TreeItem(item, SWT.NONE).setText("Item" + i + j); } } overrideTree.setData("name", "Tree"); overrideTree.setData("child", "Tree Item"); overrideTree.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Tree treeTable, overrideTreeTable; treeTable = new Tree(shell, SWT.BORDER | SWT.MULTI); treeTable.setHeaderVisible(true); treeTable.setLinesVisible(true); for (int col = 0; col < 3; col++) { TreeColumn column = new TreeColumn(treeTable, SWT.NONE); column.setText("Col " + col); column.pack(); } for (int i = 0; i < 3; i++) { TreeItem item = new TreeItem(treeTable, SWT.NONE); item.setText(new String[] { "I" + i + "C0", "I" + i + "C1", "I" + i + "C2" }); for (int j = 0; j < 4; j++) { new TreeItem(item, SWT.NONE) .setText(new String[] { "I" + i + j + "C0", "I" + i + j + "C1", "I" + i + j + "C2" }); } } overrideTreeTable = new Tree(shell, SWT.BORDER | SWT.MULTI); overrideTreeTable.setHeaderVisible(true); overrideTreeTable.setLinesVisible(true); for (int col = 0; col < 3; col++) { TreeColumn column = new TreeColumn(overrideTreeTable, SWT.NONE); column.setText("Col " + col); column.pack(); } for (int i = 0; i < 3; i++) { TreeItem item = new TreeItem(overrideTreeTable, SWT.NONE); item.setText(new String[] { "I" + i + "C0", "I" + i + "C1", "I" + i + "C2" }); for (int j = 0; j < 4; j++) { new TreeItem(item, SWT.NONE) .setText(new String[] { "I" + i + j + "C0", "I" + i + j + "C1", "I" + i + j + "C2" }); } } overrideTreeTable.setData("name", "Tree Table"); overrideTreeTable.setData("child", "Tree Table Item"); overrideTreeTable.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // ToolBar toolBar, overrideToolBar; toolBar = new ToolBar(shell, SWT.FLAT); for (int i = 0; i < 3; i++) { ToolItem item = new ToolItem(toolBar, SWT.PUSH); item.setText("Item" + i); item.setToolTipText("ToolItem ToolTip" + i); } overrideToolBar = new ToolBar(shell, SWT.FLAT); for (int i = 0; i < 3; i++) { ToolItem item = new ToolItem(overrideToolBar, SWT.PUSH); item.setText("Item" + i); item.setToolTipText("ToolItem ToolTip" + i); } overrideToolBar.setData("name", "ToolBar"); overrideToolBar.setData("child", "ToolBar Item"); overrideToolBar.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // ToolBar imageToolBar, overrideImageToolBar; imageToolBar = new ToolBar(shell, SWT.FLAT); for (int i = 0; i < 3; i++) { ToolItem item = new ToolItem(imageToolBar, SWT.PUSH); item.setImage(transparentImage); item.setToolTipText("Image ToolItem ToolTip" + i); } overrideImageToolBar = new ToolBar(shell, SWT.FLAT); for (int i = 0; i < 3; i++) { ToolItem item = new ToolItem(overrideImageToolBar, SWT.PUSH); item.setImage(transparentImage); item.setToolTipText("Image ToolItem ToolTip" + i); } overrideImageToolBar.setData("name", "Image ToolBar"); overrideImageToolBar.setData("child", "Image ToolBar Item"); overrideImageToolBar.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // CoolBar coolBar, overrideCoolBar; coolBar = new CoolBar(shell, SWT.FLAT); for (int i = 0; i < 2; i++) { CoolItem coolItem = new CoolItem(coolBar, SWT.PUSH); ToolBar coolItemToolBar = new ToolBar(coolBar, SWT.FLAT); int toolItemWidth = 0; for (int j = 0; j < 2; j++) { ToolItem item = new ToolItem(coolItemToolBar, SWT.PUSH); item.setText("I" + i + j); item.setToolTipText("ToolItem ToolTip" + i + j); if (item.getWidth() > toolItemWidth) toolItemWidth = item.getWidth(); } coolItem.setControl(coolItemToolBar); Point size = coolItemToolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT); Point coolSize = coolItem.computeSize(size.x, size.y); coolItem.setMinimumSize(toolItemWidth, coolSize.y); coolItem.setPreferredSize(coolSize); coolItem.setSize(coolSize); } overrideCoolBar = new CoolBar(shell, SWT.FLAT); for (int i = 0; i < 2; i++) { CoolItem coolItem = new CoolItem(overrideCoolBar, SWT.PUSH); ToolBar coolItemToolBar = new ToolBar(overrideCoolBar, SWT.FLAT); int toolItemWidth = 0; for (int j = 0; j < 2; j++) { ToolItem item = new ToolItem(coolItemToolBar, SWT.PUSH); item.setText("I" + i + j); item.setToolTipText("ToolItem ToolTip" + i + j); if (item.getWidth() > toolItemWidth) toolItemWidth = item.getWidth(); } coolItem.setControl(coolItemToolBar); Point size = coolItemToolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT); Point coolSize = coolItem.computeSize(size.x, size.y); coolItem.setMinimumSize(toolItemWidth, coolSize.y); coolItem.setPreferredSize(coolSize); coolItem.setSize(coolSize); } overrideCoolBar.setData("name", "CoolBar"); overrideCoolBar.setData("child", "CoolBar Item"); overrideCoolBar.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Canvas canvas, overrideCanvas; canvas = new Canvas(shell, SWT.BORDER); canvas.addPaintListener(e -> e.gc.drawString("Canvas", 15, 25)); /* Set a caret into the canvas so that it will take focus. */ Caret caret = new Caret(canvas, SWT.NONE); caret.setBounds(15, 25, 2, 20); canvas.setCaret(caret); /* Hook key listener so canvas will take focus during traversal in. */ canvas.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { e.doit = true; } @Override public void keyReleased(KeyEvent e) { e.doit = true; } }); /* Hook traverse listener to make canvas give up focus during traversal out. */ canvas.addTraverseListener(e -> e.doit = true); overrideCanvas = new Canvas(shell, SWT.BORDER); overrideCanvas.addPaintListener(e -> e.gc.drawString("Canvas", 15, 25)); /* Set a caret into the canvas so that it will take focus. */ caret = new Caret(overrideCanvas, SWT.NONE); caret.setBounds(15, 25, 2, 20); overrideCanvas.setCaret(caret); /* Hook key listener so canvas will take focus during traversal in. */ overrideCanvas.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { e.doit = true; } @Override public void keyReleased(KeyEvent e) { e.doit = true; } }); /* Hook traverse listener to make canvas give up focus during traversal out. */ overrideCanvas.addTraverseListener(e -> e.doit = true); overrideCanvas.setData("name", "Canvas"); overrideCanvas.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Composite composite, overrideComposite; composite = new Composite(shell, SWT.BORDER); composite.setLayout(new GridLayout()); new Button(composite, SWT.RADIO).setText("Child 1"); new Button(composite, SWT.RADIO).setText("Child 2"); overrideComposite = new Composite(shell, SWT.BORDER); overrideComposite.setLayout(new GridLayout()); new Button(overrideComposite, SWT.RADIO).setText("Child 1"); new Button(overrideComposite, SWT.RADIO).setText("Child 2"); overrideComposite.setData("name", "Composite"); overrideComposite.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Group group, overrideGroup; group = new Group(shell, SWT.NONE); group.setText("Group"); group.setLayout(new FillLayout()); new Text(group, SWT.SINGLE).setText("Text in Group"); overrideGroup = new Group(shell, SWT.NONE); overrideGroup.setText("Group"); overrideGroup.setLayout(new FillLayout()); new Text(overrideGroup, SWT.SINGLE).setText("Text in Group"); overrideGroup.setData("name", "Group"); overrideGroup.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // TabFolder tabFolder, overrideTabFolder; tabFolder = new TabFolder(shell, SWT.NONE); for (int i = 0; i < 3; i++) { TabItem item = new TabItem(tabFolder, SWT.NONE); item.setText("TabItem &" + i); item.setToolTipText("TabItem ToolTip" + i); Text itemText = new Text(tabFolder, SWT.MULTI | SWT.BORDER); itemText.setText("\nText for TabItem " + i + "\n\n"); item.setControl(itemText); } overrideTabFolder = new TabFolder(shell, SWT.NONE); for (int i = 0; i < 3; i++) { TabItem item = new TabItem(overrideTabFolder, SWT.NONE); item.setText("TabItem &" + i); item.setToolTipText("TabItem ToolTip" + i); Text itemText = new Text(overrideTabFolder, SWT.MULTI | SWT.BORDER); itemText.setText("\nText for TabItem " + i + "\n\n"); item.setControl(itemText); } overrideTabFolder.setData("name", "TabFolder"); overrideTabFolder.setData("child", "TabItem"); overrideTabFolder.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // CLabel cLabel, overrideCLabel; cLabel = new CLabel(shell, SWT.BORDER); cLabel.setText("CLabel"); cLabel.setToolTipText("CLabel ToolTip"); cLabel.setLayoutData(new GridData(100, SWT.DEFAULT)); overrideCLabel = new CLabel(shell, SWT.BORDER); overrideCLabel.setText("CLabel"); overrideCLabel.setToolTipText("CLabel ToolTip"); overrideCLabel.setLayoutData(new GridData(100, SWT.DEFAULT)); overrideCLabel.setData("name", "CLabel"); overrideCLabel.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // CCombo cCombo, overrideCCombo; cCombo = new CCombo(shell, SWT.BORDER); for (int i = 0; i < 5; i++) { cCombo.add("item" + i); } cCombo.setText("CCombo"); cCombo.setToolTipText("CCombo ToolTip"); // Note: This doesn't work well because CCombo has Control children overrideCCombo = new CCombo(shell, SWT.BORDER); for (int i = 0; i < 5; i++) { overrideCCombo.add("item" + i); } overrideCCombo.setText("CCombo"); overrideCCombo.setToolTipText("CCombo ToolTip"); overrideCCombo.setData("name", "CCombo"); overrideCCombo.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // CTabFolder cTabFolder, overrideCTabFolder; cTabFolder = new CTabFolder(shell, SWT.NONE); for (int i = 0; i < 3; i++) { CTabItem item = new CTabItem(cTabFolder, SWT.NONE); item.setText("CTabItem &" + i); item.setToolTipText("TabItem ToolTip" + i); Text itemText = new Text(cTabFolder, SWT.MULTI | SWT.BORDER); itemText.setText("\nText for CTabItem " + i + "\n\n"); item.setControl(itemText); } cTabFolder.setSelection(cTabFolder.getItem(0)); overrideCTabFolder = new CTabFolder(shell, SWT.NONE); for (int i = 0; i < 3; i++) { CTabItem item = new CTabItem(overrideCTabFolder, SWT.NONE); item.setText("CTabItem &" + i); item.setToolTipText("TabItem ToolTip" + i); Text itemText = new Text(overrideCTabFolder, SWT.MULTI | SWT.BORDER); itemText.setText("\nText for CTabItem " + i + "\n\n"); item.setControl(itemText); } overrideCTabFolder.setSelection(overrideCTabFolder.getItem(0)); overrideCTabFolder.setData("name", "CTabFolder"); overrideCTabFolder.setData("child", "CTabItem"); overrideCTabFolder.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // StyledText styledText, overrideStyledText; styledText = new StyledText(shell, SWT.SINGLE | SWT.BORDER); styledText.setText("Contents of single-line StyledText"); overrideStyledText = new StyledText(shell, SWT.SINGLE | SWT.BORDER); overrideStyledText.setText("Contents of single-line StyledText"); overrideStyledText.setData("name", "StyledText"); overrideStyledText.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // StyledText multiLineStyledText, overrideMultiLineStyledText; multiLineStyledText = new StyledText(shell, SWT.MULTI | SWT.BORDER); multiLineStyledText.setText("Contents of multi-line StyledText\nLine 2\nLine 3\nLine 4"); overrideMultiLineStyledText = new StyledText(shell, SWT.MULTI | SWT.BORDER); overrideMultiLineStyledText.setText("Contents of multi-line StyledText\nLine 2\nLine 3\nLine 4"); overrideMultiLineStyledText.setData("name", "MultiLineStyledText"); overrideMultiLineStyledText.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Scale scale, overrideScale; scale = new Scale(shell, SWT.NONE); scale.setToolTipText("Scale ToolTip"); overrideScale = new Scale(shell, SWT.NONE); overrideScale.setToolTipText("Scale ToolTip"); overrideScale.setData("name", "Scale"); overrideScale.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Slider slider, overrideSlider; slider = new Slider(shell, SWT.NONE); slider.setToolTipText("Slider ToolTip"); overrideSlider = new Slider(shell, SWT.NONE); overrideSlider.setToolTipText("Slider ToolTip"); overrideSlider.setData("name", "Slider"); overrideSlider.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // ProgressBar progressBar, overrideProgressBar; if (!SWT.getPlatform().equals("cocoa")) { progressBar = new ProgressBar(shell, SWT.NONE); progressBar.setSelection(50); progressBar.setToolTipText("ProgressBar ToolTip"); overrideProgressBar = new ProgressBar(shell, SWT.NONE); overrideProgressBar.setSelection(50); overrideProgressBar.setToolTipText("ProgressBar ToolTip"); overrideProgressBar.setData("name", "ProgressBar"); overrideProgressBar.getAccessible().addAccessibleListener(overrideAccessibleAdapter); } // Sash sash, overrideSash; sash = new Sash(shell, SWT.BORDER); sash.setToolTipText("Sash ToolTip"); overrideSash = new Sash(shell, SWT.BORDER); overrideSash.setToolTipText("Sash ToolTip"); overrideSash.setData("name", "Sash"); overrideSash.getAccessible().addAccessibleListener(overrideAccessibleAdapter); // Link link, overrideLink; link = new Link(shell, SWT.NONE); link.setText("<a>This is a link</a>"); link.setToolTipText("Link ToolTip"); overrideLink = new Link(shell, SWT.NONE); overrideLink.setText("<a>This is a link</a>"); overrideLink.setToolTipText("Link ToolTip"); overrideLink.setData("name", "Link"); overrideLink.getAccessible().addAccessibleListener(overrideAccessibleAdapter); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } largeImage.dispose(); smallImage.dispose(); transparentImage.dispose(); display.dispose(); }
From source file:LayoutExample.java
/** * Creates the "control" widget children. Subclasses override this method to * augment the standard controls created. *//*from w w w . j a v a2 s. co m*/ void createControlWidgets() { createChildGroup(); code = new Button(controlGroup, SWT.PUSH); code.setText(LayoutExample.getResourceString("Code")); GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.GRAB_HORIZONTAL); gridData.horizontalSpan = 2; code.setLayoutData(gridData); code.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { final Shell shell = new Shell(); shell.setText(LayoutExample.getResourceString("Generated_Code")); shell.setLayout(new FillLayout()); final StyledText text = new StyledText(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); String layoutCode = generateCode().toString(); if (layoutCode.length() == 0) return; text.setText(layoutCode); Menu bar = new Menu(shell, SWT.BAR); shell.setMenuBar(bar); MenuItem editItem = new MenuItem(bar, SWT.CASCADE); editItem.setText(LayoutExample.getResourceString("Edit")); Menu menu = new Menu(bar); MenuItem select = new MenuItem(menu, SWT.PUSH); select.setText(LayoutExample.getResourceString("Select_All")); select.setAccelerator(SWT.MOD1 + 'A'); select.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { text.selectAll(); } }); MenuItem copy = new MenuItem(menu, SWT.PUSH); copy.setText(LayoutExample.getResourceString("Copy")); copy.setAccelerator(SWT.MOD1 + 'C'); copy.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { text.copy(); } }); MenuItem exit = new MenuItem(menu, SWT.PUSH); exit.setText(LayoutExample.getResourceString("Exit")); exit.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { shell.close(); } }); editItem.setMenu(menu); shell.pack(); shell.setSize(400, 500); shell.open(); Display display = shell.getDisplay(); while (!shell.isDisposed()) if (!display.readAndDispatch()) display.sleep(); } }); }
From source file:org.eclipse.swt.snippets.SnippetExplorer.java
/** Initialize the SnippetExplorer controls. * * @param shell parent shell//from w w w . ja v a 2 s . c o m */ private void createControls(Shell shell) { shell.setLayout(new FormLayout()); if (listUpdater == null) { listUpdater = new ListUpdater(); listUpdater.start(); } final Composite leftContainer = new Composite(shell, SWT.NONE); leftContainer.setLayout(new GridLayout()); final Sash splitter = new Sash(shell, SWT.BORDER | SWT.VERTICAL); final int splitterWidth = 3; splitter.addListener(SWT.Selection, e -> splitter.setBounds(e.x, e.y, e.width, e.height)); final Composite rightContainer = new Composite(shell, SWT.NONE); rightContainer.setLayout(new GridLayout()); FormData formData = new FormData(); formData.left = new FormAttachment(0, 0); formData.right = new FormAttachment(splitter, 0); formData.top = new FormAttachment(0, 0); formData.bottom = new FormAttachment(100, 0); leftContainer.setLayoutData(formData); formData = new FormData(); formData.left = new FormAttachment(50, 0); formData.right = new FormAttachment(50, splitterWidth); formData.top = new FormAttachment(0, 0); formData.bottom = new FormAttachment(100, 0); splitter.setLayoutData(formData); splitter.addListener(SWT.Selection, event -> { final FormData splitterFormData = (FormData) splitter.getLayoutData(); splitterFormData.left = new FormAttachment(0, event.x); splitterFormData.right = new FormAttachment(0, event.x + splitterWidth); shell.layout(); }); formData = new FormData(); formData.left = new FormAttachment(splitter, 0); formData.right = new FormAttachment(100, 0); formData.top = new FormAttachment(0, 0); formData.bottom = new FormAttachment(100, 0); rightContainer.setLayoutData(formData); filterField = new Text(leftContainer, SWT.SINGLE | SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL); filterField.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); filterField.setMessage(FILTER_HINT); filterField.addListener(SWT.Modify, event -> { listUpdater.updateInMs(FILTER_DELAY_MS); }); snippetTable = new Table(leftContainer, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION); snippetTable.setLinesVisible(true); snippetTable.setHeaderVisible(true); final GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); data.heightHint = 500; snippetTable.setLayoutData(data); snippetTable.addListener(SWT.MouseDoubleClick, event -> { final Point clickPoint = new Point(event.x, event.y); launchSnippet(snippetTable.getItem(clickPoint)); }); snippetTable.addListener(SWT.KeyUp, event -> { if (event.keyCode == '\r' || event.keyCode == '\n') { launchSnippet(snippetTable.getSelection()); } }); final Composite buttonRow = new Composite(leftContainer, SWT.NONE); buttonRow.setLayout(new GridLayout(3, false)); buttonRow.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); startSelectedButton = new Button(buttonRow, SWT.LEAD); startSelectedButton.setText(" Start &selected Snippets"); snippetTable.addListener(SWT.Selection, event -> { startSelectedButton.setEnabled(snippetTable.getSelectionCount() > 0); updateInfoTab(snippetTable.getSelection()); }); startSelectedButton.setEnabled(snippetTable.getSelectionCount() > 0); startSelectedButton.addListener(SWT.Selection, event -> { launchSnippet(snippetTable.getSelection()); }); final Label runnerLabel = new Label(buttonRow, SWT.NONE); runnerLabel.setText("Snippet Runner:"); runnerLabel.setLayoutData(new GridData(SWT.TRAIL, SWT.CENTER, true, false)); runnerCombo = new Combo(buttonRow, SWT.TRAIL | SWT.DROP_DOWN | SWT.READ_ONLY); runnerMapping.clear(); if (multiDisplaySupport) { runnerCombo.add("Thread"); runnerMapping.add(THREAD_RUNNER); } if (javaCommand != null) { runnerCombo.add("Process"); runnerMapping.add(PROCESS_RUNNER); } runnerCombo.add("Serial"); runnerMapping.add(null); runnerCombo.setData(runnerMapping); runnerCombo.addListener(SWT.Modify, event -> { if (runnerMapping.size() > runnerCombo.getSelectionIndex()) { snippetRunner = runnerMapping.get(runnerCombo.getSelectionIndex()); } else { System.err.println("Unknown runner index " + runnerCombo.getSelectionIndex()); } }); runnerCombo.select(0); infoTabs = new TabFolder(rightContainer, SWT.TOP); infoTabs.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); descriptionView = new StyledText(infoTabs, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY | SWT.V_SCROLL); sourceView = new StyledText(infoTabs, SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL); setMonospaceFont(sourceView); final ScrolledComposite previewContainer = new ScrolledComposite(infoTabs, SWT.V_SCROLL | SWT.H_SCROLL); previewImageLabel = new Label(previewContainer, SWT.NONE); previewContainer.setContent(previewImageLabel); final TabItem descriptionTab = new TabItem(infoTabs, SWT.NONE); descriptionTab.setText("Description"); descriptionTab.setControl(descriptionView); final TabItem sourceTab = new TabItem(infoTabs, SWT.NONE); sourceTab.setText("Source"); sourceTab.setControl(sourceView); final TabItem previewTab = new TabItem(infoTabs, SWT.NONE); previewTab.setText("Preview"); previewTab.setControl(previewContainer); updateInfoTab(null, true); updateInfoTab(snippetTable.getSelection()); }
From source file:ClipboardExample.java
void createControlTransfer(Composite parent) { Label l = new Label(parent, SWT.NONE); l.setText("Text:"); Button b = new Button(parent, SWT.PUSH); b.setText("Cut"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { text.cut();/*from w w w .ja v a 2 s.c o m*/ } }); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { text.copy(); } }); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { text.paste(); } }); text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; text.setLayoutData(data); l = new Label(parent, SWT.NONE); l.setText("Combo:"); b = new Button(parent, SWT.PUSH); b.setText("Cut"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { combo.cut(); } }); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { combo.copy(); } }); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { combo.paste(); } }); combo = new Combo(parent, SWT.NONE); combo.setItems(new String[] { "Item 1", "Item 2", "Item 3", "A longer Item" }); l = new Label(parent, SWT.NONE); l.setText("StyledText:"); l = new Label(parent, SWT.NONE); l.setVisible(false); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { styledText.copy(); } }); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { styledText.paste(); } }); styledText = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); data = new GridData(GridData.FILL_HORIZONTAL); data.heightHint = data.widthHint = SIZE; styledText.setLayoutData(data); }
From source file:ConnectionInfo.java
protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NULL); composite.setLayout(new FillLayout()); // the vertical sashform. SashForm verticalForm = new SashForm(composite, SWT.VERTICAL); // the horizontal sashform. SashForm horizontalForm = new SashForm(verticalForm, SWT.HORIZONTAL); // Local dir browser. Composite compositeLocalDir = new Composite(horizontalForm, SWT.NULL); GridLayout gridLayout = new GridLayout(); gridLayout.horizontalSpacing = 1;// w w w .j a v a 2 s.c o m gridLayout.verticalSpacing = 1; compositeLocalDir.setLayout(gridLayout); Group compositeLocalDirTop = new Group(compositeLocalDir, SWT.NULL); compositeLocalDirTop.setText("Local"); GridLayout gridLayout2 = new GridLayout(3, false); gridLayout2.marginHeight = 0; compositeLocalDirTop.setLayout(gridLayout2); compositeLocalDirTop.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); labelPathLocal = new Label(compositeLocalDirTop, SWT.NULL); labelPathLocal.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); labelPathLocal.setText("Path: "); Button buttonUpLocalDir = new Button(compositeLocalDirTop, SWT.PUSH); buttonUpLocalDir.setText(actionUpLocalDir.getText()); buttonUpLocalDir.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { actionUpLocalDir.run(); } }); Button buttonBrowseLocalDir = new Button(compositeLocalDirTop, SWT.PUSH); buttonBrowseLocalDir.setText(actionBrowseLocalDir.getText()); buttonBrowseLocalDir.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { actionBrowseLocalDir.run(); } }); Table table = new Table(compositeLocalDir, SWT.BORDER); TableColumn tcFile = new TableColumn(table, SWT.LEFT); tcFile.setText("Name"); TableColumn tcSize = new TableColumn(table, SWT.NULL); tcSize.setText("Size"); TableColumn tcDate = new TableColumn(table, SWT.NULL); tcDate.setText("Date"); tcFile.setWidth(200); tcSize.setWidth(100); tcDate.setWidth(100); table.setHeaderVisible(true); table.setLayoutData(new GridData(GridData.FILL_BOTH)); localDirBrowser = new LocalDirectoryBrowser(table); table.addListener(SWT.MouseDoubleClick, new Listener() { public void handleEvent(Event event) { IStructuredSelection selection = (IStructuredSelection) localDirBrowser.getSelection(); File file = (File) selection.getFirstElement(); if (file != null && file.isDirectory()) { localDirBrowser.setInput(file); labelPathLocal.setText("Path: " + file); } } }); // Remote directory browser. Composite compositeRemoteDir = new Composite(horizontalForm, SWT.NULL); gridLayout = new GridLayout(); gridLayout.horizontalSpacing = 1; gridLayout.verticalSpacing = 1; compositeRemoteDir.setLayout(gridLayout); Group compositeRemoteDirTop = new Group(compositeRemoteDir, SWT.NULL); compositeRemoteDirTop.setText("Remote"); gridLayout2 = new GridLayout(2, false); gridLayout2.marginHeight = 0; compositeRemoteDirTop.setLayout(gridLayout2); compositeRemoteDirTop.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); labelPathRemote = new Label(compositeRemoteDirTop, SWT.NULL); labelPathRemote.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); labelPathRemote.setText("Path: "); Button buttonUpRemoteDir = new Button(compositeRemoteDirTop, SWT.PUSH); buttonUpRemoteDir.setText(actionUpLocalDir.getText()); buttonUpRemoteDir.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { actionUpRemoteDir.run(); } }); Table tableRemote = new Table(compositeRemoteDir, SWT.BORDER); TableColumn tcFileRemote = new TableColumn(tableRemote, SWT.LEFT); tcFileRemote.setText("Name"); TableColumn tcSizeRemote = new TableColumn(tableRemote, SWT.NULL); tcSizeRemote.setText("Size"); TableColumn tcDateRemote = new TableColumn(tableRemote, SWT.NULL); tcDateRemote.setText("Date"); tcFileRemote.setWidth(200); tcSizeRemote.setWidth(100); tcDateRemote.setWidth(100); tableRemote.setHeaderVisible(true); tableRemote.setLayoutData(new GridData(GridData.FILL_BOTH)); remoteDirBrowser = new RemoteDirectoryBrowser(tableRemote); tableRemote.addListener(SWT.MouseDoubleClick, new Listener() { public void handleEvent(Event event) { IStructuredSelection selection = (IStructuredSelection) remoteDirBrowser.getSelection(); FTPFile file = (FTPFile) selection.getFirstElement(); if (file != null && file.isDirectory()) { try { ftp.changeWorkingDirectory(file.getName()); labelPathRemote.setText("Path: " + ftp.printWorkingDirectory()); remoteDirBrowser.setInput(ftp.listFiles()); } catch (IOException e) { logError(e.toString()); } } } }); // the log box. textLog = new StyledText(verticalForm, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); localDirBrowser.setInput(File.listRoots()[0]); labelPathLocal.setText("Path: " + File.listRoots()[0]); // resize sashform children. verticalForm.setWeights(new int[] { 4, 1 }); // adding drag and drop support. dragNDropSupport(); getToolBarControl().setBackground(new Color(getShell().getDisplay(), 230, 230, 230)); getShell().setImage(new Image(getShell().getDisplay(), "icons/ftp/ftp.gif")); getShell().setText("FTP Client v1.0"); return composite; }
From source file:org.eclipse.swt.examples.clipboard.ClipboardExample.java
void createControlTransfer(Composite parent) { // TODO: CCombo and Spinner also have cut(), copy() and paste() API Label l = new Label(parent, SWT.NONE); l.setText("Text:"); Button b = new Button(parent, SWT.PUSH); b.setText("Cut"); b.addSelectionListener(widgetSelectedAdapter(e -> text.cut())); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(widgetSelectedAdapter(e -> text.copy())); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(widgetSelectedAdapter(e -> text.paste())); text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.widthHint = HSIZE;/*from w w w . ja va2 s .co m*/ data.heightHint = VSIZE; text.setLayoutData(data); l = new Label(parent, SWT.NONE); l.setText("Combo:"); b = new Button(parent, SWT.PUSH); b.setText("Cut"); b.addSelectionListener(widgetSelectedAdapter(e -> combo.cut())); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(widgetSelectedAdapter(e -> combo.copy())); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(widgetSelectedAdapter(e -> combo.paste())); combo = new Combo(parent, SWT.NONE); combo.setItems("Item 1", "Item 2", "Item 3", "A longer Item"); combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); l = new Label(parent, SWT.NONE); l.setText("StyledText:"); b = new Button(parent, SWT.PUSH); b.setText("Cut"); b.addSelectionListener(widgetSelectedAdapter(e -> styledText.cut())); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(widgetSelectedAdapter(e -> styledText.copy())); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(widgetSelectedAdapter(e -> styledText.paste())); styledText = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); data = new GridData(GridData.FILL_HORIZONTAL); data.widthHint = HSIZE; data.heightHint = VSIZE; styledText.setLayoutData(data); }
From source file:ImageAnalyzer.java
void createWidgets() { // Add the widgets to the shell in a grid layout. GridLayout layout = new GridLayout(); layout.marginHeight = 0;//w w w. j a v a2 s. 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); }