List of usage examples for org.eclipse.swt.widgets Button setText
public void setText(String text)
From source file:eu.hydrologis.jgrass.charting.datamodels.MultiXYTimeChartCreator.java
/** * Make a composite with the plot of the supplied chartdata. There are several HINT* variables * that can be set to tweak and configure the plot. * /*from ww w . j a v a 2 s. c o m*/ * @param parentComposite * @param chartData */ public void makePlot(Composite parentComposite, NumericChartData chartData) { final int tabNums = chartData.getTabItemNumbers(); if (tabNums == 0) { return; } Shell dummyShell = null; // try { // dummyShell = PlatformUI.getWorkbench().getDisplay().getActiveShell(); // } catch (Exception e) { dummyShell = new Shell(Display.getCurrent(), SWT.None); // } /* * wrapping panel needed in the case of hide checks */ TabFolder tabFolder = null; if (tabNums > 1) { tabFolder = new TabFolder(parentComposite, SWT.BORDER); tabFolder.setLayout(new GridLayout()); tabFolder.setLayoutData( new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); } for (int i = 0; i < tabNums; i++) { NumericChartDataItem chartItem = chartData.getChartDataItem(i); int chartNums = chartItem.chartSeriesData.size(); /* * are there data to create the lower chart panel */ List<LinkedHashMap<String, Integer>> series = new ArrayList<LinkedHashMap<String, Integer>>(); List<XYPlot> plots = new ArrayList<XYPlot>(); List<JFreeChart> charts = new ArrayList<JFreeChart>(); for (int j = 0; j < chartNums; j++) { final LinkedHashMap<String, Integer> chartSeries = new LinkedHashMap<String, Integer>(); XYPlot chartPlot = null; JGrassChart chart = null; double[][][] cLD = chartItem.chartSeriesData.get(j); if (M_HINT_CREATE_CHART[i][j]) { final String[] cT = chartItem.seriesNames.get(j); final String title = chartItem.chartTitles.get(j); final String xT = chartItem.chartXLabels.get(j); final String yT = chartItem.chartYLabels.get(j); if (M_HINT_CHART_TYPE[i][j] == XYLINECHART) { chart = new JGrassXYLineChart(cT, cLD); } else if (M_HINT_CHART_TYPE[i][j] == XYBARCHART) { chart = new JGrassXYBarChart(cT, cLD, HINT_barwidth); } else if (M_HINT_CHART_TYPE[i][j] == TIMEYLINECHART) { chart = new JGrassXYTimeLineChart(cT, cLD, Minute.class); ((JGrassXYTimeLineChart) chart).setTimeAxisFormat(TIMEFORMAT); } else if (M_HINT_CHART_TYPE[i][j] == TIMEYBARCHART) { chart = new JGrassXYTimeBarChart(cT, cLD, Minute.class, HINT_barwidth); ((JGrassXYTimeBarChart) chart).setTimeAxisFormat(TIMEFORMAT); } else if (M_HINT_CHART_TYPE[i][j] == XYPOINTCHART) { chart = new JGrassXYLineChart(cT, cLD); ((JGrassXYLineChart) chart).toggleLineShapesDisplay(false, true); } else if (M_HINT_CHART_TYPE[i][j] == TIMEXYPOINTCHART) { chart = new JGrassXYTimeLineChart(cT, cLD, Minute.class); ((JGrassXYTimeLineChart) chart).setTimeAxisFormat(TIMEFORMAT); ((JGrassXYTimeLineChart) chart).toggleLineShapesDisplay(false, true); } else { chart = new JGrassXYLineChart(cT, cLD); } final Composite p1Composite = new Composite(dummyShell, SWT.None); p1Composite.setLayout(new FillLayout()); p1Composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); chart.makeChartPanel(p1Composite, title, xT, yT, null, true, true, true, true); chartPlot = (XYPlot) chart.getPlot(); XYItemRenderer renderer = chartPlot.getRenderer(); chartPlot.setDomainGridlinesVisible(HINT_doDomainGridVisible); chartPlot.setRangeGridlinesVisible(HINT_doRangeGridVisible); if (HINT_doDisplayToolTips) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); } if (!M_HINT_CHARTORIENTATION_UP[i][j]) { chartPlot.getRangeAxis().setInverted(true); } if (M_HINT_CHARTSERIESCOLOR != null) { final XYItemRenderer rend = renderer; for (int k = 0; k < cLD.length; k++) { rend.setSeriesPaint(k, M_HINT_CHARTSERIESCOLOR[i][j][k]); } } chart.toggleFilledShapeDisplay(HINT_doDisplayBaseShapes, HINT_doFillBaseShapes, true); for (int k = 0; k < cT.length; k++) { chartSeries.put(cT[k], k); } series.add(chartSeries); chartPlot.setNoDataMessage("No data available"); chartPlot.setNoDataMessagePaint(Color.red); plots.add(chartPlot); charts.add(chart.getChart(title, xT, yT, null, true, HINT_doDisplayToolTips, true)); chartsList.add(chart); /* * add annotations? */ if (chartItem.annotationsOnChart.size() > 0) { LinkedHashMap<String, double[]> annotations = chartItem.annotationsOnChart.get(j); if (annotations.size() > 0) { Set<String> keys = annotations.keySet(); for (String key : keys) { double[] c = annotations.get(key); XYPointerAnnotation ann = new XYPointerAnnotation(key, c[0], c[1], HINT_AnnotationArrowAngle); ann.setTextAnchor(HINT_AnnotationTextAncor); ann.setPaint(HINT_AnnotationTextColor); ann.setArrowPaint(HINT_AnnotationArrowColor); // ann.setArrowLength(15); renderer.addAnnotation(ann); // Marker currentEnd = new ValueMarker(c[0]); // currentEnd.setPaint(Color.red); // currentEnd.setLabel(""); // currentEnd.setLabelAnchor(RectangleAnchor.TOP_RIGHT); // currentEnd.setLabelTextAnchor(TextAnchor.TOP_LEFT); // chartPlot.addDomainMarker(currentEnd); // Drawable cd = new LineDrawer(Color.red, new BasicStroke(1.0f)); // XYAnnotation bestBid = new XYDrawableAnnotation(c[0], c[1]/2.0, // 0, c[1], // cd); // chartPlot.addAnnotation(bestBid); // pointer.setFont(new Font("SansSerif", Font.PLAIN, 9)); } } } } } JFreeChart theChart = null; if (plots.size() > 1) { ValueAxis domainAxis = null; if (M_HINT_CHART_TYPE[i][0] == ChartCreator.TIMEYBARCHART || M_HINT_CHART_TYPE[i][0] == ChartCreator.TIMEYLINECHART) { domainAxis = (plots.get(0)).getDomainAxis(); } else { domainAxis = new NumberAxis(chartItem.chartXLabels.get(0)); } final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(domainAxis); plot.setGap(10.0); // add the subplots... for (int k = 0; k < plots.size(); k++) { XYPlot tmpPlot = plots.get(k); if (HINT_labelInsets != null) { tmpPlot.getRangeAxis().setLabelInsets(HINT_labelInsets); } plot.add(tmpPlot, k + 1); } plot.setOrientation(PlotOrientation.VERTICAL); theChart = new JFreeChart(chartItem.bigTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true); } else if (plots.size() == 1) { theChart = new JFreeChart(chartItem.chartTitles.get(0), JFreeChart.DEFAULT_TITLE_FONT, plots.get(0), true); } else { return; } /* * create the chart composite */ Composite tmp; if (tabNums > 1 && tabFolder != null) { tmp = new Composite(tabFolder, SWT.None); } else { tmp = new Composite(parentComposite, SWT.None); } tmp.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); tmp.setLayout(new GridLayout()); final ChartComposite frame = new ChartComposite(tmp, SWT.None, theChart, 680, 420, 300, 200, 700, 500, false, true, // properties true, // save true, // print true, // zoom true // tooltips ); // public static final boolean DEFAULT_BUFFER_USED = false; // public static final int DEFAULT_WIDTH = 680; // public static final int DEFAULT_HEIGHT = 420; // public static final int DEFAULT_MINIMUM_DRAW_WIDTH = 300; // public static final int DEFAULT_MINIMUM_DRAW_HEIGHT = 200; // public static final int DEFAULT_MAXIMUM_DRAW_WIDTH = 800; // public static final int DEFAULT_MAXIMUM_DRAW_HEIGHT = 600; // public static final int DEFAULT_ZOOM_TRIGGER_DISTANCE = 10; frame.setLayoutData( new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); frame.setLayout(new FillLayout()); frame.setDisplayToolTips(HINT_doDisplayToolTips); frame.setHorizontalAxisTrace(HINT_doHorizontalAxisTrace); frame.setVerticalAxisTrace(HINT_doVerticalAxisTrace); frame.setDomainZoomable(HINT_doDomainZoomable); frame.setRangeZoomable(HINT_doRangeZoomable); if (tabNums > 1 && tabFolder != null) { final TabItem item = new TabItem(tabFolder, SWT.NONE); item.setText(chartData.getChartDataItem(i).chartStringExtra); item.setControl(tmp); } /* * create the hide toggling part */ for (int j = 0; j < plots.size(); j++) { if (M_HINT_CREATE_TOGGLEHIDESERIES[i][j]) { final LinkedHashMap<Button, Integer> allButtons = new LinkedHashMap<Button, Integer>(); Group checksComposite = new Group(tmp, SWT.None); checksComposite.setText(""); RowLayout rowLayout = new RowLayout(); rowLayout.wrap = true; rowLayout.type = SWT.HORIZONTAL; checksComposite.setLayout(rowLayout); checksComposite .setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); final XYItemRenderer renderer = plots.get(j).getRenderer(); Set<String> lTitles = series.get(j).keySet(); for (final String title : lTitles) { final Button b = new Button(checksComposite, SWT.CHECK); b.setText(title); b.setSelection(true); final int index = series.get(j).get(title); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { boolean visible = renderer.getItemVisible(index, 0); renderer.setSeriesVisible(index, new Boolean(!visible)); } }); allButtons.put(b, index); } /* * toggle all and none */ if (HINT_doToggleTuttiButton) { Composite allchecksComposite = new Composite(tmp, SWT.None); RowLayout allrowLayout = new RowLayout(); allrowLayout.wrap = true; allrowLayout.type = SWT.HORIZONTAL; allchecksComposite.setLayout(allrowLayout); allchecksComposite .setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); final Button tuttiButton = new Button(allchecksComposite, SWT.BORDER | SWT.PUSH); tuttiButton.setText("Tutti"); tuttiButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Set<Button> set = allButtons.keySet(); for (Button button : set) { button.setSelection(true); int i = allButtons.get(button); if (renderer != null) { renderer.setSeriesVisible(i, new Boolean(true)); } } } }); final Button noneButton = new Button(allchecksComposite, SWT.BORDER | SWT.PUSH); noneButton.setText("Nessuno"); noneButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Set<Button> set = allButtons.keySet(); for (Button button : set) { button.setSelection(false); int i = allButtons.get(button); if (renderer != null) { renderer.setSeriesVisible(i, new Boolean(false)); } } } }); } } } } }
From source file:org.eclipse.swt.examples.layoutexample.Tab.java
/** * Creates the "control" group. This is the group on the * right half of each example tab. It contains controls * for adding new children to the layoutComposite, and * for modifying the children's layout data. *///from www . ja va 2s . c o m void createControlGroup() { controlGroup = new Group(sash, SWT.NONE); controlGroup.setText(LayoutExample.getResourceString("Parameters")); GridLayout layout = new GridLayout(2, true); layout.horizontalSpacing = 10; controlGroup.setLayout(layout); final Button preferredButton = new Button(controlGroup, SWT.CHECK); preferredButton.setText(LayoutExample.getResourceString("Preferred_Size")); preferredButton.setSelection(false); preferredButton.addSelectionListener(widgetSelectedAdapter(e -> { resetEditors(); GridData data = (GridData) layoutComposite.getLayoutData(); if (preferredButton.getSelection()) { data.heightHint = data.widthHint = SWT.DEFAULT; data.verticalAlignment = data.horizontalAlignment = 0; data.grabExcessVerticalSpace = data.grabExcessHorizontalSpace = false; } else { data.verticalAlignment = data.horizontalAlignment = SWT.FILL; data.grabExcessVerticalSpace = data.grabExcessHorizontalSpace = true; } layoutComposite.setLayoutData(data); layoutGroup.layout(true); })); preferredButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); createControlWidgets(); }
From source file:edu.isistan.carcha.plugin.editors.TraceabilityEditor.java
/** * Creates the impact list page.//from ww w . j ava 2 s.c o m */ void impactListPage() { final Composite composite = new Composite(getContainer(), SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); composite.setLayout(new GridLayout()); Label concernLabel = new Label(composite, SWT.BORDER); concernLabel.setText("Crosccuting Concerns(CCC)"); concernLabel.setToolTipText("This are the concern detected on the requierement document."); GridData gridData = new GridData(SWT.LEFT, SWT.TOP, false, false); concernLabel.setLayoutData(gridData); ///////////////////// ScrolledComposite sc = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL); Composite parent = new Composite(sc, SWT.NONE); parent.setLayout(new GridLayout()); topViewLink = new TableViewer(parent, SWT.BORDER); createColumns(parent, topViewLink); final Table table = topViewLink.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); topViewLink.setContentProvider(new ArrayContentProvider()); getSite().setSelectionProvider(topViewLink); GridData data = new GridData(SWT.FILL, SWT.FILL, true, false); data.heightHint = 10 * table.getItemHeight(); table.setLayoutData(data); sc.setContent(parent); sc.setExpandHorizontal(true); sc.setExpandVertical(true); sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT)); ///////////////////// Button button = new Button(composite, SWT.PUSH); button.setText("Remove"); button.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent event) { } public void widgetSelected(SelectionEvent event) { IStructuredSelection topSelection = (IStructuredSelection) topViewLink.getSelection(); IStructuredSelection bottomSelection = (IStructuredSelection) bottomViewLink.getSelection(); String[] crosscuttingConcern = (String[]) topSelection.getFirstElement(); String[] designDecision = (String[]) bottomSelection.getFirstElement(); if (topSelection.size() > 1) { MessageDialog.openError(composite.getShell(), "Error", "Please select one crosscutting concern"); } else { if ((crosscuttingConcern != null) && (designDecision != null)) { // create dialog with ok and cancel button and info icon MessageBox dialog = new MessageBox(composite.getShell(), SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL); dialog.setText("Link confirmation"); dialog.setMessage("Do you want to remove the link between the selected items?"); // open dialog and await user selection int response = dialog.open(); if (response == SWT.OK) { PluginUtil.removeLink(crosscuttingConcern, designDecision, cp); dirty = true; firePropertyChange(IEditorPart.PROP_DIRTY); // update the list after the remove generateLinkViewData(); bottomViewLink.getTable().clearAll(); } } else { MessageDialog.openError(composite.getShell(), "Error", "Please select a crosscutting concern and a design decision to remove a traceability link"); } } } }); gridData = new GridData(SWT.CENTER, SWT.TOP, false, false, 2, 1); button.setLayoutData(gridData); Label ddsLabel = new Label(composite, SWT.BORDER); ddsLabel.setText("Architectural design decisions"); ddsLabel.setToolTipText("This are the design decisions detected on the architectural document"); gridData = new GridData(SWT.LEFT, SWT.TOP, false, false); ddsLabel.setLayoutData(gridData); bottomViewLink = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); createColumns(composite, bottomViewLink); Table table2 = bottomViewLink.getTable(); table2.setHeaderVisible(true); table2.setLinesVisible(true); bottomViewLink.setContentProvider(new ArrayContentProvider()); topViewLink.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (!selection.isEmpty()) { String[] cccs = (String[]) selection.getFirstElement(); List<DesignDecision> dds = PluginUtil.getDesignDecisionsForCrossCuttingConcern(cp, cccs[1], cccs[0]); logger.info("Impact List for CCC (" + dds.size() + " DDD): " + cccs[0] + " - " + cccs[1]); List<String[]> designDecisions = new ArrayList<String[]>(); for (DesignDecision dd : dds) { String[] designDecision = { dd.getKind(), dd.getName() }; designDecisions.add(designDecision); } bottomViewLink.setInput(designDecisions); } } }); getSite().setSelectionProvider(bottomViewLink); gridData = new GridData(SWT.FILL, SWT.FILL, true, true); bottomViewLink.getControl().setLayoutData(gridData); int index = addPage(composite); setPageText(index, "Links"); }
From source file:org.eclipse.swt.examples.layoutexample.Tab.java
/** * Refreshes the composite and draws all controls * in the layout example.//from ww w . j av a2 s . c o m */ void refreshLayoutComposite() { /* Remove children that are already laid out */ children = layoutComposite.getChildren(); for (Control child : children) { child.dispose(); } /* Add all children listed in the table */ TableItem[] items = table.getItems(); children = new Control[items.length]; String[] itemValues = new String[] { LayoutExample.getResourceString("Item", new String[] { "1" }), LayoutExample.getResourceString("Item", new String[] { "2" }), LayoutExample.getResourceString("Item", new String[] { "3" }) }; for (int i = 0; i < items.length; i++) { String control = items[i].getText(1); String controlName = items[i].getText(0); if (control.equals("Button")) { Button button = new Button(layoutComposite, SWT.PUSH); button.setText(controlName); children[i] = button; } else if (control.equals("Canvas")) { Canvas canvas = new Canvas(layoutComposite, SWT.BORDER); children[i] = canvas; } else if (control.equals("Combo")) { Combo combo = new Combo(layoutComposite, SWT.NONE); combo.setItems(itemValues); combo.setText(controlName); children[i] = combo; } else if (control.equals("Composite")) { Composite composite = new Composite(layoutComposite, SWT.BORDER); children[i] = composite; } else if (control.equals("CoolBar")) { CoolBar coolBar = new CoolBar(layoutComposite, SWT.NONE); ToolBar toolBar = new ToolBar(coolBar, SWT.BORDER); ToolItem item = new ToolItem(toolBar, 0); item.setText(LayoutExample.getResourceString("Item", new String[] { "1" })); item = new ToolItem(toolBar, 0); item.setText(LayoutExample.getResourceString("Item", new String[] { "2" })); CoolItem coolItem1 = new CoolItem(coolBar, 0); coolItem1.setControl(toolBar); toolBar = new ToolBar(coolBar, SWT.BORDER); item = new ToolItem(toolBar, 0); item.setText(LayoutExample.getResourceString("Item", new String[] { "3" })); item = new ToolItem(toolBar, 0); item.setText(LayoutExample.getResourceString("Item", new String[] { "4" })); CoolItem coolItem2 = new CoolItem(coolBar, 0); coolItem2.setControl(toolBar); Point size = toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT); coolItem1.setSize(coolItem1.computeSize(size.x, size.y)); coolItem2.setSize(coolItem2.computeSize(size.x, size.y)); coolBar.setSize(coolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT)); children[i] = coolBar; } else if (control.equals("Group")) { Group group = new Group(layoutComposite, SWT.NONE); group.setText(controlName); children[i] = group; } else if (control.equals("Label")) { Label label = new Label(layoutComposite, SWT.NONE); label.setText(controlName); children[i] = label; } else if (control.equals("Link")) { Link link = new Link(layoutComposite, SWT.NONE); link.setText(controlName); children[i] = link; } else if (control.equals("List")) { org.eclipse.swt.widgets.List list = new org.eclipse.swt.widgets.List(layoutComposite, SWT.BORDER); list.setItems(itemValues); children[i] = list; } else if (control.equals("ProgressBar")) { ProgressBar progress = new ProgressBar(layoutComposite, SWT.NONE); progress.setSelection(50); children[i] = progress; } else if (control.equals("Scale")) { Scale scale = new Scale(layoutComposite, SWT.NONE); children[i] = scale; } else if (control.equals("Slider")) { Slider slider = new Slider(layoutComposite, SWT.NONE); children[i] = slider; } else if (control.equals("StyledText")) { StyledText styledText = new StyledText(layoutComposite, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); styledText.setText(controlName); children[i] = styledText; } else if (control.equals("Table")) { Table table = new Table(layoutComposite, SWT.BORDER); table.setLinesVisible(true); TableItem item1 = new TableItem(table, 0); item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" })); TableItem item2 = new TableItem(table, 0); item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" })); children[i] = table; } else if (control.equals("Text")) { Text text = new Text(layoutComposite, SWT.BORDER); text.setText(controlName); children[i] = text; } else if (control.equals("ToolBar")) { ToolBar toolBar = new ToolBar(layoutComposite, SWT.BORDER); ToolItem item1 = new ToolItem(toolBar, 0); item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" })); ToolItem item2 = new ToolItem(toolBar, 0); item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" })); children[i] = toolBar; } else { Tree tree = new Tree(layoutComposite, SWT.BORDER); TreeItem item1 = new TreeItem(tree, 0); item1.setText(LayoutExample.getResourceString("Item", new String[] { "1" })); TreeItem item2 = new TreeItem(tree, 0); item2.setText(LayoutExample.getResourceString("Item", new String[] { "2" })); children[i] = tree; } } }
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;/*from www . jav 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:SWTAddressBook.java
private void createControlButtons() { Composite composite = new Composite(shell, SWT.NULL); composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER)); GridLayout layout = new GridLayout(); layout.numColumns = 2;/* w w w .jav a 2 s. c o m*/ composite.setLayout(layout); Button okButton = new Button(composite, SWT.PUSH); okButton.setText("OK"); okButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { shell.close(); } }); Button cancelButton = new Button(composite, SWT.PUSH); cancelButton.setText("Cancel"); cancelButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { values = null; shell.close(); } }); shell.setDefaultButton(okButton); }
From source file:CalculatorMichaelSchmidt.java
@Override protected Control createDialogArea(final Composite parent) { Composite container = (Composite) super.createDialogArea(parent); final GridLayout calculatorGridLayout = new GridLayout(); calculatorGridLayout.marginRight = 5; calculatorGridLayout.marginLeft = 5; calculatorGridLayout.marginBottom = 5; calculatorGridLayout.marginTop = 5;/*from w ww. j ava2 s . co m*/ calculatorGridLayout.marginWidth = 10; calculatorGridLayout.marginHeight = 2; calculatorGridLayout.numColumns = 4; calculatorGridLayout.verticalSpacing = 2; calculatorGridLayout.makeColumnsEqualWidth = true; calculatorGridLayout.horizontalSpacing = 2; container.setLayout(calculatorGridLayout); // The display. Note that it has a limit of 30 characters, // much greater than the length of a double-precision number. displayText = new Text(container, SWT.RIGHT | SWT.BORDER); displayText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); displayText.setEditable(false); displayText.setDoubleClickEnabled(false); displayText.setTextLimit(30); displayText.setText(displayString); displayText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 4, 1)); final Button msButton = new Button(container, SWT.NONE); msButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateMemory('S'); } }); msButton.setToolTipText("Save value to Memory"); msButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); msButton.setText("MS"); final Button mcButton = new Button(container, SWT.NONE); mcButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('D'); } }); mcButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); mcButton.setToolTipText("Clear Memory"); mcButton.setText("MC"); final Button clearButton = new Button(container, SWT.NONE); clearButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('C'); } }); clearButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); clearButton.setToolTipText("Clear all Calculator Registers"); clearButton.setText("C"); final Button ceButton = new Button(container, SWT.NONE); ceButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('E'); } }); ceButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); ceButton.setToolTipText("Clear Entry"); ceButton.setText("CE"); final Button memAddButton = new Button(container, SWT.NONE); memAddButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateMemory('+'); } }); memAddButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); memAddButton.setToolTipText("Add value to Memory"); memAddButton.setText("M+"); final Button mrButton = new Button(container, SWT.NONE); mrButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('R'); } }); mrButton.setToolTipText("Recall value in Memory"); mrButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); mrButton.setText("MR"); final Button backButton = new Button(container, SWT.NONE); backButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('B'); } }); backButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); backButton.setToolTipText("Backspace"); backButton.setText("BACK"); final Button divideButton = new Button(container, SWT.NONE); divideButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateCalc('/'); } }); divideButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); divideButton.setToolTipText("Divide"); divideButton.setText("/"); final Button memSubtractButton = new Button(container, SWT.NONE); memSubtractButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateMemory('-'); } }); memSubtractButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); memSubtractButton.setToolTipText("Subtract value from Memory"); memSubtractButton.setText("M-"); final Button inverseButton = new Button(container, SWT.NONE); inverseButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('I'); } }); inverseButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); inverseButton.setToolTipText("Inverse of value"); inverseButton.setText("1/X"); final Button sqrtButton = new Button(container, SWT.NONE); sqrtButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('Q'); } }); sqrtButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); sqrtButton.setToolTipText("Square Root of value"); sqrtButton.setText("SQRT"); final Button multiplyButton = new Button(container, SWT.NONE); multiplyButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateCalc('*'); } }); multiplyButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); multiplyButton.setToolTipText("Multiply"); multiplyButton.setText("*"); final Button num7Button = new Button(container, SWT.NONE); num7Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('7'); } }); num7Button.setToolTipText("Numeric Pad"); num7Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num7Button.setText("7"); final Button num8Button = new Button(container, SWT.NONE); num8Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('8'); } }); num8Button.setToolTipText("Numeric Pad"); num8Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num8Button.setText("8"); final Button num9Button = new Button(container, SWT.NONE); num9Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('9'); } }); num9Button.setToolTipText("Numeric Pad"); num9Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num9Button.setText("9"); final Button SubtractButton = new Button(container, SWT.NONE); SubtractButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateCalc('-'); } }); SubtractButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); SubtractButton.setToolTipText("Subtract"); SubtractButton.setText("-"); final Button num4Button = new Button(container, SWT.NONE); num4Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('4'); } }); num4Button.setToolTipText("Numeric Pad"); num4Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num4Button.setText("4"); final Button num5Button = new Button(container, SWT.NONE); num5Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('5'); } }); num5Button.setToolTipText("Numeric Pad"); num5Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num5Button.setText("5"); final Button num6Button = new Button(container, SWT.NONE); num6Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('6'); } }); num6Button.setToolTipText("Numeric Pad"); num6Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num6Button.setText("6"); final Button AdditionButton = new Button(container, SWT.NONE); AdditionButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateCalc('+'); } }); AdditionButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); AdditionButton.setToolTipText("Add"); AdditionButton.setText("+"); final Button num1Button = new Button(container, SWT.NONE); num1Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('1'); } }); num1Button.setCapture(true); num1Button.setToolTipText("Numeric Pad"); num1Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num1Button.setText("1"); final Button num2Button = new Button(container, SWT.NONE); num2Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('2'); } }); num2Button.setToolTipText("Numeric Pad"); num2Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num2Button.setText("2"); final Button num3Button = new Button(container, SWT.NONE); num3Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('3'); } }); num3Button.setToolTipText("Numeric Pad"); num3Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num3Button.setText("3"); final Button equalsButton = new Button(container, SWT.NONE); equalsButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateCalc('='); } }); equalsButton.setToolTipText("Equals (get result)"); equalsButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 2)); equalsButton.setText("="); final Button num0Button = new Button(container, SWT.NONE); num0Button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('0'); } }); num0Button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); num0Button.setToolTipText("Numeric Pad"); num0Button.setText("0"); final Button decimalButton = new Button(container, SWT.NONE); decimalButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('.'); } }); decimalButton.setToolTipText("Numeric Pad"); decimalButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); decimalButton.setText("."); final Button signButton = new Button(container, SWT.NONE); signButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { updateDisplay('-'); } }); signButton.setToolTipText("Change sign of value"); signButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); signButton.setText("+/-"); new Label(container, SWT.NONE); // return container; }
From source file:SWTAddressBook.java
/** * Class constructor that sets the parent shell and the table widget that * the dialog will search.//from w ww. j av a2s. c om * * @param parent * Shell The shell that is the parent of the dialog. */ public SearchDialog(Shell parent) { shell = new Shell(parent, SWT.CLOSE | SWT.BORDER | SWT.TITLE); GridLayout layout = new GridLayout(); layout.numColumns = 2; shell.setLayout(layout); shell.setText("Search"); shell.addShellListener(new ShellAdapter() { public void shellClosed(ShellEvent e) { // don't dispose of the shell, just hide it for later use e.doit = false; shell.setVisible(false); } }); Label label = new Label(shell, SWT.LEFT); label.setText("Dialog_find_what"); searchText = new Text(shell, SWT.BORDER); GridData gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.widthHint = 200; searchText.setLayoutData(gridData); searchText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { boolean enableFind = (searchText.getCharCount() != 0); findButton.setEnabled(enableFind); } }); searchAreaLabel = new Label(shell, SWT.LEFT); searchArea = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.widthHint = 200; searchArea.setLayoutData(gridData); matchCase = new Button(shell, SWT.CHECK); matchCase.setText("Dialog_match_case"); gridData = new GridData(); gridData.horizontalSpan = 2; matchCase.setLayoutData(gridData); matchWord = new Button(shell, SWT.CHECK); matchWord.setText("Dialog_match_word"); gridData = new GridData(); gridData.horizontalSpan = 2; matchWord.setLayoutData(gridData); Group direction = new Group(shell, SWT.NONE); gridData = new GridData(); gridData.horizontalSpan = 2; direction.setLayoutData(gridData); direction.setLayout(new FillLayout()); direction.setText("Dialog_direction"); Button up = new Button(direction, SWT.RADIO); up.setText("Dialog_dir_up"); up.setSelection(false); down = new Button(direction, SWT.RADIO); down.setText("Dialog_dir_down"); down.setSelection(true); Composite composite = new Composite(shell, SWT.NONE); gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); gridData.horizontalSpan = 2; composite.setLayoutData(gridData); layout = new GridLayout(); layout.numColumns = 2; layout.makeColumnsEqualWidth = true; composite.setLayout(layout); findButton = new Button(composite, SWT.PUSH); findButton.setText("Dialog_find"); findButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); findButton.setEnabled(false); findButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (!findHandler.find()) { MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK | SWT.PRIMARY_MODAL); box.setText(shell.getText()); box.setMessage("Cannot_find" + "\"" + searchText.getText() + "\""); box.open(); } } }); Button cancelButton = new Button(composite, SWT.PUSH); cancelButton.setText("Cancel"); cancelButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); cancelButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { shell.setVisible(false); } }); shell.pack(); }
From source file:DNDExample.java
private void createDropTypes(Composite parent) { parent.setLayout(new RowLayout(SWT.VERTICAL)); Button b = new Button(parent, SWT.CHECK); b.setText("Text Transfer"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.widget; if (b.getSelection()) { addDropTransfer(TextTransfer.getInstance()); } else { removeDropTransfer(TextTransfer.getInstance()); }/*from ww w. ja v a2 s .c o m*/ } }); b = new Button(parent, SWT.CHECK); b.setText("RTF Transfer"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.widget; if (b.getSelection()) { addDropTransfer(RTFTransfer.getInstance()); } else { removeDropTransfer(RTFTransfer.getInstance()); } } }); b = new Button(parent, SWT.CHECK); b.setText("HTML Transfer"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.widget; if (b.getSelection()) { addDropTransfer(HTMLTransfer.getInstance()); } else { removeDropTransfer(HTMLTransfer.getInstance()); } } }); b = new Button(parent, SWT.CHECK); b.setText("File Transfer"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.widget; if (b.getSelection()) { addDropTransfer(FileTransfer.getInstance()); } else { removeDropTransfer(FileTransfer.getInstance()); } } }); }
From source file:DNDExample.java
private void createDropWidget(Composite parent) { parent.setLayout(new FormLayout()); Combo combo = new Combo(parent, SWT.READ_ONLY); combo.setItems(new String[] { "Toggle Button", "Radio Button", "Checkbox", "Canvas", "Label", "List", "Table", "Tree", "Text" }); combo.select(LABEL);/* www . j a v a 2s . c om*/ dropControlType = combo.getSelectionIndex(); dropControl = createWidget(dropControlType, parent, "Drop Target"); combo.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Object data = dropControl.getLayoutData(); Composite parent = dropControl.getParent(); dropControl.dispose(); Combo c = (Combo) e.widget; dropControlType = c.getSelectionIndex(); dropControl = createWidget(dropControlType, parent, "Drop Target"); dropControl.setLayoutData(data); if (dropEnabled) createDropTarget(); parent.layout(); } }); Button b = new Button(parent, SWT.CHECK); b.setText("DropTarget"); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { Button b = (Button) e.widget; dropEnabled = b.getSelection(); if (dropEnabled) { createDropTarget(); } else { if (dropTarget != null) { dropTarget.dispose(); } dropTarget = null; } } }); FormData data = new FormData(); data.top = new FormAttachment(0, 10); data.bottom = new FormAttachment(combo, -10); data.left = new FormAttachment(0, 10); data.right = new FormAttachment(100, -10); dropControl.setLayoutData(data); data = new FormData(); data.bottom = new FormAttachment(100, -10); data.left = new FormAttachment(0, 10); combo.setLayoutData(data); data = new FormData(); data.bottom = new FormAttachment(100, -10); data.left = new FormAttachment(combo, 10); b.setLayoutData(data); }