/** * Sets the image. * * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the image is disposed * </ul> * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setImage(Image image) { checkWidget(); if (image != null && image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); this.image = image; strategy.update(); }
/** * Sets the text. * * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the text is null * </ul> * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setText(String text) { checkWidget(); if (text == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); this.text = text; strategy.update(); redraw(); }
/* * (non-Javadoc) * * @see org.eclipse.swt.widgets.Control#computeSize(int, int, boolean) */ public Point computeSize(int arg0, int arg1, boolean arg2) { checkWidget(); if (getExpanded()) return super.computeSize(arg0, arg1, arg2); Rectangle trim = strategy.computeTrim(0, 0, 0, 0); trim.width = super.computeSize(arg0, arg1, arg2).x; return new Point(trim.width, Math.max(trim.height, arg1)); }
/** * Sets the strategy. * * @param strategy the strategy to set * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the strategy is null * </ul> * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ @SuppressWarnings("null") public void setStrategy(AbstractGroupStrategy strategy) { checkWidget(); if (strategy == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); this.strategy = strategy; setForeground(null); strategy.initialize(this); }
/** * Constructs a new instance of this class given its parent and a style value describing its * behavior and appearance. * * <p>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>To ensure that the color of corners is equal to one of the underlying control invoke the * parent composites {@link Composite#setBackgroundMode(int)} with {@link SWT#INHERIT_DEFAULT} or * {@link SWT#INHERIT_DEFAULT} * * @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 * </ul> * * @exception SWTException * <ul> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass * </ul> * * @see SWT * @see Widget#checkSubclass * @see Widget#getStyle */ public PGroup(Composite parent, int style) { super(parent, checkStyle(style)); setStrategy(new RectangleGroupStrategy()); setToggleRenderer(new ChevronsToggleRenderer()); setToolItemRenderer(new SimpleToolItemRenderer()); initialFont = new Font( getDisplay(), getFont().getFontData()[0].getName(), getFont().getFontData()[0].getHeight(), SWT.BOLD); super.setFont(initialFont); strategy.initialize(this); initListeners(); }
private void onPaint(PaintEvent e) { Color back = e.gc.getBackground(); Color fore = e.gc.getForeground(); strategy.paint(e.gc); e.gc.setBackground(back); e.gc.setForeground(fore); if (toggleRenderer != null) { toggleRenderer.setExpanded(expanded); toggleRenderer.setFocus(isFocusControl()); toggleRenderer.setHover(overToggle); toggleRenderer.paint(e.gc, this); } if (toolItemRenderer != null && toolitems.size() > 0) { paintToolItems(e.gc); } }
public void setToolItemRenderer(AbstractToolItemRenderer toolItemRenderer) { checkWidget(); this.toolItemRenderer = toolItemRenderer; strategy.update(); redraw(); }
/** {@inheritDoc} */ public Rectangle getClientArea() { checkWidget(); if (getExpanded()) return strategy.getClientArea(); return new Rectangle(-10, 0, 0, 0); }
/** {@inheritDoc} */ public Rectangle computeTrim(int x, int y, int width, int height) { checkWidget(); return strategy.computeTrim(x, y, width, height); }
/** * Sets the line position. The line position is a combination of integer constants OR'ed together. * Valid values are <code>SWT.BOTTOM</code> and <code>SWT.CENTER</code> (mutually exclusive). * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setLinePosition(int linePosition) { checkWidget(); this.linePosition = linePosition; strategy.update(); redraw(); }
/** * Sets the toggle position. The toggle position is a combination of integer constants OR'ed * together. Valid values are <code>SWT.LEFT</code> and <code>SWT.RIGHT</code> (mutually * exclusive). * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setTogglePosition(int togglePosition) { checkWidget(); this.togglePosition = togglePosition; strategy.update(); redraw(); }
/** * Sets the image position. The image position is a combination of integer constants OR'ed * together. Valid values are <code>SWT.LEFT</code> and <code>SWT.RIGHT</code> (mutually * exclusive). <code>SWT.TOP</code> is hint interpreted by some strategies. * * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the strategy is null * </ul> * * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public void setImagePosition(int imagePosition) { checkWidget(); this.imagePosition = imagePosition; strategy.update(); redraw(); }
private void onDispose() { strategy.dispose(); if (initialFont != null) initialFont.dispose(); }
/* * (non-Javadoc) * * @see org.eclipse.swt.widgets.Control#setFont(org.eclipse.swt.graphics.Font) */ public void setFont(Font font) { checkWidget(); super.setFont(font); strategy.update(); redraw(); }
private void paintToolItems(GC gc) { Rectangle itemArea = strategy.getToolItemArea(); if (itemArea != null) { int spacing = 3; Iterator<PGroupToolItem> it = toolitems.iterator(); AbstractToolItemRenderer toolitemRenderer = getToolItemRenderer(); Point[] sizes = new Point[toolitems.size()]; boolean min = false; int width = 0; int i = 0; while (it.hasNext()) { PGroupToolItem item = (PGroupToolItem) it.next(); Point p = toolitemRenderer.computeSize(gc, item, AbstractToolItemRenderer.DEFAULT); sizes[i++] = p; if (width + spacing + p.x > itemArea.width) { min = true; break; } else { width += p.x + spacing; } } if (min) { toolitemRenderer.setSizeType(AbstractToolItemRenderer.MIN); } else { toolitemRenderer.setSizeType(AbstractToolItemRenderer.DEFAULT); } if (min) { it = toolitems.iterator(); i = 0; while (it.hasNext()) { PGroupToolItem item = (PGroupToolItem) it.next(); sizes[i++] = toolitemRenderer.computeSize(gc, item, AbstractToolItemRenderer.MIN); } } it = toolitems.iterator(); int x = itemArea.x; i = 0; while (it.hasNext()) { PGroupToolItem item = (PGroupToolItem) it.next(); Point p = sizes[i++]; Rectangle rect = new Rectangle(x, itemArea.y, p.x, itemArea.height); item.setBounds(rect); toolitemRenderer.setBounds(rect); x += p.x + spacing; if ((item.getStyle() & SWT.DROP_DOWN) != 0) { item.setDropDownArea(toolitemRenderer.computeDropDownArea(item.getBounds())); } toolitemRenderer.setHover(activeToolItem == item); toolitemRenderer.paint(gc, item); } } }