List of usage examples for org.eclipse.swt.widgets Composite setLayoutData
public void setLayoutData(Object layoutData)
From source file:ummisco.gama.ui.views.displays.SWTChartEditor.java
/** * Creates a new editor.//from w w w . j av a2 s.c om * * @param display * the display. * @param chart2edit * the chart to edit. */ public SWTChartEditor(final Display display, final JFreeChart chart2edit, final Point position) { this.shell = new Shell(display, SWT.APPLICATION_MODAL | SWT.NO_TRIM); this.shell.setSize(400, 500); this.shell.setBackground(WorkbenchHelper.getDisplay().getSystemColor(SWT.COLOR_BLACK)); // this.shell.setAlpha(140); this.chart = chart2edit; this.shell.setText("Chart properties"); this.shell.setLocation(position); final GridLayout layout = new GridLayout(2, false); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 5; this.shell.setLayout(layout); final Composite main = new Composite(this.shell, SWT.NONE); main.setLayout(new FillLayout()); main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); final TabFolder tab = new TabFolder(main, SWT.BORDER); // build first tab final TabItem item1 = new TabItem(tab, SWT.NONE); item1.setText(" " + "Title" + " "); this.titleEditor = new SWTTitleEditor(tab, SWT.NONE, this.chart.getTitle()); item1.setControl(this.titleEditor); // build second tab final TabItem item2 = new TabItem(tab, SWT.NONE); item2.setText(" " + "Plot" + " "); this.plotEditor = new SWTPlotEditor(tab, SWT.NONE, this.chart.getPlot()); item2.setControl(this.plotEditor); // build the third tab final TabItem item3 = new TabItem(tab, SWT.NONE); item3.setText(" " + "Other" + " "); this.otherEditor = new SWTOtherEditor(tab, SWT.NONE, this.chart); item3.setControl(this.otherEditor); // ok and cancel buttons final Button cancel = new Button(this.shell, SWT.PUSH); cancel.setText(" Cancel "); cancel.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); cancel.pack(); cancel.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { SWTChartEditor.this.shell.dispose(); } }); final Button ok = new Button(this.shell, SWT.PUSH | SWT.OK); ok.setText(" Ok "); ok.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); ok.pack(); ok.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { updateChart(SWTChartEditor.this.chart); SWTChartEditor.this.shell.dispose(); } }); }
From source file:fr.inria.soctrace.framesoc.ui.piechart.view.StatisticsPieChartView.java
@Override public void createFramesocPartControl(Composite parent) { // parent layout GridLayout gl_parent = new GridLayout(1, false); gl_parent.verticalSpacing = 2;// ww w . j av a2 s.c o m gl_parent.marginWidth = 0; gl_parent.horizontalSpacing = 0; gl_parent.marginHeight = 0; parent.setLayout(gl_parent); // ------------------------------- // Base GUI: pie + table // ------------------------------- SashForm sashForm = new SashForm(parent, SWT.BORDER | SWT.SMOOTH); sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); // Composite Left: composite combo + composite pie Composite compositeLeft = new Composite(sashForm, SWT.NONE); GridLayout gl_compositeLeft = new GridLayout(1, false); gl_compositeLeft.marginBottom = 3; gl_compositeLeft.verticalSpacing = 0; gl_compositeLeft.marginHeight = 0; compositeLeft.setLayout(gl_compositeLeft); // Composite Combo Composite compositeCombo = new Composite(compositeLeft, SWT.NONE); compositeCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); GridLayout gl_compositeCombo = new GridLayout(1, false); gl_compositeCombo.marginWidth = 0; compositeCombo.setLayout(gl_compositeCombo); // combo combo = new Combo(compositeCombo, SWT.READ_ONLY); combo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); combo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean firstTime = true; for (LoaderDescriptor d : loaderDescriptors) { firstTime = firstTime && !d.dataLoaded(); } if (firstTime) { return; } currentDescriptor = loaderDescriptors.get(combo.getSelectionIndex()); cleanTableFilter(); refreshTableFilter(); // use global load interval timeBar.setSelection(globalLoadInterval); loadPieChart(); } }); int position = 0; for (LoaderDescriptor descriptor : loaderDescriptors) { combo.add(descriptor.loader.getStatName(), position++); } combo.select(0); currentDescriptor = loaderDescriptors.get(0); combo.setEnabled(false); // Composite Pie compositePie = new Group(compositeLeft, SWT.NONE); // Fill layout with Grid Data (FILL) to allow correct resize compositePie.setLayout(new FillLayout()); compositePie.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); txtDescription = new Text(compositePie, SWT.READ_ONLY | SWT.WRAP | SWT.CENTER | SWT.MULTI); txtDescription.setEnabled(false); txtDescription.setEditable(false); txtDescription.setText("Select one of the above metrics, then press the Load button."); txtDescription.setVisible(false); // Composite Table Composite compositeTable = new Composite(sashForm, SWT.NONE); GridLayout gl_compositeTable = new GridLayout(1, false); compositeTable.setLayout(gl_compositeTable); // filter textFilter = new Text(compositeTable, SWT.BORDER); textFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); textFilter.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { String filter = textFilter.getText().trim(); if (filter.isEmpty()) { cleanTableFilter(); } } @Override public void focusGained(FocusEvent e) { String filter = textFilter.getText().trim(); if (filter.equals(FILTER_HINT)) { textFilter.setText(""); textFilter.setData(""); textFilter.setForeground(blackColor); } } }); textFilter.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.keyCode == SWT.CR || textFilter.getText().trim().isEmpty()) { textFilter.setData(textFilter.getText()); refreshTableFilter(); } } }); // table tableTreeViewer = new TreeViewer(compositeTable, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL); tableTreeViewer.setContentProvider(new TreeContentProvider()); comparator = new StatisticsColumnComparator(); tableTreeViewer.setComparator(comparator); Tree table = tableTreeViewer.getTree(); table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); table.setLinesVisible(true); table.setHeaderVisible(true); createColumns(); createContextMenu(); // status bar Composite statusBar = new Composite(compositeTable, SWT.BORDER); GridLayout statusBarLayout = new GridLayout(); GridData statusBarGridData = new GridData(); statusBarGridData.horizontalAlignment = SWT.FILL; statusBarGridData.grabExcessHorizontalSpace = true; statusBar.setLayoutData(statusBarGridData); statusBarLayout.numColumns = 1; statusBar.setLayout(statusBarLayout); // text statusText = new Text(statusBar, SWT.NONE); statusText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); statusText.setText(getStatus(0, 0)); // ------------------------------- // TIME MANAGEMENT BAR // ------------------------------- Composite timeComposite = new Composite(parent, SWT.BORDER); timeComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); GridLayout gl_timeComposite = new GridLayout(1, false); gl_timeComposite.horizontalSpacing = 0; timeComposite.setLayout(gl_timeComposite); // time manager timeBar = new TimeBar(timeComposite, SWT.NONE, true, true); timeBar.setEnabled(false); combo.setEnabled(false); IStatusLineManager statusLineManager = getViewSite().getActionBars().getStatusLineManager(); timeBar.setStatusLineManager(statusLineManager); // button to synch the timebar with the gantt timeBar.getSynchButton().addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (combo != null && timeBar != null && currentDescriptor != null) { if (currentDescriptor.dataLoaded()) { timeBar.setSelection(currentDescriptor.interval.startTimestamp, currentDescriptor.interval.endTimestamp); } else { timeBar.setSelection(currentShownTrace.getMinTimestamp(), currentShownTrace.getMaxTimestamp()); } } } }); timeBar.getSynchButton().setToolTipText("Synch Selection With Pie Chart"); // load button timeBar.getLoadButton().addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (combo.getSelectionIndex() == -1) return; currentDescriptor = loaderDescriptors.get(combo.getSelectionIndex()); cleanTableFilter(); refreshTableFilter(); loadPieChart(); } }); // ---------- // TOOL BAR // ---------- // filters and actions createFilterDialogs(); createActions(); // create SWT resources createResources(); // clean the filter, after creating the font cleanTableFilter(); }
From source file:com.planetmayo.debrief.satc_rcp.views.MaintainContributionsView.java
private void initPreferencesGroup(Composite parent) { GridData gridData = new GridData(); gridData.horizontalAlignment = SWT.FILL; gridData.grabExcessHorizontalSpace = true; Group group = new Group(parent, SWT.SHADOW_ETCHED_IN); GridLayout layout = new GridLayout(1, false); group.setLayoutData(gridData);//from w w w .j a va 2s.c o m group.setLayout(layout); group.setText("Preferences"); final ScrolledComposite scrolled = new ScrolledComposite(group, SWT.H_SCROLL); scrolled.setLayoutData(new GridData(GridData.FILL_BOTH)); final Composite preferencesComposite = UIUtils.createScrolledBody(scrolled, SWT.NONE); preferencesComposite.setLayout(new GridLayout(6, false)); scrolled.addListener(SWT.Resize, new Listener() { @Override public void handleEvent(Event e) { scrolled.setMinSize(preferencesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); } }); scrolled.setAlwaysShowScrollBars(true); scrolled.setContent(preferencesComposite); scrolled.setMinSize(preferencesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); scrolled.setExpandHorizontal(true); scrolled.setExpandVertical(true); liveConstraints = new Button(preferencesComposite, SWT.TOGGLE); liveConstraints.setText("Auto-Recalc of Constraints"); liveConstraints.setEnabled(false); liveConstraints .setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_CENTER)); recalculate = new Button(preferencesComposite, SWT.DEFAULT); recalculate.setText("Calculate Solution"); recalculate.setEnabled(false); recalculate.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (activeSolver != null) { // ok - make sure the performance tab is open graphTabs.setSelection(performanceTab); activeSolver.run(true, true); main.setSize(0, 0); main.getParent().layout(true, true); } } }); recalculate.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.VERTICAL_ALIGN_CENTER)); cancelGeneration = new Button(preferencesComposite, SWT.PUSH); cancelGeneration.setText("Cancel"); cancelGeneration.setVisible(false); cancelGeneration.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (activeSolver != null) { activeSolver.cancel(); } } }); suppressCuts = new Button(preferencesComposite, SWT.CHECK); suppressCuts.setText("Suppress Cuts"); suppressCuts.setVisible(true); suppressCuts.setEnabled(false); suppressCuts.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (activeSolver != null) { boolean doSuppress = suppressCuts.getSelection(); activeSolver.setAutoSuppress(doSuppress); } } }); showOSCourse = new Button(preferencesComposite, SWT.CHECK); showOSCourse.setText("Plot O/S Course"); showOSCourse.setVisible(true); showOSCourse.setEnabled(false); showOSCourse.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (activeSolver != null) { redoOwnshipStates(); } } }); Composite precisionPanel = new Composite(preferencesComposite, SWT.NONE); precisionPanel.setLayoutData(new GridData( GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER)); GridLayout precisionLayout = new GridLayout(2, false); precisionLayout.horizontalSpacing = 5; precisionPanel.setLayout(precisionLayout); Label precisionLabel = new Label(precisionPanel, SWT.NONE); precisionLabel.setText("Precision:"); precisionLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER)); precisionsCombo = new ComboViewer(precisionPanel); precisionsCombo.getCombo().setEnabled(false); precisionsCombo.setContentProvider(new ArrayContentProvider()); precisionsCombo.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { return ((Precision) element).getLabel(); } }); precisionsCombo.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { ISelection sel = precisionsCombo.getSelection(); IStructuredSelection cSel = (IStructuredSelection) sel; Precision precision = (Precision) cSel.getFirstElement(); if (activeSolver != null) { activeSolver.setPrecision(precision); } } }); }
From source file:msi.gama.gui.swt.controls.SWTChartEditor.java
/** * Creates a new editor.//from w ww . j av a 2 s .c om * * @param display the display. * @param chart2edit the chart to edit. */ public SWTChartEditor(final Display display, final JFreeChart chart2edit, final Point position) { this.shell = new Shell(display, SWT.APPLICATION_MODAL | SWT.NO_TRIM); this.shell.setSize(400, 500); this.shell.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); // this.shell.setAlpha(140); this.chart = chart2edit; this.shell.setText("Chart properties"); this.shell.setLocation(position); GridLayout layout = new GridLayout(2, false); layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 5; this.shell.setLayout(layout); Composite main = new Composite(this.shell, SWT.NONE); main.setLayout(new FillLayout()); main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); TabFolder tab = new TabFolder(main, SWT.BORDER); // build first tab TabItem item1 = new TabItem(tab, SWT.NONE); item1.setText(" " + "Title" + " "); this.titleEditor = new SWTTitleEditor(tab, SWT.NONE, this.chart.getTitle()); item1.setControl(this.titleEditor); // build second tab TabItem item2 = new TabItem(tab, SWT.NONE); item2.setText(" " + "Plot" + " "); this.plotEditor = new SWTPlotEditor(tab, SWT.NONE, this.chart.getPlot()); item2.setControl(this.plotEditor); // build the third tab TabItem item3 = new TabItem(tab, SWT.NONE); item3.setText(" " + "Other" + " "); this.otherEditor = new SWTOtherEditor(tab, SWT.NONE, this.chart); item3.setControl(this.otherEditor); // ok and cancel buttons Button cancel = new Button(this.shell, SWT.PUSH); cancel.setText(" Cancel "); cancel.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); cancel.pack(); cancel.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { SWTChartEditor.this.shell.dispose(); } }); Button ok = new Button(this.shell, SWT.PUSH | SWT.OK); ok.setText(" Ok "); ok.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); ok.pack(); ok.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { updateChart(SWTChartEditor.this.chart); SWTChartEditor.this.shell.dispose(); } }); }
From source file:edu.harvard.i2b2.analysis.ui.AnalysisComposite.java
/** * Create the composite//from w ww. j av a2 s.c om * * @param parent * @param style */ public AnalysisComposite(Composite parent, int style) { super(parent, style); setLayout(new GridLayout()); this.setSize(557, 224); // Create the types Transfer[] types = new Transfer[] { TextTransfer.getInstance() }; final Composite composite_2 = new Composite(this, SWT.NONE); composite_2.setLayout(new FillLayout()); final GridData gd_composite_2 = new GridData(SWT.FILL, SWT.FILL, true, true); gd_composite_2.heightHint = 263; gd_composite_2.widthHint = 540; composite_2.setLayoutData(gd_composite_2); final SashForm sashForm = new SashForm(composite_2, SWT.HORIZONTAL); sashForm.setOrientation(SWT.HORIZONTAL); { composite2 = new FramedComposite(sashForm, SWT.SHADOW_NONE); GridLayout composite2Layout = new GridLayout(); composite2Layout.horizontalSpacing = 1; composite2.setLayout(composite2Layout); { composite3 = new FramedComposite(composite2, SWT.SHADOW_NONE); GridLayout composite3Layout = new GridLayout(); composite3Layout.numColumns = 2; composite3Layout.marginHeight = 3; GridData composite3LData = new GridData(); composite3LData.grabExcessHorizontalSpace = true; composite3LData.horizontalAlignment = GridData.FILL; composite3LData.heightHint = 25; composite3.setLayoutData(composite3LData); composite3.setLayout(composite3Layout); { label2 = new Label(composite3, SWT.NONE); label2.setText("Graphic Analyses"); GridData label2LData = new GridData(); label2LData.horizontalAlignment = GridData.FILL; label2LData.heightHint = 14; label2LData.grabExcessHorizontalSpace = true; label2.setLayoutData(label2LData); label2.setAlignment(SWT.CENTER); } { clearButton = new Button(composite3, SWT.PUSH | SWT.CENTER); GridData button1LData = new GridData(); button1LData.horizontalAlignment = GridData.CENTER; button1LData.widthHint = 19; button1LData.verticalAlignment = GridData.BEGINNING; button1LData.heightHint = 18; clearButton.setLayoutData(button1LData); clearButton.setText("x"); clearButton.setToolTipText("Remove all nodes in analysis tree panel below"); clearButton.setFont(SWTResourceManager.getFont("Tahoma", 10, 1, false, false)); clearButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent evt) { clearButtonWidgetSelected(evt); } }); } } { tree1 = new Tree(composite2, SWT.BORDER); tree1.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent e) { final TreeItem item = tree1.getSelection()[0]; if (item.getText().equalsIgnoreCase("No results to display")) { return; } getDisplay().syncExec(new Runnable() { public void run() { queryName = item.getParentItem().getText(); label1.setText(item.getParentItem().getText()); } }); setSelection((QueryResultData) item.getData()); } }); GridData tree1LData = new GridData(); tree1LData.verticalAlignment = GridData.FILL; tree1LData.horizontalAlignment = GridData.FILL; tree1LData.grabExcessHorizontalSpace = true; tree1LData.grabExcessVerticalSpace = true; tree1.setLayoutData(tree1LData); { /* * analyses = new TreeItem(tree1, SWT.NONE); * analyses.setText("Analyses"); analyses * .setImage(SWTResourceManager * .getImage("edu/harvard/i2b2/analysis/ui/openFolder.jpg" * )); analyses.setExpanded(true); */ } } } { final FramedComposite right_composite = new FramedComposite(sashForm, SWT.SHADOW_NONE); GridLayout right_compositeLayout = new GridLayout(); right_composite.setLayout(right_compositeLayout); { final FramedComposite top_composite = new FramedComposite(right_composite, SWT.SHADOW_NONE); GridLayout top_compositeLayout = new GridLayout(); top_compositeLayout.makeColumnsEqualWidth = true; top_composite.setLayout(top_compositeLayout); GridData top_compositeLData = new GridData(); top_compositeLData.horizontalAlignment = GridData.FILL; top_compositeLData.grabExcessHorizontalSpace = true; top_composite.setLayoutData(top_compositeLData); { label1 = new Label(top_composite, SWT.NO_TRIM); GridData gd_top_composite = new GridData(); gd_top_composite.grabExcessHorizontalSpace = true; gd_top_composite.horizontalAlignment = GridData.FILL; label1.setLayoutData(gd_top_composite); queryName = "Query Name: "; label1.setText("Query Name: "); label1.addListener(SWT.Resize, new Listener() { public void handleEvent(Event event) { int width = label1.getBounds().width; GC gc = new GC(Display.getCurrent().getActiveShell()); if (gc != null) { gc.setFont(label1.getFont()); Point pt = gc.stringExtent(queryName); if (pt.x <= width) { label1.setText(queryName); gc.dispose(); return; } int charWidth = pt.x / queryName.length(); int charNum = width / charWidth; label1.setText(queryName.substring(0, charNum - 6) + "..."); // System.out.println("size: "+label1.getSize() // + "; width"+width+ // " font width: "+pt.x+"char width: "+pt.x/ // queryName.length()); gc.dispose(); } } }); label1.addMouseTrackListener(new MouseTrackListener() { public void mouseEnter(MouseEvent arg0) { top_composite.setForeground(getDisplay().getSystemColor(SWT.COLOR_YELLOW)); } public void mouseExit(MouseEvent arg0) { top_composite.setForeground(getDisplay().getSystemColor(SWT.COLOR_BLACK)); } public void mouseHover(MouseEvent arg0) { top_composite.setForeground(getDisplay().getSystemColor(SWT.COLOR_YELLOW)); } }); } { DropTarget target1 = new DropTarget(top_composite, DND.DROP_COPY); // RowData target1LData = new RowData(); // target1.setLayoutData(target1LData); target1.setTransfer(types); target1.addDropListener(new DropTargetAdapter() { @SuppressWarnings("unchecked") public void drop(DropTargetEvent event) { if (event.data == null) { event.detail = DND.DROP_NONE; return; } try { SAXBuilder parser = new SAXBuilder(); String xmlContent = (String) event.data; java.io.StringReader xmlStringReader = new java.io.StringReader(xmlContent); org.jdom.Document tableDoc = parser.build(xmlStringReader); org.jdom.Element tableXml = tableDoc.getRootElement().getChild("query_master", Namespace.getNamespace("http://www.i2b2.org/xsd/cell/crc/psm/1.1/")); if (tableXml == null) { tableXml = tableDoc.getRootElement().getChild("query_instance", Namespace.getNamespace("http://www.i2b2.org/xsd/cell/crc/psm/1.1/")); if (tableXml == null) { MessageBox mBox = new MessageBox(top_composite.getShell(), SWT.ICON_INFORMATION | SWT.OK); mBox.setText("Please Note ..."); mBox.setMessage("You can not drop this item here."); mBox.open(); event.detail = DND.DROP_NONE; return; } else { try { QueryInstanceData ndata = new QueryInstanceData(); // ndata.name(tableXml.getChildText( // "name")); // label1.setText("Query Name: " + // ndata.name()); ndata.xmlContent(null); ndata.id(tableXml.getChildTextTrim("query_instance_id")); ndata.userId(tableXml.getChildTextTrim("user_id")); ndata.name(tableXml.getChildTextTrim("name")); insertNodes(ndata); setSelection(tree1.getItemCount() - 1); } catch (Exception e) { e.printStackTrace(); return; } event.detail = DND.DROP_NONE; return; } } try { JAXBUtil jaxbUtil = AnalysisJAXBUtil.getJAXBUtil(); QueryMasterData ndata = new QueryMasterData(); ndata.name(tableXml.getChildText("name")); // label1.setText("Query Name: " + // ndata.name()); ndata.xmlContent(null); ndata.id(tableXml.getChildTextTrim("query_master_id")); ndata.userId(tableXml.getChildTextTrim("user_id")); // get query instance String xmlRequest = ndata.writeContentQueryXML(); // lastRequestMessage(xmlRequest); String xmlResponse = QueryClient.sendQueryRequestREST(xmlRequest); // lastResponseMessage(xmlResponse); JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse); ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue(); BodyType bt = messageType.getMessageBody(); InstanceResponseType instanceResponseType = (InstanceResponseType) new JAXBUnWrapHelper() .getObjectByClass(bt.getAny(), InstanceResponseType.class); QueryInstanceData instanceData = null; XMLGregorianCalendar startDate = null; for (QueryInstanceType queryInstanceType : instanceResponseType .getQueryInstance()) { QueryInstanceData runData = new QueryInstanceData(); runData.visualAttribute("FA"); runData.tooltip("The results of the query run"); runData.id(new Integer(queryInstanceType.getQueryInstanceId()).toString()); XMLGregorianCalendar cldr = queryInstanceType.getStartDate(); runData.name(ndata.name()); if (instanceData == null) { startDate = cldr; instanceData = runData; } else { if (cldr.toGregorianCalendar() .compareTo(startDate.toGregorianCalendar()) > 0) { startDate = cldr; instanceData = runData; } } } insertNodes(instanceData); if (treeItem.getItemCount() == 0) { getDisplay().syncExec(new Runnable() { public void run() { TreeItem treeItem1 = new TreeItem(treeItem, SWT.NONE); treeItem1.setText("No results to display"); treeItem1.setForeground(getDisplay().getSystemColor(SWT.COLOR_RED)); treeItem1.setExpanded(true); treeItem1.setImage(SWTResourceManager .getImage("edu/harvard/i2b2/analysis/ui/leaf.jpg")); JFreeChart chart = createNoDataChart(createEmptyDataset()); composite1.getChildren()[0].dispose(); ChartComposite frame = new ChartComposite(composite1, SWT.NONE, chart, true, true, false, true, true); frame.pack(); composite1.layout(); tree1.select(treeItem1); return; } }); } else { setSelection(tree1.getItemCount() - 1); } } catch (Exception e) { e.printStackTrace(); return; } event.detail = DND.DROP_NONE; } catch (Exception e) { e.printStackTrace(); event.detail = DND.DROP_NONE; return; } } @Override public void dragLeave(DropTargetEvent event) { super.dragLeave(event); top_composite.setForeground(getDisplay().getSystemColor(SWT.COLOR_BLACK)); } public void dragEnter(DropTargetEvent event) { event.detail = DND.DROP_COPY; top_composite.setForeground(getDisplay().getSystemColor(SWT.COLOR_YELLOW)); } }); } top_composite.addMouseTrackListener(new MouseTrackListener() { public void mouseEnter(MouseEvent arg0) { top_composite.setForeground(getDisplay().getSystemColor(SWT.COLOR_YELLOW)); } public void mouseExit(MouseEvent arg0) { top_composite.setForeground(getDisplay().getSystemColor(SWT.COLOR_BLACK)); } public void mouseHover(MouseEvent arg0) { top_composite.setForeground(getDisplay().getSystemColor(SWT.COLOR_YELLOW)); } }); } { composite1 = new Composite(right_composite, SWT.BORDER); FillLayout composite1Layout = new FillLayout(org.eclipse.swt.SWT.HORIZONTAL); GridData composite1LData = new GridData(); composite1LData.grabExcessHorizontalSpace = true; composite1LData.grabExcessVerticalSpace = true; composite1LData.horizontalAlignment = GridData.FILL; composite1LData.verticalAlignment = GridData.FILL; composite1.setLayoutData(composite1LData); composite1.setLayout(composite1Layout); // composite1.setBackground(SWTResourceManager.getColor(255, // 255, // 0)); getDisplay().syncExec(new Runnable() { public void run() { JFreeChart chart = createEmptyChart(createEmptyDataset()); /* final ChartComposite frame = */new ChartComposite(composite1, SWT.NONE, chart, true, true, false, true, true); } }); } } { // label2 = new Label(top_composite, SWT.NONE); // label2.setText("2512+3 patients"); // label2.setBounds(254, 7, 108, 19); } { DropTarget target2 = new DropTarget(tree1, DND.DROP_COPY); target2.setTransfer(types); target2.addDropListener(new DropTargetAdapter() { public void dragEnter(DropTargetEvent event) { event.detail = DND.DROP_COPY; } @SuppressWarnings("unchecked") public void drop(DropTargetEvent event) { if (event.data == null) { event.detail = DND.DROP_NONE; return; } try { SAXBuilder parser = new SAXBuilder(); String xmlContent = (String) event.data; java.io.StringReader xmlStringReader = new java.io.StringReader(xmlContent); org.jdom.Document tableDoc = parser.build(xmlStringReader); org.jdom.Element tableXml = tableDoc.getRootElement().getChild("query_master", Namespace.getNamespace("http://www.i2b2.org/xsd/cell/crc/psm/1.1/")); if (tableXml == null) { tableXml = tableDoc.getRootElement().getChild("query_instance", Namespace.getNamespace("http://www.i2b2.org/xsd/cell/crc/psm/1.1/")); if (tableXml == null) { MessageBox mBox = new MessageBox(tree1.getShell(), SWT.ICON_INFORMATION | SWT.OK); mBox.setText("Please Note ..."); mBox.setMessage("You can not drop this item here."); mBox.open(); event.detail = DND.DROP_NONE; return; } else { try { // JAXBUtil jaxbUtil = // AnalysisJAXBUtil.getJAXBUtil(); QueryInstanceData ndata = new QueryInstanceData(); // ndata.name(tableXml.getChildText("name")); // label1.setText("Query Name: " + // ndata.name()); ndata.xmlContent(null); ndata.id(tableXml.getChildTextTrim("query_instance_id")); ndata.userId(tableXml.getChildTextTrim("user_id")); ndata.name(tableXml.getChildTextTrim("name")); // clearTree(); insertNodes(ndata); setSelection(tree1.getItemCount() - 1); } catch (Exception e) { e.printStackTrace(); return; } event.detail = DND.DROP_NONE; return; } } try { JAXBUtil jaxbUtil = AnalysisJAXBUtil.getJAXBUtil(); QueryMasterData ndata = new QueryMasterData(); ndata.name(tableXml.getChildText("name")); // label1.setText("Query Name: " + ndata.name()); ndata.xmlContent(null); ndata.id(tableXml.getChildTextTrim("query_master_id")); ndata.userId(tableXml.getChildTextTrim("user_id")); // get query instance String xmlRequest = ndata.writeContentQueryXML(); // lastRequestMessage(xmlRequest); String xmlResponse = QueryClient.sendQueryRequestREST(xmlRequest); // lastResponseMessage(xmlResponse); JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse); ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue(); BodyType bt = messageType.getMessageBody(); InstanceResponseType instanceResponseType = (InstanceResponseType) new JAXBUnWrapHelper() .getObjectByClass(bt.getAny(), InstanceResponseType.class); QueryInstanceData instanceData = null; XMLGregorianCalendar startDate = null; for (QueryInstanceType queryInstanceType : instanceResponseType.getQueryInstance()) { QueryInstanceData runData = new QueryInstanceData(); runData.visualAttribute("FA"); runData.tooltip("The results of the query run"); runData.id(new Integer(queryInstanceType.getQueryInstanceId()).toString()); XMLGregorianCalendar cldr = queryInstanceType.getStartDate(); runData.name(ndata.name()); if (instanceData == null) { startDate = cldr; instanceData = runData; } else { if (cldr.toGregorianCalendar().compareTo(startDate.toGregorianCalendar()) > 0) { startDate = cldr; instanceData = runData; } } } // clearTree(); insertNodes(instanceData); setSelection(tree1.getItemCount() - 1); } catch (Exception e) { e.printStackTrace(); return; } event.detail = DND.DROP_NONE; } catch (Exception e) { e.printStackTrace(); event.detail = DND.DROP_NONE; return; } } }); } sashForm.setWeights(new int[] { 30, 70 }); sashForm.setSashWidth(1); }
From source file:fr.inria.soctrace.framesoc.ui.histogram.view.HistogramView.java
@Override public void createFramesocPartControl(Composite parent) { statusLineManager = getViewSite().getActionBars().getStatusLineManager(); // parent layout GridLayout gl_parent = new GridLayout(1, false); gl_parent.verticalSpacing = 2;//www . j av a 2 s .c o m gl_parent.marginWidth = 0; gl_parent.horizontalSpacing = 0; gl_parent.marginHeight = 0; parent.setLayout(gl_parent); // Sash SashForm sashForm = new SashForm(parent, SWT.NONE); sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); // Chart Composite compositeChart = new Composite(sashForm, SWT.BORDER); FillLayout fl_compositeChart = new FillLayout(SWT.HORIZONTAL); compositeChart.setLayout(fl_compositeChart); compositeChart.addControlListener(new ControlAdapter() { @Override public void controlResized(ControlEvent e) { int width = Math.max(compositeChart.getSize().x - 40, 1); numberOfTicks = Math.max(width / TIMESTAMP_MAX_SIZE, 1); refresh(false, false, true); } }); // Configuration Composite compositeConf = new Composite(sashForm, SWT.NONE); GridLayout gl_compositeConf = new GridLayout(1, false); gl_compositeConf.marginHeight = 1; gl_compositeConf.verticalSpacing = 0; gl_compositeConf.marginWidth = 0; compositeConf.setLayout(gl_compositeConf); compositeConf.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); // Tab folder TabFolder tabFolder = new TabFolder(compositeConf, SWT.NONE); tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); PatternFilter filter = new TreePatternFilter(); TreeContentProvider contentProvider = new TreeContentProvider(); ViewerComparator treeComparator = new ViewerComparator(); SelectionChangedListener selectionChangeListener = new SelectionChangedListener(); CheckStateListener checkStateListener = new CheckStateListener(); SquareIconLabelProvider p = null; // Tab item types TabItem tbtmEventTypes = new TabItem(tabFolder, SWT.NONE); tbtmEventTypes.setData(ConfigurationDimension.TYPE); tbtmEventTypes.setText(ConfigurationDimension.TYPE.getName()); filter.setIncludeLeadingWildcard(true); FilteredCheckboxTree typeTree = new FilteredCheckboxTree(tabFolder, SWT.BORDER, filter, true); configurationMap.get(ConfigurationDimension.TYPE).tree = typeTree; typeTree.getViewer().setContentProvider(contentProvider); p = new EventTypeTreeLabelProvider(); labelProviders.add(p); typeTree.getViewer().setLabelProvider(p); typeTree.getViewer().setComparator(treeComparator); typeTree.addCheckStateListener(checkStateListener); typeTree.getViewer().addSelectionChangedListener(selectionChangeListener); tbtmEventTypes.setControl(typeTree); // Tab item producers TabItem tbtmEventProducers = new TabItem(tabFolder, SWT.NONE); tbtmEventProducers.setData(ConfigurationDimension.PRODUCERS); tbtmEventProducers.setText(ConfigurationDimension.PRODUCERS.getName()); FilteredCheckboxTree prodTree = new FilteredCheckboxTree(tabFolder, SWT.BORDER, filter, true); configurationMap.get(ConfigurationDimension.PRODUCERS).tree = prodTree; prodTree.getViewer().setContentProvider(contentProvider); p = new EventProducerTreeLabelProvider(); labelProviders.add(p); prodTree.getViewer().setLabelProvider(p); prodTree.getViewer().setComparator(treeComparator); prodTree.addCheckStateListener(checkStateListener); prodTree.getViewer().addSelectionChangedListener(selectionChangeListener); tbtmEventProducers.setControl(prodTree); // sash weights sashForm.setWeights(new int[] { 80, 20 }); // tab switch tabFolder.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { currentDimension = (ConfigurationDimension) event.item.getData(); enableTreeButtons(); enableSubTreeButtons(); } }); // Buttons Composite compositeBtn = new Composite(compositeConf, SWT.BORDER); GridLayout gl_compositeBtn = new GridLayout(10, false); gl_compositeBtn.marginWidth = 1; gl_compositeBtn.horizontalSpacing = 1; compositeBtn.setLayout(gl_compositeBtn); compositeBtn.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false, 1, 1)); btnCheckall = new Button(compositeBtn, SWT.NONE); btnCheckall.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1)); btnCheckall.setToolTipText("Check all"); btnCheckall.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/check_all.png")); btnCheckall.setEnabled(false); btnCheckall.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (configurationMap.get(currentDimension).roots != null) { FilteredCheckboxTree tree = configurationMap.get(currentDimension).tree; TreeContentProvider provider = (TreeContentProvider) tree.getViewer().getContentProvider(); Object[] roots = provider.getElements(tree.getViewer().getInput()); for (Object root : roots) { checkElementAndSubtree(root); } selectionChanged(); } } }); btnUncheckall = new Button(compositeBtn, SWT.NONE); btnUncheckall.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); btnUncheckall.setToolTipText("Uncheck all"); btnUncheckall.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/uncheck_all.png")); btnUncheckall.setEnabled(false); btnUncheckall.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { configurationMap.get(currentDimension).tree.setCheckedElements(EMPTY_ARRAY); selectionChanged(); } }); Label separator = new Label(compositeBtn, SWT.SEPARATOR | SWT.VERTICAL); GridData gd_separator = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1); gd_separator.horizontalIndent = 2; gd_separator.widthHint = 5; gd_separator.heightHint = 20; separator.setLayoutData(gd_separator); btnCheckSubtree = new Button(compositeBtn, SWT.NONE); btnCheckSubtree.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); btnCheckSubtree.setToolTipText("Check subtree"); btnCheckSubtree.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/check_subtree.png")); btnCheckSubtree.setEnabled(false); btnCheckSubtree.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (configurationMap.get(currentDimension).roots != null) { ITreeNode node = getCurrentSelection(configurationMap.get(currentDimension).tree); if (node == null) return; checkElementAndSubtree(node); selectionChanged(); } } }); btnUncheckSubtree = new Button(compositeBtn, SWT.NONE); btnUncheckSubtree.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); btnUncheckSubtree.setToolTipText("Uncheck subtree"); btnUncheckSubtree .setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/uncheck_subtree.png")); btnUncheckSubtree.setEnabled(false); btnUncheckSubtree.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (configurationMap.get(currentDimension).roots != null) { ITreeNode node = getCurrentSelection(configurationMap.get(currentDimension).tree); if (node == null) return; uncheckElement(node); uncheckAncestors(node); selectionChanged(); } } }); // Time management bar Composite timeComposite = new Composite(parent, SWT.BORDER); timeComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); GridLayout gl_timeComposite = new GridLayout(1, false); gl_timeComposite.horizontalSpacing = 0; timeComposite.setLayout(gl_timeComposite); // time manager timeBar = new TimeBar(timeComposite, SWT.NONE, true, true); timeBar.setEnabled(false); IStatusLineManager statusLineManager = getViewSite().getActionBars().getStatusLineManager(); timeBar.setStatusLineManager(statusLineManager); timeBar.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { TimeInterval barInterval = timeBar.getSelection(); if (marker == null) { addNewMarker(barInterval.startTimestamp, barInterval.endTimestamp); } else { marker.setStartValue(barInterval.startTimestamp); marker.setEndValue(barInterval.endTimestamp); } selectedTs0 = barInterval.startTimestamp; selectedTs1 = barInterval.endTimestamp; timeChanged = !barInterval.equals(loadedInterval); } }); // button to synch the timebar, producers and type with the current loaded data timeBar.getSynchButton().setToolTipText("Reset Timebar, Types and Producers"); timeBar.getSynchButton().addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (loadedInterval != null) { timeBar.setSelection(loadedInterval); if (marker != null && plot != null) { plot.removeDomainMarker(marker); marker = null; } } for (ConfigurationData data : configurationMap.values()) { data.tree.setCheckedElements(data.checked); } timeChanged = false; enableTreeButtons(); enableSubTreeButtons(); } }); // load button timeBar.getLoadButton().addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (timeChanged || configurationChanged) { loadHistogram(currentShownTrace, timeBar.getSelection()); } } }); // build toolbar IActionBars actionBars = getViewSite().getActionBars(); IToolBarManager toolBar = actionBars.getToolBarManager(); TableTraceIntervalAction.add(toolBar, createTableAction()); GanttTraceIntervalAction.add(toolBar, createGanttAction()); PieTraceIntervalAction.add(toolBar, createPieAction()); enableActions(false); }
From source file:org.eclipse.swt.snippets.SnippetExplorer.java
/** Initialize the SnippetExplorer controls. * * @param shell parent shell//from w ww .ja va 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:ImageAnalyzer.java
void createWidgets() { // Add the widgets to the shell in a grid layout. GridLayout layout = new GridLayout(); layout.marginHeight = 0;/*from ww w . j a v a 2 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); }
From source file:org.eclipse.swt.examples.imageanalyzer.ImageAnalyzer.java
void createWidgets() { // Add the widgets to the shell in a grid layout. GridLayout layout = new GridLayout(); layout.marginHeight = 0;// w w w. ja va 2s . c om layout.numColumns = 2; shell.setLayout(layout); // Add a composite to contain some control widgets across the top. Composite controls = new Composite(shell, SWT.NONE); RowLayout rowLayout = new RowLayout(); rowLayout.marginTop = 5; rowLayout.marginBottom = 5; rowLayout.spacing = 8; controls.setLayout(rowLayout); GridData gridData = new GridData(); gridData.horizontalSpan = 2; controls.setLayoutData(gridData); // Combo to change the background. Group group = new Group(controls, SWT.NONE); group.setLayout(new RowLayout()); group.setText(bundle.getString("Background")); backgroundCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY); backgroundCombo.setItems(bundle.getString("None"), bundle.getString("White"), bundle.getString("Black"), bundle.getString("Red"), bundle.getString("Green"), bundle.getString("Blue")); backgroundCombo.select(backgroundCombo.indexOf(bundle.getString("White"))); backgroundCombo.addSelectionListener(widgetSelectedAdapter(event -> changeBackground())); // Combo to change the compression ratio. group = new Group(controls, SWT.NONE); group.setLayout(new GridLayout(3, true)); group.setText(bundle.getString("Save_group")); imageTypeCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY); String[] types = { "JPEG", "PNG", "GIF", "ICO", "TIFF", "BMP" }; for (String type : types) { imageTypeCombo.add(type); } imageTypeCombo.select(imageTypeCombo.indexOf("JPEG")); imageTypeCombo.addSelectionListener(widgetSelectedAdapter(event -> { int index = imageTypeCombo.getSelectionIndex(); switch (index) { case 0: compressionCombo.setEnabled(true); compressionRatioLabel.setEnabled(true); if (compressionCombo.getItemCount() == 100) break; compressionCombo.removeAll(); for (int i = 0; i < 100; i++) { compressionCombo.add(String.valueOf(i + 1)); } compressionCombo.select(compressionCombo.indexOf("75")); break; case 1: compressionCombo.setEnabled(true); compressionRatioLabel.setEnabled(true); if (compressionCombo.getItemCount() == 10) break; compressionCombo.removeAll(); for (int i = 0; i < 4; i++) { compressionCombo.add(String.valueOf(i)); } compressionCombo.select(0); break; case 2: case 3: case 4: case 5: compressionCombo.setEnabled(false); compressionRatioLabel.setEnabled(false); break; } })); imageTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); compressionRatioLabel = new Label(group, SWT.NONE); compressionRatioLabel.setText(bundle.getString("Compression")); compressionRatioLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false)); compressionCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY); for (int i = 0; i < 100; i++) { compressionCombo.add(String.valueOf(i + 1)); } compressionCombo.select(compressionCombo.indexOf("75")); compressionCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); // 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.NONE); group.setLayout(new RowLayout()); group.setText(bundle.getString("X_scale")); scaleXCombo = new Combo(group, SWT.DROP_DOWN); for (String value : values) { scaleXCombo.add(value); } scaleXCombo.select(scaleXCombo.indexOf("1")); scaleXCombo.addSelectionListener(widgetSelectedAdapter(event -> scaleX())); // Combo to change the y scale. group = new Group(controls, SWT.NONE); group.setLayout(new RowLayout()); group.setText(bundle.getString("Y_scale")); scaleYCombo = new Combo(group, SWT.DROP_DOWN); for (String value : values) { scaleYCombo.add(value); } scaleYCombo.select(scaleYCombo.indexOf("1")); scaleYCombo.addSelectionListener(widgetSelectedAdapter(event -> scaleY())); // Combo to change the alpha value. group = new Group(controls, SWT.NONE); group.setLayout(new RowLayout()); group.setText(bundle.getString("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(widgetSelectedAdapter(event -> alpha())); // Check box to request incremental display. group = new Group(controls, SWT.NONE); group.setLayout(new RowLayout()); group.setText(bundle.getString("Display")); incrementalCheck = new Button(group, SWT.CHECK); incrementalCheck.setText(bundle.getString("Incremental")); incrementalCheck.setSelection(incremental); incrementalCheck.addSelectionListener( widgetSelectedAdapter(event -> incremental = ((Button) event.widget).getSelection())); // Check box to request transparent display. transparentCheck = new Button(group, SWT.CHECK); transparentCheck.setText(bundle.getString("Transparent")); transparentCheck.setSelection(transparent); transparentCheck.addSelectionListener(widgetSelectedAdapter(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(bundle.getString("Mask")); maskCheck.setSelection(showMask); maskCheck.addSelectionListener(widgetSelectedAdapter(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(bundle.getString("Background")); backgroundCheck.setSelection(showBackground); backgroundCheck.addSelectionListener( widgetSelectedAdapter(event -> showBackground = ((Button) event.widget).getSelection())); // Group the animation buttons. group = new Group(controls, SWT.NONE); group.setLayout(new RowLayout()); group.setText(bundle.getString("Animation")); // Push button to display the previous image in a multi-image file. previousButton = new Button(group, SWT.PUSH); previousButton.setText(bundle.getString("Previous")); previousButton.setEnabled(false); previousButton.addSelectionListener(widgetSelectedAdapter(event -> previous())); // Push button to display the next image in a multi-image file. nextButton = new Button(group, SWT.PUSH); nextButton.setText(bundle.getString("Next")); nextButton.setEnabled(false); nextButton.addSelectionListener(widgetSelectedAdapter(event -> next())); // Push button to toggle animation of a multi-image file. animateButton = new Button(group, SWT.PUSH); animateButton.setText(bundle.getString("Animate")); animateButton.setEnabled(false); animateButton.addSelectionListener(widgetSelectedAdapter(event -> animate())); // Label to show the image file type. typeLabel = new Label(shell, SWT.NONE); typeLabel.setText(bundle.getString("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 | SWT.NO_BACKGROUND); 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(event -> { if (image == null) { Rectangle bounds = imageCanvas.getBounds(); event.gc.fillRectangle(0, 0, bounds.width, bounds.height); } else { paintImage(event); } }); imageCanvas.addMouseMoveListener(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(widgetSelectedAdapter(event -> scrollHorizontally((ScrollBar) event.widget))); ScrollBar vertical = imageCanvas.getVerticalBar(); vertical.setVisible(true); vertical.setMinimum(0); vertical.setEnabled(false); vertical.addSelectionListener(widgetSelectedAdapter(event -> scrollVertically((ScrollBar) event.widget))); // Label to show the image size. sizeLabel = new Label(shell, SWT.NONE); sizeLabel.setText(bundle.getString("Size_initial")); sizeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the image depth. depthLabel = new Label(shell, SWT.NONE); depthLabel.setText(bundle.getString("Depth_initial")); depthLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the transparent pixel. transparentPixelLabel = new Label(shell, SWT.NONE); transparentPixelLabel.setText(bundle.getString("Transparent_pixel_initial")); transparentPixelLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the time to load. timeToLoadLabel = new Label(shell, SWT.NONE); timeToLoadLabel.setText(bundle.getString("Time_to_load_initial")); timeToLoadLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Separate the animation fields from the rest of the fields. Label 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.NONE); screenSizeLabel.setText(bundle.getString("Animation_size_initial")); screenSizeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the background pixel. backgroundPixelLabel = new Label(shell, SWT.NONE); backgroundPixelLabel.setText(bundle.getString("Background_pixel_initial")); backgroundPixelLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the image location (x, y). locationLabel = new Label(shell, SWT.NONE); locationLabel.setText(bundle.getString("Image_location_initial")); locationLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the image disposal method. disposalMethodLabel = new Label(shell, SWT.NONE); disposalMethodLabel.setText(bundle.getString("Disposal_initial")); disposalMethodLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the image delay time. delayTimeLabel = new Label(shell, SWT.NONE); delayTimeLabel.setText(bundle.getString("Delay_initial")); delayTimeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); // Label to show the background pixel. repeatCountLabel = new Label(shell, SWT.NONE); repeatCountLabel.setText(bundle.getString("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.NONE); paletteLabel.setText(bundle.getString("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(bundle.getString("Max_length_string")).x; gc.dispose(); gridData.widthHint = paletteWidth; gridData.heightHint = 16 * 11; // show at least 16 colors paletteCanvas.setLayoutData(gridData); paletteCanvas.addPaintListener(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(widgetSelectedAdapter(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(widgetSelectedAdapter(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.NONE); dataLabel.setText(bundle.getString("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(MouseListener.mouseDownAdapter(event -> { if (image != null && event.button == 1) { showColorForData(); } })); dataText.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent event) { if (image != null) { showColorForData(); } } }); // Label to show status and cursor location in image. statusLabel = new Label(shell, SWT.NONE); statusLabel.setText(""); gridData = new GridData(); gridData.horizontalSpan = 2; gridData.horizontalAlignment = GridData.FILL; statusLabel.setLayoutData(gridData); }
From source file:PaintExample.java
/** * Handles a mouseDown event.//from www. ja v a2 s. com * * @param event the mouse event detail information */ public void mouseDown(MouseEvent event) { if (event.button == 1) { // draw with left mouse button getPaintSurface().commitRubberbandSelection(); } else { // set text with right mouse button getPaintSurface().clearRubberbandSelection(); Shell shell = getPaintSurface().getShell(); final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialog.setText(PaintExample.getResourceString("tool.Text.dialog.title")); dialog.setLayout(new GridLayout()); Label label = new Label(dialog, SWT.NONE); label.setText(PaintExample.getResourceString("tool.Text.dialog.message")); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); final Text field = new Text(dialog, SWT.SINGLE | SWT.BORDER); field.setText(drawText); field.selectAll(); field.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); Composite buttons = new Composite(dialog, SWT.NONE); GridLayout layout = new GridLayout(2, true); layout.marginWidth = 0; buttons.setLayout(layout); buttons.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); Button ok = new Button(buttons, SWT.PUSH); ok.setText(PaintExample.getResourceString("OK")); ok.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); ok.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { drawText = field.getText(); dialog.dispose(); } }); Button cancel = new Button(buttons, SWT.PUSH); cancel.setText(PaintExample.getResourceString("Cancel")); cancel.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { dialog.dispose(); } }); dialog.setDefaultButton(ok); dialog.pack(); dialog.open(); Display display = dialog.getDisplay(); while (!shell.isDisposed() && !dialog.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } }