List of usage examples for org.eclipse.jface.resource JFaceResources getDefaultFont
public static Font getDefaultFont()
From source file:com.ociweb.gmf.EnumDirectEdit.EnumDirectEditManager.java
License:Open Source License
/** * Given a label figure object, this will calculate the * correct Font needed to display into screen coordinates, taking into * account the current mapmode. This will typically be used by direct * edit cell editors that need to display independent of the zoom or any * coordinate mapping that is taking place on the drawing surface. * //www . j a v a 2 s .c om * @param label the label to use for the font calculation * @return the <code>Font</code> that is scaled to the screen coordinates. * Note: the returned <code>Font</code> should not be disposed since it is * cached by a common resource manager. */ protected Font getScaledFont(IFigure label) { Font scaledFont = label.getFont(); FontData data = scaledFont.getFontData()[0]; Dimension fontSize = new Dimension(0, MapModeUtil.getMapMode(label).DPtoLP(data.getHeight())); label.translateToAbsolute(fontSize); if (Math.abs(data.getHeight() - fontSize.height) < 2) fontSize.height = data.getHeight(); try { FontDescriptor fontDescriptor = FontDescriptor.createFrom(data); cachedFontDescriptors.add(fontDescriptor); return getResourceManager().createFont(fontDescriptor); } catch (DeviceResourceException e) { Trace.catching(DiagramUIPlugin.getInstance(), DiagramUIDebugOptions.EXCEPTIONS_CATCHING, getClass(), "getScaledFont", e); //$NON-NLS-1$ Log.error(DiagramUIPlugin.getInstance(), DiagramUIStatusCodes.IGNORED_EXCEPTION_WARNING, "getScaledFont", e); //$NON-NLS-1$ } return JFaceResources.getDefaultFont(); }
From source file:com.rcpcompany.uibindings.extests.utils.BindingSpecTest.java
License:Open Source License
@Test public void testSimpleSpecMapUnit1() { final Display d = Display.getDefault(); final GC gc = new GC(d); final Font f = JFaceResources.getDefaultFont(); gc.setFont(f);//from ww w. ja v a 2s. c o m final FontMetrics fm = gc.getFontMetrics(); gc.dispose(); final float fh = f.getFontData()[0].getHeight(); assertTrue("Font size range, got " + fh, 7.0f <= fh && fh < 18.0f); final List<IBindingSpec> spec = IBindingSpec.Factory.parseSingleSpec(ShopPackage.Literals.CONTACT, "country(w=10em).name(w=10dlu)", SpecContext.FORM_FIELD); assertNotNull(spec); assertEquals(2, spec.size()); specTest(spec.get(0), ShopPackage.Literals.CONTACT__COUNTRY, Constants.ARG_WIDTH, Math.round(10 * fh)); specTest(spec.get(1), IMOAOPackage.Literals.NAMED_OBJECT__NAME, Constants.ARG_WIDTH, Math.round(10 / 4.0f * fh)); }
From source file:com.siteview.mde.internal.ui.util.SWTUtil.java
License:Open Source License
/** * Returns a width hint for a button control. */// w w w. j ava 2 s . co m public static int getButtonWidthHint(Button button) { if (button.getFont().equals(JFaceResources.getDefaultFont())) button.setFont(JFaceResources.getDialogFont()); PixelConverter converter = new PixelConverter(button); int widthHint = converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); }
From source file:de.anbos.eclipse.logviewer.plugin.LogViewerPlugin.java
License:Apache License
private void loadDefaultPluginPreferences(IPreferenceStore store) { store.setDefault(ILogViewerConstants.PREF_BACKLOG, ILogViewerConstants.DEFAULT_BACKLOG); store.setDefault(ILogViewerConstants.PREF_BUFFER, ILogViewerConstants.DEFAULT_BUFFER_CAPACITY); store.setDefault(ILogViewerConstants.PREF_READWAIT, ILogViewerConstants.DEFAULT_READWAIT_SIZE); store.setDefault(ILogViewerConstants.PREF_ENCODING, System.getProperty("file.encoding")); store.setDefault(ILogViewerConstants.PREF_WORD_WRAP, ILogViewerConstants.DEAFULT_WORD_WRAP); store.setDefault(ILogViewerConstants.PREF_SHOW_WHEN_UPDATED, ILogViewerConstants.DEAFULT_SHOW_WHEN_UPDATED); store.setDefault(ILogViewerConstants.PREF_FILTER_EXTENSIONS, ILogViewerConstants.DEFAULT_FILTER_EXTENSIONS); store.setDefault(ILogViewerConstants.PREF_SHOW_TOP_OF_FILE, ILogViewerConstants.DEAFULT_SHOW_TOP_OF_FILE); PreferenceConverter.setDefault(store, ILogViewerConstants.PREF_CURSORLINE_COLOR, new RGB(192, 192, 192)); PreferenceConverter.setDefault(store, ILogViewerConstants.PREF_EDITOR_FONT_STYLE, JFaceResources.getDefaultFont().getFontData()); }
From source file:de.anbos.eclipse.logviewer.plugin.viewer.LogFileViewer.java
License:Apache License
public LogFileViewer(Composite parent, int style) { store = LogViewerPlugin.getDefault().getPreferenceStore(); if (store.getBoolean(ILogViewerConstants.PREF_WORD_WRAP)) style |= SWT.WRAP;//from www. j a v a 2s . c o m showWhenUpdated = store.getBoolean(ILogViewerConstants.PREF_SHOW_WHEN_UPDATED); showTopOfFile = store.getBoolean(ILogViewerConstants.PREF_SHOW_TOP_OF_FILE); txtViewer = new SourceViewer(parent, null, style); FontData[] fontData = PreferenceConverter.getFontDataArray(store, ILogViewerConstants.PREF_EDITOR_FONT_STYLE); if (fontData == null) { fontData = JFaceResources.getDefaultFont().getFontData(); } txtViewer.getTextWidget().setFont(new Font(Display.getCurrent(), fontData)); propertyChangeListener = new PropertyChangeListener(); store.addPropertyChangeListener(propertyChangeListener); createCursorLinePainter(); createAndInstallPresentationReconciler(); }
From source file:de.femodeling.e4.ui.progress.internal.DetailedProgressViewer.java
License:Open Source License
/** * Create a new instance of the receiver with a control that is a child of * parent with style style.//from w ww . j a va 2s. c om * * @param parent * @param style */ public DetailedProgressViewer(Composite parent, int style) { scrolled = new ScrolledComposite(parent, SWT.V_SCROLL | style); int height = JFaceResources.getDefaultFont().getFontData()[0].getHeight(); scrolled.getVerticalBar().setIncrement(height * 2); scrolled.setExpandHorizontal(true); scrolled.setExpandVertical(true); control = new Composite(scrolled, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; control.setLayout(layout); control.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); control.addFocusListener(new FocusAdapter() { private boolean settingFocus = false; /* * (non-Javadoc) * * @see org.eclipse.swt.events.FocusAdapter#focusGained(org.eclipse.swt.events.FocusEvent) */ public void focusGained(FocusEvent e) { if (!settingFocus) { // Prevent new focus events as a result this update // occurring settingFocus = true; setFocus(); settingFocus = false; } } }); control.addControlListener(new ControlListener() { /* * (non-Javadoc) * * @see org.eclipse.swt.events.ControlListener#controlMoved(org.eclipse.swt.events.ControlEvent) */ public void controlMoved(ControlEvent e) { updateVisibleItems(); } /* * (non-Javadoc) * * @see org.eclipse.swt.events.ControlListener#controlResized(org.eclipse.swt.events.ControlEvent) */ public void controlResized(ControlEvent e) { updateVisibleItems(); } }); /* PlatformUI.getWorkbench().getHelpSystem().setHelp(control, IWorkbenchHelpContextIds.RESPONSIVE_UI); */ scrolled.setContent(control); hookControl(control); noEntryArea = new Composite(scrolled, SWT.NONE); noEntryArea.setLayout(new GridLayout()); Text noEntryLabel = new Text(noEntryArea, SWT.SINGLE); noEntryLabel.setText(ProgressMessages.ProgressView_NoOperations); noEntryLabel.setBackground(noEntryArea.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); GridData textData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); noEntryLabel.setLayoutData(textData); noEntryLabel.setEditable(false); /* PlatformUI.getWorkbench().getHelpSystem().setHelp(noEntryLabel, IWorkbenchHelpContextIds.RESPONSIVE_UI); */ }
From source file:de.femodeling.e4.ui.progress.internal.ProgressCanvasViewer.java
License:Open Source License
/** * Create a new instance of the receiver with the supplied * parent and style bits./*from www.ja v a2s . c o m*/ * @param parent The composite the Canvas is created in * @param style style bits for the canvas * @param itemsToShow the number of items this will show * @param numChars The number of characters for the width hint. * @param side the side to display text, this helps determine horizontal vs vertical */ ProgressCanvasViewer(Composite parent, int style, int itemsToShow, int numChars, int orientation) { super(); this.orientation = orientation; numShowItems = itemsToShow; maxCharacterWidth = numChars; canvas = new Canvas(parent, style); hookControl(canvas); // Compute and store a font metric GC gc = new GC(canvas); gc.setFont(JFaceResources.getDefaultFont()); fontMetrics = gc.getFontMetrics(); gc.dispose(); initializeListeners(); }
From source file:descent.internal.ui.util.SWTUtil.java
License:Open Source License
/** * Returns a height hint for a button control. *///from w w w. j a va 2 s . com public static int getButtonHeigthHint(Button button) { if (button.getFont().equals(JFaceResources.getDefaultFont())) button.setFont(JFaceResources.getDialogFont()); PixelConverter converter = new PixelConverter(button); return converter.convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); }
From source file:edu.buffalo.cse.green.editor.model.CompartmentModel.java
License:Open Source License
/** * @return A new <code>CompartmentModel</code> that holds * <code>TypeModel</code> instances. *//*from w w w . ja v a2 s . c o m*/ public static CompartmentModel newTypeCompartment() { return new CompartmentModel() { /** * Label holder for incremental exploration labels */ private IFigure _relLabel = null; /** * A reference to this model's figure equivalent */ private CompartmentFigure _figure; /** * @see edu.buffalo.cse.green.editor.model.CompartmentModel#addChild(edu.buffalo.cse.green.editor.model.FieldModel) */ void addChild(FieldModel model) { GreenException.illegalOperation("Invalid parent."); } /** * @see edu.buffalo.cse.green.editor.model.CompartmentModel#addChild(edu.buffalo.cse.green.editor.model.MethodModel) */ void addChild(MethodModel model) { GreenException.illegalOperation("Invalid parent."); } /** * @see edu.buffalo.cse.green.editor.model.CompartmentModel#getLayout() */ public int getLayout() { return ALIGN_CENTER; } /** * @see edu.buffalo.cse.green.editor.model.CompartmentModel#dispatchLabels(edu.buffalo.cse.green.editor.controller.CompartmentPart) */ public void dispatchLabels(CompartmentPart part, CompartmentFigure figure) { final TypePart parent = (TypePart) part.getParent(); _figure = figure; _figure.add(parent.getNameLabel()); _relLabel = parent.getRelLabel(); _relLabel.setLayoutManager(new ToolbarLayout(true)); _relLabel.add(new Label(" ")); Label r = new Label(" ALL ", null); r.setFont(new Font(null, JFaceResources.getDefaultFont().getFontData()[0].getName(), 12, 0)); _relLabel.add(r); r.addMouseListener(new MouseListener() { public void mousePressed(MouseEvent me) { TypeModel typeModel = (TypeModel) parent.getModel(); DiagramEditor editor = parent.getEditor(); editor.execute(new IncrementalExploreCommand(editor, typeModel, false)); } public void mouseReleased(MouseEvent me) { } public void mouseDoubleClicked(MouseEvent me) { } }); r.setToolTip(new Label(" All ")); for (final RelationshipGroup group : PlugIn.getRelationshipList()) { Label rel = new Label(" ", group.getImageDescriptor().createImage()); _relLabel.add(rel); rel.addMouseListener(new MouseListener() { public void mousePressed(MouseEvent me) { List<RelationshipGroup> relationships = new ArrayList<RelationshipGroup>(); relationships.add(group); TypeModel typeModel = (TypeModel) parent.getModel(); DiagramEditor editor = parent.getEditor(); editor.execute(new IncrementalExploreCommand(editor, typeModel, relationships, false)); } public void mouseReleased(MouseEvent me) { } public void mouseDoubleClicked(MouseEvent me) { } }); rel.setToolTip(new Label(" " + (group.getSubtype() != null ? group.getSubtype() + " " : "") + group.getName() + " ")); } } public boolean isTypeLabelCompartment() { return true; } @Override public void updateLabels(boolean visible) { if (_figure != null && _relLabel != null) { if (visible) _figure.add(_relLabel); else if (!visible && _figure.getChildren().contains(_relLabel)) _figure.remove(_relLabel); } } }; }
From source file:edu.tsinghua.lumaqq.ui.BorderStyler.java
License:Open Source License
/** * shell/*from www. j a v a 2 s. co m*/ * * @param shell * @return * */ public Composite decorateShell(Shell s) { shell = s; shell.setData(STYLER, this); // layout GridLayout layout = new GridLayout(3, false); layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0; shell.setLayout(layout); Composite leftTop = new Composite(shell, SWT.NONE | SWT.NO_BACKGROUND); if (resizable) leftTop.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENWSE)); GridData gd = new GridData(); gd.widthHint = gd.heightHint = 5; leftTop.setLayoutData(gd); leftTop.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); int i = 0; for (Color c : Colors.MAINSHELL_BORDERS) { e.gc.setForeground(c); e.gc.drawLine(i, i, bound.width, i); e.gc.drawLine(i, i, i, bound.height); i++; } } }); if (resizable) { leftTop.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Control control = (Control) e.getSource(); Point loc = control.toDisplay(e.x, e.y); downX = loc.x; downY = loc.y; } @Override public void mouseUp(MouseEvent e) { Control control = (Control) e.getSource(); Point loc = control.toDisplay(e.x, e.y); int dx = downX - loc.x; int dy = downY - loc.y; if (dx == 0 && dy == 0) return; Rectangle bound = shell.getBounds(); bound.x -= dx; bound.y -= dy; bound.width += dx; bound.height += dy; setShellBound(bound); } }); } top = new Label(shell, SWT.LEFT); if (resizable) top.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENS)); gd = new GridData(GridData.FILL_HORIZONTAL); gd.heightHint = 5; top.setLayoutData(gd); top.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); int i = 0; for (Color c : Colors.MAINSHELL_BORDERS) { e.gc.setForeground(c); e.gc.drawLine(0, i, bound.width, i); i++; } } }); if (resizable) { top.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Control control = (Control) e.getSource(); downY = control.toDisplay(e.x, e.y).y; } @Override public void mouseUp(MouseEvent e) { Control control = (Control) e.getSource(); int newY = control.toDisplay(e.x, e.y).y; int dy = downY - newY; if (dy == 0) return; Rectangle bound = shell.getBounds(); bound.y -= dy; bound.height += dy; setShellBound(bound); } }); } Composite rightTop = new Composite(shell, SWT.NONE | SWT.NO_BACKGROUND); if (resizable) rightTop.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENESW)); gd = new GridData(); gd.widthHint = gd.heightHint = 5; rightTop.setLayoutData(gd); rightTop.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); int i = 0; for (Color c : Colors.MAINSHELL_BORDERS) { e.gc.setForeground(c); e.gc.drawLine(bound.width - i - 1, i, 0, i); e.gc.drawLine(bound.width - i - 1, i, bound.width - i - 1, bound.height); i++; } } }); if (resizable) { rightTop.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Control control = (Control) e.getSource(); Point loc = control.toDisplay(e.x, e.y); downX = loc.x; downY = loc.y; } @Override public void mouseUp(MouseEvent e) { Control control = (Control) e.getSource(); Point loc = control.toDisplay(e.x, e.y); int dx = loc.x - downX; int dy = downY - loc.y; if (dx == 0 && dy == 0) return; Rectangle bound = shell.getBounds(); bound.y -= dy; bound.width += dx; bound.height += dy; setShellBound(bound); } }); } left = new Label(shell, SWT.LEFT); gd = new GridData(GridData.FILL_VERTICAL); gd.widthHint = 5; gd.verticalSpan = 2; left.setLayoutData(gd); if (resizable) left.setCursor(display.getSystemCursor(SWT.CURSOR_SIZEWE)); left.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); int i = 0; for (Color c : Colors.MAINSHELL_BORDERS) { e.gc.setForeground(c); e.gc.drawLine(i, 0, i, bound.height); i++; } } }); if (resizable) { left.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Control control = (Control) e.getSource(); downX = control.toDisplay(e.x, e.y).x; } @Override public void mouseUp(MouseEvent e) { Control control = (Control) e.getSource(); int newX = control.toDisplay(e.x, e.y).x; int dx = downX - newX; if (dx == 0) return; Rectangle bound = shell.getBounds(); bound.x -= dx; bound.width += dx; setShellBound(bound); } }); } topDown = new Composite(shell, SWT.LEFT); gd = new GridData(GridData.FILL_HORIZONTAL); gd.heightHint = 23; topDown.setLayoutData(gd); topDown.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); e.gc.setForeground(Colors.MAINSHELL_TITLE_TOP); e.gc.setBackground(Colors.MAINSHELL_TITLE_BOTTOM); e.gc.fillGradientRectangle(0, 0, bound.width, bound.height, true); e.gc.setForeground(Colors.MAINSHELL_TITLE_SEPARATOR_TOP); e.gc.drawLine(2, 19, bound.width - 2, 19); e.gc.setForeground(Colors.MAINSHELL_TITLE_SEPARATOR_BOTTOM); e.gc.drawLine(2, 20, bound.width - 2, 20); Image image = shell.getImage(); Rectangle imgBound = (image == null) ? new Rectangle(0, 0, 16, 16) : image.getBounds(); if (image != null) { e.gc.drawImage(image, 2, (18 - imgBound.height) >> 1); } String text = shell.getText(); if (text != null) { String name = JFaceResources.getDefaultFont().getFontData()[0].getName(); e.gc.setForeground(Colors.WHITE); e.gc.setFont(JFaceResources.getFontRegistry().getBold(name)); Point extent = e.gc.textExtent(text); e.gc.drawString(text, imgBound.width + 7, (18 - extent.y) >> 1, true); } } }); topDown.setLayout(new FormLayout()); topDown.addMouseListener(new MouseListener() { public void mouseDown(MouseEvent e) { downX = e.x; downY = e.y; isMove = true; fireMouseDownEvent(e); } public void mouseUp(MouseEvent e) { isMove = false; fireMouseUpEvent(e); } public void mouseDoubleClick(MouseEvent e) { if (maximizeWhenDoubleClick && showMaxButton) doMaximize(); } }); topDown.addMouseMoveListener(new MouseMoveListener() { public void mouseMove(MouseEvent e) { if (isMove) { Point loc = shell.getLocation(); int x = loc.x + e.x - downX; int y = loc.y + e.y - downY; shell.setLocation(x, y); } } }); // Label lblClose = new Label(topDown, SWT.CENTER); lblClose.setImage(res.getImage(Resources.bmpCloseNormal)); FormData fd = new FormData(); fd.top = new FormAttachment(0, 0); fd.bottom = new FormAttachment(0, 16); fd.right = new FormAttachment(100, -2); fd.left = new FormAttachment(100, -19); lblClose.setLayoutData(fd); lblClose.addMouseTrackListener(new MouseTrackAdapter() { @Override public void mouseEnter(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(res.getImage(Resources.bmpCloseHover)); } @Override public void mouseExit(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(res.getImage(Resources.bmpCloseNormal)); } }); lblClose.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(res.getImage(Resources.bmpCloseDown)); } @Override public void mouseUp(MouseEvent e) { if (checkMinimizeWhenClose && main != null) { if (main.getOptionHelper().isMinimizeWhenClose()) { Label lbl = (Label) e.getSource(); lbl.setImage(res.getImage(Resources.bmpCloseHover)); shell.setMinimized(true); shell.setVisible(false); } else shell.close(); } else shell.close(); } }); Label referenceLabel = lblClose; // if (showMaxButton) { lblMax = new Label(topDown, SWT.CENTER); lblMax.setImage(res.getImage(Resources.bmpMaxNormal)); fd = new FormData(); fd.top = new FormAttachment(0, 0); fd.bottom = new FormAttachment(0, 16); fd.right = new FormAttachment(referenceLabel, 0, SWT.LEFT); fd.left = new FormAttachment(referenceLabel, -17, SWT.LEFT); lblMax.setLayoutData(fd); lblMax.addMouseTrackListener(new MouseTrackAdapter() { @Override public void mouseEnter(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(shell.getMaximized() ? res.getImage(Resources.bmpRestoreHover) : res.getImage(Resources.bmpMaxHover)); } @Override public void mouseExit(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(shell.getMaximized() ? res.getImage(Resources.bmpRestoreNormal) : res.getImage(Resources.bmpMaxNormal)); } }); lblMax.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(shell.getMaximized() ? res.getImage(Resources.bmpRestoreDown) : res.getImage(Resources.bmpMaxDown)); } @Override public void mouseUp(MouseEvent e) { doMaximize(); } }); referenceLabel = lblMax; } // ? if (showMinButton) { Label lblMin = new Label(topDown, SWT.CENTER); lblMin.setImage(res.getImage(Resources.bmpMinNormal)); fd = new FormData(); fd.top = new FormAttachment(0, 0); fd.bottom = new FormAttachment(0, 16); fd.right = new FormAttachment(referenceLabel, 0, SWT.LEFT); fd.left = new FormAttachment(referenceLabel, -16, SWT.LEFT); lblMin.setLayoutData(fd); lblMin.addMouseTrackListener(new MouseTrackAdapter() { @Override public void mouseEnter(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(res.getImage(Resources.bmpMinHover)); } @Override public void mouseExit(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(res.getImage(Resources.bmpMinNormal)); } }); lblMin.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(res.getImage(Resources.bmpMinDown)); } @Override public void mouseUp(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(res.getImage(Resources.bmpMinHover)); shell.setMinimized(true); if (hideWhenMinimize) shell.setVisible(false); } }); referenceLabel = lblMin; } // if (showPlusButton) { Label lblPlus = new Label(topDown, SWT.CENTER); lblPlus.setImage(res.getImage(Resources.bmpPlusNormal)); fd = new FormData(); fd.top = new FormAttachment(0, 0); fd.bottom = new FormAttachment(0, 16); fd.right = new FormAttachment(referenceLabel, -1, SWT.LEFT); fd.left = new FormAttachment(referenceLabel, -17, SWT.LEFT); lblPlus.setLayoutData(fd); lblPlus.addMouseTrackListener(new MouseTrackAdapter() { @Override public void mouseEnter(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(res.getImage(Resources.bmpPlusHover)); } @Override public void mouseExit(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(res.getImage(Resources.bmpPlusNormal)); } }); lblPlus.addMouseListener(new MouseListener() { public void mouseDown(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(res.getImage(Resources.bmpPlusDown)); if (plusMouseListener != null) plusMouseListener.mouseDown(e); } public void mouseDoubleClick(MouseEvent e) { if (plusMouseListener != null) plusMouseListener.mouseDoubleClick(e); } public void mouseUp(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(res.getImage(Resources.bmpPlusHover)); if (plusMouseListener != null) plusMouseListener.mouseUp(e); } }); } right = new Label(shell, SWT.LEFT); gd = new GridData(GridData.FILL_VERTICAL); gd.widthHint = 5; gd.verticalSpan = 2; right.setLayoutData(gd); if (resizable) right.setCursor(display.getSystemCursor(SWT.CURSOR_SIZEWE)); right.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); int i = 4; for (Color c : Colors.MAINSHELL_BORDERS) { e.gc.setForeground(c); e.gc.drawLine(i, 0, i, bound.height); i--; } } }); if (resizable) { right.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Control control = (Control) e.getSource(); downX = control.toDisplay(e.x, e.y).x; } @Override public void mouseUp(MouseEvent e) { Control control = (Control) e.getSource(); int newX = control.toDisplay(e.x, e.y).x; int dx = newX - downX; if (dx == 0) return; Point size = shell.getSize(); size.x += dx; setShellSize(size); } }); } center = new Composite(shell, SWT.NONE); center.setLayoutData(new GridData(GridData.FILL_BOTH)); layout = new GridLayout(); layout.marginHeight = layout.marginWidth = layout.horizontalSpacing = layout.verticalSpacing = 0; center.setLayout(layout); Composite leftBottom = new Composite(shell, SWT.NONE | SWT.NO_BACKGROUND); if (resizable) leftBottom.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENESW)); gd = new GridData(); gd.widthHint = gd.heightHint = 5; leftBottom.setLayoutData(gd); leftBottom.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); int i = 0; for (Color c : Colors.MAINSHELL_BORDERS) { e.gc.setForeground(c); e.gc.drawLine(i, bound.height - i - 1, i, 0); e.gc.drawLine(i, bound.height - i - 1, bound.width, bound.height - i - 1); i++; } } }); if (resizable) { leftBottom.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Control control = (Control) e.getSource(); Point loc = control.toDisplay(e.x, e.y); downX = loc.x; downY = loc.y; } @Override public void mouseUp(MouseEvent e) { Control control = (Control) e.getSource(); Point loc = control.toDisplay(e.x, e.y); int dx = downX - loc.x; int dy = loc.y - downY; if (dx == 0 && dy == 0) return; Rectangle bound = shell.getBounds(); bound.x -= dx; bound.width += dx; bound.height += dy; setShellBound(bound); } }); } bottom = new Label(shell, SWT.LEFT); if (resizable) bottom.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENS)); gd = new GridData(GridData.FILL_HORIZONTAL); gd.heightHint = 5; bottom.setLayoutData(gd); bottom.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); int i = 0; for (Color c : Colors.MAINSHELL_BORDERS) { e.gc.setForeground(c); e.gc.drawLine(0, 5 - i - 1, bound.width, 5 - i - 1); i++; } } }); if (resizable) { bottom.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Control control = (Control) e.getSource(); downY = control.toDisplay(e.x, e.y).y; } @Override public void mouseUp(MouseEvent e) { Control control = (Control) e.getSource(); int newY = control.toDisplay(e.x, e.y).y; int dy = newY - downY; if (dy == 0) return; Point size = shell.getSize(); size.y += dy; setShellSize(size); } }); } Composite rightBottom = new Composite(shell, SWT.NONE | SWT.NO_BACKGROUND); if (resizable) rightBottom.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENWSE)); gd = new GridData(); gd.widthHint = gd.heightHint = 5; rightBottom.setLayoutData(gd); rightBottom.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); int i = 0; for (Color c : Colors.MAINSHELL_BORDERS) { e.gc.setForeground(c); e.gc.drawLine(bound.width - i - 1, bound.height - i - 1, bound.width - i - 1, 0); e.gc.drawLine(bound.width - i - 1, bound.height - i - 1, 0, bound.height - i - 1); i++; } } }); if (resizable) { rightBottom.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Control control = (Control) e.getSource(); Point loc = control.toDisplay(e.x, e.y); downX = loc.x; downY = loc.y; } @Override public void mouseUp(MouseEvent e) { Control control = (Control) e.getSource(); Point loc = control.toDisplay(e.x, e.y); int dx = loc.x - downX; int dy = loc.y - downY; if (dx == 0 && dy == 0) return; Point size = shell.getSize(); size.x += dx; size.y += dy; setShellSize(size); } }); } return center; }