List of usage examples for org.eclipse.jface.dialogs Dialog shortenText
public static String shortenText(String textValue, Control control)
textValue
so that its width in pixels does not exceed the width of the given control. From source file:com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigEditDialog.java
License:Open Source License
/** * resets the status label to show the file that will be created. *///w w w .j ava 2 s . co m private void resetStatus() { String displayString = Dialog.shortenText(String.format("Config: %1$s", mConfig.toString()), mStatusLabel); mStatusLabel.setText(displayString); }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigEditDialog.java
License:Open Source License
private void setError(String text) { String displayString = Dialog.shortenText(text, mStatusLabel); mStatusLabel.setText(displayString); mStatusImage.setImage(mError);// w w w. ja v a 2 s . co m getButton(IDialogConstants.OK_ID).setEnabled(false); }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.configuration.LayoutCreatorDialog.java
License:Open Source License
/** * resets the status label to show the file that will be created. *///from w ww.j a v a2 s . c om private void resetStatus() { String displayString = Dialog.shortenText(String.format("New File: res/%1$s/%2$s", mConfig.getFolderName(ResourceFolderType.LAYOUT), mFileName), mStatusLabel); mStatusLabel.setText(displayString); }
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 . ja v a 2 s .c o 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.nokia.carbide.cpp.internal.pi.wizards.ui.NewPIWizardObySymbolPairDialog.java
License:Open Source License
boolean validateAll() { setMessage(null);/*from w ww .j av a 2s .co m*/ setErrorMessage(null); symbolText.setEnabled(false); symbolButton.setEnabled(false); if (obyText.getText().length() > 0) { if (obyText.getText().toLowerCase().endsWith(".oby") == false) { //$NON-NLS-1$ setErrorMessage(Messages.getString("NewPIWizardObySymbolPairDialog.oby.file.extension.error")); //$NON-NLS-1$ return false; } if (new java.io.File(obyText.getText()).exists() == false) { setErrorMessage( Dialog.shortenText( Messages.getString("NewPIWizardObySymbolPairDialog.oby.file") + obyText.getText() //$NON-NLS-1$ + Messages.getString( "NewPIWizardObySymbolPairDialog.does.not.exist.in.file.system"), //$NON-NLS-1$ obyComposite)); return false; } symbolText.setEnabled(true); symbolButton.setEnabled(true); } if (symbolText.getText().length() > 0) { if (symbolText.getText().toLowerCase().endsWith(".symbol") == false) { //$NON-NLS-1$ setErrorMessage(Messages.getString("NewPIWizardObySymbolPairDialog.symbol.extension.error")); //$NON-NLS-1$ return false; } if (new java.io.File(symbolText.getText()).exists() == false) { setErrorMessage(Dialog.shortenText( Messages.getString("NewPIWizardObySymbolPairDialog.symbol.file.2") + symbolText.getText() //$NON-NLS-1$ + Messages.getString( "NewPIWizardObySymbolPairDialog.does.not.exist.in.file.system.2"), //$NON-NLS-1$ symbolComposite)); return false; } } return true; }
From source file:com.nokia.carbide.cpp.internal.pi.wizards.ui.NewPIWizardPageRomSubTask.java
License:Open Source License
public void validatePage() { if (symbolText.getText().length() > 1 || obyText.getText().length() > 1 || rofsObySymbolTable.getItemCount() > 1) { if (sdkCommon.getSelectedSdk() == null) { setErrorMessage(Messages.getString("NewPIWizardPageRomSubTask.error.1")); //$NON-NLS-1$ setPageComplete(false);/* ww w . java2s . c om*/ return; } } if (symbolText.getText().length() > 0) { java.io.File symFile = new java.io.File(symbolText.getText()); if (!symFile.exists() || !symFile.isFile()) { setErrorMessage(Dialog.shortenText( Messages.getString("NewPIWizardPageRomSubTask.symbol.label") + " " + symbolText.getText() //$NON-NLS-1$//$NON-NLS-2$ + " " + Messages.getString("NewPIWizardPageRomSubTask.error.2"), //$NON-NLS-1$//$NON-NLS-2$ symbolComposite)); setPageComplete(false); return; } } if (obyText.getText().length() > 0) { java.io.File obyFile = new java.io.File(obyText.getText()); if (!obyFile.exists() || !obyFile.isFile()) { setErrorMessage( Dialog.shortenText( Messages.getString("NewPIWizardPageRomSubTask.oby.label") + " " + obyText.getText() //$NON-NLS-1$//$NON-NLS-2$ + " " + Messages.getString("NewPIWizardPageRomSubTask.error.2"), //$NON-NLS-1$//$NON-NLS-2$ obyComposite)); setPageComplete(false); return; } } setErrorMessage(null); setPageComplete(true); return; }
From source file:de.femodeling.e4.ui.progress.internal.ProgressInfoItem.java
License:Open Source License
/** * Set the main text of the receiver. Truncate to fit the available space. *//* w w w .j a va2 s . c o m*/ private void setMainText() { progressLabel.setText(Dialog.shortenText(getMainTitle(), progressLabel)); }
From source file:de.femodeling.e4.ui.progress.internal.ProgressInfoItem.java
License:Open Source License
/** * Update the text in the link//from w w w .j a v a 2s . c o m * * @param taskString * @param link */ private void updateText(String taskString, Link link) { taskString = Dialog.shortenText(taskString, link); // Put in a hyperlink if there is an action link.setText(link.getData(TRIGGER_KEY) == null ? taskString : NLS.bind("<a>{0}</a>", taskString));//$NON-NLS-1$ }
From source file:net.tourbook.preferences.PrefPageStatisticTourFrequency.java
License:Open Source License
/** * show an example of the entered values *///from ww w .j a va 2 s. c o m private void computeExample(final Label label, final int lowValue, final int interval, final int numbers, final String unit, final int unitType) { final StringBuilder text = new StringBuilder(); for (int number = 0; number < numbers; number++) { if (unitType == ChartDataSerie.AXIS_UNIT_HOUR_MINUTE) { text.append(Util.formatValue((lowValue * 60) + (interval * number * 60), unitType)); } else { text.append(lowValue + (interval * number)); } if (number < numbers - 1) { text.append(Messages.Pref_Statistic_Label_separator); } } label.setText(Dialog.shortenText(text.toString() + " " + unit, label)); //$NON-NLS-1$ }
From source file:org.eclipse.rcptt.ui.controls.StatusBarComposite.java
License:Open Source License
public void createControl(Composite parent) { shell = parent.getShell();// w w w.j a v a 2 s. c o m this.parent = parent; composite = new Composite(parent, SWT.NONE); messageLabel = new Label(composite, SWT.NONE); progressIndicator = new ProgressIndicator(composite); composite.addControlListener(new ControlListener() { public void controlMoved(ControlEvent e) { } public void controlResized(ControlEvent e) { if (messageLabel != null && messageLabel.isVisible() && message != null) { messageLabel.setText(Dialog.shortenText(message, messageLabel)); } } }); setMessageLayout(); hide(); }