public Dimension getPreferredSize(JComponent c) { SynthContext context = getContext(c); Dimension dim = null; if (context.getComponent().getName() == "ScrollBar.button") { //... } if (dim == null) { // For all other cases (including Spinner, ComboBox), we will // fall back on the single ArrowButton.size value to create // a square return value int size = context.getStyle().getInt(context, "ArrowButton.size", 16); dim = new Dimension(size, size); } //...
/** * @param context * @param style * @return */ public static SynthContext getContext(SynthContext context, SynthStyle style) { if (context.getStyle().equals(style)) return context; return getContext(context.getComponent(), context.getRegion(), style, context.getComponentState()); } /**
/** * @param context * @param style * @return */ public static SynthContext getContext(SynthContext context, SynthStyle style) { if (context.getStyle().equals(style)) return context; return getContext(context.getComponent(), context.getRegion(), style, context.getComponentState()); } /**
/** * Returns true if the region is opaque. * * <p>Overridden to cause this style to populate itself with data from * UIDefaults, if necessary. If opacity is not specified in UI defaults, * then it defaults to being non-opaque.</p> * * @param ctx context SynthContext identifying requester * * @return true if region is opaque. */ @Override public boolean isOpaque(SynthContext ctx) { // Force Table CellRenderers to be opaque if ("Table.cellRenderer".equals(ctx.getComponent().getName())) { return true; } Boolean opaque = (Boolean) get(ctx, "opaque"); return opaque == null ? false : opaque; }
/** * @param context * @param style * @return */ public static SynthContext getContext(SynthContext context, SynthStyle style) { if (context.getStyle().equals(style)) return context; return getContext(context.getComponent(), context.getRegion(), style, context.getComponentState()); } /**
/** * A convience method that will reset the Style of StyleContext if * necessary. * * @return newStyle */ public static SynthStyle updateSeaglassStyle(SynthContext context, SeaglassUI ui) { SynthStyle newStyle = getStyle(context.getComponent(), context.getRegion()); // TODO rossi 04.07.2011 this code is now private in the Synth L&F // SynthStyle oldStyle = context.getStyle(); // // if (newStyle != oldStyle) { // if (oldStyle != null) { // oldStyle.uninstallDefaults(context); // } // context.setStyle(newStyle); // newStyle.installDefaults(context, ui); // } return newStyle; }
/** * Returns a context with the given component state and all other fields same as input context. * * @param context the context, must not be null * @param state the component state. * @return a context with the given component state and other fields as inpu context. */ public static SynthContext getContext(SynthContext context, int state) { if (context.getComponentState() == state) return context; return getContext(context.getComponent(), context.getRegion(), context.getStyle(), state); }
/** * {@inheritDoc} */ @Override protected Font getFontForState(SynthContext ctx) { Font f = (Font) get(ctx, "font"); if (f == null) f = UIManager.getFont("defaultFont"); // Account for scale // The key "JComponent.sizeVariant" is used to match Apple's LAF String scaleKey = SeaGlassStyle.getSizeVariant(ctx.getComponent()); if (scaleKey != null) { if (LARGE_KEY.equals(scaleKey)) { f = f.deriveFont(Math.round(f.getSize2D() * LARGE_SCALE)); } else if (SMALL_KEY.equals(scaleKey)) { f = f.deriveFont(Math.round(f.getSize2D() * SMALL_SCALE)); } else if (MINI_KEY.equals(scaleKey)) { f = f.deriveFont(Math.round(f.getSize2D() * MINI_SCALE)); } } return f; }
/** * @param context * @param style * @return */ public static SynthContext getContext(SynthContext context, SynthStyle style) { if (context.getStyle().equals(style)) return context; return getContext(context.getComponent(), context.getRegion(), style, context.getComponentState()); } /**
/** * Paints the border of a text field. * * @param context SynthContext identifying the <code>JComponent</code> and * <code>Region</code> to paint to * @param g <code>Graphics</code> to paint to * @param x X coordinate of the area to paint to * @param y Y coordinate of the area to paint to * @param w Width of the area to paint to * @param h Height of the area to paint to */ public void paintTextFieldBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { if (context.getComponent().getComponentOrientation().isLeftToRight()) { paintBorder(context, g, x, y, w, h, null); } else { AffineTransform transform = new AffineTransform(); transform.translate(x, y); transform.scale(-1, 1); transform.translate(-w, 0); paintBorder(context, g, 0, 0, w, h, transform); } }
/** * Returns a context with the given component state and all other fields same as input context. * * @param context the context, must not be null * @param state the component state. * @return a context with the given component state and other fields as inpu context. */ public static SynthContext getContext(SynthContext context, int state) { if (context.getComponentState() == state) return context; return getContext(context.getComponent(), context.getRegion(), context.getStyle(), state); }
/** * Paints the background of a combo box. * * @param context SynthContext identifying the <code>JComponent</code> and * <code>Region</code> to paint to * @param g <code>Graphics</code> to paint to * @param x X coordinate of the area to paint to * @param y Y coordinate of the area to paint to * @param w Width of the area to paint to * @param h Height of the area to paint to */ public void paintComboBoxBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { if (context.getComponent().getComponentOrientation().isLeftToRight()) { paintBackground(context, g, x, y, w, h, null); } else { AffineTransform transform = new AffineTransform(); transform.translate(x, y); transform.scale(-1, 1); transform.translate(-w, 0); paintBackground(context, g, 0, 0, w, h, transform); } }
/** * Returns a context with the given component state and all other fields same as input context. * * @param context the context, must not be null * @param state the component state. * @return a context with the given component state and other fields as inpu context. */ public static SynthContext getContext(SynthContext context, int state) { if (context.getComponentState() == state) return context; return getContext(context.getComponent(), context.getRegion(), context.getStyle(), state); }
/** * Paints the border of a formatted text field. * * @param context SynthContext identifying the <code>JComponent</code> and * <code>Region</code> to paint to * @param g <code>Graphics</code> to paint to * @param x X coordinate of the area to paint to * @param y Y coordinate of the area to paint to * @param w Width of the area to paint to * @param h Height of the area to paint to */ public void paintFormattedTextFieldBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { if (context.getComponent().getComponentOrientation().isLeftToRight()) { paintBorder(context, g, x, y, w, h, null); } else { AffineTransform transform = new AffineTransform(); transform.translate(x, y); transform.scale(-1, 1); transform.translate(-w, 0); paintBorder(context, g, 0, 0, w, h, transform); } }
/** * Returns a context with the given component state and all other fields same as input context. * * @param context the context, must not be null * @param state the component state. * @return a context with the given component state and other fields as inpu context. */ public static SynthContext getContext(SynthContext context, int state) { if (context.getComponentState() == state) return context; return getContext(context.getComponent(), context.getRegion(), context.getStyle(), state); }
/** * Paints the background of a formatted text field. * * @param context SynthContext identifying the <code>JComponent</code> and * <code>Region</code> to paint to * @param g <code>Graphics</code> to paint to * @param x X coordinate of the area to paint to * @param y Y coordinate of the area to paint to * @param w Width of the area to paint to * @param h Height of the area to paint to */ public void paintFormattedTextFieldBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { if (context.getComponent().getComponentOrientation().isLeftToRight()) { paintBackground(context, g, x, y, w, h, null); } else { AffineTransform transform = new AffineTransform(); transform.translate(x, y); transform.scale(-1, 1); transform.translate(-w, 0); paintBackground(context, g, 0, 0, w, h, transform); } }
/** * @see SeaglassUI#paintBorder(javax.swing.plaf.synth.SeaGlassContext, * java.awt.Graphics, int, int, int, int) */ public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { JSeparator separator = (JSeparator) context.getComponent(); ((SeaGlassContext) context).getPainter().paintSeparatorBorder(context, g, x, y, w, h, separator.getOrientation()); }
/** * A convenience method to return where the foreground should be painted for * the Component identified by the passed in AbstractSynthContext. * * @param state the SynthContext representing the current state. * @param insets an Insets object to be filled with the painting insets. * * @return the insets object passed in and filled with the painting insets. */ public static Insets getPaintingInsets(SynthContext state, Insets insets) { if (state.getRegion().isSubregion()) { insets = state.getStyle().getInsets(state, insets); } else { insets = state.getComponent().getInsets(insets); } return insets; }
public static void paint(SynthContext context, SynthContext accContext, Graphics g, Icon checkIcon, Icon arrowIcon, String acceleratorDelimiter, int defaultTextIconGap, String propertyPrefix) { JMenuItem mi = (JMenuItem) context.getComponent(); SynthStyle style = context.getStyle(); g.setFont(style.getFont(context)); Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight()); boolean leftToRight = SeaGlassLookAndFeel.isLeftToRight(mi); applyInsets(viewRect, mi.getInsets(), leftToRight); SeaGlassMenuItemLayoutHelper lh = new SeaGlassMenuItemLayoutHelper(context, accContext, mi, checkIcon, arrowIcon, viewRect, defaultTextIconGap, acceleratorDelimiter, leftToRight, MenuItemLayoutHelper.useCheckAndArrow(mi), propertyPrefix); MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem(); paintMenuItem(g, lh, lr); }
/** * Paints the specified component. * * @param context * context for the component being painted * @param g * the {@code Graphics} object used for painting * @see #update(Graphics,JComponent) */ protected void paint(SynthContext context, Graphics g) { JToolTip tip = (JToolTip) context.getComponent(); Insets insets = tip.getInsets(); View v = (View) tip.getClientProperty(BasicHTML.propertyKey); if (v != null) { Rectangle paintTextR = new Rectangle(insets.left, insets.top, tip.getWidth() - (insets.left + insets.right), tip.getHeight() - (insets.top + insets.bottom)); v.paint(g, paintTextR); } else { g.setColor(context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND)); g.setFont(style.getFont(context)); context.getStyle().getGraphicsUtils(context).paintText(context, g, tip.getTipText(), insets.left, insets.top, -1); } }