List of usage examples for org.eclipse.swt.widgets Canvas Canvas
public Canvas(Composite parent, int style)
From source file:org.eclipse.swt.examples.accessibility.CTable.java
/** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. * <p>//from w w w. j av a 2s . com * The style value is either one of the style constants defined in * class <code>SWT</code> which is applicable to instances of this * class, or must be built by <em>bitwise OR</em>'ing together * (that is, using the <code>int</code> "|" operator) two or more * of those <code>SWT</code> style constants. The class description * lists the style constants that are applicable to the class. * Style bits are also inherited from superclasses. * </p> * * @param parent a composite control which will be the parent of the new instance (cannot be null) * @param style the style of control to construct * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> * </ul> * * @see SWT#SINGLE * @see SWT#MULTI * @see SWT#CHECK * @see SWT#FULL_SELECTION * @see SWT#HIDE_SELECTION * @see SWT#VIRTUAL * @see SWT#NO_SCROLL * @see Widget#checkSubclass * @see Widget#getStyle */ public CTable(Composite parent, int style) { super(parent, checkStyle(style)); this.display = parent.getDisplay(); setForeground(null); /* set foreground and background to chosen default colors */ setBackground(null); GC gc = new GC(this); fontHeight = gc.getFontMetrics().getHeight(); gc.dispose(); itemHeight = fontHeight + (2 * getCellPadding()); initImages(display); checkboxBounds = getUncheckedImage().getBounds(); arrowBounds = getArrowDownImage().getBounds(); clientArea = getClientArea(); Listener listener = event -> handleEvents(event); addListener(SWT.Paint, listener); addListener(SWT.MouseDown, listener); addListener(SWT.MouseUp, listener); addListener(SWT.MouseDoubleClick, listener); addListener(SWT.Dispose, listener); addListener(SWT.Resize, listener); addListener(SWT.KeyDown, listener); addListener(SWT.FocusOut, listener); addListener(SWT.FocusIn, listener); addListener(SWT.Traverse, listener); initAccessibility(); header = new Canvas(this, SWT.NO_REDRAW_RESIZE | SWT.NO_FOCUS); header.setVisible(false); header.setBounds(0, 0, 0, fontHeight + 2 * getHeaderPadding()); header.addListener(SWT.Paint, listener); header.addListener(SWT.MouseDown, listener); header.addListener(SWT.MouseUp, listener); header.addListener(SWT.MouseHover, listener); header.addListener(SWT.MouseDoubleClick, listener); header.addListener(SWT.MouseMove, listener); header.addListener(SWT.MouseExit, listener); header.addListener(SWT.MenuDetect, listener); toolTipListener = event -> { switch (event.type) { case SWT.MouseHover: case SWT.MouseMove: if (headerUpdateToolTip(event.x)) break; // FALL THROUGH case SWT.MouseExit: case SWT.MouseDown: headerHideToolTip(); break; } }; ScrollBar hBar = getHorizontalBar(); if (hBar != null) { hBar.setValues(0, 0, 1, 1, 1, 1); hBar.setVisible(false); hBar.addListener(SWT.Selection, listener); } ScrollBar vBar = getVerticalBar(); if (vBar != null) { vBar.setValues(0, 0, 1, 1, 1, 1); vBar.setVisible(false); vBar.addListener(SWT.Selection, listener); } }
From source file:widgetTest3.java
/** * Images ** */ public static void doubleBuffering(Composite composite) { // Create canvas final Canvas canvas = new Canvas(composite, SWT.BORDER); // Get white system color Color white = canvas.getDisplay().getSystemColor(SWT.COLOR_WHITE); // Set canvas background to white canvas.setBackground(white);//from w w w .java2s . c om // Add paint listener canvas.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { // Get Display instance from the event object Display display = e.display; // Get black and red system color - don't dispose these Color black = display.getSystemColor(SWT.COLOR_BLACK); Color red = display.getSystemColor(SWT.COLOR_RED); // Get the graphics context from event object GC gc = e.gc; // Get the widget that caused the event Composite source = (Composite) e.widget; // Get the size of this widgets client area Rectangle rect = source.getClientArea(); // Create buffer for double buffering Image buffer = new Image(display, rect.width, rect.height); // Create graphics context for this buffer GC bufferGC = new GC(buffer); // perform drawing operations bufferGC.setBackground(red); bufferGC.fillRectangle(5, 5, rect.width - 10, rect.height - 10); bufferGC.setForeground(black); bufferGC.drawRectangle(5, 5, rect.width - 10, rect.height - 10); bufferGC.setBackground(source.getBackground()); bufferGC.fillRectangle(10, 10, rect.width - 20, rect.height - 20); // Now draw the buffered image to the target drawable gc.drawImage(buffer, 0, 0); // Dispose of the buffer's graphics context bufferGC.dispose(); // Dispose of the buffer buffer.dispose(); } }); }
From source file:org.eclipse.swt.examples.clipboard.ClipboardExample.java
void createImageTransfer(Composite copyParent, Composite pasteParent) { final Image[] copyImage = new Image[] { null }; Label l = new Label(copyParent, SWT.NONE); l.setText("ImageTransfer:"); //$NON-NLS-1$ GridData data = new GridData(); data.verticalSpan = 2;/* w w w.java2s .co m*/ l.setLayoutData(data); final Canvas copyImageCanvas = new Canvas(copyParent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); data = new GridData(GridData.FILL_BOTH); data.verticalSpan = 2; data.widthHint = HSIZE; data.heightHint = VSIZE; copyImageCanvas.setLayoutData(data); final Point copyOrigin = new Point(0, 0); final ScrollBar copyHBar = copyImageCanvas.getHorizontalBar(); copyHBar.setEnabled(false); copyHBar.addListener(SWT.Selection, e -> { if (copyImage[0] != null) { int hSelection = copyHBar.getSelection(); int destX = -hSelection - copyOrigin.x; Rectangle rect = copyImage[0].getBounds(); copyImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); copyOrigin.x = -hSelection; } }); final ScrollBar copyVBar = copyImageCanvas.getVerticalBar(); copyVBar.setEnabled(false); copyVBar.addListener(SWT.Selection, e -> { if (copyImage[0] != null) { int vSelection = copyVBar.getSelection(); int destY = -vSelection - copyOrigin.y; Rectangle rect = copyImage[0].getBounds(); copyImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false); copyOrigin.y = -vSelection; } }); copyImageCanvas.addListener(SWT.Paint, e -> { if (copyImage[0] != null) { GC gc = e.gc; gc.drawImage(copyImage[0], copyOrigin.x, copyOrigin.y); Rectangle rect = copyImage[0].getBounds(); Rectangle client = copyImageCanvas.getClientArea(); int marginWidth = client.width - rect.width; if (marginWidth > 0) { gc.fillRectangle(rect.width, 0, marginWidth, client.height); } int marginHeight = client.height - rect.height; if (marginHeight > 0) { gc.fillRectangle(0, rect.height, client.width, marginHeight); } gc.dispose(); } }); Button openButton = new Button(copyParent, SWT.PUSH); openButton.setText("Open Image"); openButton.addSelectionListener(widgetSelectedAdapter(e -> { FileDialog dialog = new FileDialog(shell, SWT.OPEN); dialog.setText("Open an image file or cancel"); String string = dialog.open(); if (string != null) { if (copyImage[0] != null) { System.out.println("CopyImage"); copyImage[0].dispose(); } copyImage[0] = new Image(e.display, string); copyVBar.setEnabled(true); copyHBar.setEnabled(true); copyOrigin.x = 0; copyOrigin.y = 0; Rectangle rect = copyImage[0].getBounds(); Rectangle client = copyImageCanvas.getClientArea(); copyHBar.setMaximum(rect.width); copyVBar.setMaximum(rect.height); copyHBar.setThumb(Math.min(rect.width, client.width)); copyVBar.setThumb(Math.min(rect.height, client.height)); copyImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true); copyVBar.setSelection(0); copyHBar.setSelection(0); copyImageCanvas.redraw(); } })); Button b = new Button(copyParent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(widgetSelectedAdapter(e -> { if (copyImage[0] != null) { status.setText(""); // Fetch ImageData at current zoom and save in the clip-board. clipboard.setContents(new Object[] { copyImage[0].getImageDataAtCurrentZoom() }, new Transfer[] { ImageTransfer.getInstance() }); } else { status.setText("No image to copy"); } })); final Image[] pasteImage = new Image[] { null }; l = new Label(pasteParent, SWT.NONE); l.setText("ImageTransfer:"); final Canvas pasteImageCanvas = new Canvas(pasteParent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); data = new GridData(GridData.FILL_BOTH); data.widthHint = HSIZE; data.heightHint = VSIZE; pasteImageCanvas.setLayoutData(data); final Point pasteOrigin = new Point(0, 0); final ScrollBar pasteHBar = pasteImageCanvas.getHorizontalBar(); pasteHBar.setEnabled(false); pasteHBar.addListener(SWT.Selection, e -> { if (pasteImage[0] != null) { int hSelection = pasteHBar.getSelection(); int destX = -hSelection - pasteOrigin.x; Rectangle rect = pasteImage[0].getBounds(); pasteImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); pasteOrigin.x = -hSelection; } }); final ScrollBar pasteVBar = pasteImageCanvas.getVerticalBar(); pasteVBar.setEnabled(false); pasteVBar.addListener(SWT.Selection, e -> { if (pasteImage[0] != null) { int vSelection = pasteVBar.getSelection(); int destY = -vSelection - pasteOrigin.y; Rectangle rect = pasteImage[0].getBounds(); pasteImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false); pasteOrigin.y = -vSelection; } }); pasteImageCanvas.addListener(SWT.Paint, e -> { if (pasteImage[0] != null) { GC gc = e.gc; gc.drawImage(pasteImage[0], pasteOrigin.x, pasteOrigin.y); Rectangle rect = pasteImage[0].getBounds(); Rectangle client = pasteImageCanvas.getClientArea(); int marginWidth = client.width - rect.width; if (marginWidth > 0) { gc.fillRectangle(rect.width, 0, marginWidth, client.height); } int marginHeight = client.height - rect.height; if (marginHeight > 0) { gc.fillRectangle(0, rect.height, client.width, marginHeight); } } }); b = new Button(pasteParent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(widgetSelectedAdapter(e -> { ImageData imageData = (ImageData) clipboard.getContents(ImageTransfer.getInstance()); if (imageData != null) { if (pasteImage[0] != null) { System.out.println("PasteImage"); pasteImage[0].dispose(); } status.setText(""); // Consume the ImageData at current zoom as-is. pasteImage[0] = new Image(e.display, new AutoScaleImageDataProvider(imageData)); pasteVBar.setEnabled(true); pasteHBar.setEnabled(true); pasteOrigin.x = 0; pasteOrigin.y = 0; Rectangle rect = pasteImage[0].getBounds(); Rectangle client = pasteImageCanvas.getClientArea(); pasteHBar.setMaximum(rect.width); pasteVBar.setMaximum(rect.height); pasteHBar.setThumb(Math.min(rect.width, client.width)); pasteVBar.setThumb(Math.min(rect.height, client.height)); pasteImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true); pasteVBar.setSelection(0); pasteHBar.setSelection(0); pasteImageCanvas.redraw(); } else { status.setText("No image to paste"); } })); }
From source file:org.mwc.cmap.grideditor.chart.FixedChartComposite.java
/** * Constructs a JFreeChart panel.//from w w w. j av a2 s. co m * * @param comp * The parent. * @param style * The style of the composite. * @param jfreechart * the chart. * @param width * the preferred width of the panel. * @param height * the preferred height of the panel. * @param minimumDrawW * the minimum drawing width. * @param minimumDrawH * the minimum drawing height. * @param maximumDrawW * the maximum drawing width. * @param maximumDrawH * the maximum drawing height. * @param usingBuffer * a flag that indicates whether to use the off-screen buffer to * improve performance (at the expense of memory). * @param properties * a flag indicating whether or not the chart property editor should * be available via the popup menu. * @param save * a flag indicating whether or not save options should be available * via the popup menu. * @param print * a flag indicating whether or not the print option should be * available via the popup menu. * @param zoom * a flag indicating whether or not zoom options should be added to * the popup menu. * @param tooltips * a flag indicating whether or not tooltips should be enabled for * the chart. */ public FixedChartComposite(final Composite comp, final int style, final JFreeChart jfreechart, final int width, final int height, final int minimumDrawW, final int minimumDrawH, final int maximumDrawW, final int maximumDrawH, final boolean usingBuffer, final boolean properties, final boolean save, final boolean print, final boolean zoom, final boolean tooltips) { super(comp, style); setChart(jfreechart); this.chartMouseListeners = new EventListenerList(); setLayout(new FillLayout()); this.info = new ChartRenderingInfo(); this.useBuffer = usingBuffer; this.refreshBuffer = false; this.minimumDrawWidth = minimumDrawW; this.minimumDrawHeight = minimumDrawH; this.maximumDrawWidth = maximumDrawW; this.maximumDrawHeight = maximumDrawH; this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE; setDisplayToolTips(tooltips); // create the canvas and add the required listeners this.canvas = new Canvas(this, SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND); this.canvas.addPaintListener(this); this.canvas.addMouseListener(this); this.canvas.addMouseMoveListener(this); // set up popup menu... this.popup = null; if (properties || save || print || zoom) this.popup = createPopupMenu(properties, save, print, zoom); this.enforceFileExtensions = true; }
From source file:ImageAnalyzer.java
void createWidgets() { // Add the widgets to the shell in a grid layout. GridLayout layout = new GridLayout(); layout.marginHeight = 0;// w w w . ja 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.jfree.experimental.chart.swt.ChartComposite.java
/** * Constructs a JFreeChart panel.//from w w w. jav a2 s . c o m * * @param comp The parent. * @param style The style of the composite. * @param jfreechart the chart. * @param width the preferred width of the panel. * @param height the preferred height of the panel. * @param minimumDrawW the minimum drawing width. * @param minimumDrawH the minimum drawing height. * @param maximumDrawW the maximum drawing width. * @param maximumDrawH the maximum drawing height. * @param usingBuffer a flag that indicates whether to use the off-screen buffer to improve * performance (at the expense of memory). * @param properties a flag indicating whether or not the chart property editor should be * available via the popup menu. * @param save a flag indicating whether or not save options should be available via the popup * menu. * @param print a flag indicating whether or not the print option should be available via the * popup menu. * @param zoom a flag indicating whether or not zoom options should be added to the popup menu. * @param tooltips a flag indicating whether or not tooltips should be enabled for the chart. */ public ChartComposite(Composite comp, int style, JFreeChart jfreechart, int width, int height, int minimumDrawW, int minimumDrawH, int maximumDrawW, int maximumDrawH, boolean usingBuffer, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips) { super(comp, style); this.setChart(jfreechart); this.chartMouseListeners = new EventListenerList(); this.setLayout(new FillLayout()); this.info = new ChartRenderingInfo(); this.useBuffer = usingBuffer; this.refreshBuffer = false; this.minimumDrawWidth = minimumDrawW; this.minimumDrawHeight = minimumDrawH; this.maximumDrawWidth = maximumDrawW; this.maximumDrawHeight = maximumDrawH; this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE; this.setDisplayToolTips(tooltips); // create the canvas and add the required listeners this.canvas = new Canvas(this, SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND); this.canvas.addPaintListener(this); this.canvas.addMouseListener(this); this.canvas.addMouseMoveListener(this); if (this.chart != null) { this.chart.addChangeListener(this); Plot plot = this.chart.getPlot(); this.domainZoomable = false; this.rangeZoomable = false; if (plot instanceof Zoomable) { Zoomable z = (Zoomable) plot; this.domainZoomable = z.isDomainZoomable(); this.rangeZoomable = z.isRangeZoomable(); this.orientation = z.getOrientation(); } } // set up popup menu... this.popup = null; if (properties || save || print || zoom) this.popup = createPopupMenu(properties, save, print, zoom); this.enforceFileExtensions = true; }
From source file:rulebender.editors.dat.view.CustomizedChartComposite.java
/** * Constructs a JFreeChart panel.// ww w .ja va 2s. co m * * @param comp The parent. * @param style The style of the composite. * @param jfreechart the chart. * @param width the preferred width of the panel. * @param height the preferred height of the panel. * @param minimumDrawW the minimum drawing width. * @param minimumDrawH the minimum drawing height. * @param maximumDrawW the maximum drawing width. * @param maximumDrawH the maximum drawing height. * @param usingBuffer a flag that indicates whether to use the off-screen * buffer to improve performance (at the expense of * memory). * @param properties a flag indicating whether or not the chart property * editor should be available via the popup menu. * @param save a flag indicating whether or not save options should be * available via the popup menu. * @param print a flag indicating whether or not the print option * should be available via the popup menu. * @param zoom a flag indicating whether or not zoom options should be * added to the popup menu. * @param tooltips a flag indicating whether or not tooltips should be * enabled for the chart. */ public CustomizedChartComposite(Composite comp, int style, JFreeChart jfreechart, int width, int height, int minimumDrawW, int minimumDrawH, int maximumDrawW, int maximumDrawH, boolean usingBuffer, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips) { super(comp, style); setChart(jfreechart); this.chartMouseListeners = new EventListenerList(); setLayout(new FillLayout()); this.info = new ChartRenderingInfo(); this.useBuffer = usingBuffer; this.refreshBuffer = false; this.minimumDrawWidth = minimumDrawW; this.minimumDrawHeight = minimumDrawH; this.maximumDrawWidth = maximumDrawW; this.maximumDrawHeight = maximumDrawH; this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE; setDisplayToolTips(tooltips); // create the canvas and add the required listeners this.canvas = new Canvas(this, SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND); this.canvas.addPaintListener(this); this.canvas.addMouseListener(this); this.canvas.addMouseMoveListener(this); // set up popup menu... this.popup = null; if (properties || save || print || zoom) this.popup = createPopupMenu(properties, save, print, zoom); this.enforceFileExtensions = true; }
From source file:com.rcp.wbw.demo.ChartComposite.java
/** * Constructs a JFreeChart panel.// ww w. ja va 2 s . c o m * * @param comp * The parent. * @param style * The style of the composite. * @param jfreechart * the chart. * @param width * the preferred width of the panel. * @param height * the preferred height of the panel. * @param minimumDrawW * the minimum drawing width. * @param minimumDrawH * the minimum drawing height. * @param maximumDrawW * the maximum drawing width. * @param maximumDrawH * the maximum drawing height. * @param usingBuffer * a flag that indicates whether to use the off-screen * buffer to improve performance (at the expense of * memory). * @param properties * a flag indicating whether or not the chart property * editor should be available via the popup menu. * @param save * a flag indicating whether or not save options should be * available via the popup menu. * @param print * a flag indicating whether or not the print option * should be available via the popup menu. * @param zoom * a flag indicating whether or not zoom options should be * added to the popup menu. * @param tooltips * a flag indicating whether or not tooltips should be * enabled for the chart. */ public ChartComposite(Composite comp, int style, JFreeChart jfreechart, int width, int height, int minimumDrawW, int minimumDrawH, int maximumDrawW, int maximumDrawH, boolean usingBuffer, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips) { super(comp, style); setChart(jfreechart); this.chartMouseListeners = new EventListenerList(); setLayout(new FillLayout()); this.info = new ChartRenderingInfo(); this.useBuffer = usingBuffer; this.refreshBuffer = false; this.minimumDrawWidth = minimumDrawW; this.minimumDrawHeight = minimumDrawH; this.maximumDrawWidth = maximumDrawW; this.maximumDrawHeight = maximumDrawH; this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE; setDisplayToolTips(tooltips); // create the canvas and add the required listeners this.canvas = new Canvas(this, SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND); this.canvas.addPaintListener(this); this.canvas.addMouseListener(this); this.canvas.addMouseMoveListener(this); // set up popup menu... this.popup = null; if (properties || save || print || zoom) this.popup = createPopupMenu(properties, save, print, zoom); this.enforceFileExtensions = true; }
From source file:com.munch.exchange.parts.neuralnetwork.results.NeuralNetworkResultChartComposite.java
/** * Constructs a JFreeChart panel.//from ww w .j a v a2 s . c o m * * @param comp The parent. * @param style The style of the composite. * @param jfreechart the chart. * @param width the preferred width of the panel. * @param height the preferred height of the panel. * @param minimumDrawW the minimum drawing width. * @param minimumDrawH the minimum drawing height. * @param maximumDrawW the maximum drawing width. * @param maximumDrawH the maximum drawing height. * @param usingBuffer a flag that indicates whether to use the off-screen * buffer to improve performance (at the expense of * memory). * @param properties a flag indicating whether or not the chart property * editor should be available via the popup menu. * @param save a flag indicating whether or not save options should be * available via the popup menu. * @param print a flag indicating whether or not the print option * should be available via the popup menu. * @param zoom a flag indicating whether or not zoom options should be * added to the popup menu. * @param tooltips a flag indicating whether or not tooltips should be * enabled for the chart. */ public NeuralNetworkResultChartComposite(Composite comp, int style, JFreeChart jfreechart, int width, int height, int minimumDrawW, int minimumDrawH, int maximumDrawW, int maximumDrawH, boolean usingBuffer, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips) { super(comp, style); setChart(jfreechart); this.chartMouseListeners = new EventListenerList(); setLayout(new FillLayout()); this.info = new ChartRenderingInfo(); this.useBuffer = usingBuffer; this.refreshBuffer = false; this.minimumDrawWidth = minimumDrawW; this.minimumDrawHeight = minimumDrawH; this.maximumDrawWidth = maximumDrawW; this.maximumDrawHeight = maximumDrawH; this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE; setDisplayToolTips(tooltips); // create the canvas and add the required listeners this.canvas = new Canvas(this, SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND); this.canvas.addPaintListener(this); this.canvas.addMouseListener(this); this.canvas.addMouseMoveListener(this); this.canvas.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { org.eclipse.swt.graphics.Image img; img = (org.eclipse.swt.graphics.Image) canvas.getData("double-buffer-image"); if (img != null) { img.dispose(); } } }); // set up popup menu... this.popup = null; if (properties || save || print || zoom) this.popup = createPopupMenu(properties, save, print, zoom); this.enforceFileExtensions = true; }
From source file:com.munch.exchange.ExchangeChartComposite.java
/** * Constructs a JFreeChart panel.//from ww w. j a v a 2 s.c o m * * @param comp The parent. * @param style The style of the composite. * @param jfreechart the chart. * @param width the preferred width of the panel. * @param height the preferred height of the panel. * @param minimumDrawW the minimum drawing width. * @param minimumDrawH the minimum drawing height. * @param maximumDrawW the maximum drawing width. * @param maximumDrawH the maximum drawing height. * @param usingBuffer a flag that indicates whether to use the off-screen * buffer to improve performance (at the expense of * memory). * @param properties a flag indicating whether or not the chart property * editor should be available via the popup menu. * @param save a flag indicating whether or not save options should be * available via the popup menu. * @param print a flag indicating whether or not the print option * should be available via the popup menu. * @param zoom a flag indicating whether or not zoom options should be * added to the popup menu. * @param tooltips a flag indicating whether or not tooltips should be * enabled for the chart. */ public ExchangeChartComposite(Composite comp, int style, JFreeChart jfreechart, int width, int height, int minimumDrawW, int minimumDrawH, int maximumDrawW, int maximumDrawH, boolean usingBuffer, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips) { super(comp, style); setChart(jfreechart); this.chartMouseListeners = new EventListenerList(); setLayout(new FillLayout()); this.info = new ChartRenderingInfo(); this.useBuffer = usingBuffer; this.refreshBuffer = false; this.minimumDrawWidth = minimumDrawW; this.minimumDrawHeight = minimumDrawH; this.maximumDrawWidth = maximumDrawW; this.maximumDrawHeight = maximumDrawH; this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE; setDisplayToolTips(tooltips); // create the canvas and add the required listeners this.canvas = new Canvas(this, SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND); this.canvas.addPaintListener(this); this.canvas.addMouseListener(this); this.canvas.addMouseMoveListener(this); this.canvas.addMouseWheelListener(this); this.canvas.addMouseTrackListener(this); //TODO Add other listener this.canvas.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { org.eclipse.swt.graphics.Image img; img = (org.eclipse.swt.graphics.Image) canvas.getData("double-buffer-image"); if (img != null) { img.dispose(); } } }); // set up popup menu... this.popup = null; if (properties || save || print || zoom) this.popup = createPopupMenu(properties, save, print, zoom); this.enforceFileExtensions = true; }