void pairDraw(GC gc, StyledRegion sr, int start, int end) { if (start > text.getCharCount() || end > text.getCharCount()) return; if (gc != null) { Point left = text.getLocationAtOffset(start); Point right = text.getLocationAtOffset(end); if (sr != null) { if (highlightStyle == HLS_XOR) { int resultColor = sr.fore ^ cm.getColor(text.getBackground()); if (text.getLineAtOffset(text.getCaretOffset()) == text.getLineAtOffset(start) && horzCross && horzCrossColor != null && ((StyledRegion) horzCrossColor).bback) resultColor = sr.fore ^ ((StyledRegion) horzCrossColor).back; Color color = cm.getColor(sr.bfore, resultColor); gc.setBackground(color); gc.setXORMode(true); gc.fillRectangle(left.x, left.y, right.x - left.x, gc.getFontMetrics().getHeight()); } else if (highlightStyle == HLS_OUTLINE) { Color color = cm.getColor(sr.bfore, sr.fore); gc.setForeground(color); gc.drawRectangle( left.x, left.y, right.x - left.x - 1, gc.getFontMetrics().getHeight() - 1); } else if (highlightStyle == HLS_OUTLINE2) { Color color = cm.getColor(sr.bfore, sr.fore); gc.setForeground(color); gc.setLineWidth(2); gc.drawRectangle( left.x + 1, left.y + 1, right.x - left.x - 2, gc.getFontMetrics().getHeight() - 2); } } } else { text.redrawRange(start, end - start, true); } }
/* * @see org.eclipse.jface.text.IInformationControlExtension5#computeSizeConstraints(int, int) */ public Point computeSizeConstraints(int widthInChars, int heightInChars) { GC gc = new GC(fText); gc.setFont(fTextFont); int width = gc.getFontMetrics().getAverageCharWidth(); int height = gc.getFontMetrics().getHeight(); gc.dispose(); return new Point(widthInChars * width, heightInChars * height); }
/** {@inheritDoc} */ @Override public final int getDesiredPixelSize( final Rectangle region, final GC gc, final Font label_font, final Font scale_font) { Activator.getLogger().log(Level.FINE, "XAxis layout"); gc.setFont(label_font); final int label_size = gc.getFontMetrics().getHeight(); gc.setFont(scale_font); final int scale_size = gc.getFontMetrics().getHeight(); // Need room for ticks, tick labels, and axis label return TICK_LENGTH + label_size + scale_size; }
/** * Initializes the computation of horizontal and vertical dialog units based on the size of * current font. * * <p>This method must be called before any of the dialog unit based conversion methods are * called. * * @param testControl a control from which to obtain the current font */ private void initializeDialogUnits(Control testControl) { // Compute and store a font metric GC gc = new GC(testControl); gc.setFont(JFaceResources.getDialogFont()); fFontMetrics = gc.getFontMetrics(); gc.dispose(); }
/** * ************************************************************************* Shows a prompt * prepared to receive an answer (controlling GUI) * ************************************************************************ */ private void promptAsControlling() { boolean defaultOptionSet = false; if (m_promptData.isList()) { m_expected = m_promptData.getExpected(); m_numericInput = false; // Set the prompt text m_promptText.setText(m_promptData.getText()); // Adjust the height and visibility of scroll bar depending on // the control doing text wrapping or not int areaWidth = m_promptText.getClientArea().width; GC gc = new GC(m_promptText); int textWidth = gc.getFontMetrics().getAverageCharWidth() * m_promptText.getText().length(); boolean wrapping = textWidth >= areaWidth; gc.dispose(); m_promptText.getVerticalBar().setVisible(wrapping); if (wrapping) { GridData gd = (GridData) m_promptText.getLayoutData(); gd.heightHint = 45; layout(); } m_promptDisplayType = m_promptData.getPromptDisplayType(); // Build the option list and show the option composite defaultOptionSet = updateOptions( m_promptData.getOptions(), m_promptData.getExpected(), m_promptData.getDefault()); if (defaultOptionSet) { m_textInput.setValue(m_promptData.getDefault()); } } else { // Not a List m_expected = null; m_promptText.setText(m_promptData.getText()); m_numericInput = m_promptData.isNumeric(); if (!m_promptData.getDefault().isEmpty()) { m_textInput.setValue(m_promptData.getDefault()); defaultOptionSet = true; } } setHint(); if (defaultOptionSet) { // If we have a default option preselected, enable the controls m_commitButton.setEnabled(true); m_resetButton.setEnabled(true); } else { // Reset the console input m_textInput.reset(); } // Set the focus, highlighting m_textInput.promptStart(); }
private int getAvarageCharWith(Control control) { GC gc = null; try { gc = new GC(control); return gc.getFontMetrics().getAverageCharWidth(); } finally { if (gc != null) gc.dispose(); } }
/** * Returns the height hint for this label. * * @param control the root control of this label * @return the height hint for this label * @since 3.0 */ private int getHeightHint(Composite control) { if (fFixedHeight < 0) { GC gc = new GC(control); gc.setFont(control.getFont()); fFixedHeight = gc.getFontMetrics().getHeight(); gc.dispose(); } return fFixedHeight; }
/** * Returns the difference between the baseline of the widget and the baseline as specified by the * font for <code>gc</code>. When drawing line numbers, the returned bias should be added to * obtain text lined up on the correct base line of the text widget. * * @param gc the {@code GC} to get the font metrics from * @param widgetLine the widget line * @return the baseline bias to use when drawing text that is lined up with the text widget. */ private int getBaselineBias(GC gc, int widgetLine) { ITextViewer textViewer = getParentRuler().getTextViewer(); int offset = textViewer.getTextWidget().getOffsetAtLine(widgetLine); int widgetBaseline = textViewer.getTextWidget().getBaseline(offset); FontMetrics fm = gc.getFontMetrics(); int fontBaseline = fm.getAscent() + fm.getLeading(); int baselineBias = widgetBaseline - fontBaseline; return Math.max(0, baselineBias); }
/** * Returns the width hint for this label. * * @param control the root control of this label * @return the width hint for this label * @since 2.1 */ private int getWidthHint(Composite control) { if (fFixedWidth < 0) { GC gc = new GC(control); gc.setFont(control.getFont()); fFixedWidth = gc.getFontMetrics().getAverageCharWidth() * fWidthInChars; fFixedWidth += INDENT * 2; gc.dispose(); } return fFixedWidth; }
/** * Returns the number of pixels corresponding to the given number of vertical dialog units. * * <p>Clients may call this framework method, but should not override it. * * @param control the control being sized * @param dlus the number of vertical dialog units * @return the number of pixels */ protected int convertVerticalDLUsToPixels(Control control, int dlus) { GC gc = new GC(control); gc.setFont(control.getFont()); int height = gc.getFontMetrics().getHeight(); gc.dispose(); double verticalDialogUnitSize = height * 0.125; return (int) Math.round(dlus * verticalDialogUnitSize); }
/** * Returns the number of pixels corresponding to the given number of horizontal dialog units. * * <p>Clients may call this framework method, but should not override it. * * @param control the control being sized * @param dlus the number of horizontal dialog units * @return the number of pixels */ protected int convertHorizontalDLUsToPixels(Control control, int dlus) { GC gc = new GC(control); gc.setFont(control.getFont()); int averageWidth = gc.getFontMetrics().getAverageCharWidth(); gc.dispose(); double horizontalDialogUnitSize = averageWidth * 0.25; return (int) Math.round(dlus * horizontalDialogUnitSize); }
public LayoutData getLayoutData() { LayoutData layoutData = super.getLayoutData(); if ((comboBox == null) || comboBox.isDisposed()) { layoutData.minimumWidth = 60; } else { // make the comboBox 10 characters wide GC gc = new GC(comboBox); layoutData.minimumWidth = (gc.getFontMetrics().getAverageCharWidth() * 10) + 10; gc.dispose(); } return layoutData; }
/** * Draw string at widget offset. * * @param gc * @param offset the widget offset * @param s the string to be drawn * @param fg the foreground color */ private void draw(GC gc, int offset, String s, Color fg) { // Compute baseline delta (see // https://bugs.eclipse.org/bugs/show_bug.cgi?id=165640) int baseline = fTextWidget.getBaseline(offset); FontMetrics fontMetrics = gc.getFontMetrics(); int fontBaseline = fontMetrics.getAscent() + fontMetrics.getLeading(); int baslineDelta = baseline - fontBaseline; Point pos = fTextWidget.getLocationAtOffset(offset); gc.setForeground(fg); gc.drawString(s, pos.x, pos.y + baslineDelta, true); }
/** * Computes the size of the color image displayed on the button. * * <p>This is an internal method and should not be called by clients. * * @param window the window to create a GC on for calculation. * @return Point The image size */ protected Point computeImageSize(Control window) { // Make the image height as high as a corresponding character. This // makes sure that the button has the same size as a "normal" text // button. GC gc = new GC(window); Font f = JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT); gc.setFont(f); int height = gc.getFontMetrics().getHeight(); gc.dispose(); Point p = new Point(height * 3 - 6, height); return p; }
@Override public Point computeSizeConstraints(final int widthInChars, final int heightInChars) { final GC gc = new GC(fContentComposite); gc.setFont(JFaceResources.getDialogFont()); final int titleWidth = gc.getFontMetrics().getAverageCharWidth() * widthInChars; final int titleHeight = fTitleText.getLineHeight(); gc.dispose(); final int infoWidth = LayoutUtil.hintWidth(fInfoText, PREF_DETAIL_PANE_FONT, widthInChars); final int infoHeight = fInfoText.getLineHeight() * (heightInChars); return new Point( Math.max(titleWidth, infoWidth), titleHeight + LayoutUtil.defaultVSpacing() + infoHeight); }
/** * Set the GridData on button to be one that is spaced for the current font. * * @param button the button the data is being set on. */ protected void setButtonLayoutData(Button button) { GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); // Compute and store a font metric GC gc = new GC(button); gc.setFont(button.getFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); int widthHint = org.eclipse.jface.dialogs.Dialog.convertVerticalDLUsToPixels( fontMetrics, IDialogConstants.BUTTON_WIDTH); data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); button.setLayoutData(data); }
/* * @see org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy#draw(org.eclipse.swt.graphics.GC, org.eclipse.swt.custom.StyledText, int, int, org.eclipse.swt.graphics.Color) */ public void draw( Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color) { if (annotation instanceof ProjectionAnnotation) { ProjectionAnnotation projectionAnnotation = (ProjectionAnnotation) annotation; if (projectionAnnotation.isCollapsed()) { if (gc != null) { StyledTextContent content = textWidget.getContent(); int line = content.getLineAtOffset(offset); int lineStart = content.getOffsetAtLine(line); String text = content.getLine(line); int lineLength = text == null ? 0 : text.length(); int lineEnd = lineStart + lineLength; Point p = textWidget.getLocationAtOffset(lineEnd); Color c = gc.getForeground(); gc.setForeground(color); FontMetrics metrics = gc.getFontMetrics(); // baseline: where the dots are drawn int baseline = textWidget.getBaseline(offset); // descent: number of pixels that the box extends over baseline int descent = Math.min(2, textWidget.getLineHeight(offset) - baseline); // ascent: so much does the box stand up from baseline int ascent = metrics.getAscent(); // leading: free space from line top to box upper line int leading = baseline - ascent; // height: height of the box int height = ascent + descent; int width = metrics.getAverageCharWidth(); gc.drawRectangle(p.x, p.y + leading, width, height); int third = width / 3; int dotsVertical = p.y + baseline - 1; gc.drawPoint(p.x + third, dotsVertical); gc.drawPoint(p.x + width - third, dotsVertical); gc.setForeground(c); } else { textWidget.redrawRange(offset, length, true); } } } }
/** Sets or clears the caret in the "Example" widget. */ void setCaret() { Caret oldCaret = canvas.getCaret(); if (caretButton.getSelection()) { Caret newCaret = new Caret(canvas, SWT.NONE); Font font = canvas.getFont(); newCaret.setFont(font); GC gc = new GC(canvas); gc.setFont(font); newCaret.setBounds(1, 1, 1, gc.getFontMetrics().getHeight()); gc.dispose(); canvas.setCaret(newCaret); canvas.setFocus(); } else { canvas.setCaret(null); } if (oldCaret != null) oldCaret.dispose(); }
/** This method initializes composite1 */ private void createComposite1() { GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2; composite1 = new Composite(sShell, SWT.NONE); composite1.setLayout(gridLayout); createComposite(); text = new Text(composite1, SWT.BORDER | SWT.SINGLE); text.setTextLimit(30); int columns = 35; GC gc = new GC(text); FontMetrics fm = gc.getFontMetrics(); int width = columns * fm.getAverageCharWidth(); gc.dispose(); text.setLayoutData(new GridData(width, SWT.DEFAULT)); text.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { String newText = text.getText(); int radix = 10; Matcher numberMatcher = null; if (hexRadioButton.getSelection()) { numberMatcher = patternHexDigits.matcher(newText); radix = 16; } else { numberMatcher = patternDecDigits.matcher(newText); } tempResult = -1; if (numberMatcher.matches()) tempResult = Long.parseLong(newText, radix); if (tempResult >= 0L && tempResult <= limit) { showButton.setEnabled(true); gotoButton.setEnabled(true); label2.setText(""); } else { showButton.setEnabled(false); gotoButton.setEnabled(false); if ("".equals(newText)) label2.setText(""); else if (tempResult < 0) label2.setText("Not a number"); else label2.setText("Location out of range"); } } }); FormData formData = new FormData(); formData.top = new FormAttachment(label); composite1.setLayoutData(formData); }
@Override public void createControl(Composite parent) { Composite topLevel = new Composite(parent, SWT.NONE); FormLayout layout = new FormLayout(); layout.marginWidth = layout.marginHeight = 5; topLevel.setLayout(layout); Label textLabel = new Label(topLevel, SWT.NONE); textLabel.setText("Wait Duration (ms): "); durationText = new Text(topLevel, SWT.SINGLE | SWT.BORDER); durationText.setText("" + xmlWait.getWaitForMilliseconds()); durationText.addListener( SWT.Verify, new Listener() { public void handleEvent(Event e) { String string = e.text; char[] chars = string.toCharArray(); for (char c : chars) { if (!('0' <= c && c <= '9')) { e.doit = false; return; } } } }); durationText.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { validateInput(); } }); GC gc = new GC(durationText); FontMetrics fm = gc.getFontMetrics(); int charWidth = fm.getAverageCharWidth(); int width = durationText.computeSize(charWidth * 8, SWT.DEFAULT).x; gc.dispose(); FormData data = new FormData(width, SWT.DEFAULT); durationText.setLayoutData(data); data.left = new FormAttachment(textLabel, 5); data.top = new FormAttachment(textLabel, 0, SWT.CENTER); setControl(topLevel); validateInput(); }
private Point getTotalSize(Image image, String text) { Point size = new Point(0, 0); if (image != null) { Rectangle r = image.getBounds(); size.x += r.width; size.y += r.height; } GC gc = new GC(this); if (text != null && text.length() > 0) { Point e = gc.textExtent(text, DRAW_FLAGS); size.x += e.x; size.y = Math.max(size.y, e.y); if (image != null) size.x += GAP; } else { size.y = Math.max(size.y, gc.getFontMetrics().getHeight()); } gc.dispose(); return size; }
private final void draw(final GC gc, final int offset, final int length) { if (gc != null) { Point left = mTextWidget.getLocationAtOffset(offset); Point right = mTextWidget.getLocationAtOffset(offset + length); Color color = mMismatch ? mMismatchColor : mColor; if (mBox) { gc.setForeground(color); int x = left.x; int y = left.y; int w = right.x - left.x - 1; int h = gc.getFontMetrics().getHeight(); gc.drawRectangle(x, y, w, h); } else { gc.setForeground(mDefaultColor); gc.setBackground(color); gc.drawString(mTextWidget.getTextRange(offset, 1), left.x, left.y, false); } } else { mTextWidget.redrawRange(offset, length, true); } }
/** * Get the size hints for the receiver. These are used for layout data. * * @return Point - the preferred x and y coordinates */ public Point getSizeHints() { Display display = canvas.getDisplay(); GC gc = new GC(canvas); FontMetrics fm = gc.getFontMetrics(); int charWidth = fm.getAverageCharWidth(); int charHeight = fm.getHeight(); gc.dispose(); int maxWidth = display.getBounds().width / 2; int maxHeight = display.getBounds().height / 6; int fontWidth = charWidth * maxCharacterWidth; int fontHeight = charHeight * numShowItems; if (maxWidth < fontWidth) { fontWidth = maxWidth; } if (maxHeight < fontHeight) { fontHeight = maxHeight; } return new Point(fontWidth, fontHeight); }
public static FontMetrics getFontMetrics(Control control) { FontData[] fontDatas = control.getFont().getFontData(); if (fontDatas.length == 0) { return null; } String fontDescription = fontDatas[0].toString(); synchronized (cachedFontMetrics) { FontMetrics fontMetrics = (FontMetrics) cachedFontMetrics.get(fontDescription); if (fontMetrics == null) { GC gc = new GC(control); gc.setFont(JFaceResources.getDialogFont()); fontMetrics = gc.getFontMetrics(); gc.dispose(); cachedFontMetrics.put(fontDescription, fontMetrics); } return fontMetrics; } }
public CsPixelConverter(Control control) { GC gc = new GC(control); gc.setFont(control.getFont()); fFontMetrics = gc.getFontMetrics(); gc.dispose(); }
protected int getFontWidth(Button b) { GC gc = new GC(b); FontMetrics fm = gc.getFontMetrics(); gc.dispose(); return fm.getAverageCharWidth(); }
@Override protected void createContent(final Composite parent) { fContentComposite = new Composite(parent, SWT.NONE) { @Override public Point computeSize(final int width, final int height, final boolean changed) { return super.computeSize(width, height, changed || width != getSize().x); } }; fContentComposite.setBackgroundMode(SWT.INHERIT_FORCE); final GridLayout gridLayout = LayoutUtil.applyCompositeDefaults(new GridLayout(), 2); gridLayout.horizontalSpacing = (int) ((gridLayout.horizontalSpacing) / 1.5); fContentComposite.setLayout(gridLayout); final int vIndent = Math.max(1, LayoutUtil.defaultVSpacing() / 4); final int hIndent = Math.max(2, LayoutUtil.defaultHSpacing() / 3); { // Title image fTitleImage = new Label(fContentComposite, SWT.NULL); final Image image = SharedUIResources.getImages().get(SharedUIResources.PLACEHOLDER_IMAGE_ID); fTitleImage.setImage(image); final GridData textGd = new GridData(SWT.FILL, SWT.TOP, false, false); fTitleText = new StyledText(fContentComposite, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP) { @Override public Point computeSize(int width, final int height, final boolean changed) { if (!fLayoutHint && width <= 0 && fContentComposite.getSize().x > 0) { width = fContentComposite.getSize().x - LayoutUtil.defaultHMargin() - fTitleImage.getSize().x - LayoutUtil.defaultHSpacing() - 10; } final Point size = super.computeSize(width, -1, true); // if (width >= 0) { // size.x = Math.min(size.x, width); // } return size; } }; fTitleText.setFont(JFaceResources.getDialogFont()); final GC gc = new GC(fTitleText); final FontMetrics fontMetrics = gc.getFontMetrics(); final GridData imageGd = new GridData(SWT.FILL, SWT.TOP, false, false); imageGd.horizontalIndent = hIndent; final int textHeight = fontMetrics.getAscent() + fontMetrics.getLeading(); final int imageHeight = image.getBounds().height; final int shift = Math.max(3, (int) ((fontMetrics.getDescent()) / 1.5)); if (textHeight + shift < imageHeight) { imageGd.verticalIndent = vIndent + shift; textGd.verticalIndent = vIndent + (imageHeight - textHeight); } else { imageGd.verticalIndent = vIndent + (textHeight - imageHeight) + shift; textGd.verticalIndent = vIndent; } fTitleImage.setLayoutData(imageGd); fTitleText.setLayoutData(textGd); fLayoutWorkaround = true; gc.dispose(); } fInfoText = new StyledText( fContentComposite, fMode == MODE_FOCUS ? (SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL) : (SWT.MULTI | SWT.READ_ONLY)); fInfoText.setIndent(hIndent); fInfoText.setFont(JFaceResources.getFont(PREF_DETAIL_PANE_FONT)); final GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); // gd.widthHint = LayoutUtil.hintWidth(fInfoText, INFO_FONT, 50); fInfoText.setLayoutData(gd); setBackgroundColor(getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); setForegroundColor(getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); updateInput(); }
/** * Creates and returns the source lookup control. * * @param parent the parent widget of this control */ @Override public void createControl(Composite parent) { Font font = parent.getFont(); Composite comp = new Composite(parent, SWT.NONE); GridLayout topLayout = new GridLayout(); topLayout.numColumns = 2; comp.setLayout(topLayout); GridData gd = new GridData(GridData.FILL_BOTH); comp.setLayoutData(gd); Label viewerLabel = new Label(comp, SWT.LEFT); viewerLabel.setText(LauncherMessages.SourceLookupBlock__Source_Lookup_Path__1); gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); gd.horizontalSpan = 2; viewerLabel.setLayoutData(gd); viewerLabel.setFont(font); fPathViewer = new RuntimeClasspathViewer(comp); fPathViewer.addEntriesChangedListener(this); gd = new GridData(GridData.FILL_BOTH); fPathViewer.getControl().setLayoutData(gd); fPathViewer.getControl().setFont(font); Composite pathButtonComp = new Composite(comp, SWT.NONE); GridLayout pathButtonLayout = new GridLayout(); pathButtonLayout.marginHeight = 0; pathButtonLayout.marginWidth = 0; pathButtonComp.setLayout(pathButtonLayout); gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL); pathButtonComp.setLayoutData(gd); pathButtonComp.setFont(font); createVerticalSpacer(comp, 2); fDefaultButton = new Button(comp, SWT.CHECK); fDefaultButton.setText(LauncherMessages.SourceLookupBlock_Use_defau_lt_source_lookup_path_1); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalSpan = 2; fDefaultButton.setLayoutData(gd); fDefaultButton.setFont(font); fDefaultButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent evt) { handleDefaultButtonSelected(); } }); fDuplicatesButton = new Button(comp, SWT.CHECK); fDuplicatesButton.setText( LauncherMessages.SourceLookupBlock__Search_for_duplicate_source_files_on_path_1); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); gd.horizontalSpan = 2; fDuplicatesButton.setLayoutData(gd); fDuplicatesButton.setFont(font); fDuplicatesButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent evt) { setDirty(true); updateLaunchConfigurationDialog(); } }); List<RuntimeClasspathAction> advancedActions = new ArrayList<RuntimeClasspathAction>(5); GC gc = new GC(parent); gc.setFont(parent.getFont()); FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); RuntimeClasspathAction action = new MoveUpAction(fPathViewer); Button button = createPushButton(pathButtonComp, action.getText(), fontMetrics); action.setButton(button); action = new MoveDownAction(fPathViewer); button = createPushButton(pathButtonComp, action.getText(), fontMetrics); action.setButton(button); action = new RemoveAction(fPathViewer); button = createPushButton(pathButtonComp, action.getText(), fontMetrics); action.setButton(button); action = new AddProjectAction(fPathViewer); button = createPushButton(pathButtonComp, action.getText(), fontMetrics); action.setButton(button); action = new AddJarAction(fPathViewer); button = createPushButton(pathButtonComp, action.getText(), fontMetrics); action.setButton(button); action = new AddExternalJarAction(fPathViewer, DIALOG_SETTINGS_PREFIX); button = createPushButton(pathButtonComp, action.getText(), fontMetrics); action.setButton(button); action = new AddFolderAction(fPathViewer); advancedActions.add(action); action = new AddExternalFolderAction(fPathViewer, DIALOG_SETTINGS_PREFIX); advancedActions.add(action); action = new AddVariableAction(fPathViewer); advancedActions.add(action); action = new AddLibraryAction(null); advancedActions.add(action); action = new AttachSourceAction(fPathViewer, SWT.RADIO); advancedActions.add(action); IAction[] adv = advancedActions.toArray(new IAction[advancedActions.size()]); action = new AddAdvancedAction(fPathViewer, adv); button = createPushButton(pathButtonComp, action.getText(), fontMetrics); action.setButton(button); setControl(comp); }
public CltPixelConverter(org.eclipse.swt.widgets.Control control) { org.eclipse.swt.graphics.GC gc = new org.eclipse.swt.graphics.GC(control); gc.setFont(control.getFont()); fFontMetrics = gc.getFontMetrics(); gc.dispose(); }
/** * Creates the progress monitor's UI parts and layouts them according to the given layout. If the * layout is <code>null</code> the part's default layout is used. * * @param layout The layout for the receiver. * @param progressIndicatorHeight The suggested height of the indicator */ protected void initialize(Layout layout, int progressIndicatorHeight) { if (layout == null) { GridLayout l = new GridLayout(); l.marginWidth = 0; l.marginHeight = 0; layout = l; } int numColumns = 1; if (fHasStopButton) numColumns++; setLayout(layout); if (layout instanceof GridLayout) ((GridLayout) layout).numColumns = numColumns; fLabel = new Label(this, SWT.LEFT); fLabel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, numColumns, 1)); if (progressIndicatorHeight == SWT.DEFAULT) { GC gc = new GC(fLabel); FontMetrics fm = gc.getFontMetrics(); gc.dispose(); progressIndicatorHeight = fm.getHeight(); } fProgressIndicator = new ProgressIndicator(this); GridData gd = new GridData(); gd.horizontalAlignment = GridData.FILL; gd.grabExcessHorizontalSpace = true; gd.grabExcessVerticalSpace = false; gd.verticalAlignment = GridData.CENTER; gd.heightHint = progressIndicatorHeight; fProgressIndicator.setLayoutData(gd); if (fHasStopButton) { fToolBar = new ToolBar(this, SWT.FLAT); gd = new GridData(); gd.grabExcessHorizontalSpace = false; gd.grabExcessVerticalSpace = false; gd.verticalAlignment = GridData.CENTER; fToolBar.setLayoutData(gd); fStopButton = new ToolItem(fToolBar, SWT.PUSH); // It would have been nice to use the fCancelListener, but that // listener operates on the fCancelComponent which must be a control. fStopButton.addSelectionListener( new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { setCanceled(true); if (fStopButton != null) { fStopButton.setEnabled(false); } } }); final Image stopImage = ImageDescriptor.createFromFile(ProgressMonitorPart.class, "images/stop.gif") .createImage(getDisplay()); // $NON-NLS-1$ final Cursor arrowCursor = new Cursor(this.getDisplay(), SWT.CURSOR_ARROW); fToolBar.setCursor(arrowCursor); fStopButton.setImage(stopImage); fStopButton.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { // RAP [rh] images don't support dispose // stopImage.dispose(); arrowCursor.dispose(); } }); fStopButton.setToolTipText( JFaceResources.getString("ProgressMonitorPart.cancelToolTip")); // $NON-NLS-1$ } }