List of usage examples for org.eclipse.jface.dialogs Dialog convertWidthInCharsToPixels
public static int convertWidthInCharsToPixels(FontMetrics fontMetrics, int chars)
From source file:com.ebmwebsourcing.petals.services.eip.designer.actions.ExportDiagramAction.java
License:Open Source License
@Override public void run() { // Determine the export location FileDialog dlg = new FileDialog(new Shell(), SWT.SAVE); dlg.setText("Image Export"); dlg.setOverwrite(true);//from w w w. j av a2 s. co m dlg.setFilterNames(new String[] { "JPEG Files (*.jpg)", "PNG Files (*.png)", "GIF Files (*.gif)" }); String[] extensions = new String[] { "*.jpg", "*.png", "*.gif" }; dlg.setFilterExtensions(extensions); String path = dlg.open(); if (path != null) { String ext = extensions[dlg.getFilterIndex()].substring(1); if (!path.endsWith(ext)) path += ext; // Only print printable layers ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) this.graphicalViewer .getEditPartRegistry().get(LayerManager.ID); IFigure rootFigure = ((LayerManager) rootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS); IFigure eipChainFigure = null; for (Object o : rootFigure.getChildren()) { if (o instanceof FreeformLayer) eipChainFigure = (FreeformLayer) o; } Rectangle bounds = eipChainFigure == null ? rootFigure.getBounds() : eipChainFigure.getBounds(); GC figureCanvasGC = new GC(this.graphicalViewer.getControl()); // Add 20 pixels to write the title of the diagram on the image Image img = new Image(null, bounds.width, bounds.height); GC gc = new GC(img); gc.setBackground(figureCanvasGC.getBackground()); gc.setForeground(figureCanvasGC.getForeground()); gc.setFont(figureCanvasGC.getFont()); gc.setLineStyle(figureCanvasGC.getLineStyle()); gc.setLineWidth(figureCanvasGC.getLineWidth()); Graphics imgGraphics = new SWTGraphics(gc); // Paint it... rootFigure.paint(imgGraphics); // Prepare the next step Font font = new Font(Display.getCurrent(), "Arial", 14, SWT.BOLD); gc.setFont(font); int height = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), 1); gc.dispose(); // Create a second image with the title and diagram version bounds.height += height + (height % 2 == 0 ? 6 : 7); // Write the title and its border bounds.height += 3 * BORDER_MARGIN_UPDOWN + 2; // Add a border + some margin bounds.width += 2 * BORDER_MARGIN_SIDES + 2; // Add a border Image finalImg = new Image(null, bounds.width, bounds.height); gc = new GC(finalImg); // Draw a surrounding border gc.setAntialias(SWT.ON); gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); gc.drawLine(BORDER_MARGIN_SIDES, BORDER_MARGIN_UPDOWN, BORDER_MARGIN_SIDES, bounds.height - BORDER_MARGIN_UPDOWN); gc.drawLine(BORDER_MARGIN_SIDES, bounds.height - BORDER_MARGIN_UPDOWN, bounds.width - BORDER_MARGIN_SIDES, bounds.height - BORDER_MARGIN_UPDOWN); gc.drawLine(BORDER_MARGIN_SIDES, BORDER_MARGIN_UPDOWN, bounds.width - BORDER_MARGIN_SIDES, BORDER_MARGIN_UPDOWN); gc.drawLine(bounds.width - BORDER_MARGIN_SIDES, BORDER_MARGIN_UPDOWN, bounds.width - BORDER_MARGIN_SIDES, bounds.height - BORDER_MARGIN_UPDOWN); // Draw the title gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); gc.setFont(font); gc.setClipping((Region) null); gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); String title = this.eipChain.getTitle() != null ? this.eipChain.getTitle() : "No diagram title"; if (!StringUtils.isEmpty(this.eipChain.getVersion())) title += " - Version " + this.eipChain.getVersion().trim(); int width = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), title.length()); if (width > bounds.width) { title = Dialog.shortenText(title, this.graphicalViewer.getControl()); width = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), title.length()); } gc.drawText(title, 6 + BORDER_MARGIN_SIDES, 4 + BORDER_MARGIN_UPDOWN, true); // Draw a surrounding shape for the title gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); Rectangle titleRectangle = new Rectangle(BORDER_MARGIN_SIDES, BORDER_MARGIN_UPDOWN, BORDER_MARGIN_SIDES + width + (width % 2 == 0 ? 10 : 11), BORDER_MARGIN_UPDOWN + height + (height % 2 == 0 ? 6 : 7)); final int arrowPadding = (titleRectangle.height + bounds.y) / 2; gc.drawLine(titleRectangle.x, titleRectangle.height, titleRectangle.width, titleRectangle.height); gc.drawLine(titleRectangle.width, titleRectangle.y, titleRectangle.width + arrowPadding, arrowPadding); gc.drawLine(titleRectangle.width, titleRectangle.height, titleRectangle.width + arrowPadding, arrowPadding); // Draw the image gc.drawImage(img, BORDER_MARGIN_SIDES + 1, BORDER_MARGIN_UPDOWN + titleRectangle.height + 1); // Save the second image ImageData[] imgData = new ImageData[1]; imgData[0] = finalImg.getImageData(); int format; String tail = path.toLowerCase().substring(path.length() - 4); if (tail.endsWith(".jpg")) format = SWT.IMAGE_JPEG; else if (tail.endsWith(".png")) format = SWT.IMAGE_PNG; else format = SWT.IMAGE_GIF; ImageLoader imgLoader = new ImageLoader(); imgLoader.data = imgData; imgLoader.save(path, format); // Dispose everything figureCanvasGC.dispose(); gc.dispose(); img.dispose(); finalImg.dispose(); font.dispose(); } }
From source file:com.google.dart.tools.ui.internal.cleanup.preference.DartEditorAppearanceConfigurationBlock.java
License:Open Source License
/** * Returns the number of pixels corresponding to the width of the given number of characters. * <p>/*from w ww .jav a 2 s . c o m*/ * This method may only be called after <code>initializeDialogUnits</code> has been called. * </p> * <p> * Clients may call this framework method, but should not override it. * </p> * * @param chars the number of characters * @return the number of pixels */ protected int convertWidthInCharsToPixels(int chars) { // test for failure to initialize for backward compatibility if (fFontMetrics == null) { return 0; } return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars); }
From source file:com.iw.plugins.spindle.ui.PixelConverter.java
License:Mozilla Public License
/** * @see org.eclipse.jface.dialogs.DialogPage#convertWidthInCharsToPixels(int) *//*from ww w . ja va2 s. c o m*/ public int convertWidthInCharsToPixels(int chars) { return Dialog.convertWidthInCharsToPixels(fontMetrics, chars); }
From source file:com.maccasoft.composer.CommandControl.java
License:Open Source License
public CommandControl(Composite parent) { container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(6, false); layout.marginWidth = layout.marginHeight = 0; container.setLayout(layout);/*from w w w . j a v a2 s . co m*/ GC gc = new GC(container); fontMetrics = gc.getFontMetrics(); gc.dispose(); disable = new Button(container, SWT.CHECK); disable.setToolTipText("Check to disable entry"); disable.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { updateEnablement(); } }); repeat = new Spinner(container, SWT.BORDER); repeat.setValues(0, 0, 99999, 0, 1, 1); repeat.setToolTipText("Repeat count (ms)"); repeat.setLayoutData(new GridData(Dialog.convertWidthInCharsToPixels(fontMetrics, 5), SWT.DEFAULT)); Label label = new Label(container, SWT.NONE); label.setText("x"); action = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY); action.setItems(new String[] { "JUMP", "SET", "MODIFY" }); action.setToolTipText("Command"); action.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { updateVisibleStack(); } }); createStack(container); }
From source file:com.maccasoft.composer.CommandControl.java
License:Open Source License
void createFrequencyControls(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginWidth = layout.marginHeight = 0; container.setLayout(layout);/*www . j av a2s. com*/ frequency = new Text(container, SWT.BORDER | SWT.CENTER); frequency.setToolTipText("Frequency"); frequency.setLayoutData(new GridData(Dialog.convertWidthInCharsToPixels(fontMetrics, 11), SWT.DEFAULT)); frequency.addFocusListener(textFocusListener); Label label = new Label(container, SWT.NONE); label.setText("Hz"); }
From source file:com.maccasoft.composer.CommandControl.java
License:Open Source License
void createFrequencyNoteControls(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(1, false); layout.marginWidth = layout.marginHeight = 0; container.setLayout(layout);/*from w w w . ja va2 s . c om*/ frequencyNote = new Text(container, SWT.BORDER | SWT.CENTER); frequencyNote.setToolTipText("Note"); frequencyNote.setLayoutData(new GridData(Dialog.convertWidthInCharsToPixels(fontMetrics, 11), SWT.DEFAULT)); frequencyNote.addFocusListener(textFocusListener); }
From source file:com.maccasoft.composer.CommandControl.java
License:Open Source License
void createFrequencyRegisterControls(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(1, false); layout.marginWidth = layout.marginHeight = 0; container.setLayout(layout);/*from w w w . ja v a2s. c o m*/ frequencyRegister = new Text(container, SWT.BORDER | SWT.CENTER); frequencyRegister.setToolTipText("Register value (hex)"); frequencyRegister .setLayoutData(new GridData(Dialog.convertWidthInCharsToPixels(fontMetrics, 11), SWT.DEFAULT)); frequencyRegister.addFocusListener(textFocusListener); }
From source file:com.maccasoft.composer.CommandControl.java
License:Open Source License
void createEnvelopeControls(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(4, false); layout.marginWidth = layout.marginHeight = 0; container.setLayout(layout);//from ww w.j a v a 2s . c om duration = new Text(container, SWT.BORDER | SWT.CENTER); duration.setToolTipText("Duration"); duration.setLayoutData(new GridData(Dialog.convertWidthInCharsToPixels(fontMetrics, 11), SWT.DEFAULT)); duration.addFocusListener(textFocusListener); Label label = new Label(container, SWT.NONE); label.setText("ms."); label.setLayoutData(new GridData(Dialog.convertWidthInCharsToPixels(fontMetrics, 3), SWT.DEFAULT)); reset = new Text(container, SWT.BORDER | SWT.CENTER); reset.setToolTipText("Reset amplitude"); reset.setLayoutData(new GridData(Dialog.convertWidthInCharsToPixels(fontMetrics, 6), SWT.DEFAULT)); reset.addFocusListener(textFocusListener); label = new Label(container, SWT.NONE); label.setText("%"); }
From source file:com.maccasoft.composer.CommandControl.java
License:Open Source License
void createEnvelopeRegisterControls(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(1, false); layout.marginWidth = layout.marginHeight = 0; container.setLayout(layout);/*from w ww . ja v a 2 s. com*/ envelopeRegister = new Text(container, SWT.BORDER | SWT.CENTER); envelopeRegister.setToolTipText("Register value (hex)"); envelopeRegister .setLayoutData(new GridData(Dialog.convertWidthInCharsToPixels(fontMetrics, 11), SWT.DEFAULT)); envelopeRegister.addFocusListener(textFocusListener); }
From source file:com.maccasoft.composer.CommandControl.java
License:Open Source License
void createVolumeControls(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginWidth = layout.marginHeight = 0; container.setLayout(layout);//from w w w . j a va 2 s . co m volume = new Text(container, SWT.BORDER | SWT.CENTER); volume.setToolTipText("Max. volume level"); volume.setLayoutData(new GridData(Dialog.convertWidthInCharsToPixels(fontMetrics, 11), SWT.DEFAULT)); volume.addFocusListener(textFocusListener); Label label = new Label(container, SWT.NONE); label.setText("%"); }