code
stringlengths
3
1.18M
language
stringclasses
1 value
/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.plaf.*; import java.io.Serializable; /** {@collect.stats} * Synth's CheckBoxUI. * * @author Jeff Dinkins */ class SynthCheckBoxUI extends SynthRadioButtonUI { // ******************************** // Create PLAF // ******************************** public static ComponentUI createUI(JComponent b) { return new SynthCheckBoxUI(); } protected String getPropertyPrefix() { return "CheckBox."; } void paintBackground(SynthContext context, Graphics g, JComponent c) { context.getPainter().paintCheckBoxBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintCheckBoxBorder(context, g, x, y, w, h); } }
Java
/* * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import sun.swing.SwingUtilities2; import sun.swing.MenuItemLayoutHelper; import java.awt.*; import javax.swing.*; import javax.swing.plaf.basic.BasicHTML; import javax.swing.text.*; import sun.swing.plaf.synth.*; /** {@collect.stats} * Wrapper for primitive graphics calls. * * @since 1.5 * @author Scott Violet */ public class SynthGraphicsUtils { // These are used in the text painting code to avoid allocating a bunch of // garbage. private Rectangle paintIconR = new Rectangle(); private Rectangle paintTextR = new Rectangle(); private Rectangle paintViewR = new Rectangle(); private Insets paintInsets = new Insets(0, 0, 0, 0); // These Rectangles/Insets are used in the text size calculation to avoid a // a bunch of garbage. private Rectangle iconR = new Rectangle(); private Rectangle textR = new Rectangle(); private Rectangle viewR = new Rectangle(); private Insets viewSizingInsets = new Insets(0, 0, 0, 0); /** {@collect.stats} * Creates a <code>SynthGraphicsUtils</code>. */ public SynthGraphicsUtils() { } /** {@collect.stats} * Draws a line between the two end points. * * @param context Identifies hosting region. * @param paintKey Identifies the portion of the component being asked * to paint, may be null. * @param g Graphics object to paint to * @param x1 x origin * @param y1 y origin * @param x2 x destination * @param y2 y destination */ public void drawLine(SynthContext context, Object paintKey, Graphics g, int x1, int y1, int x2, int y2) { g.drawLine(x1, y1, x2, y2); } /** {@collect.stats} * Draws a line between the two end points. * <p>This implementation supports only one line style key, * <code>"dashed"</code>. The <code>"dashed"</code> line style is applied * only to vertical and horizontal lines. * <p>Specifying <code>null</code> or any key different from * <code>"dashed"</code> will draw solid lines. * * @param context identifies hosting region * @param paintKey identifies the portion of the component being asked * to paint, may be null * @param g Graphics object to paint to * @param x1 x origin * @param y1 y origin * @param x2 x destination * @param y2 y destination * @param styleKey identifies the requested style of the line (e.g. "dashed") * @since 1.6 */ public void drawLine(SynthContext context, Object paintKey, Graphics g, int x1, int y1, int x2, int y2, Object styleKey) { if ("dashed".equals(styleKey)) { // draw vertical line if (x1 == x2) { y1 += (y1 % 2); for (int y = y1; y <= y2; y+=2) { g.drawLine(x1, y, x2, y); } // draw horizontal line } else if (y1 == y2) { x1 += (x1 % 2); for (int x = x1; x <= x2; x+=2) { g.drawLine(x, y1, x, y2); } // oblique lines are not supported } } else { drawLine(context, paintKey, g, x1, y1, x2, y2); } } /** {@collect.stats} * Lays out text and an icon returning, by reference, the location to * place the icon and text. * * @param ss SynthContext * @param fm FontMetrics for the Font to use, this may be ignored * @param text Text to layout * @param icon Icon to layout * @param hAlign horizontal alignment * @param vAlign vertical alignment * @param hTextPosition horizontal text position * @param vTextPosition vertical text position * @param viewR Rectangle to layout text and icon in. * @param iconR Rectangle to place icon bounds in * @param textR Rectangle to place text in * @param iconTextGap gap between icon and text */ public String layoutText(SynthContext ss, FontMetrics fm, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR, int iconTextGap) { if (icon instanceof SynthIcon) { SynthIconWrapper wrapper = SynthIconWrapper.get((SynthIcon)icon, ss); String formattedText = SwingUtilities.layoutCompoundLabel( ss.getComponent(), fm, text, wrapper, vAlign, hAlign, vTextPosition, hTextPosition, viewR, iconR, textR, iconTextGap); SynthIconWrapper.release(wrapper); return formattedText; } return SwingUtilities.layoutCompoundLabel( ss.getComponent(), fm, text, icon, vAlign, hAlign, vTextPosition, hTextPosition, viewR, iconR, textR, iconTextGap); } /** {@collect.stats} * Returns the size of the passed in string. * * @param ss SynthContext * @param font Font to use * @param metrics FontMetrics, may be ignored * @param text Text to get size of. */ public int computeStringWidth(SynthContext ss, Font font, FontMetrics metrics, String text) { return SwingUtilities2.stringWidth(ss.getComponent(), metrics, text); } /** {@collect.stats} * Returns the minimum size needed to properly render an icon and text. * * @param ss SynthContext * @param font Font to use * @param text Text to layout * @param icon Icon to layout * @param hAlign horizontal alignment * @param vAlign vertical alignment * @param hTextPosition horizontal text position * @param vTextPosition vertical text position * @param iconTextGap gap between icon and text * @param mnemonicIndex Index into text to render the mnemonic at, -1 * indicates no mnemonic. */ public Dimension getMinimumSize(SynthContext ss, Font font, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex) { JComponent c = ss.getComponent(); Dimension size = getPreferredSize(ss, font, text, icon, hAlign, vAlign, hTextPosition, vTextPosition, iconTextGap, mnemonicIndex); View v = (View) c.getClientProperty(BasicHTML.propertyKey); if (v != null) { size.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS); } return size; } /** {@collect.stats} * Returns the maximum size needed to properly render an icon and text. * * @param ss SynthContext * @param font Font to use * @param text Text to layout * @param icon Icon to layout * @param hAlign horizontal alignment * @param vAlign vertical alignment * @param hTextPosition horizontal text position * @param vTextPosition vertical text position * @param iconTextGap gap between icon and text * @param mnemonicIndex Index into text to render the mnemonic at, -1 * indicates no mnemonic. */ public Dimension getMaximumSize(SynthContext ss, Font font, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex) { JComponent c = ss.getComponent(); Dimension size = getPreferredSize(ss, font, text, icon, hAlign, vAlign, hTextPosition, vTextPosition, iconTextGap, mnemonicIndex); View v = (View) c.getClientProperty(BasicHTML.propertyKey); if (v != null) { size.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS); } return size; } /** {@collect.stats} * Returns the maximum height of the the Font from the passed in * SynthContext. * * @param context SynthContext used to determine font. * @return maximum height of the characters for the font from the passed * in context. */ public int getMaximumCharHeight(SynthContext context) { FontMetrics fm = context.getComponent().getFontMetrics( context.getStyle().getFont(context)); return (fm.getAscent() + fm.getDescent()); } /** {@collect.stats} * Returns the preferred size needed to properly render an icon and text. * * @param ss SynthContext * @param font Font to use * @param text Text to layout * @param icon Icon to layout * @param hAlign horizontal alignment * @param vAlign vertical alignment * @param hTextPosition horizontal text position * @param vTextPosition vertical text position * @param iconTextGap gap between icon and text * @param mnemonicIndex Index into text to render the mnemonic at, -1 * indicates no mnemonic. */ public Dimension getPreferredSize(SynthContext ss, Font font, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex) { JComponent c = ss.getComponent(); Insets insets = c.getInsets(viewSizingInsets); int dx = insets.left + insets.right; int dy = insets.top + insets.bottom; if (icon == null && (text == null || font == null)) { return new Dimension(dx, dy); } else if ((text == null) || ((icon != null) && (font == null))) { return new Dimension(SynthIcon.getIconWidth(icon, ss) + dx, SynthIcon.getIconHeight(icon, ss) + dy); } else { FontMetrics fm = c.getFontMetrics(font); iconR.x = iconR.y = iconR.width = iconR.height = 0; textR.x = textR.y = textR.width = textR.height = 0; viewR.x = dx; viewR.y = dy; viewR.width = viewR.height = Short.MAX_VALUE; layoutText(ss, fm, text, icon, hAlign, vAlign, hTextPosition, vTextPosition, viewR, iconR, textR, iconTextGap); int x1 = Math.min(iconR.x, textR.x); int x2 = Math.max(iconR.x + iconR.width, textR.x + textR.width); int y1 = Math.min(iconR.y, textR.y); int y2 = Math.max(iconR.y + iconR.height, textR.y + textR.height); Dimension rv = new Dimension(x2 - x1, y2 - y1); rv.width += dx; rv.height += dy; return rv; } } /** {@collect.stats} * Paints text at the specified location. This will not attempt to * render the text as html nor will it offset by the insets of the * component. * * @param ss SynthContext * @param g Graphics used to render string in. * @param text Text to render * @param bounds Bounds of the text to be drawn. * @param mnemonicIndex Index to draw string at. */ public void paintText(SynthContext ss, Graphics g, String text, Rectangle bounds, int mnemonicIndex) { paintText(ss, g, text, bounds.x, bounds.y, mnemonicIndex); } /** {@collect.stats} * Paints text at the specified location. This will not attempt to * render the text as html nor will it offset by the insets of the * component. * * @param ss SynthContext * @param g Graphics used to render string in. * @param text Text to render * @param x X location to draw text at. * @param y Upper left corner to draw text at. * @param mnemonicIndex Index to draw string at. */ public void paintText(SynthContext ss, Graphics g, String text, int x, int y, int mnemonicIndex) { if (text != null) { JComponent c = ss.getComponent(); FontMetrics fm = SwingUtilities2.getFontMetrics(c, g); y += fm.getAscent(); SwingUtilities2.drawStringUnderlineCharAt(c, g, text, mnemonicIndex, x, y); } } /** {@collect.stats} * Paints an icon and text. This will render the text as html, if * necessary, and offset the location by the insets of the component. * * @param ss SynthContext * @param g Graphics to render string and icon into * @param text Text to layout * @param icon Icon to layout * @param hAlign horizontal alignment * @param vAlign vertical alignment * @param hTextPosition horizontal text position * @param vTextPosition vertical text position * @param iconTextGap gap between icon and text * @param mnemonicIndex Index into text to render the mnemonic at, -1 * indicates no mnemonic. * @param textOffset Amount to offset the text when painting */ public void paintText(SynthContext ss, Graphics g, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex, int textOffset) { if ((icon == null) && (text == null)) { return; } JComponent c = ss.getComponent(); FontMetrics fm = SwingUtilities2.getFontMetrics(c, g); Insets insets = SynthLookAndFeel.getPaintingInsets(ss, paintInsets); paintViewR.x = insets.left; paintViewR.y = insets.top; paintViewR.width = c.getWidth() - (insets.left + insets.right); paintViewR.height = c.getHeight() - (insets.top + insets.bottom); paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0; paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0; String clippedText = layoutText(ss, fm, text, icon, hAlign, vAlign, hTextPosition, vTextPosition, paintViewR, paintIconR, paintTextR, iconTextGap); if (icon != null) { Color color = g.getColor(); if (ss.getStyle().getBoolean(ss, "TableHeader.alignSorterArrow", false) && "TableHeader.renderer".equals(c.getName())) { paintIconR.x = paintViewR.width - paintIconR.width; } else { paintIconR.x += textOffset; } paintIconR.y += textOffset; SynthIcon.paintIcon(icon, ss, g, paintIconR.x, paintIconR.y, paintIconR.width, paintIconR.height); g.setColor(color); } if (text != null) { View v = (View) c.getClientProperty(BasicHTML.propertyKey); if (v != null) { v.paint(g, paintTextR); } else { paintTextR.x += textOffset; paintTextR.y += textOffset; paintText(ss, g, clippedText, paintTextR, mnemonicIndex); } } } /** {@collect.stats} * A quick note about how preferred sizes are calculated... Generally * speaking, SynthPopupMenuUI will run through the list of its children * (from top to bottom) and ask each for its preferred size. Each menu * item will add up the max width of each element (icons, text, * accelerator spacing, accelerator text or arrow icon) encountered thus * far, so by the time all menu items have been calculated, we will * know the maximum (preferred) menu item size for that popup menu. * Later when it comes time to paint each menu item, we can use those * same accumulated max element sizes in order to layout the item. */ static Dimension getPreferredMenuItemSize(SynthContext context, SynthContext accContext, JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap, String acceleratorDelimiter, boolean useCheckAndArrow, String propertyPrefix) { JMenuItem mi = (JMenuItem) c; SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper( context, accContext, mi, checkIcon, arrowIcon, MenuItemLayoutHelper.createMaxRect(), defaultTextIconGap, acceleratorDelimiter, SynthLookAndFeel.isLeftToRight(mi), useCheckAndArrow, propertyPrefix); Dimension result = new Dimension(); // Calculate the result width int gap = lh.getGap(); result.width = 0; MenuItemLayoutHelper.addMaxWidth(lh.getCheckSize(), gap, result); MenuItemLayoutHelper.addMaxWidth(lh.getLabelSize(), gap, result); MenuItemLayoutHelper.addWidth(lh.getMaxAccOrArrowWidth(), 5 * gap, result); // The last gap is unnecessary result.width -= gap; // Calculate the result height result.height = MenuItemLayoutHelper.max(lh.getCheckSize().getHeight(), lh.getLabelSize().getHeight(), lh.getAccSize().getHeight(), lh.getArrowSize().getHeight()); // Take into account menu item insets Insets insets = lh.getMenuItem().getInsets(); if (insets != null) { result.width += insets.left + insets.right; result.height += insets.top + insets.bottom; } // if the width is even, bump it up one. This is critical // for the focus dash lhne to draw properly if (result.width % 2 == 0) { result.width++; } // if the height is even, bump it up one. This is critical // for the text to center properly if (result.height % 2 == 0) { result.height++; } return result; } static void applyInsets(Rectangle rect, Insets insets, boolean leftToRight) { if (insets != null) { rect.x += (leftToRight ? insets.left : insets.right); rect.y += insets.top; rect.width -= (leftToRight ? insets.right : insets.left) + rect.x; rect.height -= (insets.bottom + rect.y); } } 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 = SynthLookAndFeel.isLeftToRight(mi); applyInsets(viewRect, mi.getInsets(), leftToRight); SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper( context, accContext, mi, checkIcon, arrowIcon, viewRect, defaultTextIconGap, acceleratorDelimiter, leftToRight, MenuItemLayoutHelper.useCheckAndArrow(mi), propertyPrefix); MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem(); paintMenuItem(g, lh, lr); } static void paintMenuItem(Graphics g, SynthMenuItemLayoutHelper lh, MenuItemLayoutHelper.LayoutResult lr) { // Save original graphics font and color Font holdf = g.getFont(); Color holdc = g.getColor(); paintBackground(g, lh); paintCheckIcon(g, lh, lr); paintIcon(g, lh, lr); paintText(g, lh, lr); paintAccText(g, lh, lr); paintArrowIcon(g, lh, lr); // Restore original graphics font and color g.setColor(holdc); g.setFont(holdf); } static void paintBackground(Graphics g, SynthMenuItemLayoutHelper lh) { paintBackground(lh.getContext(), g, lh.getMenuItem()); } static void paintBackground(SynthContext context, Graphics g, JComponent c) { context.getPainter().paintMenuItemBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); } static void paintIcon(Graphics g, SynthMenuItemLayoutHelper lh, MenuItemLayoutHelper.LayoutResult lr) { if (lh.getIcon() != null) { Icon icon; JMenuItem mi = lh.getMenuItem(); ButtonModel model = mi.getModel(); if (!model.isEnabled()) { icon = mi.getDisabledIcon(); } else if (model.isPressed() && model.isArmed()) { icon = mi.getPressedIcon(); if (icon == null) { // Use default icon icon = mi.getIcon(); } } else { icon = mi.getIcon(); } if (icon != null) { Rectangle iconRect = lr.getIconRect(); SynthIcon.paintIcon(icon, lh.getContext(), g, iconRect.x, iconRect.y, iconRect.width, iconRect.height); } } } static void paintCheckIcon(Graphics g, SynthMenuItemLayoutHelper lh, MenuItemLayoutHelper.LayoutResult lr) { if (lh.getCheckIcon() != null) { Rectangle checkRect = lr.getCheckRect(); SynthIcon.paintIcon(lh.getCheckIcon(), lh.getContext(), g, checkRect.x, checkRect.y, checkRect.width, checkRect.height); } } static void paintAccText(Graphics g, SynthMenuItemLayoutHelper lh, MenuItemLayoutHelper.LayoutResult lr) { String accText = lh.getAccText(); if (accText != null && !accText.equals("")) { g.setColor(lh.getAccStyle().getColor(lh.getAccContext(), ColorType.TEXT_FOREGROUND)); g.setFont(lh.getAccStyle().getFont(lh.getAccContext())); lh.getAccGraphicsUtils().paintText(lh.getAccContext(), g, accText, lr.getAccRect().x, lr.getAccRect().y, -1); } } static void paintText(Graphics g, SynthMenuItemLayoutHelper lh, MenuItemLayoutHelper.LayoutResult lr) { if (!lh.getText().equals("")) { if (lh.getHtmlView() != null) { // Text is HTML lh.getHtmlView().paint(g, lr.getTextRect()); } else { // Text isn't HTML g.setColor(lh.getStyle().getColor( lh.getContext(), ColorType.TEXT_FOREGROUND)); g.setFont(lh.getStyle().getFont(lh.getContext())); lh.getGraphicsUtils().paintText(lh.getContext(), g, lh.getText(), lr.getTextRect().x, lr.getTextRect().y, lh.getMenuItem().getDisplayedMnemonicIndex()); } } } static void paintArrowIcon(Graphics g, SynthMenuItemLayoutHelper lh, MenuItemLayoutHelper.LayoutResult lr) { if (lh.getArrowIcon() != null) { Rectangle arrowRect = lr.getArrowRect(); SynthIcon.paintIcon(lh.getArrowIcon(), lh.getContext(), g, arrowRect.x, arrowRect.y, arrowRect.width, arrowRect.height); } } /** {@collect.stats} * Wraps a SynthIcon around the Icon interface, forwarding calls to * the SynthIcon with a given SynthContext. */ private static class SynthIconWrapper implements Icon { private static final java.util.List CACHE = new java.util.ArrayList(1); private SynthIcon synthIcon; private SynthContext context; static SynthIconWrapper get(SynthIcon icon, SynthContext context) { synchronized(CACHE) { int size = CACHE.size(); if (size > 0) { SynthIconWrapper wrapper = (SynthIconWrapper)CACHE.remove( size - 1); wrapper.reset(icon, context); return wrapper; } } return new SynthIconWrapper(icon, context); } static void release(SynthIconWrapper wrapper) { wrapper.reset(null, null); synchronized(CACHE) { CACHE.add(wrapper); } } SynthIconWrapper(SynthIcon icon, SynthContext context) { reset(icon, context); } void reset(SynthIcon icon, SynthContext context) { synthIcon = icon; this.context = context; } public void paintIcon(Component c, Graphics g, int x, int y) { // This is a noop as this should only be for sizing calls. } public int getIconWidth() { return synthIcon.getIconWidth(context); } public int getIconHeight() { return synthIcon.getIconHeight(context); } } }
Java
/* * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.*; import javax.swing.text.*; import javax.swing.event.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.BasicTextFieldUI; import java.awt.*; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.beans.PropertyChangeEvent; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Basis of a look and feel for a JTextField in the Synth * look and feel. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Shannon Hickey */ class SynthTextFieldUI extends BasicTextFieldUI implements SynthUI, FocusListener { private SynthStyle style; /** {@collect.stats} * Creates a UI for a JTextField. * * @param c the text field * @return the UI */ public static ComponentUI createUI(JComponent c) { return new SynthTextFieldUI(); } public SynthTextFieldUI() { super(); } private void updateStyle(JTextComponent comp) { SynthContext context = getContext(comp, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { SynthTextFieldUI.updateStyle(comp, context, getPropertyPrefix()); if (oldStyle != null) { uninstallKeyboardActions(); installKeyboardActions(); } } context.dispose(); } static void updateStyle(JTextComponent comp, SynthContext context, String prefix) { SynthStyle style = context.getStyle(); Color color = comp.getCaretColor(); if (color == null || color instanceof UIResource) { comp.setCaretColor( (Color)style.get(context, prefix + ".caretForeground")); } Color fg = comp.getForeground(); if (fg == null || fg instanceof UIResource) { fg = style.getColorForState(context, ColorType.TEXT_FOREGROUND); if (fg != null) { comp.setForeground(fg); } } Object ar = style.get(context, prefix + ".caretAspectRatio"); if (ar instanceof Number) { comp.putClientProperty("caretAspectRatio", ar); } context.setComponentState(SELECTED | FOCUSED); Color s = comp.getSelectionColor(); if (s == null || s instanceof UIResource) { comp.setSelectionColor( style.getColor(context, ColorType.TEXT_BACKGROUND)); } Color sfg = comp.getSelectedTextColor(); if (sfg == null || sfg instanceof UIResource) { comp.setSelectedTextColor( style.getColor(context, ColorType.TEXT_FOREGROUND)); } context.setComponentState(DISABLED); Color dfg = comp.getDisabledTextColor(); if (dfg == null || dfg instanceof UIResource) { comp.setDisabledTextColor( style.getColor(context, ColorType.TEXT_FOREGROUND)); } Insets margin = comp.getMargin(); if (margin == null || margin instanceof UIResource) { margin = (Insets)style.get(context, prefix + ".margin"); if (margin == null) { // Some places assume margins are non-null. margin = SynthLookAndFeel.EMPTY_UIRESOURCE_INSETS; } comp.setMargin(margin); } Caret caret = comp.getCaret(); if (caret instanceof UIResource) { Object o = style.get(context, prefix + ".caretBlinkRate"); if (o != null && o instanceof Integer) { Integer rate = (Integer)o; caret.setBlinkRate(rate.intValue()); } } } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); paintBackground(context, g, c); paint(context, g); context.dispose(); } /** {@collect.stats} * Paints the interface. This is routed to the * paintSafely method under the guarantee that * the model won't change from the view of this thread * while it's rendering (if the associated model is * derived from AbstractDocument). This enables the * model to potentially be updated asynchronously. */ protected void paint(SynthContext context, Graphics g) { super.paint(g, getComponent()); } void paintBackground(SynthContext context, Graphics g, JComponent c) { context.getPainter().paintTextFieldBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintTextFieldBorder(context, g, x, y, w, h); } protected void paintBackground(Graphics g) { // Overriden to do nothing, all our painting is done from update/paint. } /** {@collect.stats} * This method gets called when a bound property is changed * on the associated JTextComponent. This is a hook * which UI implementations may change to reflect how the * UI displays bound properties of JTextComponent subclasses. * This is implemented to do nothing (i.e. the response to * properties in JTextComponent itself are handled prior * to calling this method). * * @param evt the property change event */ protected void propertyChange(PropertyChangeEvent evt) { if (SynthLookAndFeel.shouldUpdateStyle(evt)) { updateStyle((JTextComponent)evt.getSource()); } super.propertyChange(evt); } public void focusGained(FocusEvent e) { getComponent().repaint(); } public void focusLost(FocusEvent e) { getComponent().repaint(); } protected void installDefaults() { // Installs the text cursor on the component super.installDefaults(); updateStyle((JTextComponent)getComponent()); getComponent().addFocusListener(this); } protected void uninstallDefaults() { SynthContext context = getContext(getComponent(), ENABLED); getComponent().putClientProperty("caretAspectRatio", null); getComponent().removeFocusListener(this); style.uninstallDefaults(context); context.dispose(); style = null; super.uninstallDefaults(); } public void installUI(JComponent c) { super.installUI(c); } }
Java
/* * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.Graphics; import java.util.LinkedList; import sun.swing.plaf.synth.DefaultSynthStyle; /** {@collect.stats} * ParsedSynthStyle are the SynthStyle's that SynthParser creates. * * @author Scott Violet */ class ParsedSynthStyle extends DefaultSynthStyle { private static SynthPainter DELEGATING_PAINTER_INSTANCE = new DelegatingPainter(); private PainterInfo[] _painters; private static PainterInfo[] mergePainterInfo(PainterInfo[] old, PainterInfo[] newPI) { if (old == null) { return newPI; } if (newPI == null) { return old; } int oldLength = old.length; int newLength = newPI.length; int dups = 0; PainterInfo[] merged = new PainterInfo[oldLength + newLength]; System.arraycopy(old, 0, merged, 0, oldLength); for (int newCounter = 0; newCounter < newLength; newCounter++) { boolean found = false; for (int oldCounter = 0; oldCounter < oldLength - dups; oldCounter++) { if (newPI[newCounter].equalsPainter(old[oldCounter])) { merged[oldCounter] = newPI[newCounter]; dups++; found = true; break; } } if (!found) { merged[oldLength + newCounter - dups] = newPI[newCounter]; } } if (dups > 0) { PainterInfo[] tmp = merged; merged = new PainterInfo[merged.length - dups]; System.arraycopy(tmp, 0, merged, 0, merged.length); } return merged; } public ParsedSynthStyle() { } public ParsedSynthStyle(DefaultSynthStyle style) { super(style); if (style instanceof ParsedSynthStyle) { ParsedSynthStyle pStyle = (ParsedSynthStyle)style; if (pStyle._painters != null) { _painters = pStyle._painters; } } } public SynthPainter getPainter(SynthContext ss) { return DELEGATING_PAINTER_INSTANCE; } public void setPainters(PainterInfo[] info) { _painters = info; } public DefaultSynthStyle addTo(DefaultSynthStyle style) { if (!(style instanceof ParsedSynthStyle)) { style = new ParsedSynthStyle(style); } ParsedSynthStyle pStyle = (ParsedSynthStyle)super.addTo(style); pStyle._painters = mergePainterInfo(pStyle._painters, _painters); return pStyle; } private SynthPainter getBestPainter(SynthContext context, String method, int direction) { // Check the state info first StateInfo info = (StateInfo)getStateInfo(context.getComponentState()); SynthPainter painter; if (info != null) { if ((painter = getBestPainter(info.getPainters(), method, direction)) != null) { return painter; } } if ((painter = getBestPainter(_painters, method, direction)) != null) { return painter; } return SynthPainter.NULL_PAINTER; } private SynthPainter getBestPainter(PainterInfo[] info, String method, int direction) { if (info != null) { // Painter specified with no method SynthPainter nullPainter = null; // Painter specified for this method SynthPainter methodPainter = null; for (int counter = info.length - 1; counter >= 0; counter--) { PainterInfo pi = info[counter]; if (pi.getMethod() == method) { if (pi.getDirection() == direction) { return pi.getPainter(); } else if (methodPainter == null &&pi.getDirection() == -1) { methodPainter = pi.getPainter(); } } else if (nullPainter == null && pi.getMethod() == null) { nullPainter = pi.getPainter(); } } if (methodPainter != null) { return methodPainter; } return nullPainter; } return null; } public String toString() { StringBuffer text = new StringBuffer(super.toString()); if (_painters != null) { text.append(",painters=["); for (int i = 0; i < +_painters.length; i++) { text.append(_painters[i].toString()); } text.append("]"); } return text.toString(); } static class StateInfo extends DefaultSynthStyle.StateInfo { private PainterInfo[] _painterInfo; public StateInfo() { } public StateInfo(DefaultSynthStyle.StateInfo info) { super(info); if (info instanceof StateInfo) { _painterInfo = ((StateInfo)info)._painterInfo; } } public void setPainters(PainterInfo[] painterInfo) { _painterInfo = painterInfo; } public PainterInfo[] getPainters() { return _painterInfo; } public Object clone() { return new StateInfo(this); } public DefaultSynthStyle.StateInfo addTo( DefaultSynthStyle.StateInfo info) { if (!(info instanceof StateInfo)) { info = new StateInfo(info); } else { info = super.addTo(info); StateInfo si = (StateInfo)info; si._painterInfo = mergePainterInfo(si._painterInfo, _painterInfo); } return info; } public String toString() { StringBuffer text = new StringBuffer(super.toString()); text.append(",painters=["); if (_painterInfo != null) { for (int i = 0; i < +_painterInfo.length; i++) { text.append(" ").append(_painterInfo[i].toString()); } } text.append("]"); return text.toString(); } } static class PainterInfo { private String _method; private SynthPainter _painter; private int _direction; PainterInfo(String method, SynthPainter painter, int direction) { if (method != null) { _method = method.intern(); } _painter = painter; _direction = direction; } void addPainter(SynthPainter painter) { if (!(_painter instanceof AggregatePainter)) { _painter = new AggregatePainter(_painter); } ((AggregatePainter) _painter).addPainter(painter); } String getMethod() { return _method; } SynthPainter getPainter() { return _painter; } int getDirection() { return _direction; } boolean equalsPainter(PainterInfo info) { return (_method == info._method && _direction == info._direction); } public String toString() { return "PainterInfo {method=" + _method + ",direction=" + _direction + ",painter=" + _painter +"}"; } } private static class AggregatePainter extends SynthPainter { private java.util.List<SynthPainter> painters; AggregatePainter(SynthPainter painter) { painters = new LinkedList<SynthPainter>(); painters.add(painter); } void addPainter(SynthPainter painter) { if (painter != null) { painters.add(painter); } } public void paintArrowButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintArrowButtonBackground(context, g, x, y, w, h); } } public void paintArrowButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintArrowButtonBorder(context, g, x, y, w, h); } } public void paintArrowButtonForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { for (SynthPainter painter: painters) { painter.paintArrowButtonForeground(context, g, x, y, w, h, direction); } } public void paintButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintButtonBackground(context, g, x, y, w, h); } } public void paintButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintButtonBorder(context, g, x, y, w, h); } } public void paintCheckBoxMenuItemBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintCheckBoxMenuItemBackground(context, g, x, y, w, h); } } public void paintCheckBoxMenuItemBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintCheckBoxMenuItemBorder(context, g, x, y, w, h); } } public void paintCheckBoxBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintCheckBoxBackground(context, g, x, y, w, h); } } public void paintCheckBoxBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintCheckBoxBorder(context, g, x, y, w, h); } } public void paintColorChooserBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintColorChooserBackground(context, g, x, y, w, h); } } public void paintColorChooserBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintColorChooserBorder(context, g, x, y, w, h); } } public void paintComboBoxBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintComboBoxBackground(context, g, x, y, w, h); } } public void paintComboBoxBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintComboBoxBorder(context, g, x, y, w, h); } } public void paintDesktopIconBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintDesktopIconBackground(context, g, x, y, w, h); } } public void paintDesktopIconBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintDesktopIconBorder(context, g, x, y, w, h); } } public void paintDesktopPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintDesktopPaneBackground(context, g, x, y, w, h); } } public void paintDesktopPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintDesktopPaneBorder(context, g, x, y, w, h); } } public void paintEditorPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintEditorPaneBackground(context, g, x, y, w, h); } } public void paintEditorPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintEditorPaneBorder(context, g, x, y, w, h); } } public void paintFileChooserBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintFileChooserBackground(context, g, x, y, w, h); } } public void paintFileChooserBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintFileChooserBorder(context, g, x, y, w, h); } } public void paintFormattedTextFieldBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintFormattedTextFieldBackground(context, g, x, y, w, h); } } public void paintFormattedTextFieldBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintFormattedTextFieldBorder(context, g, x, y, w, h); } } public void paintInternalFrameTitlePaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintInternalFrameTitlePaneBackground(context, g, x, y, w, h); } } public void paintInternalFrameTitlePaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintInternalFrameTitlePaneBorder(context, g, x, y, w, h); } } public void paintInternalFrameBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintInternalFrameBackground(context, g, x, y, w, h); } } public void paintInternalFrameBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintInternalFrameBorder(context, g, x, y, w, h); } } public void paintLabelBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintLabelBackground(context, g, x, y, w, h); } } public void paintLabelBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintLabelBorder(context, g, x, y, w, h); } } public void paintListBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintListBackground(context, g, x, y, w, h); } } public void paintListBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintListBorder(context, g, x, y, w, h); } } public void paintMenuBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintMenuBarBackground(context, g, x, y, w, h); } } public void paintMenuBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintMenuBarBorder(context, g, x, y, w, h); } } public void paintMenuItemBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintMenuItemBackground(context, g, x, y, w, h); } } public void paintMenuItemBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintMenuItemBorder(context, g, x, y, w, h); } } public void paintMenuBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintMenuBackground(context, g, x, y, w, h); } } public void paintMenuBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintMenuBorder(context, g, x, y, w, h); } } public void paintOptionPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintOptionPaneBackground(context, g, x, y, w, h); } } public void paintOptionPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintOptionPaneBorder(context, g, x, y, w, h); } } public void paintPanelBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintPanelBackground(context, g, x, y, w, h); } } public void paintPanelBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintPanelBorder(context, g, x, y, w, h); } } public void paintPasswordFieldBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintPasswordFieldBackground(context, g, x, y, w, h); } } public void paintPasswordFieldBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintPasswordFieldBorder(context, g, x, y, w, h); } } public void paintPopupMenuBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintPopupMenuBackground(context, g, x, y, w, h); } } public void paintPopupMenuBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintPopupMenuBorder(context, g, x, y, w, h); } } public void paintProgressBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintProgressBarBackground(context, g, x, y, w, h); } } public void paintProgressBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintProgressBarBackground(context, g, x, y, w, h, orientation); } } public void paintProgressBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintProgressBarBorder(context, g, x, y, w, h); } } public void paintProgressBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintProgressBarBorder(context, g, x, y, w, h, orientation); } } public void paintProgressBarForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintProgressBarForeground(context, g, x, y, w, h, orientation); } } public void paintRadioButtonMenuItemBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintRadioButtonMenuItemBackground(context, g, x, y, w, h); } } public void paintRadioButtonMenuItemBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintRadioButtonMenuItemBorder(context, g, x, y, w, h); } } public void paintRadioButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintRadioButtonBackground(context, g, x, y, w, h); } } public void paintRadioButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintRadioButtonBorder(context, g, x, y, w, h); } } public void paintRootPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintRootPaneBackground(context, g, x, y, w, h); } } public void paintRootPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintRootPaneBorder(context, g, x, y, w, h); } } public void paintScrollBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintScrollBarBackground(context, g, x, y, w, h); } } public void paintScrollBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintScrollBarBackground(context, g, x, y, w, h, orientation); } } public void paintScrollBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintScrollBarBorder(context, g, x, y, w, h); } } public void paintScrollBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintScrollBarBorder(context, g, x, y, w, h, orientation); } } public void paintScrollBarThumbBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintScrollBarThumbBackground(context, g, x, y, w, h, orientation); } } public void paintScrollBarThumbBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintScrollBarThumbBorder(context, g, x, y, w, h, orientation); } } public void paintScrollBarTrackBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintScrollBarTrackBackground(context, g, x, y, w, h); } } public void paintScrollBarTrackBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintScrollBarTrackBackground(context, g, x, y, w, h, orientation); } } public void paintScrollBarTrackBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintScrollBarTrackBorder(context, g, x, y, w, h); } } public void paintScrollBarTrackBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintScrollBarTrackBorder(context, g, x, y, w, h, orientation); } } public void paintScrollPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintScrollPaneBackground(context, g, x, y, w, h); } } public void paintScrollPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintScrollPaneBorder(context, g, x, y, w, h); } } public void paintSeparatorBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintSeparatorBackground(context, g, x, y, w, h); } } public void paintSeparatorBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintSeparatorBackground(context, g, x, y, w, h, orientation); } } public void paintSeparatorBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintSeparatorBorder(context, g, x, y, w, h); } } public void paintSeparatorBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintSeparatorBorder(context, g, x, y, w, h, orientation); } } public void paintSeparatorForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintSeparatorForeground(context, g, x, y, w, h, orientation); } } public void paintSliderBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintSliderBackground(context, g, x, y, w, h); } } public void paintSliderBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintSliderBackground(context, g, x, y, w, h, orientation); } } public void paintSliderBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintSliderBorder(context, g, x, y, w, h); } } public void paintSliderBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintSliderBorder(context, g, x, y, w, h, orientation); } } public void paintSliderThumbBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintSliderThumbBackground(context, g, x, y, w, h, orientation); } } public void paintSliderThumbBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintSliderThumbBorder(context, g, x, y, w, h, orientation); } } public void paintSliderTrackBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintSliderTrackBackground(context, g, x, y, w, h); } } public void paintSliderTrackBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintSliderTrackBackground(context, g, x, y, w, h, orientation); } } public void paintSliderTrackBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintSliderTrackBorder(context, g, x, y, w, h); } } public void paintSliderTrackBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintSliderTrackBorder(context, g, x, y, w, h, orientation); } } public void paintSpinnerBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintSpinnerBackground(context, g, x, y, w, h); } } public void paintSpinnerBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintSpinnerBorder(context, g, x, y, w, h); } } public void paintSplitPaneDividerBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintSplitPaneDividerBackground(context, g, x, y, w, h); } } public void paintSplitPaneDividerBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintSplitPaneDividerBackground(context, g, x, y, w, h, orientation); } } public void paintSplitPaneDividerForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintSplitPaneDividerForeground(context, g, x, y, w, h, orientation); } } public void paintSplitPaneDragDivider(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintSplitPaneDragDivider(context, g, x, y, w, h, orientation); } } public void paintSplitPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintSplitPaneBackground(context, g, x, y, w, h); } } public void paintSplitPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintSplitPaneBorder(context, g, x, y, w, h); } } public void paintTabbedPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTabbedPaneBackground(context, g, x, y, w, h); } } public void paintTabbedPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTabbedPaneBorder(context, g, x, y, w, h); } } public void paintTabbedPaneTabAreaBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTabbedPaneTabAreaBackground(context, g, x, y, w, h); } } public void paintTabbedPaneTabAreaBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintTabbedPaneTabAreaBackground(context, g, x, y, w, h, orientation); } } public void paintTabbedPaneTabAreaBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTabbedPaneTabAreaBorder(context, g, x, y, w, h); } } public void paintTabbedPaneTabAreaBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintTabbedPaneTabAreaBorder(context, g, x, y, w, h, orientation); } } public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex) { for (SynthPainter painter: painters) { painter.paintTabbedPaneTabBackground(context, g, x, y, w, h, tabIndex); } } public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex, int orientation) { for (SynthPainter painter: painters) { painter.paintTabbedPaneTabBackground(context, g, x, y, w, h, tabIndex, orientation); } } public void paintTabbedPaneTabBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex) { for (SynthPainter painter: painters) { painter.paintTabbedPaneTabBorder(context, g, x, y, w, h, tabIndex); } } public void paintTabbedPaneTabBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex, int orientation) { for (SynthPainter painter: painters) { painter.paintTabbedPaneTabBorder(context, g, x, y, w, h, tabIndex, orientation); } } public void paintTabbedPaneContentBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTabbedPaneContentBackground(context, g, x, y, w, h); } } public void paintTabbedPaneContentBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTabbedPaneContentBorder(context, g, x, y, w, h); } } public void paintTableHeaderBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTableHeaderBackground(context, g, x, y, w, h); } } public void paintTableHeaderBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTableHeaderBorder(context, g, x, y, w, h); } } public void paintTableBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTableBackground(context, g, x, y, w, h); } } public void paintTableBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTableBorder(context, g, x, y, w, h); } } public void paintTextAreaBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTextAreaBackground(context, g, x, y, w, h); } } public void paintTextAreaBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTextAreaBorder(context, g, x, y, w, h); } } public void paintTextPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTextPaneBackground(context, g, x, y, w, h); } } public void paintTextPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTextPaneBorder(context, g, x, y, w, h); } } public void paintTextFieldBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTextFieldBackground(context, g, x, y, w, h); } } public void paintTextFieldBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTextFieldBorder(context, g, x, y, w, h); } } public void paintToggleButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintToggleButtonBackground(context, g, x, y, w, h); } } public void paintToggleButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintToggleButtonBorder(context, g, x, y, w, h); } } public void paintToolBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintToolBarBackground(context, g, x, y, w, h); } } public void paintToolBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintToolBarBackground(context, g, x, y, w, h, orientation); } } public void paintToolBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintToolBarBorder(context, g, x, y, w, h); } } public void paintToolBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintToolBarBorder(context, g, x, y, w, h, orientation); } } public void paintToolBarContentBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintToolBarContentBackground(context, g, x, y, w, h); } } public void paintToolBarContentBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintToolBarContentBackground(context, g, x, y, w, h, orientation); } } public void paintToolBarContentBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintToolBarContentBorder(context, g, x, y, w, h); } } public void paintToolBarContentBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintToolBarContentBorder(context, g, x, y, w, h, orientation); } } public void paintToolBarDragWindowBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintToolBarDragWindowBackground(context, g, x, y, w, h); } } public void paintToolBarDragWindowBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintToolBarDragWindowBackground(context, g, x, y, w, h, orientation); } } public void paintToolBarDragWindowBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintToolBarDragWindowBorder(context, g, x, y, w, h); } } public void paintToolBarDragWindowBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { for (SynthPainter painter: painters) { painter.paintToolBarDragWindowBorder(context, g, x, y, w, h, orientation); } } public void paintToolTipBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintToolTipBackground(context, g, x, y, w, h); } } public void paintToolTipBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintToolTipBorder(context, g, x, y, w, h); } } public void paintTreeBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTreeBackground(context, g, x, y, w, h); } } public void paintTreeBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTreeBorder(context, g, x, y, w, h); } } public void paintTreeCellBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTreeCellBackground(context, g, x, y, w, h); } } public void paintTreeCellBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTreeCellBorder(context, g, x, y, w, h); } } public void paintTreeCellFocus(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintTreeCellFocus(context, g, x, y, w, h); } } public void paintViewportBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintViewportBackground(context, g, x, y, w, h); } } public void paintViewportBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { for (SynthPainter painter: painters) { painter.paintViewportBorder(context, g, x, y, w, h); } } } private static class DelegatingPainter extends SynthPainter { private static SynthPainter getPainter(SynthContext context, String method, int direction) { return ((ParsedSynthStyle)context.getStyle()).getBestPainter( context, method, direction); } public void paintArrowButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "arrowbuttonbackground", -1). paintArrowButtonBackground(context, g, x, y, w, h); } public void paintArrowButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "arrowbuttonborder", -1). paintArrowButtonBorder(context, g, x, y, w, h); } public void paintArrowButtonForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "arrowbuttonforeground", direction). paintArrowButtonForeground(context, g, x, y, w, h, direction); } public void paintButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "buttonbackground", -1). paintButtonBackground(context, g, x, y, w, h); } public void paintButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "buttonborder", -1). paintButtonBorder(context, g, x, y, w, h); } public void paintCheckBoxMenuItemBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "checkboxmenuitembackground", -1). paintCheckBoxMenuItemBackground(context, g, x, y, w, h); } public void paintCheckBoxMenuItemBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "checkboxmenuitemborder", -1). paintCheckBoxMenuItemBorder(context, g, x, y, w, h); } public void paintCheckBoxBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "checkboxbackground", -1). paintCheckBoxBackground(context, g, x, y, w, h); } public void paintCheckBoxBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "checkboxborder", -1). paintCheckBoxBorder(context, g, x, y, w, h); } public void paintColorChooserBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "colorchooserbackground", -1). paintColorChooserBackground(context, g, x, y, w, h); } public void paintColorChooserBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "colorchooserborder", -1). paintColorChooserBorder(context, g, x, y, w, h); } public void paintComboBoxBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "comboboxbackground", -1). paintComboBoxBackground(context, g, x, y, w, h); } public void paintComboBoxBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "comboboxborder", -1). paintComboBoxBorder(context, g, x, y, w, h); } public void paintDesktopIconBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "desktopiconbackground", -1). paintDesktopIconBackground(context, g, x, y, w, h); } public void paintDesktopIconBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "desktopiconborder", -1). paintDesktopIconBorder(context, g, x, y, w, h); } public void paintDesktopPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "desktoppanebackground", -1). paintDesktopPaneBackground(context, g, x, y, w, h); } public void paintDesktopPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "desktoppaneborder", -1). paintDesktopPaneBorder(context, g, x, y, w, h); } public void paintEditorPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "editorpanebackground", -1). paintEditorPaneBackground(context, g, x, y, w, h); } public void paintEditorPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "editorpaneborder", -1). paintEditorPaneBorder(context, g, x, y, w, h); } public void paintFileChooserBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "filechooserbackground", -1). paintFileChooserBackground(context, g, x, y, w, h); } public void paintFileChooserBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "filechooserborder", -1). paintFileChooserBorder(context, g, x, y, w, h); } public void paintFormattedTextFieldBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "formattedtextfieldbackground", -1). paintFormattedTextFieldBackground(context, g, x, y, w, h); } public void paintFormattedTextFieldBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "formattedtextfieldborder", -1). paintFormattedTextFieldBorder(context, g, x, y, w, h); } public void paintInternalFrameTitlePaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "internalframetitlepanebackground", -1). paintInternalFrameTitlePaneBackground(context, g, x, y, w, h); } public void paintInternalFrameTitlePaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "internalframetitlepaneborder", -1). paintInternalFrameTitlePaneBorder(context, g, x, y, w, h); } public void paintInternalFrameBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "internalframebackground", -1). paintInternalFrameBackground(context, g, x, y, w, h); } public void paintInternalFrameBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "internalframeborder", -1). paintInternalFrameBorder(context, g, x, y, w, h); } public void paintLabelBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "labelbackground", -1). paintLabelBackground(context, g, x, y, w, h); } public void paintLabelBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "labelborder", -1). paintLabelBorder(context, g, x, y, w, h); } public void paintListBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "listbackground", -1). paintListBackground(context, g, x, y, w, h); } public void paintListBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "listborder", -1). paintListBorder(context, g, x, y, w, h); } public void paintMenuBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "menubarbackground", -1). paintMenuBarBackground(context, g, x, y, w, h); } public void paintMenuBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "menubarborder", -1). paintMenuBarBorder(context, g, x, y, w, h); } public void paintMenuItemBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "menuitembackground", -1). paintMenuItemBackground(context, g, x, y, w, h); } public void paintMenuItemBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "menuitemborder", -1). paintMenuItemBorder(context, g, x, y, w, h); } public void paintMenuBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "menubackground", -1). paintMenuBackground(context, g, x, y, w, h); } public void paintMenuBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "menuborder", -1). paintMenuBorder(context, g, x, y, w, h); } public void paintOptionPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "optionpanebackground", -1). paintOptionPaneBackground(context, g, x, y, w, h); } public void paintOptionPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "optionpaneborder", -1). paintOptionPaneBorder(context, g, x, y, w, h); } public void paintPanelBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "panelbackground", -1). paintPanelBackground(context, g, x, y, w, h); } public void paintPanelBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "panelborder", -1). paintPanelBorder(context, g, x, y, w, h); } public void paintPasswordFieldBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "passwordfieldbackground", -1). paintPasswordFieldBackground(context, g, x, y, w, h); } public void paintPasswordFieldBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "passwordfieldborder", -1). paintPasswordFieldBorder(context, g, x, y, w, h); } public void paintPopupMenuBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "popupmenubackground", -1). paintPopupMenuBackground(context, g, x, y, w, h); } public void paintPopupMenuBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "popupmenuborder", -1). paintPopupMenuBorder(context, g, x, y, w, h); } public void paintProgressBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "progressbarbackground", -1). paintProgressBarBackground(context, g, x, y, w, h); } public void paintProgressBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "progressbarbackground", direction). paintProgressBarBackground(context, g, x, y, w, h, direction); } public void paintProgressBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "progressbarborder", -1). paintProgressBarBorder(context, g, x, y, w, h); } public void paintProgressBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "progressbarborder", direction). paintProgressBarBorder(context, g, x, y, w, h, direction); } public void paintProgressBarForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "progressbarforeground", direction). paintProgressBarForeground(context, g, x, y, w, h, direction); } public void paintRadioButtonMenuItemBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "radiobuttonmenuitembackground", -1). paintRadioButtonMenuItemBackground(context, g, x, y, w, h); } public void paintRadioButtonMenuItemBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "radiobuttonmenuitemborder", -1). paintRadioButtonMenuItemBorder(context, g, x, y, w, h); } public void paintRadioButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "radiobuttonbackground", -1). paintRadioButtonBackground(context, g, x, y, w, h); } public void paintRadioButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "radiobuttonborder", -1). paintRadioButtonBorder(context, g, x, y, w, h); } public void paintRootPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "rootpanebackground", -1). paintRootPaneBackground(context, g, x, y, w, h); } public void paintRootPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "rootpaneborder", -1). paintRootPaneBorder(context, g, x, y, w, h); } public void paintScrollBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "scrollbarbackground", -1). paintScrollBarBackground(context, g, x, y, w, h); } public void paintScrollBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "scrollbarbackground", direction). paintScrollBarBackground(context, g, x, y, w, h, direction); } public void paintScrollBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "scrollbarborder", -1). paintScrollBarBorder(context, g, x, y, w, h); } public void paintScrollBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { getPainter(context, "scrollbarborder", orientation). paintScrollBarBorder(context, g, x, y, w, h, orientation); } public void paintScrollBarThumbBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "scrollbarthumbbackground", direction). paintScrollBarThumbBackground(context, g, x, y, w, h, direction); } public void paintScrollBarThumbBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "scrollbarthumbborder", direction). paintScrollBarThumbBorder(context, g, x, y, w, h, direction); } public void paintScrollBarTrackBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "scrollbartrackbackground", -1). paintScrollBarTrackBackground(context, g, x, y, w, h); } public void paintScrollBarTrackBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "scrollbartrackbackground", direction). paintScrollBarTrackBackground(context, g, x, y, w, h, direction); } public void paintScrollBarTrackBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "scrollbartrackborder", -1). paintScrollBarTrackBorder(context, g, x, y, w, h); } public void paintScrollBarTrackBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { getPainter(context, "scrollbartrackborder", orientation). paintScrollBarTrackBorder(context, g, x, y, w, h, orientation); } public void paintScrollPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "scrollpanebackground", -1). paintScrollPaneBackground(context, g, x, y, w, h); } public void paintScrollPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "scrollpaneborder", -1). paintScrollPaneBorder(context, g, x, y, w, h); } public void paintSeparatorBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "separatorbackground", -1). paintSeparatorBackground(context, g, x, y, w, h); } public void paintSeparatorBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { getPainter(context, "separatorbackground", orientation). paintSeparatorBackground(context, g, x, y, w, h, orientation); } public void paintSeparatorBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "separatorborder", -1). paintSeparatorBorder(context, g, x, y, w, h); } public void paintSeparatorBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { getPainter(context, "separatorborder", orientation). paintSeparatorBorder(context, g, x, y, w, h, orientation); } public void paintSeparatorForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "separatorforeground", direction). paintSeparatorForeground(context, g, x, y, w, h, direction); } public void paintSliderBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "sliderbackground", -1). paintSliderBackground(context, g, x, y, w, h); } public void paintSliderBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "sliderbackground", direction). paintSliderBackground(context, g, x, y, w, h, direction); } public void paintSliderBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "sliderborder", -1). paintSliderBorder(context, g, x, y, w, h); } public void paintSliderBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "sliderborder", direction). paintSliderBorder(context, g, x, y, w, h, direction); } public void paintSliderThumbBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "sliderthumbbackground", direction). paintSliderThumbBackground(context, g, x, y, w, h, direction); } public void paintSliderThumbBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "sliderthumbborder", direction). paintSliderThumbBorder(context, g, x, y, w, h, direction); } public void paintSliderTrackBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "slidertrackbackground", -1). paintSliderTrackBackground(context, g, x, y, w, h); } public void paintSliderTrackBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "slidertrackbackground", direction). paintSliderTrackBackground(context, g, x, y, w, h, direction); } public void paintSliderTrackBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "slidertrackborder", -1). paintSliderTrackBorder(context, g, x, y, w, h); } public void paintSliderTrackBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "slidertrackborder", direction). paintSliderTrackBorder(context, g, x, y, w, h, direction); } public void paintSpinnerBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "spinnerbackground", -1). paintSpinnerBackground(context, g, x, y, w, h); } public void paintSpinnerBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "spinnerborder", -1). paintSpinnerBorder(context, g, x, y, w, h); } public void paintSplitPaneDividerBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "splitpanedividerbackground", -1). paintSplitPaneDividerBackground(context, g, x, y, w, h); } public void paintSplitPaneDividerBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { getPainter(context, "splitpanedividerbackground", orientation). paintSplitPaneDividerBackground(context, g, x, y, w, h, orientation); } public void paintSplitPaneDividerForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "splitpanedividerforeground", direction). paintSplitPaneDividerForeground(context, g, x, y, w, h, direction); } public void paintSplitPaneDragDivider(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "splitpanedragdivider", direction). paintSplitPaneDragDivider(context, g, x, y, w, h, direction); } public void paintSplitPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "splitpanebackground", -1). paintSplitPaneBackground(context, g, x, y, w, h); } public void paintSplitPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "splitpaneborder", -1). paintSplitPaneBorder(context, g, x, y, w, h); } public void paintTabbedPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "tabbedpanebackground", -1). paintTabbedPaneBackground(context, g, x, y, w, h); } public void paintTabbedPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "tabbedpaneborder", -1). paintTabbedPaneBorder(context, g, x, y, w, h); } public void paintTabbedPaneTabAreaBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "tabbedpanetabareabackground", -1). paintTabbedPaneTabAreaBackground(context, g, x, y, w, h); } public void paintTabbedPaneTabAreaBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { getPainter(context, "tabbedpanetabareabackground", orientation). paintTabbedPaneTabAreaBackground(context, g, x, y, w, h, orientation); } public void paintTabbedPaneTabAreaBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "tabbedpanetabareaborder", -1). paintTabbedPaneTabAreaBorder(context, g, x, y, w, h); } public void paintTabbedPaneTabAreaBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { getPainter(context, "tabbedpanetabareaborder", orientation). paintTabbedPaneTabAreaBorder(context, g, x, y, w, h, orientation); } public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "tabbedpanetabbackground", -1). paintTabbedPaneTabBackground(context, g, x, y, w, h, direction); } public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex, int direction) { getPainter(context, "tabbedpanetabbackground", direction). paintTabbedPaneTabBackground(context, g, x, y, w, h, tabIndex, direction); } public void paintTabbedPaneTabBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { getPainter(context, "tabbedpanetabborder", -1). paintTabbedPaneTabBorder(context, g, x, y, w, h, direction); } public void paintTabbedPaneTabBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex, int direction) { getPainter(context, "tabbedpanetabborder", direction). paintTabbedPaneTabBorder(context, g, x, y, w, h, tabIndex, direction); } public void paintTabbedPaneContentBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "tabbedpanecontentbackground", -1). paintTabbedPaneContentBackground(context, g, x, y, w, h); } public void paintTabbedPaneContentBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "tabbedpanecontentborder", -1). paintTabbedPaneContentBorder(context, g, x, y, w, h); } public void paintTableHeaderBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "tableheaderbackground", -1). paintTableHeaderBackground(context, g, x, y, w, h); } public void paintTableHeaderBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "tableheaderborder", -1). paintTableHeaderBorder(context, g, x, y, w, h); } public void paintTableBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "tablebackground", -1). paintTableBackground(context, g, x, y, w, h); } public void paintTableBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "tableborder", -1). paintTableBorder(context, g, x, y, w, h); } public void paintTextAreaBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "textareabackground", -1). paintTextAreaBackground(context, g, x, y, w, h); } public void paintTextAreaBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "textareaborder", -1). paintTextAreaBorder(context, g, x, y, w, h); } public void paintTextPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "textpanebackground", -1). paintTextPaneBackground(context, g, x, y, w, h); } public void paintTextPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "textpaneborder", -1). paintTextPaneBorder(context, g, x, y, w, h); } public void paintTextFieldBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "textfieldbackground", -1). paintTextFieldBackground(context, g, x, y, w, h); } public void paintTextFieldBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "textfieldborder", -1). paintTextFieldBorder(context, g, x, y, w, h); } public void paintToggleButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "togglebuttonbackground", -1). paintToggleButtonBackground(context, g, x, y, w, h); } public void paintToggleButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "togglebuttonborder", -1). paintToggleButtonBorder(context, g, x, y, w, h); } public void paintToolBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "toolbarbackground", -1). paintToolBarBackground(context, g, x, y, w, h); } public void paintToolBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { getPainter(context, "toolbarbackground", orientation). paintToolBarBackground(context, g, x, y, w, h, orientation); } public void paintToolBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "toolbarborder", -1). paintToolBarBorder(context, g, x, y, w, h); } public void paintToolBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { getPainter(context, "toolbarborder", orientation). paintToolBarBorder(context, g, x, y, w, h, orientation); } public void paintToolBarContentBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "toolbarcontentbackground", -1). paintToolBarContentBackground(context, g, x, y, w, h); } public void paintToolBarContentBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { getPainter(context, "toolbarcontentbackground", orientation). paintToolBarContentBackground(context, g, x, y, w, h, orientation); } public void paintToolBarContentBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "toolbarcontentborder", -1). paintToolBarContentBorder(context, g, x, y, w, h); } public void paintToolBarContentBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { getPainter(context, "toolbarcontentborder", orientation). paintToolBarContentBorder(context, g, x, y, w, h, orientation); } public void paintToolBarDragWindowBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "toolbardragwindowbackground", -1). paintToolBarDragWindowBackground(context, g, x, y, w, h); } public void paintToolBarDragWindowBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { getPainter(context, "toolbardragwindowbackground", orientation). paintToolBarDragWindowBackground(context, g, x, y, w, h, orientation); } public void paintToolBarDragWindowBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "toolbardragwindowborder", -1). paintToolBarDragWindowBorder(context, g, x, y, w, h); } public void paintToolBarDragWindowBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { getPainter(context, "toolbardragwindowborder", orientation). paintToolBarDragWindowBorder(context, g, x, y, w, h, orientation); } public void paintToolTipBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "tooltipbackground", -1). paintToolTipBackground(context, g, x, y, w, h); } public void paintToolTipBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "tooltipborder", -1). paintToolTipBorder(context, g, x, y, w, h); } public void paintTreeBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "treebackground", -1). paintTreeBackground(context, g, x, y, w, h); } public void paintTreeBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "treeborder", -1). paintTreeBorder(context, g, x, y, w, h); } public void paintTreeCellBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "treecellbackground", -1). paintTreeCellBackground(context, g, x, y, w, h); } public void paintTreeCellBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "treecellborder", -1). paintTreeCellBorder(context, g, x, y, w, h); } public void paintTreeCellFocus(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "treecellfocus", -1). paintTreeCellFocus(context, g, x, y, w, h); } public void paintViewportBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "viewportbackground", -1). paintViewportBackground(context, g, x, y, w, h); } public void paintViewportBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { getPainter(context, "viewportborder", -1). paintViewportBorder(context, g, x, y, w, h); } } }
Java
/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import java.beans.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import sun.swing.DefaultLookup; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Synth's OptionPaneUI. * * @author James Gosling * @author Scott Violet * @author Amy Fowler */ class SynthOptionPaneUI extends BasicOptionPaneUI implements PropertyChangeListener, SynthUI { private SynthStyle style; /** {@collect.stats} * Creates a new BasicOptionPaneUI instance. */ public static ComponentUI createUI(JComponent x) { return new SynthOptionPaneUI(); } protected void installDefaults() { updateStyle(optionPane); } protected void installListeners() { super.installListeners(); optionPane.addPropertyChangeListener(this); } private void updateStyle(JComponent c) { SynthContext context = getContext(c, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { minimumSize = (Dimension)style.get(context, "OptionPane.minimumSize"); if (minimumSize == null) { minimumSize = new Dimension(262, 90); } if (oldStyle != null) { uninstallKeyboardActions(); installKeyboardActions(); } } context.dispose(); } protected void uninstallDefaults() { SynthContext context = getContext(optionPane, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; } protected void uninstallListeners() { super.uninstallListeners(); optionPane.removePropertyChangeListener(this); } protected void installComponents() { optionPane.add(createMessageArea()); Container separator = createSeparator(); if (separator != null) { optionPane.add(separator); SynthContext context = getContext(optionPane, ENABLED); optionPane.add(Box.createVerticalStrut(context.getStyle(). getInt(context, "OptionPane.separatorPadding", 6))); context.dispose(); } optionPane.add(createButtonArea()); optionPane.applyComponentOrientation(optionPane.getComponentOrientation()); } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintOptionPaneBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintOptionPaneBorder(context, g, x, y, w, h); } public void propertyChange(PropertyChangeEvent e) { if (SynthLookAndFeel.shouldUpdateStyle(e)) { updateStyle((JOptionPane)e.getSource()); } } protected boolean getSizeButtonsToSameWidth() { return DefaultLookup.getBoolean(optionPane, this, "OptionPane.sameSizeButtons", true); } /** {@collect.stats} * Messaged from installComponents to create a Container containing the * body of the message. The icon is the created by calling * <code>addIcon</code>. */ protected Container createMessageArea() { JPanel top = new JPanel(); top.setName("OptionPane.messageArea"); top.setLayout(new BorderLayout()); /* Fill the body. */ Container body = new JPanel(new GridBagLayout()); Container realBody = new JPanel(new BorderLayout()); body.setName("OptionPane.body"); realBody.setName("OptionPane.realBody"); if (getIcon() != null) { JPanel sep = new JPanel(); sep.setName("OptionPane.separator"); sep.setPreferredSize(new Dimension(15, 1)); realBody.add(sep, BorderLayout.BEFORE_LINE_BEGINS); } realBody.add(body, BorderLayout.CENTER); GridBagConstraints cons = new GridBagConstraints(); cons.gridx = cons.gridy = 0; cons.gridwidth = GridBagConstraints.REMAINDER; cons.gridheight = 1; SynthContext context = getContext(optionPane, ENABLED); cons.anchor = context.getStyle().getInt(context, "OptionPane.messageAnchor", GridBagConstraints.CENTER); context.dispose(); cons.insets = new Insets(0,0,3,0); addMessageComponents(body, cons, getMessage(), getMaxCharactersPerLineCount(), false); top.add(realBody, BorderLayout.CENTER); addIcon(top); return top; } protected Container createSeparator() { JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL); separator.setName("OptionPane.separator"); return separator; } }
Java
/* * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.plaf.basic.BasicHTML; import java.awt.*; import java.awt.event.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import javax.swing.text.View; import sun.swing.plaf.synth.*; import sun.swing.MenuItemLayoutHelper; /** {@collect.stats} * Synth's MenuItemUI. * * @author Georges Saab * @author David Karlton * @author Arnaud Weber * @author Fredrik Lagerblad */ class SynthMenuItemUI extends BasicMenuItemUI implements PropertyChangeListener, SynthUI { private SynthStyle style; private SynthStyle accStyle; private String acceleratorDelimiter; public static ComponentUI createUI(JComponent c) { return new SynthMenuItemUI(); } public void uninstallUI(JComponent c) { super.uninstallUI(c); // Remove values from the parent's Client Properties. JComponent p = MenuItemLayoutHelper.getMenuItemParent((JMenuItem) c); if (p != null) { p.putClientProperty( SynthMenuItemLayoutHelper.MAX_ACC_OR_ARROW_WIDTH, null); } } protected void installDefaults() { updateStyle(menuItem); } protected void installListeners() { super.installListeners(); menuItem.addPropertyChangeListener(this); } private void updateStyle(JMenuItem mi) { SynthContext context = getContext(mi, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (oldStyle != style) { String prefix = getPropertyPrefix(); Object value = style.get(context, prefix + ".textIconGap"); if (value != null) { LookAndFeel.installProperty(mi, "iconTextGap", value); } defaultTextIconGap = mi.getIconTextGap(); if (menuItem.getMargin() == null || (menuItem.getMargin() instanceof UIResource)) { Insets insets = (Insets)style.get(context, prefix + ".margin"); if (insets == null) { // Some places assume margins are non-null. insets = SynthLookAndFeel.EMPTY_UIRESOURCE_INSETS; } menuItem.setMargin(insets); } acceleratorDelimiter = style.getString(context, prefix + ".acceleratorDelimiter", "+"); arrowIcon = style.getIcon(context, prefix + ".arrowIcon"); checkIcon = style.getIcon(context, prefix + ".checkIcon"); if (oldStyle != null) { uninstallKeyboardActions(); installKeyboardActions(); } } context.dispose(); SynthContext accContext = getContext(mi, Region.MENU_ITEM_ACCELERATOR, ENABLED); accStyle = SynthLookAndFeel.updateStyle(accContext, this); accContext.dispose(); } protected void uninstallDefaults() { SynthContext context = getContext(menuItem, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; SynthContext accContext = getContext(menuItem, Region.MENU_ITEM_ACCELERATOR, ENABLED); accStyle.uninstallDefaults(accContext); accContext.dispose(); accStyle = null; super.uninstallDefaults(); } protected void uninstallListeners() { super.uninstallListeners(); menuItem.removePropertyChangeListener(this); } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } public SynthContext getContext(JComponent c, Region region) { return getContext(c, region, getComponentState(c, region)); } private SynthContext getContext(JComponent c, Region region, int state) { return SynthContext.getContext(SynthContext.class, c, region, accStyle, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { int state; if (!c.isEnabled()) { state = DISABLED; } else if (menuItem.isArmed()) { state = MOUSE_OVER; } else { state = SynthLookAndFeel.getComponentState(c); } if (menuItem.isSelected()) { state |= SELECTED; } return state; } private int getComponentState(JComponent c, Region region) { return getComponentState(c); } protected Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap) { SynthContext context = getContext(c); SynthContext accContext = getContext(c, Region.MENU_ITEM_ACCELERATOR); Dimension value = SynthGraphicsUtils.getPreferredMenuItemSize( context, accContext, c, checkIcon, arrowIcon, defaultTextIconGap, acceleratorDelimiter, MenuItemLayoutHelper.useCheckAndArrow(menuItem), getPropertyPrefix()); context.dispose(); accContext.dispose(); return value; } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); paintBackground(context, g, c); paint(context, g); context.dispose(); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { SynthContext accContext = getContext(menuItem, Region.MENU_ITEM_ACCELERATOR); // Refetch the appropriate check indicator for the current state String prefix = getPropertyPrefix(); Icon checkIcon = style.getIcon(context, prefix + ".checkIcon"); Icon arrowIcon = style.getIcon(context, prefix + ".arrowIcon"); SynthGraphicsUtils.paint(context, accContext, g, checkIcon, arrowIcon, acceleratorDelimiter, defaultTextIconGap, getPropertyPrefix()); accContext.dispose(); } void paintBackground(SynthContext context, Graphics g, JComponent c) { SynthGraphicsUtils.paintBackground(context, g, c); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintMenuItemBorder(context, g, x, y, w, h); } public void propertyChange(PropertyChangeEvent e) { if (SynthLookAndFeel.shouldUpdateStyle(e)) { updateStyle((JMenuItem)e.getSource()); } } }
Java
/* * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.*; import javax.swing.plaf.FontUIResource; import java.awt.Font; import java.util.*; import java.util.regex.*; import sun.swing.plaf.synth.*; import sun.swing.BakedArrayList; /** {@collect.stats} * Factory used for obtaining styles. Supports associating a style based on * the name of the component as returned by <code>Component.getName()</code>, * and the <code>Region</code> associated with the <code>JComponent</code>. * Lookup is done using regular expressions. * * @author Scott Violet */ class DefaultSynthStyleFactory extends SynthStyleFactory { /** {@collect.stats} * Used to indicate the lookup should be done based on Component name. */ public static final int NAME = 0; /** {@collect.stats} * Used to indicate the lookup should be done based on region. */ public static final int REGION = 1; /** {@collect.stats} * List containing set of StyleAssociations used in determining matching * styles. */ private List<StyleAssociation> _styles; /** {@collect.stats} * Used during lookup. */ private BakedArrayList _tmpList; /** {@collect.stats} * Maps from a List (BakedArrayList to be precise) to the merged style. */ private Map _resolvedStyles; /** {@collect.stats} * Used if there are no styles matching a widget. */ private SynthStyle _defaultStyle; DefaultSynthStyleFactory() { _tmpList = new BakedArrayList(5); _styles = new ArrayList<StyleAssociation>(); _resolvedStyles = new HashMap(); } public synchronized void addStyle(DefaultSynthStyle style, String path, int type) throws PatternSyntaxException { if (path == null) { // Make an empty path match all. path = ".*"; } if (type == NAME) { _styles.add(StyleAssociation.createStyleAssociation( path, style, type)); } else if (type == REGION) { _styles.add(StyleAssociation.createStyleAssociation( path.toLowerCase(), style, type)); } } /** {@collect.stats} * Returns the style for the specified Component. * * @param c Component asking for * @param id ID of the Component */ public synchronized SynthStyle getStyle(JComponent c, Region id) { BakedArrayList matches = _tmpList; matches.clear(); getMatchingStyles(matches, c, id); if (matches.size() == 0) { return getDefaultStyle(); } // Use a cached Style if possible, otherwise create a new one. matches.cacheHashCode(); SynthStyle style = getCachedStyle(matches); if (style == null) { style = mergeStyles(matches); if (style != null) { cacheStyle(matches, style); } } return style; } /** {@collect.stats} * Returns the style to use if there are no matching styles. */ private SynthStyle getDefaultStyle() { if (_defaultStyle == null) { _defaultStyle = new DefaultSynthStyle(); ((DefaultSynthStyle)_defaultStyle).setFont( new FontUIResource(Font.DIALOG, Font.PLAIN,12)); } return _defaultStyle; } /** {@collect.stats} * Fetches any styles that match the passed into arguments into * <code>matches</code>. */ private void getMatchingStyles(java.util.List matches, JComponent c, Region id) { String idName = id.getLowerCaseName(); String cName = c.getName(); if (cName == null) { cName = ""; } for (int counter = _styles.size() - 1; counter >= 0; counter--){ StyleAssociation sa = _styles.get(counter); String path; if (sa.getID() == NAME) { path = cName; } else { path = idName; } if (sa.matches(path) && matches.indexOf(sa.getStyle()) == -1) { matches.add(sa.getStyle()); } } } /** {@collect.stats} * Caches the specified style. */ private void cacheStyle(java.util.List styles, SynthStyle style) { BakedArrayList cachedStyles = new BakedArrayList(styles); _resolvedStyles.put(cachedStyles, style); } /** {@collect.stats} * Returns the cached style from the passed in arguments. */ private SynthStyle getCachedStyle(java.util.List styles) { if (styles.size() == 0) { return null; } return (SynthStyle)_resolvedStyles.get(styles); } /** {@collect.stats} * Creates a single Style from the passed in styles. The passed in List * is reverse sorted, that is the most recently added style found to * match will be first. */ private SynthStyle mergeStyles(java.util.List styles) { int size = styles.size(); if (size == 0) { return null; } else if (size == 1) { return (SynthStyle)((DefaultSynthStyle)styles.get(0)).clone(); } // NOTE: merging is done backwards as DefaultSynthStyleFactory reverses // order, that is, the most specific style is first. DefaultSynthStyle style = (DefaultSynthStyle)styles.get(size - 1); style = (DefaultSynthStyle)style.clone(); for (int counter = size - 2; counter >= 0; counter--) { style = ((DefaultSynthStyle)styles.get(counter)).addTo(style); } return style; } }
Java
/* * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import javax.swing.text.View; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.Insets; import java.awt.Color; import java.awt.Graphics; import java.awt.Font; import java.awt.FontMetrics; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Synth's LabelUI. * * @author Scott Violet */ class SynthLabelUI extends BasicLabelUI implements SynthUI { private SynthStyle style; /** {@collect.stats} * Returns the LabelUI implementation used for the skins look and feel. */ public static ComponentUI createUI(JComponent c){ return new SynthLabelUI(); } protected void installDefaults(JLabel c) { updateStyle(c); } void updateStyle(JLabel c) { SynthContext context = getContext(c, ENABLED); style = SynthLookAndFeel.updateStyle(context, this); context.dispose(); } protected void uninstallDefaults(JLabel c){ SynthContext context = getContext(c, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { int state = SynthLookAndFeel.getComponentState(c); if (SynthLookAndFeel.selectedUI == this && state == SynthConstants.ENABLED) { state = SynthLookAndFeel.selectedUIState | SynthConstants.ENABLED; } return state; } public int getBaseline(JComponent c, int width, int height) { if (c == null) { throw new NullPointerException("Component must be non-null"); } if (width < 0 || height < 0) { throw new IllegalArgumentException( "Width and height must be >= 0"); } JLabel label = (JLabel)c; String text = label.getText(); if (text == null || "".equals(text)) { return -1; } Insets i = label.getInsets(); Rectangle viewRect = new Rectangle(); Rectangle textRect = new Rectangle(); Rectangle iconRect = new Rectangle(); viewRect.x = i.left; viewRect.y = i.top; viewRect.width = width - (i.right + viewRect.x); viewRect.height = height - (i.bottom + viewRect.y); // layout the text and icon SynthContext context = getContext(label); FontMetrics fm = context.getComponent().getFontMetrics( context.getStyle().getFont(context)); context.getStyle().getGraphicsUtils(context).layoutText( context, fm, label.getText(), label.getIcon(), label.getHorizontalAlignment(), label.getVerticalAlignment(), label.getHorizontalTextPosition(), label.getVerticalTextPosition(), viewRect, iconRect, textRect, label.getIconTextGap()); View view = (View)label.getClientProperty(BasicHTML.propertyKey); int baseline; if (view != null) { baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height); if (baseline >= 0) { baseline += textRect.y; } } else { baseline = textRect.y + fm.getAscent(); } context.dispose(); return baseline; } /** {@collect.stats} * Notifies this UI delegate that it's time to paint the specified * component. This method is invoked by <code>JComponent</code> * when the specified component is being painted. */ public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintLabelBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { JLabel label = (JLabel)context.getComponent(); Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon(); g.setColor(context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND)); g.setFont(style.getFont(context)); context.getStyle().getGraphicsUtils(context).paintText( context, g, label.getText(), icon, label.getHorizontalAlignment(), label.getVerticalAlignment(), label.getHorizontalTextPosition(), label.getVerticalTextPosition(), label.getIconTextGap(), label.getDisplayedMnemonicIndex(), 0); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintLabelBorder(context, g, x, y, w, h); } public Dimension getPreferredSize(JComponent c) { JLabel label = (JLabel)c; Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon(); SynthContext context = getContext(c); Dimension size = context.getStyle().getGraphicsUtils(context). getPreferredSize( context, context.getStyle().getFont(context), label.getText(), icon, label.getHorizontalAlignment(), label.getVerticalAlignment(), label.getHorizontalTextPosition(), label.getVerticalTextPosition(), label.getIconTextGap(), label.getDisplayedMnemonicIndex()); context.dispose(); return size; } public Dimension getMinimumSize(JComponent c) { JLabel label = (JLabel)c; Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon(); SynthContext context = getContext(c); Dimension size = context.getStyle().getGraphicsUtils(context). getMinimumSize( context, context.getStyle().getFont(context), label.getText(), icon, label.getHorizontalAlignment(), label.getVerticalAlignment(), label.getHorizontalTextPosition(), label.getVerticalTextPosition(), label.getIconTextGap(), label.getDisplayedMnemonicIndex()); context.dispose(); return size; } public Dimension getMaximumSize(JComponent c) { JLabel label = (JLabel)c; Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon(); SynthContext context = getContext(c); Dimension size = context.getStyle().getGraphicsUtils(context). getMaximumSize( context, context.getStyle().getFont(context), label.getText(), icon, label.getHorizontalAlignment(), label.getVerticalAlignment(), label.getHorizontalTextPosition(), label.getVerticalTextPosition(), label.getIconTextGap(), label.getDisplayedMnemonicIndex()); context.dispose(); return size; } public void propertyChange(PropertyChangeEvent e) { super.propertyChange(e); if (SynthLookAndFeel.shouldUpdateStyle(e)) { updateStyle((JLabel)e.getSource()); } } }
Java
/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import java.util.*; import javax.swing.plaf.*; import javax.swing.*; /** {@collect.stats} * Factory used for obtaining <code>SynthStyle</code>s. Each of the * Synth <code>ComponentUI</code>s will call into the current * <code>SynthStyleFactory</code> to obtain a <code>SynthStyle</code> * for each of the distinct regions they have. * <p> * The following example creates a custom <code>SynthStyleFactory</code> * that returns a different style based on the <code>Region</code>: * <pre> * class MyStyleFactory extends SynthStyleFactory { * public SynthStyle getStyle(JComponent c, Region id) { * if (id == Region.BUTTON) { * return buttonStyle; * } * else if (id == Region.TREE) { * return treeStyle; * } * return defaultStyle; * } * } * SynthLookAndFeel laf = new SynthLookAndFeel(); * UIManager.setLookAndFeel(laf); * SynthLookAndFeel.setStyleFactory(new MyStyleFactory()); * </pre> * * @see SynthStyleFactory * @see SynthStyle * * @since 1.5 * @author Scott Violet */ public abstract class SynthStyleFactory { /** {@collect.stats} * Creates a <code>SynthStyleFactory</code>. */ public SynthStyleFactory() { } /** {@collect.stats} * Returns the style for the specified Component. * * @param c Component asking for * @param id Region identifier * @return SynthStyle for region. */ public abstract SynthStyle getStyle(JComponent c, Region id); }
Java
/* * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Point; import java.awt.Rectangle; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.text.DateFormat; import java.text.Format; import java.text.NumberFormat; import java.util.Date; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JTable; import javax.swing.LookAndFeel; import javax.swing.border.Border; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicTableUI; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.JTableHeader; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * SynthTableUI implementation * * @author Philip Milne */ class SynthTableUI extends BasicTableUI implements SynthUI, PropertyChangeListener { // // Instance Variables // private SynthStyle style; private boolean useTableColors; private boolean useUIBorder; private Color alternateColor; //the background color to use for cells for alternate cells // TableCellRenderer installed on the JTable at the time we're installed, // cached so that we can reinstall them at uninstallUI time. private TableCellRenderer dateRenderer; private TableCellRenderer numberRenderer; private TableCellRenderer doubleRender; private TableCellRenderer floatRenderer; private TableCellRenderer iconRenderer; private TableCellRenderer imageIconRenderer; private TableCellRenderer booleanRenderer; private TableCellRenderer objectRenderer; // // The installation/uninstall procedures and support // public static ComponentUI createUI(JComponent c) { return new SynthTableUI(); } /** {@collect.stats} * Initialize JTable properties, e.g. font, foreground, and background. * The font, foreground, and background properties are only set if their * current value is either null or a UIResource, other properties are set * if the current value is null. * * @see #installUI */ protected void installDefaults() { dateRenderer = installRendererIfPossible(Date.class, null); numberRenderer = installRendererIfPossible(Number.class, null); doubleRender = installRendererIfPossible(Double.class, null); floatRenderer = installRendererIfPossible(Float.class, null); iconRenderer = installRendererIfPossible(Icon.class, null); imageIconRenderer = installRendererIfPossible(ImageIcon.class, null); booleanRenderer = installRendererIfPossible(Boolean.class, new SynthBooleanTableCellRenderer()); objectRenderer = installRendererIfPossible(Object.class, new SynthTableCellRenderer()); updateStyle(table); } private TableCellRenderer installRendererIfPossible(Class objectClass, TableCellRenderer renderer) { TableCellRenderer currentRenderer = table.getDefaultRenderer( objectClass); if (currentRenderer instanceof UIResource) { table.setDefaultRenderer(objectClass, renderer); } return currentRenderer; } private void updateStyle(JTable c) { SynthContext context = getContext(c, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { context.setComponentState(ENABLED | SELECTED); Color sbg = table.getSelectionBackground(); if (sbg == null || sbg instanceof UIResource) { table.setSelectionBackground(style.getColor( context, ColorType.TEXT_BACKGROUND)); } Color sfg = table.getSelectionForeground(); if (sfg == null || sfg instanceof UIResource) { table.setSelectionForeground(style.getColor( context, ColorType.TEXT_FOREGROUND)); } context.setComponentState(ENABLED); Color gridColor = table.getGridColor(); if (gridColor == null || gridColor instanceof UIResource) { gridColor = (Color)style.get(context, "Table.gridColor"); if (gridColor == null) { gridColor = style.getColor(context, ColorType.FOREGROUND); } table.setGridColor(gridColor); } useTableColors = style.getBoolean(context, "Table.rendererUseTableColors", true); useUIBorder = style.getBoolean(context, "Table.rendererUseUIBorder", true); Object rowHeight = style.get(context, "Table.rowHeight"); if (rowHeight != null) { LookAndFeel.installProperty(table, "rowHeight", rowHeight); } boolean showGrid = style.getBoolean(context, "Table.showGrid", true); if (!showGrid) { table.setShowGrid(false); } Dimension d = table.getIntercellSpacing(); // if (d == null || d instanceof UIResource) { if (d != null) { d = (Dimension)style.get(context, "Table.intercellSpacing"); } alternateColor = (Color)style.get(context, "Table.alternateRowColor"); if (d != null) { table.setIntercellSpacing(d); } if (oldStyle != null) { uninstallKeyboardActions(); installKeyboardActions(); } } context.dispose(); } /** {@collect.stats} * Attaches listeners to the JTable. */ protected void installListeners() { super.installListeners(); table.addPropertyChangeListener(this); } protected void uninstallDefaults() { table.setDefaultRenderer(Date.class, dateRenderer); table.setDefaultRenderer(Number.class, numberRenderer); table.setDefaultRenderer(Double.class, doubleRender); table.setDefaultRenderer(Float.class, floatRenderer); table.setDefaultRenderer(Icon.class, iconRenderer); table.setDefaultRenderer(ImageIcon.class, imageIconRenderer); table.setDefaultRenderer(Boolean.class, booleanRenderer); table.setDefaultRenderer(Object.class, objectRenderer); if (table.getTransferHandler() instanceof UIResource) { table.setTransferHandler(null); } SynthContext context = getContext(table, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; } protected void uninstallListeners() { table.removePropertyChangeListener(this); super.uninstallListeners(); } // // SynthUI // public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } // // Paint methods and support // public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintTableBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintTableBorder(context, g, x, y, w, h); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { Rectangle clip = g.getClipBounds(); Rectangle bounds = table.getBounds(); // account for the fact that the graphics has already been translated // into the table's bounds bounds.x = bounds.y = 0; if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 || // this check prevents us from painting the entire table // when the clip doesn't intersect our bounds at all !bounds.intersects(clip)) { paintDropLines(context, g); return; } boolean ltr = table.getComponentOrientation().isLeftToRight(); Point upperLeft = clip.getLocation(); Point lowerRight = new Point(clip.x + clip.width - 1, clip.y + clip.height - 1); int rMin = table.rowAtPoint(upperLeft); int rMax = table.rowAtPoint(lowerRight); // This should never happen (as long as our bounds intersect the clip, // which is why we bail above if that is the case). if (rMin == -1) { rMin = 0; } // If the table does not have enough rows to fill the view we'll get -1. // (We could also get -1 if our bounds don't intersect the clip, // which is why we bail above if that is the case). // Replace this with the index of the last row. if (rMax == -1) { rMax = table.getRowCount()-1; } int cMin = table.columnAtPoint(ltr ? upperLeft : lowerRight); int cMax = table.columnAtPoint(ltr ? lowerRight : upperLeft); // This should never happen. if (cMin == -1) { cMin = 0; } // If the table does not have enough columns to fill the view we'll get -1. // Replace this with the index of the last column. if (cMax == -1) { cMax = table.getColumnCount()-1; } // Paint the grid. paintGrid(context, g, rMin, rMax, cMin, cMax); // Paint the cells. paintCells(context, g, rMin, rMax, cMin, cMax); paintDropLines(context, g); } private void paintDropLines(SynthContext context, Graphics g) { JTable.DropLocation loc = table.getDropLocation(); if (loc == null) { return; } Color color = (Color)style.get(context, "Table.dropLineColor"); Color shortColor = (Color)style.get(context, "Table.dropLineShortColor"); if (color == null && shortColor == null) { return; } Rectangle rect; rect = getHDropLineRect(loc); if (rect != null) { int x = rect.x; int w = rect.width; if (color != null) { extendRect(rect, true); g.setColor(color); g.fillRect(rect.x, rect.y, rect.width, rect.height); } if (!loc.isInsertColumn() && shortColor != null) { g.setColor(shortColor); g.fillRect(x, rect.y, w, rect.height); } } rect = getVDropLineRect(loc); if (rect != null) { int y = rect.y; int h = rect.height; if (color != null) { extendRect(rect, false); g.setColor(color); g.fillRect(rect.x, rect.y, rect.width, rect.height); } if (!loc.isInsertRow() && shortColor != null) { g.setColor(shortColor); g.fillRect(rect.x, y, rect.width, h); } } } private Rectangle getHDropLineRect(JTable.DropLocation loc) { if (!loc.isInsertRow()) { return null; } int row = loc.getRow(); int col = loc.getColumn(); if (col >= table.getColumnCount()) { col--; } Rectangle rect = table.getCellRect(row, col, true); if (row >= table.getRowCount()) { row--; Rectangle prevRect = table.getCellRect(row, col, true); rect.y = prevRect.y + prevRect.height; } if (rect.y == 0) { rect.y = -1; } else { rect.y -= 2; } rect.height = 3; return rect; } private Rectangle getVDropLineRect(JTable.DropLocation loc) { if (!loc.isInsertColumn()) { return null; } boolean ltr = table.getComponentOrientation().isLeftToRight(); int col = loc.getColumn(); Rectangle rect = table.getCellRect(loc.getRow(), col, true); if (col >= table.getColumnCount()) { col--; rect = table.getCellRect(loc.getRow(), col, true); if (ltr) { rect.x = rect.x + rect.width; } } else if (!ltr) { rect.x = rect.x + rect.width; } if (rect.x == 0) { rect.x = -1; } else { rect.x -= 2; } rect.width = 3; return rect; } private Rectangle extendRect(Rectangle rect, boolean horizontal) { if (rect == null) { return rect; } if (horizontal) { rect.x = 0; rect.width = table.getWidth(); } else { rect.y = 0; if (table.getRowCount() != 0) { Rectangle lastRect = table.getCellRect(table.getRowCount() - 1, 0, true); rect.height = lastRect.y + lastRect.height; } else { rect.height = table.getHeight(); } } return rect; } /* * Paints the grid lines within <I>aRect</I>, using the grid * color set with <I>setGridColor</I>. Paints vertical lines * if <code>getShowVerticalLines()</code> returns true and paints * horizontal lines if <code>getShowHorizontalLines()</code> * returns true. */ private void paintGrid(SynthContext context, Graphics g, int rMin, int rMax, int cMin, int cMax) { g.setColor(table.getGridColor()); Rectangle minCell = table.getCellRect(rMin, cMin, true); Rectangle maxCell = table.getCellRect(rMax, cMax, true); Rectangle damagedArea = minCell.union( maxCell ); SynthGraphicsUtils synthG = context.getStyle().getGraphicsUtils( context); if (table.getShowHorizontalLines()) { int tableWidth = damagedArea.x + damagedArea.width; int y = damagedArea.y; for (int row = rMin; row <= rMax; row++) { y += table.getRowHeight(row); synthG.drawLine(context, "Table.grid", g, damagedArea.x, y - 1, tableWidth - 1,y - 1); } } if (table.getShowVerticalLines()) { TableColumnModel cm = table.getColumnModel(); int tableHeight = damagedArea.y + damagedArea.height; int x; if (table.getComponentOrientation().isLeftToRight()) { x = damagedArea.x; for (int column = cMin; column <= cMax; column++) { int w = cm.getColumn(column).getWidth(); x += w; synthG.drawLine(context, "Table.grid", g, x - 1, 0, x - 1, tableHeight - 1); } } else { x = damagedArea.x; for (int column = cMax; column >= cMin; column--) { int w = cm.getColumn(column).getWidth(); x += w; synthG.drawLine(context, "Table.grid", g, x - 1, 0, x - 1, tableHeight - 1); } } } } private int viewIndexForColumn(TableColumn aColumn) { TableColumnModel cm = table.getColumnModel(); for (int column = 0; column < cm.getColumnCount(); column++) { if (cm.getColumn(column) == aColumn) { return column; } } return -1; } private void paintCells(SynthContext context, Graphics g, int rMin, int rMax, int cMin, int cMax) { JTableHeader header = table.getTableHeader(); TableColumn draggedColumn = (header == null) ? null : header.getDraggedColumn(); TableColumnModel cm = table.getColumnModel(); int columnMargin = cm.getColumnMargin(); Rectangle cellRect; TableColumn aColumn; int columnWidth; if (table.getComponentOrientation().isLeftToRight()) { for(int row = rMin; row <= rMax; row++) { cellRect = table.getCellRect(row, cMin, false); for(int column = cMin; column <= cMax; column++) { aColumn = cm.getColumn(column); columnWidth = aColumn.getWidth(); cellRect.width = columnWidth - columnMargin; if (aColumn != draggedColumn) { paintCell(context, g, cellRect, row, column); } cellRect.x += columnWidth; } } } else { for(int row = rMin; row <= rMax; row++) { cellRect = table.getCellRect(row, cMin, false); aColumn = cm.getColumn(cMin); if (aColumn != draggedColumn) { columnWidth = aColumn.getWidth(); cellRect.width = columnWidth - columnMargin; paintCell(context, g, cellRect, row, cMin); } for(int column = cMin+1; column <= cMax; column++) { aColumn = cm.getColumn(column); columnWidth = aColumn.getWidth(); cellRect.width = columnWidth - columnMargin; cellRect.x -= columnWidth; if (aColumn != draggedColumn) { paintCell(context, g, cellRect, row, column); } } } } // Paint the dragged column if we are dragging. if (draggedColumn != null) { paintDraggedArea(context, g, rMin, rMax, draggedColumn, header.getDraggedDistance()); } // Remove any renderers that may be left in the rendererPane. rendererPane.removeAll(); } private void paintDraggedArea(SynthContext context, Graphics g, int rMin, int rMax, TableColumn draggedColumn, int distance) { int draggedColumnIndex = viewIndexForColumn(draggedColumn); Rectangle minCell = table.getCellRect(rMin, draggedColumnIndex, true); Rectangle maxCell = table.getCellRect(rMax, draggedColumnIndex, true); Rectangle vacatedColumnRect = minCell.union(maxCell); // Paint a gray well in place of the moving column. g.setColor(table.getParent().getBackground()); g.fillRect(vacatedColumnRect.x, vacatedColumnRect.y, vacatedColumnRect.width, vacatedColumnRect.height); // Move to the where the cell has been dragged. vacatedColumnRect.x += distance; // Fill the background. g.setColor(context.getStyle().getColor(context, ColorType.BACKGROUND)); g.fillRect(vacatedColumnRect.x, vacatedColumnRect.y, vacatedColumnRect.width, vacatedColumnRect.height); SynthGraphicsUtils synthG = context.getStyle().getGraphicsUtils( context); // Paint the vertical grid lines if necessary. if (table.getShowVerticalLines()) { g.setColor(table.getGridColor()); int x1 = vacatedColumnRect.x; int y1 = vacatedColumnRect.y; int x2 = x1 + vacatedColumnRect.width - 1; int y2 = y1 + vacatedColumnRect.height - 1; // Left synthG.drawLine(context, "Table.grid", g, x1-1, y1, x1-1, y2); // Right synthG.drawLine(context, "Table.grid", g, x2, y1, x2, y2); } for(int row = rMin; row <= rMax; row++) { // Render the cell value Rectangle r = table.getCellRect(row, draggedColumnIndex, false); r.x += distance; paintCell(context, g, r, row, draggedColumnIndex); // Paint the (lower) horizontal grid line if necessary. if (table.getShowHorizontalLines()) { g.setColor(table.getGridColor()); Rectangle rcr = table.getCellRect(row, draggedColumnIndex, true); rcr.x += distance; int x1 = rcr.x; int y1 = rcr.y; int x2 = x1 + rcr.width - 1; int y2 = y1 + rcr.height - 1; synthG.drawLine(context, "Table.grid", g, x1, y2, x2, y2); } } } private void paintCell(SynthContext context, Graphics g, Rectangle cellRect, int row, int column) { if (table.isEditing() && table.getEditingRow()==row && table.getEditingColumn()==column) { Component component = table.getEditorComponent(); component.setBounds(cellRect); component.validate(); } else { TableCellRenderer renderer = table.getCellRenderer(row, column); Component component = table.prepareRenderer(renderer, row, column); Color b = component.getBackground(); if ((b == null || b instanceof UIResource || component instanceof SynthBooleanTableCellRenderer) && !table.isCellSelected(row, column)) { if (alternateColor != null && row % 2 != 0) { component.setBackground(alternateColor); } } rendererPane.paintComponent(g, component, table, cellRect.x, cellRect.y, cellRect.width, cellRect.height, true); } } public void propertyChange(PropertyChangeEvent event) { if (SynthLookAndFeel.shouldUpdateStyle(event)) { updateStyle((JTable)event.getSource()); } } private class SynthBooleanTableCellRenderer extends JCheckBox implements TableCellRenderer { private boolean isRowSelected; public SynthBooleanTableCellRenderer() { setHorizontalAlignment(JLabel.CENTER); setName("Table.cellRenderer"); } public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { isRowSelected = isSelected; if (isSelected) { setForeground(unwrap(table.getSelectionForeground())); setBackground(unwrap(table.getSelectionBackground())); } else { setForeground(unwrap(table.getForeground())); setBackground(unwrap(table.getBackground())); } setSelected((value != null && ((Boolean)value).booleanValue())); return this; } private Color unwrap(Color c) { if (c instanceof UIResource) { return new Color(c.getRGB()); } return c; } public boolean isOpaque() { return isRowSelected ? true : super.isOpaque(); } } private class SynthTableCellRenderer extends DefaultTableCellRenderer { private Object numberFormat; private Object dateFormat; private boolean opaque; public void setOpaque(boolean isOpaque) { opaque = isOpaque; } public boolean isOpaque() { return opaque; } public String getName() { String name = super.getName(); if (name == null) { return "Table.cellRenderer"; } return name; } public void setBorder(Border b) { if (useUIBorder || b instanceof SynthBorder) { super.setBorder(b); } } public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (!useTableColors && (isSelected || hasFocus)) { SynthLookAndFeel.setSelectedUI((SynthLabelUI)SynthLookAndFeel. getUIOfType(getUI(), SynthLabelUI.class), isSelected, hasFocus, table.isEnabled(), false); } else { SynthLookAndFeel.resetSelectedUI(); } super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); setIcon(null); Class columnClass = table.getColumnClass(column); configureValue(value, columnClass); return this; } private void configureValue(Object value, Class columnClass) { if (columnClass == Object.class || columnClass == null) { setHorizontalAlignment(JLabel.LEADING); } else if (columnClass == Float.class || columnClass == Double.class) { if (numberFormat == null) { numberFormat = NumberFormat.getInstance(); } setHorizontalAlignment(JLabel.TRAILING); setText((value == null) ? "" : ((NumberFormat)numberFormat).format(value)); } else if (columnClass == Number.class) { setHorizontalAlignment(JLabel.TRAILING); // Super will have set value. } else if (columnClass == Icon.class || columnClass == ImageIcon.class) { setHorizontalAlignment(JLabel.CENTER); setIcon((value instanceof Icon) ? (Icon)value : null); setText(""); } else if (columnClass == Date.class) { if (dateFormat == null) { dateFormat = DateFormat.getDateInstance(); } setHorizontalAlignment(JLabel.LEADING); setText((value == null) ? "" : ((Format)dateFormat).format(value)); } else { configureValue(value, columnClass.getSuperclass()); } } public void paint(Graphics g) { super.paint(g); SynthLookAndFeel.resetSelectedUI(); } } }
Java
/* * Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import sun.awt.AppContext; import java.util.HashMap; import java.util.Locale; import java.util.Map; import javax.swing.JComponent; import javax.swing.UIDefaults; /** {@collect.stats} * A distinct rendering area of a Swing component. A component may * support one or more regions. Specific component regions are defined * by the typesafe enumeration in this class. * <p> * Regions are typically used as a way to identify the <code>Component</code>s * and areas a particular style is to apply to. Synth's file format allows you * to bind styles based on the name of a <code>Region</code>. * The name is derived from the field name of the constant: * <ol> * <li>Map all characters to lowercase. * <li>Map the first character to uppercase. * <li>Map the first character after underscores to uppercase. * <li>Remove all underscores. * </ol> * For example, to identify the <code>SPLIT_PANE</code> * <code>Region</code> you would use <code>SplitPane</code>. * The following shows a custom <code>SynthStyleFactory</code> * that returns a specific style for split panes: * <pre> * public SynthStyle getStyle(JComponent c, Region id) { * if (id == Region.SPLIT_PANE) { * return splitPaneStyle; * } * ... * } * </pre> * The following <a href="doc-files/synthFileFormat.html">xml</a> * accomplishes the same thing: * <pre> * &lt;style id="splitPaneStyle"> * ... * &lt;/style> * &lt;bind style="splitPaneStyle" type="region" key="SplitPane"/> * </pre> * * @since 1.5 * @author Scott Violet */ public class Region { private static final Object UI_TO_REGION_MAP_KEY = new Object(); private static final Object LOWER_CASE_NAME_MAP_KEY = new Object(); /** {@collect.stats} * ArrowButton's are special types of buttons that also render a * directional indicator, typically an arrow. ArrowButtons are used by * composite components, for example ScrollBar's contain ArrowButtons. * To bind a style to this <code>Region</code> use the name * <code>ArrowButton</code>. */ public static final Region ARROW_BUTTON = new Region("ArrowButton", false); /** {@collect.stats} * Button region. To bind a style to this <code>Region</code> use the name * <code>Button</code>. */ public static final Region BUTTON = new Region("Button", false); /** {@collect.stats} * CheckBox region. To bind a style to this <code>Region</code> use the name * <code>CheckBox</code>. */ public static final Region CHECK_BOX = new Region("CheckBox", false); /** {@collect.stats} * CheckBoxMenuItem region. To bind a style to this <code>Region</code> use * the name <code>CheckBoxMenuItem</code>. */ public static final Region CHECK_BOX_MENU_ITEM = new Region("CheckBoxMenuItem", false); /** {@collect.stats} * ColorChooser region. To bind a style to this <code>Region</code> use * the name <code>ColorChooser</code>. */ public static final Region COLOR_CHOOSER = new Region("ColorChooser", false); /** {@collect.stats} * ComboBox region. To bind a style to this <code>Region</code> use * the name <code>ComboBox</code>. */ public static final Region COMBO_BOX = new Region("ComboBox", false); /** {@collect.stats} * DesktopPane region. To bind a style to this <code>Region</code> use * the name <code>DesktopPane</code>. */ public static final Region DESKTOP_PANE = new Region("DesktopPane", false); /** {@collect.stats} * DesktopIcon region. To bind a style to this <code>Region</code> use * the name <code>DesktopIcon</code>. */ public static final Region DESKTOP_ICON = new Region("DesktopIcon", false); /** {@collect.stats} * EditorPane region. To bind a style to this <code>Region</code> use * the name <code>EditorPane</code>. */ public static final Region EDITOR_PANE = new Region("EditorPane", false); /** {@collect.stats} * FileChooser region. To bind a style to this <code>Region</code> use * the name <code>FileChooser</code>. */ public static final Region FILE_CHOOSER = new Region("FileChooser", false); /** {@collect.stats} * FormattedTextField region. To bind a style to this <code>Region</code> use * the name <code>FormattedTextField</code>. */ public static final Region FORMATTED_TEXT_FIELD = new Region("FormattedTextField", false); /** {@collect.stats} * InternalFrame region. To bind a style to this <code>Region</code> use * the name <code>InternalFrame</code>. */ public static final Region INTERNAL_FRAME = new Region("InternalFrame", false); /** {@collect.stats} * TitlePane of an InternalFrame. The TitlePane typically * shows a menu, title, widgets to manipulate the internal frame. * To bind a style to this <code>Region</code> use the name * <code>InternalFrameTitlePane</code>. */ public static final Region INTERNAL_FRAME_TITLE_PANE = new Region("InternalFrameTitlePane", false); /** {@collect.stats} * Label region. To bind a style to this <code>Region</code> use the name * <code>Label</code>. */ public static final Region LABEL = new Region("Label", false); /** {@collect.stats} * List region. To bind a style to this <code>Region</code> use the name * <code>List</code>. */ public static final Region LIST = new Region("List", false); /** {@collect.stats} * Menu region. To bind a style to this <code>Region</code> use the name * <code>Menu</code>. */ public static final Region MENU = new Region("Menu", false); /** {@collect.stats} * MenuBar region. To bind a style to this <code>Region</code> use the name * <code>MenuBar</code>. */ public static final Region MENU_BAR = new Region("MenuBar", false); /** {@collect.stats} * MenuItem region. To bind a style to this <code>Region</code> use the name * <code>MenuItem</code>. */ public static final Region MENU_ITEM = new Region("MenuItem", false); /** {@collect.stats} * Accelerator region of a MenuItem. To bind a style to this * <code>Region</code> use the name <code>MenuItemAccelerator</code>. */ public static final Region MENU_ITEM_ACCELERATOR = new Region("MenuItemAccelerator", true); /** {@collect.stats} * OptionPane region. To bind a style to this <code>Region</code> use * the name <code>OptionPane</code>. */ public static final Region OPTION_PANE = new Region("OptionPane", false); /** {@collect.stats} * Panel region. To bind a style to this <code>Region</code> use the name * <code>Panel</code>. */ public static final Region PANEL = new Region("Panel", false); /** {@collect.stats} * PasswordField region. To bind a style to this <code>Region</code> use * the name <code>PasswordField</code>. */ public static final Region PASSWORD_FIELD = new Region("PasswordField", false); /** {@collect.stats} * PopupMenu region. To bind a style to this <code>Region</code> use * the name <code>PopupMenu</code>. */ public static final Region POPUP_MENU = new Region("PopupMenu", false); /** {@collect.stats} * PopupMenuSeparator region. To bind a style to this <code>Region</code> * use the name <code>PopupMenuSeparator</code>. */ public static final Region POPUP_MENU_SEPARATOR = new Region("PopupMenuSeparator", false); /** {@collect.stats} * ProgressBar region. To bind a style to this <code>Region</code> * use the name <code>ProgressBar</code>. */ public static final Region PROGRESS_BAR = new Region("ProgressBar", false); /** {@collect.stats} * RadioButton region. To bind a style to this <code>Region</code> * use the name <code>RadioButton</code>. */ public static final Region RADIO_BUTTON = new Region("RadioButton", false); /** {@collect.stats} * RegionButtonMenuItem region. To bind a style to this <code>Region</code> * use the name <code>RadioButtonMenuItem</code>. */ public static final Region RADIO_BUTTON_MENU_ITEM = new Region("RadioButtonMenuItem", false); /** {@collect.stats} * RootPane region. To bind a style to this <code>Region</code> use * the name <code>RootPane</code>. */ public static final Region ROOT_PANE = new Region("RootPane", false); /** {@collect.stats} * ScrollBar region. To bind a style to this <code>Region</code> use * the name <code>ScrollBar</code>. */ public static final Region SCROLL_BAR = new Region("ScrollBar", false); /** {@collect.stats} * Track of the ScrollBar. To bind a style to this <code>Region</code> use * the name <code>ScrollBarTrack</code>. */ public static final Region SCROLL_BAR_TRACK = new Region("ScrollBarTrack", true); /** {@collect.stats} * Thumb of the ScrollBar. The thumb is the region of the ScrollBar * that gives a graphical depiction of what percentage of the View is * currently visible. To bind a style to this <code>Region</code> use * the name <code>ScrollBarThumb</code>. */ public static final Region SCROLL_BAR_THUMB = new Region("ScrollBarThumb", true); /** {@collect.stats} * ScrollPane region. To bind a style to this <code>Region</code> use * the name <code>ScrollPane</code>. */ public static final Region SCROLL_PANE = new Region("ScrollPane", false); /** {@collect.stats} * Separator region. To bind a style to this <code>Region</code> use * the name <code>Separator</code>. */ public static final Region SEPARATOR = new Region("Separator", false); /** {@collect.stats} * Slider region. To bind a style to this <code>Region</code> use * the name <code>Slider</code>. */ public static final Region SLIDER = new Region("Slider", false); /** {@collect.stats} * Track of the Slider. To bind a style to this <code>Region</code> use * the name <code>SliderTrack</code>. */ public static final Region SLIDER_TRACK = new Region("SliderTrack", true); /** {@collect.stats} * Thumb of the Slider. The thumb of the Slider identifies the current * value. To bind a style to this <code>Region</code> use the name * <code>SliderThumb</code>. */ public static final Region SLIDER_THUMB = new Region("SliderThumb", true); /** {@collect.stats} * Spinner region. To bind a style to this <code>Region</code> use the name * <code>Spinner</code>. */ public static final Region SPINNER = new Region("Spinner", false); /** {@collect.stats} * SplitPane region. To bind a style to this <code>Region</code> use the name * <code>SplitPane</code>. */ public static final Region SPLIT_PANE = new Region("SplitPane", false); /** {@collect.stats} * Divider of the SplitPane. To bind a style to this <code>Region</code> * use the name <code>SplitPaneDivider</code>. */ public static final Region SPLIT_PANE_DIVIDER = new Region("SplitPaneDivider", true); /** {@collect.stats} * TabbedPane region. To bind a style to this <code>Region</code> use * the name <code>TabbedPane</code>. */ public static final Region TABBED_PANE = new Region("TabbedPane", false); /** {@collect.stats} * Region of a TabbedPane for one tab. To bind a style to this * <code>Region</code> use the name <code>TabbedPaneTab</code>. */ public static final Region TABBED_PANE_TAB = new Region("TabbedPaneTab", true); /** {@collect.stats} * Region of a TabbedPane containing the tabs. To bind a style to this * <code>Region</code> use the name <code>TabbedPaneTabArea</code>. */ public static final Region TABBED_PANE_TAB_AREA = new Region("TabbedPaneTabArea", true); /** {@collect.stats} * Region of a TabbedPane containing the content. To bind a style to this * <code>Region</code> use the name <code>TabbedPaneContent</code>. */ public static final Region TABBED_PANE_CONTENT = new Region("TabbedPaneContent", true); /** {@collect.stats} * Table region. To bind a style to this <code>Region</code> use * the name <code>Table</code>. */ public static final Region TABLE = new Region("Table", false); /** {@collect.stats} * TableHeader region. To bind a style to this <code>Region</code> use * the name <code>TableHeader</code>. */ public static final Region TABLE_HEADER = new Region("TableHeader", false); /** {@collect.stats} * TextArea region. To bind a style to this <code>Region</code> use * the name <code>TextArea</code>. */ public static final Region TEXT_AREA = new Region("TextArea", false); /** {@collect.stats} * TextField region. To bind a style to this <code>Region</code> use * the name <code>TextField</code>. */ public static final Region TEXT_FIELD = new Region("TextField", false); /** {@collect.stats} * TextPane region. To bind a style to this <code>Region</code> use * the name <code>TextPane</code>. */ public static final Region TEXT_PANE = new Region("TextPane", false); /** {@collect.stats} * ToggleButton region. To bind a style to this <code>Region</code> use * the name <code>ToggleButton</code>. */ public static final Region TOGGLE_BUTTON = new Region("ToggleButton", false); /** {@collect.stats} * ToolBar region. To bind a style to this <code>Region</code> use * the name <code>ToolBar</code>. */ public static final Region TOOL_BAR = new Region("ToolBar", false); /** {@collect.stats} * Region of the ToolBar containing the content. To bind a style to this * <code>Region</code> use the name <code>ToolBarContent</code>. */ public static final Region TOOL_BAR_CONTENT = new Region("ToolBarContent", true); /** {@collect.stats} * Region for the Window containing the ToolBar. To bind a style to this * <code>Region</code> use the name <code>ToolBarDragWindow</code>. */ public static final Region TOOL_BAR_DRAG_WINDOW = new Region("ToolBarDragWindow", false); /** {@collect.stats} * ToolTip region. To bind a style to this <code>Region</code> use * the name <code>ToolTip</code>. */ public static final Region TOOL_TIP = new Region("ToolTip", false); /** {@collect.stats} * ToolBar separator region. To bind a style to this <code>Region</code> use * the name <code>ToolBarSeparator</code>. */ public static final Region TOOL_BAR_SEPARATOR = new Region("ToolBarSeparator", false); /** {@collect.stats} * Tree region. To bind a style to this <code>Region</code> use the name * <code>Tree</code>. */ public static final Region TREE = new Region("Tree", false); /** {@collect.stats} * Region of the Tree for one cell. To bind a style to this * <code>Region</code> use the name <code>TreeCell</code>. */ public static final Region TREE_CELL = new Region("TreeCell", true); /** {@collect.stats} * Viewport region. To bind a style to this <code>Region</code> use * the name <code>Viewport</code>. */ public static final Region VIEWPORT = new Region("Viewport", false); private static Map<String, Region> getUItoRegionMap() { AppContext context = AppContext.getAppContext(); Map<String, Region> map = (Map<String, Region>) context.get(UI_TO_REGION_MAP_KEY); if (map == null) { map = new HashMap<String, Region>(); map.put("ArrowButtonUI", ARROW_BUTTON); map.put("ButtonUI", BUTTON); map.put("CheckBoxUI", CHECK_BOX); map.put("CheckBoxMenuItemUI", CHECK_BOX_MENU_ITEM); map.put("ColorChooserUI", COLOR_CHOOSER); map.put("ComboBoxUI", COMBO_BOX); map.put("DesktopPaneUI", DESKTOP_PANE); map.put("DesktopIconUI", DESKTOP_ICON); map.put("EditorPaneUI", EDITOR_PANE); map.put("FileChooserUI", FILE_CHOOSER); map.put("FormattedTextFieldUI", FORMATTED_TEXT_FIELD); map.put("InternalFrameUI", INTERNAL_FRAME); map.put("InternalFrameTitlePaneUI", INTERNAL_FRAME_TITLE_PANE); map.put("LabelUI", LABEL); map.put("ListUI", LIST); map.put("MenuUI", MENU); map.put("MenuBarUI", MENU_BAR); map.put("MenuItemUI", MENU_ITEM); map.put("OptionPaneUI", OPTION_PANE); map.put("PanelUI", PANEL); map.put("PasswordFieldUI", PASSWORD_FIELD); map.put("PopupMenuUI", POPUP_MENU); map.put("PopupMenuSeparatorUI", POPUP_MENU_SEPARATOR); map.put("ProgressBarUI", PROGRESS_BAR); map.put("RadioButtonUI", RADIO_BUTTON); map.put("RadioButtonMenuItemUI", RADIO_BUTTON_MENU_ITEM); map.put("RootPaneUI", ROOT_PANE); map.put("ScrollBarUI", SCROLL_BAR); map.put("ScrollPaneUI", SCROLL_PANE); map.put("SeparatorUI", SEPARATOR); map.put("SliderUI", SLIDER); map.put("SpinnerUI", SPINNER); map.put("SplitPaneUI", SPLIT_PANE); map.put("TabbedPaneUI", TABBED_PANE); map.put("TableUI", TABLE); map.put("TableHeaderUI", TABLE_HEADER); map.put("TextAreaUI", TEXT_AREA); map.put("TextFieldUI", TEXT_FIELD); map.put("TextPaneUI", TEXT_PANE); map.put("ToggleButtonUI", TOGGLE_BUTTON); map.put("ToolBarUI", TOOL_BAR); map.put("ToolTipUI", TOOL_TIP); map.put("ToolBarSeparatorUI", TOOL_BAR_SEPARATOR); map.put("TreeUI", TREE); map.put("ViewportUI", VIEWPORT); context.put(UI_TO_REGION_MAP_KEY, map); } return map; } private static Map<Region, String> getLowerCaseNameMap() { AppContext context = AppContext.getAppContext(); Map<Region, String> map = (Map<Region, String>) context.get(LOWER_CASE_NAME_MAP_KEY); if (map == null) { map = new HashMap<Region, String>(); context.put(LOWER_CASE_NAME_MAP_KEY, map); } return map; } static Region getRegion(JComponent c) { return getUItoRegionMap().get(c.getUIClassID()); } static void registerUIs(UIDefaults table) { for (Object key : getUItoRegionMap().keySet()) { table.put(key, "javax.swing.plaf.synth.SynthLookAndFeel"); } } private final String name; private final boolean subregion; private Region(String name, boolean subregion) { if (name == null) { throw new NullPointerException("You must specify a non-null name"); } this.name = name; this.subregion = subregion; } /** {@collect.stats} * Creates a Region with the specified name. This should only be * used if you are creating your own <code>JComponent</code> subclass * with a custom <code>ComponentUI</code> class. * * @param name Name of the region * @param ui String that will be returned from * <code>component.getUIClassID</code>. This will be null * if this is a subregion. * @param subregion Whether or not this is a subregion. */ protected Region(String name, String ui, boolean subregion) { this(name, subregion); if (ui != null) { getUItoRegionMap().put(ui, this); } } /** {@collect.stats} * Returns true if the Region is a subregion of a Component, otherwise * false. For example, <code>Region.BUTTON</code> corresponds do a * <code>Component</code> so that <code>Region.BUTTON.isSubregion()</code> * returns false. * * @return true if the Region is a subregion of a Component. */ public boolean isSubregion() { return subregion; } /** {@collect.stats} * Returns the name of the region. * * @return name of the Region. */ public String getName() { return name; } /** {@collect.stats} * Returns the name, in lowercase. * * @return lower case representation of the name of the Region */ String getLowerCaseName() { Map<Region, String> lowerCaseNameMap = getLowerCaseNameMap(); String lowerCaseName = lowerCaseNameMap.get(this); if (lowerCaseName == null) { lowerCaseName = name.toLowerCase(Locale.ENGLISH); lowerCaseNameMap.put(this, lowerCaseName); } return lowerCaseName; } /** {@collect.stats} * Returns the name of the Region. * * @return name of the Region. */ @Override public String toString() { return name; } }
Java
/* * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.BasicInternalFrameTitlePane; import javax.swing.border.*; import javax.swing.event.InternalFrameEvent; import java.util.EventListener; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import java.beans.VetoableChangeListener; import java.beans.PropertyVetoException; import sun.swing.plaf.synth.SynthUI; import sun.swing.SwingUtilities2; /** {@collect.stats} * The class that manages a synth title bar * * @author David Kloba * @author Joshua Outwater * @author Steve Wilson */ class SynthInternalFrameTitlePane extends BasicInternalFrameTitlePane implements SynthUI, PropertyChangeListener { protected JPopupMenu systemPopupMenu; protected JButton menuButton; private SynthStyle style; private int titleSpacing; private int buttonSpacing; // Alignment for the title, one of SwingConstants.(LEADING|TRAILING|CENTER) private int titleAlignment; public SynthInternalFrameTitlePane(JInternalFrame f) { super(f); } public String getUIClassID() { return "InternalFrameTitlePaneUI"; } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } public SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { if (frame != null) { if (frame.isSelected()) { return SELECTED; } } return SynthLookAndFeel.getComponentState(c); } protected void addSubComponents() { menuButton.setName("InternalFrameTitlePane.menuButton"); iconButton.setName("InternalFrameTitlePane.iconifyButton"); maxButton.setName("InternalFrameTitlePane.maximizeButton"); closeButton.setName("InternalFrameTitlePane.closeButton"); add(menuButton); add(iconButton); add(maxButton); add(closeButton); } protected void installListeners() { super.installListeners(); frame.addPropertyChangeListener(this); addPropertyChangeListener(this); } protected void uninstallListeners() { frame.removePropertyChangeListener(this); removePropertyChangeListener(this); super.uninstallListeners(); } private void updateStyle(JComponent c) { SynthContext context = getContext(this, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { maxIcon = style.getIcon(context,"InternalFrameTitlePane.maximizeIcon"); minIcon = style.getIcon(context,"InternalFrameTitlePane.minimizeIcon"); iconIcon = style.getIcon(context,"InternalFrameTitlePane.iconifyIcon"); closeIcon = style.getIcon(context,"InternalFrameTitlePane.closeIcon"); titleSpacing = style.getInt(context, "InternalFrameTitlePane.titleSpacing", 2); buttonSpacing = style.getInt(context, "InternalFrameTitlePane.buttonSpacing", 2); String alignString = (String)style.get(context, "InternalFrameTitlePane.titleAlignment"); titleAlignment = SwingConstants.LEADING; if (alignString != null) { alignString = alignString.toUpperCase(); if (alignString.equals("TRAILING")) { titleAlignment = SwingConstants.TRAILING; } else if (alignString.equals("CENTER")) { titleAlignment = SwingConstants.CENTER; } } } context.dispose(); } protected void installDefaults() { super.installDefaults(); updateStyle(this); } protected void uninstallDefaults() { SynthContext context = getContext(this, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; JInternalFrame.JDesktopIcon di = frame.getDesktopIcon(); if(di != null && di.getComponentPopupMenu() == systemPopupMenu) { // Release link to systemMenu from the JInternalFrame di.setComponentPopupMenu(null); } super.uninstallDefaults(); } private static class JPopupMenuUIResource extends JPopupMenu implements UIResource { } protected void assembleSystemMenu() { systemPopupMenu = new JPopupMenuUIResource(); addSystemMenuItems(systemPopupMenu); enableActions(); menuButton = createNoFocusButton(); updateMenuIcon(); menuButton.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { try { frame.setSelected(true); } catch(PropertyVetoException pve) { } showSystemMenu(); } }); JPopupMenu p = frame.getComponentPopupMenu(); if (p == null || p instanceof UIResource) { frame.setComponentPopupMenu(systemPopupMenu); } if (frame.getDesktopIcon() != null) { p = frame.getDesktopIcon().getComponentPopupMenu(); if (p == null || p instanceof UIResource) { frame.getDesktopIcon().setComponentPopupMenu(systemPopupMenu); } } setInheritsPopupMenu(true); } protected void addSystemMenuItems(JPopupMenu menu) { // PENDING: this should all be localizable! JMenuItem mi = (JMenuItem)menu.add(restoreAction); mi.setMnemonic('R'); mi = (JMenuItem)menu.add(moveAction); mi.setMnemonic('M'); mi = (JMenuItem)menu.add(sizeAction); mi.setMnemonic('S'); mi = (JMenuItem)menu.add(iconifyAction); mi.setMnemonic('n'); mi = (JMenuItem)menu.add(maximizeAction); mi.setMnemonic('x'); menu.add(new JSeparator()); mi = (JMenuItem)menu.add(closeAction); mi.setMnemonic('C'); } protected void showSystemMenu() { Insets insets = frame.getInsets(); if (!frame.isIcon()) { systemPopupMenu.show(frame, insets.left, getY() + getHeight()); } else { systemPopupMenu.show(menuButton, getX() - insets.left - insets.right, getY() - systemPopupMenu.getPreferredSize().height - insets.bottom - insets.top); } } // SynthInternalFrameTitlePane has no UI, we'll invoke paint on it. public void paintComponent(Graphics g) { SynthContext context = getContext(this); SynthLookAndFeel.update(context, g); context.getPainter().paintInternalFrameTitlePaneBackground(context, g, 0, 0, getWidth(), getHeight()); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { String title = frame.getTitle(); if (title != null) { SynthStyle style = context.getStyle(); g.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND)); g.setFont(style.getFont(context)); // Center text vertically. FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g); int baseline = (getHeight() + fm.getAscent() - fm.getLeading() - fm.getDescent()) / 2; JButton lastButton = null; if (frame.isIconifiable()) { lastButton = iconButton; } else if (frame.isMaximizable()) { lastButton = maxButton; } else if (frame.isClosable()) { lastButton = closeButton; } int maxX; int minX; boolean ltr = SynthLookAndFeel.isLeftToRight(frame); int titleAlignment = this.titleAlignment; if (ltr) { if (lastButton != null) { maxX = lastButton.getX() - titleSpacing; } else { maxX = frame.getWidth() - frame.getInsets().right - titleSpacing; } minX = menuButton.getX() + menuButton.getWidth() + titleSpacing; } else { if (lastButton != null) { minX = lastButton.getX() + lastButton.getWidth() + titleSpacing; } else { minX = frame.getInsets().left + titleSpacing; } maxX = menuButton.getX() - titleSpacing; if (titleAlignment == SwingConstants.LEADING) { titleAlignment = SwingConstants.TRAILING; } else if (titleAlignment == SwingConstants.TRAILING) { titleAlignment = SwingConstants.LEADING; } } String clippedTitle = getTitle(title, fm, maxX - minX); if (clippedTitle == title) { // String fit, align as necessary. if (titleAlignment == SwingConstants.TRAILING) { minX = maxX - style.getGraphicsUtils(context). computeStringWidth(context, g.getFont(), fm, title); } else if (titleAlignment == SwingConstants.CENTER) { int width = style.getGraphicsUtils(context). computeStringWidth(context, g.getFont(), fm, title); minX = Math.max(minX, (getWidth() - width) / 2); minX = Math.min(maxX - width, minX); } } style.getGraphicsUtils(context).paintText( context, g, clippedTitle, minX, baseline - fm.getAscent(), -1); } } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintInternalFrameTitlePaneBorder(context, g, x, y, w, h); } protected LayoutManager createLayout() { SynthContext context = getContext(this); LayoutManager lm = (LayoutManager)style.get(context, "InternalFrameTitlePane.titlePaneLayout"); context.dispose(); return (lm != null) ? lm : new SynthTitlePaneLayout(); } public void propertyChange(PropertyChangeEvent evt) { if (evt.getSource() == this) { if (SynthLookAndFeel.shouldUpdateStyle(evt)) { updateStyle(this); } } else { // Changes for the internal frame if (evt.getPropertyName() == JInternalFrame.FRAME_ICON_PROPERTY) { updateMenuIcon(); } } } /** {@collect.stats} * Resets the menuButton icon to match that of the frame. */ private void updateMenuIcon() { Icon frameIcon = frame.getFrameIcon(); SynthContext context = getContext(this); if (frameIcon != null) { Dimension maxSize = (Dimension)context.getStyle().get(context, "InternalFrameTitlePane.maxFrameIconSize"); int maxWidth = 16; int maxHeight = 16; if (maxSize != null) { maxWidth = maxSize.width; maxHeight = maxSize.height; } if ((frameIcon.getIconWidth() > maxWidth || frameIcon.getIconHeight() > maxHeight) && (frameIcon instanceof ImageIcon)) { frameIcon = new ImageIcon(((ImageIcon)frameIcon). getImage().getScaledInstance(maxWidth, maxHeight, Image.SCALE_SMOOTH)); } } context.dispose(); menuButton.setIcon(frameIcon); } class SynthTitlePaneLayout implements LayoutManager { public void addLayoutComponent(String name, Component c) {} public void removeLayoutComponent(Component c) {} public Dimension preferredLayoutSize(Container c) { return minimumLayoutSize(c); } public Dimension minimumLayoutSize(Container c) { SynthContext context = getContext( SynthInternalFrameTitlePane.this); int width = 0; int height = 0; int buttonCount = 0; Dimension pref; if (frame.isClosable()) { pref = closeButton.getPreferredSize(); width += pref.width; height = Math.max(pref.height, height); buttonCount++; } if (frame.isMaximizable()) { pref = maxButton.getPreferredSize(); width += pref.width; height = Math.max(pref.height, height); buttonCount++; } if (frame.isIconifiable()) { pref = iconButton.getPreferredSize(); width += pref.width; height = Math.max(pref.height, height); buttonCount++; } pref = menuButton.getPreferredSize(); width += pref.width; height = Math.max(pref.height, height); width += Math.max(0, (buttonCount - 1) * buttonSpacing); FontMetrics fm = SynthInternalFrameTitlePane.this.getFontMetrics( getFont()); SynthGraphicsUtils graphicsUtils = context.getStyle(). getGraphicsUtils(context); String frameTitle = frame.getTitle(); int title_w = frameTitle != null ? graphicsUtils. computeStringWidth(context, fm.getFont(), fm, frameTitle) : 0; int title_length = frameTitle != null ? frameTitle.length() : 0; // Leave room for three characters in the title. if (title_length > 3) { int subtitle_w = graphicsUtils.computeStringWidth(context, fm.getFont(), fm, frameTitle.substring(0, 3) + "..."); width += (title_w < subtitle_w) ? title_w : subtitle_w; } else { width += title_w; } height = Math.max(fm.getHeight() + 2, height); width += titleSpacing + titleSpacing; Insets insets = getInsets(); height += insets.top + insets.bottom; width += insets.left + insets.right; context.dispose(); return new Dimension(width, height); } private int center(Component c, Insets insets, int x, boolean trailing) { Dimension pref = c.getPreferredSize(); if (trailing) { x -= pref.width; } c.setBounds(x, insets.top + (getHeight() - insets.top - insets.bottom - pref.height) / 2, pref.width, pref.height); if (pref.width > 0) { if (trailing) { return x - buttonSpacing; } return x + pref.width + buttonSpacing; } return x; } public void layoutContainer(Container c) { Insets insets = c.getInsets(); Dimension pref; if (SynthLookAndFeel.isLeftToRight(frame)) { center(menuButton, insets, insets.left, false); int x = getWidth() - insets.right; if (frame.isClosable()) { x = center(closeButton, insets, x, true); } if (frame.isMaximizable()) { x = center(maxButton, insets, x, true); } if (frame.isIconifiable()) { x = center(iconButton, insets, x, true); } } else { center(menuButton, insets, getWidth() - insets.right, true); int x = insets.left; if (frame.isClosable()) { x = center(closeButton, insets, x, false); } if (frame.isMaximizable()) { x = center(maxButton, insets, x, false); } if (frame.isIconifiable()) { x = center(iconButton, insets, x, false); } } } } private JButton createNoFocusButton() { JButton button = new JButton(); button.setFocusable(false); button.setMargin(new Insets(0,0,0,0)); return button; } }
Java
/* * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.Graphics; import java.awt.Image; import java.awt.Insets; import java.awt.Toolkit; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.text.ParseException; import java.util.ArrayList; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.StringTokenizer; import java.util.regex.PatternSyntaxException; import javax.swing.ImageIcon; import javax.swing.JSplitPane; import javax.swing.SwingConstants; import javax.swing.UIDefaults; import javax.swing.plaf.ColorUIResource; import javax.swing.plaf.DimensionUIResource; import javax.swing.plaf.FontUIResource; import javax.swing.plaf.InsetsUIResource; import javax.swing.plaf.UIResource; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.AttributeList; import org.xml.sax.HandlerBase; import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import com.sun.beans.ObjectHandler; /** {@collect.stats} */ class SynthParser extends HandlerBase { // // Known element names // private static final String ELEMENT_SYNTH = "synth"; private static final String ELEMENT_STYLE = "style"; private static final String ELEMENT_STATE = "state"; private static final String ELEMENT_FONT = "font"; private static final String ELEMENT_COLOR = "color"; private static final String ELEMENT_IMAGE_PAINTER = "imagePainter"; private static final String ELEMENT_PAINTER = "painter"; private static final String ELEMENT_PROPERTY = "property"; private static final String ELEMENT_SYNTH_GRAPHICS = "graphicsUtils"; private static final String ELEMENT_IMAGE_ICON = "imageIcon"; private static final String ELEMENT_BIND = "bind"; private static final String ELEMENT_BIND_KEY = "bindKey"; private static final String ELEMENT_INSETS = "insets"; private static final String ELEMENT_OPAQUE = "opaque"; private static final String ELEMENT_DEFAULTS_PROPERTY = "defaultsProperty"; private static final String ELEMENT_INPUT_MAP = "inputMap"; // // Known attribute names // private static final String ATTRIBUTE_ACTION = "action"; private static final String ATTRIBUTE_ID = "id"; private static final String ATTRIBUTE_IDREF = "idref"; private static final String ATTRIBUTE_CLONE = "clone"; private static final String ATTRIBUTE_VALUE = "value"; private static final String ATTRIBUTE_NAME = "name"; private static final String ATTRIBUTE_STYLE = "style"; private static final String ATTRIBUTE_SIZE = "size"; private static final String ATTRIBUTE_TYPE = "type"; private static final String ATTRIBUTE_TOP = "top"; private static final String ATTRIBUTE_LEFT = "left"; private static final String ATTRIBUTE_BOTTOM = "bottom"; private static final String ATTRIBUTE_RIGHT = "right"; private static final String ATTRIBUTE_KEY = "key"; private static final String ATTRIBUTE_SOURCE_INSETS = "sourceInsets"; private static final String ATTRIBUTE_DEST_INSETS = "destinationInsets"; private static final String ATTRIBUTE_PATH = "path"; private static final String ATTRIBUTE_STRETCH = "stretch"; private static final String ATTRIBUTE_PAINT_CENTER = "paintCenter"; private static final String ATTRIBUTE_METHOD = "method"; private static final String ATTRIBUTE_DIRECTION = "direction"; private static final String ATTRIBUTE_CENTER = "center"; /** {@collect.stats} * Lazily created, used for anything we don't understand. */ private ObjectHandler _handler; /** {@collect.stats} * Indicates the depth of how many elements we've encountered but don't * understand. This is used when forwarding to beans persistance to know * when we hsould stop forwarding. */ private int _depth; /** {@collect.stats} * Factory that new styles are added to. */ private DefaultSynthStyleFactory _factory; /** {@collect.stats} * Array of state infos for the current style. These are pushed to the * style when </style> is received. */ private java.util.List _stateInfos; /** {@collect.stats} * Current style. */ private ParsedSynthStyle _style; /** {@collect.stats} * Current state info. */ private ParsedSynthStyle.StateInfo _stateInfo; /** {@collect.stats} * Bindings for the current InputMap */ private java.util.List _inputMapBindings; /** {@collect.stats} * ID for the input map. This is cached as * the InputMap is created AFTER the inputMapProperty has ended. */ private String _inputMapID; /** {@collect.stats} * Object references outside the scope of persistance. */ private Map<String,Object> _mapping; /** {@collect.stats} * Based URL used to resolve paths. */ private URL _urlResourceBase; /** {@collect.stats} * Based class used to resolve paths. */ private Class<?> _classResourceBase; /** {@collect.stats} * List of ColorTypes. This is populated in startColorType. */ private java.util.List _colorTypes; /** {@collect.stats} * defaultsPropertys are placed here. */ private Map _defaultsMap; /** {@collect.stats} * List of SynthStyle.Painters that will be applied to the current style. */ private java.util.List _stylePainters; /** {@collect.stats} * List of SynthStyle.Painters that will be applied to the current state. */ private java.util.List _statePainters; SynthParser() { _mapping = new HashMap<String,Object>(); _stateInfos = new ArrayList(); _colorTypes = new ArrayList(); _inputMapBindings = new ArrayList(); _stylePainters = new ArrayList(); _statePainters = new ArrayList(); } /** {@collect.stats} * Parses a set of styles from <code>inputStream</code>, adding the * resulting styles to the passed in DefaultSynthStyleFactory. * Resources are resolved either from a URL or from a Class. When calling * this method, one of the URL or the Class must be null but not both at * the same time. * * @param inputStream XML document containing the styles to read * @param factory DefaultSynthStyleFactory that new styles are added to * @param urlResourceBase the URL used to resolve any resources, such as Images * @param classResourceBase the Class used to resolve any resources, such as Images * @param defaultsMap Map that UIDefaults properties are placed in */ public void parse(InputStream inputStream, DefaultSynthStyleFactory factory, URL urlResourceBase, Class<?> classResourceBase, Map defaultsMap) throws ParseException, IllegalArgumentException { if (inputStream == null || factory == null || (urlResourceBase == null && classResourceBase == null)) { throw new IllegalArgumentException( "You must supply an InputStream, StyleFactory and Class or URL"); } assert(!(urlResourceBase != null && classResourceBase != null)); _factory = factory; _classResourceBase = classResourceBase; _urlResourceBase = urlResourceBase; _defaultsMap = defaultsMap; try { try { SAXParser saxParser = SAXParserFactory.newInstance(). newSAXParser(); saxParser.parse(new BufferedInputStream(inputStream), this); } catch (ParserConfigurationException e) { throw new ParseException("Error parsing: " + e, 0); } catch (SAXException se) { throw new ParseException("Error parsing: " + se + " " + se.getException(), 0); } catch (IOException ioe) { throw new ParseException("Error parsing: " + ioe, 0); } } finally { reset(); } } /** {@collect.stats} * Returns the path to a resource. */ private URL getResource(String path) { if (_classResourceBase != null) { return _classResourceBase.getResource(path); } else { try { return new URL(_urlResourceBase, path); } catch (MalformedURLException mue) { return null; } } } /** {@collect.stats} * Clears our internal state. */ private void reset() { _handler = null; _depth = 0; _mapping.clear(); _stateInfos.clear(); _colorTypes.clear(); _statePainters.clear(); _stylePainters.clear(); } /** {@collect.stats} * Returns true if we are forwarding to persistance. */ private boolean isForwarding() { return (_depth > 0); } /** {@collect.stats} * Handles beans persistance. */ private ObjectHandler getHandler() { if (_handler == null) { if (_urlResourceBase != null) { // getHandler() is never called before parse() so it is safe // to create a URLClassLoader with _resourceBase. // // getResource(".") is called to ensure we have the directory // containing the resources in the case the resource base is a // .class file. URL[] urls = new URL[] { getResource(".") }; ClassLoader parent = Thread.currentThread().getContextClassLoader(); ClassLoader urlLoader = new URLClassLoader(urls, parent); _handler = new ObjectHandler(null, urlLoader); } else { _handler = new ObjectHandler(null, _classResourceBase.getClassLoader()); } for (String key : _mapping.keySet()) { _handler.register(key, _mapping.get(key)); } } return _handler; } /** {@collect.stats} * If <code>value</code> is an instance of <code>type</code> it is * returned, otherwise a SAXException is thrown. */ private Object checkCast(Object value, Class type) throws SAXException { if (!type.isInstance(value)) { throw new SAXException("Expected type " + type + " got " + value.getClass()); } return value; } /** {@collect.stats} * Returns an object created with id=key. If the object is not of * type type, this will throw an exception. */ private Object lookup(String key, Class type) throws SAXException { Object value = null; if (_handler != null) { if ((value = _handler.lookup(key)) != null) { return checkCast(value, type); } } value = _mapping.get(key); if (value == null) { throw new SAXException("ID " + key + " has not been defined"); } return checkCast(value, type); } /** {@collect.stats} * Registers an object by name. This will throw an exception if an * object has already been registered under the given name. */ private void register(String key, Object value) throws SAXException { if (key != null) { if (_mapping.get(key) != null || (_handler != null && _handler.lookup(key) != null)) { throw new SAXException("ID " + key + " is already defined"); } if (_handler != null) { _handler.register(key, value); } else { _mapping.put(key, value); } } } /** {@collect.stats} * Convenience method to return the next int, or throw if there are no * more valid ints. */ private int nextInt(StringTokenizer tok, String errorMsg) throws SAXException { if (!tok.hasMoreTokens()) { throw new SAXException(errorMsg); } try { return Integer.parseInt(tok.nextToken()); } catch (NumberFormatException nfe) { throw new SAXException(errorMsg); } } /** {@collect.stats} * Convenience method to return an Insets object. */ private Insets parseInsets(String insets, String errorMsg) throws SAXException { StringTokenizer tokenizer = new StringTokenizer(insets); return new Insets(nextInt(tokenizer, errorMsg), nextInt(tokenizer, errorMsg), nextInt(tokenizer, errorMsg), nextInt(tokenizer, errorMsg)); } // // The following methods are invoked from startElement/stopElement // private void startStyle(AttributeList attributes) throws SAXException { String id = null; _style = null; for(int i = attributes.getLength() - 1; i >= 0; i--) { String key = attributes.getName(i); if (key.equals(ATTRIBUTE_CLONE)) { _style = (ParsedSynthStyle)((ParsedSynthStyle)lookup( attributes.getValue(i), ParsedSynthStyle.class)). clone(); } else if (key.equals(ATTRIBUTE_ID)) { id = attributes.getValue(i); } } if (_style == null) { _style = new ParsedSynthStyle(); } register(id, _style); } private void endStyle() throws SAXException { int size = _stylePainters.size(); if (size > 0) { _style.setPainters((ParsedSynthStyle.PainterInfo[]) _stylePainters.toArray(new ParsedSynthStyle. PainterInfo[size])); _stylePainters.clear(); } size = _stateInfos.size(); if (size > 0) { _style.setStateInfo((ParsedSynthStyle.StateInfo[])_stateInfos. toArray(new ParsedSynthStyle.StateInfo[size])); _stateInfos.clear(); } _style = null; } private void startState(AttributeList attributes) throws SAXException { ParsedSynthStyle.StateInfo stateInfo = null; int state = 0; String id = null; _stateInfo = null; for(int i = attributes.getLength() - 1; i >= 0; i--) { String key = attributes.getName(i); if (key.equals(ATTRIBUTE_ID)) { id = attributes.getValue(i); } else if (key.equals(ATTRIBUTE_IDREF)) { _stateInfo = (ParsedSynthStyle.StateInfo)lookup( attributes.getValue(i), ParsedSynthStyle.StateInfo.class); } else if (key.equals(ATTRIBUTE_CLONE)) { _stateInfo = (ParsedSynthStyle.StateInfo)((ParsedSynthStyle. StateInfo)lookup(attributes.getValue(i), ParsedSynthStyle.StateInfo.class)).clone(); } else if (key.equals(ATTRIBUTE_VALUE)) { StringTokenizer tokenizer = new StringTokenizer( attributes.getValue(i)); while (tokenizer.hasMoreTokens()) { String stateString = tokenizer.nextToken().toUpperCase(). intern(); if (stateString == "ENABLED") { state |= SynthConstants.ENABLED; } else if (stateString == "MOUSE_OVER") { state |= SynthConstants.MOUSE_OVER; } else if (stateString == "PRESSED") { state |= SynthConstants.PRESSED; } else if (stateString == "DISABLED") { state |= SynthConstants.DISABLED; } else if (stateString == "FOCUSED") { state |= SynthConstants.FOCUSED; } else if (stateString == "SELECTED") { state |= SynthConstants.SELECTED; } else if (stateString == "DEFAULT") { state |= SynthConstants.DEFAULT; } else if (stateString != "AND") { throw new SAXException("Unknown state: " + state); } } } } if (_stateInfo == null) { _stateInfo = new ParsedSynthStyle.StateInfo(); } _stateInfo.setComponentState(state); register(id, _stateInfo); _stateInfos.add(_stateInfo); } private void endState() throws SAXException { int size = _statePainters.size(); if (size > 0) { _stateInfo.setPainters((ParsedSynthStyle.PainterInfo[]) _statePainters.toArray(new ParsedSynthStyle. PainterInfo[size])); _statePainters.clear(); } _stateInfo = null; } private void startFont(AttributeList attributes) throws SAXException { Font font = null; int style = Font.PLAIN; int size = 0; String id = null; String name = null; for(int i = attributes.getLength() - 1; i >= 0; i--) { String key = attributes.getName(i); if (key.equals(ATTRIBUTE_ID)) { id = attributes.getValue(i); } else if (key.equals(ATTRIBUTE_IDREF)) { font = (Font)lookup(attributes.getValue(i), Font.class); } else if (key.equals(ATTRIBUTE_NAME)) { name = attributes.getValue(i); } else if (key.equals(ATTRIBUTE_SIZE)) { try { size = Integer.parseInt(attributes.getValue(i)); } catch (NumberFormatException nfe) { throw new SAXException("Invalid font size: " + attributes.getValue(i)); } } else if (key.equals(ATTRIBUTE_STYLE)) { StringTokenizer tok = new StringTokenizer( attributes.getValue(i)); while (tok.hasMoreTokens()) { String token = tok.nextToken().intern(); if (token == "BOLD") { style = ((style | Font.PLAIN) ^ Font.PLAIN) | Font.BOLD; } else if (token == "ITALIC") { style |= Font.ITALIC; } } } } if (font == null) { if (name == null) { throw new SAXException("You must define a name for the font"); } if (size == 0) { throw new SAXException("You must define a size for the font"); } font = new FontUIResource(name, style, size); } else if (name != null || size != 0 || style != Font.PLAIN) { throw new SAXException("Name, size and style are not for use " + "with idref"); } register(id, font); if (_stateInfo != null) { _stateInfo.setFont(font); } else if (_style != null) { _style.setFont(font); } } private void startColor(AttributeList attributes) throws SAXException { Color color = null; String id = null; _colorTypes.clear(); for(int i = attributes.getLength() - 1; i >= 0; i--) { String key = attributes.getName(i); if (key.equals(ATTRIBUTE_ID)) { id = attributes.getValue(i); } else if (key.equals(ATTRIBUTE_IDREF)) { color = (Color)lookup(attributes.getValue(i), Color.class); } else if (key.equals(ATTRIBUTE_NAME)) { } else if (key.equals(ATTRIBUTE_VALUE)) { String value = attributes.getValue(i); if (value.startsWith("#")) { try { int argb; boolean hasAlpha; int length = value.length(); if (length < 8) { // Just RGB, or some portion of it. argb = Integer.decode(value); hasAlpha = false; } else if (length == 8) { // Single character alpha: #ARRGGBB. argb = Integer.decode(value); hasAlpha = true; } else if (length == 9) { // Color has alpha and is of the form // #AARRGGBB. // The following split decoding is mandatory due to // Integer.decode() behavior which won't decode // hexadecimal values higher than #7FFFFFFF. // Thus, when an alpha channel is detected, it is // decoded separately from the RGB channels. int rgb = Integer.decode('#' + value.substring(3, 9)); int a = Integer.decode(value.substring(0, 3)); argb = (a << 24) | rgb; hasAlpha = true; } else { throw new SAXException("Invalid Color value: " + value); } color = new ColorUIResource(new Color(argb, hasAlpha)); } catch (NumberFormatException nfe) { throw new SAXException("Invalid Color value: " +value); } } else { try { color = new ColorUIResource((Color)Color.class. getField(value.toUpperCase()).get(Color.class)); } catch (NoSuchFieldException nsfe) { throw new SAXException("Invalid color name: " + value); } catch (IllegalAccessException iae) { throw new SAXException("Invalid color name: " + value); } } } else if (key.equals(ATTRIBUTE_TYPE)) { StringTokenizer tokenizer = new StringTokenizer( attributes.getValue(i)); while (tokenizer.hasMoreTokens()) { String typeName = tokenizer.nextToken(); int classIndex = typeName.lastIndexOf('.'); Class typeClass; if (classIndex == -1) { typeClass = ColorType.class; classIndex = 0; } else { try { typeClass = Class.forName(typeName.substring( 0, classIndex)); } catch (ClassNotFoundException cnfe) { throw new SAXException("Unknown class: " + typeName.substring(0, classIndex)); } classIndex++; } try { _colorTypes.add((ColorType)checkCast(typeClass. getField(typeName.substring(classIndex, typeName.length() - classIndex)). get(typeClass), ColorType.class)); } catch (NoSuchFieldException nsfe) { throw new SAXException("Unable to find color type: " + typeName); } catch (IllegalAccessException iae) { throw new SAXException("Unable to find color type: " + typeName); } } } } if (color == null) { throw new SAXException("color: you must specificy a value"); } register(id, color); if (_stateInfo != null && _colorTypes.size() > 0) { Color[] colors = _stateInfo.getColors(); int max = 0; for (int counter = _colorTypes.size() - 1; counter >= 0; counter--) { max = Math.max(max, ((ColorType)_colorTypes.get(counter)). getID()); } if (colors == null || colors.length <= max) { Color[] newColors = new Color[max + 1]; if (colors != null) { System.arraycopy(colors, 0, newColors, 0, colors.length); } colors = newColors; } for (int counter = _colorTypes.size() - 1; counter >= 0; counter--) { colors[((ColorType)_colorTypes.get(counter)).getID()] = color; } _stateInfo.setColors(colors); } } private void startProperty(AttributeList attributes, Object property) throws SAXException { Object value = null; Object key = null; // Type of the value: 0=idref, 1=boolean, 2=dimension, 3=insets, // 4=integer,5=string int iType = 0; String aValue = null; for(int i = attributes.getLength() - 1; i >= 0; i--) { String aName = attributes.getName(i); if (aName.equals(ATTRIBUTE_TYPE)) { String type = attributes.getValue(i).toUpperCase(); if (type.equals("IDREF")) { iType = 0; } else if (type.equals("BOOLEAN")) { iType = 1; } else if (type.equals("DIMENSION")) { iType = 2; } else if (type.equals("INSETS")) { iType = 3; } else if (type.equals("INTEGER")) { iType = 4; } else if (type.equals("STRING")) { iType = 5; } else { throw new SAXException(property + " unknown type, use" + "idref, boolean, dimension, insets or integer"); } } else if (aName.equals(ATTRIBUTE_VALUE)) { aValue = attributes.getValue(i); } else if (aName.equals(ATTRIBUTE_KEY)) { key = attributes.getValue(i); } } if (aValue != null) { switch (iType) { case 0: // idref value = lookup(aValue, Object.class); break; case 1: // boolean if (aValue.toUpperCase().equals("TRUE")) { value = Boolean.TRUE; } else { value = Boolean.FALSE; } break; case 2: // dimension StringTokenizer tok = new StringTokenizer(aValue); value = new DimensionUIResource( nextInt(tok, "Invalid dimension"), nextInt(tok, "Invalid dimension")); break; case 3: // insets value = parseInsets(aValue, property + " invalid insets"); break; case 4: // integer try { value = new Integer(Integer.parseInt(aValue)); } catch (NumberFormatException nfe) { throw new SAXException(property + " invalid value"); } break; case 5: //string value = aValue; break; } } if (value == null || key == null) { throw new SAXException(property + ": you must supply a " + "key and value"); } if (property == ELEMENT_DEFAULTS_PROPERTY) { _defaultsMap.put(key, value); } else if (_stateInfo != null) { if (_stateInfo.getData() == null) { _stateInfo.setData(new HashMap()); } _stateInfo.getData().put(key, value); } else if (_style != null) { if (_style.getData() == null) { _style.setData(new HashMap()); } _style.getData().put(key, value); } } private void startGraphics(AttributeList attributes) throws SAXException { SynthGraphicsUtils graphics = null; for(int i = attributes.getLength() - 1; i >= 0; i--) { String key = attributes.getName(i); if (key.equals(ATTRIBUTE_IDREF)) { graphics = (SynthGraphicsUtils)lookup(attributes.getValue(i), SynthGraphicsUtils.class); } } if (graphics == null) { throw new SAXException("graphicsUtils: you must supply an idref"); } if (_style != null) { _style.setGraphicsUtils(graphics); } } private void startInsets(AttributeList attributes) throws SAXException { int top = 0; int bottom = 0; int left = 0; int right = 0; Insets insets = null; String id = null; for(int i = attributes.getLength() - 1; i >= 0; i--) { String key = attributes.getName(i); try { if (key.equals(ATTRIBUTE_IDREF)) { insets = (Insets)lookup(attributes.getValue(i), Insets.class); } else if (key.equals(ATTRIBUTE_ID)) { id = attributes.getValue(i); } else if (key.equals(ATTRIBUTE_TOP)) { top = Integer.parseInt(attributes.getValue(i)); } else if (key.equals(ATTRIBUTE_LEFT)) { left = Integer.parseInt(attributes.getValue(i)); } else if (key.equals(ATTRIBUTE_BOTTOM)) { bottom = Integer.parseInt(attributes.getValue(i)); } else if (key.equals(ATTRIBUTE_RIGHT)) { right = Integer.parseInt(attributes.getValue(i)); } } catch (NumberFormatException nfe) { throw new SAXException("insets: bad integer value for " + attributes.getValue(i)); } } if (insets == null) { insets = new InsetsUIResource(top, left, bottom, right); } register(id, insets); if (_style != null) { _style.setInsets(insets); } } private void startBind(AttributeList attributes) throws SAXException { ParsedSynthStyle style = null; String path = null; int type = -1; for(int i = attributes.getLength() - 1; i >= 0; i--) { String key = attributes.getName(i); if (key.equals(ATTRIBUTE_STYLE)) { style = (ParsedSynthStyle)lookup(attributes.getValue(i), ParsedSynthStyle.class); } else if (key.equals(ATTRIBUTE_TYPE)) { String typeS = attributes.getValue(i).toUpperCase(); if (typeS.equals("NAME")) { type = DefaultSynthStyleFactory.NAME; } else if (typeS.equals("REGION")) { type = DefaultSynthStyleFactory.REGION; } else { throw new SAXException("bind: unknown type " + typeS); } } else if (key.equals(ATTRIBUTE_KEY)) { path = attributes.getValue(i); } } if (style == null || path == null || type == -1) { throw new SAXException("bind: you must specify a style, type " + "and key"); } try { _factory.addStyle(style, path, type); } catch (PatternSyntaxException pse) { throw new SAXException("bind: " + path + " is not a valid " + "regular expression"); } } private void startPainter(AttributeList attributes, String type) throws SAXException { Insets sourceInsets = null; Insets destInsets = null; String path = null; boolean paintCenter = true; boolean stretch = true; SynthPainter painter = null; String method = null; String id = null; int direction = -1; boolean center = false; boolean stretchSpecified = false; boolean paintCenterSpecified = false; for(int i = attributes.getLength() - 1; i >= 0; i--) { String key = attributes.getName(i); String value = attributes.getValue(i); if (key.equals(ATTRIBUTE_ID)) { id = value; } else if (key.equals(ATTRIBUTE_METHOD)) { method = value.toLowerCase(Locale.ENGLISH); } else if (key.equals(ATTRIBUTE_IDREF)) { painter = (SynthPainter)lookup(value, SynthPainter.class); } else if (key.equals(ATTRIBUTE_PATH)) { path = value; } else if (key.equals(ATTRIBUTE_SOURCE_INSETS)) { sourceInsets = parseInsets(value, type + ": sourceInsets must be top left bottom right"); } else if (key.equals(ATTRIBUTE_DEST_INSETS)) { destInsets = parseInsets(value, type + ": destinationInsets must be top left bottom right"); } else if (key.equals(ATTRIBUTE_PAINT_CENTER)) { paintCenter = value.toLowerCase().equals("true"); paintCenterSpecified = true; } else if (key.equals(ATTRIBUTE_STRETCH)) { stretch = value.toLowerCase().equals("true"); stretchSpecified = true; } else if (key.equals(ATTRIBUTE_DIRECTION)) { value = value.toUpperCase().intern(); if (value == "EAST") { direction = SwingConstants.EAST; } else if (value == "NORTH") { direction = SwingConstants.NORTH; } else if (value == "SOUTH") { direction = SwingConstants.SOUTH; } else if (value == "WEST") { direction = SwingConstants.WEST; } else if (value == "TOP") { direction = SwingConstants.TOP; } else if (value == "LEFT") { direction = SwingConstants.LEFT; } else if (value == "BOTTOM") { direction = SwingConstants.BOTTOM; } else if (value == "RIGHT") { direction = SwingConstants.RIGHT; } else if (value == "HORIZONTAL") { direction = SwingConstants.HORIZONTAL; } else if (value == "VERTICAL") { direction = SwingConstants.VERTICAL; } else if (value == "HORIZONTAL_SPLIT") { direction = JSplitPane.HORIZONTAL_SPLIT; } else if (value == "VERTICAL_SPLIT") { direction = JSplitPane.VERTICAL_SPLIT; } else { throw new SAXException(type + ": unknown direction"); } } else if (key.equals(ATTRIBUTE_CENTER)) { center = value.toLowerCase().equals("true"); } } if (painter == null) { if (type == ELEMENT_PAINTER) { throw new SAXException(type + ": you must specify an idref"); } if (sourceInsets == null && !center) { throw new SAXException( "property: you must specify sourceInsets"); } if (path == null) { throw new SAXException("property: you must specify a path"); } if (center && (sourceInsets != null || destInsets != null || paintCenterSpecified || stretchSpecified)) { throw new SAXException("The attributes: sourceInsets, " + "destinationInsets, paintCenter and stretch " + " are not legal when center is true"); } painter = new ImagePainter(!stretch, paintCenter, sourceInsets, destInsets, getResource(path), center); } register(id, painter); if (_stateInfo != null) { addPainterOrMerge(_statePainters, method, painter, direction); } else if (_style != null) { addPainterOrMerge(_stylePainters, method, painter, direction); } } private void addPainterOrMerge(java.util.List painters, String method, SynthPainter painter, int direction) { ParsedSynthStyle.PainterInfo painterInfo; painterInfo = new ParsedSynthStyle.PainterInfo(method, painter, direction); for (Object infoObject: painters) { ParsedSynthStyle.PainterInfo info; info = (ParsedSynthStyle.PainterInfo) infoObject; if (painterInfo.equalsPainter(info)) { info.addPainter(painter); return; } } painters.add(painterInfo); } private void startImageIcon(AttributeList attributes) throws SAXException { String path = null; String id = null; for(int i = attributes.getLength() - 1; i >= 0; i--) { String key = attributes.getName(i); if (key.equals(ATTRIBUTE_ID)) { id = attributes.getValue(i); } else if (key.equals(ATTRIBUTE_PATH)) { path = attributes.getValue(i); } } if (path == null) { throw new SAXException("imageIcon: you must specify a path"); } register(id, new LazyImageIcon(getResource(path))); } private void startOpaque(AttributeList attributes) throws SAXException { if (_style != null) { _style.setOpaque(true); for(int i = attributes.getLength() - 1; i >= 0; i--) { String key = attributes.getName(i); if (key.equals(ATTRIBUTE_VALUE)) { _style.setOpaque("true".equals(attributes.getValue(i). toLowerCase())); } } } } private void startInputMap(AttributeList attributes) throws SAXException { _inputMapBindings.clear(); _inputMapID = null; if (_style != null) { for(int i = attributes.getLength() - 1; i >= 0; i--) { String key = attributes.getName(i); if (key.equals(ATTRIBUTE_ID)) { _inputMapID = attributes.getValue(i); } } } } private void endInputMap() throws SAXException { if (_inputMapID != null) { register(_inputMapID, new UIDefaults.LazyInputMap( _inputMapBindings.toArray(new Object[_inputMapBindings. size()]))); } _inputMapBindings.clear(); _inputMapID = null; } private void startBindKey(AttributeList attributes) throws SAXException { if (_inputMapID == null) { // Not in an inputmap, bail. return; } if (_style != null) { String key = null; String value = null; for(int i = attributes.getLength() - 1; i >= 0; i--) { String aKey = attributes.getName(i); if (aKey.equals(ATTRIBUTE_KEY)) { key = attributes.getValue(i); } else if (aKey.equals(ATTRIBUTE_ACTION)) { value = attributes.getValue(i); } } if (key == null || value == null) { throw new SAXException( "bindKey: you must supply a key and action"); } _inputMapBindings.add(key); _inputMapBindings.add(value); } } // // SAX methods, these forward to the ObjectHandler if we don't know // the element name. // public InputSource resolveEntity(String publicId, String systemId) throws SAXException { if (isForwarding()) { return getHandler().resolveEntity(publicId, systemId); } return null; } public void notationDecl(String name, String publicId, String systemId) { if (isForwarding()) { getHandler().notationDecl(name, publicId, systemId); } } public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName) { if (isForwarding()) { getHandler().unparsedEntityDecl(name, publicId, systemId, notationName); } } public void setDocumentLocator(Locator locator) { if (isForwarding()) { getHandler().setDocumentLocator(locator); } } public void startDocument() throws SAXException { if (isForwarding()) { getHandler().startDocument(); } } public void endDocument() throws SAXException { if (isForwarding()) { getHandler().endDocument(); } } public void startElement(String name, AttributeList attributes) throws SAXException { name = name.intern(); if (name == ELEMENT_STYLE) { startStyle(attributes); } else if (name == ELEMENT_STATE) { startState(attributes); } else if (name == ELEMENT_FONT) { startFont(attributes); } else if (name == ELEMENT_COLOR) { startColor(attributes); } else if (name == ELEMENT_PAINTER) { startPainter(attributes, name); } else if (name == ELEMENT_IMAGE_PAINTER) { startPainter(attributes, name); } else if (name == ELEMENT_PROPERTY) { startProperty(attributes, ELEMENT_PROPERTY); } else if (name == ELEMENT_DEFAULTS_PROPERTY) { startProperty(attributes, ELEMENT_DEFAULTS_PROPERTY); } else if (name == ELEMENT_SYNTH_GRAPHICS) { startGraphics(attributes); } else if (name == ELEMENT_INSETS) { startInsets(attributes); } else if (name == ELEMENT_BIND) { startBind(attributes); } else if (name == ELEMENT_BIND_KEY) { startBindKey(attributes); } else if (name == ELEMENT_IMAGE_ICON) { startImageIcon(attributes); } else if (name == ELEMENT_OPAQUE) { startOpaque(attributes); } else if (name == ELEMENT_INPUT_MAP) { startInputMap(attributes); } else if (name != ELEMENT_SYNTH) { if (_depth++ == 0) { getHandler().reset(); } getHandler().startElement(name, attributes); } } public void endElement(String name) throws SAXException { if (isForwarding()) { getHandler().endElement(name); _depth--; if (!isForwarding()) { getHandler().reset(); } } else { name = name.intern(); if (name == ELEMENT_STYLE) { endStyle(); } else if (name == ELEMENT_STATE) { endState(); } else if (name == ELEMENT_INPUT_MAP) { endInputMap(); } } } public void characters(char ch[], int start, int length) throws SAXException { if (isForwarding()) { getHandler().characters(ch, start, length); } } public void ignorableWhitespace (char ch[], int start, int length) throws SAXException { if (isForwarding()) { getHandler().ignorableWhitespace(ch, start, length); } } public void processingInstruction(String target, String data) throws SAXException { if (isForwarding()) { getHandler().processingInstruction(target, data); } } public void warning(SAXParseException e) throws SAXException { if (isForwarding()) { getHandler().warning(e); } } public void error(SAXParseException e) throws SAXException { if (isForwarding()) { getHandler().error(e); } } public void fatalError(SAXParseException e) throws SAXException { if (isForwarding()) { getHandler().fatalError(e); } throw e; } /** {@collect.stats} * ImageIcon that lazily loads the image until needed. */ private static class LazyImageIcon extends ImageIcon implements UIResource { private URL location; public LazyImageIcon(URL location) { super(); this.location = location; } public void paintIcon(Component c, Graphics g, int x, int y) { if (getImage() != null) { super.paintIcon(c, g, x, y); } } public int getIconWidth() { if (getImage() != null) { return super.getIconWidth(); } return 0; } public int getIconHeight() { if (getImage() != null) { return super.getIconHeight(); } return 0; } public Image getImage() { if (location != null) { setImage(Toolkit.getDefaultToolkit().getImage(location)); location = null; } return super.getImage(); } } }
Java
/* * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import java.awt.geom.AffineTransform; import javax.swing.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.BasicProgressBarUI; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import sun.swing.plaf.synth.SynthUI; import sun.swing.SwingUtilities2; /** {@collect.stats} * Synth's ProgressBarUI. * * @author Joshua Outwater */ class SynthProgressBarUI extends BasicProgressBarUI implements SynthUI, PropertyChangeListener { private SynthStyle style; private int progressPadding; private boolean rotateText; // added for Nimbus LAF private boolean paintOutsideClip; private boolean tileWhenIndeterminate; //whether to tile indeterminate painting private int tileWidth; //the width of each tile public static ComponentUI createUI(JComponent x) { return new SynthProgressBarUI(); } @Override protected void installListeners() { super.installListeners(); progressBar.addPropertyChangeListener(this); } @Override protected void uninstallListeners() { super.uninstallListeners(); progressBar.removePropertyChangeListener(this); } @Override protected void installDefaults() { updateStyle(progressBar); } private void updateStyle(JProgressBar c) { SynthContext context = getContext(c, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); setCellLength(style.getInt(context, "ProgressBar.cellLength", 1)); setCellSpacing(style.getInt(context, "ProgressBar.cellSpacing", 0)); progressPadding = style.getInt(context, "ProgressBar.progressPadding", 0); paintOutsideClip = style.getBoolean(context, "ProgressBar.paintOutsideClip", false); rotateText = style.getBoolean(context, "ProgressBar.rotateText", false); tileWhenIndeterminate = style.getBoolean(context, "ProgressBar.tileWhenIndeterminate", false); tileWidth = style.getInt(context, "ProgressBar.tileWidth", 15); // handle scaling for sizeVarients for special case components. The // key "JComponent.sizeVariant" scales for large/small/mini // components are based on Apples LAF String scaleKey = (String)progressBar.getClientProperty( "JComponent.sizeVariant"); if (scaleKey != null){ if ("large".equals(scaleKey)){ tileWidth *= 1.15; } else if ("small".equals(scaleKey)){ tileWidth *= 0.857; } else if ("mini".equals(scaleKey)){ tileWidth *= 0.784; } } context.dispose(); } @Override protected void uninstallDefaults() { SynthContext context = getContext(progressBar, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } @Override public int getBaseline(JComponent c, int width, int height) { super.getBaseline(c, width, height); if (progressBar.isStringPainted() && progressBar.getOrientation() == JProgressBar.HORIZONTAL) { SynthContext context = getContext(c); Font font = context.getStyle().getFont(context); FontMetrics metrics = progressBar.getFontMetrics(font); context.dispose(); return (height - metrics.getAscent() - metrics.getDescent()) / 2 + metrics.getAscent(); } return -1; } @Override protected Rectangle getBox(Rectangle r) { if (tileWhenIndeterminate) { return SwingUtilities.calculateInnerArea(progressBar, r); } else { return super.getBox(r); } } @Override protected void setAnimationIndex(int newValue) { if (paintOutsideClip) { if (getAnimationIndex() == newValue) { return; } super.setAnimationIndex(newValue); progressBar.repaint(); } else { super.setAnimationIndex(newValue); } } @Override public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintProgressBarBackground(context, g, 0, 0, c.getWidth(), c.getHeight(), progressBar.getOrientation()); paint(context, g); context.dispose(); } @Override public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { JProgressBar pBar = (JProgressBar)context.getComponent(); int x = 0, y = 0, width = 0, height = 0; if (!pBar.isIndeterminate()) { Insets pBarInsets = pBar.getInsets(); double percentComplete = pBar.getPercentComplete(); if (percentComplete != 0.0) { if (pBar.getOrientation() == JProgressBar.HORIZONTAL) { x = pBarInsets.left + progressPadding; y = pBarInsets.top + progressPadding; width = (int)(percentComplete * (pBar.getWidth() - (pBarInsets.left + progressPadding + pBarInsets.right + progressPadding))); height = pBar.getHeight() - (pBarInsets.top + progressPadding + pBarInsets.bottom + progressPadding); if (!SynthLookAndFeel.isLeftToRight(pBar)) { x = pBar.getWidth() - pBarInsets.right - width - progressPadding; } } else { // JProgressBar.VERTICAL x = pBarInsets.left + progressPadding; width = pBar.getWidth() - (pBarInsets.left + progressPadding + pBarInsets.right + progressPadding); height = (int)(percentComplete * (pBar.getHeight() - (pBarInsets.top + progressPadding + pBarInsets.bottom + progressPadding))); y = pBar.getHeight() - pBarInsets.bottom - height - progressPadding; // When the progress bar is vertical we always paint // from bottom to top, not matter what the component // orientation is. } } } else { boxRect = getBox(boxRect); x = boxRect.x + progressPadding; y = boxRect.y + progressPadding; width = boxRect.width - progressPadding - progressPadding; height = boxRect.height - progressPadding - progressPadding; } //if tiling and indeterminate, then paint the progress bar foreground a //bit wider than it should be. Shift as needed to ensure that there is //an animated effect if (tileWhenIndeterminate && pBar.isIndeterminate()) { double percentComplete = (double)getAnimationIndex() / (double)getFrameCount(); int offset = (int)(percentComplete * tileWidth); Shape clip = g.getClip(); g.clipRect(x, y, width, height); if (pBar.getOrientation() == JProgressBar.HORIZONTAL) { //paint each tile horizontally for (int i=x-tileWidth+offset; i<=width; i+=tileWidth) { context.getPainter().paintProgressBarForeground( context, g, i, y, tileWidth, height, pBar.getOrientation()); } } else { //JProgressBar.VERTICAL //paint each tile vertically for (int i=y-offset; i<height+tileWidth; i+=tileWidth) { context.getPainter().paintProgressBarForeground( context, g, x, i, width, tileWidth, pBar.getOrientation()); } } g.setClip(clip); } else { context.getPainter().paintProgressBarForeground(context, g, x, y, width, height, pBar.getOrientation()); } if (pBar.isStringPainted()) { paintText(context, g, pBar.getString()); } } protected void paintText(SynthContext context, Graphics g, String title) { if (progressBar.isStringPainted()) { SynthStyle style = context.getStyle(); Font font = style.getFont(context); FontMetrics fm = SwingUtilities2.getFontMetrics( progressBar, g, font); int strLength = style.getGraphicsUtils(context). computeStringWidth(context, font, fm, title); Rectangle bounds = progressBar.getBounds(); if (rotateText && progressBar.getOrientation() == JProgressBar.VERTICAL){ Graphics2D g2 = (Graphics2D)g; // Calculate the position for the text. Point textPos; AffineTransform rotation; if (progressBar.getComponentOrientation().isLeftToRight()){ rotation = AffineTransform.getRotateInstance(-Math.PI/2); textPos = new Point( (bounds.width+fm.getAscent()-fm.getDescent())/2, (bounds.height+strLength)/2); } else { rotation = AffineTransform.getRotateInstance(Math.PI/2); textPos = new Point( (bounds.width-fm.getAscent()+fm.getDescent())/2, (bounds.height-strLength)/2); } // Progress bar isn't wide enough for the font. Don't paint it. if (textPos.x < 0) { return; } // Paint the text. font = font.deriveFont(rotation); g2.setFont(font); g2.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND)); style.getGraphicsUtils(context).paintText(context, g, title, textPos.x, textPos.y, -1); } else { // Calculate the bounds for the text. Rectangle textRect = new Rectangle( (bounds.width / 2) - (strLength / 2), (bounds.height - (fm.getAscent() + fm.getDescent())) / 2, 0, 0); // Progress bar isn't tall enough for the font. Don't paint it. if (textRect.y < 0) { return; } // Paint the text. g.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND)); g.setFont(font); style.getGraphicsUtils(context).paintText(context, g, title, textRect.x, textRect.y, -1); } } } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintProgressBarBorder(context, g, x, y, w, h, progressBar.getOrientation()); } public void propertyChange(PropertyChangeEvent e) { if (SynthLookAndFeel.shouldUpdateStyle(e) || "indeterminate".equals(e.getPropertyName())) { updateStyle((JProgressBar)e.getSource()); } } @Override public Dimension getPreferredSize(JComponent c) { Dimension size = null; Insets border = progressBar.getInsets(); FontMetrics fontSizer = progressBar.getFontMetrics(progressBar.getFont()); String progString = progressBar.getString(); int stringHeight = fontSizer.getHeight() + fontSizer.getDescent(); if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { size = new Dimension(getPreferredInnerHorizontal()); if (progressBar.isStringPainted()) { // adjust the height if necessary to make room for the string if (stringHeight > size.height) { size.height = stringHeight; } // adjust the width if necessary to make room for the string int stringWidth = SwingUtilities2.stringWidth( progressBar, fontSizer, progString); if (stringWidth > size.width) { size.width = stringWidth; } } } else { size = new Dimension(getPreferredInnerVertical()); if (progressBar.isStringPainted()) { // make sure the width is big enough for the string if (stringHeight > size.width) { size.width = stringHeight; } // make sure the height is big enough for the string int stringWidth = SwingUtilities2.stringWidth( progressBar, fontSizer, progString); if (stringWidth > size.height) { size.height = stringWidth; } } } // handle scaling for sizeVarients for special case components. The // key "JComponent.sizeVariant" scales for large/small/mini // components are based on Apples LAF String scaleKey = (String)progressBar.getClientProperty( "JComponent.sizeVariant"); if (scaleKey != null){ if ("large".equals(scaleKey)){ size.width *= 1.15f; size.height *= 1.15f; } else if ("small".equals(scaleKey)){ size.width *= 0.90f; size.height *= 0.90f; } else if ("mini".equals(scaleKey)){ size.width *= 0.784f; size.height *= 0.784f; } } size.width += border.left + border.right; size.height += border.top + border.bottom; return size; } }
Java
/* * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; /** {@collect.stats} * A typesafe enumeration of colors that can be fetched from a style. * <p> * Each <code>SynthStyle</code> has a set of <code>ColorType</code>s that * are accessed by way of the * {@link SynthStyle#getColor(SynthContext, ColorType)} method. * <code>SynthStyle</code>'s <code>installDefaults</code> will install * the <code>FOREGROUND</code> color * as the foreground of * the Component, and the <code>BACKGROUND</code> color to the background of * the component (assuming that you have not explicitly specified a * foreground and background color). Some components * support more color based properties, for * example <code>JList</code> has the property * <code>selectionForeground</code> which will be mapped to * <code>FOREGROUND</code> with a component state of * <code>SynthConstants.SELECTED</code>. * <p> * The following example shows a custom <code>SynthStyle</code> that returns * a red Color for the <code>DISABLED</code> state, otherwise a black color. * <pre> * class MyStyle extends SynthStyle { * private Color disabledColor = new ColorUIResource(Color.RED); * private Color color = new ColorUIResource(Color.BLACK); * protected Color getColorForState(SynthContext context, ColorType type){ * if (context.getComponentState() == SynthConstants.DISABLED) { * return disabledColor; * } * return color; * } * } * </pre> * * @since 1.5 * @author Scott Violet */ public class ColorType { /** {@collect.stats} * ColorType for the foreground of a region. */ public static final ColorType FOREGROUND = new ColorType("Foreground"); /** {@collect.stats} * ColorType for the background of a region. */ public static final ColorType BACKGROUND = new ColorType("Background"); /** {@collect.stats} * ColorType for the foreground of a region. */ public static final ColorType TEXT_FOREGROUND = new ColorType( "TextForeground"); /** {@collect.stats} * ColorType for the background of a region. */ public static final ColorType TEXT_BACKGROUND =new ColorType( "TextBackground"); /** {@collect.stats} * ColorType for the focus. */ public static final ColorType FOCUS = new ColorType("Focus"); /** {@collect.stats} * Maximum number of <code>ColorType</code>s. */ public static final int MAX_COUNT; private static int nextID; private String description; private int index; static { MAX_COUNT = Math.max(FOREGROUND.getID(), Math.max( BACKGROUND.getID(), FOCUS.getID())) + 1; } /** {@collect.stats} * Creates a new ColorType with the specified description. * * @param description String description of the ColorType. */ protected ColorType(String description) { if (description == null) { throw new NullPointerException( "ColorType must have a valid description"); } this.description = description; synchronized(ColorType.class) { this.index = nextID++; } } /** {@collect.stats} * Returns a unique id, as an integer, for this ColorType. * * @return a unique id, as an integer, for this ColorType. */ public final int getID() { return index; } /** {@collect.stats} * Returns the textual description of this <code>ColorType</code>. * This is the same value that the <code>ColorType</code> was created * with. * * @return the description of the string */ public String toString() { return description; } }
Java
/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.*; import javax.swing.plaf.basic.BasicHTML; import javax.swing.plaf.basic.BasicToolTipUI; import javax.swing.plaf.ComponentUI; import javax.swing.text.View; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Synth's ToolTipUI. * * @author Joshua Outwater */ class SynthToolTipUI extends BasicToolTipUI implements PropertyChangeListener, SynthUI { private SynthStyle style; public static ComponentUI createUI(JComponent c) { return new SynthToolTipUI(); } protected void installDefaults(JComponent c) { updateStyle(c); } private void updateStyle(JComponent c) { SynthContext context = getContext(c, ENABLED); style = SynthLookAndFeel.updateStyle(context, this); context.dispose(); } protected void uninstallDefaults(JComponent c) { SynthContext context = getContext(c, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; } protected void installListeners(JComponent c) { c.addPropertyChangeListener(this); } protected void uninstallListeners(JComponent c) { c.removePropertyChangeListener(this); } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { JComponent comp = ((JToolTip)c).getComponent(); if (comp != null && !comp.isEnabled()) { return DISABLED; } return SynthLookAndFeel.getComponentState(c); } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintToolTipBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintToolTipBorder(context, g, x, y, w, h); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { JToolTip tip = (JToolTip)context.getComponent(); String tipText = tip.getToolTipText(); 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); } } public Dimension getPreferredSize(JComponent c) { SynthContext context = getContext(c); Insets insets = c.getInsets(); Dimension prefSize = new Dimension(insets.left+insets.right, insets.top+insets.bottom); String text = ((JToolTip)c).getTipText(); if (text != null) { View v = (c != null) ? (View) c.getClientProperty("html") : null; if (v != null) { prefSize.width += (int) v.getPreferredSpan(View.X_AXIS); prefSize.height += (int) v.getPreferredSpan(View.Y_AXIS); } else { Font font = context.getStyle().getFont(context); FontMetrics fm = c.getFontMetrics(font); prefSize.width += context.getStyle().getGraphicsUtils(context). computeStringWidth(context, font, fm, text); prefSize.height += fm.getHeight(); } } context.dispose(); return prefSize; } public void propertyChange(PropertyChangeEvent e) { if (SynthLookAndFeel.shouldUpdateStyle(e)) { updateStyle((JToolTip)e.getSource()); } String name = e.getPropertyName(); if (name.equals("tiptext") || "font".equals(name) || "foreground".equals(name)) { // remove the old html view client property if one // existed, and install a new one if the text installed // into the JLabel is html source. JToolTip tip = ((JToolTip) e.getSource()); String text = tip.getTipText(); BasicHTML.updateRenderer(tip, text); } } }
Java
/* * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import java.awt.event.*; import java.beans.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import javax.swing.border.*; import java.util.Arrays; import java.util.ArrayList; import sun.swing.plaf.synth.SynthUI; import sun.swing.MenuItemLayoutHelper; /** {@collect.stats} * Synth's MenuUI. * * @author Georges Saab * @author David Karlton * @author Arnaud Weber */ class SynthMenuUI extends BasicMenuUI implements PropertyChangeListener, SynthUI { private SynthStyle style; private SynthStyle accStyle; private String acceleratorDelimiter; public static ComponentUI createUI(JComponent x) { return new SynthMenuUI(); } protected void installDefaults() { updateStyle(menuItem); } protected void installListeners() { super.installListeners(); menuItem.addPropertyChangeListener(this); } private void updateStyle(JMenuItem mi) { SynthStyle oldStyle = style; SynthContext context = getContext(mi, ENABLED); style = SynthLookAndFeel.updateStyle(context, this); if (oldStyle != style) { String prefix = getPropertyPrefix(); defaultTextIconGap = style.getInt( context, prefix + ".textIconGap", 4); if (menuItem.getMargin() == null || (menuItem.getMargin() instanceof UIResource)) { Insets insets = (Insets)style.get(context, prefix + ".margin"); if (insets == null) { // Some places assume margins are non-null. insets = SynthLookAndFeel.EMPTY_UIRESOURCE_INSETS; } menuItem.setMargin(insets); } acceleratorDelimiter = style.getString(context, prefix + ".acceleratorDelimiter", "+"); if (MenuItemLayoutHelper.useCheckAndArrow(menuItem)) { checkIcon = style.getIcon(context, prefix + ".checkIcon"); arrowIcon = style.getIcon(context, prefix + ".arrowIcon"); } else { // Not needed in this case checkIcon = null; arrowIcon = null; } ((JMenu)menuItem).setDelay(style.getInt(context, prefix + ".delay", 200)); if (oldStyle != null) { uninstallKeyboardActions(); installKeyboardActions(); } } context.dispose(); SynthContext accContext = getContext(mi, Region.MENU_ITEM_ACCELERATOR, ENABLED); accStyle = SynthLookAndFeel.updateStyle(accContext, this); accContext.dispose(); } public void uninstallUI(JComponent c) { super.uninstallUI(c); // Remove values from the parent's Client Properties. JComponent p = MenuItemLayoutHelper.getMenuItemParent((JMenuItem) c); if (p != null) { p.putClientProperty( SynthMenuItemLayoutHelper.MAX_ACC_OR_ARROW_WIDTH, null); } } protected void uninstallDefaults() { SynthContext context = getContext(menuItem, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; SynthContext accContext = getContext(menuItem, Region.MENU_ITEM_ACCELERATOR, ENABLED); accStyle.uninstallDefaults(accContext); accContext.dispose(); accStyle = null; super.uninstallDefaults(); } protected void uninstallListeners() { super.uninstallListeners(); menuItem.removePropertyChangeListener(this); } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } SynthContext getContext(JComponent c, int state) { Region region = getRegion(c); return SynthContext.getContext(SynthContext.class, c, region, style, state); } public SynthContext getContext(JComponent c, Region region) { return getContext(c, region, getComponentState(c, region)); } private SynthContext getContext(JComponent c, Region region, int state) { return SynthContext.getContext(SynthContext.class, c, region, accStyle, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { int state; if (!c.isEnabled()) { return DISABLED; } if (menuItem.isArmed()) { state = MOUSE_OVER; } else { state = SynthLookAndFeel.getComponentState(c); } if (menuItem.isSelected()) { state |= SELECTED; } return state; } private int getComponentState(JComponent c, Region region) { return getComponentState(c); } protected Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap) { SynthContext context = getContext(c); SynthContext accContext = getContext(c, Region.MENU_ITEM_ACCELERATOR); Dimension value = SynthGraphicsUtils.getPreferredMenuItemSize( context, accContext, c, checkIcon, arrowIcon, defaultTextIconGap, acceleratorDelimiter, MenuItemLayoutHelper.useCheckAndArrow(menuItem), getPropertyPrefix()); context.dispose(); accContext.dispose(); return value; } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintMenuBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { SynthContext accContext = getContext(menuItem, Region.MENU_ITEM_ACCELERATOR); // Refetch the appropriate check indicator for the current state String prefix = getPropertyPrefix(); Icon checkIcon = style.getIcon(context, prefix + ".checkIcon"); Icon arrowIcon = style.getIcon(context, prefix + ".arrowIcon"); SynthGraphicsUtils.paint(context, accContext, g, checkIcon, arrowIcon, acceleratorDelimiter, defaultTextIconGap, getPropertyPrefix()); accContext.dispose(); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintMenuBorder(context, g, x, y, w, h); } public void propertyChange(PropertyChangeEvent e) { if (SynthLookAndFeel.shouldUpdateStyle(e)) { updateStyle((JMenu)e.getSource()); } } }
Java
/* * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.*; import javax.swing.plaf.UIResource; import java.awt.Container; import java.awt.Dimension; /** {@collect.stats} * The default layout manager for Popup menus and menubars. This * class is an extension of BoxLayout which adds the UIResource tag * so that plauggable L&Fs can distinguish it from user-installed * layout managers on menus. * * Derived from javax.swing.plaf.basic.DefaultMenuLayout * * @author Georges Saab */ class DefaultMenuLayout extends BoxLayout implements UIResource { public DefaultMenuLayout(Container target, int axis) { super(target, axis); } public Dimension preferredLayoutSize(Container target) { if (target instanceof JPopupMenu) { JPopupMenu popupMenu = (JPopupMenu) target; popupMenu.putClientProperty( SynthMenuItemLayoutHelper.MAX_ACC_OR_ARROW_WIDTH, null); sun.swing.MenuItemLayoutHelper.clearUsedClientProperties(popupMenu); if (popupMenu.getComponentCount() == 0) { return new Dimension(0, 0); } } // Make BoxLayout recalculate cached preferred sizes super.invalidateLayout(target); return super.preferredLayoutSize(target); } }
Java
/* * Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import javax.swing.*; import javax.swing.text.*; import javax.swing.plaf.*; /** {@collect.stats} * Provides the Synth look and feel for a password field. * The only difference from the standard text field is that * the view of the text is simply a string of the echo * character as specified in JPasswordField, rather than the * real text contained in the field. * * @author Shannon Hickey */ class SynthPasswordFieldUI extends SynthTextFieldUI { /** {@collect.stats} * Creates a UI for a JPasswordField. * * @param c the JPasswordField * @return the UI */ public static ComponentUI createUI(JComponent c) { return new SynthPasswordFieldUI(); } /** {@collect.stats} * Fetches the name used as a key to look up properties through the * UIManager. This is used as a prefix to all the standard * text properties. * * @return the name ("PasswordField") */ protected String getPropertyPrefix() { return "PasswordField"; } /** {@collect.stats} * Creates a view (PasswordView) for an element. * * @param elem the element * @return the view */ public View create(Element elem) { return new PasswordView(elem); } void paintBackground(SynthContext context, Graphics g, JComponent c) { context.getPainter().paintPasswordFieldBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintPasswordFieldBorder(context, g, x, y, w, h); } protected void installKeyboardActions() { super.installKeyboardActions(); ActionMap map = SwingUtilities.getUIActionMap(getComponent()); if (map != null && map.get(DefaultEditorKit.selectWordAction) != null) { Action a = map.get(DefaultEditorKit.selectLineAction); if (a != null) { map.put(DefaultEditorKit.selectWordAction, a); } } } }
Java
/* * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import javax.swing.text.View; import java.awt.*; import java.awt.event.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import sun.swing.plaf.synth.SynthUI; import sun.swing.SwingUtilities2; /** {@collect.stats} * A Synth L&F implementation of TabbedPaneUI. * * @author Scott Violet */ /** {@collect.stats} * Looks up 'selectedTabPadInsets' from the Style, which will be additional * insets for the selected tab. */ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyChangeListener { /** {@collect.stats} * <p>If non-zero, tabOverlap indicates the amount that the tab bounds * should be altered such that they would overlap with a tab on either the * leading or trailing end of a run (ie: in TOP, this would be on the left * or right).</p> * <p>A positive overlap indicates that tabs should overlap right/down, * while a negative overlap indicates tha tabs should overlap left/up.</p> * * <p>When tabOverlap is specified, it both changes the x position and width * of the tab if in TOP or BOTTOM placement, and changes the y position and * height if in LEFT or RIGHT placement.</p> * * <p>This is done for the following reason. Consider a run of 10 tabs. * There are 9 gaps between these tabs. If you specified a tabOverlap of * "-1", then each of the tabs "x" values will be shifted left. This leaves * 9 pixels of space to the right of the right-most tab unpainted. So, each * tab's width is also extended by 1 pixel to make up the difference.</p> * * <p>This property respects the RTL component orientation.</p> */ private int tabOverlap = 0; /** {@collect.stats} * When a tabbed pane has multiple rows of tabs, this indicates whether * the tabs in the upper row(s) should extend to the base of the tab area, * or whether they should remain at their normal tab height. This does not * affect the bounds of the tabs, only the bounds of area painted by the * tabs. The text position does not change. The result is that the bottom * border of the upper row of tabs becomes fully obscured by the lower tabs, * resulting in a cleaner look. */ private boolean extendTabsToBase = false; private SynthContext tabAreaContext; private SynthContext tabContext; private SynthContext tabContentContext; private SynthStyle style; private SynthStyle tabStyle; private SynthStyle tabAreaStyle; private SynthStyle tabContentStyle; private Rectangle textRect; private Rectangle iconRect; private Rectangle tabAreaBounds = new Rectangle(); //added for the Nimbus look and feel, where the tab area is painted differently depending on the //state for the selected tab private boolean tabAreaStatesMatchSelectedTab = false; //added for the Nimbus LAF to ensure that the labels don't move whether the tab is selected or not private boolean nudgeSelectedLabel = true; private boolean selectedTabIsPressed = false; public static ComponentUI createUI(JComponent c) { return new SynthTabbedPaneUI(); } SynthTabbedPaneUI() { textRect = new Rectangle(); iconRect = new Rectangle(); } private boolean scrollableTabLayoutEnabled() { return (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT); } protected void installDefaults() { updateStyle(tabPane); } private void updateStyle(JTabbedPane c) { SynthContext context = getContext(c, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); // Add properties other than JComponent colors, Borders and // opacity settings here: if (style != oldStyle) { tabRunOverlay = style.getInt(context, "TabbedPane.tabRunOverlay", 0); tabOverlap = style.getInt(context, "TabbedPane.tabOverlap", 0); extendTabsToBase = style.getBoolean(context, "TabbedPane.extendTabsToBase", false); textIconGap = style.getInt(context, "TabbedPane.textIconGap", 0); selectedTabPadInsets = (Insets)style.get(context, "TabbedPane.selectedTabPadInsets"); if (selectedTabPadInsets == null) { selectedTabPadInsets = new Insets(0, 0, 0, 0); } tabAreaStatesMatchSelectedTab = style.getBoolean(context, "TabbedPane.tabAreaStatesMatchSelectedTab", false); nudgeSelectedLabel = style.getBoolean(context, "TabbedPane.nudgeSelectedLabel", true); if (oldStyle != null) { uninstallKeyboardActions(); installKeyboardActions(); } } context.dispose(); if (tabContext != null) { tabContext.dispose(); } tabContext = getContext(c, Region.TABBED_PANE_TAB, ENABLED); this.tabStyle = SynthLookAndFeel.updateStyle(tabContext, this); tabInsets = tabStyle.getInsets(tabContext, null); if (tabAreaContext != null) { tabAreaContext.dispose(); } tabAreaContext = getContext(c, Region.TABBED_PANE_TAB_AREA, ENABLED); this.tabAreaStyle = SynthLookAndFeel.updateStyle(tabAreaContext, this); tabAreaInsets = tabAreaStyle.getInsets(tabAreaContext, null); if (tabContentContext != null) { tabContentContext.dispose(); } tabContentContext = getContext(c, Region.TABBED_PANE_CONTENT, ENABLED); this.tabContentStyle = SynthLookAndFeel.updateStyle(tabContentContext, this); contentBorderInsets = tabContentStyle.getInsets(tabContentContext, null); } protected void installListeners() { super.installListeners(); tabPane.addPropertyChangeListener(this); } protected void uninstallListeners() { super.uninstallListeners(); tabPane.removePropertyChangeListener(this); } protected void uninstallDefaults() { SynthContext context = getContext(tabPane, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; tabStyle.uninstallDefaults(tabContext); tabContext.dispose(); tabContext = null; tabStyle = null; tabAreaStyle.uninstallDefaults(tabAreaContext); tabAreaContext.dispose(); tabAreaContext = null; tabAreaStyle = null; tabContentStyle.uninstallDefaults(tabContentContext); tabContentContext.dispose(); tabContentContext = null; tabContentStyle = null; } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } public SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c),style, state); } public SynthContext getContext(JComponent c, Region subregion) { return getContext(c, subregion, getComponentState(c)); } private SynthContext getContext(JComponent c, Region subregion, int state){ SynthStyle style = null; Class klass = SynthContext.class; if (subregion == Region.TABBED_PANE_TAB) { style = tabStyle; } else if (subregion == Region.TABBED_PANE_TAB_AREA) { style = tabAreaStyle; } else if (subregion == Region.TABBED_PANE_CONTENT) { style = tabContentStyle; } return SynthContext.getContext(klass, c, subregion, style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } protected JButton createScrollButton(int direction) { // added for Nimbus LAF so that it can use the basic arrow buttons // UIManager is queried directly here because this is called before // updateStyle is called so the style can not be queried directly if (UIManager.getBoolean("TabbedPane.useBasicArrows")) { JButton btn = super.createScrollButton(direction); btn.setBorder(BorderFactory.createEmptyBorder()); return btn; } return new SynthScrollableTabButton(direction); } public void propertyChange(PropertyChangeEvent e) { if (SynthLookAndFeel.shouldUpdateStyle(e)) { updateStyle(tabPane); } } /** {@collect.stats} * @inheritDoc * * Overridden to keep track of whether the selected tab is also pressed. */ @Override protected MouseListener createMouseListener() { final MouseListener delegate = super.createMouseListener(); final MouseMotionListener delegate2 = (MouseMotionListener)delegate; return new MouseListener() { public void mouseClicked(MouseEvent e) { delegate.mouseClicked(e); } public void mouseEntered(MouseEvent e) { delegate.mouseEntered(e); } public void mouseExited(MouseEvent e) { delegate.mouseExited(e); } public void mousePressed(MouseEvent e) { if (!tabPane.isEnabled()) { return; } int tabIndex = tabForCoordinate(tabPane, e.getX(), e.getY()); if (tabIndex >= 0 && tabPane.isEnabledAt(tabIndex)) { if (tabIndex == tabPane.getSelectedIndex()) { // Clicking on selected tab selectedTabIsPressed = true; //TODO need to just repaint the tab area! tabPane.repaint(); } } //forward the event (this will set the selected index, or none at all delegate.mousePressed(e); } public void mouseReleased(MouseEvent e) { if (selectedTabIsPressed) { selectedTabIsPressed = false; //TODO need to just repaint the tab area! tabPane.repaint(); } //forward the event delegate.mouseReleased(e); //hack: The super method *should* be setting the mouse-over property correctly //here, but it doesn't. That is, when the mouse is released, whatever tab is below the //released mouse should be in rollover state. But, if you select a tab and don't //move the mouse, this doesn't happen. Hence, forwarding the event. delegate2.mouseMoved(e); } }; } @Override protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected) { if (nudgeSelectedLabel) { return super.getTabLabelShiftX(tabPlacement, tabIndex, isSelected); } else { return 0; } } @Override protected int getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected) { if (nudgeSelectedLabel) { return super.getTabLabelShiftY(tabPlacement, tabIndex, isSelected); } else { return 0; } } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintTabbedPaneBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } protected int getBaseline(int tab) { if (tabPane.getTabComponentAt(tab) != null || getTextViewForTab(tab) != null) { return super.getBaseline(tab); } String title = tabPane.getTitleAt(tab); Font font = tabContext.getStyle().getFont(tabContext); FontMetrics metrics = getFontMetrics(font); Icon icon = getIconForTab(tab); textRect.setBounds(0, 0, 0, 0); iconRect.setBounds(0, 0, 0, 0); calcRect.setBounds(0, 0, Short.MAX_VALUE, maxTabHeight); tabContext.getStyle().getGraphicsUtils(tabContext).layoutText( tabContext, metrics, title, icon, SwingUtilities.CENTER, SwingUtilities.CENTER, SwingUtilities.LEADING, SwingUtilities.TRAILING, calcRect, iconRect, textRect, textIconGap); return textRect.y + metrics.getAscent() + getBaselineOffset(); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintTabbedPaneBorder(context, g, x, y, w, h); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { int selectedIndex = tabPane.getSelectedIndex(); int tabPlacement = tabPane.getTabPlacement(); ensureCurrentLayout(); // Paint tab area // If scrollable tabs are enabled, the tab area will be // painted by the scrollable tab panel instead. // if (!scrollableTabLayoutEnabled()) { // WRAP_TAB_LAYOUT Insets insets = tabPane.getInsets(); int x = insets.left; int y = insets.top; int width = tabPane.getWidth() - insets.left - insets.right; int height = tabPane.getHeight() - insets.top - insets.bottom; int size; switch(tabPlacement) { case LEFT: width = calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth); break; case RIGHT: size = calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth); x = x + width - size; width = size; break; case BOTTOM: size = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight); y = y + height - size; height = size; break; case TOP: default: height = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight); } tabAreaBounds.setBounds(x, y, width, height); if (g.getClipBounds().intersects(tabAreaBounds)) { paintTabArea(tabAreaContext, g, tabPlacement, selectedIndex, tabAreaBounds); } } // Paint content border paintContentBorder(tabContentContext, g, tabPlacement, selectedIndex); } protected void paintTabArea(Graphics g, int tabPlacement, int selectedIndex) { // This can be invoked from ScrollabeTabPanel Insets insets = tabPane.getInsets(); int x = insets.left; int y = insets.top; int width = tabPane.getWidth() - insets.left - insets.right; int height = tabPane.getHeight() - insets.top - insets.bottom; paintTabArea(tabAreaContext, g, tabPlacement, selectedIndex, new Rectangle(x, y, width, height)); } protected void paintTabArea(SynthContext ss, Graphics g, int tabPlacement, int selectedIndex, Rectangle tabAreaBounds) { Rectangle clipRect = g.getClipBounds(); //if the tab area's states should match that of the selected tab, then //first update the selected tab's states, then set the state //for the tab area to match //otherwise, restore the tab area's state to ENABLED (which is the //only supported state otherwise). if (tabAreaStatesMatchSelectedTab && selectedIndex >= 0) { updateTabContext(selectedIndex, true, selectedTabIsPressed, (getRolloverTab() == selectedIndex), (getFocusIndex() == selectedIndex)); ss.setComponentState(tabContext.getComponentState()); } else { ss.setComponentState(SynthConstants.ENABLED); } // Paint the tab area. SynthLookAndFeel.updateSubregion(ss, g, tabAreaBounds); ss.getPainter().paintTabbedPaneTabAreaBackground(ss, g, tabAreaBounds.x, tabAreaBounds.y, tabAreaBounds.width, tabAreaBounds.height, tabPlacement); ss.getPainter().paintTabbedPaneTabAreaBorder(ss, g, tabAreaBounds.x, tabAreaBounds.y, tabAreaBounds.width, tabAreaBounds.height, tabPlacement); int tabCount = tabPane.getTabCount(); iconRect.setBounds(0, 0, 0, 0); textRect.setBounds(0, 0, 0, 0); // Paint tabRuns of tabs from back to front for (int i = runCount - 1; i >= 0; i--) { int start = tabRuns[i]; int next = tabRuns[(i == runCount - 1)? 0 : i + 1]; int end = (next != 0? next - 1: tabCount - 1); for (int j = start; j <= end; j++) { if (rects[j].intersects(clipRect) && selectedIndex != j) { paintTab(tabContext, g, tabPlacement, rects, j, iconRect, textRect); } } } if (selectedIndex >= 0) { if (rects[selectedIndex].intersects(clipRect)) { paintTab(tabContext, g, tabPlacement, rects, selectedIndex, iconRect, textRect); } } } protected void setRolloverTab(int index) { int oldRolloverTab = getRolloverTab(); super.setRolloverTab(index); Rectangle r = null; if (oldRolloverTab != index && tabAreaStatesMatchSelectedTab) { //TODO need to just repaint the tab area! tabPane.repaint(); } else { if ((oldRolloverTab >= 0) && (oldRolloverTab < tabPane.getTabCount())) { r = getTabBounds(tabPane, oldRolloverTab); if (r != null) { tabPane.repaint(r); } } if (index >= 0) { r = getTabBounds(tabPane, index); if (r != null) { tabPane.repaint(r); } } } } protected void paintTab(SynthContext ss, Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect) { Rectangle tabRect = rects[tabIndex]; int selectedIndex = tabPane.getSelectedIndex(); boolean isSelected = selectedIndex == tabIndex; updateTabContext(tabIndex, isSelected, isSelected && selectedTabIsPressed, (getRolloverTab() == tabIndex), (getFocusIndex() == tabIndex)); SynthLookAndFeel.updateSubregion(ss, g, tabRect); int x = tabRect.x; int y = tabRect.y; int height = tabRect.height; int width = tabRect.width; int placement = tabPane.getTabPlacement(); if (extendTabsToBase && runCount > 1) { //paint this tab such that its edge closest to the base is equal to //edge of the selected tab closest to the base. In terms of the TOP //tab placement, this will cause the bottom of each tab to be //painted even with the bottom of the selected tab. This is because //in each tab placement (TOP, LEFT, BOTTOM, RIGHT) the selected tab //is closest to the base. if (selectedIndex >= 0) { Rectangle r = rects[selectedIndex]; switch (placement) { case TOP: int bottomY = r.y + r.height; height = bottomY - tabRect.y; break; case LEFT: int rightX = r.x + r.width; width = rightX - tabRect.x; break; case BOTTOM: int topY = r.y; height = (tabRect.y + tabRect.height) - topY; y = topY; break; case RIGHT: int leftX = r.x; width = (tabRect.x + tabRect.width) - leftX; x = leftX; break; } } } tabContext.getPainter().paintTabbedPaneTabBackground(tabContext, g, x, y, width, height, tabIndex, placement); tabContext.getPainter().paintTabbedPaneTabBorder(tabContext, g, x, y, width, height, tabIndex, placement); if (tabPane.getTabComponentAt(tabIndex) == null) { String title = tabPane.getTitleAt(tabIndex); Font font = ss.getStyle().getFont(ss); FontMetrics metrics = SwingUtilities2.getFontMetrics(tabPane, g, font); Icon icon = getIconForTab(tabIndex); layoutLabel(ss, tabPlacement, metrics, tabIndex, title, icon, tabRect, iconRect, textRect, isSelected); paintText(ss, g, tabPlacement, font, metrics, tabIndex, title, textRect, isSelected); paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected); } } protected void layoutLabel(SynthContext ss, int tabPlacement, FontMetrics metrics, int tabIndex, String title, Icon icon, Rectangle tabRect, Rectangle iconRect, Rectangle textRect, boolean isSelected ) { View v = getTextViewForTab(tabIndex); if (v != null) { tabPane.putClientProperty("html", v); } textRect.x = textRect.y = iconRect.x = iconRect.y = 0; ss.getStyle().getGraphicsUtils(ss).layoutText(ss, metrics, title, icon, SwingUtilities.CENTER, SwingUtilities.CENTER, SwingUtilities.LEADING, SwingUtilities.TRAILING, tabRect, iconRect, textRect, textIconGap); tabPane.putClientProperty("html", null); int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected); int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected); iconRect.x += xNudge; iconRect.y += yNudge; textRect.x += xNudge; textRect.y += yNudge; } protected void paintText(SynthContext ss, Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect, boolean isSelected) { g.setFont(font); View v = getTextViewForTab(tabIndex); if (v != null) { // html v.paint(g, textRect); } else { // plain text int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex); g.setColor(ss.getStyle().getColor(ss, ColorType.TEXT_FOREGROUND)); ss.getStyle().getGraphicsUtils(ss).paintText(ss, g, title, textRect, mnemIndex); } } protected void paintContentBorder(SynthContext ss, Graphics g, int tabPlacement, int selectedIndex) { int width = tabPane.getWidth(); int height = tabPane.getHeight(); Insets insets = tabPane.getInsets(); int x = insets.left; int y = insets.top; int w = width - insets.right - insets.left; int h = height - insets.top - insets.bottom; switch(tabPlacement) { case LEFT: x += calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth); w -= (x - insets.left); break; case RIGHT: w -= calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth); break; case BOTTOM: h -= calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight); break; case TOP: default: y += calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight); h -= (y - insets.top); } SynthLookAndFeel.updateSubregion(ss, g, new Rectangle(x, y, w, h)); ss.getPainter().paintTabbedPaneContentBackground(ss, g, x, y, w, h); ss.getPainter().paintTabbedPaneContentBorder(ss, g, x, y, w, h); } private void ensureCurrentLayout() { if (!tabPane.isValid()) { tabPane.validate(); } /* If tabPane doesn't have a peer yet, the validate() call will * silently fail. We handle that by forcing a layout if tabPane * is still invalid. See bug 4237677. */ if (!tabPane.isValid()) { TabbedPaneLayout layout = (TabbedPaneLayout)tabPane.getLayout(); layout.calculateLayoutInfo(); } } protected int calculateMaxTabHeight(int tabPlacement) { FontMetrics metrics = getFontMetrics(tabContext.getStyle().getFont( tabContext)); int tabCount = tabPane.getTabCount(); int result = 0; int fontHeight = metrics.getHeight(); for(int i = 0; i < tabCount; i++) { result = Math.max(calculateTabHeight(tabPlacement, i, fontHeight), result); } return result; } protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) { Icon icon = getIconForTab(tabIndex); Insets tabInsets = getTabInsets(tabPlacement, tabIndex); int width = tabInsets.left + tabInsets.right; Component tabComponent = tabPane.getTabComponentAt(tabIndex); if (tabComponent != null) { width += tabComponent.getPreferredSize().width; } else { if (icon != null) { width += icon.getIconWidth() + textIconGap; } View v = getTextViewForTab(tabIndex); if (v != null) { // html width += (int) v.getPreferredSpan(View.X_AXIS); } else { // plain text String title = tabPane.getTitleAt(tabIndex); width += tabContext.getStyle().getGraphicsUtils(tabContext). computeStringWidth(tabContext, metrics.getFont(), metrics, title); } } return width; } protected int calculateMaxTabWidth(int tabPlacement) { FontMetrics metrics = getFontMetrics(tabContext.getStyle().getFont( tabContext)); int tabCount = tabPane.getTabCount(); int result = 0; for(int i = 0; i < tabCount; i++) { result = Math.max(calculateTabWidth(tabPlacement, i, metrics), result); } return result; } protected Insets getTabInsets(int tabPlacement, int tabIndex) { updateTabContext(tabIndex, false, false, false, (getFocusIndex() == tabIndex)); return tabInsets; } protected FontMetrics getFontMetrics() { return getFontMetrics(tabContext.getStyle().getFont(tabContext)); } protected FontMetrics getFontMetrics(Font font) { return tabPane.getFontMetrics(font); } private void updateTabContext(int index, boolean selected, boolean isMouseDown, boolean isMouseOver, boolean hasFocus) { int state = 0; if (!tabPane.isEnabled() || !tabPane.isEnabledAt(index)) { state |= SynthConstants.DISABLED; if (selected) { state |= SynthConstants.SELECTED; } } else if (selected) { state |= (SynthConstants.ENABLED | SynthConstants.SELECTED); if (isMouseOver && UIManager.getBoolean("TabbedPane.isTabRollover")) { state |= SynthConstants.MOUSE_OVER; } } else if (isMouseOver) { state |= (SynthConstants.ENABLED | SynthConstants.MOUSE_OVER); } else { state = SynthLookAndFeel.getComponentState(tabPane); state &= ~SynthConstants.FOCUSED; // don't use tabbedpane focus state } if (hasFocus && tabPane.hasFocus()) { state |= SynthConstants.FOCUSED; // individual tab has focus } if (isMouseDown) { state |= SynthConstants.PRESSED; } tabContext.setComponentState(state); } /** {@collect.stats} * @inheritDoc * * Overridden to create a TabbedPaneLayout subclass which takes into * account tabOverlap. */ @Override protected LayoutManager createLayoutManager() { if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) { return super.createLayoutManager(); } else { /* WRAP_TAB_LAYOUT */ return new TabbedPaneLayout() { @Override public void calculateLayoutInfo() { super.calculateLayoutInfo(); //shift all the tabs, if necessary if (tabOverlap != 0) { int tabCount = tabPane.getTabCount(); //left-to-right/right-to-left only affects layout //when placement is TOP or BOTTOM boolean ltr = tabPane.getComponentOrientation().isLeftToRight(); for (int i = runCount - 1; i >= 0; i--) { int start = tabRuns[i]; int next = tabRuns[(i == runCount - 1)? 0 : i + 1]; int end = (next != 0? next - 1: tabCount - 1); for (int j = start+1; j <= end; j++) { // xshift and yshift represent the amount & // direction to shift the tab in their // respective axis. int xshift = 0; int yshift = 0; // configure xshift and y shift based on tab // position and ltr/rtl switch (tabPane.getTabPlacement()) { case JTabbedPane.TOP: case JTabbedPane.BOTTOM: xshift = ltr ? tabOverlap : -tabOverlap; break; case JTabbedPane.LEFT: case JTabbedPane.RIGHT: yshift = tabOverlap; break; default: //do nothing } rects[j].x += xshift; rects[j].y += yshift; rects[j].width += Math.abs(xshift); rects[j].height += Math.abs(yshift); } } } } }; } } private class SynthScrollableTabButton extends SynthArrowButton implements UIResource { public SynthScrollableTabButton(int direction) { super(direction); } } }
Java
/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.*; import javax.swing.event.*; import javax.swing.plaf.basic.*; import java.awt.*; import java.awt.event.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import java.io.Serializable; /** {@collect.stats} * Synth's ComboPopup. * * @author Scott Violet */ class SynthComboPopup extends BasicComboPopup { public SynthComboPopup( JComboBox combo ) { super(combo); } /** {@collect.stats} * Configures the list which is used to hold the combo box items in the * popup. This method is called when the UI class * is created. * * @see #createList */ protected void configureList() { list.setFont( comboBox.getFont() ); list.setCellRenderer( comboBox.getRenderer() ); list.setFocusable( false ); list.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); int selectedIndex = comboBox.getSelectedIndex(); if ( selectedIndex == -1 ) { list.clearSelection(); } else { list.setSelectedIndex( selectedIndex ); list.ensureIndexIsVisible( selectedIndex ); } installListListeners(); } }
Java
/* * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import javax.swing.*; /** {@collect.stats} * <code>SynthPainter</code> is used for painting portions of * <code>JComponent</code>s. At a minimum each <code>JComponent</code> * has two paint methods: one for the border and one for the background. Some * <code>JComponent</code>s have more than one <code>Region</code>, and as * a consequence more paint methods. * <p> * Instances of <code>SynthPainter</code> are obtained from the * {@link javax.swing.plaf.synth.SynthStyle#getPainter} method. * <p> * You typically supply a <code>SynthPainter</code> by way of Synth's * <a href="doc-files/synthFileFormat.html">file</a> format. The following * example registers a painter for all <code>JButton</code>s that will * render the image <code>myImage.png</code>: * <pre> * &lt;style id="buttonStyle"> * &lt;imagePainter path="myImage.png" sourceInsets="2 2 2 2" * paintCenter="true" stretch="true"/> * &lt;insets top="2" bottom="2" left="2" right="2"/> * &lt;/style> * &lt;bind style="buttonStyle" type="REGION" key="button"/> *</pre> * <p> * <code>SynthPainter</code> is abstract in so far as it does no painting, * all the methods * are empty. While none of these methods are typed to throw an exception, * subclasses can assume that valid arguments are passed in, and if not * they can throw a <code>NullPointerException</code> or * <code>IllegalArgumentException</code> in response to invalid arguments. * * @since 1.5 * @author Scott Violet */ public abstract class SynthPainter { /** {@collect.stats} * Used to avoid null painter checks everywhere. */ static SynthPainter NULL_PAINTER = new SynthPainter() {}; /** {@collect.stats} * Paints the background of an arrow button. Arrow buttons are created by * some components, such as <code>JScrollBar</code>. * * @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 paintArrowButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of an arrow button. Arrow buttons are created by * some components, such as <code>JScrollBar</code>. * * @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 paintArrowButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the foreground of an arrow button. This method is responsible * for drawing a graphical representation of a direction, typically * an arrow. Arrow buttons are created by * some components, such as <code>JScrollBar</code> * * @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 * @param direction One of SwingConstants.NORTH, SwingConstants.SOUTH * SwingConstants.EAST or SwingConstants.WEST */ public void paintArrowButtonForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { } /** {@collect.stats} * Paints the background of a button. * * @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 paintButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a button. * * @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 paintButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a check box menu item. * * @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 paintCheckBoxMenuItemBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a check box menu item. * * @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 paintCheckBoxMenuItemBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a check 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 paintCheckBoxBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a check 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 paintCheckBoxBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a color chooser. * * @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 paintColorChooserBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a color chooser. * * @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 paintColorChooserBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * 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) { } /** {@collect.stats} * Paints the border 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 paintComboBoxBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a desktop icon. * * @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 paintDesktopIconBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a desktop icon. * * @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 paintDesktopIconBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a desktop pane. * * @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 paintDesktopPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a desktop pane. * * @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 paintDesktopPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of an editor pane. * * @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 paintEditorPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of an editor pane. * * @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 paintEditorPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a file chooser. * * @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 paintFileChooserBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a file chooser. * * @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 paintFileChooserBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * 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) { } /** {@collect.stats} * 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) { } /** {@collect.stats} * Paints the background of an internal frame title pane. * * @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 paintInternalFrameTitlePaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of an internal frame title pane. * * @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 paintInternalFrameTitlePaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of an internal frame. * * @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 paintInternalFrameBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of an internal frame. * * @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 paintInternalFrameBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a label. * * @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 paintLabelBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a label. * * @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 paintLabelBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a list. * * @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 paintListBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a list. * * @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 paintListBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a menu bar. * * @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 paintMenuBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a menu bar. * * @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 paintMenuBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a menu item. * * @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 paintMenuItemBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a menu item. * * @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 paintMenuItemBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a menu. * * @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 paintMenuBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a menu. * * @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 paintMenuBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of an option pane. * * @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 paintOptionPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of an option pane. * * @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 paintOptionPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a panel. * * @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 paintPanelBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a panel. * * @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 paintPanelBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a password 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 paintPasswordFieldBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a password 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 paintPasswordFieldBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a popup menu. * * @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 paintPopupMenuBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a popup menu. * * @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 paintPopupMenuBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a progress bar. * * @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 paintProgressBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a progress bar. This implementation invokes the * method of the same name without the orientation. * * @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 * @param orientation one of <code>JProgressBar.HORIZONTAL</code> or * <code>JProgressBar.VERTICAL</code> * @since 1.6 */ public void paintProgressBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintProgressBarBackground(context, g, x, y, w, h); } /** {@collect.stats} * Paints the border of a progress bar. * * @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 paintProgressBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a progress bar. This implementation invokes the * method of the same name without the orientation. * * @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 * @param orientation one of <code>JProgressBar.HORIZONTAL</code> or * <code>JProgressBar.VERTICAL</code> * @since 1.6 */ public void paintProgressBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintProgressBarBorder(context, g, x, y, w, h); } /** {@collect.stats} * Paints the foreground of a progress bar. is responsible for * providing an indication of the progress of the progress bar. * * @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 * @param orientation one of <code>JProgressBar.HORIZONTAL</code> or * <code>JProgressBar.VERTICAL</code> */ public void paintProgressBarForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { } /** {@collect.stats} * Paints the background of a radio button menu item. * * @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 paintRadioButtonMenuItemBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a radio button menu item. * * @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 paintRadioButtonMenuItemBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a radio button. * * @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 paintRadioButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a radio button. * * @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 paintRadioButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a root pane. * * @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 paintRootPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a root pane. * * @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 paintRootPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a scrollbar. * * @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 paintScrollBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a scrollbar. This implementation invokes the * method of the same name without the orientation. * * @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 * @param orientation Orientation of the JScrollBar, one of * <code>JScrollBar.HORIZONTAL</code> or * <code>JScrollBar.VERTICAL</code> * @since 1.6 */ public void paintScrollBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintScrollBarBackground(context, g, x, y, w, h); } /** {@collect.stats} * Paints the border of a scrollbar. * * @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 paintScrollBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a scrollbar. This implementation invokes the * method of the same name without the orientation. * * @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 * @param orientation Orientation of the JScrollBar, one of * <code>JScrollBar.HORIZONTAL</code> or * <code>JScrollBar.VERTICAL</code> * @since 1.6 */ public void paintScrollBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintScrollBarBorder(context, g, x, y, w, h); } /** {@collect.stats} * Paints the background of the thumb of a scrollbar. The thumb provides * a graphical indication as to how much of the Component is visible in a * <code>JScrollPane</code>. * * @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 * @param orientation Orientation of the JScrollBar, one of * <code>JScrollBar.HORIZONTAL</code> or * <code>JScrollBar.VERTICAL</code> */ public void paintScrollBarThumbBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { } /** {@collect.stats} * Paints the border of the thumb of a scrollbar. The thumb provides * a graphical indication as to how much of the Component is visible in a * <code>JScrollPane</code>. * * @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 * @param orientation Orientation of the JScrollBar, one of * <code>JScrollBar.HORIZONTAL</code> or * <code>JScrollBar.VERTICAL</code> */ public void paintScrollBarThumbBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { } /** {@collect.stats} * Paints the background of the track of a scrollbar. The track contains * the thumb. * * @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 paintScrollBarTrackBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of the track of a scrollbar. The track contains * the thumb. This implementation invokes the method of the same name without * the orientation. * * @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 * @param orientation Orientation of the JScrollBar, one of * <code>JScrollBar.HORIZONTAL</code> or * <code>JScrollBar.VERTICAL</code> * @since 1.6 */ public void paintScrollBarTrackBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintScrollBarTrackBackground(context, g, x, y, w, h); } /** {@collect.stats} * Paints the border of the track of a scrollbar. The track contains * the thumb. * * @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 paintScrollBarTrackBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of the track of a scrollbar. The track contains * the thumb. This implementation invokes the method of the same name without * the orientation. * * @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 * @param orientation Orientation of the JScrollBar, one of * <code>JScrollBar.HORIZONTAL</code> or * <code>JScrollBar.VERTICAL</code> * @since 1.6 */ public void paintScrollBarTrackBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintScrollBarTrackBorder(context, g, x, y, w, h); } /** {@collect.stats} * Paints the background of a scroll pane. * * @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 paintScrollPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a scroll pane. * * @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 paintScrollPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a separator. * * @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 paintSeparatorBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a separator. This implementation invokes the * method of the same name without the orientation. * * @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 * @param orientation One of <code>JSeparator.HORIZONTAL</code> or * <code>JSeparator.VERTICAL</code> * @since 1.6 */ public void paintSeparatorBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintSeparatorBackground(context, g, x, y, w, h); } /** {@collect.stats} * Paints the border of a separator. * * @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 paintSeparatorBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a separator. This implementation invokes the * method of the same name without the orientation. * * @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 * @param orientation One of <code>JSeparator.HORIZONTAL</code> or * <code>JSeparator.VERTICAL</code> * @since 1.6 */ public void paintSeparatorBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintSeparatorBorder(context, g, x, y, w, h); } /** {@collect.stats} * Paints the foreground of a separator. * * @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 * @param orientation One of <code>JSeparator.HORIZONTAL</code> or * <code>JSeparator.VERTICAL</code> */ public void paintSeparatorForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { } /** {@collect.stats} * Paints the background of a slider. * * @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 paintSliderBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a slider. This implementation invokes the * method of the same name without the orientation. * * @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 * @param orientation One of <code>JSlider.HORIZONTAL</code> or * <code>JSlider.VERTICAL</code> * @since 1.6 */ public void paintSliderBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintSliderBackground(context, g, x, y, w, h); } /** {@collect.stats} * Paints the border of a slider. * * @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 paintSliderBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a slider. This implementation invokes the * method of the same name without the orientation. * * @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 * @param orientation One of <code>JSlider.HORIZONTAL</code> or * <code>JSlider.VERTICAL</code> * @since 1.6 */ public void paintSliderBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintSliderBorder(context, g, x, y, w, h); } /** {@collect.stats} * Paints the background of the thumb of a slider. * * @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 * @param orientation One of <code>JSlider.HORIZONTAL</code> or * <code>JSlider.VERTICAL</code> */ public void paintSliderThumbBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { } /** {@collect.stats} * Paints the border of the thumb of a slider. * * @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 * @param orientation One of <code>JSlider.HORIZONTAL</code> or * <code>JSlider.VERTICAL</code> */ public void paintSliderThumbBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { } /** {@collect.stats} * Paints the background of the track of a slider. * * @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 paintSliderTrackBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of the track of a slider. This implementation invokes * the method of the same name without the orientation. * * @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 * @param orientation One of <code>JSlider.HORIZONTAL</code> or * <code>JSlider.VERTICAL</code> * @since 1.6 */ public void paintSliderTrackBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintSliderTrackBackground(context, g, x, y, w, h); } /** {@collect.stats} * Paints the border of the track of a slider. * * @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 paintSliderTrackBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of the track of a slider. This implementation invokes the * method of the same name without the orientation. * * @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 * @param orientation One of <code>JSlider.HORIZONTAL</code> or * <code>JSlider.VERTICAL</code> * @since 1.6 */ public void paintSliderTrackBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintSliderTrackBorder(context, g, x, y, w, h); } /** {@collect.stats} * Paints the background of a spinner. * * @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 paintSpinnerBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a spinner. * * @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 paintSpinnerBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of the divider of a split pane. * * @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 paintSplitPaneDividerBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of the divider of a split pane. This implementation * invokes the method of the same name without the orientation. * * @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 * @param orientation One of <code>JSplitPane.HORIZONTAL_SPLIT</code> or * <code>JSplitPane.VERTICAL_SPLIT</code> * @since 1.6 */ public void paintSplitPaneDividerBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintSplitPaneDividerBackground(context, g, x, y, w, h); } /** {@collect.stats} * Paints the foreground of the divider of a split pane. * * @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 * @param orientation One of <code>JSplitPane.HORIZONTAL_SPLIT</code> or * <code>JSplitPane.VERTICAL_SPLIT</code> */ public void paintSplitPaneDividerForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { } /** {@collect.stats} * Paints the divider, when the user is dragging the divider, of a * split pane. * * @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 * @param orientation One of <code>JSplitPane.HORIZONTAL_SPLIT</code> or * <code>JSplitPane.VERTICAL_SPLIT</code> */ public void paintSplitPaneDragDivider(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { } /** {@collect.stats} * Paints the background of a split pane. * * @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 paintSplitPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a split pane. * * @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 paintSplitPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a tabbed pane. * * @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 paintTabbedPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a tabbed pane. * * @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 paintTabbedPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of the area behind the tabs of a tabbed pane. * * @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 paintTabbedPaneTabAreaBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of the area behind the tabs of a tabbed pane. * This implementation invokes the method of the same name without the * orientation. * * @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 * @param orientation One of <code>JTabbedPane.TOP</code>, * <code>JTabbedPane.LEFT</code>, * <code>JTabbedPane.BOTTOM</code>, or * <code>JTabbedPane.RIGHT</code> * @since 1.6 */ public void paintTabbedPaneTabAreaBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintTabbedPaneTabAreaBackground(context, g, x, y, w, h); } /** {@collect.stats} * Paints the border of the area behind the tabs of a tabbed pane. * * @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 paintTabbedPaneTabAreaBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of the area behind the tabs of a tabbed pane. This * implementation invokes the method of the same name without the orientation. * * @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 * @param orientation One of <code>JTabbedPane.TOP</code>, * <code>JTabbedPane.LEFT</code>, * <code>JTabbedPane.BOTTOM</code>, or * <code>JTabbedPane.RIGHT</code> * @since 1.6 */ public void paintTabbedPaneTabAreaBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintTabbedPaneTabAreaBorder(context, g, x, y, w, h); } /** {@collect.stats} * Paints the background of a tab of a tabbed pane. * * @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 * @param tabIndex Index of tab being painted. */ public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex) { } /** {@collect.stats} * Paints the background of a tab of a tabbed pane. This implementation * invokes the method of the same name without the orientation. * * @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 * @param tabIndex Index of tab being painted. * @param orientation One of <code>JTabbedPane.TOP</code>, * <code>JTabbedPane.LEFT</code>, * <code>JTabbedPane.BOTTOM</code>, or * <code>JTabbedPane.RIGHT</code> * @since 1.6 */ public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex, int orientation) { paintTabbedPaneTabBackground(context, g, x, y, w, h, tabIndex); } /** {@collect.stats} * Paints the border of a tab of a tabbed pane. * * @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 * @param tabIndex Index of tab being painted. */ public void paintTabbedPaneTabBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex) { } /** {@collect.stats} * Paints the border of a tab of a tabbed pane. This implementation invokes * the method of the same name without the orientation. * * @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 * @param tabIndex Index of tab being painted. * @param orientation One of <code>JTabbedPane.TOP</code>, * <code>JTabbedPane.LEFT</code>, * <code>JTabbedPane.BOTTOM</code>, or * <code>JTabbedPane.RIGHT</code> * @since 1.6 */ public void paintTabbedPaneTabBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex, int orientation) { paintTabbedPaneTabBorder(context, g, x, y, w, h, tabIndex); } /** {@collect.stats} * Paints the background of the area that contains the content of the * selected tab of a tabbed pane. * * @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 paintTabbedPaneContentBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of the area that contains the content of the * selected tab of a tabbed pane. * * @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 paintTabbedPaneContentBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of the header of a table. * * @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 paintTableHeaderBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of the header of a table. * * @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 paintTableHeaderBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a table. * * @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 paintTableBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a table. * * @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 paintTableBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a text area. * * @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 paintTextAreaBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a text area. * * @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 paintTextAreaBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a text pane. * * @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 paintTextPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a text pane. * * @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 paintTextPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background 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 paintTextFieldBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * 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) { } /** {@collect.stats} * Paints the background of a toggle button. * * @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 paintToggleButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a toggle button. * * @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 paintToggleButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a tool bar. * * @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 paintToolBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a tool bar. This implementation invokes the * method of the same name without the orientation. * * @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 * @param orientation One of <code>JToolBar.HORIZONTAL</code> or * <code>JToolBar.VERTICAL</code> * @since 1.6 */ public void paintToolBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintToolBarBackground(context, g, x, y, w, h); } /** {@collect.stats} * Paints the border of a tool bar. * * @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 paintToolBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a tool bar. This implementation invokes the * method of the same name without the orientation. * * @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 * @param orientation One of <code>JToolBar.HORIZONTAL</code> or * <code>JToolBar.VERTICAL</code> * @since 1.6 */ public void paintToolBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintToolBarBorder(context, g, x, y, w, h); } /** {@collect.stats} * Paints the background of the tool bar's content area. * * @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 paintToolBarContentBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of the tool bar's content area. This implementation * invokes the method of the same name without the orientation. * * @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 * @param orientation One of <code>JToolBar.HORIZONTAL</code> or * <code>JToolBar.VERTICAL</code> * @since 1.6 */ public void paintToolBarContentBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintToolBarContentBackground(context, g, x, y, w, h); } /** {@collect.stats} * Paints the border of the content area of a tool bar. * * @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 paintToolBarContentBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of the content area of a tool bar. This implementation * invokes the method of the same name without the orientation. * * @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 * @param orientation One of <code>JToolBar.HORIZONTAL</code> or * <code>JToolBar.VERTICAL</code> * @since 1.6 */ public void paintToolBarContentBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintToolBarContentBorder(context, g, x, y, w, h); } /** {@collect.stats} * Paints the background of the window containing the tool bar when it * has been detached from its primary frame. * * @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 paintToolBarDragWindowBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of the window containing the tool bar when it * has been detached from its primary frame. This implementation invokes the * method of the same name without the orientation. * * @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 * @param orientation One of <code>JToolBar.HORIZONTAL</code> or * <code>JToolBar.VERTICAL</code> * @since 1.6 */ public void paintToolBarDragWindowBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintToolBarDragWindowBackground(context, g, x, y, w, h); } /** {@collect.stats} * Paints the border of the window containing the tool bar when it * has been detached from it's primary frame. * * @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 paintToolBarDragWindowBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of the window containing the tool bar when it * has been detached from it's primary frame. This implementation invokes the * method of the same name without the orientation. * * @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 * @param orientation One of <code>JToolBar.HORIZONTAL</code> or * <code>JToolBar.VERTICAL</code> * @since 1.6 */ public void paintToolBarDragWindowBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paintToolBarDragWindowBorder(context, g, x, y, w, h); } /** {@collect.stats} * Paints the background of a tool tip. * * @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 paintToolTipBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a tool tip. * * @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 paintToolTipBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of a tree. * * @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 paintTreeBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a tree. * * @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 paintTreeBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of the row containing a cell in a tree. * * @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 paintTreeCellBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of the row containing a cell in a tree. * * @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 paintTreeCellBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the focus indicator for a cell in a tree when it has focus. * * @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 paintTreeCellFocus(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the background of the viewport. * * @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 paintViewportBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { } /** {@collect.stats} * Paints the border of a viewport. * * @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 paintViewportBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { } }
Java
/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.BasicPanelUI; import java.awt.*; import java.awt.event.*; import java.beans.*; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Synth's PanelUI. * * @author Steve Wilson */ class SynthPanelUI extends BasicPanelUI implements PropertyChangeListener, SynthUI { private SynthStyle style; public static ComponentUI createUI(JComponent c) { return new SynthPanelUI(); } public void installUI(JComponent c) { JPanel p = (JPanel)c; super.installUI(c); installListeners(p); } public void uninstallUI(JComponent c) { JPanel p = (JPanel)c; uninstallListeners(p); super.uninstallUI(c); } protected void installListeners(JPanel p) { p.addPropertyChangeListener(this); } protected void uninstallListeners(JPanel p) { p.removePropertyChangeListener(this); } protected void installDefaults(JPanel p) { updateStyle(p); } protected void uninstallDefaults(JPanel p) { SynthContext context = getContext(p, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; } private void updateStyle(JPanel c) { SynthContext context = getContext(c, ENABLED); style = SynthLookAndFeel.updateStyle(context, this); context.dispose(); } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintPanelBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { // do actual painting } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintPanelBorder(context, g, x, y, w, h); } public void propertyChange(PropertyChangeEvent pce) { if (SynthLookAndFeel.shouldUpdateStyle(pce)) { updateStyle((JPanel)pce.getSource()); } } }
Java
/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.BasicDesktopIconUI; import java.beans.*; import java.io.Serializable; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Synth L&F for a minimized window on a desktop. * * @author Joshua Outwater */ class SynthDesktopIconUI extends BasicDesktopIconUI implements SynthUI, ActionListener, PropertyChangeListener { private SynthStyle style; public static ComponentUI createUI(JComponent c) { return new SynthDesktopIconUI(); } protected void installComponents() { if (UIManager.getBoolean("InternalFrame.useTaskBar")) { iconPane = new JToggleButton(frame.getTitle(), frame.getFrameIcon()) { public String getToolTipText() { return getText(); } public JPopupMenu getComponentPopupMenu() { return frame.getComponentPopupMenu(); } }; ToolTipManager.sharedInstance().registerComponent(iconPane); iconPane.setFont(desktopIcon.getFont()); iconPane.setBackground(desktopIcon.getBackground()); iconPane.setForeground(desktopIcon.getForeground()); } else { iconPane = new SynthInternalFrameTitlePane(frame); iconPane.setName("InternalFrame.northPane"); } desktopIcon.setLayout(new BorderLayout()); desktopIcon.add(iconPane, BorderLayout.CENTER); } protected void installListeners() { super.installListeners(); desktopIcon.addPropertyChangeListener(this); if (iconPane instanceof JToggleButton) { frame.addPropertyChangeListener(this); ((JToggleButton)iconPane).addActionListener(this); } } protected void uninstallListeners() { if (iconPane instanceof JToggleButton) { frame.removePropertyChangeListener(this); } desktopIcon.removePropertyChangeListener(this); super.uninstallListeners(); } protected void installDefaults() { updateStyle(desktopIcon); } private void updateStyle(JComponent c) { SynthContext context = getContext(c, ENABLED); style = SynthLookAndFeel.updateStyle(context, this); context.dispose(); } protected void uninstallDefaults() { SynthContext context = getContext(desktopIcon, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { Region region = getRegion(c); return SynthContext.getContext(SynthContext.class, c, region, style, state); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintDesktopIconBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintDesktopIconBorder(context, g, x, y, w, h); } public void actionPerformed(ActionEvent evt) { if (evt.getSource() instanceof JToggleButton) { // Either iconify the frame or deiconify and activate it. JToggleButton button = (JToggleButton)evt.getSource(); try { boolean selected = button.isSelected(); if (!selected && !frame.isIconifiable()) { button.setSelected(true); } else { frame.setIcon(!selected); if (selected) { frame.setSelected(true); } } } catch (PropertyVetoException e2) { } } } public void propertyChange(PropertyChangeEvent evt) { if (evt.getSource() instanceof JInternalFrame.JDesktopIcon) { if (SynthLookAndFeel.shouldUpdateStyle(evt)) { updateStyle((JInternalFrame.JDesktopIcon)evt.getSource()); } } else if (evt.getSource() instanceof JInternalFrame) { JInternalFrame frame = (JInternalFrame)evt.getSource(); if (iconPane instanceof JToggleButton) { JToggleButton button = (JToggleButton)iconPane; String prop = evt.getPropertyName(); if (prop == "title") { button.setText((String)evt.getNewValue()); } else if (prop == "frameIcon") { button.setIcon((Icon)evt.getNewValue()); } else if (prop == JInternalFrame.IS_ICON_PROPERTY || prop == JInternalFrame.IS_SELECTED_PROPERTY) { button.setSelected(!frame.isIcon() && frame.isSelected()); } } } } }
Java
/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import java.awt.event.ActionEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.BasicRootPaneUI; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Synth's RootPaneUI. * * @author Scott Violet */ class SynthRootPaneUI extends BasicRootPaneUI implements SynthUI { private SynthStyle style; public static ComponentUI createUI(JComponent c) { return new SynthRootPaneUI(); } protected void installDefaults(JRootPane c){ updateStyle(c); } protected void uninstallDefaults(JRootPane root) { SynthContext context = getContext(root, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } private void updateStyle(JComponent c) { SynthContext context = getContext(c, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { if (oldStyle != null) { uninstallKeyboardActions((JRootPane)c); installKeyboardActions((JRootPane)c); } } context.dispose(); } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintRootPaneBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintRootPaneBorder(context, g, x, y, w, h); } /** {@collect.stats} * Invoked when a property changes on the root pane. If the event * indicates the <code>defaultButton</code> has changed, this will * reinstall the keyboard actions. */ public void propertyChange(PropertyChangeEvent e) { if (SynthLookAndFeel.shouldUpdateStyle(e)) { updateStyle((JRootPane)e.getSource()); } super.propertyChange(e); } }
Java
/* * Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import java.lang.ref.WeakReference; import java.net.*; import javax.swing.*; import sun.awt.AppContext; import sun.swing.plaf.synth.Paint9Painter; /** {@collect.stats} * ImagePainter fills in the specified region using an Image. The Image * is split into 9 segments: north, north east, east, south east, south, * south west, west, north west and the center. The corners are defined * by way of an insets, and the remaining regions are either tiled or * scaled to fit. * * @author Scott Violet */ class ImagePainter extends SynthPainter { private static final Object CACHE_KEY = new Object(); // SynthCacheKey private Image image; private Insets sInsets; private Insets dInsets; private URL path; private boolean tiles; private boolean paintCenter; private Paint9Painter imageCache; private boolean center; private static Paint9Painter getPaint9Painter() { // A SynthPainter is created per <imagePainter>. We want the // cache to be shared by all, and we don't use a static because we // don't want it to persist between look and feels. For that reason // we use a AppContext specific Paint9Painter. It's backed via // a WeakRef so that it can go away if the look and feel changes. synchronized(CACHE_KEY) { WeakReference<Paint9Painter> cacheRef = (WeakReference<Paint9Painter>)AppContext.getAppContext(). get(CACHE_KEY); Paint9Painter painter; if (cacheRef == null || (painter = cacheRef.get()) == null) { painter = new Paint9Painter(30); cacheRef = new WeakReference(painter); AppContext.getAppContext().put(CACHE_KEY, cacheRef); } return painter; } } ImagePainter(boolean tiles, boolean paintCenter, Insets sourceInsets, Insets destinationInsets, URL path, boolean center) { if (sourceInsets != null) { this.sInsets = (Insets)sourceInsets.clone(); } if (destinationInsets == null) { dInsets = sInsets; } else { this.dInsets = (Insets)destinationInsets.clone(); } this.tiles = tiles; this.paintCenter = paintCenter; this.imageCache = getPaint9Painter(); this.path = path; this.center = center; } public boolean getTiles() { return tiles; } public boolean getPaintsCenter() { return paintCenter; } public boolean getCenter() { return center; } public Insets getInsets(Insets insets) { if (insets == null) { return (Insets)this.dInsets.clone(); } insets.left = this.dInsets.left; insets.right = this.dInsets.right; insets.top = this.dInsets.top; insets.bottom = this.dInsets.bottom; return insets; } public Image getImage() { if (image == null) { image = new ImageIcon(path, null).getImage(); } return image; } private void paint(SynthContext context, Graphics g, int x, int y, int w, int h) { Image image = getImage(); if (Paint9Painter.validImage(image)) { Paint9Painter.PaintType type; if (getCenter()) { type = Paint9Painter.PaintType.CENTER; } else if (!getTiles()) { type = Paint9Painter.PaintType.PAINT9_STRETCH; } else { type = Paint9Painter.PaintType.PAINT9_TILE; } int mask = Paint9Painter.PAINT_ALL; if (!getCenter() && !getPaintsCenter()) { mask |= Paint9Painter.PAINT_CENTER; } imageCache.paint(context.getComponent(), g, x, y, w, h, image, sInsets, dInsets, type, mask); } } // SynthPainter public void paintArrowButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintArrowButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintArrowButtonForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int direction) { paint(context, g, x, y, w, h); } // BUTTON public void paintButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // CHECK_BOX_MENU_ITEM public void paintCheckBoxMenuItemBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintCheckBoxMenuItemBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // CHECK_BOX public void paintCheckBoxBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintCheckBoxBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // COLOR_CHOOSER public void paintColorChooserBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintColorChooserBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // COMBO_BOX public void paintComboBoxBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintComboBoxBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // DESKTOP_ICON public void paintDesktopIconBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintDesktopIconBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // DESKTOP_PANE public void paintDesktopPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintDesktopPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // EDITOR_PANE public void paintEditorPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintEditorPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // FILE_CHOOSER public void paintFileChooserBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintFileChooserBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // FORMATTED_TEXT_FIELD public void paintFormattedTextFieldBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintFormattedTextFieldBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // INTERNAL_FRAME_TITLE_PANE public void paintInternalFrameTitlePaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintInternalFrameTitlePaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // INTERNAL_FRAME public void paintInternalFrameBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintInternalFrameBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // LABEL public void paintLabelBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintLabelBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // LIST public void paintListBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintListBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // MENU_BAR public void paintMenuBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintMenuBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // MENU_ITEM public void paintMenuItemBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintMenuItemBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // MENU public void paintMenuBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintMenuBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // OPTION_PANE public void paintOptionPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintOptionPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // PANEL public void paintPanelBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintPanelBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // PANEL public void paintPasswordFieldBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintPasswordFieldBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // POPUP_MENU public void paintPopupMenuBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintPopupMenuBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // PROGRESS_BAR public void paintProgressBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintProgressBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } public void paintProgressBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintProgressBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } public void paintProgressBarForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } // RADIO_BUTTON_MENU_ITEM public void paintRadioButtonMenuItemBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintRadioButtonMenuItemBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // RADIO_BUTTON public void paintRadioButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintRadioButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // ROOT_PANE public void paintRootPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintRootPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // SCROLL_BAR public void paintScrollBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintScrollBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } public void paintScrollBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintScrollBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } // SCROLL_BAR_THUMB public void paintScrollBarThumbBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } public void paintScrollBarThumbBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } // SCROLL_BAR_TRACK public void paintScrollBarTrackBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintScrollBarTrackBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } public void paintScrollBarTrackBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintScrollBarTrackBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } // SCROLL_PANE public void paintScrollPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintScrollPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // SEPARATOR public void paintSeparatorBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintSeparatorBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } public void paintSeparatorBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintSeparatorBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } public void paintSeparatorForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } // SLIDER public void paintSliderBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintSliderBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } public void paintSliderBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintSliderBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } // SLIDER_THUMB public void paintSliderThumbBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } public void paintSliderThumbBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } // SLIDER_TRACK public void paintSliderTrackBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintSliderTrackBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } public void paintSliderTrackBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintSliderTrackBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } // SPINNER public void paintSpinnerBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintSpinnerBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // SPLIT_PANE_DIVIDER public void paintSplitPaneDividerBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintSplitPaneDividerBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } public void paintSplitPaneDividerForeground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } public void paintSplitPaneDragDivider(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } // SPLIT_PANE public void paintSplitPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintSplitPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // TABBED_PANE public void paintTabbedPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintTabbedPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // TABBED_PANE_TAB_AREA public void paintTabbedPaneTabAreaBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintTabbedPaneTabAreaBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } public void paintTabbedPaneTabAreaBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintTabbedPaneTabAreaBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } // TABBED_PANE_TAB public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex) { paint(context, g, x, y, w, h); } public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex, int orientation) { paint(context, g, x, y, w, h); } public void paintTabbedPaneTabBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex) { paint(context, g, x, y, w, h); } public void paintTabbedPaneTabBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int tabIndex, int orientation) { paint(context, g, x, y, w, h); } // TABBED_PANE_CONTENT public void paintTabbedPaneContentBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintTabbedPaneContentBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // TABLE_HEADER public void paintTableHeaderBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintTableHeaderBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // TABLE public void paintTableBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintTableBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // TEXT_AREA public void paintTextAreaBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintTextAreaBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // TEXT_PANE public void paintTextPaneBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintTextPaneBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // TEXT_FIELD public void paintTextFieldBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintTextFieldBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // TOGGLE_BUTTON public void paintToggleButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintToggleButtonBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // TOOL_BAR public void paintToolBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintToolBarBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } public void paintToolBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintToolBarBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } // TOOL_BAR_CONTENT public void paintToolBarContentBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintToolBarContentBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } public void paintToolBarContentBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintToolBarContentBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } // TOOL_DRAG_WINDOW public void paintToolBarDragWindowBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintToolBarDragWindowBackground(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } public void paintToolBarDragWindowBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintToolBarDragWindowBorder(SynthContext context, Graphics g, int x, int y, int w, int h, int orientation) { paint(context, g, x, y, w, h); } // TOOL_TIP public void paintToolTipBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintToolTipBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // TREE public void paintTreeBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintTreeBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // TREE_CELL public void paintTreeCellBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintTreeCellBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintTreeCellFocus(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } // VIEWPORT public void paintViewportBackground(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } public void paintViewportBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { paint(context, g, x, y, w, h); } }
Java
/* * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import java.awt.event.*; import java.awt.peer.LightweightPeer; import javax.swing.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.BasicInternalFrameUI; import javax.swing.event.*; import java.beans.*; import java.io.Serializable; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Synth's InternalFrameUI. * * @author David Kloba * @author Joshua Outwater * @author Rich Schiavi */ class SynthInternalFrameUI extends BasicInternalFrameUI implements SynthUI, PropertyChangeListener { private SynthStyle style; private static DesktopManager sharedDesktopManager; private boolean componentListenerAdded = false; private Rectangle parentBounds; public static ComponentUI createUI(JComponent b) { return new SynthInternalFrameUI((JInternalFrame)b); } public SynthInternalFrameUI(JInternalFrame b) { super(b); } public void installDefaults() { frame.setLayout(internalFrameLayout = createLayoutManager()); updateStyle(frame); } protected void installListeners() { super.installListeners(); frame.addPropertyChangeListener(this); } protected void uninstallComponents() { if (frame.getComponentPopupMenu() instanceof UIResource) { frame.setComponentPopupMenu(null); } super.uninstallComponents(); } protected void uninstallListeners() { frame.removePropertyChangeListener(this); super.uninstallListeners(); } private void updateStyle(JComponent c) { SynthContext context = getContext(c, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { Icon frameIcon = frame.getFrameIcon(); if (frameIcon == null || frameIcon instanceof UIResource) { frame.setFrameIcon(context.getStyle().getIcon( context, "InternalFrame.icon")); } if (oldStyle != null) { uninstallKeyboardActions(); installKeyboardActions(); } } context.dispose(); } protected void uninstallDefaults() { SynthContext context = getContext(frame, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; if(frame.getLayout() == internalFrameLayout) { frame.setLayout(null); } } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } public int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } protected JComponent createNorthPane(JInternalFrame w) { titlePane = new SynthInternalFrameTitlePane(w); titlePane.setName("InternalFrame.northPane"); return titlePane; } protected ComponentListener createComponentListener() { if (UIManager.getBoolean("InternalFrame.useTaskBar")) { return new ComponentHandler() { public void componentResized(ComponentEvent e) { if (frame != null && frame.isMaximum()) { JDesktopPane desktop = (JDesktopPane)e.getSource(); for (Component comp : desktop.getComponents()) { if (comp instanceof SynthDesktopPaneUI.TaskBar) { frame.setBounds(0, 0, desktop.getWidth(), desktop.getHeight() - comp.getHeight()); frame.revalidate(); break; } } } // Update the new parent bounds for next resize, but don't // let the super method touch this frame JInternalFrame f = frame; frame = null; super.componentResized(e); frame = f; } }; } else { return super.createComponentListener(); } } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintInternalFrameBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintInternalFrameBorder(context, g, x, y, w, h); } public void propertyChange(PropertyChangeEvent evt) { SynthStyle oldStyle = style; JInternalFrame f = (JInternalFrame)evt.getSource(); String prop = evt.getPropertyName(); if (SynthLookAndFeel.shouldUpdateStyle(evt)) { updateStyle(f); } if (style == oldStyle && (prop == JInternalFrame.IS_MAXIMUM_PROPERTY || prop == JInternalFrame.IS_SELECTED_PROPERTY)) { // Border (and other defaults) may need to change SynthContext context = getContext(f, ENABLED); style.uninstallDefaults(context); style.installDefaults(context, this); } } }
Java
/* * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.BasicSpinnerUI; import java.beans.*; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Synth's SpinnerUI. * * @author Hans Muller * @author Joshua Outwater */ class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener, SynthUI { private SynthStyle style; /** {@collect.stats} * A FocusListener implementation which causes the entire spinner to be * repainted whenever the editor component (typically a text field) becomes * focused, or loses focus. This is necessary because since SynthSpinnerUI * is composed of an editor and two buttons, it is necessary that all three * components indicate that they are "focused" so that they can be drawn * appropriately. The repaint is used to ensure that the buttons are drawn * in the new focused or unfocused state, mirroring that of the editor. */ private EditorFocusHandler editorFocusHandler = new EditorFocusHandler(); /** {@collect.stats} * Returns a new instance of SynthSpinnerUI. * * @param c the JSpinner (not used) * @see ComponentUI#createUI * @return a new SynthSpinnerUI object */ public static ComponentUI createUI(JComponent c) { return new SynthSpinnerUI(); } @Override protected void installListeners() { super.installListeners(); spinner.addPropertyChangeListener(this); JComponent editor = spinner.getEditor(); if (editor instanceof JSpinner.DefaultEditor) { JTextField tf = ((JSpinner.DefaultEditor)editor).getTextField(); if (tf != null) { tf.addFocusListener(editorFocusHandler); } } } /** {@collect.stats} * Removes the <code>propertyChangeListener</code> added * by installListeners. * <p> * This method is called by <code>uninstallUI</code>. * * @see #installListeners */ @Override protected void uninstallListeners() { super.uninstallListeners(); spinner.removePropertyChangeListener(this); JComponent editor = spinner.getEditor(); if (editor instanceof JSpinner.DefaultEditor) { JTextField tf = ((JSpinner.DefaultEditor)editor).getTextField(); if (tf != null) { tf.removeFocusListener(editorFocusHandler); } } } /** {@collect.stats} * Initialize the <code>JSpinner</code> <code>border</code>, * <code>foreground</code>, and <code>background</code>, properties * based on the corresponding "Spinner.*" properties from defaults table. * The <code>JSpinners</code> layout is set to the value returned by * <code>createLayout</code>. This method is called by <code>installUI</code>. * * @see #uninstallDefaults * @see #installUI * @see #createLayout * @see LookAndFeel#installBorder * @see LookAndFeel#installColors */ protected void installDefaults() { LayoutManager layout = spinner.getLayout(); if (layout == null || layout instanceof UIResource) { spinner.setLayout(createLayout()); } updateStyle(spinner); } private void updateStyle(JSpinner c) { SynthContext context = getContext(c, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { if (oldStyle != null) { // Only call installKeyboardActions as uninstall is not // public. installKeyboardActions(); } } context.dispose(); } /** {@collect.stats} * Sets the <code>JSpinner's</code> layout manager to null. This * method is called by <code>uninstallUI</code>. * * @see #installDefaults * @see #uninstallUI */ protected void uninstallDefaults() { if (spinner.getLayout() instanceof UIResource) { spinner.setLayout(null); } SynthContext context = getContext(spinner, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; } protected LayoutManager createLayout() { return new SpinnerLayout(); } /** {@collect.stats} * Create a component that will replace the spinner models value * with the object returned by <code>spinner.getPreviousValue</code>. * By default the <code>previousButton</code> is a JButton * who's <code>ActionListener</code> updates it's <code>JSpinner</code> * ancestors model. If a previousButton isn't needed (in a subclass) * then override this method to return null. * * @return a component that will replace the spinners model with the * next value in the sequence, or null * @see #installUI * @see #createNextButton */ protected Component createPreviousButton() { JButton b = new SynthArrowButton(SwingConstants.SOUTH); b.setName("Spinner.previousButton"); installPreviousButtonListeners(b); return b; } /** {@collect.stats} * Create a component that will replace the spinner models value * with the object returned by <code>spinner.getNextValue</code>. * By default the <code>nextButton</code> is a JButton * who's <code>ActionListener</code> updates it's <code>JSpinner</code> * ancestors model. If a nextButton isn't needed (in a subclass) * then override this method to return null. * * @return a component that will replace the spinners model with the * next value in the sequence, or null * @see #installUI * @see #createPreviousButton */ protected Component createNextButton() { JButton b = new SynthArrowButton(SwingConstants.NORTH); b.setName("Spinner.nextButton"); installNextButtonListeners(b); return b; } /** {@collect.stats} * This method is called by installUI to get the editor component * of the <code>JSpinner</code>. By default it just returns * <code>JSpinner.getEditor()</code>. Subclasses can override * <code>createEditor</code> to return a component that contains * the spinner's editor or null, if they're going to handle adding * the editor to the <code>JSpinner</code> in an * <code>installUI</code> override. * <p> * Typically this method would be overridden to wrap the editor * with a container with a custom border, since one can't assume * that the editors border can be set directly. * <p> * The <code>replaceEditor</code> method is called when the spinners * editor is changed with <code>JSpinner.setEditor</code>. If you've * overriden this method, then you'll probably want to override * <code>replaceEditor</code> as well. * * @return the JSpinners editor JComponent, spinner.getEditor() by default * @see #installUI * @see #replaceEditor * @see JSpinner#getEditor */ protected JComponent createEditor() { JComponent editor = spinner.getEditor(); editor.setName("Spinner.editor"); updateEditorAlignment(editor); return editor; } /** {@collect.stats} * Called by the <code>PropertyChangeListener</code> when the * <code>JSpinner</code> editor property changes. It's the responsibility * of this method to remove the old editor and add the new one. By * default this operation is just: * <pre> * spinner.remove(oldEditor); * spinner.add(newEditor, "Editor"); * </pre> * The implementation of <code>replaceEditor</code> should be coordinated * with the <code>createEditor</code> method. * * @see #createEditor * @see #createPropertyChangeListener */ protected void replaceEditor(JComponent oldEditor, JComponent newEditor) { spinner.remove(oldEditor); updateEditorAlignment(newEditor); spinner.add(newEditor, "Editor"); if (oldEditor instanceof JSpinner.DefaultEditor) { JTextField tf = ((JSpinner.DefaultEditor)oldEditor).getTextField(); if (tf != null) { tf.removeFocusListener(editorFocusHandler); } } if (newEditor instanceof JSpinner.DefaultEditor) { JTextField tf = ((JSpinner.DefaultEditor)newEditor).getTextField(); if (tf != null) { tf.addFocusListener(editorFocusHandler); } } } private void updateEditorAlignment(JComponent editor) { if (editor instanceof JSpinner.DefaultEditor) { SynthContext context = getContext(spinner); Integer alignment = (Integer)context.getStyle().get( context, "Spinner.editorAlignment"); JTextField text = ((JSpinner.DefaultEditor)editor).getTextField(); if (alignment != null) { text.setHorizontalAlignment(alignment); } // copy across the sizeVariant property to the editor text.putClientProperty("JComponent.sizeVariant", spinner.getClientProperty("JComponent.sizeVariant")); } } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintSpinnerBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintSpinnerBorder(context, g, x, y, w, h); } /** {@collect.stats} * A simple layout manager for the editor and the next/previous buttons. * See the SynthSpinnerUI javadoc for more information about exactly * how the components are arranged. */ private static class SpinnerLayout implements LayoutManager, UIResource { private Component nextButton = null; private Component previousButton = null; private Component editor = null; public void addLayoutComponent(String name, Component c) { if ("Next".equals(name)) { nextButton = c; } else if ("Previous".equals(name)) { previousButton = c; } else if ("Editor".equals(name)) { editor = c; } } public void removeLayoutComponent(Component c) { if (c == nextButton) { nextButton = null; } else if (c == previousButton) { previousButton = null; } else if (c == editor) { editor = null; } } private Dimension preferredSize(Component c) { return (c == null) ? new Dimension(0, 0) : c.getPreferredSize(); } public Dimension preferredLayoutSize(Container parent) { Dimension nextD = preferredSize(nextButton); Dimension previousD = preferredSize(previousButton); Dimension editorD = preferredSize(editor); /* Force the editors height to be a multiple of 2 */ editorD.height = ((editorD.height + 1) / 2) * 2; Dimension size = new Dimension(editorD.width, editorD.height); size.width += Math.max(nextD.width, previousD.width); Insets insets = parent.getInsets(); size.width += insets.left + insets.right; size.height += insets.top + insets.bottom; return size; } public Dimension minimumLayoutSize(Container parent) { return preferredLayoutSize(parent); } private void setBounds(Component c, int x, int y, int width, int height) { if (c != null) { c.setBounds(x, y, width, height); } } public void layoutContainer(Container parent) { Insets insets = parent.getInsets(); int availWidth = parent.getWidth() - (insets.left + insets.right); int availHeight = parent.getHeight() - (insets.top + insets.bottom); Dimension nextD = preferredSize(nextButton); Dimension previousD = preferredSize(previousButton); int nextHeight = availHeight / 2; int previousHeight = availHeight - nextHeight; int buttonsWidth = Math.max(nextD.width, previousD.width); int editorWidth = availWidth - buttonsWidth; /* Deal with the spinners componentOrientation property. */ int editorX, buttonsX; if (parent.getComponentOrientation().isLeftToRight()) { editorX = insets.left; buttonsX = editorX + editorWidth; } else { buttonsX = insets.left; editorX = buttonsX + buttonsWidth; } int previousY = insets.top + nextHeight; setBounds(editor, editorX, insets.top, editorWidth, availHeight); setBounds(nextButton, buttonsX, insets.top, buttonsWidth, nextHeight); setBounds(previousButton, buttonsX, previousY, buttonsWidth, previousHeight); } } public void propertyChange(PropertyChangeEvent e) { String propertyName = e.getPropertyName(); JSpinner spinner = (JSpinner)(e.getSource()); SpinnerUI spinnerUI = spinner.getUI(); if (spinnerUI instanceof SynthSpinnerUI) { SynthSpinnerUI ui = (SynthSpinnerUI)spinnerUI; if (SynthLookAndFeel.shouldUpdateStyle(e)) { ui.updateStyle(spinner); } } } /** {@collect.stats} Listen to editor text field focus changes and repaint whole spinner */ private class EditorFocusHandler implements FocusListener{ /** {@collect.stats} Invoked when a editor text field gains the keyboard focus. */ public void focusGained(FocusEvent e) { spinner.repaint(); } /** {@collect.stats} Invoked when a editor text field loses the keyboard focus. */ public void focusLost(FocusEvent e) { spinner.repaint(); } } /** {@collect.stats} Override the arrowbuttons focus handling to follow the text fields focus */ private class SpinnerArrowButton extends SynthArrowButton{ public SpinnerArrowButton(int direction) { super(direction); } @Override public boolean isFocusOwner() { if (spinner == null){ return super.isFocusOwner(); } else if (spinner.getEditor() instanceof JSpinner.DefaultEditor){ return ((JSpinner.DefaultEditor)spinner.getEditor()) .getTextField().isFocusOwner(); } else if (spinner.getEditor()!= null) { return spinner.getEditor().isFocusOwner(); } else { return super.isFocusOwner(); } } } }
Java
/* * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.Component; import java.awt.Container; import java.awt.Adjustable; import java.awt.event.*; import java.awt.Graphics; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Rectangle; import java.awt.Point; import java.awt.Insets; import java.awt.Color; import java.awt.IllegalComponentStateException; import java.awt.Polygon; import java.beans.*; import java.util.Dictionary; import java.util.Enumeration; import javax.swing.border.AbstractBorder; import javax.swing.*; import javax.swing.event.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.BasicSliderUI; import sun.swing.plaf.synth.SynthUI; import sun.swing.SwingUtilities2; /** {@collect.stats} * Synth's SliderUI. * * @author Joshua Outwater */ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener, SynthUI { protected Dimension contentDim = new Dimension(); protected Rectangle valueRect = new Rectangle(); protected boolean paintValue; /** {@collect.stats} * When a JSlider is used as a renderer in a JTable, its layout is not * being recomputed even though the size is changing. Even though there * is a ComponentListener installed, it is not being notified. As such, * at times when being asked to paint the layout should first be redone. * At the end of the layout method we set this lastSize variable, which * represents the size of the slider the last time it was layed out. * * In the paint method we then check to see that this is accurate, that * the slider has not changed sizes since being last layed out. If necessary * we recompute the layout. */ private Dimension lastSize = null; private int trackHeight; private int trackBorder; private int thumbWidth; private int thumbHeight; private SynthStyle style; private SynthStyle sliderTrackStyle; private SynthStyle sliderThumbStyle; /** {@collect.stats} Used to determine the color to paint the thumb. */ private transient boolean thumbActive; //happens on rollover, and when pressed private transient boolean thumbPressed; //happens when mouse was depressed while over thumb /////////////////////////////////////////////////// // ComponentUI Interface Implementation methods /////////////////////////////////////////////////// public static ComponentUI createUI(JComponent c) { return new SynthSliderUI((JSlider)c); } public SynthSliderUI(JSlider c) { super(c); } protected void installDefaults(JSlider slider) { updateStyle(slider); } protected void uninstallDefaults() { SynthContext context = getContext(slider, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; context = getContext(slider, Region.SLIDER_TRACK, ENABLED); sliderTrackStyle.uninstallDefaults(context); context.dispose(); sliderTrackStyle = null; context = getContext(slider, Region.SLIDER_THUMB, ENABLED); sliderThumbStyle.uninstallDefaults(context); context.dispose(); sliderThumbStyle = null; } protected void installListeners(JSlider slider) { super.installListeners(slider); slider.addPropertyChangeListener(this); } protected void uninstallListeners(JSlider slider) { slider.removePropertyChangeListener(this); super.uninstallListeners(slider); } private void updateStyle(JSlider c) { SynthContext context = getContext(c, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { thumbWidth = style.getInt(context, "Slider.thumbWidth", 30); thumbHeight = style.getInt(context, "Slider.thumbHeight", 14); // handle scaling for sizeVarients for special case components. The // key "JComponent.sizeVariant" scales for large/small/mini // components are based on Apples LAF String scaleKey = (String)slider.getClientProperty( "JComponent.sizeVariant"); if (scaleKey != null){ if ("large".equals(scaleKey)){ thumbWidth *= 1.15; thumbHeight *= 1.15; } else if ("small".equals(scaleKey)){ thumbWidth *= 0.857; thumbHeight *= 0.857; } else if ("mini".equals(scaleKey)){ thumbWidth *= 0.784; thumbHeight *= 0.784; } } trackBorder = style.getInt(context, "Slider.trackBorder", 1); trackHeight = thumbHeight + trackBorder * 2; paintValue = style.getBoolean(context, "Slider.paintValue", true); if (oldStyle != null) { uninstallKeyboardActions(c); installKeyboardActions(c); } } context.dispose(); context = getContext(c, Region.SLIDER_TRACK, ENABLED); sliderTrackStyle = SynthLookAndFeel.updateStyle(context, this); context.dispose(); context = getContext(c, Region.SLIDER_THUMB, ENABLED); sliderThumbStyle = SynthLookAndFeel.updateStyle(context, this); context.dispose(); } protected TrackListener createTrackListener(JSlider s) { return new SynthTrackListener(); } private void updateThumbState(int x, int y) { setThumbActive(thumbRect.contains(x, y)); } private void updateThumbState(int x, int y, boolean pressed) { updateThumbState(x, y); setThumbPressed(pressed); } private void setThumbActive(boolean active) { if (thumbActive != active) { thumbActive = active; slider.repaint(thumbRect); } } private void setThumbPressed(boolean pressed) { if (thumbPressed != pressed) { thumbPressed = pressed; slider.repaint(thumbRect); } } public int getBaseline(JComponent c, int width, int height) { if (c == null) { throw new NullPointerException("Component must be non-null"); } if (width < 0 || height < 0) { throw new IllegalArgumentException( "Width and height must be >= 0"); } if (slider.getPaintLabels() && labelsHaveSameBaselines()) { // Get the insets for the track. Insets trackInsets = new Insets(0, 0, 0, 0); SynthContext trackContext = getContext(slider, Region.SLIDER_TRACK); style.getInsets(trackContext, trackInsets); trackContext.dispose(); if (slider.getOrientation() == JSlider.HORIZONTAL) { int valueHeight = 0; if (paintValue) { SynthContext context = getContext(slider); valueHeight = context.getStyle().getGraphicsUtils(context). getMaximumCharHeight(context); context.dispose(); } int tickHeight = 0; if (slider.getPaintTicks()) { tickHeight = getTickLength(); } int labelHeight = getHeightOfTallestLabel(); int contentHeight = valueHeight + trackHeight + trackInsets.top + trackInsets.bottom + tickHeight + labelHeight + 4; int centerY = height / 2 - contentHeight / 2; centerY += valueHeight + 2; centerY += trackHeight + trackInsets.top + trackInsets.bottom; centerY += tickHeight + 2; Component label = (Component)slider.getLabelTable(). elements().nextElement(); Dimension pref = label.getPreferredSize(); return centerY + label.getBaseline(pref.width, pref.height); } else { // VERTICAL Integer value = slider.getInverted() ? getLowestValue() : getHighestValue(); if (value != null) { int valueY = insetCache.top; int valueHeight = 0; if (paintValue) { SynthContext context = getContext(slider); valueHeight = context.getStyle().getGraphicsUtils( context).getMaximumCharHeight(context); context.dispose(); } int contentHeight = height - insetCache.top - insetCache.bottom; int trackY = valueY + valueHeight; int trackHeight = contentHeight - valueHeight; int yPosition = yPositionForValue(value.intValue(), trackY, trackHeight); Component label = (Component)slider.getLabelTable(). get(value); Dimension pref = label.getPreferredSize(); return yPosition - pref.height / 2 + label.getBaseline(pref.width, pref.height); } } } return -1; } public Dimension getPreferredSize(JComponent c) { recalculateIfInsetsChanged(); Dimension d = new Dimension(contentDim); if (slider.getOrientation() == JSlider.VERTICAL) { d.height = 200; } else { d.width = 200; } Insets i = slider.getInsets(); d.width += i.left + i.right; d.height += i.top + i.bottom; return d; } public Dimension getMinimumSize(JComponent c) { recalculateIfInsetsChanged(); Dimension d = new Dimension(contentDim); if (slider.getOrientation() == JSlider.VERTICAL) { d.height = thumbRect.height + insetCache.top + insetCache.bottom; } else { d.width = thumbRect.width + insetCache.left + insetCache.right; } return d; } protected void calculateGeometry() { layout(); calculateThumbLocation(); } protected void layout() { SynthContext context = getContext(slider); SynthGraphicsUtils synthGraphics = style.getGraphicsUtils(context); // Set the thumb size. Dimension size = getThumbSize(); thumbRect.setSize(size.width, size.height); // Get the insets for the track. Insets trackInsets = new Insets(0, 0, 0, 0); SynthContext trackContext = getContext(slider, Region.SLIDER_TRACK); style.getInsets(trackContext, trackInsets); trackContext.dispose(); if (slider.getOrientation() == JSlider.HORIZONTAL) { // Calculate the height of all the subcomponents so we can center // them. valueRect.height = 0; if (paintValue) { valueRect.height = synthGraphics.getMaximumCharHeight(context); } trackRect.height = trackHeight; tickRect.height = 0; if (slider.getPaintTicks()) { tickRect.height = getTickLength(); } labelRect.height = 0; if (slider.getPaintLabels()) { labelRect.height = getHeightOfTallestLabel(); } contentDim.height = valueRect.height + trackRect.height + trackInsets.top + trackInsets.bottom + tickRect.height + labelRect.height + 4; contentDim.width = slider.getWidth() - insetCache.left - insetCache.right; // Check if any of the labels will paint out of bounds. int pad = 0; if (slider.getPaintLabels()) { // Calculate the track rectangle. It is necessary for // xPositionForValue to return correct values. trackRect.x = insetCache.left; trackRect.width = contentDim.width; Dictionary dictionary = slider.getLabelTable(); if (dictionary != null) { int minValue = slider.getMinimum(); int maxValue = slider.getMaximum(); // Iterate through the keys in the dictionary and find the // first and last labels indices that fall within the // slider range. int firstLblIdx = Integer.MAX_VALUE; int lastLblIdx = Integer.MIN_VALUE; for (Enumeration keys = dictionary.keys(); keys.hasMoreElements(); ) { int keyInt = ((Integer)keys.nextElement()).intValue(); if (keyInt >= minValue && keyInt < firstLblIdx) { firstLblIdx = keyInt; } if (keyInt <= maxValue && keyInt > lastLblIdx) { lastLblIdx = keyInt; } } // Calculate the pad necessary for the labels at the first // and last visible indices. pad = getPadForLabel(firstLblIdx); pad = Math.max(pad, getPadForLabel(lastLblIdx)); } } // Calculate the painting rectangles for each of the different // slider areas. valueRect.x = trackRect.x = tickRect.x = labelRect.x = (insetCache.left + pad); valueRect.width = trackRect.width = tickRect.width = labelRect.width = (contentDim.width - (pad * 2)); int centerY = slider.getHeight() / 2 - contentDim.height / 2; valueRect.y = centerY; centerY += valueRect.height + 2; trackRect.y = centerY + trackInsets.top; centerY += trackRect.height + trackInsets.top + trackInsets.bottom; tickRect.y = centerY; centerY += tickRect.height + 2; labelRect.y = centerY; centerY += labelRect.height; } else { // Calculate the width of all the subcomponents so we can center // them. trackRect.width = trackHeight; tickRect.width = 0; if (slider.getPaintTicks()) { tickRect.width = getTickLength(); } labelRect.width = 0; if (slider.getPaintLabels()) { labelRect.width = getWidthOfWidestLabel(); } valueRect.y = insetCache.top; valueRect.height = 0; if (paintValue) { valueRect.height = synthGraphics.getMaximumCharHeight(context); } // Get the max width of the min or max value of the slider. FontMetrics fm = slider.getFontMetrics(slider.getFont()); valueRect.width = Math.max( synthGraphics.computeStringWidth(context, slider.getFont(), fm, "" + slider.getMaximum()), synthGraphics.computeStringWidth(context, slider.getFont(), fm, "" + slider.getMinimum())); int l = valueRect.width / 2; int w1 = trackInsets.left + trackRect.width / 2; int w2 = trackRect.width / 2 + trackInsets.right + tickRect.width + labelRect.width; contentDim.width = Math.max(w1, l) + Math.max(w2, l) + 2 + insetCache.left + insetCache.right; contentDim.height = slider.getHeight() - insetCache.top - insetCache.bottom; // Layout the components. trackRect.y = tickRect.y = labelRect.y = valueRect.y + valueRect.height; trackRect.height = tickRect.height = labelRect.height = contentDim.height - valueRect.height; int startX = slider.getWidth() / 2 - contentDim.width / 2; if (SynthLookAndFeel.isLeftToRight(slider)) { if (l > w1) { startX += (l - w1); } trackRect.x = startX + trackInsets.left; startX += trackInsets.left + trackRect.width + trackInsets.right; tickRect.x = startX; labelRect.x = startX + tickRect.width + 2; } else { if (l > w2) { startX += (l - w2); } labelRect.x = startX; startX += labelRect.width + 2; tickRect.x = startX; trackRect.x = startX + tickRect.width + trackInsets.left; } } context.dispose(); lastSize = slider.getSize(); } /** {@collect.stats} * Calculates the pad for the label at the specified index. * * @param index index of the label to calculate pad for. * @return padding required to keep label visible. */ private int getPadForLabel(int i) { Dictionary dictionary = slider.getLabelTable(); int pad = 0; Object o = dictionary.get(i); if (o != null) { Component c = (Component)o; int centerX = xPositionForValue(i); int cHalfWidth = c.getPreferredSize().width / 2; if (centerX - cHalfWidth < insetCache.left) { pad = Math.max(pad, insetCache.left - (centerX - cHalfWidth)); } if (centerX + cHalfWidth > slider.getWidth() - insetCache.right) { pad = Math.max(pad, (centerX + cHalfWidth) - (slider.getWidth() - insetCache.right)); } } return pad; } protected void calculateThumbLocation() { super.calculateThumbLocation(); if (slider.getOrientation() == JSlider.HORIZONTAL) { thumbRect.y += trackBorder; } else { thumbRect.x += trackBorder; } Point mousePosition = slider.getMousePosition(); if(mousePosition != null) { updateThumbState(mousePosition.x, mousePosition.y); } } protected void calculateTickRect() { if (slider.getOrientation() == JSlider.HORIZONTAL) { tickRect.x = trackRect.x; tickRect.y = trackRect.y + trackRect.height + 2 + getTickLength(); tickRect.width = trackRect.width; tickRect.height = getTickLength(); if (!slider.getPaintTicks()) { --tickRect.y; tickRect.height = 0; } } else { if (SynthLookAndFeel.isLeftToRight(slider)) { tickRect.x = trackRect.x + trackRect.width; tickRect.width = getTickLength(); } else { tickRect.width = getTickLength(); tickRect.x = trackRect.x - tickRect.width; } tickRect.y = trackRect.y; tickRect.height = trackRect.height; if (!slider.getPaintTicks()) { --tickRect.x; tickRect.width = 0; } } } private static Rectangle unionRect = new Rectangle(); public void setThumbLocation(int x, int y) { super.setThumbLocation(x, y); // Value rect is tied to the thumb location. We need to repaint when // the thumb repaints. slider.repaint(valueRect.x, valueRect.y, valueRect.width, valueRect.height); setThumbActive(false); } protected int xPositionForValue(int value) { int min = slider.getMinimum(); int max = slider.getMaximum(); int trackLeft = trackRect.x + thumbRect.width / 2 + trackBorder; int trackRight = trackRect.x + trackRect.width - thumbRect.width / 2 - trackBorder; int trackLength = trackRight - trackLeft; double valueRange = (double)max - (double)min; double pixelsPerValue = (double)trackLength / valueRange; int xPosition; if (!drawInverted()) { xPosition = trackLeft; xPosition += Math.round( pixelsPerValue * ((double)value - min)); } else { xPosition = trackRight; xPosition -= Math.round( pixelsPerValue * ((double)value - min)); } xPosition = Math.max(trackLeft, xPosition); xPosition = Math.min(trackRight, xPosition); return xPosition; } protected int yPositionForValue(int value, int trackY, int trackHeight) { int min = slider.getMinimum(); int max = slider.getMaximum(); int trackTop = trackY + thumbRect.height / 2 + trackBorder; int trackBottom = trackY + trackHeight - thumbRect.height / 2 - trackBorder; int trackLength = trackBottom - trackTop; double valueRange = (double)max - (double)min; double pixelsPerValue = (double)trackLength / (double)valueRange; int yPosition; if (!drawInverted()) { yPosition = trackTop; yPosition += Math.round(pixelsPerValue * ((double)max - value)); } else { yPosition = trackTop; yPosition += Math.round(pixelsPerValue * ((double)value - min)); } yPosition = Math.max(trackTop, yPosition); yPosition = Math.min(trackBottom, yPosition); return yPosition; } /** {@collect.stats} * Returns a value give a y position. If yPos is past the track at the * top or the bottom it will set the value to the min or max of the * slider, depending if the slider is inverted or not. */ public int valueForYPosition(int yPos) { int value; int minValue = slider.getMinimum(); int maxValue = slider.getMaximum(); int trackTop = trackRect.y + thumbRect.height / 2 + trackBorder; int trackBottom = trackRect.y + trackRect.height - thumbRect.height / 2 - trackBorder; int trackLength = trackBottom - trackTop; if (yPos <= trackTop) { value = drawInverted() ? minValue : maxValue; } else if (yPos >= trackBottom) { value = drawInverted() ? maxValue : minValue; } else { int distanceFromTrackTop = yPos - trackTop; double valueRange = (double)maxValue - (double)minValue; double valuePerPixel = valueRange / (double)trackLength; int valueFromTrackTop = (int)Math.round(distanceFromTrackTop * valuePerPixel); value = drawInverted() ? minValue + valueFromTrackTop : maxValue - valueFromTrackTop; } return value; } /** {@collect.stats} * Returns a value give an x position. If xPos is past the track at the * left or the right it will set the value to the min or max of the * slider, depending if the slider is inverted or not. */ public int valueForXPosition(int xPos) { int value; int minValue = slider.getMinimum(); int maxValue = slider.getMaximum(); int trackLeft = trackRect.x + thumbRect.width / 2 + trackBorder; int trackRight = trackRect.x + trackRect.width - thumbRect.width / 2 - trackBorder; int trackLength = trackRight - trackLeft; if (xPos <= trackLeft) { value = drawInverted() ? maxValue : minValue; } else if (xPos >= trackRight) { value = drawInverted() ? minValue : maxValue; } else { int distanceFromTrackLeft = xPos - trackLeft; double valueRange = (double)maxValue - (double)minValue; double valuePerPixel = valueRange / (double)trackLength; int valueFromTrackLeft = (int)Math.round(distanceFromTrackLeft * valuePerPixel); value = drawInverted() ? maxValue - valueFromTrackLeft : minValue + valueFromTrackLeft; } return value; } protected Dimension getThumbSize() { Dimension size = new Dimension(); if (slider.getOrientation() == JSlider.VERTICAL) { size.width = thumbHeight; size.height = thumbWidth; } else { size.width = thumbWidth; size.height = thumbHeight; } return size; } protected void recalculateIfInsetsChanged() { SynthContext context = getContext(slider); Insets newInsets = style.getInsets(context, null); Insets compInsets = slider.getInsets(); newInsets.left += compInsets.left; newInsets.right += compInsets.right; newInsets.top += compInsets.top; newInsets.bottom += compInsets.bottom; if (!newInsets.equals(insetCache)) { insetCache = newInsets; calculateGeometry(); } context.dispose(); } public Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } public SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } public SynthContext getContext(JComponent c, Region subregion) { return getContext(c, subregion, getComponentState(c, subregion)); } private SynthContext getContext(JComponent c, Region subregion, int state) { SynthStyle style = null; Class klass = SynthContext.class; if (subregion == Region.SLIDER_TRACK) { style = sliderTrackStyle; } else if (subregion == Region.SLIDER_THUMB) { style = sliderThumbStyle; } return SynthContext.getContext(klass, c, subregion, style, state); } public int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } private int getComponentState(JComponent c, Region region) { if (region == Region.SLIDER_THUMB && thumbActive &&c.isEnabled()) { int state = thumbPressed ? PRESSED : MOUSE_OVER; if (c.isFocusOwner()) state |= FOCUSED; return state; } return SynthLookAndFeel.getComponentState(c); } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintSliderBackground(context, g, 0, 0, c.getWidth(), c.getHeight(), slider.getOrientation()); paint(context, g); context.dispose(); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } public void paint(SynthContext context, Graphics g) { recalculateIfInsetsChanged(); recalculateIfOrientationChanged(); Rectangle clip = g.getClipBounds(); if (lastSize == null || !lastSize.equals(slider.getSize())) { calculateGeometry(); } if (paintValue) { FontMetrics fm = SwingUtilities2.getFontMetrics(slider, g); int labelWidth = context.getStyle().getGraphicsUtils(context). computeStringWidth(context, g.getFont(), fm, "" + slider.getValue()); valueRect.x = thumbRect.x + (thumbRect.width - labelWidth) / 2; // For horizontal sliders, make sure value is not painted // outside slider bounds. if (slider.getOrientation() == JSlider.HORIZONTAL) { if (valueRect.x + labelWidth > insetCache.left + contentDim.width) { valueRect.x = (insetCache.left + contentDim.width) - labelWidth; } valueRect.x = Math.max(valueRect.x, 0); } g.setColor(context.getStyle().getColor( context, ColorType.TEXT_FOREGROUND)); context.getStyle().getGraphicsUtils(context).paintText( context, g, "" + slider.getValue(), valueRect.x, valueRect.y, -1); } SynthContext subcontext = getContext(slider, Region.SLIDER_TRACK); paintTrack(subcontext, g, trackRect); subcontext.dispose(); subcontext = getContext(slider, Region.SLIDER_THUMB); paintThumb(subcontext, g, thumbRect); subcontext.dispose(); if (slider.getPaintTicks() && clip.intersects(tickRect)) { paintTicks(g); } if (slider.getPaintLabels() && clip.intersects(labelRect)) { paintLabels(g); } } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintSliderBorder(context, g, x, y, w, h, slider.getOrientation()); } public void paintThumb(SynthContext context, Graphics g, Rectangle thumbBounds) { int orientation = slider.getOrientation(); SynthLookAndFeel.updateSubregion(context, g, thumbBounds); context.getPainter().paintSliderThumbBackground(context, g, thumbBounds.x, thumbBounds.y, thumbBounds.width, thumbBounds.height, orientation); context.getPainter().paintSliderThumbBorder(context, g, thumbBounds.x, thumbBounds.y, thumbBounds.width, thumbBounds.height, orientation); } public void paintTrack(SynthContext context, Graphics g, Rectangle trackBounds) { int orientation = slider.getOrientation(); SynthLookAndFeel.updateSubregion(context, g, trackBounds); context.getPainter().paintSliderTrackBackground(context, g, trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height, orientation); context.getPainter().paintSliderTrackBorder(context, g, trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height, orientation); } public void propertyChange(PropertyChangeEvent e) { if (SynthLookAndFeel.shouldUpdateStyle(e)) { updateStyle((JSlider)e.getSource()); } } ////////////////////////////////////////////////// /// Track Listener Class ////////////////////////////////////////////////// /** {@collect.stats} * Track mouse movements. */ protected class SynthTrackListener extends TrackListener { public void mouseExited(MouseEvent e) { setThumbActive(false); } public void mousePressed(MouseEvent e) { super.mousePressed(e); setThumbPressed(thumbRect.contains(e.getX(), e.getY())); } public void mouseReleased(MouseEvent e) { super.mouseReleased(e); updateThumbState(e.getX(), e.getY(), false); } public void mouseDragged(MouseEvent e) { SynthScrollBarUI ui; int thumbMiddle = 0; if (!slider.isEnabled()) { return; } currentMouseX = e.getX(); currentMouseY = e.getY(); if (!isDragging()) { return; } slider.setValueIsAdjusting(true); switch (slider.getOrientation()) { case JSlider.VERTICAL: int halfThumbHeight = thumbRect.height / 2; int thumbTop = e.getY() - offset; int trackTop = trackRect.y; int trackBottom = trackRect.y + trackRect.height - halfThumbHeight - trackBorder; int vMax = yPositionForValue(slider.getMaximum() - slider.getExtent()); if (drawInverted()) { trackBottom = vMax; trackTop = trackTop + halfThumbHeight; } else { trackTop = vMax; } thumbTop = Math.max(thumbTop, trackTop - halfThumbHeight); thumbTop = Math.min(thumbTop, trackBottom - halfThumbHeight); setThumbLocation(thumbRect.x, thumbTop); thumbMiddle = thumbTop + halfThumbHeight; slider.setValue(valueForYPosition(thumbMiddle)); break; case JSlider.HORIZONTAL: int halfThumbWidth = thumbRect.width / 2; int thumbLeft = e.getX() - offset; int trackLeft = trackRect.x + halfThumbWidth + trackBorder; int trackRight = trackRect.x + trackRect.width - halfThumbWidth - trackBorder; int hMax = xPositionForValue(slider.getMaximum() - slider.getExtent()); if (drawInverted()) { trackLeft = hMax; } else { trackRight = hMax; } thumbLeft = Math.max(thumbLeft, trackLeft - halfThumbWidth); thumbLeft = Math.min(thumbLeft, trackRight - halfThumbWidth); setThumbLocation(thumbLeft, thumbRect.y); thumbMiddle = thumbLeft + halfThumbWidth; slider.setValue(valueForXPosition(thumbMiddle)); break; default: return; } if (slider.getValueIsAdjusting()) { setThumbActive(true); } } public void mouseMoved(MouseEvent e) { updateThumbState(e.getX(), e.getY()); } } }
Java
/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.*; import javax.swing.text.*; import javax.swing.plaf.*; import java.beans.PropertyChangeEvent; import java.awt.*; /** {@collect.stats} * Provides the look and feel for a styled text editor in the * Synth look and feel. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Shannon Hickey */ class SynthTextPaneUI extends SynthEditorPaneUI { /** {@collect.stats} * Creates a UI for the JTextPane. * * @param c the JTextPane object * @return the UI */ public static ComponentUI createUI(JComponent c) { return new SynthTextPaneUI(); } /** {@collect.stats} * Fetches the name used as a key to lookup properties through the * UIManager. This is used as a prefix to all the standard * text properties. * * @return the name ("TextPane") */ protected String getPropertyPrefix() { return "TextPane"; } public void installUI(JComponent c) { super.installUI(c); updateForeground(c.getForeground()); updateFont(c.getFont()); } /** {@collect.stats} * This method gets called when a bound property is changed * on the associated JTextComponent. This is a hook * which UI implementations may change to reflect how the * UI displays bound properties of JTextComponent subclasses. * If the font, foreground or document has changed, the * the appropriate property is set in the default style of * the document. * * @param evt the property change event */ protected void propertyChange(PropertyChangeEvent evt) { super.propertyChange(evt); String name = evt.getPropertyName(); if (name.equals("foreground")) { updateForeground((Color)evt.getNewValue()); } else if (name.equals("font")) { updateFont((Font)evt.getNewValue()); } else if (name.equals("document")) { JComponent comp = getComponent(); updateForeground(comp.getForeground()); updateFont(comp.getFont()); } } /** {@collect.stats} * Update the color in the default style of the document. * * @param color the new color to use or null to remove the color attribute * from the document's style */ private void updateForeground(Color color) { StyledDocument doc = (StyledDocument)getComponent().getDocument(); Style style = doc.getStyle(StyleContext.DEFAULT_STYLE); if (style == null) { return; } if (color == null) { style.removeAttribute(StyleConstants.Foreground); } else { StyleConstants.setForeground(style, color); } } /** {@collect.stats} * Update the font in the default style of the document. * * @param font the new font to use or null to remove the font attribute * from the document's style */ private void updateFont(Font font) { StyledDocument doc = (StyledDocument)getComponent().getDocument(); Style style = doc.getStyle(StyleContext.DEFAULT_STYLE); if (style == null) { return; } if (font == null) { style.removeAttribute(StyleConstants.FontFamily); style.removeAttribute(StyleConstants.FontSize); style.removeAttribute(StyleConstants.Bold); style.removeAttribute(StyleConstants.Italic); } else { StyleConstants.setFontFamily(style, font.getName()); StyleConstants.setFontSize(style, font.getSize()); StyleConstants.setBold(style, font.isBold()); StyleConstants.setItalic(style, font.isItalic()); } } void paintBackground(SynthContext context, Graphics g, JComponent c) { context.getPainter().paintTextPaneBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintTextPaneBorder(context, g, x, y, w, h); } }
Java
/* * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.*; import javax.swing.text.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.BasicTextAreaUI; import java.awt.*; import java.awt.event.FocusListener; import java.awt.event.FocusEvent; import java.beans.PropertyChangeEvent; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Provides the look and feel for a plain text editor in the * Synth look and feel. In this implementation the default UI * is extended to act as a simple view factory. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Shannon Hickey */ class SynthTextAreaUI extends BasicTextAreaUI implements SynthUI, FocusListener { private SynthStyle style; /** {@collect.stats} * Creates a UI for a JTextArea. * * @param ta a text area * @return the UI */ public static ComponentUI createUI(JComponent ta) { return new SynthTextAreaUI(); } public void focusGained(FocusEvent e) { getComponent().repaint(); } public void focusLost(FocusEvent e) { getComponent().repaint(); } protected void installDefaults() { // Installs the text cursor on the component super.installDefaults(); updateStyle((JTextComponent)getComponent()); getComponent().addFocusListener(this); } protected void uninstallDefaults() { SynthContext context = getContext(getComponent(), ENABLED); getComponent().putClientProperty("caretAspectRatio", null); getComponent().removeFocusListener(this); style.uninstallDefaults(context); context.dispose(); style = null; super.uninstallDefaults(); } public void installUI(JComponent c) { super.installUI(c); } private void updateStyle(JTextComponent comp) { SynthContext context = getContext(comp, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { SynthTextFieldUI.updateStyle(comp, context, getPropertyPrefix()); if (oldStyle != null) { uninstallKeyboardActions(); installKeyboardActions(); } } context.dispose(); } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintTextAreaBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { super.paint(g, getComponent()); } protected void paintBackground(Graphics g) { // Overriden to do nothing, all our painting is done from update/paint. } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintTextAreaBorder(context, g, x, y, w, h); } /** {@collect.stats} * This method gets called when a bound property is changed * on the associated JTextComponent. This is a hook * which UI implementations may change to reflect how the * UI displays bound properties of JTextComponent subclasses. * This is implemented to rebuild the View when the * <em>WrapLine</em> or the <em>WrapStyleWord</em> property changes. * * @param evt the property change event */ protected void propertyChange(PropertyChangeEvent evt) { if (SynthLookAndFeel.shouldUpdateStyle(evt)) { updateStyle((JTextComponent)evt.getSource()); } super.propertyChange(evt); } }
Java
/* * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.beans.*; import javax.swing.*; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Insets; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.SeparatorUI; import javax.swing.plaf.UIResource; import javax.swing.plaf.DimensionUIResource; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * A Synth L&F implementation of SeparatorUI. This implementation * is a "combined" view/controller. * * @author Shannon Hickey * @author Joshua Outwater */ class SynthSeparatorUI extends SeparatorUI implements PropertyChangeListener, SynthUI { private SynthStyle style; public static ComponentUI createUI(JComponent c) { return new SynthSeparatorUI(); } public void installUI(JComponent c) { installDefaults((JSeparator)c); installListeners((JSeparator)c); } public void uninstallDefaults(JComponent c) { uninstallListeners((JSeparator)c); uninstallDefaults((JSeparator)c); } public void installDefaults(JSeparator c) { updateStyle(c); } private void updateStyle(JSeparator sep) { SynthContext context = getContext(sep, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { if (sep instanceof JToolBar.Separator) { Dimension size = ((JToolBar.Separator)sep).getSeparatorSize(); if (size == null || size instanceof UIResource) { size = (DimensionUIResource)style.get( context, "ToolBar.separatorSize"); if (size == null) { size = new DimensionUIResource(10, 10); } ((JToolBar.Separator)sep).setSeparatorSize(size); } } } context.dispose(); } public void uninstallDefaults(JSeparator c) { SynthContext context = getContext(c, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; } public void installListeners(JSeparator c) { c.addPropertyChangeListener(this); } public void uninstallListeners(JSeparator c) { c.removePropertyChangeListener(this); } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); JSeparator separator = (JSeparator)context.getComponent(); SynthLookAndFeel.update(context, g); context.getPainter().paintSeparatorBackground(context, g, 0, 0, c.getWidth(), c.getHeight(), separator.getOrientation()); paint(context, g); context.dispose(); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { JSeparator separator = (JSeparator)context.getComponent(); context.getPainter().paintSeparatorForeground(context, g, 0, 0, separator.getWidth(), separator.getHeight(), separator.getOrientation()); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { JSeparator separator = (JSeparator)context.getComponent(); context.getPainter().paintSeparatorBorder(context, g, x, y, w, h, separator.getOrientation()); } public Dimension getPreferredSize(JComponent c) { SynthContext context = getContext(c); int thickness = style.getInt(context, "Separator.thickness", 2); Insets insets = c.getInsets(); Dimension size; if (((JSeparator)c).getOrientation() == JSeparator.VERTICAL) { size = new Dimension(insets.left + insets.right + thickness, insets.top + insets.bottom); } else { size = new Dimension(insets.left + insets.right, insets.top + insets.bottom + thickness); } context.dispose(); return size; } public Dimension getMinimumSize(JComponent c) { return getPreferredSize(c); } public Dimension getMaximumSize(JComponent c) { return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE); } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } public void propertyChange(PropertyChangeEvent evt) { if (SynthLookAndFeel.shouldUpdateStyle(evt)) { updateStyle((JSeparator)evt.getSource()); } } }
Java
/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import javax.swing.*; import javax.swing.plaf.ComponentUI; /** {@collect.stats} * Provides the look and feel implementation for * <code>JFormattedTextField</code>. * */ class SynthFormattedTextFieldUI extends SynthTextFieldUI { /** {@collect.stats} * Creates a UI for a JFormattedTextField. * * @param c the formatted text field * @return the UI */ public static ComponentUI createUI(JComponent c) { return new SynthFormattedTextFieldUI(); } /** {@collect.stats} * Fetches the name used as a key to lookup properties through the * UIManager. This is used as a prefix to all the standard * text properties. * * @return the name "FormattedTextField" */ protected String getPropertyPrefix() { return "FormattedTextField"; } void paintBackground(SynthContext context, Graphics g, JComponent c) { context.getPainter().paintFormattedTextFieldBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintFormattedTextFieldBorder(context, g, x, y, w, h); } }
Java
/* * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import sun.swing.DefaultLookup; import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * SynthDefaultLookup redirects all lookup calls to the SynthContext. * * @author Scott Violet */ class SynthDefaultLookup extends DefaultLookup { public Object getDefault(JComponent c, ComponentUI ui, String key) { if (!(ui instanceof SynthUI)) { Object value = super.getDefault(c, ui, key); return value; } SynthContext context = ((SynthUI)ui).getContext(c); Object value = context.getStyle().get(context, key); context.dispose(); return value; } }
Java
/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.*; /** {@collect.stats} * Constants used by Synth. Not all Components support all states. A * Component will at least be in one of the primary states. That is, the * return value from <code>SynthContext.getComponentState()</code> will at * least be one of <code>ENABLED</code>, <code>MOUSE_OVER</code>, * <code>PRESSED</code> or <code>DISABLED</code>, and may also contain * <code>FOCUSED</code>, <code>SELECTED</code> or <code>DEFAULT</code>. * * @since 1.5 */ public interface SynthConstants { /** {@collect.stats} * Primary state indicating the component is enabled. */ public static final int ENABLED = 1 << 0; /** {@collect.stats} * Primary state indicating the mouse is over the region. */ public static final int MOUSE_OVER = 1 << 1; /** {@collect.stats} * Primary state indicating the region is in a pressed state. Pressed * does not necessarily mean the user has pressed the mouse button. */ public static final int PRESSED = 1 << 2; /** {@collect.stats} * Primary state indicating the region is not enabled. */ public static final int DISABLED = 1 << 3; /** {@collect.stats} * Indicates the region has focus. */ public static final int FOCUSED = 1 << 8; /** {@collect.stats} * Indicates the region is selected. */ public static final int SELECTED = 1 << 9; /** {@collect.stats} * Indicates the region is the default. This is typically used for buttons * to indicate this button is somehow special. */ public static final int DEFAULT = 1 << 10; }
Java
/* * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Insets; import java.awt.LayoutManager; import java.awt.Rectangle; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.Box; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JSeparator; import javax.swing.JToolBar; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicToolBarUI; import sun.swing.plaf.synth.SynthIcon; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * A Synth L&F implementation of ToolBarUI. This implementation * is a "combined" view/controller. * <p> * */ class SynthToolBarUI extends BasicToolBarUI implements PropertyChangeListener, SynthUI { protected Icon handleIcon = null; protected Rectangle contentRect = new Rectangle(); private SynthStyle style; private SynthStyle contentStyle; private SynthStyle dragWindowStyle; public static ComponentUI createUI(JComponent c) { return new SynthToolBarUI(); } @Override protected void installDefaults() { toolBar.setLayout(createLayout()); updateStyle(toolBar); } @Override protected void installListeners() { super.installListeners(); toolBar.addPropertyChangeListener(this); } @Override protected void uninstallListeners() { super.uninstallListeners(); toolBar.removePropertyChangeListener(this); } private void updateStyle(JToolBar c) { SynthContext context = getContext( c, Region.TOOL_BAR_CONTENT, null, ENABLED); contentStyle = SynthLookAndFeel.updateStyle(context, this); context.dispose(); context = getContext(c, Region.TOOL_BAR_DRAG_WINDOW, null, ENABLED); dragWindowStyle = SynthLookAndFeel.updateStyle(context, this); context.dispose(); context = getContext(c, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (oldStyle != style) { handleIcon = style.getIcon(context, "ToolBar.handleIcon"); if (oldStyle != null) { uninstallKeyboardActions(); installKeyboardActions(); } } context.dispose(); } @Override protected void uninstallDefaults() { SynthContext context = getContext(toolBar, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; handleIcon = null; context = getContext(toolBar, Region.TOOL_BAR_CONTENT, contentStyle, ENABLED); contentStyle.uninstallDefaults(context); context.dispose(); contentStyle = null; context = getContext(toolBar, Region.TOOL_BAR_DRAG_WINDOW, dragWindowStyle, ENABLED); dragWindowStyle.uninstallDefaults(context); context.dispose(); dragWindowStyle = null; toolBar.setLayout(null); } @Override protected void installComponents() {} @Override protected void uninstallComponents() {} protected LayoutManager createLayout() { return new SynthToolBarLayoutManager(); } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private SynthContext getContext(JComponent c, Region region, SynthStyle style) { return SynthContext.getContext(SynthContext.class, c, region, style, getComponentState(c, region)); } private SynthContext getContext(JComponent c, Region region, SynthStyle style, int state) { return SynthContext.getContext(SynthContext.class, c, region, style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } private int getComponentState(JComponent c, Region region) { return SynthLookAndFeel.getComponentState(c); } @Override public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintToolBarBackground(context, g, 0, 0, c.getWidth(), c.getHeight(), toolBar.getOrientation()); paint(context, g); context.dispose(); } @Override public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintToolBarBorder(context, g, x, y, w, h, toolBar.getOrientation()); } // Overloaded to do nothing so we can share listeners. @Override protected void setBorderToNonRollover(Component c) {} // Overloaded to do nothing so we can share listeners. @Override protected void setBorderToRollover(Component c) {} // Overloaded to do nothing so we can share listeners. @Override protected void setBorderToNormal(Component c) {} protected void paint(SynthContext context, Graphics g) { if (handleIcon != null && toolBar.isFloatable()) { int startX = toolBar.getComponentOrientation().isLeftToRight() ? 0 : toolBar.getWidth() - SynthIcon.getIconWidth(handleIcon, context); SynthIcon.paintIcon(handleIcon, context, g, startX, 0, SynthIcon.getIconWidth(handleIcon, context), SynthIcon.getIconHeight(handleIcon, context)); } SynthContext subcontext = getContext( toolBar, Region.TOOL_BAR_CONTENT, contentStyle); paintContent(subcontext, g, contentRect); subcontext.dispose(); } public void paintContent(SynthContext context, Graphics g, Rectangle bounds) { SynthLookAndFeel.updateSubregion(context, g, bounds); context.getPainter().paintToolBarContentBackground(context, g, bounds.x, bounds.y, bounds.width, bounds.height, toolBar.getOrientation()); context.getPainter().paintToolBarContentBorder(context, g, bounds.x, bounds.y, bounds.width, bounds.height, toolBar.getOrientation()); } @Override protected void paintDragWindow(Graphics g) { int w = dragWindow.getWidth(); int h = dragWindow.getHeight(); SynthContext context = getContext( toolBar, Region.TOOL_BAR_DRAG_WINDOW, dragWindowStyle); SynthLookAndFeel.updateSubregion( context, g, new Rectangle(0, 0, w, h)); context.getPainter().paintToolBarDragWindowBackground(context, g, 0, 0, w, h, dragWindow.getOrientation()); context.getPainter().paintToolBarDragWindowBorder(context, g, 0, 0, w, h, dragWindow.getOrientation()); context.dispose(); } // // PropertyChangeListener // public void propertyChange(PropertyChangeEvent e) { if (SynthLookAndFeel.shouldUpdateStyle(e)) { updateStyle((JToolBar)e.getSource()); } } class SynthToolBarLayoutManager implements LayoutManager { public void addLayoutComponent(String name, Component comp) {} public void removeLayoutComponent(Component comp) {} public Dimension minimumLayoutSize(Container parent) { JToolBar tb = (JToolBar)parent; Insets insets = tb.getInsets(); Dimension dim = new Dimension(); SynthContext context = getContext(tb); if (tb.getOrientation() == JToolBar.HORIZONTAL) { dim.width = tb.isFloatable() ? SynthIcon.getIconWidth(handleIcon, context) : 0; Dimension compDim; for (int i = 0; i < tb.getComponentCount(); i++) { compDim = tb.getComponent(i).getMinimumSize(); dim.width += compDim.width; dim.height = Math.max(dim.height, compDim.height); } } else { dim.height = tb.isFloatable() ? SynthIcon.getIconHeight(handleIcon, context) : 0; Dimension compDim; for (int i = 0; i < tb.getComponentCount(); i++) { compDim = tb.getComponent(i).getMinimumSize(); dim.width = Math.max(dim.width, compDim.width); dim.height += compDim.height; } } dim.width += insets.left + insets.right; dim.height += insets.top + insets.bottom; context.dispose(); return dim; } public Dimension preferredLayoutSize(Container parent) { JToolBar tb = (JToolBar)parent; Insets insets = tb.getInsets(); Dimension dim = new Dimension(); SynthContext context = getContext(tb); if (tb.getOrientation() == JToolBar.HORIZONTAL) { dim.width = tb.isFloatable() ? SynthIcon.getIconWidth(handleIcon, context) : 0; Dimension compDim; for (int i = 0; i < tb.getComponentCount(); i++) { compDim = tb.getComponent(i).getPreferredSize(); dim.width += compDim.width; dim.height = Math.max(dim.height, compDim.height); } } else { dim.height = tb.isFloatable() ? SynthIcon.getIconHeight(handleIcon, context) : 0; Dimension compDim; for (int i = 0; i < tb.getComponentCount(); i++) { compDim = tb.getComponent(i).getPreferredSize(); dim.width = Math.max(dim.width, compDim.width); dim.height += compDim.height; } } dim.width += insets.left + insets.right; dim.height += insets.top + insets.bottom; context.dispose(); return dim; } public void layoutContainer(Container parent) { JToolBar tb = (JToolBar)parent; Insets insets = tb.getInsets(); boolean ltr = tb.getComponentOrientation().isLeftToRight(); SynthContext context = getContext(tb); Component c; Dimension d; // JToolBar by default uses a somewhat modified BoxLayout as // its layout manager. For compatibility reasons, we want to // support Box "glue" as a way to move things around on the // toolbar. "glue" is represented in BoxLayout as a Box.Filler // with a minimum and preferred size of (0,0). // So what we do here is find the number of such glue fillers // and figure out how much space should be allocated to them. int glueCount = 0; for (int i=0; i<tb.getComponentCount(); i++) { if (isGlue(tb.getComponent(i))) glueCount++; } if (tb.getOrientation() == JToolBar.HORIZONTAL) { int handleWidth = tb.isFloatable() ? SynthIcon.getIconWidth(handleIcon, context) : 0; // Note: contentRect does not take insets into account // since it is used for determining the bounds that are // passed to paintToolBarContentBackground(). contentRect.x = ltr ? handleWidth : 0; contentRect.y = 0; contentRect.width = tb.getWidth() - handleWidth; contentRect.height = tb.getHeight(); // However, we do take the insets into account here for // the purposes of laying out the toolbar child components. int x = ltr ? handleWidth + insets.left : tb.getWidth() - handleWidth - insets.right; int baseY = insets.top; int baseH = tb.getHeight() - insets.top - insets.bottom; // we need to get the minimum width for laying things out // so that we can calculate how much empty space needs to // be distributed among the "glue", if any int extraSpacePerGlue = 0; if (glueCount > 0) { int minWidth = minimumLayoutSize(parent).width; extraSpacePerGlue = (tb.getWidth() - minWidth) / glueCount; if (extraSpacePerGlue < 0) extraSpacePerGlue = 0; } for (int i = 0; i < tb.getComponentCount(); i++) { c = tb.getComponent(i); d = c.getPreferredSize(); int y, h; if (d.height >= baseH || c instanceof JSeparator) { // Fill available height y = baseY; h = baseH; } else { // Center component vertically in the available space y = baseY + (baseH / 2) - (d.height / 2); h = d.height; } //if the component is a "glue" component then add to its //width the extraSpacePerGlue it is due if (isGlue(c)) d.width += extraSpacePerGlue; c.setBounds(ltr ? x : x - d.width, y, d.width, h); x = ltr ? x + d.width : x - d.width; } } else { int handleHeight = tb.isFloatable() ? SynthIcon.getIconHeight(handleIcon, context) : 0; // See notes above regarding the use of insets contentRect.x = 0; contentRect.y = handleHeight; contentRect.width = tb.getWidth(); contentRect.height = tb.getHeight() - handleHeight; int baseX = insets.left; int baseW = tb.getWidth() - insets.left - insets.right; int y = handleHeight + insets.top; // we need to get the minimum height for laying things out // so that we can calculate how much empty space needs to // be distributed among the "glue", if any int extraSpacePerGlue = 0; if (glueCount > 0) { int minHeight = minimumLayoutSize(parent).height; extraSpacePerGlue = (tb.getHeight() - minHeight) / glueCount; if (extraSpacePerGlue < 0) extraSpacePerGlue = 0; } for (int i = 0; i < tb.getComponentCount(); i++) { c = tb.getComponent(i); d = c.getPreferredSize(); int x, w; if (d.width >= baseW || c instanceof JSeparator) { // Fill available width x = baseX; w = baseW; } else { // Center component horizontally in the available space x = baseX + (baseW / 2) - (d.width / 2); w = d.width; } //if the component is a "glue" component then add to its //height the extraSpacePerGlue it is due if (isGlue(c)) d.height += extraSpacePerGlue; c.setBounds(x, y, w, d.height); y += d.height; } } context.dispose(); } private boolean isGlue(Component c) { if (c instanceof Box.Filler) { Box.Filler f = (Box.Filler)c; Dimension min = f.getMinimumSize(); Dimension pref = f.getPreferredSize(); return min.width == 0 && min.height == 0 && pref.width == 0 && pref.height == 0; } return false; } } }
Java
/* * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import java.beans.*; import javax.swing.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Synth's ScrollBarUI. * * @author Scott Violet */ class SynthScrollBarUI extends BasicScrollBarUI implements PropertyChangeListener, SynthUI { private SynthStyle style; private SynthStyle thumbStyle; private SynthStyle trackStyle; private boolean validMinimumThumbSize; private int scrollBarWidth; //These two variables should be removed when the corrosponding ones in BasicScrollBarUI are made protected private int incrGap; private int decrGap; public static ComponentUI createUI(JComponent c) { return new SynthScrollBarUI(); } protected void installDefaults() { //NOTE: This next line of code was added because, since incrGap and decrGap in //BasicScrollBarUI are private, I need to have some way of updating them. //This is an incomplete solution (since it implies that the incrGap and decrGap //are set once, and not reset per state. Probably ok, but not always ok). //This line of code should be removed at the same time that incrGap and //decrGap are removed and made protected in the super class. super.installDefaults(); trackHighlight = NO_HIGHLIGHT; if (scrollbar.getLayout() == null || (scrollbar.getLayout() instanceof UIResource)) { scrollbar.setLayout(this); } updateStyle(scrollbar); } protected void configureScrollBarColors() { } private void updateStyle(JScrollBar c) { SynthStyle oldStyle = style; SynthContext context = getContext(c, ENABLED); style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { scrollBarWidth = style.getInt(context,"ScrollBar.thumbHeight", 14); minimumThumbSize = (Dimension)style.get(context, "ScrollBar.minimumThumbSize"); if (minimumThumbSize == null) { minimumThumbSize = new Dimension(); validMinimumThumbSize = false; } else { validMinimumThumbSize = true; } maximumThumbSize = (Dimension)style.get(context, "ScrollBar.maximumThumbSize"); if (maximumThumbSize == null) { maximumThumbSize = new Dimension(4096, 4097); } incrGap = style.getInt(context, "ScrollBar.incrementButtonGap", 0); decrGap = style.getInt(context, "ScrollBar.decrementButtonGap", 0); // handle scaling for sizeVarients for special case components. The // key "JComponent.sizeVariant" scales for large/small/mini // components are based on Apples LAF String scaleKey = (String)scrollbar.getClientProperty( "JComponent.sizeVariant"); if (scaleKey != null){ if ("large".equals(scaleKey)){ scrollBarWidth *= 1.15; incrGap *= 1.15; decrGap *= 1.15; } else if ("small".equals(scaleKey)){ scrollBarWidth *= 0.857; incrGap *= 0.857; decrGap *= 0.857; } else if ("mini".equals(scaleKey)){ scrollBarWidth *= 0.714; incrGap *= 0.714; decrGap *= 0.714; } } if (oldStyle != null) { uninstallKeyboardActions(); installKeyboardActions(); } } context.dispose(); context = getContext(c, Region.SCROLL_BAR_TRACK, ENABLED); trackStyle = SynthLookAndFeel.updateStyle(context, this); context.dispose(); context = getContext(c, Region.SCROLL_BAR_THUMB, ENABLED); thumbStyle = SynthLookAndFeel.updateStyle(context, this); context.dispose(); } protected void installListeners() { super.installListeners(); scrollbar.addPropertyChangeListener(this); } protected void uninstallListeners() { super.uninstallListeners(); scrollbar.removePropertyChangeListener(this); } protected void uninstallDefaults(){ SynthContext context = getContext(scrollbar, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; context = getContext(scrollbar, Region.SCROLL_BAR_TRACK, ENABLED); trackStyle.uninstallDefaults(context); context.dispose(); trackStyle = null; context = getContext(scrollbar, Region.SCROLL_BAR_THUMB, ENABLED); thumbStyle.uninstallDefaults(context); context.dispose(); thumbStyle = null; super.uninstallDefaults(); } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } private SynthContext getContext(JComponent c, Region region) { return getContext(c, region, getComponentState(c, region)); } private SynthContext getContext(JComponent c, Region region, int state) { SynthStyle style = trackStyle; if (region == Region.SCROLL_BAR_THUMB) { style = thumbStyle; } return SynthContext.getContext(SynthContext.class, c, region, style, state); } private int getComponentState(JComponent c, Region region) { if (region == Region.SCROLL_BAR_THUMB && isThumbRollover() && c.isEnabled()) { return MOUSE_OVER; } return SynthLookAndFeel.getComponentState(c); } public boolean getSupportsAbsolutePositioning() { SynthContext context = getContext(scrollbar); boolean value = style.getBoolean(context, "ScrollBar.allowsAbsolutePositioning", false); context.dispose(); return value; } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintScrollBarBackground(context, g, 0, 0, c.getWidth(), c.getHeight(), scrollbar.getOrientation()); paint(context, g); context.dispose(); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { SynthContext subcontext = getContext(scrollbar, Region.SCROLL_BAR_TRACK); paintTrack(subcontext, g, getTrackBounds()); subcontext.dispose(); subcontext = getContext(scrollbar, Region.SCROLL_BAR_THUMB); paintThumb(subcontext, g, getThumbBounds()); subcontext.dispose(); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintScrollBarBorder(context, g, x, y, w, h, scrollbar.getOrientation()); } protected void paintTrack(SynthContext ss, Graphics g, Rectangle trackBounds) { SynthLookAndFeel.updateSubregion(ss, g, trackBounds); ss.getPainter().paintScrollBarTrackBackground(ss, g, trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height, scrollbar.getOrientation()); ss.getPainter().paintScrollBarTrackBorder(ss, g, trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height, scrollbar.getOrientation()); } protected void paintThumb(SynthContext ss, Graphics g, Rectangle thumbBounds) { SynthLookAndFeel.updateSubregion(ss, g, thumbBounds); int orientation = scrollbar.getOrientation(); ss.getPainter().paintScrollBarThumbBackground(ss, g, thumbBounds.x, thumbBounds.y, thumbBounds.width, thumbBounds.height, orientation); ss.getPainter().paintScrollBarThumbBorder(ss, g, thumbBounds.x, thumbBounds.y, thumbBounds.width, thumbBounds.height, orientation); } /** {@collect.stats} * A vertical scrollbar's preferred width is the maximum of * preferred widths of the (non <code>null</code>) * increment/decrement buttons, * and the minimum width of the thumb. The preferred height is the * sum of the preferred heights of the same parts. The basis for * the preferred size of a horizontal scrollbar is similar. * <p> * The <code>preferredSize</code> is only computed once, subsequent * calls to this method just return a cached size. * * @param c the <code>JScrollBar</code> that's delegating this method to us * @return the preferred size of a Basic JScrollBar * @see #getMaximumSize * @see #getMinimumSize */ public Dimension getPreferredSize(JComponent c) { Insets insets = c.getInsets(); return (scrollbar.getOrientation() == JScrollBar.VERTICAL) ? new Dimension(scrollBarWidth + insets.left + insets.right, 48) : new Dimension(48, scrollBarWidth + insets.top + insets.bottom); } protected Dimension getMinimumThumbSize() { if (!validMinimumThumbSize) { if (scrollbar.getOrientation() == JScrollBar.VERTICAL) { minimumThumbSize.width = scrollBarWidth; minimumThumbSize.height = 7; } else { minimumThumbSize.width = 7; minimumThumbSize.height = scrollBarWidth; } } return minimumThumbSize; } protected JButton createDecreaseButton(int orientation) { SynthArrowButton synthArrowButton = new SynthArrowButton(orientation) { @Override public boolean contains(int x, int y) { if (decrGap < 0) { //there is an overlap between the track and button int width = getWidth(); int height = getHeight(); if (scrollbar.getOrientation() == JScrollBar.VERTICAL) { //adjust the height by decrGap //Note: decrGap is negative! height += decrGap; } else { //adjust the width by decrGap //Note: decrGap is negative! width += decrGap; } return (x >= 0) && (x < width) && (y >= 0) && (y < height); } return super.contains(x, y); } }; synthArrowButton.setName("ScrollBar.button"); return synthArrowButton; } protected JButton createIncreaseButton(int orientation) { SynthArrowButton synthArrowButton = new SynthArrowButton(orientation) { @Override public boolean contains(int x, int y) { if (incrGap < 0) { //there is an overlap between the track and button int width = getWidth(); int height = getHeight(); if (scrollbar.getOrientation() == JScrollBar.VERTICAL) { //adjust the height and y by incrGap //Note: incrGap is negative! height += incrGap; y += incrGap; } else { //adjust the width and x by incrGap //Note: incrGap is negative! width += incrGap; x += incrGap; } return (x >= 0) && (x < width) && (y >= 0) && (y < height); } return super.contains(x, y); } }; synthArrowButton.setName("ScrollBar.button"); return synthArrowButton; } protected void setThumbRollover(boolean active) { if (isThumbRollover() != active) { scrollbar.repaint(getThumbBounds()); super.setThumbRollover(active); } } private void updateButtonDirections() { int orient = scrollbar.getOrientation(); if (scrollbar.getComponentOrientation().isLeftToRight()) { ((SynthArrowButton)incrButton).setDirection( orient == HORIZONTAL? EAST : SOUTH); ((SynthArrowButton)decrButton).setDirection( orient == HORIZONTAL? WEST : NORTH); } else { ((SynthArrowButton)incrButton).setDirection( orient == HORIZONTAL? WEST : SOUTH); ((SynthArrowButton)decrButton).setDirection( orient == HORIZONTAL ? EAST : NORTH); } } // // PropertyChangeListener // public void propertyChange(PropertyChangeEvent e) { String propertyName = e.getPropertyName(); if (SynthLookAndFeel.shouldUpdateStyle(e)) { updateStyle((JScrollBar)e.getSource()); } if ("orientation" == propertyName) { updateButtonDirections(); } else if ("componentOrientation" == propertyName) { updateButtonDirections(); } } }
Java
/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.plaf.*; import javax.swing.border.*; import java.io.Serializable; /** {@collect.stats} * Synth's CheckBoxMenuItemUI. * * @author Leif Samuelsson * @author Georges Saab * @author David Karlton * @author Arnaud Weber */ class SynthCheckBoxMenuItemUI extends SynthMenuItemUI { public static ComponentUI createUI(JComponent c) { return new SynthCheckBoxMenuItemUI(); } protected String getPropertyPrefix() { return "CheckBoxMenuItem"; } public void processMouseEvent(JMenuItem item, MouseEvent e, MenuElement path[], MenuSelectionManager manager) { Point p = e.getPoint(); if (p.x >= 0 && p.x < item.getWidth() && p.y >= 0 && p.y < item.getHeight()) { if (e.getID() == MouseEvent.MOUSE_RELEASED) { manager.clearSelectedPath(); item.doClick(0); } else { manager.setSelectedPath(path); } } else if (item.getModel().isArmed()) { int c = path.length - 1; MenuElement newPath[] = new MenuElement[c]; for (int i = 0; i < c; i++) { newPath[i] = path[i]; } manager.setSelectedPath(newPath); } } void paintBackground(SynthContext context, Graphics g, JComponent c) { context.getPainter().paintCheckBoxMenuItemBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintCheckBoxMenuItemBorder(context, g, x, y, w, h); } }
Java
/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.*; import java.util.*; /** {@collect.stats} * An immutable transient object containing contextual information about * a <code>Region</code>. A <code>SynthContext</code> should only be * considered valid for the duration * of the method it is passed to. In other words you should not cache * a <code>SynthContext</code> that is passed to you and expect it to * remain valid. * * @since 1.5 * @author Scott Violet */ public class SynthContext { private static final Map contextMap; private JComponent component; private Region region; private SynthStyle style; private int state; static { contextMap = new HashMap(); } static SynthContext getContext(Class type, JComponent component, Region region, SynthStyle style, int state) { SynthContext context = null; synchronized(contextMap) { java.util.List instances = (java.util.List)contextMap.get(type); if (instances != null) { int size = instances.size(); if (size > 0) { context = (SynthContext)instances.remove(size - 1); } } } if (context == null) { try { context = (SynthContext)type.newInstance(); } catch (IllegalAccessException iae) { } catch (InstantiationException ie) { } } context.reset(component, region, style, state); return context; } static void releaseContext(SynthContext context) { synchronized(contextMap) { java.util.List instances = (java.util.List)contextMap.get( context.getClass()); if (instances == null) { instances = new ArrayList(5); contextMap.put(context.getClass(), instances); } instances.add(context); } } SynthContext() { } /** {@collect.stats} * Creates a SynthContext with the specified values. This is meant * for subclasses and custom UI implementors. You very rarely need to * construct a SynthContext, though some methods will take one. * * @param component JComponent * @param region Identifies the portion of the JComponent * @param style Style associated with the component * @param state State of the component as defined in SynthConstants. * @throws NullPointerException if component, region of style is null. */ public SynthContext(JComponent component, Region region, SynthStyle style, int state) { if (component == null || region == null || style == null) { throw new NullPointerException( "You must supply a non-null component, region and style"); } reset(component, region, style, state); } /** {@collect.stats} * Returns the hosting component containing the region. * * @return Hosting Component */ public JComponent getComponent() { return component; } /** {@collect.stats} * Returns the Region identifying this state. * * @return Region of the hosting component */ public Region getRegion() { return region; } /** {@collect.stats} * A convenience method for <code>getRegion().isSubregion()</code>. */ boolean isSubregion() { return getRegion().isSubregion(); } void setStyle(SynthStyle style) { this.style = style; } /** {@collect.stats} * Returns the style associated with this Region. * * @return SynthStyle associated with the region. */ public SynthStyle getStyle() { return style; } void setComponentState(int state) { this.state = state; } /** {@collect.stats} * Returns the state of the widget, which is a bitmask of the * values defined in <code>SynthConstants</code>. A region will at least * be in one of * <code>ENABLED</code>, <code>MOUSE_OVER</code>, <code>PRESSED</code> * or <code>DISABLED</code>. * * @see SynthConstants * @return State of Component */ public int getComponentState() { return state; } /** {@collect.stats} * Resets the state of the Context. */ void reset(JComponent component, Region region, SynthStyle style, int state) { this.component = component; this.region = region; this.style = style; this.state = state; } void dispose() { this.component = null; this.style = null; releaseContext(this); } /** {@collect.stats} * Convenience method to get the Painter from the current SynthStyle. * This will NEVER return null. */ SynthPainter getPainter() { SynthPainter painter = getStyle().getPainter(this); if (painter != null) { return painter; } return SynthPainter.NULL_PAINTER; } }
Java
/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.*; import javax.swing.border.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.BasicDesktopPaneUI; import java.beans.*; import java.awt.event.*; import java.awt.Dimension; import java.awt.Insets; import java.awt.Graphics; import java.awt.KeyboardFocusManager; import java.awt.*; import java.util.Vector; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Synth L&F for a desktop. * * @author Joshua Outwater * @author Steve Wilson */ class SynthDesktopPaneUI extends BasicDesktopPaneUI implements PropertyChangeListener, SynthUI { private SynthStyle style; private TaskBar taskBar; private DesktopManager oldDesktopManager; public static ComponentUI createUI(JComponent c) { return new SynthDesktopPaneUI(); } protected void installListeners() { super.installListeners(); desktop.addPropertyChangeListener(this); if (taskBar != null) { // Listen for desktop being resized desktop.addComponentListener(taskBar); // Listen for frames being added to desktop desktop.addContainerListener(taskBar); } } protected void installDefaults() { updateStyle(desktop); if (UIManager.getBoolean("InternalFrame.useTaskBar")) { taskBar = new TaskBar(); for (Component comp : desktop.getComponents()) { JInternalFrame.JDesktopIcon desktopIcon; if (comp instanceof JInternalFrame.JDesktopIcon) { desktopIcon = (JInternalFrame.JDesktopIcon)comp; } else if (comp instanceof JInternalFrame) { desktopIcon = ((JInternalFrame)comp).getDesktopIcon(); } else { continue; } // Move desktopIcon from desktop to taskBar if (desktopIcon.getParent() == desktop) { desktop.remove(desktopIcon); } if (desktopIcon.getParent() != taskBar) { taskBar.add(desktopIcon); desktopIcon.getInternalFrame().addComponentListener( taskBar); } } taskBar.setBackground(desktop.getBackground()); desktop.add(taskBar, new Integer(JLayeredPane.PALETTE_LAYER.intValue() + 1)); if (desktop.isShowing()) { taskBar.adjustSize(); } } } private void updateStyle(JDesktopPane c) { SynthStyle oldStyle = style; SynthContext context = getContext(c, ENABLED); style = SynthLookAndFeel.updateStyle(context, this); if (oldStyle != null) { uninstallKeyboardActions(); installKeyboardActions(); } context.dispose(); } protected void uninstallListeners() { if (taskBar != null) { desktop.removeComponentListener(taskBar); desktop.removeContainerListener(taskBar); } desktop.removePropertyChangeListener(this); super.uninstallListeners(); } protected void uninstallDefaults() { SynthContext context = getContext(desktop, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; if (taskBar != null) { for (Component comp : taskBar.getComponents()) { JInternalFrame.JDesktopIcon desktopIcon = (JInternalFrame.JDesktopIcon)comp; taskBar.remove(desktopIcon); desktopIcon.setPreferredSize(null); JInternalFrame f = desktopIcon.getInternalFrame(); if (f.isIcon()) { desktop.add(desktopIcon); } f.removeComponentListener(taskBar); } desktop.remove(taskBar); taskBar = null; } } protected void installDesktopManager() { if (UIManager.getBoolean("InternalFrame.useTaskBar")) { desktopManager = oldDesktopManager = desktop.getDesktopManager(); if (!(desktopManager instanceof SynthDesktopManager)) { desktopManager = new SynthDesktopManager(); desktop.setDesktopManager(desktopManager); } } else { super.installDesktopManager(); } } protected void uninstallDesktopManager() { if (oldDesktopManager != null && !(oldDesktopManager instanceof UIResource)) { desktopManager = desktop.getDesktopManager(); if (desktopManager == null || desktopManager instanceof UIResource) { desktop.setDesktopManager(oldDesktopManager); } } oldDesktopManager = null; super.uninstallDesktopManager(); } static class TaskBar extends JPanel implements ComponentListener, ContainerListener { TaskBar() { setOpaque(true); setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0) { public void layoutContainer(Container target) { // First shrink buttons to fit Component[] comps = target.getComponents(); int n = comps.length; if (n > 0) { // Start with the largest preferred width int prefWidth = 0; for (Component c : comps) { c.setPreferredSize(null); Dimension prefSize = c.getPreferredSize(); if (prefSize.width > prefWidth) { prefWidth = prefSize.width; } } // Shrink equally to fit if needed Insets insets = target.getInsets(); int tw = target.getWidth() - insets.left - insets.right; int w = Math.min(prefWidth, Math.max(10, tw/n)); for (Component c : comps) { Dimension prefSize = c.getPreferredSize(); c.setPreferredSize(new Dimension(w, prefSize.height)); } } super.layoutContainer(target); } }); // PENDING: This should be handled by the painter setBorder(new BevelBorder(BevelBorder.RAISED) { protected void paintRaisedBevel(Component c, Graphics g, int x, int y, int w, int h) { Color oldColor = g.getColor(); g.translate(x, y); g.setColor(getHighlightOuterColor(c)); g.drawLine(0, 0, 0, h-2); g.drawLine(1, 0, w-2, 0); g.setColor(getShadowOuterColor(c)); g.drawLine(0, h-1, w-1, h-1); g.drawLine(w-1, 0, w-1, h-2); g.translate(-x, -y); g.setColor(oldColor); } }); } void adjustSize() { JDesktopPane desktop = (JDesktopPane)getParent(); if (desktop != null) { int height = getPreferredSize().height; Insets insets = getInsets(); if (height == insets.top + insets.bottom) { if (getHeight() <= height) { // Initial size, because we have no buttons yet height += 21; } else { // We already have a good height height = getHeight(); } } setBounds(0, desktop.getHeight() - height, desktop.getWidth(), height); revalidate(); repaint(); } } // ComponentListener interface public void componentResized(ComponentEvent e) { if (e.getSource() instanceof JDesktopPane) { adjustSize(); } } public void componentMoved(ComponentEvent e){} public void componentShown(ComponentEvent e) { if (e.getSource() instanceof JInternalFrame) { adjustSize(); } } public void componentHidden(ComponentEvent e) { if (e.getSource() instanceof JInternalFrame) { ((JInternalFrame)e.getSource()).getDesktopIcon().setVisible(false); revalidate(); } } // ContainerListener interface public void componentAdded(ContainerEvent e) { if (e.getChild() instanceof JInternalFrame) { JDesktopPane desktop = (JDesktopPane)e.getSource(); JInternalFrame f = (JInternalFrame)e.getChild(); JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon(); for (Component comp : getComponents()) { if (comp == desktopIcon) { // We have it already return; } } add(desktopIcon); f.addComponentListener(this); if (getComponentCount() == 1) { adjustSize(); } } } public void componentRemoved(ContainerEvent e) { if (e.getChild() instanceof JInternalFrame) { JInternalFrame f = (JInternalFrame)e.getChild(); if (!f.isIcon()) { // Frame was removed without using setClosed(true) remove(f.getDesktopIcon()); f.removeComponentListener(this); revalidate(); repaint(); } } } } class SynthDesktopManager extends DefaultDesktopManager implements UIResource { public void maximizeFrame(JInternalFrame f) { if (f.isIcon()) { try { f.setIcon(false); } catch (PropertyVetoException e2) { } } else { f.setNormalBounds(f.getBounds()); Component desktop = f.getParent(); setBoundsForFrame(f, 0, 0, desktop.getWidth(), desktop.getHeight() - taskBar.getHeight()); } try { f.setSelected(true); } catch (PropertyVetoException e2) { } } public void iconifyFrame(JInternalFrame f) { JInternalFrame.JDesktopIcon desktopIcon; Container c = f.getParent(); JDesktopPane d = f.getDesktopPane(); boolean findNext = f.isSelected(); if (c == null) { return; } desktopIcon = f.getDesktopIcon(); if (!f.isMaximum()) { f.setNormalBounds(f.getBounds()); } c.remove(f); c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight()); try { f.setSelected(false); } catch (PropertyVetoException e2) { } // Get topmost of the remaining frames if (findNext) { for (Component comp : c.getComponents()) { if (comp instanceof JInternalFrame) { try { ((JInternalFrame)comp).setSelected(true); } catch (PropertyVetoException e2) { } ((JInternalFrame)comp).moveToFront(); return; } } } } public void deiconifyFrame(JInternalFrame f) { JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon(); Container c = desktopIcon.getParent(); if (c != null) { c = c.getParent(); if (c != null) { c.add(f); if (f.isMaximum()) { int w = c.getWidth(); int h = c.getHeight() - taskBar.getHeight(); if (f.getWidth() != w || f.getHeight() != h) { setBoundsForFrame(f, 0, 0, w, h); } } if (f.isSelected()) { f.moveToFront(); } else { try { f.setSelected(true); } catch (PropertyVetoException e2) { } } } } } protected void removeIconFor(JInternalFrame f) { super.removeIconFor(f); taskBar.validate(); } public void setBoundsForFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) { super.setBoundsForFrame(f, newX, newY, newWidth, newHeight); if (taskBar != null && newY >= taskBar.getY()) { f.setLocation(f.getX(), taskBar.getY()-f.getInsets().top); } } } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintDesktopPaneBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintDesktopPaneBorder(context, g, x, y, w, h); } public void propertyChange(PropertyChangeEvent evt) { if (SynthLookAndFeel.shouldUpdateStyle(evt)) { updateStyle((JDesktopPane)evt.getSource()); } if (evt.getPropertyName() == "ancestor" && taskBar != null) { taskBar.adjustSize(); } } }
Java
/* * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import javax.swing.text.Position; import java.awt.*; import java.awt.event.*; import java.awt.datatransfer.Transferable; import java.awt.dnd.*; import java.util.ArrayList; import java.util.TooManyListenersException; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Synth's ListUI. * * @author Scott Violet */ class SynthListUI extends BasicListUI implements PropertyChangeListener, SynthUI { private SynthStyle style; private boolean useListColors; private boolean useUIBorder; public static ComponentUI createUI(JComponent list) { return new SynthListUI(); } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintListBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); context.dispose(); paint(g, c); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintListBorder(context, g, x, y, w, h); } protected void installListeners() { super.installListeners(); list.addPropertyChangeListener(this); } public void propertyChange(PropertyChangeEvent e) { if (SynthLookAndFeel.shouldUpdateStyle(e)) { updateStyle((JList)e.getSource()); } } protected void uninstallListeners() { super.uninstallListeners(); list.removePropertyChangeListener(this); } protected void installDefaults() { if (list.getCellRenderer() == null || (list.getCellRenderer() instanceof UIResource)) { list.setCellRenderer(new SynthListCellRenderer()); } updateStyle(list); } private void updateStyle(JComponent c) { SynthContext context = getContext(list, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { context.setComponentState(SELECTED); Color sbg = list.getSelectionBackground(); if (sbg == null || sbg instanceof UIResource) { list.setSelectionBackground(style.getColor( context, ColorType.TEXT_BACKGROUND)); } Color sfg = list.getSelectionForeground(); if (sfg == null || sfg instanceof UIResource) { list.setSelectionForeground(style.getColor( context, ColorType.TEXT_FOREGROUND)); } useListColors = style.getBoolean(context, "List.rendererUseListColors", true); useUIBorder = style.getBoolean(context, "List.rendererUseUIBorder", true); int height = style.getInt(context, "List.cellHeight", -1); if (height != -1) { list.setFixedCellHeight(height); } if (oldStyle != null) { uninstallKeyboardActions(); installKeyboardActions(); } } context.dispose(); } protected void uninstallDefaults() { super.uninstallDefaults(); SynthContext context = getContext(list, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } private class SynthListCellRenderer extends DefaultListCellRenderer.UIResource { public String getName() { return "List.cellRenderer"; } public void setBorder(Border b) { if (useUIBorder || b instanceof SynthBorder) { super.setBorder(b); } } public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (!useListColors && (isSelected || cellHasFocus)) { SynthLookAndFeel.setSelectedUI((SynthLabelUI)SynthLookAndFeel. getUIOfType(getUI(), SynthLabelUI.class), isSelected, cellHasFocus, list.isEnabled(), false); } else { SynthLookAndFeel.resetSelectedUI(); } super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); return this; } public void paint(Graphics g) { super.paint(g); SynthLookAndFeel.resetSelectedUI(); } } }
Java
/* * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.Color; import java.awt.Component; import java.awt.Graphics; import java.awt.Insets; import java.awt.Rectangle; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.Enumeration; import javax.swing.DefaultCellEditor; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JTextField; import javax.swing.JTree; import javax.swing.LookAndFeel; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicTreeUI; import javax.swing.tree.DefaultTreeCellEditor; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.TreeCellEditor; import javax.swing.tree.TreeCellRenderer; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; import sun.swing.plaf.synth.SynthIcon; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Skinnable TreeUI. * * @author Scott Violet */ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener, SynthUI { private SynthStyle style; private SynthStyle cellStyle; private SynthContext paintContext; private boolean drawHorizontalLines; private boolean drawVerticalLines; private Object linesStyle; private int leadRow; private int padding; private boolean useTreeColors; private Icon expandedIconWrapper; public static ComponentUI createUI(JComponent x) { return new SynthTreeUI(); } SynthTreeUI() { expandedIconWrapper = new ExpandedIconWrapper(); } @Override public Icon getExpandedIcon() { return expandedIconWrapper; } @Override protected void installDefaults() { updateStyle(tree); } private void updateStyle(JTree tree) { SynthContext context = getContext(tree, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { Object value; setExpandedIcon(style.getIcon(context, "Tree.expandedIcon")); setCollapsedIcon(style.getIcon(context, "Tree.collapsedIcon")); setLeftChildIndent(style.getInt(context, "Tree.leftChildIndent", 0)); setRightChildIndent(style.getInt(context, "Tree.rightChildIndent", 0)); drawHorizontalLines = style.getBoolean( context, "Tree.drawHorizontalLines",true); drawVerticalLines = style.getBoolean( context, "Tree.drawVerticalLines", true); linesStyle = style.get(context, "Tree.linesStyle"); value = style.get(context, "Tree.rowHeight"); if (value != null) { LookAndFeel.installProperty(tree, "rowHeight", value); } value = style.get(context, "Tree.scrollsOnExpand"); LookAndFeel.installProperty(tree, "scrollsOnExpand", value != null? value : Boolean.TRUE); padding = style.getInt(context, "Tree.padding", 0); largeModel = (tree.isLargeModel() && tree.getRowHeight() > 0); useTreeColors = style.getBoolean(context, "Tree.rendererUseTreeColors", true); Boolean showsRootHandles = style.getBoolean( context, "Tree.showsRootHandles", Boolean.TRUE); LookAndFeel.installProperty( tree, JTree.SHOWS_ROOT_HANDLES_PROPERTY, showsRootHandles); if (oldStyle != null) { uninstallKeyboardActions(); installKeyboardActions(); } } context.dispose(); context = getContext(tree, Region.TREE_CELL, ENABLED); cellStyle = SynthLookAndFeel.updateStyle(context, this); context.dispose(); } @Override protected void installListeners() { super.installListeners(); tree.addPropertyChangeListener(this); } @Override public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JTree c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } private SynthContext getContext(JComponent c, Region region) { return getContext(c, region, getComponentState(c, region)); } private SynthContext getContext(JComponent c, Region region, int state) { return SynthContext.getContext(SynthContext.class, c, region, cellStyle, state); } private int getComponentState(JComponent c, Region region) { // Always treat the cell as selected, will be adjusted appropriately // when painted. return ENABLED | SELECTED; } @Override protected TreeCellEditor createDefaultCellEditor() { TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellEditor editor; if(renderer != null && (renderer instanceof DefaultTreeCellRenderer)) { editor = new SynthTreeCellEditor(tree, (DefaultTreeCellRenderer) renderer); } else { editor = new SynthTreeCellEditor(tree, null); } return editor; } @Override protected TreeCellRenderer createDefaultCellRenderer() { return new SynthTreeCellRenderer(); } @Override protected void uninstallDefaults() { SynthContext context = getContext(tree, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; context = getContext(tree, Region.TREE_CELL, ENABLED); cellStyle.uninstallDefaults(context); context.dispose(); cellStyle = null; if (tree.getTransferHandler() instanceof UIResource) { tree.setTransferHandler(null); } } @Override protected void uninstallListeners() { super.uninstallListeners(); tree.removePropertyChangeListener(this); } @Override public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintTreeBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintTreeBorder(context, g, x, y, w, h); } @Override public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } private void updateLeadRow() { leadRow = getRowForPath(tree, tree.getLeadSelectionPath()); } protected void paint(SynthContext context, Graphics g) { paintContext = context; updateLeadRow(); Rectangle paintBounds = g.getClipBounds(); Insets insets = tree.getInsets(); TreePath initialPath = getClosestPathForLocation(tree, 0, paintBounds.y); Enumeration paintingEnumerator = treeState.getVisiblePathsFrom (initialPath); int row = treeState.getRowForPath(initialPath); int endY = paintBounds.y + paintBounds.height; TreeModel treeModel = tree.getModel(); SynthContext cellContext = getContext(tree, Region.TREE_CELL); drawingCache.clear(); setHashColor(context.getStyle().getColor(context, ColorType.FOREGROUND)); if (paintingEnumerator != null) { // First pass, draw the rows boolean done = false; boolean isExpanded; boolean hasBeenExpanded; boolean isLeaf; Rectangle boundsBuffer = new Rectangle(); Rectangle rowBounds = new Rectangle(0, 0, tree.getWidth(),0); Rectangle bounds; TreePath path; TreeCellRenderer renderer = tree.getCellRenderer(); DefaultTreeCellRenderer dtcr = (renderer instanceof DefaultTreeCellRenderer) ? (DefaultTreeCellRenderer) renderer : null; configureRenderer(cellContext); while (!done && paintingEnumerator.hasMoreElements()) { path = (TreePath)paintingEnumerator.nextElement(); if (path != null) { isLeaf = treeModel.isLeaf(path.getLastPathComponent()); if (isLeaf) { isExpanded = hasBeenExpanded = false; } else { isExpanded = treeState.getExpandedState(path); hasBeenExpanded = tree.hasBeenExpanded(path); } bounds = getPathBounds(tree, path); rowBounds.y = bounds.y; rowBounds.height = bounds.height; paintRow(renderer, dtcr, context, cellContext, g, paintBounds, insets, bounds, rowBounds, path, row, isExpanded, hasBeenExpanded, isLeaf); if ((bounds.y + bounds.height) >= endY) { done = true; } } else { done = true; } row++; } // Draw the connecting lines and controls. // Find each parent and have them draw a line to their last child boolean rootVisible = tree.isRootVisible(); TreePath parentPath = initialPath; parentPath = parentPath.getParentPath(); while (parentPath != null) { paintVerticalPartOfLeg(g, paintBounds, insets, parentPath); drawingCache.put(parentPath, Boolean.TRUE); parentPath = parentPath.getParentPath(); } done = false; paintingEnumerator = treeState.getVisiblePathsFrom(initialPath); while (!done && paintingEnumerator.hasMoreElements()) { path = (TreePath)paintingEnumerator.nextElement(); if (path != null) { isLeaf = treeModel.isLeaf(path.getLastPathComponent()); if (isLeaf) { isExpanded = hasBeenExpanded = false; } else { isExpanded = treeState.getExpandedState(path); hasBeenExpanded = tree.hasBeenExpanded(path); } bounds = getPathBounds(tree, path); // See if the vertical line to the parent has been drawn. parentPath = path.getParentPath(); if (parentPath != null) { if (drawingCache.get(parentPath) == null) { paintVerticalPartOfLeg(g, paintBounds, insets, parentPath); drawingCache.put(parentPath, Boolean.TRUE); } paintHorizontalPartOfLeg(g, paintBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf); } else if (rootVisible && row == 0) { paintHorizontalPartOfLeg(g, paintBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf); } if (shouldPaintExpandControl(path, row, isExpanded, hasBeenExpanded, isLeaf)) { paintExpandControl(g, paintBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded,isLeaf); } if ((bounds.y + bounds.height) >= endY) { done = true; } } else { done = true; } row++; } } cellContext.dispose(); paintDropLine(g); // Empty out the renderer pane, allowing renderers to be gc'ed. rendererPane.removeAll(); } private boolean isDropLine(JTree.DropLocation loc) { return loc != null && loc.getPath() != null && loc.getChildIndex() != -1; } private void paintDropLine(Graphics g) { JTree.DropLocation loc = tree.getDropLocation(); if (!isDropLine(loc)) { return; } Color c = (Color)style.get(paintContext, "Tree.dropLineColor"); if (c != null) { g.setColor(c); Rectangle rect = getDropLineRect(loc); g.fillRect(rect.x, rect.y, rect.width, rect.height); } } private Rectangle getDropLineRect(JTree.DropLocation loc) { Rectangle rect = null; TreePath path = loc.getPath(); int index = loc.getChildIndex(); boolean ltr = tree.getComponentOrientation().isLeftToRight(); Insets insets = tree.getInsets(); if (tree.getRowCount() == 0) { rect = new Rectangle(insets.left, insets.top, tree.getWidth() - insets.left - insets.right, 0); } else { int row = tree.getRowForPath(path); TreeModel model = getModel(); Object root = model.getRoot(); if (path.getLastPathComponent() == root && index >= model.getChildCount(root)) { rect = tree.getRowBounds(tree.getRowCount() - 1); rect.y = rect.y + rect.height; Rectangle xRect; if (!tree.isRootVisible()) { xRect = tree.getRowBounds(0); } else if (model.getChildCount(root) == 0){ xRect = tree.getRowBounds(0); xRect.x += totalChildIndent; xRect.width -= totalChildIndent + totalChildIndent; } else { TreePath lastChildPath = path.pathByAddingChild( model.getChild(root, model.getChildCount(root) - 1)); xRect = tree.getPathBounds(lastChildPath); } rect.x = xRect.x; rect.width = xRect.width; } else { rect = tree.getPathBounds(path.pathByAddingChild( model.getChild(path.getLastPathComponent(), index))); } } if (rect.y != 0) { rect.y--; } if (!ltr) { rect.x = rect.x + rect.width - 100; } rect.width = 100; rect.height = 2; return rect; } private void configureRenderer(SynthContext context) { TreeCellRenderer renderer = tree.getCellRenderer(); if (renderer instanceof DefaultTreeCellRenderer) { DefaultTreeCellRenderer r = (DefaultTreeCellRenderer)renderer; SynthStyle style = context.getStyle(); context.setComponentState(ENABLED | SELECTED); Color color = r.getTextSelectionColor(); if (color == null || (color instanceof UIResource)) { r.setTextSelectionColor(style.getColor( context, ColorType.TEXT_FOREGROUND)); } color = r.getBackgroundSelectionColor(); if (color == null || (color instanceof UIResource)) { r.setBackgroundSelectionColor(style.getColor( context, ColorType.TEXT_BACKGROUND)); } context.setComponentState(ENABLED); color = r.getTextNonSelectionColor(); if (color == null || color instanceof UIResource) { r.setTextNonSelectionColor(style.getColorForState( context, ColorType.TEXT_FOREGROUND)); } color = r.getBackgroundNonSelectionColor(); if (color == null || color instanceof UIResource) { r.setBackgroundNonSelectionColor(style.getColorForState( context, ColorType.TEXT_BACKGROUND)); } } } @Override protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) { if (drawHorizontalLines) { super.paintHorizontalPartOfLeg(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf); } } @Override protected void paintHorizontalLine(Graphics g, JComponent c, int y, int left, int right) { paintContext.getStyle().getGraphicsUtils(paintContext).drawLine( paintContext, "Tree.horizontalLine", g, left, y, right, y, linesStyle); } @Override protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, TreePath path) { if (drawVerticalLines) { super.paintVerticalPartOfLeg(g, clipBounds, insets, path); } } @Override protected void paintVerticalLine(Graphics g, JComponent c, int x, int top, int bottom) { paintContext.getStyle().getGraphicsUtils(paintContext).drawLine( paintContext, "Tree.verticalLine", g, x, top, x, bottom, linesStyle); } protected void paintRow(TreeCellRenderer renderer, DefaultTreeCellRenderer dtcr, SynthContext treeContext, SynthContext cellContext, Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, Rectangle rowBounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) { // Don't paint the renderer if editing this row. boolean selected = tree.isRowSelected(row); JTree.DropLocation dropLocation = (JTree.DropLocation)tree.getDropLocation(); boolean isDrop = dropLocation != null && dropLocation.getChildIndex() == -1 && path == dropLocation.getPath(); int state = ENABLED; if (selected || isDrop) { state |= SELECTED; } if (tree.isFocusOwner() && row == leadRow) { state |= FOCUSED; } cellContext.setComponentState(state); if (dtcr != null && (dtcr.getBorderSelectionColor() instanceof UIResource)) { dtcr.setBorderSelectionColor(style.getColor( cellContext, ColorType.FOCUS)); } SynthLookAndFeel.updateSubregion(cellContext, g, rowBounds); cellContext.getPainter().paintTreeCellBackground(cellContext, g, rowBounds.x, rowBounds.y, rowBounds.width, rowBounds.height); cellContext.getPainter().paintTreeCellBorder(cellContext, g, rowBounds.x, rowBounds.y, rowBounds.width, rowBounds.height); if (editingComponent != null && editingRow == row) { return; } int leadIndex; if (tree.hasFocus()) { leadIndex = leadRow; } else { leadIndex = -1; } Component component = renderer.getTreeCellRendererComponent( tree, path.getLastPathComponent(), selected, isExpanded, isLeaf, row, (leadIndex == row)); rendererPane.paintComponent(g, component, tree, bounds.x, bounds.y, bounds.width, bounds.height, true); } private int findCenteredX(int x, int iconWidth) { return tree.getComponentOrientation().isLeftToRight() ? x - (int)Math.ceil(iconWidth / 2.0) : x - (int)Math.floor(iconWidth / 2.0); } /** {@collect.stats} * @inheritDoc */ @Override protected void paintExpandControl(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) { //modify the paintContext's state to match the state for the row //this is a hack in that it requires knowledge of the subsequent //method calls. The point is, the context used in drawCentered //should reflect the state of the row, not of the tree. boolean isSelected = tree.getSelectionModel().isPathSelected(path); int state = paintContext.getComponentState(); if (isSelected) { paintContext.setComponentState(state | SynthConstants.SELECTED); } super.paintExpandControl(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf); paintContext.setComponentState(state); } @Override protected void drawCentered(Component c, Graphics graphics, Icon icon, int x, int y) { int w = SynthIcon.getIconWidth(icon, paintContext); int h = SynthIcon.getIconHeight(icon, paintContext); SynthIcon.paintIcon(icon, paintContext, graphics, findCenteredX(x, w), y - h/2, w, h); } public void propertyChange(PropertyChangeEvent event) { if (SynthLookAndFeel.shouldUpdateStyle(event)) { updateStyle((JTree)event.getSource()); } if ("dropLocation" == event.getPropertyName()) { JTree.DropLocation oldValue = (JTree.DropLocation)event.getOldValue(); repaintDropLocation(oldValue); repaintDropLocation(tree.getDropLocation()); } } private void repaintDropLocation(JTree.DropLocation loc) { if (loc == null) { return; } Rectangle r; if (isDropLine(loc)) { r = getDropLineRect(loc); } else { r = tree.getPathBounds(loc.getPath()); if (r != null) { r.x = 0; r.width = tree.getWidth(); } } if (r != null) { tree.repaint(r); } } @Override protected int getRowX(int row, int depth) { return super.getRowX(row, depth) + padding; } private class SynthTreeCellRenderer extends DefaultTreeCellRenderer implements UIResource { SynthTreeCellRenderer() { } @Override public String getName() { return "Tree.cellRenderer"; } @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (!useTreeColors && (sel || hasFocus)) { SynthLookAndFeel.setSelectedUI((SynthLabelUI)SynthLookAndFeel. getUIOfType(getUI(), SynthLabelUI.class), sel, hasFocus, tree.isEnabled(), false); } else { SynthLookAndFeel.resetSelectedUI(); } return super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); } @Override public void paint(Graphics g) { paintComponent(g); if (hasFocus) { SynthContext context = getContext(tree, Region.TREE_CELL); if (context.getStyle() == null) { assert false: "SynthTreeCellRenderer is being used " + "outside of UI that created it"; return; } int imageOffset = 0; Icon currentI = getIcon(); if(currentI != null && getText() != null) { imageOffset = currentI.getIconWidth() + Math.max(0, getIconTextGap() - 1); } if (selected) { context.setComponentState(ENABLED | SELECTED); } else { context.setComponentState(ENABLED); } if(getComponentOrientation().isLeftToRight()) { context.getPainter().paintTreeCellFocus(context, g, imageOffset, 0, getWidth() - imageOffset, getHeight()); } else { context.getPainter().paintTreeCellFocus(context, g, 0, 0, getWidth() - imageOffset, getHeight()); } context.dispose(); } SynthLookAndFeel.resetSelectedUI(); } } private static class SynthTreeCellEditor extends DefaultTreeCellEditor { public SynthTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer) { super(tree, renderer); setBorderSelectionColor(null); } @Override protected TreeCellEditor createTreeCellEditor() { JTextField tf = new JTextField() { @Override public String getName() { return "Tree.cellEditor"; } }; DefaultCellEditor editor = new DefaultCellEditor(tf); // One click to edit. editor.setClickCountToStart(1); return editor; } } // // BasicTreeUI directly uses expandIcon outside of the Synth methods. // To get the correct context we return an instance of this that fetches // the SynthContext as needed. // private class ExpandedIconWrapper extends SynthIcon { public void paintIcon(SynthContext context, Graphics g, int x, int y, int w, int h) { if (context == null) { context = getContext(tree); SynthIcon.paintIcon(expandedIcon, context, g, x, y, w, h); context.dispose(); } else { SynthIcon.paintIcon(expandedIcon, context, g, x, y, w, h); } } public int getIconWidth(SynthContext context) { int width; if (context == null) { context = getContext(tree); width = SynthIcon.getIconWidth(expandedIcon, context); context.dispose(); } else { width = SynthIcon.getIconWidth(expandedIcon, context); } return width; } public int getIconHeight(SynthContext context) { int height; if (context == null) { context = getContext(tree); height = SynthIcon.getIconHeight(expandedIcon, context); context.dispose(); } else { height = SynthIcon.getIconHeight(expandedIcon, context); } return height; } } }
Java
/* * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import javax.swing.*; import javax.swing.text.JTextComponent; import javax.swing.border.*; import javax.swing.plaf.UIResource; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * SynthBorder is a border that delegates to a Painter. The Insets * are determined at construction time. * * @author Scott Violet */ class SynthBorder extends AbstractBorder implements UIResource { private SynthUI ui; private Insets insets; SynthBorder(SynthUI ui, Insets insets) { this.ui = ui; this.insets = insets; } SynthBorder(SynthUI ui) { this(ui, null); } public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { JComponent jc = (JComponent)c; SynthContext context = ui.getContext(jc); SynthStyle style = context.getStyle(); if (style == null) { assert false: "SynthBorder is being used outside after the UI " + "has been uninstalled"; return; } ui.paintBorder(context, g, x, y, width, height); context.dispose(); } /** {@collect.stats} * This default implementation returns a new <code>Insets</code> * instance where the <code>top</code>, <code>left</code>, * <code>bottom</code>, and * <code>right</code> fields are set to <code>0</code>. * @param c the component for which this border insets value applies * @return the new <code>Insets</code> object initialized to 0 */ public Insets getBorderInsets(Component c) { return getBorderInsets(c, null); } /** {@collect.stats} * Reinitializes the insets parameter with this Border's current Insets. * @param c the component for which this border insets value applies * @param insets the object to be reinitialized * @return the <code>insets</code> object */ public Insets getBorderInsets(Component c, Insets insets) { if (this.insets != null) { if (insets == null) { insets = new Insets(this.insets.top, this.insets.left, this.insets.bottom, this.insets.right); } else { insets.top = this.insets.top; insets.bottom = this.insets.bottom; insets.left = this.insets.left; insets.right = this.insets.right; } } else if (insets == null) { insets = new Insets(0, 0, 0, 0); } else { insets.top = insets.bottom = insets.left = insets.right = 0; } if (c instanceof JComponent) { Region region = Region.getRegion((JComponent)c); Insets margin = null; if ((region == Region.ARROW_BUTTON || region == Region.BUTTON || region == Region.CHECK_BOX || region == Region.CHECK_BOX_MENU_ITEM || region == Region.MENU || region == Region.MENU_ITEM || region == Region.RADIO_BUTTON || region == Region.RADIO_BUTTON_MENU_ITEM || region == Region.TOGGLE_BUTTON) && (c instanceof AbstractButton)) { margin = ((AbstractButton)c).getMargin(); } else if ((region == Region.EDITOR_PANE || region == Region.FORMATTED_TEXT_FIELD || region == Region.PASSWORD_FIELD || region == Region.TEXT_AREA || region == Region.TEXT_FIELD || region == Region.TEXT_PANE) && (c instanceof JTextComponent)) { margin = ((JTextComponent)c).getMargin(); } else if (region == Region.TOOL_BAR && (c instanceof JToolBar)) { margin = ((JToolBar)c).getMargin(); } else if (region == Region.MENU_BAR && (c instanceof JMenuBar)) { margin = ((JMenuBar)c).getMargin(); } if (margin != null) { insets.top += margin.top; insets.bottom += margin.bottom; insets.left += margin.left; insets.right += margin.right; } } return insets; } /** {@collect.stats} * This default implementation returns false. * @return false */ public boolean isBorderOpaque() { return false; } }
Java
/* * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.*; import javax.swing.event.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import javax.swing.border.*; import java.applet.Applet; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Graphics; import java.awt.KeyboardFocusManager; import java.awt.Window; import java.awt.event.*; import java.awt.AWTEvent; import java.awt.Toolkit; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import java.util.*; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Synth's PopupMenuUI. * * @author Georges Saab * @author David Karlton * @author Arnaud Weber */ class SynthPopupMenuUI extends BasicPopupMenuUI implements PropertyChangeListener, SynthUI { private SynthStyle style; public static ComponentUI createUI(JComponent x) { return new SynthPopupMenuUI(); } public void installDefaults() { if (popupMenu.getLayout() == null || popupMenu.getLayout() instanceof UIResource) { popupMenu.setLayout(new DefaultMenuLayout( popupMenu, BoxLayout.Y_AXIS)); } updateStyle(popupMenu); } private void updateStyle(JComponent c) { SynthContext context = getContext(c, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { if (oldStyle != null) { uninstallKeyboardActions(); installKeyboardActions(); } } context.dispose(); } protected void installListeners() { super.installListeners(); popupMenu.addPropertyChangeListener(this); } protected void uninstallDefaults() { SynthContext context = getContext(popupMenu, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; if (popupMenu.getLayout() instanceof UIResource) { popupMenu.setLayout(null); } } protected void uninstallListeners() { super.uninstallListeners(); popupMenu.removePropertyChangeListener(this); } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintPopupMenuBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintPopupMenuBorder(context, g, x, y, w, h); } public void propertyChange(PropertyChangeEvent e) { if (SynthLookAndFeel.shouldUpdateStyle(e)) { updateStyle(popupMenu); } } }
Java
/* * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import java.awt.*; import java.awt.event.*; import java.beans.*; import java.util.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Synth's SplitPaneUI. * * @author Scott Violet */ class SynthSplitPaneUI extends BasicSplitPaneUI implements PropertyChangeListener, SynthUI { /** {@collect.stats} * Keys to use for forward focus traversal when the JComponent is * managing focus. */ private static Set managingFocusForwardTraversalKeys; /** {@collect.stats} * Keys to use for backward focus traversal when the JComponent is * managing focus. */ private static Set managingFocusBackwardTraversalKeys; /** {@collect.stats} * Style for the JSplitPane. */ private SynthStyle style; /** {@collect.stats} * Style for the divider. */ private SynthStyle dividerStyle; /** {@collect.stats} * Creates a new SynthSplitPaneUI instance */ public static ComponentUI createUI(JComponent x) { return new SynthSplitPaneUI(); } /** {@collect.stats} * Installs the UI defaults. */ protected void installDefaults() { updateStyle(splitPane); setOrientation(splitPane.getOrientation()); setContinuousLayout(splitPane.isContinuousLayout()); resetLayoutManager(); /* Install the nonContinuousLayoutDivider here to avoid having to add/remove everything later. */ if(nonContinuousLayoutDivider == null) { setNonContinuousLayoutDivider( createDefaultNonContinuousLayoutDivider(), true); } else { setNonContinuousLayoutDivider(nonContinuousLayoutDivider, true); } // focus forward traversal key if (managingFocusForwardTraversalKeys==null) { managingFocusForwardTraversalKeys = new HashSet(); managingFocusForwardTraversalKeys.add( KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)); } splitPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, managingFocusForwardTraversalKeys); // focus backward traversal key if (managingFocusBackwardTraversalKeys==null) { managingFocusBackwardTraversalKeys = new HashSet(); managingFocusBackwardTraversalKeys.add( KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK)); } splitPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, managingFocusBackwardTraversalKeys); } private void updateStyle(JSplitPane splitPane) { SynthContext context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER, ENABLED); SynthStyle oldDividerStyle = dividerStyle; dividerStyle = SynthLookAndFeel.updateStyle(context, this); context.dispose(); context = getContext(splitPane, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { Object value = style.get(context, "SplitPane.size"); if (value == null) { value = new Integer(6); } LookAndFeel.installProperty(splitPane, "dividerSize", value); value = style.get(context, "SplitPane.oneTouchExpandable"); if (value != null) { LookAndFeel.installProperty(splitPane, "oneTouchExpandable", value); } if (divider != null) { splitPane.remove(divider); divider.setDividerSize(splitPane.getDividerSize()); } if (oldStyle != null) { uninstallKeyboardActions(); installKeyboardActions(); } } if (style != oldStyle || dividerStyle != oldDividerStyle) { // Only way to force BasicSplitPaneDivider to reread the // necessary properties. if (divider != null) { splitPane.remove(divider); } divider = createDefaultDivider(); divider.setBasicSplitPaneUI(this); splitPane.add(divider, JSplitPane.DIVIDER); } context.dispose(); } /** {@collect.stats} * Installs the event listeners for the UI. */ protected void installListeners() { super.installListeners(); splitPane.addPropertyChangeListener(this); } /** {@collect.stats} * Uninstalls the UI defaults. */ protected void uninstallDefaults() { SynthContext context = getContext(splitPane, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER, ENABLED); dividerStyle.uninstallDefaults(context); context.dispose(); dividerStyle = null; super.uninstallDefaults(); } /** {@collect.stats} * Uninstalls the event listeners for the UI. */ protected void uninstallListeners() { super.uninstallListeners(); splitPane.removePropertyChangeListener(this); } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } SynthContext getContext(JComponent c, Region region) { return getContext(c, region, getComponentState(c, region)); } private SynthContext getContext(JComponent c, Region region, int state) { if (region == Region.SPLIT_PANE_DIVIDER) { return SynthContext.getContext(SynthContext.class, c, region, dividerStyle, state); } return SynthContext.getContext(SynthContext.class, c, region, style, state); } private int getComponentState(JComponent c, Region subregion) { int state = SynthLookAndFeel.getComponentState(c); if (divider.isMouseOver()) { state |= MOUSE_OVER; } return state; } public void propertyChange(PropertyChangeEvent e) { if (SynthLookAndFeel.shouldUpdateStyle(e)) { updateStyle((JSplitPane)e.getSource()); } } /** {@collect.stats} * Creates the default divider. */ public BasicSplitPaneDivider createDefaultDivider() { SynthSplitPaneDivider divider = new SynthSplitPaneDivider(this); divider.setDividerSize(splitPane.getDividerSize()); return divider; } protected Component createDefaultNonContinuousLayoutDivider() { return new Canvas() { public void paint(Graphics g) { paintDragDivider(g, 0, 0, getWidth(), getHeight()); } }; } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintSplitPaneBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { // This is done to update package private variables in // BasicSplitPaneUI super.paint(g, splitPane); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintSplitPaneBorder(context, g, x, y, w, h); } private void paintDragDivider(Graphics g, int x, int y, int w, int h) { SynthContext context = getContext(splitPane,Region.SPLIT_PANE_DIVIDER); context.setComponentState(((context.getComponentState() | MOUSE_OVER) ^ MOUSE_OVER) | PRESSED); Shape oldClip = g.getClip(); g.clipRect(x, y, w, h); context.getPainter().paintSplitPaneDragDivider(context, g, x, y, w, h, splitPane.getOrientation()); g.setClip(oldClip); context.dispose(); } public void finishedPaintingChildren(JSplitPane jc, Graphics g) { if(jc == splitPane && getLastDragLocation() != -1 && !isContinuousLayout() && !draggingHW) { if(jc.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) { paintDragDivider(g, getLastDragLocation(), 0, dividerSize - 1, splitPane.getHeight() - 1); } else { paintDragDivider(g, 0, getLastDragLocation(), splitPane.getWidth() - 1, dividerSize - 1); } } } }
Java
/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.*; import javax.swing.text.JTextComponent; import javax.swing.border.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import java.awt.*; import java.awt.event.ContainerListener; import java.awt.event.ContainerEvent; import java.awt.event.FocusListener; import java.awt.event.FocusEvent; import sun.swing.plaf.synth.SynthUI; /** {@collect.stats} * Synth's ScrollPaneUI. * * @author Scott Violet */ class SynthScrollPaneUI extends BasicScrollPaneUI implements PropertyChangeListener, SynthUI { private SynthStyle style; private boolean viewportViewHasFocus = false; private ViewportViewFocusHandler viewportViewFocusHandler; public static ComponentUI createUI(JComponent x) { return new SynthScrollPaneUI(); } @Override public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintScrollPaneBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } @Override public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { Border vpBorder = scrollpane.getViewportBorder(); if (vpBorder != null) { Rectangle r = scrollpane.getViewportBorderBounds(); vpBorder.paintBorder(scrollpane, g, r.x, r.y, r.width, r.height); } } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintScrollPaneBorder(context, g, x, y, w, h); } @Override protected void installDefaults(JScrollPane scrollpane) { updateStyle(scrollpane); } private void updateStyle(JScrollPane c) { SynthContext context = getContext(c, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); if (style != oldStyle) { Border vpBorder = scrollpane.getViewportBorder(); if ((vpBorder == null) ||( vpBorder instanceof UIResource)) { scrollpane.setViewportBorder(new ViewportBorder(context)); } if (oldStyle != null) { uninstallKeyboardActions(c); installKeyboardActions(c); } } context.dispose(); } @Override protected void installListeners(JScrollPane c) { super.installListeners(c); c.addPropertyChangeListener(this); if (UIManager.getBoolean("ScrollPane.useChildTextComponentFocus")){ viewportViewFocusHandler = new ViewportViewFocusHandler(); c.getViewport().addContainerListener(viewportViewFocusHandler); Component view = c.getViewport().getView(); if (view instanceof JTextComponent) { view.addFocusListener(viewportViewFocusHandler); } } } @Override protected void uninstallDefaults(JScrollPane c) { SynthContext context = getContext(c, ENABLED); style.uninstallDefaults(context); context.dispose(); if (scrollpane.getViewportBorder() instanceof UIResource) { scrollpane.setViewportBorder(null); } } @Override protected void uninstallListeners(JComponent c) { super.uninstallListeners(c); c.removePropertyChangeListener(this); if (viewportViewFocusHandler != null) { JViewport viewport = ((JScrollPane) c).getViewport(); viewport.removeContainerListener(viewportViewFocusHandler); if (viewport.getView()!= null) { viewport.getView().removeFocusListener(viewportViewFocusHandler); } viewportViewFocusHandler = null; } } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } private SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c), style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { int baseState = SynthLookAndFeel.getComponentState(c); if (viewportViewFocusHandler!=null && viewportViewHasFocus){ baseState = baseState | FOCUSED; } return baseState; } public void propertyChange(PropertyChangeEvent e) { if (SynthLookAndFeel.shouldUpdateStyle(e)) { updateStyle(scrollpane); } } private class ViewportBorder extends AbstractBorder implements UIResource { private Insets insets; ViewportBorder(SynthContext context) { this.insets = (Insets)context.getStyle().get(context, "ScrollPane.viewportBorderInsets"); if (this.insets == null) { this.insets = SynthLookAndFeel.EMPTY_UIRESOURCE_INSETS; } } @Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { JComponent jc = (JComponent)c; SynthContext context = getContext(jc); SynthStyle style = context.getStyle(); if (style == null) { assert false: "SynthBorder is being used outside after the " + " UI has been uninstalled"; return; } context.getPainter().paintViewportBorder(context, g, x, y, width, height); context.dispose(); } public Insets getBorderInsets(Component c) { return getBorderInsets(c, null); } @Override public Insets getBorderInsets(Component c, Insets insets) { if (insets == null) { return new Insets(this.insets.top, this.insets.left, this.insets.bottom, this.insets.right); } insets.top = this.insets.top; insets.bottom = this.insets.bottom; insets.left = this.insets.left; insets.right = this.insets.left; return insets; } @Override public boolean isBorderOpaque() { return false; } } /** {@collect.stats} * Handle keeping track of the viewport's view's focus */ private class ViewportViewFocusHandler implements ContainerListener, FocusListener{ public void componentAdded(ContainerEvent e) { if (e.getChild() instanceof JTextComponent) { e.getChild().addFocusListener(this); viewportViewHasFocus = e.getChild().isFocusOwner(); scrollpane.repaint(); } } public void componentRemoved(ContainerEvent e) { if (e.getChild() instanceof JTextComponent) { e.getChild().removeFocusListener(this); } } public void focusGained(FocusEvent e) { viewportViewHasFocus = true; scrollpane.repaint(); } public void focusLost(FocusEvent e) { viewportViewHasFocus = false; scrollpane.repaint(); } } }
Java
/* * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.synth; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.plaf.*; import javax.swing.border.*; /** {@collect.stats} * Synth's RadioButtonMenuItemUI. * * @author Georges Saab * @author David Karlton */ class SynthRadioButtonMenuItemUI extends SynthMenuItemUI { public static ComponentUI createUI(JComponent b) { return new SynthRadioButtonMenuItemUI(); } protected String getPropertyPrefix() { return "RadioButtonMenuItem"; } public void processMouseEvent(JMenuItem item,MouseEvent e,MenuElement path[],MenuSelectionManager manager) { Point p = e.getPoint(); if(p.x >= 0 && p.x < item.getWidth() && p.y >= 0 && p.y < item.getHeight()) { if(e.getID() == MouseEvent.MOUSE_RELEASED) { manager.clearSelectedPath(); item.doClick(0); item.setArmed(false); } else manager.setSelectedPath(path); } else if(item.getModel().isArmed()) { MenuElement newPath[] = new MenuElement[path.length-1]; int i,c; for(i=0,c=path.length-1;i<c;i++) newPath[i] = path[i]; manager.setSelectedPath(newPath); } } void paintBackground(SynthContext context, Graphics g, JComponent c) { context.getPainter().paintRadioButtonMenuItemBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintRadioButtonMenuItemBorder(context, g, x, y, w, h); } }
Java
/* * Copyright (c) 1997, 1998, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; /** {@collect.stats} * Pluggable look and feel interface for JSlider. * * @author Hans Muller */ public abstract class SliderUI extends ComponentUI { }
Java
/* * Copyright (c) 1997, 1998, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; import javax.swing.*; import java.awt.event.*; /** {@collect.stats} * Pluggable look and feel interface for JMenuItem. * * @author Georges Saab * @author David Karlton * @author Arnaud Weber */ public abstract class MenuItemUI extends ButtonUI { }
Java
/* * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; import javax.swing.Action; import javax.swing.BoundedRangeModel; import java.awt.Point; import java.awt.Rectangle; import java.awt.Insets; import javax.swing.text.*; /** {@collect.stats} * Text editor user interface * * @author Timothy Prinzing */ public abstract class TextUI extends ComponentUI { /** {@collect.stats} * Converts the given location in the model to a place in * the view coordinate system. * * @param pos the local location in the model to translate >= 0 * @return the coordinates as a rectangle * @exception BadLocationException if the given position does not * represent a valid location in the associated document */ public abstract Rectangle modelToView(JTextComponent t, int pos) throws BadLocationException; /** {@collect.stats} * Converts the given location in the model to a place in * the view coordinate system. * * @param pos the local location in the model to translate >= 0 * @return the coordinates as a rectangle * @exception BadLocationException if the given position does not * represent a valid location in the associated document */ public abstract Rectangle modelToView(JTextComponent t, int pos, Position.Bias bias) throws BadLocationException; /** {@collect.stats} * Converts the given place in the view coordinate system * to the nearest representative location in the model. * * @param pt the location in the view to translate. This * should be in the same coordinate system as the mouse * events. * @return the offset from the start of the document >= 0 */ public abstract int viewToModel(JTextComponent t, Point pt); /** {@collect.stats} * Provides a mapping from the view coordinate space to the logical * coordinate space of the model. * * @param pt the location in the view to translate. * This should be in the same coordinate system * as the mouse events. * @param biasReturn * filled in by this method to indicate whether * the point given is closer to the previous or the next * character in the model * * @return the location within the model that best represents the * given point in the view >= 0 */ public abstract int viewToModel(JTextComponent t, Point pt, Position.Bias[] biasReturn); /** {@collect.stats} * Provides a way to determine the next visually represented model * location that one might place a caret. Some views may not be visible, * they might not be in the same order found in the model, or they just * might not allow access to some of the locations in the model. * * @param t the text component for which this UI is installed * @param pos the position to convert >= 0 * @param b the bias for the position * @param direction the direction from the current position that can * be thought of as the arrow keys typically found on a keyboard. * This may be SwingConstants.WEST, SwingConstants.EAST, * SwingConstants.NORTH, or SwingConstants.SOUTH * @param biasRet an array to contain the bias for the returned position * @return the location within the model that best represents the next * location visual position * @exception BadLocationException * @exception IllegalArgumentException for an invalid direction */ public abstract int getNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet) throws BadLocationException; /** {@collect.stats} * Causes the portion of the view responsible for the * given part of the model to be repainted. * * @param p0 the beginning of the range >= 0 * @param p1 the end of the range >= p0 */ public abstract void damageRange(JTextComponent t, int p0, int p1); /** {@collect.stats} * Causes the portion of the view responsible for the * given part of the model to be repainted. * * @param p0 the beginning of the range >= 0 * @param p1 the end of the range >= p0 */ public abstract void damageRange(JTextComponent t, int p0, int p1, Position.Bias firstBias, Position.Bias secondBias); /** {@collect.stats} * Fetches the binding of services that set a policy * for the type of document being edited. This contains * things like the commands available, stream readers and * writers, etc. * * @return the editor kit binding */ public abstract EditorKit getEditorKit(JTextComponent t); /** {@collect.stats} * Fetches a View with the allocation of the associated * text component (i.e. the root of the hierarchy) that * can be traversed to determine how the model is being * represented spatially. * * @return the view */ public abstract View getRootView(JTextComponent t); /** {@collect.stats} * Returns the string to be used as the tooltip at the passed in location. * * @see javax.swing.text.JTextComponent#getToolTipText * @since 1.4 */ public String getToolTipText(JTextComponent t, Point pt) { return null; } }
Java
/* * Copyright (c) 1997, 1998, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; import java.awt.Insets; import javax.swing.JMenuBar; import javax.swing.JMenu; /** {@collect.stats} * Pluggable look and feel interface for JMenuBar. * * @author Georges Saab * @author David Karlton */ public abstract class MenuBarUI extends ComponentUI { }
Java
/* * Copyright (c) 1997, 1998, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; /** {@collect.stats} * Pluggable look and feel interface for JDesktopIcon. * * @author David Kloba */ public abstract class DesktopIconUI extends ComponentUI { }
Java
/* * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; import java.awt.Color; /* * A subclass of Color that implements UIResource. UI * classes that create colors should use this class. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @see javax.swing.plaf.UIResource * @author Hans Muller * */ public class ColorUIResource extends Color implements UIResource { public ColorUIResource(int r, int g, int b) { super(r, g, b); } public ColorUIResource(int rgb) { super(rgb); } public ColorUIResource(float r, float g, float b) { super(r, g, b); } public ColorUIResource(Color c) { super(c.getRGB(), (c.getRGB() & 0xFF000000) != 0xFF000000); } }
Java
/* * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; /** {@collect.stats} * Pluggable look and feel interface for JViewport. * * @author Rich Schiavi */ public abstract class ViewportUI extends ComponentUI { }
Java
/* * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; /** {@collect.stats} * Pluggable look and feel interface for JRootPane. * * @author Scott Violet * @since 1.3 */ public abstract class RootPaneUI extends ComponentUI { }
Java
/* * Copyright (c) 1997, 1998, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; import javax.swing.JSplitPane; import java.awt.Graphics; /** {@collect.stats} * Pluggable look and feel interface for JSplitPane. * * @author Scott Violet */ public abstract class SplitPaneUI extends ComponentUI { /** {@collect.stats} * Messaged to relayout the JSplitPane based on the preferred size * of the children components. */ public abstract void resetToPreferredSizes(JSplitPane jc); /** {@collect.stats} * Sets the location of the divider to location. */ public abstract void setDividerLocation(JSplitPane jc, int location); /** {@collect.stats} * Returns the location of the divider. */ public abstract int getDividerLocation(JSplitPane jc); /** {@collect.stats} * Returns the minimum possible location of the divider. */ public abstract int getMinimumDividerLocation(JSplitPane jc); /** {@collect.stats} * Returns the maximum possible location of the divider. */ public abstract int getMaximumDividerLocation(JSplitPane jc); /** {@collect.stats} * Messaged after the JSplitPane the receiver is providing the look * and feel for paints its children. */ public abstract void finishedPaintingChildren(JSplitPane jc, Graphics g); }
Java
/* * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; /** {@collect.stats} * Pluggable look and feel interface for Panel. * * @author Steve Wilson */ public abstract class PanelUI extends ComponentUI { }
Java
/* * Copyright (c) 1997, 1998, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; import java.awt.Insets; import javax.swing.JToolBar; /** {@collect.stats} * Pluggable look and feel interface for JToolBar. * * @author Georges Saab */ public abstract class ToolBarUI extends ComponentUI { }
Java
/* * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; import javax.swing.AbstractButton; import javax.swing.GrayFilter; import javax.swing.Icon; import javax.swing.ImageIcon; import java.awt.Insets; /** {@collect.stats} * Pluggable look and feel interface for JButton. * * @author Jeff Dinkins */ public abstract class ButtonUI extends ComponentUI { }
Java
/* * Copyright (c) 1997, 1998, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; /** {@collect.stats} * Pluggable look and feel interface for JLabel. * * @author Hans Muller */ public abstract class LabelUI extends ComponentUI { }
Java
/* * Copyright (c) 1997, 1998, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; /** {@collect.stats} * Pluggable look and feel interface for JTableHeader. * * @author Alan Chung */ public abstract class TableHeaderUI extends ComponentUI { }
Java
/* * Copyright (c) 1997, 2000, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; import javax.swing.JComboBox; /** {@collect.stats} * Pluggable look and feel interface for JComboBox. * * @author Arnaud Weber * @author Tom Santos */ public abstract class ComboBoxUI extends ComponentUI { /** {@collect.stats} * Set the visiblity of the popup */ public abstract void setPopupVisible( JComboBox c, boolean v ); /** {@collect.stats} * Determine the visibility of the popup */ public abstract boolean isPopupVisible( JComboBox c ); /** {@collect.stats} * Determine whether or not the combo box itself is traversable */ public abstract boolean isFocusTraversable( JComboBox c ); }
Java
/* * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; import javax.swing.JComponent; import javax.swing.SwingUtilities; import javax.accessibility.Accessible; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Insets; /** {@collect.stats} * The base class for all UI delegate objects in the Swing pluggable * look and feel architecture. The UI delegate object for a Swing * component is responsible for implementing the aspects of the * component that depend on the look and feel. * The <code>JComponent</code> class * invokes methods from this class in order to delegate operations * (painting, layout calculations, etc.) that may vary depending on the * look and feel installed. <b>Client programs should not invoke methods * on this class directly.</b> * * @see javax.swing.JComponent * @see javax.swing.UIManager * */ public abstract class ComponentUI { /** {@collect.stats} * Sole constructor. (For invocation by subclass constructors, * typically implicit.) */ public ComponentUI() { } /** {@collect.stats} * Configures the specified component appropriate for the look and feel. * This method is invoked when the <code>ComponentUI</code> instance is being installed * as the UI delegate on the specified component. This method should * completely configure the component for the look and feel, * including the following: * <ol> * <li>Install any default property values for color, fonts, borders, * icons, opacity, etc. on the component. Whenever possible, * property values initialized by the client program should <i>not</i> * be overridden. * <li>Install a <code>LayoutManager</code> on the component if necessary. * <li>Create/add any required sub-components to the component. * <li>Create/install event listeners on the component. * <li>Create/install a <code>PropertyChangeListener</code> on the component in order * to detect and respond to component property changes appropriately. * <li>Install keyboard UI (mnemonics, traversal, etc.) on the component. * <li>Initialize any appropriate instance data. * </ol> * @param c the component where this UI delegate is being installed * * @see #uninstallUI * @see javax.swing.JComponent#setUI * @see javax.swing.JComponent#updateUI */ public void installUI(JComponent c) { } /** {@collect.stats} * Reverses configuration which was done on the specified component during * <code>installUI</code>. This method is invoked when this * <code>UIComponent</code> instance is being removed as the UI delegate * for the specified component. This method should undo the * configuration performed in <code>installUI</code>, being careful to * leave the <code>JComponent</code> instance in a clean state (no * extraneous listeners, look-and-feel-specific property objects, etc.). * This should include the following: * <ol> * <li>Remove any UI-set borders from the component. * <li>Remove any UI-set layout managers on the component. * <li>Remove any UI-added sub-components from the component. * <li>Remove any UI-added event/property listeners from the component. * <li>Remove any UI-installed keyboard UI from the component. * <li>Nullify any allocated instance data objects to allow for GC. * </ol> * @param c the component from which this UI delegate is being removed; * this argument is often ignored, * but might be used if the UI object is stateless * and shared by multiple components * * @see #installUI * @see javax.swing.JComponent#updateUI */ public void uninstallUI(JComponent c) { } /** {@collect.stats} * Paints the specified component appropriate for the look and feel. * This method is invoked from the <code>ComponentUI.update</code> method when * the specified component is being painted. Subclasses should override * this method and use the specified <code>Graphics</code> object to * render the content of the component. * * @param g the <code>Graphics</code> context in which to paint * @param c the component being painted; * this argument is often ignored, * but might be used if the UI object is stateless * and shared by multiple components * * @see #update */ public void paint(Graphics g, JComponent c) { } /** {@collect.stats} * Notifies this UI delegate that it's time to paint the specified * component. This method is invoked by <code>JComponent</code> * when the specified component is being painted. * By default this method will fill the specified component with * its background color (if its <code>opaque</code> property is * <code>true</code>) and then immediately call <code>paint</code>. * In general this method need not be overridden by subclasses; * all look-and-feel rendering code should reside in the <code>paint</code> * method. * * @param g the <code>Graphics</code> context in which to paint * @param c the component being painted; * this argument is often ignored, * but might be used if the UI object is stateless * and shared by multiple components * * @see #paint * @see javax.swing.JComponent#paintComponent */ public void update(Graphics g, JComponent c) { if (c.isOpaque()) { g.setColor(c.getBackground()); g.fillRect(0, 0, c.getWidth(),c.getHeight()); } paint(g, c); } /** {@collect.stats} * Returns the specified component's preferred size appropriate for * the look and feel. If <code>null</code> is returned, the preferred * size will be calculated by the component's layout manager instead * (this is the preferred approach for any component with a specific * layout manager installed). The default implementation of this * method returns <code>null</code>. * * @param c the component whose preferred size is being queried; * this argument is often ignored, * but might be used if the UI object is stateless * and shared by multiple components * * @see javax.swing.JComponent#getPreferredSize * @see java.awt.LayoutManager#preferredLayoutSize */ public Dimension getPreferredSize(JComponent c) { return null; } /** {@collect.stats} * Returns the specified component's minimum size appropriate for * the look and feel. If <code>null</code> is returned, the minimum * size will be calculated by the component's layout manager instead * (this is the preferred approach for any component with a specific * layout manager installed). The default implementation of this * method invokes <code>getPreferredSize</code> and returns that value. * * @param c the component whose minimum size is being queried; * this argument is often ignored, * but might be used if the UI object is stateless * and shared by multiple components * * @return a <code>Dimension</code> object or <code>null</code> * * @see javax.swing.JComponent#getMinimumSize * @see java.awt.LayoutManager#minimumLayoutSize * @see #getPreferredSize */ public Dimension getMinimumSize(JComponent c) { return getPreferredSize(c); } /** {@collect.stats} * Returns the specified component's maximum size appropriate for * the look and feel. If <code>null</code> is returned, the maximum * size will be calculated by the component's layout manager instead * (this is the preferred approach for any component with a specific * layout manager installed). The default implementation of this * method invokes <code>getPreferredSize</code> and returns that value. * * @param c the component whose maximum size is being queried; * this argument is often ignored, * but might be used if the UI object is stateless * and shared by multiple components * @return a <code>Dimension</code> object or <code>null</code> * * @see javax.swing.JComponent#getMaximumSize * @see java.awt.LayoutManager2#maximumLayoutSize */ public Dimension getMaximumSize(JComponent c) { return getPreferredSize(c); } /** {@collect.stats} * Returns <code>true</code> if the specified <i>x,y</i> location is * contained within the look and feel's defined shape of the specified * component. <code>x</code> and <code>y</code> are defined to be relative * to the coordinate system of the specified component. Although * a component's <code>bounds</code> is constrained to a rectangle, * this method provides the means for defining a non-rectangular * shape within those bounds for the purpose of hit detection. * * @param c the component where the <i>x,y</i> location is being queried; * this argument is often ignored, * but might be used if the UI object is stateless * and shared by multiple components * @param x the <i>x</i> coordinate of the point * @param y the <i>y</i> coordinate of the point * * @see javax.swing.JComponent#contains * @see java.awt.Component#contains */ public boolean contains(JComponent c, int x, int y) { return c.inside(x, y); } /** {@collect.stats} * Returns an instance of the UI delegate for the specified component. * Each subclass must provide its own static <code>createUI</code> * method that returns an instance of that UI delegate subclass. * If the UI delegate subclass is stateless, it may return an instance * that is shared by multiple components. If the UI delegate is * stateful, then it should return a new instance per component. * The default implementation of this method throws an error, as it * should never be invoked. */ public static ComponentUI createUI(JComponent c) { throw new Error("ComponentUI.createUI not implemented."); } /** {@collect.stats} * Returns the baseline. The baseline is measured from the top of * the component. This method is primarily meant for * <code>LayoutManager</code>s to align components along their * baseline. A return value less than 0 indicates this component * does not have a reasonable baseline and that * <code>LayoutManager</code>s should not align this component on * its baseline. * <p> * This method returns -1. Subclasses that have a meaningful baseline * should override appropriately. * * @param c <code>JComponent</code> baseline is being requested for * @param width the width to get the baseline for * @param height the height to get the baseline for * @throws NullPointerException if <code>c</code> is <code>null</code> * @throws IllegalArgumentException if width or height is &lt; 0 * @return baseline or a value &lt; 0 indicating there is no reasonable * baseline * @see javax.swing.JComponent#getBaseline(int,int) * @since 1.6 */ public int getBaseline(JComponent c, int width, int height) { if (c == null) { throw new NullPointerException("Component must be non-null"); } if (width < 0 || height < 0) { throw new IllegalArgumentException( "Width and height must be >= 0"); } return -1; } /** {@collect.stats} * Returns an enum indicating how the baseline of he component * changes as the size changes. This method is primarily meant for * layout managers and GUI builders. * <p> * This method returns <code>BaselineResizeBehavior.OTHER</code>. * Subclasses that support a baseline should override appropriately. * * @param c <code>JComponent</code> to return baseline resize behavior for * @return an enum indicating how the baseline changes as the component * size changes * @throws NullPointerException if <code>c</code> is <code>null</code> * @see javax.swing.JComponent#getBaseline(int, int) * @since 1.6 */ public Component.BaselineResizeBehavior getBaselineResizeBehavior( JComponent c) { if (c == null) { throw new NullPointerException("Component must be non-null"); } return Component.BaselineResizeBehavior.OTHER; } /** {@collect.stats} * Returns the number of accessible children in the object. If all * of the children of this object implement <code>Accessible</code>, * this * method should return the number of children of this object. * UIs might wish to override this if they present areas on the * screen that can be viewed as components, but actual components * are not used for presenting those areas. * * Note: As of v1.3, it is recommended that developers call * <code>Component.AccessibleAWTComponent.getAccessibleChildrenCount()</code> instead * of this method. * * @see #getAccessibleChild * @return the number of accessible children in the object */ public int getAccessibleChildrenCount(JComponent c) { return SwingUtilities.getAccessibleChildrenCount(c); } /** {@collect.stats} * Returns the <code>i</code>th <code>Accessible</code> child of the object. * UIs might need to override this if they present areas on the * screen that can be viewed as components, but actual components * are not used for presenting those areas. * * <p> * * Note: As of v1.3, it is recommended that developers call * <code>Component.AccessibleAWTComponent.getAccessibleChild()</code> instead of * this method. * * @see #getAccessibleChildrenCount * @param i zero-based index of child * @return the <code>i</code>th <code>Accessible</code> child of the object */ public Accessible getAccessibleChild(JComponent c, int i) { return SwingUtilities.getAccessibleChild(c, i); } }
Java
/* * Copyright (c) 1997, 1998, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; /** {@collect.stats} * Pluggable look and feel interface for JScrollPane. * * @author Hans Muller */ public abstract class ScrollPaneUI extends ComponentUI { }
Java
/* * Copyright (c) 1997, 1998, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf; /** {@collect.stats} * Pluggable look and feel interface for JTable. * * @author Alan Chung */ public abstract class TableUI extends ComponentUI { }
Java
/* * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import java.awt.*; import java.net.URL; import java.util.*; import javax.swing.*; import javax.swing.plaf.*; import sun.swing.SwingUtilities2; import sun.swing.PrintColorUIResource; import sun.swing.SwingLazyValue; /** {@collect.stats} * The default theme for the {@code MetalLookAndFeel}. * <p> * The designers * of the Metal Look and Feel strive to keep the default look up to * date, possibly through the use of new themes in the future. * Therefore, developers should only use this class directly when they * wish to customize the "Ocean" look, or force it to be the current * theme, regardless of future updates. * <p> * All colors returned by {@code OceanTheme} are completely * opaque. * * @since 1.5 * @see MetalLookAndFeel#setCurrentTheme */ public class OceanTheme extends DefaultMetalTheme { private static final ColorUIResource PRIMARY1 = new ColorUIResource(0x6382BF); private static final ColorUIResource PRIMARY2 = new ColorUIResource(0xA3B8CC); private static final ColorUIResource PRIMARY3 = new ColorUIResource(0xB8CFE5); private static final ColorUIResource SECONDARY1 = new ColorUIResource(0x7A8A99); private static final ColorUIResource SECONDARY2 = new ColorUIResource(0xB8CFE5); private static final ColorUIResource SECONDARY3 = new ColorUIResource(0xEEEEEE); private static final ColorUIResource CONTROL_TEXT_COLOR = new PrintColorUIResource(0x333333, Color.BLACK); private static final ColorUIResource INACTIVE_CONTROL_TEXT_COLOR = new ColorUIResource(0x999999); private static final ColorUIResource MENU_DISABLED_FOREGROUND = new ColorUIResource(0x999999); private static final ColorUIResource OCEAN_BLACK = new PrintColorUIResource(0x333333, Color.BLACK); private static final ColorUIResource OCEAN_DROP = new ColorUIResource(0xD2E9FF); // ComponentOrientation Icon // Delegates to different icons based on component orientation private static class COIcon extends IconUIResource { private Icon rtl; public COIcon(Icon ltr, Icon rtl) { super(ltr); this.rtl = rtl; } public void paintIcon(Component c, Graphics g, int x, int y) { if (MetalUtils.isLeftToRight(c)) { super.paintIcon(c, g, x, y); } else { rtl.paintIcon(c, g, x, y); } } } // InternalFrame Icon // Delegates to different icons based on button state private static class IFIcon extends IconUIResource { private Icon pressed; public IFIcon(Icon normal, Icon pressed) { super(normal); this.pressed = pressed; } public void paintIcon(Component c, Graphics g, int x, int y) { ButtonModel model = ((AbstractButton)c).getModel(); if (model.isPressed() && model.isArmed()) { pressed.paintIcon(c, g, x, y); } else { super.paintIcon(c, g, x, y); } } } /** {@collect.stats} * Creates an instance of <code>OceanTheme</code> */ public OceanTheme() { } /** {@collect.stats} * Add this theme's custom entries to the defaults table. * * @param table the defaults table, non-null * @throws NullPointerException if {@code table} is {@code null} */ public void addCustomEntriesToTable(UIDefaults table) { Object focusBorder = new SwingLazyValue( "javax.swing.plaf.BorderUIResource$LineBorderUIResource", new Object[] {getPrimary1()}); // .30 0 DDE8F3 white secondary2 java.util.List buttonGradient = Arrays.asList( new Object[] {new Float(.3f), new Float(0f), new ColorUIResource(0xDDE8F3), getWhite(), getSecondary2() }); // Other possible properties that aren't defined: // // Used when generating the disabled Icons, provides the region to // constrain grays to. // Button.disabledGrayRange -> Object[] of Integers giving min/max // InternalFrame.inactiveTitleGradient -> Gradient when the // internal frame is inactive. Color cccccc = new ColorUIResource(0xCCCCCC); Color dadada = new ColorUIResource(0xDADADA); Color c8ddf2 = new ColorUIResource(0xC8DDF2); Object directoryIcon = getIconResource("icons/ocean/directory.gif"); Object fileIcon = getIconResource("icons/ocean/file.gif"); java.util.List sliderGradient = Arrays.asList(new Object[] { new Float(.3f), new Float(.2f), c8ddf2, getWhite(), new ColorUIResource(SECONDARY2) }); Object[] defaults = new Object[] { "Button.gradient", buttonGradient, "Button.rollover", Boolean.TRUE, "Button.toolBarBorderBackground", INACTIVE_CONTROL_TEXT_COLOR, "Button.disabledToolBarBorderBackground", cccccc, "Button.rolloverIconType", "ocean", "CheckBox.rollover", Boolean.TRUE, "CheckBox.gradient", buttonGradient, "CheckBoxMenuItem.gradient", buttonGradient, // home2 "FileChooser.homeFolderIcon", getIconResource("icons/ocean/homeFolder.gif"), // directory2 "FileChooser.newFolderIcon", getIconResource("icons/ocean/newFolder.gif"), // updir2 "FileChooser.upFolderIcon", getIconResource("icons/ocean/upFolder.gif"), // computer2 "FileView.computerIcon", getIconResource("icons/ocean/computer.gif"), "FileView.directoryIcon", directoryIcon, // disk2 "FileView.hardDriveIcon", getIconResource("icons/ocean/hardDrive.gif"), "FileView.fileIcon", fileIcon, // floppy2 "FileView.floppyDriveIcon", getIconResource("icons/ocean/floppy.gif"), "Label.disabledForeground", getInactiveControlTextColor(), "Menu.opaque", Boolean.FALSE, "MenuBar.gradient", Arrays.asList(new Object[] { new Float(1f), new Float(0f), getWhite(), dadada, new ColorUIResource(dadada) }), "MenuBar.borderColor", cccccc, "InternalFrame.activeTitleGradient", buttonGradient, // close2 "InternalFrame.closeIcon", new UIDefaults.LazyValue() { public Object createValue(UIDefaults table) { return new IFIcon(getHastenedIcon("icons/ocean/close.gif", table), getHastenedIcon("icons/ocean/close-pressed.gif", table)); } }, // minimize "InternalFrame.iconifyIcon", new UIDefaults.LazyValue() { public Object createValue(UIDefaults table) { return new IFIcon(getHastenedIcon("icons/ocean/iconify.gif", table), getHastenedIcon("icons/ocean/iconify-pressed.gif", table)); } }, // restore "InternalFrame.minimizeIcon", new UIDefaults.LazyValue() { public Object createValue(UIDefaults table) { return new IFIcon(getHastenedIcon("icons/ocean/minimize.gif", table), getHastenedIcon("icons/ocean/minimize-pressed.gif", table)); } }, // menubutton3 "InternalFrame.icon", getIconResource("icons/ocean/menu.gif"), // maximize2 "InternalFrame.maximizeIcon", new UIDefaults.LazyValue() { public Object createValue(UIDefaults table) { return new IFIcon(getHastenedIcon("icons/ocean/maximize.gif", table), getHastenedIcon("icons/ocean/maximize-pressed.gif", table)); } }, // paletteclose "InternalFrame.paletteCloseIcon", new UIDefaults.LazyValue() { public Object createValue(UIDefaults table) { return new IFIcon(getHastenedIcon("icons/ocean/paletteClose.gif", table), getHastenedIcon("icons/ocean/paletteClose-pressed.gif", table)); } }, "List.focusCellHighlightBorder", focusBorder, "MenuBarUI", "javax.swing.plaf.metal.MetalMenuBarUI", "OptionPane.errorIcon", getIconResource("icons/ocean/error.png"), "OptionPane.informationIcon", getIconResource("icons/ocean/info.png"), "OptionPane.questionIcon", getIconResource("icons/ocean/question.png"), "OptionPane.warningIcon", getIconResource("icons/ocean/warning.png"), "RadioButton.gradient", buttonGradient, "RadioButton.rollover", Boolean.TRUE, "RadioButtonMenuItem.gradient", buttonGradient, "ScrollBar.gradient", buttonGradient, "Slider.altTrackColor", new ColorUIResource(0xD2E2EF), "Slider.gradient", sliderGradient, "Slider.focusGradient", sliderGradient, "SplitPane.oneTouchButtonsOpaque", Boolean.FALSE, "SplitPane.dividerFocusColor", c8ddf2, "TabbedPane.borderHightlightColor", getPrimary1(), "TabbedPane.contentAreaColor", c8ddf2, "TabbedPane.contentBorderInsets", new Insets(4, 2, 3, 3), "TabbedPane.selected", c8ddf2, "TabbedPane.tabAreaBackground", dadada, "TabbedPane.tabAreaInsets", new Insets(2, 2, 0, 6), "TabbedPane.unselectedBackground", SECONDARY3, "Table.focusCellHighlightBorder", focusBorder, "Table.gridColor", SECONDARY1, "TableHeader.focusCellBackground", c8ddf2, "ToggleButton.gradient", buttonGradient, "ToolBar.borderColor", cccccc, "ToolBar.isRollover", Boolean.TRUE, "Tree.closedIcon", directoryIcon, "Tree.collapsedIcon", new UIDefaults.LazyValue() { public Object createValue(UIDefaults table) { return new COIcon(getHastenedIcon("icons/ocean/collapsed.gif", table), getHastenedIcon("icons/ocean/collapsed-rtl.gif", table)); } }, "Tree.expandedIcon", getIconResource("icons/ocean/expanded.gif"), "Tree.leafIcon", fileIcon, "Tree.openIcon", directoryIcon, "Tree.selectionBorderColor", getPrimary1(), "Tree.dropLineColor", getPrimary1(), "Table.dropLineColor", getPrimary1(), "Table.dropLineShortColor", OCEAN_BLACK, "Table.dropCellBackground", OCEAN_DROP, "Tree.dropCellBackground", OCEAN_DROP, "List.dropCellBackground", OCEAN_DROP, "List.dropLineColor", getPrimary1() }; table.putDefaults(defaults); } /** {@collect.stats} * Overriden to enable picking up the system fonts, if applicable. */ boolean isSystemTheme() { return true; } /** {@collect.stats} * Return the name of this theme, "Ocean". * * @return "Ocean" */ public String getName() { return "Ocean"; } /** {@collect.stats} * Returns the primary 1 color. This returns a color with an rgb hex value * of {@code 0x6382BF}. * * @return the primary 1 color * @see java.awt.Color#decode */ protected ColorUIResource getPrimary1() { return PRIMARY1; } /** {@collect.stats} * Returns the primary 2 color. This returns a color with an rgb hex value * of {@code 0xA3B8CC}. * * @return the primary 2 color * @see java.awt.Color#decode */ protected ColorUIResource getPrimary2() { return PRIMARY2; } /** {@collect.stats} * Returns the primary 3 color. This returns a color with an rgb hex value * of {@code 0xB8CFE5}. * * @return the primary 3 color * @see java.awt.Color#decode */ protected ColorUIResource getPrimary3() { return PRIMARY3; } /** {@collect.stats} * Returns the secondary 1 color. This returns a color with an rgb hex * value of {@code 0x7A8A99}. * * @return the secondary 1 color * @see java.awt.Color#decode */ protected ColorUIResource getSecondary1() { return SECONDARY1; } /** {@collect.stats} * Returns the secondary 2 color. This returns a color with an rgb hex * value of {@code 0xB8CFE5}. * * @return the secondary 2 color * @see java.awt.Color#decode */ protected ColorUIResource getSecondary2() { return SECONDARY2; } /** {@collect.stats} * Returns the secondary 3 color. This returns a color with an rgb hex * value of {@code 0xEEEEEE}. * * @return the secondary 3 color * @see java.awt.Color#decode */ protected ColorUIResource getSecondary3() { return SECONDARY3; } /** {@collect.stats} * Returns the black color. This returns a color with an rgb hex * value of {@code 0x333333}. * * @return the black color * @see java.awt.Color#decode */ protected ColorUIResource getBlack() { return OCEAN_BLACK; } /** {@collect.stats} * Returns the desktop color. This returns a color with an rgb hex * value of {@code 0xFFFFFF}. * * @return the desktop color * @see java.awt.Color#decode */ public ColorUIResource getDesktopColor() { return MetalTheme.white; } /** {@collect.stats} * Returns the inactive control text color. This returns a color with an * rgb hex value of {@code 0x999999}. * * @return the inactive control text color */ public ColorUIResource getInactiveControlTextColor() { return INACTIVE_CONTROL_TEXT_COLOR; } /** {@collect.stats} * Returns the control text color. This returns a color with an * rgb hex value of {@code 0x333333}. * * @return the control text color */ public ColorUIResource getControlTextColor() { return CONTROL_TEXT_COLOR; } /** {@collect.stats} * Returns the menu disabled foreground color. This returns a color with an * rgb hex value of {@code 0x999999}. * * @return the menu disabled foreground color */ public ColorUIResource getMenuDisabledForeground() { return MENU_DISABLED_FOREGROUND; } private Object getIconResource(String iconID) { return SwingUtilities2.makeIcon(getClass(), OceanTheme.class, iconID); } // makes use of getIconResource() to fetch an icon and then hastens it // - calls createValue() on it and returns the actual icon private Icon getHastenedIcon(String iconID, UIDefaults table) { Object res = getIconResource(iconID); return (Icon)((UIDefaults.LazyValue)res).createValue(table); } }
Java
/* * Copyright (c) 2001, 2002, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import javax.swing.plaf.metal.*; import javax.swing.*; import javax.swing.border.*; import java.awt.*; /** {@collect.stats} * A high contrast theme. This is used on Windows if the system property * awt.highContrast.on is true. * * @author Michael C. Albers */ class MetalHighContrastTheme extends DefaultMetalTheme { private static final ColorUIResource primary1 = new ColorUIResource(0, 0, 0); private static final ColorUIResource primary2 = new ColorUIResource( 204, 204, 204); private static final ColorUIResource primary3 = new ColorUIResource(255, 255, 255); private static final ColorUIResource primaryHighlight = new ColorUIResource(102, 102, 102); private static final ColorUIResource secondary2 = new ColorUIResource( 204, 204, 204); private static final ColorUIResource secondary3 = new ColorUIResource( 255, 255, 255); private static final ColorUIResource controlHighlight = new ColorUIResource(102, 102, 102); // This does not override getSecondary1 (102,102,102) public String getName() { return "Contrast"; } protected ColorUIResource getPrimary1() { return primary1; } protected ColorUIResource getPrimary2() { return primary2; } protected ColorUIResource getPrimary3() { return primary3; } public ColorUIResource getPrimaryControlHighlight() { return primaryHighlight; } protected ColorUIResource getSecondary2() { return secondary2; } protected ColorUIResource getSecondary3() { return secondary3; } public ColorUIResource getControlHighlight() { // This was super.getSecondary3(); return secondary2; } public ColorUIResource getFocusColor() { return getBlack(); } public ColorUIResource getTextHighlightColor() { return getBlack(); } public ColorUIResource getHighlightedTextColor() { return getWhite(); } public ColorUIResource getMenuSelectedBackground() { return getBlack(); } public ColorUIResource getMenuSelectedForeground() { return getWhite(); } public ColorUIResource getAcceleratorForeground() { return getBlack(); } public ColorUIResource getAcceleratorSelectedForeground() { return getWhite(); } public void addCustomEntriesToTable(UIDefaults table) { Border blackLineBorder = new BorderUIResource(new LineBorder( getBlack())); Border whiteLineBorder = new BorderUIResource(new LineBorder( getWhite())); Object textBorder = new BorderUIResource(new CompoundBorder( blackLineBorder, new BasicBorders.MarginBorder())); Object[] defaults = new Object[] { "ToolTip.border", blackLineBorder, "TitledBorder.border", blackLineBorder, "TextField.border", textBorder, "PasswordField.border", textBorder, "TextArea.border", textBorder, "TextPane.border", textBorder, "EditorPane.border", textBorder, "ComboBox.background", getWindowBackground(), "ComboBox.foreground", getUserTextColor(), "ComboBox.selectionBackground", getTextHighlightColor(), "ComboBox.selectionForeground", getHighlightedTextColor(), "ProgressBar.foreground", getUserTextColor(), "ProgressBar.background", getWindowBackground(), "ProgressBar.selectionForeground", getWindowBackground(), "ProgressBar.selectionBackground", getUserTextColor(), "OptionPane.errorDialog.border.background", getPrimary1(), "OptionPane.errorDialog.titlePane.foreground", getPrimary3(), "OptionPane.errorDialog.titlePane.background", getPrimary1(), "OptionPane.errorDialog.titlePane.shadow", getPrimary2(), "OptionPane.questionDialog.border.background", getPrimary1(), "OptionPane.questionDialog.titlePane.foreground", getPrimary3(), "OptionPane.questionDialog.titlePane.background", getPrimary1(), "OptionPane.questionDialog.titlePane.shadow", getPrimary2(), "OptionPane.warningDialog.border.background", getPrimary1(), "OptionPane.warningDialog.titlePane.foreground", getPrimary3(), "OptionPane.warningDialog.titlePane.background", getPrimary1(), "OptionPane.warningDialog.titlePane.shadow", getPrimary2(), }; table.putDefaults(defaults); } /** {@collect.stats} * Returns true if this is a theme provided by the core platform. */ boolean isSystemTheme() { return (getClass() == MetalHighContrastTheme.class); } }
Java
/* * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import sun.awt.AppContext; import javax.swing.*; import javax.swing.plaf.basic.BasicCheckBoxUI; import java.awt.*; import java.awt.event.*; import javax.swing.plaf.*; import java.io.Serializable; /** {@collect.stats} * CheckboxUI implementation for MetalCheckboxUI * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Michael C. Albers * */ public class MetalCheckBoxUI extends MetalRadioButtonUI { // NOTE: MetalCheckBoxUI inherts from MetalRadioButtonUI instead // of BasicCheckBoxUI because we want to pick up all the // painting changes made in MetalRadioButtonUI. private static final Object METAL_CHECK_BOX_UI_KEY = new Object(); private final static String propertyPrefix = "CheckBox" + "."; private boolean defaults_initialized = false; // ******************************** // Create PlAF // ******************************** public static ComponentUI createUI(JComponent b) { AppContext appContext = AppContext.getAppContext(); MetalCheckBoxUI checkboxUI = (MetalCheckBoxUI) appContext.get(METAL_CHECK_BOX_UI_KEY); if (checkboxUI == null) { checkboxUI = new MetalCheckBoxUI(); appContext.put(METAL_CHECK_BOX_UI_KEY, checkboxUI); } return checkboxUI; } public String getPropertyPrefix() { return propertyPrefix; } // ******************************** // Defaults // ******************************** public void installDefaults(AbstractButton b) { super.installDefaults(b); if(!defaults_initialized) { icon = UIManager.getIcon(getPropertyPrefix() + "icon"); defaults_initialized = true; } } protected void uninstallDefaults(AbstractButton b) { super.uninstallDefaults(b); defaults_initialized = false; } }
Java
/* * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.plaf.*; import javax.swing.*; /** {@collect.stats} * {@code MetalTheme} provides the color palette and fonts used by * the Java Look and Feel. * <p> * {@code MetalTheme} is abstract, see {@code DefaultMetalTheme} and * {@code OceanTheme} for concrete implementations. * <p> * {@code MetalLookAndFeel} maintains the current theme that the * the {@code ComponentUI} implementations for metal use. Refer to * {@link MetalLookAndFeel#setCurrentTheme * MetalLookAndFeel.setCurrentTheme(MetalTheme)} for details on changing * the current theme. * <p> * {@code MetalTheme} provides a number of public methods for getting * colors. These methods are implemented in terms of a * handful of protected abstract methods. A subclass need only override * the protected abstract methods ({@code getPrimary1}, * {@code getPrimary2}, {@code getPrimary3}, {@code getSecondary1}, * {@code getSecondary2}, and {@code getSecondary3}); although a subclass * may override the other public methods for more control over the set of * colors that are used. * <p> * Concrete implementations of {@code MetalTheme} must return {@code non-null} * values from all methods. While the behavior of returning {@code null} is * not specified, returning {@code null} will result in incorrect behavior. * <p> * It is strongly recommended that subclasses return completely opaque colors. * To do otherwise may result in rendering problems, such as visual garbage. * * @see DefaultMetalTheme * @see OceanTheme * @see MetalLookAndFeel#setCurrentTheme * * @author Steve Wilson */ public abstract class MetalTheme { // Contants identifying the various Fonts that are Theme can support static final int CONTROL_TEXT_FONT = 0; static final int SYSTEM_TEXT_FONT = 1; static final int USER_TEXT_FONT = 2; static final int MENU_TEXT_FONT = 3; static final int WINDOW_TITLE_FONT = 4; static final int SUB_TEXT_FONT = 5; static ColorUIResource white = new ColorUIResource( 255, 255, 255 ); private static ColorUIResource black = new ColorUIResource( 0, 0, 0 ); /** {@collect.stats} * Returns the name of this theme. * * @return the name of this theme */ public abstract String getName(); /** {@collect.stats} * Returns the primary 1 color. * * @return the primary 1 color */ protected abstract ColorUIResource getPrimary1(); // these are blue in Metal Default Theme /** {@collect.stats} * Returns the primary 2 color. * * @return the primary 2 color */ protected abstract ColorUIResource getPrimary2(); /** {@collect.stats} * Returns the primary 3 color. * * @return the primary 3 color */ protected abstract ColorUIResource getPrimary3(); /** {@collect.stats} * Returns the secondary 1 color. * * @return the secondary 1 color */ protected abstract ColorUIResource getSecondary1(); // these are gray in Metal Default Theme /** {@collect.stats} * Returns the secondary 2 color. * * @return the secondary 2 color */ protected abstract ColorUIResource getSecondary2(); /** {@collect.stats} * Returns the secondary 3 color. * * @return the secondary 3 color */ protected abstract ColorUIResource getSecondary3(); /** {@collect.stats} * Returns the control text font. * * @return the control text font */ public abstract FontUIResource getControlTextFont(); /** {@collect.stats} * Returns the system text font. * * @return the system text font */ public abstract FontUIResource getSystemTextFont(); /** {@collect.stats} * Returns the user text font. * * @return the user text font */ public abstract FontUIResource getUserTextFont(); /** {@collect.stats} * Returns the menu text font. * * @return the menu text font */ public abstract FontUIResource getMenuTextFont(); /** {@collect.stats} * Returns the window title font. * * @return the window title font */ public abstract FontUIResource getWindowTitleFont(); /** {@collect.stats} * Returns the sub-text font. * * @return the sub-text font */ public abstract FontUIResource getSubTextFont(); /** {@collect.stats} * Returns the white color. This returns opaque white * ({@code 0xFFFFFFFF}). * * @return the white color */ protected ColorUIResource getWhite() { return white; } /** {@collect.stats} * Returns the black color. This returns opaque black * ({@code 0xFF000000}). * * @return the black color */ protected ColorUIResource getBlack() { return black; } /** {@collect.stats} * Returns the focus color. This returns the value of * {@code getPrimary2()}. * * @return the focus color */ public ColorUIResource getFocusColor() { return getPrimary2(); } /** {@collect.stats} * Returns the desktop color. This returns the value of * {@code getPrimary2()}. * * @return the desktop color */ public ColorUIResource getDesktopColor() { return getPrimary2(); } /** {@collect.stats} * Returns the control color. This returns the value of * {@code getSecondary3()}. * * @return the control color */ public ColorUIResource getControl() { return getSecondary3(); } /** {@collect.stats} * Returns the control shadow color. This returns * the value of {@code getSecondary2()}. * * @return the control shadow color */ public ColorUIResource getControlShadow() { return getSecondary2(); } /** {@collect.stats} * Returns the control dark shadow color. This returns * the value of {@code getSecondary1()}. * * @return the control dark shadow color */ public ColorUIResource getControlDarkShadow() { return getSecondary1(); } /** {@collect.stats} * Returns the control info color. This returns * the value of {@code getBlack()}. * * @return the control info color */ public ColorUIResource getControlInfo() { return getBlack(); } /** {@collect.stats} * Returns the control highlight color. This returns * the value of {@code getWhite()}. * * @return the control highlight color */ public ColorUIResource getControlHighlight() { return getWhite(); } /** {@collect.stats} * Returns the control disabled color. This returns * the value of {@code getSecondary2()}. * * @return the control disabled color */ public ColorUIResource getControlDisabled() { return getSecondary2(); } /** {@collect.stats} * Returns the primary control color. This returns * the value of {@code getPrimary3()}. * * @return the primary control color */ public ColorUIResource getPrimaryControl() { return getPrimary3(); } /** {@collect.stats} * Returns the primary control shadow color. This returns * the value of {@code getPrimary2()}. * * @return the primary control shadow color */ public ColorUIResource getPrimaryControlShadow() { return getPrimary2(); } /** {@collect.stats} * Returns the primary control dark shadow color. This * returns the value of {@code getPrimary1()}. * * @return the primary control dark shadow color */ public ColorUIResource getPrimaryControlDarkShadow() { return getPrimary1(); } /** {@collect.stats} * Returns the primary control info color. This * returns the value of {@code getBlack()}. * * @return the primary control info color */ public ColorUIResource getPrimaryControlInfo() { return getBlack(); } /** {@collect.stats} * Returns the primary control highlight color. This * returns the value of {@code getWhite()}. * * @return the primary control highlight color */ public ColorUIResource getPrimaryControlHighlight() { return getWhite(); } /** {@collect.stats} * Returns the system text color. This returns the value of * {@code getBlack()}. * * @return the system text color */ public ColorUIResource getSystemTextColor() { return getBlack(); } /** {@collect.stats} * Returns the control text color. This returns the value of * {@code getControlInfo()}. * * @return the control text color */ public ColorUIResource getControlTextColor() { return getControlInfo(); } /** {@collect.stats} * Returns the inactive control text color. This returns the value of * {@code getControlDisabled()}. * * @return the inactive control text color */ public ColorUIResource getInactiveControlTextColor() { return getControlDisabled(); } /** {@collect.stats} * Returns the inactive system text color. This returns the value of * {@code getSecondary2()}. * * @return the inactive system text color */ public ColorUIResource getInactiveSystemTextColor() { return getSecondary2(); } /** {@collect.stats} * Returns the user text color. This returns the value of * {@code getBlack()}. * * @return the user text color */ public ColorUIResource getUserTextColor() { return getBlack(); } /** {@collect.stats} * Returns the text highlight color. This returns the value of * {@code getPrimary3()}. * * @return the text highlight color */ public ColorUIResource getTextHighlightColor() { return getPrimary3(); } /** {@collect.stats} * Returns the highlighted text color. This returns the value of * {@code getControlTextColor()}. * * @return the highlighted text color */ public ColorUIResource getHighlightedTextColor() { return getControlTextColor(); } /** {@collect.stats} * Returns the window background color. This returns the value of * {@code getWhite()}. * * @return the window background color */ public ColorUIResource getWindowBackground() { return getWhite(); } /** {@collect.stats} * Returns the window title background color. This returns the value of * {@code getPrimary3()}. * * @return the window title background color */ public ColorUIResource getWindowTitleBackground() { return getPrimary3(); } /** {@collect.stats} * Returns the window title foreground color. This returns the value of * {@code getBlack()}. * * @return the window title foreground color */ public ColorUIResource getWindowTitleForeground() { return getBlack(); } /** {@collect.stats} * Returns the window title inactive background color. This * returns the value of {@code getSecondary3()}. * * @return the window title inactive background color */ public ColorUIResource getWindowTitleInactiveBackground() { return getSecondary3(); } /** {@collect.stats} * Returns the window title inactive foreground color. This * returns the value of {@code getBlack()}. * * @return the window title inactive foreground color */ public ColorUIResource getWindowTitleInactiveForeground() { return getBlack(); } /** {@collect.stats} * Returns the menu background color. This * returns the value of {@code getSecondary3()}. * * @return the menu background color */ public ColorUIResource getMenuBackground() { return getSecondary3(); } /** {@collect.stats} * Returns the menu foreground color. This * returns the value of {@code getBlack()}. * * @return the menu foreground color */ public ColorUIResource getMenuForeground() { return getBlack(); } /** {@collect.stats} * Returns the menu selected background color. This * returns the value of {@code getPrimary2()}. * * @return the menu selected background color */ public ColorUIResource getMenuSelectedBackground() { return getPrimary2(); } /** {@collect.stats} * Returns the menu selected foreground color. This * returns the value of {@code getBlack()}. * * @return the menu selected foreground color */ public ColorUIResource getMenuSelectedForeground() { return getBlack(); } /** {@collect.stats} * Returns the menu disabled foreground color. This * returns the value of {@code getSecondary2()}. * * @return the menu disabled foreground color */ public ColorUIResource getMenuDisabledForeground() { return getSecondary2(); } /** {@collect.stats} * Returns the separator background color. This * returns the value of {@code getWhite()}. * * @return the separator background color */ public ColorUIResource getSeparatorBackground() { return getWhite(); } /** {@collect.stats} * Returns the separator foreground color. This * returns the value of {@code getPrimary1()}. * * @return the separator foreground color */ public ColorUIResource getSeparatorForeground() { return getPrimary1(); } /** {@collect.stats} * Returns the accelerator foreground color. This * returns the value of {@code getPrimary1()}. * * @return the accelerator foreground color */ public ColorUIResource getAcceleratorForeground() { return getPrimary1(); } /** {@collect.stats} * Returns the accelerator selected foreground color. This * returns the value of {@code getBlack()}. * * @return the accelerator selected foreground color */ public ColorUIResource getAcceleratorSelectedForeground() { return getBlack(); } /** {@collect.stats} * Adds values specific to this theme to the defaults table. This method * is invoked when the look and feel defaults are obtained from * {@code MetalLookAndFeel}. * <p> * This implementation does nothing; it is provided for subclasses * that wish to customize the defaults table. * * @param table the {@code UIDefaults} to add the values to * * @see MetalLookAndFeel#getDefaults */ public void addCustomEntriesToTable(UIDefaults table) {} /** {@collect.stats} * This is invoked when a MetalLookAndFeel is installed and about to * start using this theme. When we can add API this should be nuked * in favor of DefaultMetalTheme overriding addCustomEntriesToTable. */ void install() { } /** {@collect.stats} * Returns true if this is a theme provided by the core platform. */ boolean isSystemTheme() { return false; } }
Java
/* * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import sun.swing.SwingUtilities2; import sun.awt.AppContext; import java.awt.*; import java.awt.event.*; import java.lang.ref.*; import java.util.*; import javax.swing.plaf.basic.BasicToggleButtonUI; import javax.swing.*; import javax.swing.border.*; import javax.swing.plaf.*; import javax.swing.*; import java.io.Serializable; /** {@collect.stats} * MetalToggleButton implementation * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Tom Santos */ public class MetalToggleButtonUI extends BasicToggleButtonUI { private static final Object METAL_TOGGLE_BUTTON_UI_KEY = new Object(); protected Color focusColor; protected Color selectColor; protected Color disabledTextColor; private boolean defaults_initialized = false; // ******************************** // Create PLAF // ******************************** public static ComponentUI createUI(JComponent b) { AppContext appContext = AppContext.getAppContext(); MetalToggleButtonUI metalToggleButtonUI = (MetalToggleButtonUI) appContext.get(METAL_TOGGLE_BUTTON_UI_KEY); if (metalToggleButtonUI == null) { metalToggleButtonUI = new MetalToggleButtonUI(); appContext.put(METAL_TOGGLE_BUTTON_UI_KEY, metalToggleButtonUI); } return metalToggleButtonUI; } // ******************************** // Install Defaults // ******************************** public void installDefaults(AbstractButton b) { super.installDefaults(b); if(!defaults_initialized) { focusColor = UIManager.getColor(getPropertyPrefix() + "focus"); selectColor = UIManager.getColor(getPropertyPrefix() + "select"); disabledTextColor = UIManager.getColor(getPropertyPrefix() + "disabledText"); defaults_initialized = true; } } protected void uninstallDefaults(AbstractButton b) { super.uninstallDefaults(b); defaults_initialized = false; } // ******************************** // Default Accessors // ******************************** protected Color getSelectColor() { return selectColor; } protected Color getDisabledTextColor() { return disabledTextColor; } protected Color getFocusColor() { return focusColor; } // ******************************** // Paint Methods // ******************************** /** {@collect.stats} * If necessary paints the background of the component, then invokes * <code>paint</code>. * * @param g Graphics to paint to * @param c JComponent painting on * @throws NullPointerException if <code>g</code> or <code>c</code> is * null * @see javax.swing.plaf.ComponentUI#update * @see javax.swing.plaf.ComponentUI#paint * @since 1.5 */ public void update(Graphics g, JComponent c) { AbstractButton button = (AbstractButton)c; if ((c.getBackground() instanceof UIResource) && button.isContentAreaFilled() && c.isEnabled()) { ButtonModel model = button.getModel(); if (!MetalUtils.isToolBarButton(c)) { if (!model.isArmed() && !model.isPressed() && MetalUtils.drawGradient( c, g, "ToggleButton.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) { paint(g, c); return; } } else if ((model.isRollover() || model.isSelected()) && MetalUtils.drawGradient(c, g, "ToggleButton.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) { paint(g, c); return; } } super.update(g, c); } protected void paintButtonPressed(Graphics g, AbstractButton b) { if ( b.isContentAreaFilled() ) { g.setColor(getSelectColor()); g.fillRect(0, 0, b.getWidth(), b.getHeight()); } } protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); FontMetrics fm = SwingUtilities2.getFontMetrics(b, g); int mnemIndex = b.getDisplayedMnemonicIndex(); /* Draw the Text */ if(model.isEnabled()) { /** {@collect.stats}* paint the text normally */ g.setColor(b.getForeground()); } else { /** {@collect.stats}* paint the text disabled ***/ if (model.isSelected()) { g.setColor(c.getBackground()); } else { g.setColor(getDisabledTextColor()); } } SwingUtilities2.drawStringUnderlineCharAt(c, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent()); } protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect){ Rectangle focusRect = new Rectangle(); String text = b.getText(); boolean isIcon = b.getIcon() != null; // If there is text if ( text != null && !text.equals( "" ) ) { if ( !isIcon ) { focusRect.setBounds( textRect ); } else { focusRect.setBounds( iconRect.union( textRect ) ); } } // If there is an icon and no text else if ( isIcon ) { focusRect.setBounds( iconRect ); } g.setColor(getFocusColor()); g.drawRect((focusRect.x-1), (focusRect.y-1), focusRect.width+1, focusRect.height+1); } /** {@collect.stats} * Paints the appropriate icon of the button <code>b</code> in the * space <code>iconRect</code>. * * @param g Graphics to paint to * @param b Button to render for * @param iconRect space to render in * @throws NullPointerException if any of the arguments are null. * @since 1.5 */ protected void paintIcon(Graphics g, AbstractButton b, Rectangle iconRect) { super.paintIcon(g, b, iconRect); } }
Java
/* * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import sun.awt.AppContext; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; import java.awt.Image; import java.awt.Transparency; import java.awt.image.BufferedImage; import java.awt.image.DataBuffer; import java.awt.image.IndexColorModel; import java.util.ArrayList; import java.util.List; import javax.swing.Icon; /** {@collect.stats} * Implements the bumps used throughout the Metal Look and Feel. * * @author Tom Santos * @author Steve Wilson */ class MetalBumps implements Icon { static final Color ALPHA = new Color(0, 0, 0, 0); protected int xBumps; protected int yBumps; protected Color topColor; protected Color shadowColor; protected Color backColor; private static final Object METAL_BUMPS = new Object(); protected BumpBuffer buffer; /** {@collect.stats} * Creates MetalBumps of the specified size with the specified colors. * If <code>newBackColor</code> is null, the background will be * transparent. */ public MetalBumps( int width, int height, Color newTopColor, Color newShadowColor, Color newBackColor ) { setBumpArea( width, height ); setBumpColors( newTopColor, newShadowColor, newBackColor ); } private static BumpBuffer createBuffer(GraphicsConfiguration gc, Color topColor, Color shadowColor, Color backColor) { AppContext context = AppContext.getAppContext(); List<BumpBuffer> buffers = (List<BumpBuffer>) context.get(METAL_BUMPS); if (buffers == null) { buffers = new ArrayList<BumpBuffer>(); context.put(METAL_BUMPS, buffers); } for (BumpBuffer buffer : buffers) { if (buffer.hasSameConfiguration(gc, topColor, shadowColor, backColor)) { return buffer; } } BumpBuffer buffer = new BumpBuffer(gc, topColor, shadowColor, backColor); buffers.add(buffer); return buffer; } public void setBumpArea( Dimension bumpArea ) { setBumpArea( bumpArea.width, bumpArea.height ); } public void setBumpArea( int width, int height ) { xBumps = width / 2; yBumps = height / 2; } public void setBumpColors( Color newTopColor, Color newShadowColor, Color newBackColor ) { topColor = newTopColor; shadowColor = newShadowColor; if (newBackColor == null) { backColor = ALPHA; } else { backColor = newBackColor; } } public void paintIcon( Component c, Graphics g, int x, int y ) { GraphicsConfiguration gc = (g instanceof Graphics2D) ? (GraphicsConfiguration)((Graphics2D)g). getDeviceConfiguration() : null; if ((buffer == null) || !buffer.hasSameConfiguration(gc, topColor, shadowColor, backColor)) { buffer = createBuffer(gc, topColor, shadowColor, backColor); } int bufferWidth = BumpBuffer.IMAGE_SIZE; int bufferHeight = BumpBuffer.IMAGE_SIZE; int iconWidth = getIconWidth(); int iconHeight = getIconHeight(); int x2 = x + iconWidth; int y2 = y + iconHeight; int savex = x; while (y < y2) { int h = Math.min(y2 - y, bufferHeight); for (x = savex; x < x2; x += bufferWidth) { int w = Math.min(x2 - x, bufferWidth); g.drawImage(buffer.getImage(), x, y, x+w, y+h, 0, 0, w, h, null); } y += bufferHeight; } } public int getIconWidth() { return xBumps * 2; } public int getIconHeight() { return yBumps * 2; } } class BumpBuffer { static final int IMAGE_SIZE = 64; transient Image image; Color topColor; Color shadowColor; Color backColor; private GraphicsConfiguration gc; public BumpBuffer(GraphicsConfiguration gc, Color aTopColor, Color aShadowColor, Color aBackColor) { this.gc = gc; topColor = aTopColor; shadowColor = aShadowColor; backColor = aBackColor; createImage(); fillBumpBuffer(); } public boolean hasSameConfiguration(GraphicsConfiguration gc, Color aTopColor, Color aShadowColor, Color aBackColor) { if (this.gc != null) { if (!this.gc.equals(gc)) { return false; } } else if (gc != null) { return false; } return topColor.equals( aTopColor ) && shadowColor.equals( aShadowColor ) && backColor.equals( aBackColor ); } /** {@collect.stats} * Returns the Image containing the bumps appropriate for the passed in * <code>GraphicsConfiguration</code>. */ public Image getImage() { return image; } /** {@collect.stats} * Paints the bumps into the current image. */ private void fillBumpBuffer() { Graphics g = image.getGraphics(); g.setColor( backColor ); g.fillRect( 0, 0, IMAGE_SIZE, IMAGE_SIZE ); g.setColor(topColor); for (int x = 0; x < IMAGE_SIZE; x+=4) { for (int y = 0; y < IMAGE_SIZE; y+=4) { g.drawLine( x, y, x, y ); g.drawLine( x+2, y+2, x+2, y+2); } } g.setColor(shadowColor); for (int x = 0; x < IMAGE_SIZE; x+=4) { for (int y = 0; y < IMAGE_SIZE; y+=4) { g.drawLine( x+1, y+1, x+1, y+1 ); g.drawLine( x+3, y+3, x+3, y+3); } } g.dispose(); } /** {@collect.stats} * Creates the image appropriate for the passed in * <code>GraphicsConfiguration</code>, which may be null. */ private void createImage() { if (gc != null) { image = gc.createCompatibleImage(IMAGE_SIZE, IMAGE_SIZE, (backColor != MetalBumps.ALPHA) ? Transparency.OPAQUE : Transparency.BITMASK); } else { int cmap[] = { backColor.getRGB(), topColor.getRGB(), shadowColor.getRGB() }; IndexColorModel icm = new IndexColorModel(8, 3, cmap, 0, false, (backColor == MetalBumps.ALPHA) ? 0 : -1, DataBuffer.TYPE_BYTE); image = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_BYTE_INDEXED, icm); } } }
Java
/* * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import sun.swing.SwingUtilities2; import sun.awt.AppContext; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.plaf.basic.*; import javax.swing.border.*; import javax.swing.plaf.*; import java.io.Serializable; import javax.swing.text.View; /** {@collect.stats} * RadioButtonUI implementation for MetalRadioButtonUI * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Michael C. Albers (Metal modifications) * @author Jeff Dinkins (original BasicRadioButtonCode) */ public class MetalRadioButtonUI extends BasicRadioButtonUI { private static final Object METAL_RADIO_BUTTON_UI_KEY = new Object(); protected Color focusColor; protected Color selectColor; protected Color disabledTextColor; private boolean defaults_initialized = false; // ******************************** // Create PlAF // ******************************** public static ComponentUI createUI(JComponent c) { AppContext appContext = AppContext.getAppContext(); MetalRadioButtonUI metalRadioButtonUI = (MetalRadioButtonUI) appContext.get(METAL_RADIO_BUTTON_UI_KEY); if (metalRadioButtonUI == null) { metalRadioButtonUI = new MetalRadioButtonUI(); appContext.put(METAL_RADIO_BUTTON_UI_KEY, metalRadioButtonUI); } return metalRadioButtonUI; } // ******************************** // Install Defaults // ******************************** public void installDefaults(AbstractButton b) { super.installDefaults(b); if(!defaults_initialized) { focusColor = UIManager.getColor(getPropertyPrefix() + "focus"); selectColor = UIManager.getColor(getPropertyPrefix() + "select"); disabledTextColor = UIManager.getColor(getPropertyPrefix() + "disabledText"); defaults_initialized = true; } LookAndFeel.installProperty(b, "opaque", Boolean.TRUE); } protected void uninstallDefaults(AbstractButton b) { super.uninstallDefaults(b); defaults_initialized = false; } // ******************************** // Default Accessors // ******************************** protected Color getSelectColor() { return selectColor; } protected Color getDisabledTextColor() { return disabledTextColor; } protected Color getFocusColor() { return focusColor; } // ******************************** // Paint Methods // ******************************** public synchronized void paint(Graphics g, JComponent c) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); Dimension size = c.getSize(); int w = size.width; int h = size.height; Font f = c.getFont(); g.setFont(f); FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f); Rectangle viewRect = new Rectangle(size); Rectangle iconRect = new Rectangle(); Rectangle textRect = new Rectangle(); Insets i = c.getInsets(); viewRect.x += i.left; viewRect.y += i.top; viewRect.width -= (i.right + viewRect.x); viewRect.height -= (i.bottom + viewRect.y); Icon altIcon = b.getIcon(); Icon selectedIcon = null; Icon disabledIcon = null; String text = SwingUtilities.layoutCompoundLabel( c, fm, b.getText(), altIcon != null ? altIcon : getDefaultIcon(), b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, b.getIconTextGap()); // fill background if(c.isOpaque()) { g.setColor(b.getBackground()); g.fillRect(0,0, size.width, size.height); } // Paint the radio button if(altIcon != null) { if(!model.isEnabled()) { if(model.isSelected()) { altIcon = b.getDisabledSelectedIcon(); } else { altIcon = b.getDisabledIcon(); } } else if(model.isPressed() && model.isArmed()) { altIcon = b.getPressedIcon(); if(altIcon == null) { // Use selected icon altIcon = b.getSelectedIcon(); } } else if(model.isSelected()) { if(b.isRolloverEnabled() && model.isRollover()) { altIcon = (Icon) b.getRolloverSelectedIcon(); if (altIcon == null) { altIcon = (Icon) b.getSelectedIcon(); } } else { altIcon = (Icon) b.getSelectedIcon(); } } else if(b.isRolloverEnabled() && model.isRollover()) { altIcon = (Icon) b.getRolloverIcon(); } if(altIcon == null) { altIcon = b.getIcon(); } altIcon.paintIcon(c, g, iconRect.x, iconRect.y); } else { getDefaultIcon().paintIcon(c, g, iconRect.x, iconRect.y); } // Draw the Text if(text != null) { View v = (View) c.getClientProperty(BasicHTML.propertyKey); if (v != null) { v.paint(g, textRect); } else { int mnemIndex = b.getDisplayedMnemonicIndex(); if(model.isEnabled()) { // *** paint the text normally g.setColor(b.getForeground()); } else { // *** paint the text disabled g.setColor(getDisabledTextColor()); } SwingUtilities2.drawStringUnderlineCharAt(c,g,text, mnemIndex, textRect.x, textRect.y + fm.getAscent()); } if(b.hasFocus() && b.isFocusPainted() && textRect.width > 0 && textRect.height > 0 ) { paintFocus(g,textRect,size); } } } protected void paintFocus(Graphics g, Rectangle t, Dimension d){ g.setColor(getFocusColor()); g.drawRect(t.x-1, t.y-1, t.width+1, t.height+1); } }
Java
/* * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.*; import javax.swing.plaf.UIResource; import java.awt.*; import java.awt.image.BufferedImage; import java.io.Serializable; import java.util.Enumeration; import java.util.Vector; import sun.swing.CachedPainter; /** {@collect.stats} * Factory object that vends <code>Icon</code>s for * the Java<sup><font size="-2">TM</font></sup> look and feel (Metal). * These icons are used extensively in Metal via the defaults mechanism. * While other look and feels often use GIFs for icons, creating icons * in code facilitates switching to other themes. * * <p> * Each method in this class returns * either an <code>Icon</code> or <code>null</code>, * where <code>null</code> implies that there is no default icon. * * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Michael C. Albers */ public class MetalIconFactory implements Serializable { // List of code-drawn Icons private static Icon fileChooserDetailViewIcon; private static Icon fileChooserHomeFolderIcon; private static Icon fileChooserListViewIcon; private static Icon fileChooserNewFolderIcon; private static Icon fileChooserUpFolderIcon; private static Icon internalFrameAltMaximizeIcon; private static Icon internalFrameCloseIcon; private static Icon internalFrameDefaultMenuIcon; private static Icon internalFrameMaximizeIcon; private static Icon internalFrameMinimizeIcon; private static Icon radioButtonIcon; private static Icon treeComputerIcon; private static Icon treeFloppyDriveIcon; private static Icon treeHardDriveIcon; private static Icon menuArrowIcon; private static Icon menuItemArrowIcon; private static Icon checkBoxMenuItemIcon; private static Icon radioButtonMenuItemIcon; private static Icon checkBoxIcon; // Ocean icons private static Icon oceanHorizontalSliderThumb; private static Icon oceanVerticalSliderThumb; // Constants public static final boolean DARK = false; public static final boolean LIGHT = true; // Accessor functions for Icons. Does the caching work. public static Icon getFileChooserDetailViewIcon() { if (fileChooserDetailViewIcon == null) { fileChooserDetailViewIcon = new FileChooserDetailViewIcon(); } return fileChooserDetailViewIcon; } public static Icon getFileChooserHomeFolderIcon() { if (fileChooserHomeFolderIcon == null) { fileChooserHomeFolderIcon = new FileChooserHomeFolderIcon(); } return fileChooserHomeFolderIcon; } public static Icon getFileChooserListViewIcon() { if (fileChooserListViewIcon == null) { fileChooserListViewIcon = new FileChooserListViewIcon(); } return fileChooserListViewIcon; } public static Icon getFileChooserNewFolderIcon() { if (fileChooserNewFolderIcon == null) { fileChooserNewFolderIcon = new FileChooserNewFolderIcon(); } return fileChooserNewFolderIcon; } public static Icon getFileChooserUpFolderIcon() { if (fileChooserUpFolderIcon == null) { fileChooserUpFolderIcon = new FileChooserUpFolderIcon(); } return fileChooserUpFolderIcon; } public static Icon getInternalFrameAltMaximizeIcon(int size) { return new InternalFrameAltMaximizeIcon(size); } public static Icon getInternalFrameCloseIcon(int size) { return new InternalFrameCloseIcon(size); } public static Icon getInternalFrameDefaultMenuIcon() { if (internalFrameDefaultMenuIcon == null) { internalFrameDefaultMenuIcon = new InternalFrameDefaultMenuIcon(); } return internalFrameDefaultMenuIcon; } public static Icon getInternalFrameMaximizeIcon(int size) { return new InternalFrameMaximizeIcon(size); } public static Icon getInternalFrameMinimizeIcon(int size) { return new InternalFrameMinimizeIcon(size); } public static Icon getRadioButtonIcon() { if (radioButtonIcon == null) { radioButtonIcon = new RadioButtonIcon(); } return radioButtonIcon; } /** {@collect.stats} * Returns a checkbox icon. * @since 1.3 */ public static Icon getCheckBoxIcon() { if (checkBoxIcon == null) { checkBoxIcon = new CheckBoxIcon(); } return checkBoxIcon; } public static Icon getTreeComputerIcon() { if ( treeComputerIcon == null ) { treeComputerIcon = new TreeComputerIcon(); } return treeComputerIcon; } public static Icon getTreeFloppyDriveIcon() { if ( treeFloppyDriveIcon == null ) { treeFloppyDriveIcon = new TreeFloppyDriveIcon(); } return treeFloppyDriveIcon; } public static Icon getTreeFolderIcon() { return new TreeFolderIcon(); } public static Icon getTreeHardDriveIcon() { if ( treeHardDriveIcon == null ) { treeHardDriveIcon = new TreeHardDriveIcon(); } return treeHardDriveIcon; } public static Icon getTreeLeafIcon() { return new TreeLeafIcon(); } public static Icon getTreeControlIcon( boolean isCollapsed ) { return new TreeControlIcon( isCollapsed ); } public static Icon getMenuArrowIcon() { if (menuArrowIcon == null) { menuArrowIcon = new MenuArrowIcon(); } return menuArrowIcon; } /** {@collect.stats} * Returns an icon to be used by <code>JCheckBoxMenuItem</code>. * * @return the default icon for check box menu items, * or <code>null</code> if no default exists */ public static Icon getMenuItemCheckIcon() { return null; } public static Icon getMenuItemArrowIcon() { if (menuItemArrowIcon == null) { menuItemArrowIcon = new MenuItemArrowIcon(); } return menuItemArrowIcon; } public static Icon getCheckBoxMenuItemIcon() { if (checkBoxMenuItemIcon == null) { checkBoxMenuItemIcon = new CheckBoxMenuItemIcon(); } return checkBoxMenuItemIcon; } public static Icon getRadioButtonMenuItemIcon() { if (radioButtonMenuItemIcon == null) { radioButtonMenuItemIcon = new RadioButtonMenuItemIcon(); } return radioButtonMenuItemIcon; } public static Icon getHorizontalSliderThumbIcon() { if (MetalLookAndFeel.usingOcean()) { if (oceanHorizontalSliderThumb == null) { oceanHorizontalSliderThumb = new OceanHorizontalSliderThumbIcon(); } return oceanHorizontalSliderThumb; } // don't cache these, bumps don't get updated otherwise return new HorizontalSliderThumbIcon(); } public static Icon getVerticalSliderThumbIcon() { if (MetalLookAndFeel.usingOcean()) { if (oceanVerticalSliderThumb == null) { oceanVerticalSliderThumb = new OceanVerticalSliderThumbIcon(); } return oceanVerticalSliderThumb; } // don't cache these, bumps don't get updated otherwise return new VerticalSliderThumbIcon(); } // File Chooser Detail View code private static class FileChooserDetailViewIcon implements Icon, UIResource, Serializable { public void paintIcon(Component c, Graphics g, int x, int y) { g.translate(x, y); // Draw outside edge of each of the documents g.setColor(MetalLookAndFeel.getPrimaryControlInfo()); // top g.drawLine(2,2, 5,2); // top g.drawLine(2,3, 2,7); // left g.drawLine(3,7, 6,7); // bottom g.drawLine(6,6, 6,3); // right // bottom g.drawLine(2,10, 5,10); // top g.drawLine(2,11, 2,15); // left g.drawLine(3,15, 6,15); // bottom g.drawLine(6,14, 6,11); // right // Draw little dots next to documents // Same color as outside edge g.drawLine(8,5, 15,5); // top g.drawLine(8,13, 15,13); // bottom // Draw inner highlight on documents g.setColor(MetalLookAndFeel.getPrimaryControl()); g.drawRect(3,3, 2,3); // top g.drawRect(3,11, 2,3); // bottom // Draw inner inner highlight on documents g.setColor(MetalLookAndFeel.getPrimaryControlHighlight()); g.drawLine(4,4, 4,5); // top g.drawLine(4,12, 4,13); // bottom g.translate(-x, -y); } public int getIconWidth() { return 18; } public int getIconHeight() { return 18; } } // End class FileChooserDetailViewIcon // File Chooser Home Folder code private static class FileChooserHomeFolderIcon implements Icon, UIResource, Serializable { public void paintIcon(Component c, Graphics g, int x, int y) { g.translate(x, y); // Draw outside edge of house g.setColor(MetalLookAndFeel.getPrimaryControlInfo()); g.drawLine(8,1, 1,8); // left edge of roof g.drawLine(8,1, 15,8); // right edge of roof g.drawLine(11,2, 11,3); // left edge of chimney g.drawLine(12,2, 12,4); // right edge of chimney g.drawLine(3,7, 3,15); // left edge of house g.drawLine(13,7, 13,15); // right edge of house g.drawLine(4,15, 12,15); // bottom edge of house // Draw door frame // same color as edge of house g.drawLine( 6,9, 6,14); // left g.drawLine(10,9, 10,14); // right g.drawLine( 7,9, 9, 9); // top // Draw roof body g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.fillRect(8,2, 1,1); //top toward bottom g.fillRect(7,3, 3,1); g.fillRect(6,4, 5,1); g.fillRect(5,5, 7,1); g.fillRect(4,6, 9,2); // Draw doornob // same color as roof body g.drawLine(9,12, 9,12); // Paint the house g.setColor(MetalLookAndFeel.getPrimaryControl()); g.drawLine(4,8, 12,8); // above door g.fillRect(4,9, 2,6); // left of door g.fillRect(11,9, 2,6); // right of door g.translate(-x, -y); } public int getIconWidth() { return 18; } public int getIconHeight() { return 18; } } // End class FileChooserHomeFolderIcon // File Chooser List View code private static class FileChooserListViewIcon implements Icon, UIResource, Serializable { public void paintIcon(Component c, Graphics g, int x, int y) { g.translate(x, y); // Draw outside edge of each of the documents g.setColor(MetalLookAndFeel.getPrimaryControlInfo()); // top left g.drawLine(2,2, 5,2); // top g.drawLine(2,3, 2,7); // left g.drawLine(3,7, 6,7); // bottom g.drawLine(6,6, 6,3); // right // top right g.drawLine(10,2, 13,2); // top g.drawLine(10,3, 10,7); // left g.drawLine(11,7, 14,7); // bottom g.drawLine(14,6, 14,3); // right // bottom left g.drawLine(2,10, 5,10); // top g.drawLine(2,11, 2,15); // left g.drawLine(3,15, 6,15); // bottom g.drawLine(6,14, 6,11); // right // bottom right g.drawLine(10,10, 13,10); // top g.drawLine(10,11, 10,15); // left g.drawLine(11,15, 14,15); // bottom g.drawLine(14,14, 14,11); // right // Draw little dots next to documents // Same color as outside edge g.drawLine(8,5, 8,5); // top left g.drawLine(16,5, 16,5); // top right g.drawLine(8,13, 8,13); // bottom left g.drawLine(16,13, 16,13); // bottom right // Draw inner highlight on documents g.setColor(MetalLookAndFeel.getPrimaryControl()); g.drawRect(3,3, 2,3); // top left g.drawRect(11,3, 2,3); // top right g.drawRect(3,11, 2,3); // bottom left g.drawRect(11,11, 2,3); // bottom right // Draw inner inner highlight on documents g.setColor(MetalLookAndFeel.getPrimaryControlHighlight()); g.drawLine(4,4, 4,5); // top left g.drawLine(12,4, 12,5); // top right g.drawLine(4,12, 4,13); // bottom left g.drawLine(12,12, 12,13); // bottom right g.translate(-x, -y); } public int getIconWidth() { return 18; } public int getIconHeight() { return 18; } } // End class FileChooserListViewIcon // File Chooser New Folder code private static class FileChooserNewFolderIcon implements Icon, UIResource, Serializable { public void paintIcon(Component c, Graphics g, int x, int y) { g.translate(x, y); // Fill background g.setColor(MetalLookAndFeel.getPrimaryControl()); g.fillRect(3,5, 12,9); // Draw outside edge of folder g.setColor(MetalLookAndFeel.getPrimaryControlInfo()); g.drawLine(1,6, 1,14); // left g.drawLine(2,14, 15,14); // bottom g.drawLine(15,13, 15,5); // right g.drawLine(2,5, 9,5); // top left g.drawLine(10,6, 14,6); // top right // Draw inner folder highlight g.setColor(MetalLookAndFeel.getPrimaryControlHighlight()); g.drawLine( 2,6, 2,13); // left g.drawLine( 3,6, 9,6); // top left g.drawLine(10,7, 14,7); // top right // Draw tab on folder g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); g.drawLine(11,3, 15,3); // top g.drawLine(10,4, 15,4); // bottom g.translate(-x, -y); } public int getIconWidth() { return 18; } public int getIconHeight() { return 18; } } // End class FileChooserNewFolderIcon // File Chooser Up Folder code private static class FileChooserUpFolderIcon implements Icon, UIResource, Serializable { public void paintIcon(Component c, Graphics g, int x, int y) { g.translate(x, y); // Fill background g.setColor(MetalLookAndFeel.getPrimaryControl()); g.fillRect(3,5, 12,9); // Draw outside edge of folder g.setColor(MetalLookAndFeel.getPrimaryControlInfo()); g.drawLine(1,6, 1,14); // left g.drawLine(2,14, 15,14); // bottom g.drawLine(15,13, 15,5); // right g.drawLine(2,5, 9,5); // top left g.drawLine(10,6, 14,6); // top right // Draw the UP arrow // same color as edge g.drawLine(8,13, 8,16); // arrow shaft g.drawLine(8, 9, 8, 9); // arrowhead top g.drawLine(7,10, 9,10); g.drawLine(6,11, 10,11); g.drawLine(5,12, 11,12); // Draw inner folder highlight g.setColor(MetalLookAndFeel.getPrimaryControlHighlight()); g.drawLine( 2,6, 2,13); // left g.drawLine( 3,6, 9,6); // top left g.drawLine(10,7, 14,7); // top right // Draw tab on folder g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); g.drawLine(11,3, 15,3); // top g.drawLine(10,4, 15,4); // bottom g.translate(-x, -y); } public int getIconWidth() { return 18; } public int getIconHeight() { return 18; } } // End class FileChooserUpFolderIcon /** {@collect.stats} * Defines an icon for Palette close * @since 1.3 */ public static class PaletteCloseIcon implements Icon, UIResource, Serializable{ int iconSize = 7; public void paintIcon(Component c, Graphics g, int x, int y) { JButton parentButton = (JButton)c; ButtonModel buttonModel = parentButton.getModel(); Color back; Color highlight = MetalLookAndFeel.getPrimaryControlHighlight(); Color shadow = MetalLookAndFeel.getPrimaryControlInfo(); if (buttonModel.isPressed() && buttonModel.isArmed()) { back = shadow; } else { back = MetalLookAndFeel.getPrimaryControlDarkShadow(); } g.translate(x, y); g.setColor(back); g.drawLine( 0, 1, 5, 6); g.drawLine( 1, 0, 6, 5); g.drawLine( 1, 1, 6, 6); g.drawLine( 6, 1, 1, 6); g.drawLine( 5,0, 0,5); g.drawLine(5,1, 1,5); g.setColor(highlight); g.drawLine(6,2, 5,3); g.drawLine(2,6, 3, 5); g.drawLine(6,6,6,6); g.translate(-x, -y); } public int getIconWidth() { return iconSize; } public int getIconHeight() { return iconSize; } } // Internal Frame Close code private static class InternalFrameCloseIcon implements Icon, UIResource, Serializable { int iconSize = 16; public InternalFrameCloseIcon(int size) { iconSize = size; } public void paintIcon(Component c, Graphics g, int x, int y) { JButton parentButton = (JButton)c; ButtonModel buttonModel = parentButton.getModel(); Color backgroundColor = MetalLookAndFeel.getPrimaryControl(); Color internalBackgroundColor = MetalLookAndFeel.getPrimaryControl(); Color mainItemColor = MetalLookAndFeel.getPrimaryControlDarkShadow(); Color darkHighlightColor = MetalLookAndFeel.getBlack(); Color xLightHighlightColor = MetalLookAndFeel.getWhite(); Color boxLightHighlightColor = MetalLookAndFeel.getWhite(); // if the inactive window if (parentButton.getClientProperty("paintActive") != Boolean.TRUE) { backgroundColor = MetalLookAndFeel.getControl(); internalBackgroundColor = backgroundColor; mainItemColor = MetalLookAndFeel.getControlDarkShadow(); // if inactive and pressed if (buttonModel.isPressed() && buttonModel.isArmed()) { internalBackgroundColor = MetalLookAndFeel.getControlShadow(); xLightHighlightColor = internalBackgroundColor; mainItemColor = darkHighlightColor; } } // if pressed else if (buttonModel.isPressed() && buttonModel.isArmed()) { internalBackgroundColor = MetalLookAndFeel.getPrimaryControlShadow(); xLightHighlightColor = internalBackgroundColor; mainItemColor = darkHighlightColor; // darkHighlightColor is still "getBlack()" } // Some calculations that are needed more than once later on. int oneHalf = (int)(iconSize / 2); // 16 -> 8 g.translate(x, y); // fill background g.setColor(backgroundColor); g.fillRect(0,0, iconSize,iconSize); // fill inside of box area g.setColor(internalBackgroundColor); g.fillRect(3,3, iconSize-6,iconSize-6); // THE BOX // the top/left dark higlight - some of this will get overwritten g.setColor(darkHighlightColor); g.drawRect(1,1, iconSize-3,iconSize-3); // draw the inside bottom/right highlight g.drawRect(2,2, iconSize-5,iconSize-5); // draw the light/outside, bottom/right highlight g.setColor(boxLightHighlightColor); g.drawRect(2,2, iconSize-3,iconSize-3); // draw the "normal" box g.setColor(mainItemColor); g.drawRect(2,2, iconSize-4,iconSize-4); g.drawLine(3,iconSize-3, 3,iconSize-3); // lower left g.drawLine(iconSize-3,3, iconSize-3,3); // up right // THE "X" // Dark highlight g.setColor(darkHighlightColor); g.drawLine(4,5, 5,4); // far up left g.drawLine(4,iconSize-6, iconSize-6,4); // against body of "X" // Light highlight g.setColor(xLightHighlightColor); g.drawLine(6,iconSize-5, iconSize-5,6); // against body of "X" // one pixel over from the body g.drawLine(oneHalf,oneHalf+2, oneHalf+2,oneHalf); // bottom right g.drawLine(iconSize-5,iconSize-5, iconSize-4,iconSize-5); g.drawLine(iconSize-5,iconSize-4, iconSize-5,iconSize-4); // Main color g.setColor(mainItemColor); // Upper left to lower right g.drawLine(5,5, iconSize-6,iconSize-6); // g.drawLine(5,5, 10,10); g.drawLine(6,5, iconSize-5,iconSize-6); // g.drawLine(6,5, 11,10); g.drawLine(5,6, iconSize-6,iconSize-5); // g.drawLine(5,6, 10,11); // Lower left to upper right g.drawLine(5,iconSize-5, iconSize-5,5); // g.drawLine(5,11, 11,5); g.drawLine(5,iconSize-6, iconSize-6,5); // g.drawLine(5,10, 10,5); g.translate(-x, -y); } public int getIconWidth() { return iconSize; } public int getIconHeight() { return iconSize; } } // End class InternalFrameCloseIcon // Internal Frame Alternate Maximize code (actually, the un-maximize icon) private static class InternalFrameAltMaximizeIcon implements Icon, UIResource, Serializable { int iconSize = 16; public InternalFrameAltMaximizeIcon(int size) { iconSize = size; } public void paintIcon(Component c, Graphics g, int x, int y) { JButton parentButton = (JButton)c; ButtonModel buttonModel = parentButton.getModel(); Color backgroundColor = MetalLookAndFeel.getPrimaryControl(); Color internalBackgroundColor = MetalLookAndFeel.getPrimaryControl(); Color mainItemColor = MetalLookAndFeel.getPrimaryControlDarkShadow(); Color darkHighlightColor = MetalLookAndFeel.getBlack(); // ul = Upper Left and lr = Lower Right Color ulLightHighlightColor = MetalLookAndFeel.getWhite(); Color lrLightHighlightColor = MetalLookAndFeel.getWhite(); // if the internal frame is inactive if (parentButton.getClientProperty("paintActive") != Boolean.TRUE) { backgroundColor = MetalLookAndFeel.getControl(); internalBackgroundColor = backgroundColor; mainItemColor = MetalLookAndFeel.getControlDarkShadow(); // if inactive and pressed if (buttonModel.isPressed() && buttonModel.isArmed()) { internalBackgroundColor = MetalLookAndFeel.getControlShadow(); ulLightHighlightColor = internalBackgroundColor; mainItemColor = darkHighlightColor; } } // if the button is pressed and the mouse is over it else if (buttonModel.isPressed() && buttonModel.isArmed()) { internalBackgroundColor = MetalLookAndFeel.getPrimaryControlShadow(); ulLightHighlightColor = internalBackgroundColor; mainItemColor = darkHighlightColor; // darkHighlightColor is still "getBlack()" } g.translate(x, y); // fill background g.setColor(backgroundColor); g.fillRect(0,0, iconSize,iconSize); // BOX // fill inside the box g.setColor(internalBackgroundColor); g.fillRect(3,6, iconSize-9,iconSize-9); // draw dark highlight color g.setColor(darkHighlightColor); g.drawRect(1,5, iconSize-8,iconSize-8); g.drawLine(1,iconSize-2, 1,iconSize-2); // extra pixel on bottom // draw lower right light highlight g.setColor(lrLightHighlightColor); g.drawRect(2,6, iconSize-7,iconSize-7); // draw upper left light highlight g.setColor(ulLightHighlightColor); g.drawRect(3,7, iconSize-9,iconSize-9); // draw the main box g.setColor(mainItemColor); g.drawRect(2,6, iconSize-8,iconSize-8); // Six extraneous pixels to deal with g.setColor(ulLightHighlightColor); g.drawLine(iconSize-6,8,iconSize-6,8); g.drawLine(iconSize-9,6, iconSize-7,8); g.setColor(mainItemColor); g.drawLine(3,iconSize-3,3,iconSize-3); g.setColor(darkHighlightColor); g.drawLine(iconSize-6,9,iconSize-6,9); g.setColor(backgroundColor); g.drawLine(iconSize-9,5,iconSize-9,5); // ARROW // do the shaft first g.setColor(mainItemColor); g.fillRect(iconSize-7,3, 3,5); // do a big block g.drawLine(iconSize-6,5, iconSize-3,2); // top shaft g.drawLine(iconSize-6,6, iconSize-2,2); // bottom shaft g.drawLine(iconSize-6,7, iconSize-3,7); // bottom arrow head // draw the dark highlight g.setColor(darkHighlightColor); g.drawLine(iconSize-8,2, iconSize-7,2); // top of arrowhead g.drawLine(iconSize-8,3, iconSize-8,7); // left of arrowhead g.drawLine(iconSize-6,4, iconSize-3,1); // top of shaft g.drawLine(iconSize-4,6, iconSize-3,6); // top,right of arrowhead // draw the light highlight g.setColor(lrLightHighlightColor); g.drawLine(iconSize-6,3, iconSize-6,3); // top g.drawLine(iconSize-4,5, iconSize-2,3); // under shaft g.drawLine(iconSize-4,8, iconSize-3,8); // under arrowhead g.drawLine(iconSize-2,8, iconSize-2,7); // right of arrowhead g.translate(-x, -y); } public int getIconWidth() { return iconSize; } public int getIconHeight() { return iconSize; } } // End class InternalFrameAltMaximizeIcon // Code for the default icons that goes in the upper left corner private static class InternalFrameDefaultMenuIcon implements Icon, UIResource, Serializable { public void paintIcon(Component c, Graphics g, int x, int y) { Color windowBodyColor = MetalLookAndFeel.getWindowBackground(); Color titleColor = MetalLookAndFeel.getPrimaryControl(); Color edgeColor = MetalLookAndFeel.getPrimaryControlDarkShadow(); g.translate(x, y); // draw background color for title area // catch four corners and title area g.setColor(titleColor); g.fillRect(0,0, 16,16); // fill body of window g.setColor(windowBodyColor); g.fillRect(2,6, 13,9); // draw light parts of two "bumps" g.drawLine(2,2, 2,2); g.drawLine(5,2, 5,2); g.drawLine(8,2, 8,2); g.drawLine(11,2, 11,2); // draw line around edge of title and icon g.setColor(edgeColor); g.drawRect(1,1, 13,13); // entire inner edge g.drawLine(1,0, 14,0); // top outter edge g.drawLine(15,1, 15,14); // right outter edge g.drawLine(1,15, 14,15); // bottom outter edge g.drawLine(0,1, 0,14); // left outter edge g.drawLine(2,5, 13,5); // bottom of title bar area // draw dark part of four "bumps" (same color) g.drawLine(3,3, 3,3); g.drawLine(6,3, 6,3); g.drawLine(9,3, 9,3); g.drawLine(12,3, 12,3); g.translate(-x, -y); } public int getIconWidth() { return 16; } public int getIconHeight() { return 16; } } // End class InternalFrameDefaultMenuIcon // Internal Frame Maximize code private static class InternalFrameMaximizeIcon implements Icon, UIResource, Serializable { protected int iconSize = 16; public InternalFrameMaximizeIcon(int size) { iconSize = size; } public void paintIcon(Component c, Graphics g, int x, int y) { JButton parentButton = (JButton)c; ButtonModel buttonModel = parentButton.getModel(); Color backgroundColor = MetalLookAndFeel.getPrimaryControl(); Color internalBackgroundColor = MetalLookAndFeel.getPrimaryControl(); Color mainItemColor = MetalLookAndFeel.getPrimaryControlDarkShadow(); Color darkHighlightColor = MetalLookAndFeel.getBlack(); // ul = Upper Left and lr = Lower Right Color ulLightHighlightColor = MetalLookAndFeel.getWhite(); Color lrLightHighlightColor = MetalLookAndFeel.getWhite(); // if the internal frame is inactive if (parentButton.getClientProperty("paintActive") != Boolean.TRUE) { backgroundColor = MetalLookAndFeel.getControl(); internalBackgroundColor = backgroundColor; mainItemColor = MetalLookAndFeel.getControlDarkShadow(); // if inactive and pressed if (buttonModel.isPressed() && buttonModel.isArmed()) { internalBackgroundColor = MetalLookAndFeel.getControlShadow(); ulLightHighlightColor = internalBackgroundColor; mainItemColor = darkHighlightColor; } } // if the button is pressed and the mouse is over it else if (buttonModel.isPressed() && buttonModel.isArmed()) { internalBackgroundColor = MetalLookAndFeel.getPrimaryControlShadow(); ulLightHighlightColor = internalBackgroundColor; mainItemColor = darkHighlightColor; // darkHighlightColor is still "getBlack()" } g.translate(x, y); // fill background g.setColor(backgroundColor); g.fillRect(0,0, iconSize,iconSize); // BOX drawing // fill inside the box g.setColor(internalBackgroundColor); g.fillRect(3,7, iconSize-10,iconSize-10); // light highlight g.setColor(ulLightHighlightColor); g.drawRect(3,7, iconSize-10,iconSize-10); // up,left g.setColor(lrLightHighlightColor); g.drawRect(2,6, iconSize-7,iconSize-7); // low,right // dark highlight g.setColor(darkHighlightColor); g.drawRect(1,5, iconSize-7,iconSize-7); // outer g.drawRect(2,6, iconSize-9,iconSize-9); // inner // main box g.setColor(mainItemColor); g.drawRect(2,6, iconSize-8,iconSize-8); // g.drawRect(2,6, 8,8); // ARROW drawing // dark highlight g.setColor(darkHighlightColor); // down,left to up,right - inside box g.drawLine(3,iconSize-5, iconSize-9,7); // down,left to up,right - outside box g.drawLine(iconSize-6,4, iconSize-5,3); // outside edge of arrow head g.drawLine(iconSize-7,1, iconSize-7,2); // outside edge of arrow head g.drawLine(iconSize-6,1, iconSize-2,1); // light highlight g.setColor(ulLightHighlightColor); // down,left to up,right - inside box g.drawLine(5,iconSize-4, iconSize-8,9); g.setColor(lrLightHighlightColor); g.drawLine(iconSize-6,3, iconSize-4,5); // outside box g.drawLine(iconSize-4,5, iconSize-4,6); // one down from this g.drawLine(iconSize-2,7, iconSize-1,7); // outside edge arrow head g.drawLine(iconSize-1,2, iconSize-1,6); // outside edge arrow head // main part of arrow g.setColor(mainItemColor); g.drawLine(3,iconSize-4, iconSize-3,2); // top edge of staff g.drawLine(3,iconSize-3, iconSize-2,2); // bottom edge of staff g.drawLine(4,iconSize-3, 5,iconSize-3); // highlights inside of box g.drawLine(iconSize-7,8, iconSize-7,9); // highlights inside of box g.drawLine(iconSize-6,2, iconSize-4,2); // top of arrow head g.drawRect(iconSize-3,3, 1,3); // right of arrow head g.translate(-x, -y); } public int getIconWidth() { return iconSize; } public int getIconHeight() { return iconSize; } } // End class InternalFrameMaximizeIcon // Internal Frame Minimize code private static class InternalFrameMinimizeIcon implements Icon, UIResource, Serializable { int iconSize = 16; public InternalFrameMinimizeIcon(int size) { iconSize = size; } public void paintIcon(Component c, Graphics g, int x, int y) { JButton parentButton = (JButton)c; ButtonModel buttonModel = parentButton.getModel(); Color backgroundColor = MetalLookAndFeel.getPrimaryControl(); Color internalBackgroundColor = MetalLookAndFeel.getPrimaryControl(); Color mainItemColor = MetalLookAndFeel.getPrimaryControlDarkShadow(); Color darkHighlightColor = MetalLookAndFeel.getBlack(); // ul = Upper Left and lr = Lower Right Color ulLightHighlightColor = MetalLookAndFeel.getWhite(); Color lrLightHighlightColor = MetalLookAndFeel.getWhite(); // if the internal frame is inactive if (parentButton.getClientProperty("paintActive") != Boolean.TRUE) { backgroundColor = MetalLookAndFeel.getControl(); internalBackgroundColor = backgroundColor; mainItemColor = MetalLookAndFeel.getControlDarkShadow(); // if inactive and pressed if (buttonModel.isPressed() && buttonModel.isArmed()) { internalBackgroundColor = MetalLookAndFeel.getControlShadow(); ulLightHighlightColor = internalBackgroundColor; mainItemColor = darkHighlightColor; } } // if the button is pressed and the mouse is over it else if (buttonModel.isPressed() && buttonModel.isArmed()) { internalBackgroundColor = MetalLookAndFeel.getPrimaryControlShadow(); ulLightHighlightColor = internalBackgroundColor; mainItemColor = darkHighlightColor; // darkHighlightColor is still "getBlack()" } g.translate(x, y); // fill background g.setColor(backgroundColor); g.fillRect(0,0, iconSize,iconSize); // BOX drawing // fill inside the box g.setColor(internalBackgroundColor); g.fillRect(4,11, iconSize-13,iconSize-13); // light highlight g.setColor(lrLightHighlightColor); g.drawRect(2,10, iconSize-10,iconSize-11); // low,right g.setColor(ulLightHighlightColor); g.drawRect(3,10, iconSize-12,iconSize-12); // up,left // dark highlight g.setColor(darkHighlightColor); g.drawRect(1,8, iconSize-10,iconSize-10); // outer g.drawRect(2,9, iconSize-12,iconSize-12); // inner // main box g.setColor(mainItemColor); g.drawRect(2,9, iconSize-11,iconSize-11); g.drawLine(iconSize-10,10, iconSize-10,10); // up right highlight g.drawLine(3,iconSize-3, 3,iconSize-3); // low left highlight // ARROW // do the shaft first g.setColor(mainItemColor); g.fillRect(iconSize-7,3, 3,5); // do a big block g.drawLine(iconSize-6,5, iconSize-3,2); // top shaft g.drawLine(iconSize-6,6, iconSize-2,2); // bottom shaft g.drawLine(iconSize-6,7, iconSize-3,7); // bottom arrow head // draw the dark highlight g.setColor(darkHighlightColor); g.drawLine(iconSize-8,2, iconSize-7,2); // top of arrowhead g.drawLine(iconSize-8,3, iconSize-8,7); // left of arrowhead g.drawLine(iconSize-6,4, iconSize-3,1); // top of shaft g.drawLine(iconSize-4,6, iconSize-3,6); // top,right of arrowhead // draw the light highlight g.setColor(lrLightHighlightColor); g.drawLine(iconSize-6,3, iconSize-6,3); // top g.drawLine(iconSize-4,5, iconSize-2,3); // under shaft g.drawLine(iconSize-7,8, iconSize-3,8); // under arrowhead g.drawLine(iconSize-2,8, iconSize-2,7); // right of arrowhead g.translate(-x, -y); } public int getIconWidth() { return iconSize; } public int getIconHeight() { return iconSize; } } // End class InternalFrameMinimizeIcon private static class CheckBoxIcon implements Icon, UIResource, Serializable { protected int getControlSize() { return 13; } private void paintOceanIcon(Component c, Graphics g, int x, int y) { ButtonModel model = ((JCheckBox)c).getModel(); g.translate(x, y); int w = getIconWidth(); int h = getIconHeight(); if ( model.isEnabled() ) { if (model.isPressed() && model.isArmed()) { g.setColor(MetalLookAndFeel.getControlShadow()); g.fillRect(0, 0, w, h); g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.fillRect(0, 0, w, 2); g.fillRect(0, 2, 2, h - 2); g.fillRect(w - 1, 1, 1, h - 1); g.fillRect(1, h - 1, w - 2, 1); } else if (model.isRollover()) { MetalUtils.drawGradient(c, g, "CheckBox.gradient", 0, 0, w, h, true); g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 1, h - 1); g.setColor(MetalLookAndFeel.getPrimaryControl()); g.drawRect(1, 1, w - 3, h - 3); g.drawRect(2, 2, w - 5, h - 5); } else { MetalUtils.drawGradient(c, g, "CheckBox.gradient", 0, 0, w, h, true); g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 1, h - 1); } g.setColor( MetalLookAndFeel.getControlInfo() ); } else { g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 1, h - 1); } g.translate(-x, -y); if (model.isSelected()) { drawCheck(c,g,x,y); } } public void paintIcon(Component c, Graphics g, int x, int y) { if (MetalLookAndFeel.usingOcean()) { paintOceanIcon(c, g, x, y); return; } ButtonModel model = ((JCheckBox)c).getModel(); int controlSize = getControlSize(); if ( model.isEnabled() ) { if (model.isPressed() && model.isArmed()) { g.setColor( MetalLookAndFeel.getControlShadow() ); g.fillRect( x, y, controlSize-1, controlSize-1); MetalUtils.drawPressed3DBorder(g, x, y, controlSize, controlSize); } else { MetalUtils.drawFlush3DBorder(g, x, y, controlSize, controlSize); } g.setColor(c.getForeground()); } else { g.setColor( MetalLookAndFeel.getControlShadow() ); g.drawRect( x, y, controlSize-2, controlSize-2); } if (model.isSelected()) { drawCheck(c,g,x,y); } } protected void drawCheck(Component c, Graphics g, int x, int y) { int controlSize = getControlSize(); g.fillRect( x+3, y+5, 2, controlSize-8 ); g.drawLine( x+(controlSize-4), y+3, x+5, y+(controlSize-6) ); g.drawLine( x+(controlSize-4), y+4, x+5, y+(controlSize-5) ); } public int getIconWidth() { return getControlSize(); } public int getIconHeight() { return getControlSize(); } } // End class CheckBoxIcon // Radio button code private static class RadioButtonIcon implements Icon, UIResource, Serializable { public void paintOceanIcon(Component c, Graphics g, int x, int y) { ButtonModel model = ((JRadioButton)c).getModel(); boolean enabled = model.isEnabled(); boolean pressed = (enabled && model.isPressed() && model.isArmed()); boolean rollover = (enabled && model.isRollover()); g.translate(x, y); if (enabled && !pressed) { // PENDING: this isn't quite right, when we're sure it won't // change it needs to be cleaned. MetalUtils.drawGradient(c, g, "RadioButton.gradient", 1, 1, 10, 10, true); g.setColor(c.getBackground()); g.fillRect(1, 1, 1, 1); g.fillRect(10, 1, 1, 1); g.fillRect(1, 10, 1, 1); g.fillRect(10, 10, 1, 1); } else if (pressed || !enabled) { if (pressed) { g.setColor(MetalLookAndFeel.getPrimaryControl()); } else { g.setColor(MetalLookAndFeel.getControl()); } g.fillRect(2, 2, 8, 8); g.fillRect(4, 1, 4, 1); g.fillRect(4, 10, 4, 1); g.fillRect(1, 4, 1, 4); g.fillRect(10, 4, 1, 4); } // draw Dark Circle (start at top, go clockwise) if (!enabled) { g.setColor(MetalLookAndFeel.getInactiveControlTextColor()); } else { g.setColor(MetalLookAndFeel.getControlDarkShadow()); } g.drawLine( 4, 0, 7, 0); g.drawLine( 8, 1, 9, 1); g.drawLine(10, 2, 10, 3); g.drawLine(11, 4, 11, 7); g.drawLine(10, 8, 10, 9); g.drawLine( 9,10, 8,10); g.drawLine( 7,11, 4,11); g.drawLine( 3,10, 2,10); g.drawLine( 1, 9, 1, 8); g.drawLine( 0, 7, 0, 4); g.drawLine( 1, 3, 1, 2); g.drawLine( 2, 1, 3, 1); if (pressed) { g.fillRect(1, 4, 1, 4); g.fillRect(2, 2, 1, 2); g.fillRect(3, 2, 1, 1); g.fillRect(4, 1, 4, 1); } else if (rollover) { g.setColor(MetalLookAndFeel.getPrimaryControl()); g.fillRect(4, 1, 4, 2); g.fillRect(8, 2, 2, 2); g.fillRect(9, 4, 2, 4); g.fillRect(8, 8, 2, 2); g.fillRect(4, 9, 4, 2); g.fillRect(2, 8, 2, 2); g.fillRect(1, 4, 2, 4); g.fillRect(2, 2, 2, 2); } // selected dot if (model.isSelected()) { if (enabled) { g.setColor(MetalLookAndFeel.getControlInfo()); } else { g.setColor(MetalLookAndFeel.getControlDarkShadow()); } g.fillRect( 4, 4, 4, 4); g.drawLine( 4, 3, 7, 3); g.drawLine( 8, 4, 8, 7); g.drawLine( 7, 8, 4, 8); g.drawLine( 3, 7, 3, 4); } g.translate(-x, -y); } public void paintIcon(Component c, Graphics g, int x, int y) { if (MetalLookAndFeel.usingOcean()) { paintOceanIcon(c, g, x, y); return; } JRadioButton rb = (JRadioButton)c; ButtonModel model = rb.getModel(); boolean drawDot = model.isSelected(); Color background = c.getBackground(); Color dotColor = c.getForeground(); Color shadow = MetalLookAndFeel.getControlShadow(); Color darkCircle = MetalLookAndFeel.getControlDarkShadow(); Color whiteInnerLeftArc = MetalLookAndFeel.getControlHighlight(); Color whiteOuterRightArc = MetalLookAndFeel.getControlHighlight(); Color interiorColor = background; // Set up colors per RadioButtonModel condition if ( !model.isEnabled() ) { whiteInnerLeftArc = whiteOuterRightArc = background; darkCircle = dotColor = shadow; } else if (model.isPressed() && model.isArmed() ) { whiteInnerLeftArc = interiorColor = shadow; } g.translate(x, y); // fill interior g.setColor(interiorColor); g.fillRect(2,2, 9,9); // draw Dark Circle (start at top, go clockwise) g.setColor(darkCircle); g.drawLine( 4, 0, 7, 0); g.drawLine( 8, 1, 9, 1); g.drawLine(10, 2, 10, 3); g.drawLine(11, 4, 11, 7); g.drawLine(10, 8, 10, 9); g.drawLine( 9,10, 8,10); g.drawLine( 7,11, 4,11); g.drawLine( 3,10, 2,10); g.drawLine( 1, 9, 1, 8); g.drawLine( 0, 7, 0, 4); g.drawLine( 1, 3, 1, 2); g.drawLine( 2, 1, 3, 1); // draw Inner Left (usually) White Arc // start at lower left corner, go clockwise g.setColor(whiteInnerLeftArc); g.drawLine( 2, 9, 2, 8); g.drawLine( 1, 7, 1, 4); g.drawLine( 2, 2, 2, 3); g.drawLine( 2, 2, 3, 2); g.drawLine( 4, 1, 7, 1); g.drawLine( 8, 2, 9, 2); // draw Outer Right White Arc // start at upper right corner, go clockwise g.setColor(whiteOuterRightArc); g.drawLine(10, 1, 10, 1); g.drawLine(11, 2, 11, 3); g.drawLine(12, 4, 12, 7); g.drawLine(11, 8, 11, 9); g.drawLine(10,10, 10,10); g.drawLine( 9,11, 8,11); g.drawLine( 7,12, 4,12); g.drawLine( 3,11, 2,11); // selected dot if ( drawDot ) { g.setColor(dotColor); g.fillRect( 4, 4, 4, 4); g.drawLine( 4, 3, 7, 3); g.drawLine( 8, 4, 8, 7); g.drawLine( 7, 8, 4, 8); g.drawLine( 3, 7, 3, 4); } g.translate(-x, -y); } public int getIconWidth() { return 13; } public int getIconHeight() { return 13; } } // End class RadioButtonIcon // Tree Computer Icon code private static class TreeComputerIcon implements Icon, UIResource, Serializable { public void paintIcon(Component c, Graphics g, int x, int y) { g.translate(x, y); // Fill glass portion of monitor g.setColor(MetalLookAndFeel.getPrimaryControl()); g.fillRect(5,4, 6,4); // Draw outside edge of monitor g.setColor(MetalLookAndFeel.getPrimaryControlInfo()); g.drawLine( 2,2, 2,8); // left g.drawLine(13,2, 13,8); // right g.drawLine( 3,1, 12,1); // top g.drawLine(12,9, 12,9); // bottom right base g.drawLine( 3,9, 3,9); // bottom left base // Draw the edge of the glass g.drawLine( 4,4, 4,7); // left g.drawLine( 5,3, 10,3); // top g.drawLine(11,4, 11,7); // right g.drawLine( 5,8, 10,8); // bottom // Draw the edge of the CPU g.drawLine( 1,10, 14,10); // top g.drawLine(14,10, 14,14); // right g.drawLine( 1,14, 14,14); // bottom g.drawLine( 1,10, 1,14); // left // Draw the disk drives g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawLine( 6,12, 8,12); // left g.drawLine(10,12, 12,12); // right g.translate(-x, -y); } public int getIconWidth() { return 16; } public int getIconHeight() { return 16; } } // End class TreeComputerIcon // Tree HardDrive Icon code private static class TreeHardDriveIcon implements Icon, UIResource, Serializable { public void paintIcon(Component c, Graphics g, int x, int y) { g.translate(x, y); // Draw edges of the disks g.setColor(MetalLookAndFeel.getPrimaryControlInfo()); // top disk g.drawLine(1,4, 1,5); // left g.drawLine(2,3, 3,3); g.drawLine(4,2, 11,2); // top g.drawLine(12,3, 13,3); g.drawLine(14,4, 14,5); // right g.drawLine(12,6, 13,6); g.drawLine(4,7, 11,7); // bottom g.drawLine(2,6, 3,6); // middle disk g.drawLine(1,7, 1,8); // left g.drawLine(2,9, 3,9); g.drawLine(4,10, 11,10); // bottom g.drawLine(12,9, 13,9); g.drawLine(14,7, 14, 8); // right // bottom disk g.drawLine(1,10, 1,11); // left g.drawLine(2,12, 3,12); g.drawLine(4,13, 11,13); // bottom g.drawLine(12,12, 13,12); g.drawLine(14,10, 14,11); // right // Draw the down right shadows g.setColor(MetalLookAndFeel.getControlShadow()); // top disk g.drawLine(7,6, 7,6); g.drawLine(9,6, 9,6); g.drawLine(10,5, 10,5); g.drawLine(11,6, 11,6); g.drawLine(12,5, 13,5); g.drawLine(13,4, 13,4); // middle disk g.drawLine(7,9, 7,9); g.drawLine(9,9, 9,9); g.drawLine(10,8, 10,8); g.drawLine(11,9, 11,9); g.drawLine(12,8, 13,8); g.drawLine(13,7, 13,7); // bottom disk g.drawLine(7,12, 7,12); g.drawLine(9,12, 9,12); g.drawLine(10,11, 10,11); g.drawLine(11,12, 11,12); g.drawLine(12,11, 13,11); g.drawLine(13,10, 13,10); // Draw the up left highlight g.setColor(MetalLookAndFeel.getControlHighlight()); // top disk g.drawLine(4,3, 5,3); g.drawLine(7,3, 9,3); g.drawLine(11,3, 11,3); g.drawLine(2,4, 6,4); g.drawLine(8,4, 8,4); g.drawLine(2,5, 3,5); g.drawLine(4,6, 4,6); // middle disk g.drawLine(2,7, 3,7); g.drawLine(2,8, 3,8); g.drawLine(4,9, 4,9); // bottom disk g.drawLine(2,10, 3,10); g.drawLine(2,11, 3,11); g.drawLine(4,12, 4,12); g.translate(-x, -y); } public int getIconWidth() { return 16; } public int getIconHeight() { return 16; } } // End class TreeHardDriveIcon // Tree FloppyDrive Icon code private static class TreeFloppyDriveIcon implements Icon, UIResource, Serializable { public void paintIcon(Component c, Graphics g, int x, int y) { g.translate(x, y); // Fill body of floppy g.setColor(MetalLookAndFeel.getPrimaryControl()); g.fillRect(2,2, 12,12); // Draw outside edge of floppy g.setColor(MetalLookAndFeel.getPrimaryControlInfo()); g.drawLine( 1, 1, 13, 1); // top g.drawLine(14, 2, 14,14); // right g.drawLine( 1,14, 14,14); // bottom g.drawLine( 1, 1, 1,14); // left // Draw grey-ish highlights g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.fillRect(5,2, 6,5); // metal disk protector part g.drawLine(4,8, 11,8); // top of label g.drawLine(3,9, 3,13); // left of label g.drawLine(12,9, 12,13); // right of label // Draw label and exposed disk g.setColor(MetalLookAndFeel.getPrimaryControlHighlight()); g.fillRect(8,3, 2,3); // exposed disk g.fillRect(4,9, 8,5); // label // Draw text on label g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); g.drawLine(5,10, 9,10); g.drawLine(5,12, 8,12); g.translate(-x, -y); } public int getIconWidth() { return 16; } public int getIconHeight() { return 16; } } // End class TreeFloppyDriveIcon static private final Dimension folderIcon16Size = new Dimension( 16, 16 ); /** {@collect.stats} * Utility class for caching icon images. This is necessary because * we need a new image whenever we are rendering into a new * GraphicsConfiguration, but we do not want to keep recreating icon * images for GC's that we have already seen (for example, * dragging a window back and forth between monitors on a multimon * system, or drawing an icon to different Components that have different * GC's). * So now whenever we create a new icon image for a given GC, we * cache that image with the GC for later retrieval. */ static class ImageCacher { // PENDING: Replace this class with CachedPainter. Vector images = new Vector(1, 1); ImageGcPair currentImageGcPair; class ImageGcPair { Image image; GraphicsConfiguration gc; ImageGcPair(Image image, GraphicsConfiguration gc) { this.image = image; this.gc = gc; } boolean hasSameConfiguration(GraphicsConfiguration newGC) { if (((newGC != null) && (newGC.equals(gc))) || ((newGC == null) && (gc == null))) { return true; } return false; } } Image getImage(GraphicsConfiguration newGC) { if ((currentImageGcPair == null) || !(currentImageGcPair.hasSameConfiguration(newGC))) { Enumeration elements = images.elements(); while (elements.hasMoreElements()) { ImageGcPair imgGcPair = (ImageGcPair)elements.nextElement(); if (imgGcPair.hasSameConfiguration(newGC)) { currentImageGcPair = imgGcPair; return imgGcPair.image; } } return null; } return currentImageGcPair.image; } void cacheImage(Image image, GraphicsConfiguration gc) { ImageGcPair imgGcPair = new ImageGcPair(image, gc); images.addElement(imgGcPair); currentImageGcPair = imgGcPair; } } /** {@collect.stats} * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. */ public static class FolderIcon16 implements Icon, Serializable { ImageCacher imageCacher; public void paintIcon(Component c, Graphics g, int x, int y) { GraphicsConfiguration gc = c.getGraphicsConfiguration(); if (imageCacher == null) { imageCacher = new ImageCacher(); } Image image = imageCacher.getImage(gc); if (image == null) { if (gc != null) { image = gc.createCompatibleImage(getIconWidth(), getIconHeight(), Transparency.BITMASK); } else { image = new BufferedImage(getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB); } Graphics imageG = image.getGraphics(); paintMe(c,imageG); imageG.dispose(); imageCacher.cacheImage(image, gc); } g.drawImage(image, x, y+getShift(), null); } private void paintMe(Component c, Graphics g) { int right = folderIcon16Size.width - 1; int bottom = folderIcon16Size.height - 1; // Draw tab top g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() ); g.drawLine( right - 5, 3, right, 3 ); g.drawLine( right - 6, 4, right, 4 ); // Draw folder front g.setColor( MetalLookAndFeel.getPrimaryControl() ); g.fillRect( 2, 7, 13, 8 ); // Draw tab bottom g.setColor( MetalLookAndFeel.getPrimaryControlShadow() ); g.drawLine( right - 6, 5, right - 1, 5 ); // Draw outline g.setColor( MetalLookAndFeel.getPrimaryControlInfo() ); g.drawLine( 0, 6, 0, bottom ); // left side g.drawLine( 1, 5, right - 7, 5 ); // first part of top g.drawLine( right - 6, 6, right - 1, 6 ); // second part of top g.drawLine( right, 5, right, bottom ); // right side g.drawLine( 0, bottom, right, bottom ); // bottom // Draw highlight g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() ); g.drawLine( 1, 6, 1, bottom - 1 ); g.drawLine( 1, 6, right - 7, 6 ); g.drawLine( right - 6, 7, right - 1, 7 ); } public int getShift() { return 0; } public int getAdditionalHeight() { return 0; } public int getIconWidth() { return folderIcon16Size.width; } public int getIconHeight() { return folderIcon16Size.height + getAdditionalHeight(); } } /** {@collect.stats} * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. */ public static class TreeFolderIcon extends FolderIcon16 { public int getShift() { return -1; } public int getAdditionalHeight() { return 2; } } static private final Dimension fileIcon16Size = new Dimension( 16, 16 ); /** {@collect.stats} * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. */ public static class FileIcon16 implements Icon, Serializable { ImageCacher imageCacher; public void paintIcon(Component c, Graphics g, int x, int y) { GraphicsConfiguration gc = c.getGraphicsConfiguration(); if (imageCacher == null) { imageCacher = new ImageCacher(); } Image image = imageCacher.getImage(gc); if (image == null) { if (gc != null) { image = gc.createCompatibleImage(getIconWidth(), getIconHeight(), Transparency.BITMASK); } else { image = new BufferedImage(getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB); } Graphics imageG = image.getGraphics(); paintMe(c,imageG); imageG.dispose(); imageCacher.cacheImage(image, gc); } g.drawImage(image, x, y+getShift(), null); } private void paintMe(Component c, Graphics g) { int right = fileIcon16Size.width - 1; int bottom = fileIcon16Size.height - 1; // Draw fill g.setColor( MetalLookAndFeel.getWindowBackground() ); g.fillRect( 4, 2, 9, 12 ); // Draw frame g.setColor( MetalLookAndFeel.getPrimaryControlInfo() ); g.drawLine( 2, 0, 2, bottom ); // left g.drawLine( 2, 0, right - 4, 0 ); // top g.drawLine( 2, bottom, right - 1, bottom ); // bottom g.drawLine( right - 1, 6, right - 1, bottom ); // right g.drawLine( right - 6, 2, right - 2, 6 ); // slant 1 g.drawLine( right - 5, 1, right - 4, 1 ); // part of slant 2 g.drawLine( right - 3, 2, right - 3, 3 ); // part of slant 2 g.drawLine( right - 2, 4, right - 2, 5 ); // part of slant 2 // Draw highlight g.setColor( MetalLookAndFeel.getPrimaryControl() ); g.drawLine( 3, 1, 3, bottom - 1 ); // left g.drawLine( 3, 1, right - 6, 1 ); // top g.drawLine( right - 2, 7, right - 2, bottom - 1 ); // right g.drawLine( right - 5, 2, right - 3, 4 ); // slant g.drawLine( 3, bottom - 1, right - 2, bottom - 1 ); // bottom } public int getShift() { return 0; } public int getAdditionalHeight() { return 0; } public int getIconWidth() { return fileIcon16Size.width; } public int getIconHeight() { return fileIcon16Size.height + getAdditionalHeight(); } } public static class TreeLeafIcon extends FileIcon16 { public int getShift() { return 2; } public int getAdditionalHeight() { return 4; } } static private final Dimension treeControlSize = new Dimension( 18, 18 ); /** {@collect.stats} * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. */ public static class TreeControlIcon implements Icon, Serializable { // This data member should not have been exposed. It's called // isLight, but now it really means isCollapsed. Since we can't change // any APIs... that's life. protected boolean isLight; public TreeControlIcon( boolean isCollapsed ) { isLight = isCollapsed; } ImageCacher imageCacher; transient boolean cachedOrientation = true; public void paintIcon(Component c, Graphics g, int x, int y) { GraphicsConfiguration gc = c.getGraphicsConfiguration(); if (imageCacher == null) { imageCacher = new ImageCacher(); } Image image = imageCacher.getImage(gc); if (image == null || cachedOrientation != MetalUtils.isLeftToRight(c)) { cachedOrientation = MetalUtils.isLeftToRight(c); if (gc != null) { image = gc.createCompatibleImage(getIconWidth(), getIconHeight(), Transparency.BITMASK); } else { image = new BufferedImage(getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB); } Graphics imageG = image.getGraphics(); paintMe(c,imageG,x,y); imageG.dispose(); imageCacher.cacheImage(image, gc); } if (MetalUtils.isLeftToRight(c)) { if (isLight) { // isCollapsed g.drawImage(image, x+5, y+3, x+18, y+13, 4,3, 17, 13, null); } else { g.drawImage(image, x+5, y+3, x+18, y+17, 4,3, 17, 17, null); } } else { if (isLight) { // isCollapsed g.drawImage(image, x+3, y+3, x+16, y+13, 4, 3, 17, 13, null); } else { g.drawImage(image, x+3, y+3, x+16, y+17, 4, 3, 17, 17, null); } } } public void paintMe(Component c, Graphics g, int x, int y) { g.setColor( MetalLookAndFeel.getPrimaryControlInfo() ); int xoff = (MetalUtils.isLeftToRight(c)) ? 0 : 4; // Draw circle g.drawLine( xoff + 4, 6, xoff + 4, 9 ); // left g.drawLine( xoff + 5, 5, xoff + 5, 5 ); // top left dot g.drawLine( xoff + 6, 4, xoff + 9, 4 ); // top g.drawLine( xoff + 10, 5, xoff + 10, 5 ); // top right dot g.drawLine( xoff + 11, 6, xoff + 11, 9 ); // right g.drawLine( xoff + 10, 10, xoff + 10, 10 ); // botom right dot g.drawLine( xoff + 6, 11, xoff + 9, 11 ); // bottom g.drawLine( xoff + 5, 10, xoff + 5, 10 ); // bottom left dot // Draw Center Dot g.drawLine( xoff + 7, 7, xoff + 8, 7 ); g.drawLine( xoff + 7, 8, xoff + 8, 8 ); // Draw Handle if ( isLight ) { // isCollapsed if( MetalUtils.isLeftToRight(c) ) { g.drawLine( 12, 7, 15, 7 ); g.drawLine( 12, 8, 15, 8 ); // g.setColor( c.getBackground() ); // g.drawLine( 16, 7, 16, 8 ); } else { g.drawLine(4, 7, 7, 7); g.drawLine(4, 8, 7, 8); } } else { g.drawLine( xoff + 7, 12, xoff + 7, 15 ); g.drawLine( xoff + 8, 12, xoff + 8, 15 ); // g.setColor( c.getBackground() ); // g.drawLine( xoff + 7, 16, xoff + 8, 16 ); } // Draw Fill g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() ); g.drawLine( xoff + 5, 6, xoff + 5, 9 ); // left shadow g.drawLine( xoff + 6, 5, xoff + 9, 5 ); // top shadow g.setColor( MetalLookAndFeel.getPrimaryControlShadow() ); g.drawLine( xoff + 6, 6, xoff + 6, 6 ); // top left fill g.drawLine( xoff + 9, 6, xoff + 9, 6 ); // top right fill g.drawLine( xoff + 6, 9, xoff + 6, 9 ); // bottom left fill g.drawLine( xoff + 10, 6, xoff + 10, 9 ); // right fill g.drawLine( xoff + 6, 10, xoff + 9, 10 ); // bottom fill g.setColor( MetalLookAndFeel.getPrimaryControl() ); g.drawLine( xoff + 6, 7, xoff + 6, 8 ); // left highlight g.drawLine( xoff + 7, 6, xoff + 8, 6 ); // top highlight g.drawLine( xoff + 9, 7, xoff + 9, 7 ); // right highlight g.drawLine( xoff + 7, 9, xoff + 7, 9 ); // bottom highlight g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() ); g.drawLine( xoff + 8, 9, xoff + 9, 9 ); g.drawLine( xoff + 9, 8, xoff + 9, 8 ); } public int getIconWidth() { return treeControlSize.width; } public int getIconHeight() { return treeControlSize.height; } } // // Menu Icons // static private final Dimension menuArrowIconSize = new Dimension( 4, 8 ); static private final Dimension menuCheckIconSize = new Dimension( 10, 10 ); static private final int xOff = 4; private static class MenuArrowIcon implements Icon, UIResource, Serializable { public void paintIcon( Component c, Graphics g, int x, int y ) { JMenuItem b = (JMenuItem) c; ButtonModel model = b.getModel(); g.translate( x, y ); if ( !model.isEnabled() ) { g.setColor( MetalLookAndFeel.getMenuDisabledForeground() ); } else { if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) ) { g.setColor( MetalLookAndFeel.getMenuSelectedForeground() ); } else { g.setColor( b.getForeground() ); } } if( MetalUtils.isLeftToRight(b) ) { g.drawLine( 0, 0, 0, 7 ); g.drawLine( 1, 1, 1, 6 ); g.drawLine( 2, 2, 2, 5 ); g.drawLine( 3, 3, 3, 4 ); } else { g.drawLine( 4, 0, 4, 7 ); g.drawLine( 3, 1, 3, 6 ); g.drawLine( 2, 2, 2, 5 ); g.drawLine( 1, 3, 1, 4 ); } g.translate( -x, -y ); } public int getIconWidth() { return menuArrowIconSize.width; } public int getIconHeight() { return menuArrowIconSize.height; } } // End class MenuArrowIcon private static class MenuItemArrowIcon implements Icon, UIResource, Serializable { public void paintIcon( Component c, Graphics g, int x, int y ) { } public int getIconWidth() { return menuArrowIconSize.width; } public int getIconHeight() { return menuArrowIconSize.height; } } // End class MenuItemArrowIcon private static class CheckBoxMenuItemIcon implements Icon, UIResource, Serializable { public void paintOceanIcon(Component c, Graphics g, int x, int y) { ButtonModel model = ((JMenuItem)c).getModel(); boolean isSelected = model.isSelected(); boolean isEnabled = model.isEnabled(); boolean isPressed = model.isPressed(); boolean isArmed = model.isArmed(); g.translate(x, y); if (isEnabled) { MetalUtils.drawGradient(c, g, "CheckBoxMenuItem.gradient", 1, 1, 7, 7, true); if (isPressed || isArmed) { g.setColor(MetalLookAndFeel.getControlInfo()); g.drawLine( 0, 0, 8, 0 ); g.drawLine( 0, 0, 0, 8 ); g.drawLine( 8, 2, 8, 8 ); g.drawLine( 2, 8, 8, 8 ); g.setColor(MetalLookAndFeel.getPrimaryControl()); g.drawLine( 9, 1, 9, 9 ); g.drawLine( 1, 9, 9, 9 ); } else { g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawLine( 0, 0, 8, 0 ); g.drawLine( 0, 0, 0, 8 ); g.drawLine( 8, 2, 8, 8 ); g.drawLine( 2, 8, 8, 8 ); g.setColor(MetalLookAndFeel.getControlHighlight()); g.drawLine( 9, 1, 9, 9 ); g.drawLine( 1, 9, 9, 9 ); } } else { g.setColor(MetalLookAndFeel.getMenuDisabledForeground()); g.drawRect( 0, 0, 8, 8 ); } if (isSelected) { if (isEnabled) { if (isArmed || ( c instanceof JMenu && isSelected)) { g.setColor( MetalLookAndFeel.getMenuSelectedForeground() ); } else { g.setColor(MetalLookAndFeel.getControlInfo()); } } else { g.setColor( MetalLookAndFeel.getMenuDisabledForeground()); } g.drawLine( 2, 2, 2, 6 ); g.drawLine( 3, 2, 3, 6 ); g.drawLine( 4, 4, 8, 0 ); g.drawLine( 4, 5, 9, 0 ); } g.translate( -x, -y ); } public void paintIcon( Component c, Graphics g, int x, int y ) { if (MetalLookAndFeel.usingOcean()) { paintOceanIcon(c, g, x, y); return; } JMenuItem b = (JMenuItem) c; ButtonModel model = b.getModel(); boolean isSelected = model.isSelected(); boolean isEnabled = model.isEnabled(); boolean isPressed = model.isPressed(); boolean isArmed = model.isArmed(); g.translate( x, y ); if ( isEnabled ) { if ( isPressed || isArmed ) { g.setColor( MetalLookAndFeel.getControlInfo() ); g.drawLine( 0, 0, 8, 0 ); g.drawLine( 0, 0, 0, 8 ); g.drawLine( 8, 2, 8, 8 ); g.drawLine( 2, 8, 8, 8 ); g.setColor( MetalLookAndFeel.getPrimaryControl() ); g.drawLine( 1, 1, 7, 1 ); g.drawLine( 1, 1, 1, 7 ); g.drawLine( 9, 1, 9, 9 ); g.drawLine( 1, 9, 9, 9 ); } else { g.setColor( MetalLookAndFeel.getControlDarkShadow() ); g.drawLine( 0, 0, 8, 0 ); g.drawLine( 0, 0, 0, 8 ); g.drawLine( 8, 2, 8, 8 ); g.drawLine( 2, 8, 8, 8 ); g.setColor( MetalLookAndFeel.getControlHighlight() ); g.drawLine( 1, 1, 7, 1 ); g.drawLine( 1, 1, 1, 7 ); g.drawLine( 9, 1, 9, 9 ); g.drawLine( 1, 9, 9, 9 ); } } else { g.setColor( MetalLookAndFeel.getMenuDisabledForeground() ); g.drawRect( 0, 0, 8, 8 ); } if ( isSelected ) { if ( isEnabled ) { if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) ) { g.setColor( MetalLookAndFeel.getMenuSelectedForeground() ); } else { g.setColor( b.getForeground() ); } } else { g.setColor( MetalLookAndFeel.getMenuDisabledForeground() ); } g.drawLine( 2, 2, 2, 6 ); g.drawLine( 3, 2, 3, 6 ); g.drawLine( 4, 4, 8, 0 ); g.drawLine( 4, 5, 9, 0 ); } g.translate( -x, -y ); } public int getIconWidth() { return menuCheckIconSize.width; } public int getIconHeight() { return menuCheckIconSize.height; } } // End class CheckBoxMenuItemIcon private static class RadioButtonMenuItemIcon implements Icon, UIResource, Serializable { public void paintOceanIcon(Component c, Graphics g, int x, int y) { ButtonModel model = ((JMenuItem)c).getModel(); boolean isSelected = model.isSelected(); boolean isEnabled = model.isEnabled(); boolean isPressed = model.isPressed(); boolean isArmed = model.isArmed(); g.translate( x, y ); if (isEnabled) { MetalUtils.drawGradient(c, g, "RadioButtonMenuItem.gradient", 1, 1, 7, 7, true); if (isPressed || isArmed) { g.setColor(MetalLookAndFeel.getPrimaryControl()); } else { g.setColor(MetalLookAndFeel.getControlHighlight()); } g.drawLine( 2, 9, 7, 9 ); g.drawLine( 9, 2, 9, 7 ); g.drawLine( 8, 8, 8, 8 ); if (isPressed || isArmed) { g.setColor(MetalLookAndFeel.getControlInfo()); } else { g.setColor(MetalLookAndFeel.getControlDarkShadow()); } } else { g.setColor( MetalLookAndFeel.getMenuDisabledForeground() ); } g.drawLine( 2, 0, 6, 0 ); g.drawLine( 2, 8, 6, 8 ); g.drawLine( 0, 2, 0, 6 ); g.drawLine( 8, 2, 8, 6 ); g.drawLine( 1, 1, 1, 1 ); g.drawLine( 7, 1, 7, 1 ); g.drawLine( 1, 7, 1, 7 ); g.drawLine( 7, 7, 7, 7 ); if (isSelected) { if (isEnabled) { if (isArmed || (c instanceof JMenu && model.isSelected())){ g.setColor(MetalLookAndFeel. getMenuSelectedForeground() ); } else { g.setColor(MetalLookAndFeel.getControlInfo()); } } else { g.setColor(MetalLookAndFeel.getMenuDisabledForeground()); } g.drawLine( 3, 2, 5, 2 ); g.drawLine( 2, 3, 6, 3 ); g.drawLine( 2, 4, 6, 4 ); g.drawLine( 2, 5, 6, 5 ); g.drawLine( 3, 6, 5, 6 ); } g.translate( -x, -y ); } public void paintIcon( Component c, Graphics g, int x, int y ) { if (MetalLookAndFeel.usingOcean()) { paintOceanIcon(c, g, x, y); return; } JMenuItem b = (JMenuItem) c; ButtonModel model = b.getModel(); boolean isSelected = model.isSelected(); boolean isEnabled = model.isEnabled(); boolean isPressed = model.isPressed(); boolean isArmed = model.isArmed(); g.translate( x, y ); if ( isEnabled ) { if ( isPressed || isArmed ) { g.setColor( MetalLookAndFeel.getPrimaryControl() ); g.drawLine( 3, 1, 8, 1 ); g.drawLine( 2, 9, 7, 9 ); g.drawLine( 1, 3, 1, 8 ); g.drawLine( 9, 2, 9, 7 ); g.drawLine( 2, 2, 2, 2 ); g.drawLine( 8, 8, 8, 8 ); g.setColor( MetalLookAndFeel.getControlInfo() ); g.drawLine( 2, 0, 6, 0 ); g.drawLine( 2, 8, 6, 8 ); g.drawLine( 0, 2, 0, 6 ); g.drawLine( 8, 2, 8, 6 ); g.drawLine( 1, 1, 1, 1 ); g.drawLine( 7, 1, 7, 1 ); g.drawLine( 1, 7, 1, 7 ); g.drawLine( 7, 7, 7, 7 ); } else { g.setColor( MetalLookAndFeel.getControlHighlight() ); g.drawLine( 3, 1, 8, 1 ); g.drawLine( 2, 9, 7, 9 ); g.drawLine( 1, 3, 1, 8 ); g.drawLine( 9, 2, 9, 7 ); g.drawLine( 2, 2, 2, 2 ); g.drawLine( 8, 8, 8, 8 ); g.setColor( MetalLookAndFeel.getControlDarkShadow() ); g.drawLine( 2, 0, 6, 0 ); g.drawLine( 2, 8, 6, 8 ); g.drawLine( 0, 2, 0, 6 ); g.drawLine( 8, 2, 8, 6 ); g.drawLine( 1, 1, 1, 1 ); g.drawLine( 7, 1, 7, 1 ); g.drawLine( 1, 7, 1, 7 ); g.drawLine( 7, 7, 7, 7 ); } } else { g.setColor( MetalLookAndFeel.getMenuDisabledForeground() ); g.drawLine( 2, 0, 6, 0 ); g.drawLine( 2, 8, 6, 8 ); g.drawLine( 0, 2, 0, 6 ); g.drawLine( 8, 2, 8, 6 ); g.drawLine( 1, 1, 1, 1 ); g.drawLine( 7, 1, 7, 1 ); g.drawLine( 1, 7, 1, 7 ); g.drawLine( 7, 7, 7, 7 ); } if ( isSelected ) { if ( isEnabled ) { if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) ) { g.setColor( MetalLookAndFeel.getMenuSelectedForeground() ); } else { g.setColor( b.getForeground() ); } } else { g.setColor( MetalLookAndFeel.getMenuDisabledForeground() ); } g.drawLine( 3, 2, 5, 2 ); g.drawLine( 2, 3, 6, 3 ); g.drawLine( 2, 4, 6, 4 ); g.drawLine( 2, 5, 6, 5 ); g.drawLine( 3, 6, 5, 6 ); } g.translate( -x, -y ); } public int getIconWidth() { return menuCheckIconSize.width; } public int getIconHeight() { return menuCheckIconSize.height; } } // End class RadioButtonMenuItemIcon private static class VerticalSliderThumbIcon implements Icon, Serializable, UIResource { protected static MetalBumps controlBumps; protected static MetalBumps primaryBumps; public VerticalSliderThumbIcon() { controlBumps = new MetalBumps( 6, 10, MetalLookAndFeel.getControlHighlight(), MetalLookAndFeel.getControlInfo(), MetalLookAndFeel.getControl() ); primaryBumps = new MetalBumps( 6, 10, MetalLookAndFeel.getPrimaryControl(), MetalLookAndFeel.getPrimaryControlDarkShadow(), MetalLookAndFeel.getPrimaryControlShadow() ); } public void paintIcon( Component c, Graphics g, int x, int y ) { JSlider slider = (JSlider)c; boolean leftToRight = MetalUtils.isLeftToRight(slider); g.translate( x, y ); // Draw the frame if ( slider.hasFocus() ) { g.setColor( MetalLookAndFeel.getPrimaryControlInfo() ); } else { g.setColor( slider.isEnabled() ? MetalLookAndFeel.getPrimaryControlInfo() : MetalLookAndFeel.getControlDarkShadow() ); } if (leftToRight) { g.drawLine( 1,0 , 8,0 ); // top g.drawLine( 0,1 , 0,13 ); // left g.drawLine( 1,14 , 8,14 ); // bottom g.drawLine( 9,1 , 15,7 ); // top slant g.drawLine( 9,13 , 15,7 ); // bottom slant } else { g.drawLine( 7,0 , 14,0 ); // top g.drawLine( 15,1 , 15,13 ); // right g.drawLine( 7,14 , 14,14 ); // bottom g.drawLine( 0,7 , 6,1 ); // top slant g.drawLine( 0,7 , 6,13 ); // bottom slant } // Fill in the background if ( slider.hasFocus() ) { g.setColor( c.getForeground() ); } else { g.setColor( MetalLookAndFeel.getControl() ); } if (leftToRight) { g.fillRect( 1,1 , 8,13 ); g.drawLine( 9,2 , 9,12 ); g.drawLine( 10,3 , 10,11 ); g.drawLine( 11,4 , 11,10 ); g.drawLine( 12,5 , 12,9 ); g.drawLine( 13,6 , 13,8 ); g.drawLine( 14,7 , 14,7 ); } else { g.fillRect( 7,1, 8,13 ); g.drawLine( 6,3 , 6,12 ); g.drawLine( 5,4 , 5,11 ); g.drawLine( 4,5 , 4,10 ); g.drawLine( 3,6 , 3,9 ); g.drawLine( 2,7 , 2,8 ); } // Draw the bumps int offset = (leftToRight) ? 2 : 8; if ( slider.isEnabled() ) { if ( slider.hasFocus() ) { primaryBumps.paintIcon( c, g, offset, 2 ); } else { controlBumps.paintIcon( c, g, offset, 2 ); } } // Draw the highlight if ( slider.isEnabled() ) { g.setColor( slider.hasFocus() ? MetalLookAndFeel.getPrimaryControl() : MetalLookAndFeel.getControlHighlight() ); if (leftToRight) { g.drawLine( 1, 1, 8, 1 ); g.drawLine( 1, 1, 1, 13 ); } else { g.drawLine( 8,1 , 14,1 ); // top g.drawLine( 1,7 , 7,1 ); // top slant } } g.translate( -x, -y ); } public int getIconWidth() { return 16; } public int getIconHeight() { return 15; } } private static class HorizontalSliderThumbIcon implements Icon, Serializable, UIResource { protected static MetalBumps controlBumps; protected static MetalBumps primaryBumps; public HorizontalSliderThumbIcon() { controlBumps = new MetalBumps( 10, 6, MetalLookAndFeel.getControlHighlight(), MetalLookAndFeel.getControlInfo(), MetalLookAndFeel.getControl() ); primaryBumps = new MetalBumps( 10, 6, MetalLookAndFeel.getPrimaryControl(), MetalLookAndFeel.getPrimaryControlDarkShadow(), MetalLookAndFeel.getPrimaryControlShadow() ); } public void paintIcon( Component c, Graphics g, int x, int y ) { JSlider slider = (JSlider)c; g.translate( x, y ); // Draw the frame if ( slider.hasFocus() ) { g.setColor( MetalLookAndFeel.getPrimaryControlInfo() ); } else { g.setColor( slider.isEnabled() ? MetalLookAndFeel.getPrimaryControlInfo() : MetalLookAndFeel.getControlDarkShadow() ); } g.drawLine( 1,0 , 13,0 ); // top g.drawLine( 0,1 , 0,8 ); // left g.drawLine( 14,1 , 14,8 ); // right g.drawLine( 1,9 , 7,15 ); // left slant g.drawLine( 7,15 , 14,8 ); // right slant // Fill in the background if ( slider.hasFocus() ) { g.setColor( c.getForeground() ); } else { g.setColor( MetalLookAndFeel.getControl() ); } g.fillRect( 1,1, 13, 8 ); g.drawLine( 2,9 , 12,9 ); g.drawLine( 3,10 , 11,10 ); g.drawLine( 4,11 , 10,11 ); g.drawLine( 5,12 , 9,12 ); g.drawLine( 6,13 , 8,13 ); g.drawLine( 7,14 , 7,14 ); // Draw the bumps if ( slider.isEnabled() ) { if ( slider.hasFocus() ) { primaryBumps.paintIcon( c, g, 2, 2 ); } else { controlBumps.paintIcon( c, g, 2, 2 ); } } // Draw the highlight if ( slider.isEnabled() ) { g.setColor( slider.hasFocus() ? MetalLookAndFeel.getPrimaryControl() : MetalLookAndFeel.getControlHighlight() ); g.drawLine( 1, 1, 13, 1 ); g.drawLine( 1, 1, 1, 8 ); } g.translate( -x, -y ); } public int getIconWidth() { return 15; } public int getIconHeight() { return 16; } } private static class OceanVerticalSliderThumbIcon extends CachedPainter implements Icon, Serializable, UIResource { // Used for clipping when the orientation is left to right private static Polygon LTR_THUMB_SHAPE; // Used for clipping when the orientation is right to left private static Polygon RTL_THUMB_SHAPE; static { LTR_THUMB_SHAPE = new Polygon(new int[] { 0, 8, 15, 8, 0}, new int[] { 0, 0, 7, 14, 14 }, 5); RTL_THUMB_SHAPE = new Polygon(new int[] { 15, 15, 7, 0, 7}, new int[] { 0, 14, 14, 7, 0}, 5); } OceanVerticalSliderThumbIcon() { super(3); } public void paintIcon(Component c, Graphics g, int x, int y) { if (!(g instanceof Graphics2D)) { return; } paint(c, g, x, y, getIconWidth(), getIconHeight(), MetalUtils.isLeftToRight(c), c.hasFocus(), c.isEnabled(), MetalLookAndFeel.getCurrentTheme()); } protected void paintToImage(Component c, Image image, Graphics g2, int w, int h, Object[] args) { Graphics2D g = (Graphics2D)g2; boolean leftToRight = ((Boolean)args[0]).booleanValue(); boolean hasFocus = ((Boolean)args[1]).booleanValue(); boolean enabled = ((Boolean)args[2]).booleanValue(); Rectangle clip = g.getClipBounds(); if (leftToRight) { g.clip(LTR_THUMB_SHAPE); } else { g.clip(RTL_THUMB_SHAPE); } if (!enabled) { g.setColor(MetalLookAndFeel.getControl()); g.fillRect(1, 1, 14, 14); } else if (hasFocus) { MetalUtils.drawGradient(c, g, "Slider.focusGradient", 1, 1, 14, 14, false); } else { MetalUtils.drawGradient(c, g, "Slider.gradient", 1, 1, 14, 14, false); } g.setClip(clip); // Draw the frame if (hasFocus) { g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); } else { g.setColor(enabled ? MetalLookAndFeel.getPrimaryControlInfo() : MetalLookAndFeel.getControlDarkShadow()); } if (leftToRight) { g.drawLine( 1,0 , 8,0 ); // top g.drawLine( 0,1 , 0,13 ); // left g.drawLine( 1,14 , 8,14 ); // bottom g.drawLine( 9,1 , 15,7 ); // top slant g.drawLine( 9,13 , 15,7 ); // bottom slant } else { g.drawLine( 7,0 , 14,0 ); // top g.drawLine( 15,1 , 15,13 ); // right g.drawLine( 7,14 , 14,14 ); // bottom g.drawLine( 0,7 , 6,1 ); // top slant g.drawLine( 0,7 , 6,13 ); // bottom slant } if (hasFocus && enabled) { // Inner line. g.setColor(MetalLookAndFeel.getPrimaryControl()); if (leftToRight) { g.drawLine( 1,1 , 8,1 ); // top g.drawLine( 1,1 , 1,13 ); // left g.drawLine( 1,13 , 8,13 ); // bottom g.drawLine( 9,2 , 14,7 ); // top slant g.drawLine( 9,12 , 14,7 ); // bottom slant } else { g.drawLine( 7,1 , 14,1 ); // top g.drawLine( 14,1 , 14,13 ); // right g.drawLine( 7,13 , 14,13 ); // bottom g.drawLine( 1,7 , 7,1 ); // top slant g.drawLine( 1,7 , 7,13 ); // bottom slant } } } public int getIconWidth() { return 16; } public int getIconHeight() { return 15; } protected Image createImage(Component c, int w, int h, GraphicsConfiguration config, Object[] args) { if (config == null) { return new BufferedImage(w, h,BufferedImage.TYPE_INT_ARGB); } return config.createCompatibleImage( w, h, Transparency.BITMASK); } } private static class OceanHorizontalSliderThumbIcon extends CachedPainter implements Icon, Serializable, UIResource { // Used for clipping private static Polygon THUMB_SHAPE; static { THUMB_SHAPE = new Polygon(new int[] { 0, 14, 14, 7, 0 }, new int[] { 0, 0, 8, 15, 8 }, 5); } OceanHorizontalSliderThumbIcon() { super(3); } public void paintIcon(Component c, Graphics g, int x, int y) { if (!(g instanceof Graphics2D)) { return; } paint(c, g, x, y, getIconWidth(), getIconHeight(), c.hasFocus(), c.isEnabled(), MetalLookAndFeel.getCurrentTheme()); } protected Image createImage(Component c, int w, int h, GraphicsConfiguration config, Object[] args) { if (config == null) { return new BufferedImage(w, h,BufferedImage.TYPE_INT_ARGB); } return config.createCompatibleImage( w, h, Transparency.BITMASK); } protected void paintToImage(Component c, Image image, Graphics g2, int w, int h, Object[] args) { Graphics2D g = (Graphics2D)g2; boolean hasFocus = ((Boolean)args[0]).booleanValue(); boolean enabled = ((Boolean)args[1]).booleanValue(); // Fill in the background Rectangle clip = g.getClipBounds(); g.clip(THUMB_SHAPE); if (!enabled) { g.setColor(MetalLookAndFeel.getControl()); g.fillRect(1, 1, 13, 14); } else if (hasFocus) { MetalUtils.drawGradient(c, g, "Slider.focusGradient", 1, 1, 13, 14, true); } else { MetalUtils.drawGradient(c, g, "Slider.gradient", 1, 1, 13, 14, true); } g.setClip(clip); // Draw the frame if (hasFocus) { g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); } else { g.setColor(enabled ? MetalLookAndFeel.getPrimaryControlInfo() : MetalLookAndFeel.getControlDarkShadow()); } g.drawLine( 1,0 , 13,0 ); // top g.drawLine( 0,1 , 0,8 ); // left g.drawLine( 14,1 , 14,8 ); // right g.drawLine( 1,9 , 7,15 ); // left slant g.drawLine( 7,15 , 14,8 ); // right slant if (hasFocus && enabled) { // Inner line. g.setColor(MetalLookAndFeel.getPrimaryControl()); g.fillRect(1, 1, 13, 1); g.fillRect(1, 2, 1, 7); g.fillRect(13, 2, 1, 7); g.drawLine(2, 9, 7, 14); g.drawLine(8, 13, 12, 9); } } public int getIconWidth() { return 15; } public int getIconHeight() { return 16; } } }
Java
/* * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import sun.swing.SwingUtilities2; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.InternalFrameEvent; import java.util.EventListener; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import javax.swing.plaf.basic.BasicInternalFrameTitlePane; /** {@collect.stats} * Class that manages a JLF title bar * @author Steve Wilson * @author Brian Beck * @since 1.3 */ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane { protected boolean isPalette = false; protected Icon paletteCloseIcon; protected int paletteTitleHeight; private static final Border handyEmptyBorder = new EmptyBorder(0,0,0,0); /** {@collect.stats} * Key used to lookup Color from UIManager. If this is null, * <code>getWindowTitleBackground</code> is used. */ private String selectedBackgroundKey; /** {@collect.stats} * Key used to lookup Color from UIManager. If this is null, * <code>getWindowTitleForeground</code> is used. */ private String selectedForegroundKey; /** {@collect.stats} * Key used to lookup shadow color from UIManager. If this is null, * <code>getPrimaryControlDarkShadow</code> is used. */ private String selectedShadowKey; /** {@collect.stats} * Boolean indicating the state of the <code>JInternalFrame</code>s * closable property at <code>updateUI</code> time. */ private boolean wasClosable; int buttonsWidth = 0; MetalBumps activeBumps = new MetalBumps( 0, 0, MetalLookAndFeel.getPrimaryControlHighlight(), MetalLookAndFeel.getPrimaryControlDarkShadow(), (UIManager.get("InternalFrame.activeTitleGradient") != null) ? null : MetalLookAndFeel.getPrimaryControl() ); MetalBumps inactiveBumps = new MetalBumps( 0, 0, MetalLookAndFeel.getControlHighlight(), MetalLookAndFeel.getControlDarkShadow(), (UIManager.get("InternalFrame.inactiveTitleGradient") != null) ? null : MetalLookAndFeel.getControl() ); MetalBumps paletteBumps; private Color activeBumpsHighlight = MetalLookAndFeel. getPrimaryControlHighlight(); private Color activeBumpsShadow = MetalLookAndFeel. getPrimaryControlDarkShadow(); public MetalInternalFrameTitlePane(JInternalFrame f) { super( f ); } public void addNotify() { super.addNotify(); // This is done here instead of in installDefaults as I was worried // that the BasicInternalFrameUI might not be fully initialized, and // that if this resets the closable state the BasicInternalFrameUI // Listeners that get notified might be in an odd/uninitialized state. updateOptionPaneState(); } protected void installDefaults() { super.installDefaults(); setFont( UIManager.getFont("InternalFrame.titleFont") ); paletteTitleHeight = UIManager.getInt("InternalFrame.paletteTitleHeight"); paletteCloseIcon = UIManager.getIcon("InternalFrame.paletteCloseIcon"); wasClosable = frame.isClosable(); selectedForegroundKey = selectedBackgroundKey = null; if (MetalLookAndFeel.usingOcean()) { setOpaque(true); } } protected void uninstallDefaults() { super.uninstallDefaults(); if (wasClosable != frame.isClosable()) { frame.setClosable(wasClosable); } } protected void createButtons() { super.createButtons(); Boolean paintActive = frame.isSelected() ? Boolean.TRUE:Boolean.FALSE; iconButton.putClientProperty("paintActive", paintActive); iconButton.setBorder(handyEmptyBorder); maxButton.putClientProperty("paintActive", paintActive); maxButton.setBorder(handyEmptyBorder); closeButton.putClientProperty("paintActive", paintActive); closeButton.setBorder(handyEmptyBorder); // The palette close icon isn't opaque while the regular close icon is. // This makes sure palette close buttons have the right background. closeButton.setBackground(MetalLookAndFeel.getPrimaryControlShadow()); if (MetalLookAndFeel.usingOcean()) { iconButton.setContentAreaFilled(false); maxButton.setContentAreaFilled(false); closeButton.setContentAreaFilled(false); } } /** {@collect.stats} * Override the parent's method to do nothing. Metal frames do not * have system menus. */ protected void assembleSystemMenu() {} /** {@collect.stats} * Override the parent's method to do nothing. Metal frames do not * have system menus. */ protected void addSystemMenuItems(JMenu systemMenu) {} /** {@collect.stats} * Override the parent's method to do nothing. Metal frames do not * have system menus. */ protected void showSystemMenu() {} /** {@collect.stats} * Override the parent's method avoid creating a menu bar. Metal frames * do not have system menus. */ protected void addSubComponents() { add(iconButton); add(maxButton); add(closeButton); } protected PropertyChangeListener createPropertyChangeListener() { return new MetalPropertyChangeHandler(); } protected LayoutManager createLayout() { return new MetalTitlePaneLayout(); } class MetalPropertyChangeHandler extends BasicInternalFrameTitlePane.PropertyChangeHandler { public void propertyChange(PropertyChangeEvent evt) { String prop = (String)evt.getPropertyName(); if( prop.equals(JInternalFrame.IS_SELECTED_PROPERTY) ) { Boolean b = (Boolean)evt.getNewValue(); iconButton.putClientProperty("paintActive", b); closeButton.putClientProperty("paintActive", b); maxButton.putClientProperty("paintActive", b); } else if ("JInternalFrame.messageType".equals(prop)) { updateOptionPaneState(); frame.repaint(); } super.propertyChange(evt); } } class MetalTitlePaneLayout extends TitlePaneLayout { public void addLayoutComponent(String name, Component c) {} public void removeLayoutComponent(Component c) {} public Dimension preferredLayoutSize(Container c) { return minimumLayoutSize(c); } public Dimension minimumLayoutSize(Container c) { // Compute width. int width = 30; if (frame.isClosable()) { width += 21; } if (frame.isMaximizable()) { width += 16 + (frame.isClosable() ? 10 : 4); } if (frame.isIconifiable()) { width += 16 + (frame.isMaximizable() ? 2 : (frame.isClosable() ? 10 : 4)); } FontMetrics fm = frame.getFontMetrics(getFont()); String frameTitle = frame.getTitle(); int title_w = frameTitle != null ? SwingUtilities2.stringWidth( frame, fm, frameTitle) : 0; int title_length = frameTitle != null ? frameTitle.length() : 0; if (title_length > 2) { int subtitle_w = SwingUtilities2.stringWidth(frame, fm, frame.getTitle().substring(0, 2) + "..."); width += (title_w < subtitle_w) ? title_w : subtitle_w; } else { width += title_w; } // Compute height. int height = 0; if (isPalette) { height = paletteTitleHeight; } else { int fontHeight = fm.getHeight(); fontHeight += 7; Icon icon = frame.getFrameIcon(); int iconHeight = 0; if (icon != null) { // SystemMenuBar forces the icon to be 16x16 or less. iconHeight = Math.min(icon.getIconHeight(), 16); } iconHeight += 5; height = Math.max(fontHeight, iconHeight); } return new Dimension(width, height); } public void layoutContainer(Container c) { boolean leftToRight = MetalUtils.isLeftToRight(frame); int w = getWidth(); int x = leftToRight ? w : 0; int y = 2; int spacing; // assumes all buttons have the same dimensions // these dimensions include the borders int buttonHeight = closeButton.getIcon().getIconHeight(); int buttonWidth = closeButton.getIcon().getIconWidth(); if(frame.isClosable()) { if (isPalette) { spacing = 3; x += leftToRight ? -spacing -(buttonWidth+2) : spacing; closeButton.setBounds(x, y, buttonWidth+2, getHeight()-4); if( !leftToRight ) x += (buttonWidth+2); } else { spacing = 4; x += leftToRight ? -spacing -buttonWidth : spacing; closeButton.setBounds(x, y, buttonWidth, buttonHeight); if( !leftToRight ) x += buttonWidth; } } if(frame.isMaximizable() && !isPalette ) { spacing = frame.isClosable() ? 10 : 4; x += leftToRight ? -spacing -buttonWidth : spacing; maxButton.setBounds(x, y, buttonWidth, buttonHeight); if( !leftToRight ) x += buttonWidth; } if(frame.isIconifiable() && !isPalette ) { spacing = frame.isMaximizable() ? 2 : (frame.isClosable() ? 10 : 4); x += leftToRight ? -spacing -buttonWidth : spacing; iconButton.setBounds(x, y, buttonWidth, buttonHeight); if( !leftToRight ) x += buttonWidth; } buttonsWidth = leftToRight ? w - x : x; } } public void paintPalette(Graphics g) { boolean leftToRight = MetalUtils.isLeftToRight(frame); int width = getWidth(); int height = getHeight(); if (paletteBumps == null) { paletteBumps = new MetalBumps(0, 0, MetalLookAndFeel.getPrimaryControlHighlight(), MetalLookAndFeel.getPrimaryControlInfo(), MetalLookAndFeel.getPrimaryControlShadow() ); } Color background = MetalLookAndFeel.getPrimaryControlShadow(); Color darkShadow = MetalLookAndFeel.getPrimaryControlDarkShadow(); g.setColor(background); g.fillRect(0, 0, width, height); g.setColor( darkShadow ); g.drawLine ( 0, height - 1, width, height -1); int xOffset = leftToRight ? 4 : buttonsWidth + 4; int bumpLength = width - buttonsWidth -2*4; int bumpHeight = getHeight() - 4; paletteBumps.setBumpArea( bumpLength, bumpHeight ); paletteBumps.paintIcon( this, g, xOffset, 2); } public void paintComponent(Graphics g) { if(isPalette) { paintPalette(g); return; } boolean leftToRight = MetalUtils.isLeftToRight(frame); boolean isSelected = frame.isSelected(); int width = getWidth(); int height = getHeight(); Color background = null; Color foreground = null; Color shadow = null; MetalBumps bumps; String gradientKey; if (isSelected) { if (!MetalLookAndFeel.usingOcean()) { closeButton.setContentAreaFilled(true); maxButton.setContentAreaFilled(true); iconButton.setContentAreaFilled(true); } if (selectedBackgroundKey != null) { background = UIManager.getColor(selectedBackgroundKey); } if (background == null) { background = MetalLookAndFeel.getWindowTitleBackground(); } if (selectedForegroundKey != null) { foreground = UIManager.getColor(selectedForegroundKey); } if (selectedShadowKey != null) { shadow = UIManager.getColor(selectedShadowKey); } if (shadow == null) { shadow = MetalLookAndFeel.getPrimaryControlDarkShadow(); } if (foreground == null) { foreground = MetalLookAndFeel.getWindowTitleForeground(); } activeBumps.setBumpColors(activeBumpsHighlight, activeBumpsShadow, UIManager.get("InternalFrame.activeTitleGradient") != null ? null : background); bumps = activeBumps; gradientKey = "InternalFrame.activeTitleGradient"; } else { if (!MetalLookAndFeel.usingOcean()) { closeButton.setContentAreaFilled(false); maxButton.setContentAreaFilled(false); iconButton.setContentAreaFilled(false); } background = MetalLookAndFeel.getWindowTitleInactiveBackground(); foreground = MetalLookAndFeel.getWindowTitleInactiveForeground(); shadow = MetalLookAndFeel.getControlDarkShadow(); bumps = inactiveBumps; gradientKey = "InternalFrame.inactiveTitleGradient"; } if (!MetalUtils.drawGradient(this, g, gradientKey, 0, 0, width, height, true)) { g.setColor(background); g.fillRect(0, 0, width, height); } g.setColor( shadow ); g.drawLine ( 0, height - 1, width, height -1); g.drawLine ( 0, 0, 0 ,0); g.drawLine ( width - 1, 0 , width -1, 0); int titleLength = 0; int xOffset = leftToRight ? 5 : width - 5; String frameTitle = frame.getTitle(); Icon icon = frame.getFrameIcon(); if ( icon != null ) { if( !leftToRight ) xOffset -= icon.getIconWidth(); int iconY = ((height / 2) - (icon.getIconHeight() /2)); icon.paintIcon(frame, g, xOffset, iconY); xOffset += leftToRight ? icon.getIconWidth() + 5 : -5; } if(frameTitle != null) { Font f = getFont(); g.setFont(f); FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g, f); int fHeight = fm.getHeight(); g.setColor(foreground); int yOffset = ( (height - fm.getHeight() ) / 2 ) + fm.getAscent(); Rectangle rect = new Rectangle(0, 0, 0, 0); if (frame.isIconifiable()) { rect = iconButton.getBounds(); } else if (frame.isMaximizable()) { rect = maxButton.getBounds(); } else if (frame.isClosable()) { rect = closeButton.getBounds(); } int titleW; if( leftToRight ) { if (rect.x == 0) { rect.x = frame.getWidth()-frame.getInsets().right-2; } titleW = rect.x - xOffset - 4; frameTitle = getTitle(frameTitle, fm, titleW); } else { titleW = xOffset - rect.x - rect.width - 4; frameTitle = getTitle(frameTitle, fm, titleW); xOffset -= SwingUtilities2.stringWidth(frame, fm, frameTitle); } titleLength = SwingUtilities2.stringWidth(frame, fm, frameTitle); SwingUtilities2.drawString(frame, g, frameTitle, xOffset, yOffset); xOffset += leftToRight ? titleLength + 5 : -5; } int bumpXOffset; int bumpLength; if( leftToRight ) { bumpLength = width - buttonsWidth - xOffset - 5; bumpXOffset = xOffset; } else { bumpLength = xOffset - buttonsWidth - 5; bumpXOffset = buttonsWidth + 5; } int bumpYOffset = 3; int bumpHeight = getHeight() - (2 * bumpYOffset); bumps.setBumpArea( bumpLength, bumpHeight ); bumps.paintIcon(this, g, bumpXOffset, bumpYOffset); } public void setPalette(boolean b) { isPalette = b; if (isPalette) { closeButton.setIcon(paletteCloseIcon); if( frame.isMaximizable() ) remove(maxButton); if( frame.isIconifiable() ) remove(iconButton); } else { closeButton.setIcon(closeIcon); if( frame.isMaximizable() ) add(maxButton); if( frame.isIconifiable() ) add(iconButton); } revalidate(); repaint(); } /** {@collect.stats} * Updates any state dependant upon the JInternalFrame being shown in * a <code>JOptionPane</code>. */ private void updateOptionPaneState() { int type = -2; boolean closable = wasClosable; Object obj = frame.getClientProperty("JInternalFrame.messageType"); if (obj == null) { // Don't change the closable state unless in an JOptionPane. return; } if (obj instanceof Integer) { type = ((Integer) obj).intValue(); } switch (type) { case JOptionPane.ERROR_MESSAGE: selectedBackgroundKey = "OptionPane.errorDialog.titlePane.background"; selectedForegroundKey = "OptionPane.errorDialog.titlePane.foreground"; selectedShadowKey = "OptionPane.errorDialog.titlePane.shadow"; closable = false; break; case JOptionPane.QUESTION_MESSAGE: selectedBackgroundKey = "OptionPane.questionDialog.titlePane.background"; selectedForegroundKey = "OptionPane.questionDialog.titlePane.foreground"; selectedShadowKey = "OptionPane.questionDialog.titlePane.shadow"; closable = false; break; case JOptionPane.WARNING_MESSAGE: selectedBackgroundKey = "OptionPane.warningDialog.titlePane.background"; selectedForegroundKey = "OptionPane.warningDialog.titlePane.foreground"; selectedShadowKey = "OptionPane.warningDialog.titlePane.shadow"; closable = false; break; case JOptionPane.INFORMATION_MESSAGE: case JOptionPane.PLAIN_MESSAGE: selectedBackgroundKey = selectedForegroundKey = selectedShadowKey = null; closable = false; break; default: selectedBackgroundKey = selectedForegroundKey = selectedShadowKey = null; break; } if (closable != frame.isClosable()) { frame.setClosable(closable); } } }
Java
/* * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.*; import javax.swing.border.*; import java.io.Serializable; import java.awt.*; import java.awt.event.*; import javax.swing.plaf.basic.BasicComboBoxEditor; /** {@collect.stats} * The default editor for Metal editable combo boxes * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Steve Wilson */ public class MetalComboBoxEditor extends BasicComboBoxEditor { public MetalComboBoxEditor() { super(); //editor.removeFocusListener(this); editor = new JTextField("",9) { // workaround for 4530952 public void setText(String s) { if (getText().equals(s)) { return; } super.setText(s); } // The preferred and minimum sizes are overriden and padded by // 4 to keep the size as it previously was. Refer to bugs // 4775789 and 4517214 for details. public Dimension getPreferredSize() { Dimension pref = super.getPreferredSize(); pref.height += 4; return pref; } public Dimension getMinimumSize() { Dimension min = super.getMinimumSize(); min.height += 4; return min; } }; editor.setBorder( new EditorBorder() ); //editor.addFocusListener(this); } /** {@collect.stats} * The default editor border <code>Insets</code>. This field * might not be used. */ protected static Insets editorBorderInsets = new Insets( 2, 2, 2, 0 ); private static final Insets SAFE_EDITOR_BORDER_INSETS = new Insets( 2, 2, 2, 0 ); class EditorBorder extends AbstractBorder { public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { g.translate( x, y ); if (MetalLookAndFeel.usingOcean()) { g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w, h - 1); g.setColor(MetalLookAndFeel.getControlShadow()); g.drawRect(1, 1, w - 2, h - 3); } else { g.setColor( MetalLookAndFeel.getControlDarkShadow() ); g.drawLine( 0, 0, w-1, 0 ); g.drawLine( 0, 0, 0, h-2 ); g.drawLine( 0, h-2, w-1, h-2 ); g.setColor( MetalLookAndFeel.getControlHighlight() ); g.drawLine( 1, 1, w-1, 1 ); g.drawLine( 1, 1, 1, h-1 ); g.drawLine( 1, h-1, w-1, h-1 ); g.setColor( MetalLookAndFeel.getControl() ); g.drawLine( 1, h-2, 1, h-2 ); } g.translate( -x, -y ); } public Insets getBorderInsets( Component c ) { if (System.getSecurityManager() != null) { return SAFE_EDITOR_BORDER_INSETS; } else { return editorBorderInsets; } } } /** {@collect.stats} * A subclass of BasicComboBoxEditor that implements UIResource. * BasicComboBoxEditor doesn't implement UIResource * directly so that applications can safely override the * cellRenderer property with BasicListCellRenderer subclasses. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. */ public static class UIResource extends MetalComboBoxEditor implements javax.swing.plaf.UIResource { } }
Java
/* * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import javax.swing.plaf.basic.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import javax.swing.plaf.*; /** {@collect.stats} * Metal implementation of JInternalFrame. * <p> * * @author Steve Wilson */ public class MetalInternalFrameUI extends BasicInternalFrameUI { private static final PropertyChangeListener metalPropertyChangeListener = new MetalPropertyChangeHandler(); private static final Border handyEmptyBorder = new EmptyBorder(0,0,0,0); protected static String IS_PALETTE = "JInternalFrame.isPalette"; private static String IS_PALETTE_KEY = "JInternalFrame.isPalette"; private static String FRAME_TYPE = "JInternalFrame.frameType"; private static String NORMAL_FRAME = "normal"; private static String PALETTE_FRAME = "palette"; private static String OPTION_DIALOG = "optionDialog"; public MetalInternalFrameUI(JInternalFrame b) { super(b); } public static ComponentUI createUI(JComponent c) { return new MetalInternalFrameUI( (JInternalFrame) c); } public void installUI(JComponent c) { super.installUI(c); Object paletteProp = c.getClientProperty(IS_PALETTE_KEY); if ( paletteProp != null ) { setPalette( ((Boolean)paletteProp).booleanValue() ); } Container content = frame.getContentPane(); stripContentBorder(content); //c.setOpaque(false); } public void uninstallUI(JComponent c) { frame = (JInternalFrame)c; Container cont = ((JInternalFrame)(c)).getContentPane(); if (cont instanceof JComponent) { JComponent content = (JComponent)cont; if ( content.getBorder() == handyEmptyBorder) { content.setBorder(null); } } super.uninstallUI(c); } protected void installListeners() { super.installListeners(); frame.addPropertyChangeListener(metalPropertyChangeListener); } protected void uninstallListeners() { frame.removePropertyChangeListener(metalPropertyChangeListener); super.uninstallListeners(); } protected void installKeyboardActions(){ super.installKeyboardActions(); ActionMap map = SwingUtilities.getUIActionMap(frame); if (map != null) { // BasicInternalFrameUI creates an action with the same name, we override // it as Metal frames do not have system menus. map.remove("showSystemMenu"); } } protected void uninstallKeyboardActions(){ super.uninstallKeyboardActions(); } protected void uninstallComponents() { titlePane = null; super.uninstallComponents(); } private void stripContentBorder(Object c) { if ( c instanceof JComponent ) { JComponent contentComp = (JComponent)c; Border contentBorder = contentComp.getBorder(); if (contentBorder == null || contentBorder instanceof UIResource) { contentComp.setBorder( handyEmptyBorder ); } } } protected JComponent createNorthPane(JInternalFrame w) { return new MetalInternalFrameTitlePane(w); } private void setFrameType( String frameType ) { if ( frameType.equals( OPTION_DIALOG ) ) { LookAndFeel.installBorder(frame, "InternalFrame.optionDialogBorder"); ((MetalInternalFrameTitlePane)titlePane).setPalette( false ); } else if ( frameType.equals( PALETTE_FRAME ) ) { LookAndFeel.installBorder(frame, "InternalFrame.paletteBorder"); ((MetalInternalFrameTitlePane)titlePane).setPalette( true ); } else { LookAndFeel.installBorder(frame, "InternalFrame.border"); ((MetalInternalFrameTitlePane)titlePane).setPalette( false ); } } // this should be deprecated - jcs public void setPalette(boolean isPalette) { if (isPalette) { LookAndFeel.installBorder(frame, "InternalFrame.paletteBorder"); } else { LookAndFeel.installBorder(frame, "InternalFrame.border"); } ((MetalInternalFrameTitlePane)titlePane).setPalette(isPalette); } private static class MetalPropertyChangeHandler implements PropertyChangeListener { public void propertyChange(PropertyChangeEvent e) { String name = e.getPropertyName(); JInternalFrame jif = (JInternalFrame)e.getSource(); if (!(jif.getUI() instanceof MetalInternalFrameUI)) { return; } MetalInternalFrameUI ui = (MetalInternalFrameUI)jif.getUI(); if ( name.equals( FRAME_TYPE ) ) { if ( e.getNewValue() instanceof String ) { ui.setFrameType( (String) e.getNewValue() ); } } else if ( name.equals(IS_PALETTE_KEY) ) { if ( e.getNewValue() != null ) { ui.setPalette( ((Boolean)e.getNewValue()).booleanValue() ); } else { ui.setPalette( false ); } } else if ( name.equals( JInternalFrame.CONTENT_PANE_PROPERTY ) ) { ui.stripContentBorder(e.getNewValue()); } } } // end class MetalPropertyChangeHandler private class BorderListener1 extends BorderListener implements SwingConstants { Rectangle getIconBounds() { boolean leftToRight = MetalUtils.isLeftToRight(frame); int xOffset = leftToRight ? 5 : titlePane.getWidth() - 5; Rectangle rect = null; Icon icon = frame.getFrameIcon(); if ( icon != null ) { if ( !leftToRight ) { xOffset -= icon.getIconWidth(); } int iconY = ((titlePane.getHeight() / 2) - (icon.getIconHeight() /2)); rect = new Rectangle(xOffset, iconY, icon.getIconWidth(), icon.getIconHeight()); } return rect; } public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2 && e.getSource() == getNorthPane() && frame.isClosable() && !frame.isIcon()) { Rectangle rect = getIconBounds(); if ((rect != null) && rect.contains(e.getX(), e.getY())) { frame.doDefaultCloseAction(); } else { super.mouseClicked(e); } } else { super.mouseClicked(e); } } }; /// End BorderListener Class /** {@collect.stats} * Returns the <code>MouseInputAdapter</code> that will be installed * on the TitlePane. * * @param w the <code>JInternalFrame</code> * @return the <code>MouseInputAdapter</code> that will be installed * on the TitlePane. * @since 1.6 */ protected MouseInputAdapter createBorderListener(JInternalFrame w) { return new BorderListener1(); } }
Java
/* * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.plaf.*; import java.beans.*; import java.util.EventListener; import java.io.Serializable; import javax.swing.plaf.basic.BasicDesktopIconUI; /** {@collect.stats} * Metal desktop icon. * * @author Steve Wilson */ public class MetalDesktopIconUI extends BasicDesktopIconUI { JButton button; JLabel label; TitleListener titleListener; private int width; public static ComponentUI createUI(JComponent c) { return new MetalDesktopIconUI(); } public MetalDesktopIconUI() { } protected void installDefaults() { super.installDefaults(); LookAndFeel.installColorsAndFont(desktopIcon, "DesktopIcon.background", "DesktopIcon.foreground", "DesktopIcon.font"); width = UIManager.getInt("DesktopIcon.width"); } protected void installComponents() { frame = desktopIcon.getInternalFrame(); Icon icon = frame.getFrameIcon(); String title = frame.getTitle(); button = new JButton (title, icon); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { deiconize(); }} ); button.setFont(desktopIcon.getFont()); button.setBackground(desktopIcon.getBackground()); button.setForeground(desktopIcon.getForeground()); int buttonH = button.getPreferredSize().height; Icon drag = new MetalBumps((buttonH/3), buttonH, MetalLookAndFeel.getControlHighlight(), MetalLookAndFeel.getControlDarkShadow(), MetalLookAndFeel.getControl()); label = new JLabel(drag); label.setBorder( new MatteBorder( 0, 2, 0, 1, desktopIcon.getBackground()) ); desktopIcon.setLayout(new BorderLayout(2, 0)); desktopIcon.add(button, BorderLayout.CENTER); desktopIcon.add(label, BorderLayout.WEST); } protected void uninstallComponents() { desktopIcon.setLayout(null); desktopIcon.remove(label); desktopIcon.remove(button); button = null; frame = null; } protected void installListeners() { super.installListeners(); desktopIcon.getInternalFrame().addPropertyChangeListener( titleListener = new TitleListener()); } protected void uninstallListeners() { desktopIcon.getInternalFrame().removePropertyChangeListener( titleListener); titleListener = null; super.uninstallListeners(); } public Dimension getPreferredSize(JComponent c) { // Metal desktop icons can not be resized. Their dimensions should // always be the minimum size. See getMinimumSize(JComponent c). return getMinimumSize(c); } public Dimension getMinimumSize(JComponent c) { // For the metal desktop icon we will use the layout maanger to // determine the correct height of the component, but we want to keep // the width consistent according to the jlf spec. return new Dimension(width, desktopIcon.getLayout().minimumLayoutSize(desktopIcon).height); } public Dimension getMaximumSize(JComponent c) { // Metal desktop icons can not be resized. Their dimensions should // always be the minimum size. See getMinimumSize(JComponent c). return getMinimumSize(c); } class TitleListener implements PropertyChangeListener { public void propertyChange (PropertyChangeEvent e) { if (e.getPropertyName().equals("title")) { button.setText((String)e.getNewValue()); } if (e.getPropertyName().equals("frameIcon")) { button.setIcon((Icon)e.getNewValue()); } } } }
Java
/* * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.*; import javax.swing.border.EmptyBorder; import javax.swing.filechooser.*; import javax.swing.event.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import java.awt.*; import java.awt.event.*; import java.beans.*; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.*; import java.security.AccessController; import java.security.PrivilegedAction; import javax.accessibility.*; import sun.awt.shell.ShellFolder; import sun.swing.*; /** {@collect.stats} * Metal L&F implementation of a FileChooser. * * @author Jeff Dinkins */ public class MetalFileChooserUI extends BasicFileChooserUI { // Much of the Metal UI for JFilechooser is just a copy of // the windows implementation, but using Metal themed buttons, lists, // icons, etc. We are planning a complete rewrite, and hence we've // made most things in this class private. private JLabel lookInLabel; private JComboBox directoryComboBox; private DirectoryComboBoxModel directoryComboBoxModel; private Action directoryComboBoxAction = new DirectoryComboBoxAction(); private FilterComboBoxModel filterComboBoxModel; private JTextField fileNameTextField; private FilePane filePane; private JToggleButton listViewButton; private JToggleButton detailsViewButton; private boolean useShellFolder; private JButton approveButton; private JButton cancelButton; private JPanel buttonPanel; private JPanel bottomPanel; private JComboBox filterComboBox; private static final Dimension hstrut5 = new Dimension(5, 1); private static final Dimension hstrut11 = new Dimension(11, 1); private static final Dimension vstrut5 = new Dimension(1, 5); private static final Insets shrinkwrap = new Insets(0,0,0,0); // Preferred and Minimum sizes for the dialog box private static int PREF_WIDTH = 500; private static int PREF_HEIGHT = 326; private static Dimension PREF_SIZE = new Dimension(PREF_WIDTH, PREF_HEIGHT); private static int MIN_WIDTH = 500; private static int MIN_HEIGHT = 326; private static Dimension MIN_SIZE = new Dimension(MIN_WIDTH, MIN_HEIGHT); private static int LIST_PREF_WIDTH = 405; private static int LIST_PREF_HEIGHT = 135; private static Dimension LIST_PREF_SIZE = new Dimension(LIST_PREF_WIDTH, LIST_PREF_HEIGHT); // Labels, mnemonics, and tooltips (oh my!) private int lookInLabelMnemonic = 0; private String lookInLabelText = null; private String saveInLabelText = null; private int fileNameLabelMnemonic = 0; private String fileNameLabelText = null; private int folderNameLabelMnemonic = 0; private String folderNameLabelText = null; private int filesOfTypeLabelMnemonic = 0; private String filesOfTypeLabelText = null; private String upFolderToolTipText = null; private String upFolderAccessibleName = null; private String homeFolderToolTipText = null; private String homeFolderAccessibleName = null; private String newFolderToolTipText = null; private String newFolderAccessibleName = null; private String listViewButtonToolTipText = null; private String listViewButtonAccessibleName = null; private String detailsViewButtonToolTipText = null; private String detailsViewButtonAccessibleName = null; private AlignedLabel fileNameLabel; private void populateFileNameLabel() { if (getFileChooser().getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) { fileNameLabel.setText(folderNameLabelText); fileNameLabel.setDisplayedMnemonic(folderNameLabelMnemonic); } else { fileNameLabel.setText(fileNameLabelText); fileNameLabel.setDisplayedMnemonic(fileNameLabelMnemonic); } } // // ComponentUI Interface Implementation methods // public static ComponentUI createUI(JComponent c) { return new MetalFileChooserUI((JFileChooser) c); } public MetalFileChooserUI(JFileChooser filechooser) { super(filechooser); } public void installUI(JComponent c) { super.installUI(c); } public void uninstallComponents(JFileChooser fc) { fc.removeAll(); bottomPanel = null; buttonPanel = null; } private class MetalFileChooserUIAccessor implements FilePane.FileChooserUIAccessor { public JFileChooser getFileChooser() { return MetalFileChooserUI.this.getFileChooser(); } public BasicDirectoryModel getModel() { return MetalFileChooserUI.this.getModel(); } public JPanel createList() { return MetalFileChooserUI.this.createList(getFileChooser()); } public JPanel createDetailsView() { return MetalFileChooserUI.this.createDetailsView(getFileChooser()); } public boolean isDirectorySelected() { return MetalFileChooserUI.this.isDirectorySelected(); } public File getDirectory() { return MetalFileChooserUI.this.getDirectory(); } public Action getChangeToParentDirectoryAction() { return MetalFileChooserUI.this.getChangeToParentDirectoryAction(); } public Action getApproveSelectionAction() { return MetalFileChooserUI.this.getApproveSelectionAction(); } public Action getNewFolderAction() { return MetalFileChooserUI.this.getNewFolderAction(); } public MouseListener createDoubleClickListener(JList list) { return MetalFileChooserUI.this.createDoubleClickListener(getFileChooser(), list); } public ListSelectionListener createListSelectionListener() { return MetalFileChooserUI.this.createListSelectionListener(getFileChooser()); } public boolean usesShellFolder() { return useShellFolder; } } public void installComponents(JFileChooser fc) { FileSystemView fsv = fc.getFileSystemView(); fc.setBorder(new EmptyBorder(12, 12, 11, 11)); fc.setLayout(new BorderLayout(0, 11)); filePane = new FilePane(new MetalFileChooserUIAccessor()); fc.addPropertyChangeListener(filePane); updateUseShellFolder(); // ********************************* // // **** Construct the top panel **** // // ********************************* // // Directory manipulation buttons JPanel topPanel = new JPanel(new BorderLayout(11, 0)); JPanel topButtonPanel = new JPanel(); topButtonPanel.setLayout(new BoxLayout(topButtonPanel, BoxLayout.LINE_AXIS)); topPanel.add(topButtonPanel, BorderLayout.AFTER_LINE_ENDS); // Add the top panel to the fileChooser fc.add(topPanel, BorderLayout.NORTH); // ComboBox Label lookInLabel = new JLabel(lookInLabelText); lookInLabel.setDisplayedMnemonic(lookInLabelMnemonic); topPanel.add(lookInLabel, BorderLayout.BEFORE_LINE_BEGINS); // CurrentDir ComboBox directoryComboBox = new JComboBox() { public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); // Must be small enough to not affect total width. d.width = 150; return d; } }; directoryComboBox.putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY, lookInLabelText); directoryComboBox.putClientProperty( "JComboBox.isTableCellEditor", Boolean.TRUE ); lookInLabel.setLabelFor(directoryComboBox); directoryComboBoxModel = createDirectoryComboBoxModel(fc); directoryComboBox.setModel(directoryComboBoxModel); directoryComboBox.addActionListener(directoryComboBoxAction); directoryComboBox.setRenderer(createDirectoryComboBoxRenderer(fc)); directoryComboBox.setAlignmentX(JComponent.LEFT_ALIGNMENT); directoryComboBox.setAlignmentY(JComponent.TOP_ALIGNMENT); directoryComboBox.setMaximumRowCount(8); topPanel.add(directoryComboBox, BorderLayout.CENTER); // Up Button JButton upFolderButton = new JButton(getChangeToParentDirectoryAction()); upFolderButton.setText(null); upFolderButton.setIcon(upFolderIcon); upFolderButton.setToolTipText(upFolderToolTipText); upFolderButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, upFolderAccessibleName); upFolderButton.setAlignmentX(JComponent.LEFT_ALIGNMENT); upFolderButton.setAlignmentY(JComponent.CENTER_ALIGNMENT); upFolderButton.setMargin(shrinkwrap); topButtonPanel.add(upFolderButton); topButtonPanel.add(Box.createRigidArea(hstrut5)); // Home Button File homeDir = fsv.getHomeDirectory(); String toolTipText = homeFolderToolTipText; if (fsv.isRoot(homeDir)) { toolTipText = getFileView(fc).getName(homeDir); // Probably "Desktop". } JButton b = new JButton(homeFolderIcon); b.setToolTipText(toolTipText); b.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, homeFolderAccessibleName); b.setAlignmentX(JComponent.LEFT_ALIGNMENT); b.setAlignmentY(JComponent.CENTER_ALIGNMENT); b.setMargin(shrinkwrap); b.addActionListener(getGoHomeAction()); topButtonPanel.add(b); topButtonPanel.add(Box.createRigidArea(hstrut5)); // New Directory Button if (!UIManager.getBoolean("FileChooser.readOnly")) { b = new JButton(filePane.getNewFolderAction()); b.setText(null); b.setIcon(newFolderIcon); b.setToolTipText(newFolderToolTipText); b.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, newFolderAccessibleName); b.setAlignmentX(JComponent.LEFT_ALIGNMENT); b.setAlignmentY(JComponent.CENTER_ALIGNMENT); b.setMargin(shrinkwrap); } topButtonPanel.add(b); topButtonPanel.add(Box.createRigidArea(hstrut5)); // View button group ButtonGroup viewButtonGroup = new ButtonGroup(); // List Button listViewButton = new JToggleButton(listViewIcon); listViewButton.setToolTipText(listViewButtonToolTipText); listViewButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, listViewButtonAccessibleName); listViewButton.setSelected(true); listViewButton.setAlignmentX(JComponent.LEFT_ALIGNMENT); listViewButton.setAlignmentY(JComponent.CENTER_ALIGNMENT); listViewButton.setMargin(shrinkwrap); listViewButton.addActionListener(filePane.getViewTypeAction(FilePane.VIEWTYPE_LIST)); topButtonPanel.add(listViewButton); viewButtonGroup.add(listViewButton); // Details Button detailsViewButton = new JToggleButton(detailsViewIcon); detailsViewButton.setToolTipText(detailsViewButtonToolTipText); detailsViewButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, detailsViewButtonAccessibleName); detailsViewButton.setAlignmentX(JComponent.LEFT_ALIGNMENT); detailsViewButton.setAlignmentY(JComponent.CENTER_ALIGNMENT); detailsViewButton.setMargin(shrinkwrap); detailsViewButton.addActionListener(filePane.getViewTypeAction(FilePane.VIEWTYPE_DETAILS)); topButtonPanel.add(detailsViewButton); viewButtonGroup.add(detailsViewButton); filePane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { if ("viewType".equals(e.getPropertyName())) { int viewType = filePane.getViewType(); switch (viewType) { case FilePane.VIEWTYPE_LIST: listViewButton.setSelected(true); break; case FilePane.VIEWTYPE_DETAILS: detailsViewButton.setSelected(true); break; } } } }); // ************************************** // // ******* Add the directory pane ******* // // ************************************** // fc.add(getAccessoryPanel(), BorderLayout.AFTER_LINE_ENDS); JComponent accessory = fc.getAccessory(); if(accessory != null) { getAccessoryPanel().add(accessory); } filePane.setPreferredSize(LIST_PREF_SIZE); fc.add(filePane, BorderLayout.CENTER); // ********************************** // // **** Construct the bottom panel ** // // ********************************** // JPanel bottomPanel = getBottomPanel(); bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.Y_AXIS)); fc.add(bottomPanel, BorderLayout.SOUTH); // FileName label and textfield JPanel fileNamePanel = new JPanel(); fileNamePanel.setLayout(new BoxLayout(fileNamePanel, BoxLayout.LINE_AXIS)); bottomPanel.add(fileNamePanel); bottomPanel.add(Box.createRigidArea(vstrut5)); fileNameLabel = new AlignedLabel(); populateFileNameLabel(); fileNamePanel.add(fileNameLabel); fileNameTextField = new JTextField(35) { public Dimension getMaximumSize() { return new Dimension(Short.MAX_VALUE, super.getPreferredSize().height); } }; fileNamePanel.add(fileNameTextField); fileNameLabel.setLabelFor(fileNameTextField); fileNameTextField.addFocusListener( new FocusAdapter() { public void focusGained(FocusEvent e) { if (!getFileChooser().isMultiSelectionEnabled()) { filePane.clearSelection(); } } } ); if (fc.isMultiSelectionEnabled()) { setFileName(fileNameString(fc.getSelectedFiles())); } else { setFileName(fileNameString(fc.getSelectedFile())); } // Filetype label and combobox JPanel filesOfTypePanel = new JPanel(); filesOfTypePanel.setLayout(new BoxLayout(filesOfTypePanel, BoxLayout.LINE_AXIS)); bottomPanel.add(filesOfTypePanel); AlignedLabel filesOfTypeLabel = new AlignedLabel(filesOfTypeLabelText); filesOfTypeLabel.setDisplayedMnemonic(filesOfTypeLabelMnemonic); filesOfTypePanel.add(filesOfTypeLabel); filterComboBoxModel = createFilterComboBoxModel(); fc.addPropertyChangeListener(filterComboBoxModel); filterComboBox = new JComboBox(filterComboBoxModel); filterComboBox.putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY, filesOfTypeLabelText); filesOfTypeLabel.setLabelFor(filterComboBox); filterComboBox.setRenderer(createFilterComboBoxRenderer()); filesOfTypePanel.add(filterComboBox); // buttons getButtonPanel().setLayout(new ButtonAreaLayout()); approveButton = new JButton(getApproveButtonText(fc)); // Note: Metal does not use mnemonics for approve and cancel approveButton.addActionListener(getApproveSelectionAction()); approveButton.setToolTipText(getApproveButtonToolTipText(fc)); getButtonPanel().add(approveButton); cancelButton = new JButton(cancelButtonText); cancelButton.setToolTipText(cancelButtonToolTipText); cancelButton.addActionListener(getCancelSelectionAction()); getButtonPanel().add(cancelButton); if(fc.getControlButtonsAreShown()) { addControlButtons(); } groupLabels(new AlignedLabel[] { fileNameLabel, filesOfTypeLabel }); } private void updateUseShellFolder() { // Decide whether to use the ShellFolder class to populate shortcut // panel and combobox. JFileChooser fc = getFileChooser(); Boolean prop = (Boolean)fc.getClientProperty("FileChooser.useShellFolder"); if (prop != null) { useShellFolder = prop.booleanValue(); } else { useShellFolder = fc.getFileSystemView().equals(FileSystemView.getFileSystemView()); } } protected JPanel getButtonPanel() { if (buttonPanel == null) { buttonPanel = new JPanel(); } return buttonPanel; } protected JPanel getBottomPanel() { if(bottomPanel == null) { bottomPanel = new JPanel(); } return bottomPanel; } protected void installStrings(JFileChooser fc) { super.installStrings(fc); Locale l = fc.getLocale(); lookInLabelMnemonic = UIManager.getInt("FileChooser.lookInLabelMnemonic"); lookInLabelText = UIManager.getString("FileChooser.lookInLabelText",l); saveInLabelText = UIManager.getString("FileChooser.saveInLabelText",l); fileNameLabelMnemonic = UIManager.getInt("FileChooser.fileNameLabelMnemonic"); fileNameLabelText = UIManager.getString("FileChooser.fileNameLabelText",l); folderNameLabelMnemonic = UIManager.getInt("FileChooser.folderNameLabelMnemonic"); folderNameLabelText = UIManager.getString("FileChooser.folderNameLabelText",l); filesOfTypeLabelMnemonic = UIManager.getInt("FileChooser.filesOfTypeLabelMnemonic"); filesOfTypeLabelText = UIManager.getString("FileChooser.filesOfTypeLabelText",l); upFolderToolTipText = UIManager.getString("FileChooser.upFolderToolTipText",l); upFolderAccessibleName = UIManager.getString("FileChooser.upFolderAccessibleName",l); homeFolderToolTipText = UIManager.getString("FileChooser.homeFolderToolTipText",l); homeFolderAccessibleName = UIManager.getString("FileChooser.homeFolderAccessibleName",l); newFolderToolTipText = UIManager.getString("FileChooser.newFolderToolTipText",l); newFolderAccessibleName = UIManager.getString("FileChooser.newFolderAccessibleName",l); listViewButtonToolTipText = UIManager.getString("FileChooser.listViewButtonToolTipText",l); listViewButtonAccessibleName = UIManager.getString("FileChooser.listViewButtonAccessibleName",l); detailsViewButtonToolTipText = UIManager.getString("FileChooser.detailsViewButtonToolTipText",l); detailsViewButtonAccessibleName = UIManager.getString("FileChooser.detailsViewButtonAccessibleName",l); } protected void installListeners(JFileChooser fc) { super.installListeners(fc); ActionMap actionMap = getActionMap(); SwingUtilities.replaceUIActionMap(fc, actionMap); } protected ActionMap getActionMap() { return createActionMap(); } protected ActionMap createActionMap() { ActionMap map = new ActionMapUIResource(); FilePane.addActionsToMap(map, filePane.getActions()); return map; } protected JPanel createList(JFileChooser fc) { return filePane.createList(); } protected JPanel createDetailsView(JFileChooser fc) { return filePane.createDetailsView(); } /** {@collect.stats} * Creates a selection listener for the list of files and directories. * * @param fc a <code>JFileChooser</code> * @return a <code>ListSelectionListener</code> */ public ListSelectionListener createListSelectionListener(JFileChooser fc) { return super.createListSelectionListener(fc); } // Obsolete class, not used in this version. protected class SingleClickListener extends MouseAdapter { public SingleClickListener(JList list) { } } // Obsolete class, not used in this version. protected class FileRenderer extends DefaultListCellRenderer { } public void uninstallUI(JComponent c) { // Remove listeners c.removePropertyChangeListener(filterComboBoxModel); c.removePropertyChangeListener(filePane); cancelButton.removeActionListener(getCancelSelectionAction()); approveButton.removeActionListener(getApproveSelectionAction()); fileNameTextField.removeActionListener(getApproveSelectionAction()); if (filePane != null) { filePane.uninstallUI(); filePane = null; } super.uninstallUI(c); } /** {@collect.stats} * Returns the preferred size of the specified * <code>JFileChooser</code>. * The preferred size is at least as large, * in both height and width, * as the preferred size recommended * by the file chooser's layout manager. * * @param c a <code>JFileChooser</code> * @return a <code>Dimension</code> specifying the preferred * width and height of the file chooser */ public Dimension getPreferredSize(JComponent c) { int prefWidth = PREF_SIZE.width; Dimension d = c.getLayout().preferredLayoutSize(c); if (d != null) { return new Dimension(d.width < prefWidth ? prefWidth : d.width, d.height < PREF_SIZE.height ? PREF_SIZE.height : d.height); } else { return new Dimension(prefWidth, PREF_SIZE.height); } } /** {@collect.stats} * Returns the minimum size of the <code>JFileChooser</code>. * * @param c a <code>JFileChooser</code> * @return a <code>Dimension</code> specifying the minimum * width and height of the file chooser */ public Dimension getMinimumSize(JComponent c) { return MIN_SIZE; } /** {@collect.stats} * Returns the maximum size of the <code>JFileChooser</code>. * * @param c a <code>JFileChooser</code> * @return a <code>Dimension</code> specifying the maximum * width and height of the file chooser */ public Dimension getMaximumSize(JComponent c) { return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); } private String fileNameString(File file) { if (file == null) { return null; } else { JFileChooser fc = getFileChooser(); if ((fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) || (fc.isDirectorySelectionEnabled() && fc.isFileSelectionEnabled() && fc.getFileSystemView().isFileSystemRoot(file))) { return file.getPath(); } else { return file.getName(); } } } private String fileNameString(File[] files) { StringBuffer buf = new StringBuffer(); for (int i = 0; files != null && i < files.length; i++) { if (i > 0) { buf.append(" "); } if (files.length > 1) { buf.append("\""); } buf.append(fileNameString(files[i])); if (files.length > 1) { buf.append("\""); } } return buf.toString(); } /* The following methods are used by the PropertyChange Listener */ private void doSelectedFileChanged(PropertyChangeEvent e) { File f = (File) e.getNewValue(); JFileChooser fc = getFileChooser(); if (f != null && ((fc.isFileSelectionEnabled() && !f.isDirectory()) || (f.isDirectory() && fc.isDirectorySelectionEnabled()))) { setFileName(fileNameString(f)); } } private void doSelectedFilesChanged(PropertyChangeEvent e) { File[] files = (File[]) e.getNewValue(); JFileChooser fc = getFileChooser(); if (files != null && files.length > 0 && (files.length > 1 || fc.isDirectorySelectionEnabled() || !files[0].isDirectory())) { setFileName(fileNameString(files)); } } private void doDirectoryChanged(PropertyChangeEvent e) { JFileChooser fc = getFileChooser(); FileSystemView fsv = fc.getFileSystemView(); clearIconCache(); File currentDirectory = fc.getCurrentDirectory(); if(currentDirectory != null) { directoryComboBoxModel.addItem(currentDirectory); if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) { if (fsv.isFileSystem(currentDirectory)) { setFileName(currentDirectory.getPath()); } else { setFileName(null); } } } } private void doFilterChanged(PropertyChangeEvent e) { clearIconCache(); } private void doFileSelectionModeChanged(PropertyChangeEvent e) { if (fileNameLabel != null) { populateFileNameLabel(); } clearIconCache(); JFileChooser fc = getFileChooser(); File currentDirectory = fc.getCurrentDirectory(); if (currentDirectory != null && fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled() && fc.getFileSystemView().isFileSystem(currentDirectory)) { setFileName(currentDirectory.getPath()); } else { setFileName(null); } } private void doAccessoryChanged(PropertyChangeEvent e) { if(getAccessoryPanel() != null) { if(e.getOldValue() != null) { getAccessoryPanel().remove((JComponent) e.getOldValue()); } JComponent accessory = (JComponent) e.getNewValue(); if(accessory != null) { getAccessoryPanel().add(accessory, BorderLayout.CENTER); } } } private void doApproveButtonTextChanged(PropertyChangeEvent e) { JFileChooser chooser = getFileChooser(); approveButton.setText(getApproveButtonText(chooser)); approveButton.setToolTipText(getApproveButtonToolTipText(chooser)); } private void doDialogTypeChanged(PropertyChangeEvent e) { JFileChooser chooser = getFileChooser(); approveButton.setText(getApproveButtonText(chooser)); approveButton.setToolTipText(getApproveButtonToolTipText(chooser)); if (chooser.getDialogType() == JFileChooser.SAVE_DIALOG) { lookInLabel.setText(saveInLabelText); } else { lookInLabel.setText(lookInLabelText); } } private void doApproveButtonMnemonicChanged(PropertyChangeEvent e) { // Note: Metal does not use mnemonics for approve and cancel } private void doControlButtonsChanged(PropertyChangeEvent e) { if(getFileChooser().getControlButtonsAreShown()) { addControlButtons(); } else { removeControlButtons(); } } /* * Listen for filechooser property changes, such as * the selected file changing, or the type of the dialog changing. */ public PropertyChangeListener createPropertyChangeListener(JFileChooser fc) { return new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String s = e.getPropertyName(); if(s.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) { doSelectedFileChanged(e); } else if (s.equals(JFileChooser.SELECTED_FILES_CHANGED_PROPERTY)) { doSelectedFilesChanged(e); } else if(s.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) { doDirectoryChanged(e); } else if(s.equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) { doFilterChanged(e); } else if(s.equals(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY)) { doFileSelectionModeChanged(e); } else if(s.equals(JFileChooser.ACCESSORY_CHANGED_PROPERTY)) { doAccessoryChanged(e); } else if (s.equals(JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY) || s.equals(JFileChooser.APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY)) { doApproveButtonTextChanged(e); } else if(s.equals(JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY)) { doDialogTypeChanged(e); } else if(s.equals(JFileChooser.APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY)) { doApproveButtonMnemonicChanged(e); } else if(s.equals(JFileChooser.CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY)) { doControlButtonsChanged(e); } else if (s.equals("componentOrientation")) { ComponentOrientation o = (ComponentOrientation)e.getNewValue(); JFileChooser cc = (JFileChooser)e.getSource(); if (o != (ComponentOrientation)e.getOldValue()) { cc.applyComponentOrientation(o); } } else if (s == "FileChooser.useShellFolder") { updateUseShellFolder(); doDirectoryChanged(e); } else if (s.equals("ancestor")) { if (e.getOldValue() == null && e.getNewValue() != null) { // Ancestor was added, set initial focus fileNameTextField.selectAll(); fileNameTextField.requestFocus(); } } } }; } protected void removeControlButtons() { getBottomPanel().remove(getButtonPanel()); } protected void addControlButtons() { getBottomPanel().add(getButtonPanel()); } public void ensureFileIsVisible(JFileChooser fc, File f) { filePane.ensureFileIsVisible(fc, f); } public void rescanCurrentDirectory(JFileChooser fc) { filePane.rescanCurrentDirectory(); } public String getFileName() { if (fileNameTextField != null) { return fileNameTextField.getText(); } else { return null; } } public void setFileName(String filename) { if (fileNameTextField != null) { fileNameTextField.setText(filename); } } /** {@collect.stats} * Property to remember whether a directory is currently selected in the UI. * This is normally called by the UI on a selection event. * * @param directorySelected if a directory is currently selected. * @since 1.4 */ protected void setDirectorySelected(boolean directorySelected) { super.setDirectorySelected(directorySelected); JFileChooser chooser = getFileChooser(); if(directorySelected) { if (approveButton != null) { approveButton.setText(directoryOpenButtonText); approveButton.setToolTipText(directoryOpenButtonToolTipText); } } else { if (approveButton != null) { approveButton.setText(getApproveButtonText(chooser)); approveButton.setToolTipText(getApproveButtonToolTipText(chooser)); } } } public String getDirectoryName() { // PENDING(jeff) - get the name from the directory combobox return null; } public void setDirectoryName(String dirname) { // PENDING(jeff) - set the name in the directory combobox } protected DirectoryComboBoxRenderer createDirectoryComboBoxRenderer(JFileChooser fc) { return new DirectoryComboBoxRenderer(); } // // Renderer for DirectoryComboBox // class DirectoryComboBoxRenderer extends DefaultListCellRenderer { IndentIcon ii = new IndentIcon(); public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value == null) { setText(""); return this; } File directory = (File)value; setText(getFileChooser().getName(directory)); Icon icon = getFileChooser().getIcon(directory); ii.icon = icon; ii.depth = directoryComboBoxModel.getDepth(index); setIcon(ii); return this; } } final static int space = 10; class IndentIcon implements Icon { Icon icon = null; int depth = 0; public void paintIcon(Component c, Graphics g, int x, int y) { if (c.getComponentOrientation().isLeftToRight()) { icon.paintIcon(c, g, x+depth*space, y); } else { icon.paintIcon(c, g, x, y); } } public int getIconWidth() { return icon.getIconWidth() + depth*space; } public int getIconHeight() { return icon.getIconHeight(); } } // // DataModel for DirectoryComboxbox // protected DirectoryComboBoxModel createDirectoryComboBoxModel(JFileChooser fc) { return new DirectoryComboBoxModel(); } /** {@collect.stats} * Data model for a type-face selection combo-box. */ protected class DirectoryComboBoxModel extends AbstractListModel implements ComboBoxModel { Vector directories = new Vector(); int[] depths = null; File selectedDirectory = null; JFileChooser chooser = getFileChooser(); FileSystemView fsv = chooser.getFileSystemView(); public DirectoryComboBoxModel() { // Add the current directory to the model, and make it the // selectedDirectory File dir = getFileChooser().getCurrentDirectory(); if(dir != null) { addItem(dir); } } /** {@collect.stats} * Adds the directory to the model and sets it to be selected, * additionally clears out the previous selected directory and * the paths leading up to it, if any. */ private void addItem(File directory) { if(directory == null) { return; } directories.clear(); File[] baseFolders; if (useShellFolder) { baseFolders = AccessController.doPrivileged(new PrivilegedAction<File[]>() { public File[] run() { return (File[]) ShellFolder.get("fileChooserComboBoxFolders"); } }); } else { baseFolders = fsv.getRoots(); } directories.addAll(Arrays.asList(baseFolders)); // Get the canonical (full) path. This has the side // benefit of removing extraneous chars from the path, // for example /foo/bar/ becomes /foo/bar File canonical = null; try { canonical = ShellFolder.getNormalizedFile(directory); } catch (IOException e) { // Maybe drive is not ready. Can't abort here. canonical = directory; } // create File instances of each directory leading up to the top try { File sf = useShellFolder ? ShellFolder.getShellFolder(canonical) : canonical; File f = sf; Vector path = new Vector(10); do { path.addElement(f); } while ((f = f.getParentFile()) != null); int pathCount = path.size(); // Insert chain at appropriate place in vector for (int i = 0; i < pathCount; i++) { f = (File)path.get(i); if (directories.contains(f)) { int topIndex = directories.indexOf(f); for (int j = i-1; j >= 0; j--) { directories.insertElementAt(path.get(j), topIndex+i-j); } break; } } calculateDepths(); setSelectedItem(sf); } catch (FileNotFoundException ex) { calculateDepths(); } } private void calculateDepths() { depths = new int[directories.size()]; for (int i = 0; i < depths.length; i++) { File dir = (File)directories.get(i); File parent = dir.getParentFile(); depths[i] = 0; if (parent != null) { for (int j = i-1; j >= 0; j--) { if (parent.equals((File)directories.get(j))) { depths[i] = depths[j] + 1; break; } } } } } public int getDepth(int i) { return (depths != null && i >= 0 && i < depths.length) ? depths[i] : 0; } public void setSelectedItem(Object selectedDirectory) { this.selectedDirectory = (File)selectedDirectory; fireContentsChanged(this, -1, -1); } public Object getSelectedItem() { return selectedDirectory; } public int getSize() { return directories.size(); } public Object getElementAt(int index) { return directories.elementAt(index); } } // // Renderer for Types ComboBox // protected FilterComboBoxRenderer createFilterComboBoxRenderer() { return new FilterComboBoxRenderer(); } /** {@collect.stats} * Render different type sizes and styles. */ public class FilterComboBoxRenderer extends DefaultListCellRenderer { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value != null && value instanceof FileFilter) { setText(((FileFilter)value).getDescription()); } return this; } } // // DataModel for Types Comboxbox // protected FilterComboBoxModel createFilterComboBoxModel() { return new FilterComboBoxModel(); } /** {@collect.stats} * Data model for a type-face selection combo-box. */ protected class FilterComboBoxModel extends AbstractListModel implements ComboBoxModel, PropertyChangeListener { protected FileFilter[] filters; protected FilterComboBoxModel() { super(); filters = getFileChooser().getChoosableFileFilters(); } public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if(prop == JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) { filters = (FileFilter[]) e.getNewValue(); fireContentsChanged(this, -1, -1); } else if (prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY) { fireContentsChanged(this, -1, -1); } } public void setSelectedItem(Object filter) { if(filter != null) { getFileChooser().setFileFilter((FileFilter) filter); fireContentsChanged(this, -1, -1); } } public Object getSelectedItem() { // Ensure that the current filter is in the list. // NOTE: we shouldnt' have to do this, since JFileChooser adds // the filter to the choosable filters list when the filter // is set. Lets be paranoid just in case someone overrides // setFileFilter in JFileChooser. FileFilter currentFilter = getFileChooser().getFileFilter(); boolean found = false; if(currentFilter != null) { for(int i=0; i < filters.length; i++) { if(filters[i] == currentFilter) { found = true; } } if(found == false) { getFileChooser().addChoosableFileFilter(currentFilter); } } return getFileChooser().getFileFilter(); } public int getSize() { if(filters != null) { return filters.length; } else { return 0; } } public Object getElementAt(int index) { if(index > getSize() - 1) { // This shouldn't happen. Try to recover gracefully. return getFileChooser().getFileFilter(); } if(filters != null) { return filters[index]; } else { return null; } } } public void valueChanged(ListSelectionEvent e) { JFileChooser fc = getFileChooser(); File f = fc.getSelectedFile(); if (!e.getValueIsAdjusting() && f != null && !getFileChooser().isTraversable(f)) { setFileName(fileNameString(f)); } } /** {@collect.stats} * Acts when DirectoryComboBox has changed the selected item. */ protected class DirectoryComboBoxAction extends AbstractAction { protected DirectoryComboBoxAction() { super("DirectoryComboBoxAction"); } public void actionPerformed(ActionEvent e) { directoryComboBox.hidePopup(); File f = (File)directoryComboBox.getSelectedItem(); if (!getFileChooser().getCurrentDirectory().equals(f)) { getFileChooser().setCurrentDirectory(f); } } } protected JButton getApproveButton(JFileChooser fc) { return approveButton; } /** {@collect.stats} * <code>ButtonAreaLayout</code> behaves in a similar manner to * <code>FlowLayout</code>. It lays out all components from left to * right, flushed right. The widths of all components will be set * to the largest preferred size width. */ private static class ButtonAreaLayout implements LayoutManager { private int hGap = 5; private int topMargin = 17; public void addLayoutComponent(String string, Component comp) { } public void layoutContainer(Container container) { Component[] children = container.getComponents(); if (children != null && children.length > 0) { int numChildren = children.length; Dimension[] sizes = new Dimension[numChildren]; Insets insets = container.getInsets(); int yLocation = insets.top + topMargin; int maxWidth = 0; for (int counter = 0; counter < numChildren; counter++) { sizes[counter] = children[counter].getPreferredSize(); maxWidth = Math.max(maxWidth, sizes[counter].width); } int xLocation, xOffset; if (container.getComponentOrientation().isLeftToRight()) { xLocation = container.getSize().width - insets.left - maxWidth; xOffset = hGap + maxWidth; } else { xLocation = insets.left; xOffset = -(hGap + maxWidth); } for (int counter = numChildren - 1; counter >= 0; counter--) { children[counter].setBounds(xLocation, yLocation, maxWidth, sizes[counter].height); xLocation -= xOffset; } } } public Dimension minimumLayoutSize(Container c) { if (c != null) { Component[] children = c.getComponents(); if (children != null && children.length > 0) { int numChildren = children.length; int height = 0; Insets cInsets = c.getInsets(); int extraHeight = topMargin + cInsets.top + cInsets.bottom; int extraWidth = cInsets.left + cInsets.right; int maxWidth = 0; for (int counter = 0; counter < numChildren; counter++) { Dimension aSize = children[counter].getPreferredSize(); height = Math.max(height, aSize.height); maxWidth = Math.max(maxWidth, aSize.width); } return new Dimension(extraWidth + numChildren * maxWidth + (numChildren - 1) * hGap, extraHeight + height); } } return new Dimension(0, 0); } public Dimension preferredLayoutSize(Container c) { return minimumLayoutSize(c); } public void removeLayoutComponent(Component c) { } } private static void groupLabels(AlignedLabel[] group) { for (int i = 0; i < group.length; i++) { group[i].group = group; } } private class AlignedLabel extends JLabel { private AlignedLabel[] group; private int maxWidth = 0; AlignedLabel() { super(); setAlignmentX(JComponent.LEFT_ALIGNMENT); } AlignedLabel(String text) { super(text); setAlignmentX(JComponent.LEFT_ALIGNMENT); } public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); // Align the width with all other labels in group. return new Dimension(getMaxWidth() + 11, d.height); } private int getMaxWidth() { if (maxWidth == 0 && group != null) { int max = 0; for (int i = 0; i < group.length; i++) { max = Math.max(group[i].getSuperPreferredWidth(), max); } for (int i = 0; i < group.length; i++) { group[i].maxWidth = max; } } return maxWidth; } private int getSuperPreferredWidth() { return super.getPreferredSize().width; } } }
Java
/* * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.*; import javax.swing.border.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.BasicBorders; import javax.swing.text.JTextComponent; import java.awt.Component; import java.awt.Insets; import java.awt.Color; import java.awt.Dialog; import java.awt.Frame; import java.awt.Graphics; import java.awt.Window; import sun.swing.StringUIClientPropertyKey; /** {@collect.stats} * Factory object that can vend Borders appropriate for the metal L & F. * @author Steve Wilson */ public class MetalBorders { /** {@collect.stats} * Client property indicating the button shouldn't provide a rollover * indicator. Only used with the Ocean theme. */ static Object NO_BUTTON_ROLLOVER = new StringUIClientPropertyKey("NoButtonRollover"); public static class Flush3DBorder extends AbstractBorder implements UIResource{ public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { if (c.isEnabled()) { MetalUtils.drawFlush3DBorder(g, x, y, w, h); } else { MetalUtils.drawDisabledBorder(g, x, y, w, h); } } public Insets getBorderInsets(Component c) { return new Insets(2, 2, 2, 2); } public Insets getBorderInsets(Component c, Insets newInsets) { newInsets.top = 2; newInsets.left = 2; newInsets.bottom = 2; newInsets.right = 2; return newInsets; } } public static class ButtonBorder extends AbstractBorder implements UIResource { protected static Insets borderInsets = new Insets( 3, 3, 3, 3 ); public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { if (MetalLookAndFeel.usingOcean()) { paintOceanBorder(c, g, x, y, w, h); return; } AbstractButton button = (AbstractButton)c; ButtonModel model = button.getModel(); if ( model.isEnabled() ) { boolean isPressed = model.isPressed() && model.isArmed(); boolean isDefault = (button instanceof JButton && ((JButton)button).isDefaultButton()); if (isPressed && isDefault) { MetalUtils.drawDefaultButtonPressedBorder(g, x, y, w, h); } else if (isPressed) { MetalUtils.drawPressed3DBorder( g, x, y, w, h ); } else if (isDefault) { MetalUtils.drawDefaultButtonBorder( g, x, y, w, h, false); } else { MetalUtils.drawButtonBorder( g, x, y, w, h, false); } } else { // disabled state MetalUtils.drawDisabledBorder( g, x, y, w-1, h-1 ); } } private void paintOceanBorder(Component c, Graphics g, int x, int y, int w, int h) { AbstractButton button = (AbstractButton)c; ButtonModel model = ((AbstractButton)c).getModel(); g.translate(x, y); if (MetalUtils.isToolBarButton(button)) { if (model.isEnabled()) { if (model.isPressed()) { g.setColor(MetalLookAndFeel.getWhite()); g.fillRect(1, h - 1, w - 1, 1); g.fillRect(w - 1, 1, 1, h - 1); g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 2, h - 2); g.fillRect(1, 1, w - 3, 1); } else if (model.isSelected() || model.isRollover()) { g.setColor(MetalLookAndFeel.getWhite()); g.fillRect(1, h - 1, w - 1, 1); g.fillRect(w - 1, 1, 1, h - 1); g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 2, h - 2); } else { g.setColor(MetalLookAndFeel.getWhite()); g.drawRect(1, 1, w - 2, h - 2); g.setColor(UIManager.getColor( "Button.toolBarBorderBackground")); g.drawRect(0, 0, w - 2, h - 2); } } else { g.setColor(UIManager.getColor( "Button.disabledToolBarBorderBackground")); g.drawRect(0, 0, w - 2, h - 2); } } else if (model.isEnabled()) { boolean pressed = model.isPressed(); boolean armed = model.isArmed(); if ((c instanceof JButton) && ((JButton)c).isDefaultButton()) { g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 1, h - 1); g.drawRect(1, 1, w - 3, h - 3); } else if (pressed) { g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.fillRect(0, 0, w, 2); g.fillRect(0, 2, 2, h - 2); g.fillRect(w - 1, 1, 1, h - 1); g.fillRect(1, h - 1, w - 2, 1); } else if (model.isRollover() && button.getClientProperty( NO_BUTTON_ROLLOVER) == null) { g.setColor(MetalLookAndFeel.getPrimaryControl()); g.drawRect(0, 0, w - 1, h - 1); g.drawRect(2, 2, w - 5, h - 5); g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(1, 1, w - 3, h - 3); } else { g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 1, h - 1); } } else { g.setColor(MetalLookAndFeel.getInactiveControlTextColor()); g.drawRect(0, 0, w - 1, h - 1); if ((c instanceof JButton) && ((JButton)c).isDefaultButton()) { g.drawRect(1, 1, w - 3, h - 3); } } } public Insets getBorderInsets( Component c ) { return new Insets(3, 3, 3, 3); } public Insets getBorderInsets(Component c, Insets newInsets) { newInsets.top = 3; newInsets.left = 3; newInsets.bottom = 3; newInsets.right = 3; return newInsets; } } public static class InternalFrameBorder extends AbstractBorder implements UIResource { private static final int corner = 14; public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { Color background; Color highlight; Color shadow; if (c instanceof JInternalFrame && ((JInternalFrame)c).isSelected()) { background = MetalLookAndFeel.getPrimaryControlDarkShadow(); highlight = MetalLookAndFeel.getPrimaryControlShadow(); shadow = MetalLookAndFeel.getPrimaryControlInfo(); } else { background = MetalLookAndFeel.getControlDarkShadow(); highlight = MetalLookAndFeel.getControlShadow(); shadow = MetalLookAndFeel.getControlInfo(); } g.setColor(background); // Draw outermost lines g.drawLine( 1, 0, w-2, 0); g.drawLine( 0, 1, 0, h-2); g.drawLine( w-1, 1, w-1, h-2); g.drawLine( 1, h-1, w-2, h-1); // Draw the bulk of the border for (int i = 1; i < 5; i++) { g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1); } if (c instanceof JInternalFrame && ((JInternalFrame)c).isResizable()) { g.setColor(highlight); // Draw the Long highlight lines g.drawLine( corner+1, 3, w-corner, 3); g.drawLine( 3, corner+1, 3, h-corner); g.drawLine( w-2, corner+1, w-2, h-corner); g.drawLine( corner+1, h-2, w-corner, h-2); g.setColor(shadow); // Draw the Long shadow lines g.drawLine( corner, 2, w-corner-1, 2); g.drawLine( 2, corner, 2, h-corner-1); g.drawLine( w-3, corner, w-3, h-corner-1); g.drawLine( corner, h-3, w-corner-1, h-3); } } public Insets getBorderInsets(Component c) { return new Insets(5, 5, 5, 5); } public Insets getBorderInsets(Component c, Insets newInsets) { newInsets.top = 5; newInsets.left = 5; newInsets.bottom = 5; newInsets.right = 5; return newInsets; } } /** {@collect.stats} * Border for a Frame. * @since 1.4 */ static class FrameBorder extends AbstractBorder implements UIResource { private static final int corner = 14; public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { Color background; Color highlight; Color shadow; Window window = SwingUtilities.getWindowAncestor(c); if (window != null && window.isActive()) { background = MetalLookAndFeel.getPrimaryControlDarkShadow(); highlight = MetalLookAndFeel.getPrimaryControlShadow(); shadow = MetalLookAndFeel.getPrimaryControlInfo(); } else { background = MetalLookAndFeel.getControlDarkShadow(); highlight = MetalLookAndFeel.getControlShadow(); shadow = MetalLookAndFeel.getControlInfo(); } g.setColor(background); // Draw outermost lines g.drawLine( x+1, y+0, x+w-2, y+0); g.drawLine( x+0, y+1, x+0, y +h-2); g.drawLine( x+w-1, y+1, x+w-1, y+h-2); g.drawLine( x+1, y+h-1, x+w-2, y+h-1); // Draw the bulk of the border for (int i = 1; i < 5; i++) { g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1); } if ((window instanceof Frame) && ((Frame) window).isResizable()) { g.setColor(highlight); // Draw the Long highlight lines g.drawLine( corner+1, 3, w-corner, 3); g.drawLine( 3, corner+1, 3, h-corner); g.drawLine( w-2, corner+1, w-2, h-corner); g.drawLine( corner+1, h-2, w-corner, h-2); g.setColor(shadow); // Draw the Long shadow lines g.drawLine( corner, 2, w-corner-1, 2); g.drawLine( 2, corner, 2, h-corner-1); g.drawLine( w-3, corner, w-3, h-corner-1); g.drawLine( corner, h-3, w-corner-1, h-3); } } public Insets getBorderInsets(Component c) { return new Insets(5, 5, 5, 5); } public Insets getBorderInsets(Component c, Insets newInsets) { newInsets.top = 5; newInsets.left = 5; newInsets.bottom = 5; newInsets.right = 5; return newInsets; } } /** {@collect.stats} * Border for a Frame. * @since 1.4 */ static class DialogBorder extends AbstractBorder implements UIResource { private static final int corner = 14; protected Color getActiveBackground() { return MetalLookAndFeel.getPrimaryControlDarkShadow(); } protected Color getActiveHighlight() { return MetalLookAndFeel.getPrimaryControlShadow(); } protected Color getActiveShadow() { return MetalLookAndFeel.getPrimaryControlInfo(); } protected Color getInactiveBackground() { return MetalLookAndFeel.getControlDarkShadow(); } protected Color getInactiveHighlight() { return MetalLookAndFeel.getControlShadow(); } protected Color getInactiveShadow() { return MetalLookAndFeel.getControlInfo(); } public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { Color background; Color highlight; Color shadow; Window window = SwingUtilities.getWindowAncestor(c); if (window != null && window.isActive()) { background = getActiveBackground(); highlight = getActiveHighlight(); shadow = getActiveShadow(); } else { background = getInactiveBackground(); highlight = getInactiveHighlight(); shadow = getInactiveShadow(); } g.setColor(background); // Draw outermost lines g.drawLine( x + 1, y + 0, x + w-2, y + 0); g.drawLine( x + 0, y + 1, x + 0, y + h - 2); g.drawLine( x + w - 1, y + 1, x + w - 1, y + h - 2); g.drawLine( x + 1, y + h - 1, x + w - 2, y + h - 1); // Draw the bulk of the border for (int i = 1; i < 5; i++) { g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1); } if ((window instanceof Dialog) && ((Dialog) window).isResizable()) { g.setColor(highlight); // Draw the Long highlight lines g.drawLine( corner+1, 3, w-corner, 3); g.drawLine( 3, corner+1, 3, h-corner); g.drawLine( w-2, corner+1, w-2, h-corner); g.drawLine( corner+1, h-2, w-corner, h-2); g.setColor(shadow); // Draw the Long shadow lines g.drawLine( corner, 2, w-corner-1, 2); g.drawLine( 2, corner, 2, h-corner-1); g.drawLine( w-3, corner, w-3, h-corner-1); g.drawLine( corner, h-3, w-corner-1, h-3); } } public Insets getBorderInsets(Component c) { return new Insets(5, 5, 5, 5); } public Insets getBorderInsets(Component c, Insets newInsets) { newInsets.top = 5; newInsets.left = 5; newInsets.bottom = 5; newInsets.right = 5; return newInsets; } } /** {@collect.stats} * Border for an Error Dialog. * @since 1.4 */ static class ErrorDialogBorder extends DialogBorder implements UIResource { protected Color getActiveBackground() { return UIManager.getColor("OptionPane.errorDialog.border.background"); } } /** {@collect.stats} * Border for a QuestionDialog. Also used for a JFileChooser and a * JColorChooser.. * @since 1.4 */ static class QuestionDialogBorder extends DialogBorder implements UIResource { protected Color getActiveBackground() { return UIManager.getColor("OptionPane.questionDialog.border.background"); } } /** {@collect.stats} * Border for a Warning Dialog. * @since 1.4 */ static class WarningDialogBorder extends DialogBorder implements UIResource { protected Color getActiveBackground() { return UIManager.getColor("OptionPane.warningDialog.border.background"); } } /** {@collect.stats} * Border for a Palette. * @since 1.3 */ public static class PaletteBorder extends AbstractBorder implements UIResource { int titleHeight = 0; public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { g.translate(x,y); g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); g.drawLine(0, 1, 0, h-2); g.drawLine(1, h-1, w-2, h-1); g.drawLine(w-1, 1, w-1, h-2); g.drawLine( 1, 0, w-2, 0); g.drawRect(1,1, w-3, h-3); g.translate(-x,-y); } public Insets getBorderInsets(Component c) { return new Insets(1, 1, 1, 1); } public Insets getBorderInsets(Component c, Insets newInsets) { newInsets.top = 1; newInsets.left = 1; newInsets.bottom = 1; newInsets.right = 1; return newInsets; } } public static class OptionDialogBorder extends AbstractBorder implements UIResource { int titleHeight = 0; public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { g.translate(x,y); int messageType = JOptionPane.PLAIN_MESSAGE; if (c instanceof JInternalFrame) { Object obj = ((JInternalFrame) c).getClientProperty( "JInternalFrame.messageType"); if (obj != null && (obj instanceof Integer)) { messageType = ((Integer) obj).intValue(); } } Color borderColor; switch (messageType) { case(JOptionPane.ERROR_MESSAGE): borderColor = UIManager.getColor( "OptionPane.errorDialog.border.background"); break; case(JOptionPane.QUESTION_MESSAGE): borderColor = UIManager.getColor( "OptionPane.questionDialog.border.background"); break; case(JOptionPane.WARNING_MESSAGE): borderColor = UIManager.getColor( "OptionPane.warningDialog.border.background"); break; case(JOptionPane.INFORMATION_MESSAGE): case(JOptionPane.PLAIN_MESSAGE): default: borderColor = MetalLookAndFeel.getPrimaryControlDarkShadow(); break; } g.setColor(borderColor); // Draw outermost lines g.drawLine( 1, 0, w-2, 0); g.drawLine( 0, 1, 0, h-2); g.drawLine( w-1, 1, w-1, h-2); g.drawLine( 1, h-1, w-2, h-1); // Draw the bulk of the border for (int i = 1; i < 3; i++) { g.drawRect(i, i, w-(i*2)-1, h-(i*2)-1); } g.translate(-x,-y); } public Insets getBorderInsets(Component c) { return new Insets(3, 3, 3, 3); } public Insets getBorderInsets(Component c, Insets newInsets) { newInsets.top = 3; newInsets.left = 3; newInsets.bottom = 3; newInsets.right = 3; return newInsets; } } public static class MenuBarBorder extends AbstractBorder implements UIResource { protected static Insets borderInsets = new Insets( 1, 0, 1, 0 ); public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { g.translate( x, y ); if (MetalLookAndFeel.usingOcean()) { // Only paint a border if we're not next to a horizontal // toolbar if (!MetalToolBarUI.doesMenuBarBorderToolBar((JMenuBar)c)) { g.setColor(MetalLookAndFeel.getControl()); g.drawLine(0, h - 2, w, h - 2); g.setColor(UIManager.getColor("MenuBar.borderColor")); g.drawLine(0, h - 1, w, h - 1); } } else { g.setColor( MetalLookAndFeel.getControlShadow() ); g.drawLine( 0, h-1, w, h-1 ); } g.translate( -x, -y ); } public Insets getBorderInsets( Component c ) { return getBorderInsets(c, new Insets(0, 0, 0, 0)); } public Insets getBorderInsets(Component c, Insets newInsets) { if (MetalLookAndFeel.usingOcean()) { newInsets.set(0, 0, 2, 0); } else { newInsets.top = 1; newInsets.left = 0; newInsets.bottom = 1; newInsets.right = 0; } return newInsets; } } public static class MenuItemBorder extends AbstractBorder implements UIResource { protected static Insets borderInsets = new Insets( 2, 2, 2, 2 ); public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { JMenuItem b = (JMenuItem) c; ButtonModel model = b.getModel(); g.translate( x, y ); if ( c.getParent() instanceof JMenuBar ) { if ( model.isArmed() || model.isSelected() ) { g.setColor( MetalLookAndFeel.getControlDarkShadow() ); g.drawLine( 0, 0, w - 2, 0 ); g.drawLine( 0, 0, 0, h - 1 ); g.drawLine( w - 2, 2, w - 2, h - 1 ); g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() ); g.drawLine( w - 1, 1, w - 1, h - 1 ); g.setColor( MetalLookAndFeel.getMenuBackground() ); g.drawLine( w - 1, 0, w - 1, 0 ); } } else { if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) ) { g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() ); g.drawLine( 0, 0, w - 1, 0 ); g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() ); g.drawLine( 0, h - 1, w - 1, h - 1 ); } else { g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() ); g.drawLine( 0, 0, 0, h - 1 ); } } g.translate( -x, -y ); } public Insets getBorderInsets( Component c ) { return new Insets(2, 2, 2, 2); } public Insets getBorderInsets(Component c, Insets newInsets) { newInsets.top = 2; newInsets.left = 2; newInsets.bottom = 2; newInsets.right = 2; return newInsets; } } public static class PopupMenuBorder extends AbstractBorder implements UIResource { protected static Insets borderInsets = new Insets( 3, 1, 2, 1 ); public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { g.translate( x, y ); g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() ); g.drawRect( 0, 0, w - 1, h - 1 ); g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() ); g.drawLine( 1, 1, w - 2, 1 ); g.drawLine( 1, 2, 1, 2 ); g.drawLine( 1, h - 2, 1, h - 2 ); g.translate( -x, -y ); } public Insets getBorderInsets( Component c ) { return new Insets(3, 1, 2, 1); } public Insets getBorderInsets(Component c, Insets newInsets) { newInsets.top = 3; newInsets.left = 1; newInsets.bottom = 2; newInsets.right = 1; return newInsets; } } public static class RolloverButtonBorder extends ButtonBorder { public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); if ( model.isRollover() && !( model.isPressed() && !model.isArmed() ) ) { super.paintBorder( c, g, x, y, w, h ); } } } /** {@collect.stats} * A border which is like a Margin border but it will only honor the margin * if the margin has been explicitly set by the developer. * * Note: This is identical to the package private class * BasicBorders.RolloverMarginBorder and should probably be consolidated. */ static class RolloverMarginBorder extends EmptyBorder { public RolloverMarginBorder() { super(3,3,3,3); // hardcoded margin for JLF requirements. } public Insets getBorderInsets(Component c) { return getBorderInsets(c, new Insets(0,0,0,0)); } public Insets getBorderInsets(Component c, Insets insets) { Insets margin = null; if (c instanceof AbstractButton) { margin = ((AbstractButton)c).getMargin(); } if (margin == null || margin instanceof UIResource) { // default margin so replace insets.left = left; insets.top = top; insets.right = right; insets.bottom = bottom; } else { // Margin which has been explicitly set by the user. insets.left = margin.left; insets.top = margin.top; insets.right = margin.right; insets.bottom = margin.bottom; } return insets; } } public static class ToolBarBorder extends AbstractBorder implements UIResource, SwingConstants { protected MetalBumps bumps = new MetalBumps( 10, 10, MetalLookAndFeel.getControlHighlight(), MetalLookAndFeel.getControlDarkShadow(), UIManager.getColor("ToolBar.background")); public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { g.translate( x, y ); if ( ((JToolBar) c).isFloatable() ) { if ( ((JToolBar) c).getOrientation() == HORIZONTAL ) { int shift = MetalLookAndFeel.usingOcean() ? -1 : 0; bumps.setBumpArea( 10, h - 4 ); if( MetalUtils.isLeftToRight(c) ) { bumps.paintIcon( c, g, 2, 2 + shift ); } else { bumps.paintIcon( c, g, w-12, 2 + shift ); } } else // vertical { bumps.setBumpArea( w - 4, 10 ); bumps.paintIcon( c, g, 2, 2 ); } } if (((JToolBar) c).getOrientation() == HORIZONTAL && MetalLookAndFeel.usingOcean()) { g.setColor(MetalLookAndFeel.getControl()); g.drawLine(0, h - 2, w, h - 2); g.setColor(UIManager.getColor("ToolBar.borderColor")); g.drawLine(0, h - 1, w, h - 1); } g.translate( -x, -y ); } public Insets getBorderInsets( Component c ) { return getBorderInsets(c, new Insets(0,0,0,0)); } public Insets getBorderInsets(Component c, Insets newInsets) { if (MetalLookAndFeel.usingOcean()) { newInsets.set(1, 2, 3, 2); } else { newInsets.top = newInsets.left = newInsets.bottom = newInsets.right = 2; } if ( ((JToolBar) c).isFloatable() ) { if ( ((JToolBar) c).getOrientation() == HORIZONTAL ) { if (c.getComponentOrientation().isLeftToRight()) { newInsets.left = 16; } else { newInsets.right = 16; } } else {// vertical newInsets.top = 16; } } Insets margin = ((JToolBar) c).getMargin(); if ( margin != null ) { newInsets.left += margin.left; newInsets.top += margin.top; newInsets.right += margin.right; newInsets.bottom += margin.bottom; } return newInsets; } } private static Border buttonBorder; /** {@collect.stats} * Returns a border instance for a JButton * @since 1.3 */ public static Border getButtonBorder() { if (buttonBorder == null) { buttonBorder = new BorderUIResource.CompoundBorderUIResource( new MetalBorders.ButtonBorder(), new BasicBorders.MarginBorder()); } return buttonBorder; } private static Border textBorder; /** {@collect.stats} * Returns a border instance for a text component * @since 1.3 */ public static Border getTextBorder() { if (textBorder == null) { textBorder = new BorderUIResource.CompoundBorderUIResource( new MetalBorders.Flush3DBorder(), new BasicBorders.MarginBorder()); } return textBorder; } private static Border textFieldBorder; /** {@collect.stats} * Returns a border instance for a JTextField * @since 1.3 */ public static Border getTextFieldBorder() { if (textFieldBorder == null) { textFieldBorder = new BorderUIResource.CompoundBorderUIResource( new MetalBorders.TextFieldBorder(), new BasicBorders.MarginBorder()); } return textFieldBorder; } public static class TextFieldBorder extends Flush3DBorder { public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { if (!(c instanceof JTextComponent)) { // special case for non-text components (bug ID 4144840) if (c.isEnabled()) { MetalUtils.drawFlush3DBorder(g, x, y, w, h); } else { MetalUtils.drawDisabledBorder(g, x, y, w, h); } return; } if (c.isEnabled() && ((JTextComponent)c).isEditable()) { MetalUtils.drawFlush3DBorder(g, x, y, w, h); } else { MetalUtils.drawDisabledBorder(g, x, y, w, h); } } } public static class ScrollPaneBorder extends AbstractBorder implements UIResource { public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { JScrollPane scroll = (JScrollPane)c; JComponent colHeader = scroll.getColumnHeader(); int colHeaderHeight = 0; if (colHeader != null) colHeaderHeight = colHeader.getHeight(); JComponent rowHeader = scroll.getRowHeader(); int rowHeaderWidth = 0; if (rowHeader != null) rowHeaderWidth = rowHeader.getWidth(); g.translate( x, y); g.setColor( MetalLookAndFeel.getControlDarkShadow() ); g.drawRect( 0, 0, w-2, h-2 ); g.setColor( MetalLookAndFeel.getControlHighlight() ); g.drawLine( w-1, 1, w-1, h-1); g.drawLine( 1, h-1, w-1, h-1); g.setColor( MetalLookAndFeel.getControl() ); g.drawLine( w-2, 2+colHeaderHeight, w-2, 2+colHeaderHeight ); g.drawLine( 1+rowHeaderWidth, h-2, 1+rowHeaderWidth, h-2 ); g.translate( -x, -y); } public Insets getBorderInsets(Component c) { return new Insets(1, 1, 2, 2); } } private static Border toggleButtonBorder; /** {@collect.stats} * Returns a border instance for a JToggleButton * @since 1.3 */ public static Border getToggleButtonBorder() { if (toggleButtonBorder == null) { toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource( new MetalBorders.ToggleButtonBorder(), new BasicBorders.MarginBorder()); } return toggleButtonBorder; } /** {@collect.stats} * @since 1.3 */ public static class ToggleButtonBorder extends ButtonBorder { public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { AbstractButton button = (AbstractButton)c; ButtonModel model = button.getModel(); if (MetalLookAndFeel.usingOcean()) { if(model.isArmed() || !button.isEnabled()) { super.paintBorder(c, g, x, y, w, h); } else { g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 1, h - 1); } return; } if (! c.isEnabled() ) { MetalUtils.drawDisabledBorder( g, x, y, w-1, h-1 ); } else { if ( model.isPressed() && model.isArmed() ) { MetalUtils.drawPressed3DBorder( g, x, y, w, h ); } else if ( model.isSelected() ) { MetalUtils.drawDark3DBorder( g, x, y, w, h ); } else { MetalUtils.drawFlush3DBorder( g, x, y, w, h ); } } } } /** {@collect.stats} * Border for a Table Header * @since 1.3 */ public static class TableHeaderBorder extends javax.swing.border.AbstractBorder { protected Insets editorBorderInsets = new Insets( 2, 2, 2, 0 ); public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { g.translate( x, y ); g.setColor( MetalLookAndFeel.getControlDarkShadow() ); g.drawLine( w-1, 0, w-1, h-1 ); g.drawLine( 1, h-1, w-1, h-1 ); g.setColor( MetalLookAndFeel.getControlHighlight() ); g.drawLine( 0, 0, w-2, 0 ); g.drawLine( 0, 0, 0, h-2 ); g.translate( -x, -y ); } public Insets getBorderInsets( Component c ) { return editorBorderInsets; } } /** {@collect.stats} * Returns a border instance for a Desktop Icon * @since 1.3 */ public static Border getDesktopIconBorder() { return new BorderUIResource.CompoundBorderUIResource( new LineBorder(MetalLookAndFeel.getControlDarkShadow(), 1), new MatteBorder (2,2,1,2, MetalLookAndFeel.getControl())); } static Border getToolBarRolloverBorder() { if (MetalLookAndFeel.usingOcean()) { return new CompoundBorder( new MetalBorders.ButtonBorder(), new MetalBorders.RolloverMarginBorder()); } return new CompoundBorder(new MetalBorders.RolloverButtonBorder(), new MetalBorders.RolloverMarginBorder()); } static Border getToolBarNonrolloverBorder() { if (MetalLookAndFeel.usingOcean()) { new CompoundBorder( new MetalBorders.ButtonBorder(), new MetalBorders.RolloverMarginBorder()); } return new CompoundBorder(new MetalBorders.ButtonBorder(), new MetalBorders.RolloverMarginBorder()); } }
Java
/* * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.*; import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Frame; import java.awt.Graphics; import java.awt.GraphicsEnvironment; import java.awt.Insets; import java.awt.Point; import java.awt.Rectangle; import java.awt.event.*; import java.lang.ref.WeakReference; import java.util.*; import java.beans.PropertyChangeListener; import javax.swing.event.*; import javax.swing.border.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; /** {@collect.stats} * A Metal Look and Feel implementation of ToolBarUI. This implementation * is a "combined" view/controller. * <p> * * @author Jeff Shapiro */ public class MetalToolBarUI extends BasicToolBarUI { /** {@collect.stats} * An array of WeakReferences that point to JComponents. This will contain * instances of JToolBars and JMenuBars and is used to find * JToolBars/JMenuBars that border each other. */ private static java.util.List components = new ArrayList(); /** {@collect.stats} * This protected field is implemenation specific. Do not access directly * or override. Use the create method instead. * * @see #createContainerListener */ protected ContainerListener contListener; /** {@collect.stats} * This protected field is implemenation specific. Do not access directly * or override. Use the create method instead. * * @see #createRolloverListener */ protected PropertyChangeListener rolloverListener; private static Border nonRolloverBorder; /** {@collect.stats} * Last menubar the toolbar touched. This is only useful for ocean. */ private JMenuBar lastMenuBar; /** {@collect.stats} * Registers the specified component. */ synchronized static void register(JComponent c) { if (c == null) { // Exception is thrown as convenience for callers that are // typed to throw an NPE. throw new NullPointerException("JComponent must be non-null"); } components.add(new WeakReference(c)); } /** {@collect.stats} * Unregisters the specified component. */ synchronized static void unregister(JComponent c) { for (int counter = components.size() - 1; counter >= 0; counter--) { // Search for the component, removing any flushed references // along the way. WeakReference ref = (WeakReference)components.get(counter); Object target = ((WeakReference)components.get(counter)).get(); if (target == c || target == null) { components.remove(counter); } } } /** {@collect.stats} * Finds a previously registered component of class <code>target</code> * that shares the JRootPane ancestor of <code>from</code>. */ synchronized static Object findRegisteredComponentOfType(JComponent from, Class target) { JRootPane rp = SwingUtilities.getRootPane(from); if (rp != null) { for (int counter = components.size() - 1; counter >= 0; counter--){ Object component = ((WeakReference)components.get(counter)). get(); if (component == null) { // WeakReference has gone away, remove the WeakReference components.remove(counter); } else if (target.isInstance(component) && SwingUtilities. getRootPane((Component)component) == rp) { return component; } } } return null; } /** {@collect.stats} * Returns true if the passed in JMenuBar is above a horizontal * JToolBar. */ static boolean doesMenuBarBorderToolBar(JMenuBar c) { JToolBar tb = (JToolBar)MetalToolBarUI. findRegisteredComponentOfType(c, JToolBar.class); if (tb != null && tb.getOrientation() == JToolBar.HORIZONTAL) { JRootPane rp = SwingUtilities.getRootPane(c); Point point = new Point(0, 0); point = SwingUtilities.convertPoint(c, point, rp); int menuX = point.x; int menuY = point.y; point.x = point.y = 0; point = SwingUtilities.convertPoint(tb, point, rp); return (point.x == menuX && menuY + c.getHeight() == point.y && c.getWidth() == tb.getWidth()); } return false; } public static ComponentUI createUI( JComponent c ) { return new MetalToolBarUI(); } public void installUI( JComponent c ) { super.installUI( c ); register(c); } public void uninstallUI( JComponent c ) { super.uninstallUI( c ); nonRolloverBorder = null; unregister(c); } protected void installListeners() { super.installListeners(); contListener = createContainerListener(); if (contListener != null) { toolBar.addContainerListener(contListener); } rolloverListener = createRolloverListener(); if (rolloverListener != null) { toolBar.addPropertyChangeListener(rolloverListener); } } protected void uninstallListeners() { super.uninstallListeners(); if (contListener != null) { toolBar.removeContainerListener(contListener); } rolloverListener = createRolloverListener(); if (rolloverListener != null) { toolBar.removePropertyChangeListener(rolloverListener); } } protected Border createRolloverBorder() { return super.createRolloverBorder(); } protected Border createNonRolloverBorder() { return super.createNonRolloverBorder(); } /** {@collect.stats} * Creates a non rollover border for Toggle buttons in the toolbar. */ private Border createNonRolloverToggleBorder() { return createNonRolloverBorder(); } protected void setBorderToNonRollover(Component c) { if (c instanceof JToggleButton && !(c instanceof JCheckBox)) { // 4735514, 4886944: The method createNonRolloverToggleBorder() is // private in BasicToolBarUI so we can't override it. We still need // to call super from this method so that it can save away the // original border and then we install ours. // Before calling super we get a handle to the old border, because // super will install a non-UIResource border that we can't // distinguish from one provided by an application. JToggleButton b = (JToggleButton)c; Border border = b.getBorder(); super.setBorderToNonRollover(c); if (border instanceof UIResource) { if (nonRolloverBorder == null) { nonRolloverBorder = createNonRolloverToggleBorder(); } b.setBorder(nonRolloverBorder); } } else { super.setBorderToNonRollover(c); } } /** {@collect.stats} * Creates a container listener that will be added to the JToolBar. * If this method returns null then it will not be added to the * toolbar. * * @return an instance of a <code>ContainerListener</code> or null */ protected ContainerListener createContainerListener() { return null; } /** {@collect.stats} * Creates a property change listener that will be added to the JToolBar. * If this method returns null then it will not be added to the * toolbar. * * @return an instance of a <code>PropertyChangeListener</code> or null */ protected PropertyChangeListener createRolloverListener() { return null; } protected MouseInputListener createDockingListener( ) { return new MetalDockingListener( toolBar ); } protected void setDragOffset(Point p) { if (!GraphicsEnvironment.isHeadless()) { if (dragWindow == null) { dragWindow = createDragWindow(toolBar); } dragWindow.setOffset(p); } } /** {@collect.stats} * If necessary paints the background of the component, then invokes * <code>paint</code>. * * @param g Graphics to paint to * @param c JComponent painting on * @throws NullPointerException if <code>g</code> or <code>c</code> is * null * @see javax.swing.plaf.ComponentUI#update * @see javax.swing.plaf.ComponentUI#paint * @since 1.5 */ public void update(Graphics g, JComponent c) { if (g == null) { throw new NullPointerException("graphics must be non-null"); } if (c.isOpaque() && (c.getBackground() instanceof UIResource) && ((JToolBar)c).getOrientation() == JToolBar.HORIZONTAL && UIManager.get( "MenuBar.gradient") != null) { JRootPane rp = SwingUtilities.getRootPane(c); JMenuBar mb = (JMenuBar)findRegisteredComponentOfType( c, JMenuBar.class); if (mb != null && mb.isOpaque() && (mb.getBackground() instanceof UIResource)) { Point point = new Point(0, 0); point = SwingUtilities.convertPoint(c, point, rp); int x = point.x; int y = point.y; point.x = point.y = 0; point = SwingUtilities.convertPoint(mb, point, rp); if (point.x == x && y == point.y + mb.getHeight() && mb.getWidth() == c.getWidth() && MetalUtils.drawGradient(c, g, "MenuBar.gradient", 0, -mb.getHeight(), c.getWidth(), c.getHeight() + mb.getHeight(), true)) { setLastMenuBar(mb); paint(g, c); return; } } if (MetalUtils.drawGradient(c, g, "MenuBar.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) { setLastMenuBar(null); paint(g, c); return; } } setLastMenuBar(null); super.update(g, c); } private void setLastMenuBar(JMenuBar lastMenuBar) { if (MetalLookAndFeel.usingOcean()) { if (this.lastMenuBar != lastMenuBar) { // The menubar we previously touched has changed, force it // to repaint. if (this.lastMenuBar != null) { this.lastMenuBar.repaint(); } if (lastMenuBar != null) { lastMenuBar.repaint(); } this.lastMenuBar = lastMenuBar; } } } // No longer used. Cannot remove for compatibility reasons protected class MetalContainerListener extends BasicToolBarUI.ToolBarContListener {} // No longer used. Cannot remove for compatibility reasons protected class MetalRolloverListener extends BasicToolBarUI.PropertyListener {} protected class MetalDockingListener extends DockingListener { private boolean pressedInBumps = false; public MetalDockingListener(JToolBar t) { super(t); } public void mousePressed(MouseEvent e) { super.mousePressed(e); if (!toolBar.isEnabled()) { return; } pressedInBumps = false; Rectangle bumpRect = new Rectangle(); if (toolBar.getOrientation() == JToolBar.HORIZONTAL) { int x = MetalUtils.isLeftToRight(toolBar) ? 0 : toolBar.getSize().width-14; bumpRect.setBounds(x, 0, 14, toolBar.getSize().height); } else { // vertical bumpRect.setBounds(0, 0, toolBar.getSize().width, 14); } if (bumpRect.contains(e.getPoint())) { pressedInBumps = true; Point dragOffset = e.getPoint(); if (!MetalUtils.isLeftToRight(toolBar)) { dragOffset.x -= (toolBar.getSize().width - toolBar.getPreferredSize().width); } setDragOffset(dragOffset); } } public void mouseDragged(MouseEvent e) { if (pressedInBumps) { super.mouseDragged(e); } } } // end class MetalDockingListener }
Java
/* * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.beans.*; import java.io.*; import java.util.*; import javax.swing.plaf.*; import javax.swing.tree.*; import javax.swing.plaf.basic.*; /** {@collect.stats} * The metal look and feel implementation of <code>TreeUI</code>. * <p> * <code>MetalTreeUI</code> allows for configuring how to * visually render the spacing and delineation between nodes. The following * hints are supported: * * <table summary="Descriptions of supported hints: Angled, Horizontal, and None"> * <tr> * <th><p align="left">Angled</p></th> * <td>A line is drawn connecting the child to the parent. For handling * of the root node refer to * {@link javax.swing.JTree#setRootVisible} and * {@link javax.swing.JTree#setShowsRootHandles}. * </td> * </tr> * <tr> * <th><p align="left">Horizontal</p></th> * <td>A horizontal line is drawn dividing the children of the root node.</td> * </tr> * <tr> * <th><p align="left">None</p></th> * <td>Do not draw any visual indication between nodes.</td> * </tr> * </table> * * <p> * As it is typically impratical to obtain the <code>TreeUI</code> from * the <code>JTree</code> and cast to an instance of <code>MetalTreeUI</code> * you enable this property via the client property * <code>JTree.lineStyle</code>. For example, to switch to * <code>Horizontal</code> style you would do: * <code>tree.putClientProperty("JTree.lineStyle", "Horizontal");</code> * <p> * The default is <code>Angled</code>. * * @author Tom Santos * @author Steve Wilson (value add stuff) */ public class MetalTreeUI extends BasicTreeUI { private static Color lineColor; private static final String LINE_STYLE = "JTree.lineStyle"; private static final String LEG_LINE_STYLE_STRING = "Angled"; private static final String HORIZ_STYLE_STRING = "Horizontal"; private static final String NO_STYLE_STRING = "None"; private static final int LEG_LINE_STYLE = 2; private static final int HORIZ_LINE_STYLE = 1; private static final int NO_LINE_STYLE = 0; private int lineStyle = LEG_LINE_STYLE; private PropertyChangeListener lineStyleListener = new LineListener(); // Boilerplate public static ComponentUI createUI(JComponent x) { return new MetalTreeUI(); } public MetalTreeUI() { super(); } protected int getHorizontalLegBuffer() { return 3; } public void installUI( JComponent c ) { super.installUI( c ); lineColor = UIManager.getColor( "Tree.line" ); Object lineStyleFlag = c.getClientProperty( LINE_STYLE ); decodeLineStyle(lineStyleFlag); c.addPropertyChangeListener(lineStyleListener); } public void uninstallUI( JComponent c) { c.removePropertyChangeListener(lineStyleListener); super.uninstallUI(c); } /** {@collect.stats} this function converts between the string passed into the client property * and the internal representation (currently and int) * */ protected void decodeLineStyle(Object lineStyleFlag) { if ( lineStyleFlag == null || lineStyleFlag.equals(LEG_LINE_STYLE_STRING)){ lineStyle = LEG_LINE_STYLE; // default case } else { if ( lineStyleFlag.equals(NO_STYLE_STRING) ) { lineStyle = NO_LINE_STYLE; } else if ( lineStyleFlag.equals(HORIZ_STYLE_STRING) ) { lineStyle = HORIZ_LINE_STYLE; } } } protected boolean isLocationInExpandControl(int row, int rowLevel, int mouseX, int mouseY) { if(tree != null && !isLeaf(row)) { int boxWidth; if(getExpandedIcon() != null) boxWidth = getExpandedIcon().getIconWidth() + 6; else boxWidth = 8; Insets i = tree.getInsets(); int boxLeftX = (i != null) ? i.left : 0; boxLeftX += (((rowLevel + depthOffset - 1) * totalChildIndent) + getLeftChildIndent()) - boxWidth/2; int boxRightX = boxLeftX + boxWidth; return mouseX >= boxLeftX && mouseX <= boxRightX; } return false; } public void paint(Graphics g, JComponent c) { super.paint( g, c ); // Paint the lines if (lineStyle == HORIZ_LINE_STYLE && !largeModel) { paintHorizontalSeparators(g,c); } } protected void paintHorizontalSeparators(Graphics g, JComponent c) { g.setColor( lineColor ); Rectangle clipBounds = g.getClipBounds(); int beginRow = getRowForPath(tree, getClosestPathForLocation (tree, 0, clipBounds.y)); int endRow = getRowForPath(tree, getClosestPathForLocation (tree, 0, clipBounds.y + clipBounds.height - 1)); if ( beginRow <= -1 || endRow <= -1 ) { return; } for ( int i = beginRow; i <= endRow; ++i ) { TreePath path = getPathForRow(tree, i); if(path != null && path.getPathCount() == 2) { Rectangle rowBounds = getPathBounds(tree,getPathForRow (tree, i)); // Draw a line at the top if(rowBounds != null) g.drawLine(clipBounds.x, rowBounds.y, clipBounds.x + clipBounds.width, rowBounds.y); } } } protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, TreePath path) { if (lineStyle == LEG_LINE_STYLE) { super.paintVerticalPartOfLeg(g, clipBounds, insets, path); } } protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) { if (lineStyle == LEG_LINE_STYLE) { super.paintHorizontalPartOfLeg(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf); } } /** {@collect.stats} This class listens for changes in line style */ class LineListener implements PropertyChangeListener { public void propertyChange(PropertyChangeEvent e) { String name = e.getPropertyName(); if ( name.equals( LINE_STYLE ) ) { decodeLineStyle(e.getNewValue()); } } } // end class PaletteListener }
Java
/* * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import java.awt.*; import java.awt.event.*; import javax.swing.plaf.basic.*; import javax.swing.*; import javax.swing.plaf.*; import javax.swing.border.*; import java.io.Serializable; /** {@collect.stats} * JButton subclass to help out MetalComboBoxUI * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @see MetalComboBoxButton * @author Tom Santos */ public class MetalComboBoxButton extends JButton { protected JComboBox comboBox; protected JList listBox; protected CellRendererPane rendererPane; protected Icon comboIcon; protected boolean iconOnly = false; public final JComboBox getComboBox() { return comboBox;} public final void setComboBox( JComboBox cb ) { comboBox = cb;} public final Icon getComboIcon() { return comboIcon;} public final void setComboIcon( Icon i ) { comboIcon = i;} public final boolean isIconOnly() { return iconOnly;} public final void setIconOnly( boolean isIconOnly ) { iconOnly = isIconOnly;} MetalComboBoxButton() { super( "" ); DefaultButtonModel model = new DefaultButtonModel() { public void setArmed( boolean armed ) { super.setArmed( isPressed() ? true : armed ); } }; setModel( model ); } public MetalComboBoxButton( JComboBox cb, Icon i, CellRendererPane pane, JList list ) { this(); comboBox = cb; comboIcon = i; rendererPane = pane; listBox = list; setEnabled( comboBox.isEnabled() ); } public MetalComboBoxButton( JComboBox cb, Icon i, boolean onlyIcon, CellRendererPane pane, JList list ) { this( cb, i, pane, list ); iconOnly = onlyIcon; } public boolean isFocusTraversable() { return false; } public void setEnabled(boolean enabled) { super.setEnabled(enabled); // Set the background and foreground to the combobox colors. if (enabled) { setBackground(comboBox.getBackground()); setForeground(comboBox.getForeground()); } else { setBackground(UIManager.getColor("ComboBox.disabledBackground")); setForeground(UIManager.getColor("ComboBox.disabledForeground")); } } public void paintComponent( Graphics g ) { boolean leftToRight = MetalUtils.isLeftToRight(comboBox); // Paint the button as usual super.paintComponent( g ); Insets insets = getInsets(); int width = getWidth() - (insets.left + insets.right); int height = getHeight() - (insets.top + insets.bottom); if ( height <= 0 || width <= 0 ) { return; } int left = insets.left; int top = insets.top; int right = left + (width - 1); int bottom = top + (height - 1); int iconWidth = 0; int iconLeft = (leftToRight) ? right : left; // Paint the icon if ( comboIcon != null ) { iconWidth = comboIcon.getIconWidth(); int iconHeight = comboIcon.getIconHeight(); int iconTop = 0; if ( iconOnly ) { iconLeft = (getWidth() / 2) - (iconWidth / 2); iconTop = (getHeight() / 2) - (iconHeight / 2); } else { if (leftToRight) { iconLeft = (left + (width - 1)) - iconWidth; } else { iconLeft = left; } iconTop = (top + ((bottom - top) / 2)) - (iconHeight / 2); } comboIcon.paintIcon( this, g, iconLeft, iconTop ); // Paint the focus if ( comboBox.hasFocus() && (!MetalLookAndFeel.usingOcean() || comboBox.isEditable())) { g.setColor( MetalLookAndFeel.getFocusColor() ); g.drawRect( left - 1, top - 1, width + 3, height + 1 ); } } if (MetalLookAndFeel.usingOcean()) { // With Ocean the button only paints the arrow, bail. return; } // Let the renderer paint if ( ! iconOnly && comboBox != null ) { ListCellRenderer renderer = comboBox.getRenderer(); Component c; boolean renderPressed = getModel().isPressed(); c = renderer.getListCellRendererComponent(listBox, comboBox.getSelectedItem(), -1, renderPressed, false); c.setFont(rendererPane.getFont()); if ( model.isArmed() && model.isPressed() ) { if ( isOpaque() ) { c.setBackground(UIManager.getColor("Button.select")); } c.setForeground(comboBox.getForeground()); } else if ( !comboBox.isEnabled() ) { if ( isOpaque() ) { c.setBackground(UIManager.getColor("ComboBox.disabledBackground")); } c.setForeground(UIManager.getColor("ComboBox.disabledForeground")); } else { c.setForeground(comboBox.getForeground()); c.setBackground(comboBox.getBackground()); } int cWidth = width - (insets.right + iconWidth); // Fix for 4238829: should lay out the JPanel. boolean shouldValidate = false; if (c instanceof JPanel) { shouldValidate = true; } if (leftToRight) { rendererPane.paintComponent( g, c, this, left, top, cWidth, height, shouldValidate ); } else { rendererPane.paintComponent( g, c, this, left + iconWidth, top, cWidth, height, shouldValidate ); } } } public Dimension getMinimumSize() { Dimension ret = new Dimension(); Insets insets = getInsets(); ret.width = insets.left + getComboIcon().getIconWidth() + insets.right; ret.height = insets.bottom + getComboIcon().getIconHeight() + insets.top; return ret; } }
Java
/* * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.plaf.*; import javax.swing.*; import java.awt.*; import sun.awt.AppContext; import sun.security.action.GetPropertyAction; import sun.swing.SwingUtilities2; /** {@collect.stats} * A concrete implementation of {@code MetalTheme} providing * the original look of the Java Look and Feel, code-named "Steel". Refer * to {@link MetalLookAndFeel#setCurrentTheme} for details on changing * the default theme. * <p> * All colors returned by {@code DefaultMetalTheme} are completely * opaque. * * <h3><a name="fontStyle"></a>Font Style</h3> * * {@code DefaultMetalTheme} uses bold fonts for many controls. To make all * controls (with the exception of the internal frame title bars and * client decorated frame title bars) use plain fonts you can do either of * the following: * <ul> * <li>Set the system property <code>swing.boldMetal</code> to * <code>false</code>. For example, * <code>java&nbsp;-Dswing.boldMetal=false&nbsp;MyApp</code>. * <li>Set the defaults property <code>swing.boldMetal</code> to * <code>Boolean.FALSE</code>. For example: * <code>UIManager.put("swing.boldMetal",&nbsp;Boolean.FALSE);</code> * </ul> * The defaults property <code>swing.boldMetal</code>, if set, * takes precendence over the system property of the same name. After * setting this defaults property you need to re-install * <code>MetalLookAndFeel</code>, as well as update the UI * of any previously created widgets. Otherwise the results are undefined. * The following illustrates how to do this: * <pre> * // turn off bold fonts * UIManager.put("swing.boldMetal", Boolean.FALSE); * * // re-install the Metal Look and Feel * UIManager.setLookAndFeel(new MetalLookAndFeel()); * * // Update the ComponentUIs for all Components. This * // needs to be invoked for all windows. * SwingUtilities.updateComponentTreeUI(rootComponent); * </pre> * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @see MetalLookAndFeel * @see MetalLookAndFeel#setCurrentTheme * * @author Steve Wilson */ public class DefaultMetalTheme extends MetalTheme { /** {@collect.stats} * Whether or not fonts should be plain. This is only used if * the defaults property 'swing.boldMetal' == "false". */ private static final boolean PLAIN_FONTS; /** {@collect.stats} * Names of the fonts to use. */ private static final String[] fontNames = { Font.DIALOG,Font.DIALOG,Font.DIALOG,Font.DIALOG,Font.DIALOG,Font.DIALOG }; /** {@collect.stats} * Styles for the fonts. This is ignored if the defaults property * <code>swing.boldMetal</code> is false, or PLAIN_FONTS is true. */ private static final int[] fontStyles = { Font.BOLD, Font.PLAIN, Font.PLAIN, Font.BOLD, Font.BOLD, Font.PLAIN }; /** {@collect.stats} * Sizes for the fonts. */ private static final int[] fontSizes = { 12, 12, 12, 12, 12, 10 }; // note the properties listed here can currently be used by people // providing runtimes to hint what fonts are good. For example the bold // dialog font looks bad on a Mac, so Apple could use this property to // hint at a good font. // // However, we don't promise to support these forever. We may move // to getting these from the swing.properties file, or elsewhere. /** {@collect.stats} * System property names used to look up fonts. */ private static final String[] defaultNames = { "swing.plaf.metal.controlFont", "swing.plaf.metal.systemFont", "swing.plaf.metal.userFont", "swing.plaf.metal.controlFont", "swing.plaf.metal.controlFont", "swing.plaf.metal.smallFont" }; /** {@collect.stats} * Returns the ideal font name for the font identified by key. */ static String getDefaultFontName(int key) { return fontNames[key]; } /** {@collect.stats} * Returns the ideal font size for the font identified by key. */ static int getDefaultFontSize(int key) { return fontSizes[key]; } /** {@collect.stats} * Returns the ideal font style for the font identified by key. */ static int getDefaultFontStyle(int key) { if (key != WINDOW_TITLE_FONT) { Object boldMetal = null; if (AppContext.getAppContext().get( SwingUtilities2.LAF_STATE_KEY) != null) { // Only access the boldMetal key if a look and feel has // been loaded, otherwise we'll trigger loading the look // and feel. boldMetal = UIManager.get("swing.boldMetal"); } if (boldMetal != null) { if (Boolean.FALSE.equals(boldMetal)) { return Font.PLAIN; } } else if (PLAIN_FONTS) { return Font.PLAIN; } } return fontStyles[key]; } /** {@collect.stats} * Returns the default used to look up the specified font. */ static String getDefaultPropertyName(int key) { return defaultNames[key]; } static { Object boldProperty = java.security.AccessController.doPrivileged( new GetPropertyAction("swing.boldMetal")); if (boldProperty == null || !"false".equals(boldProperty)) { PLAIN_FONTS = false; } else { PLAIN_FONTS = true; } } private static final ColorUIResource primary1 = new ColorUIResource( 102, 102, 153); private static final ColorUIResource primary2 = new ColorUIResource(153, 153, 204); private static final ColorUIResource primary3 = new ColorUIResource( 204, 204, 255); private static final ColorUIResource secondary1 = new ColorUIResource( 102, 102, 102); private static final ColorUIResource secondary2 = new ColorUIResource( 153, 153, 153); private static final ColorUIResource secondary3 = new ColorUIResource( 204, 204, 204); private FontDelegate fontDelegate; /** {@collect.stats} * Returns the name of this theme. This returns {@code "Steel"}. * * @return the name of this theme. */ public String getName() { return "Steel"; } /** {@collect.stats} * Creates and returns an instance of {@code DefaultMetalTheme}. */ public DefaultMetalTheme() { install(); } /** {@collect.stats} * Returns the primary 1 color. This returns a color with rgb values * of 102, 102, and 153, respectively. * * @return the primary 1 color */ protected ColorUIResource getPrimary1() { return primary1; } /** {@collect.stats} * Returns the primary 2 color. This returns a color with rgb values * of 153, 153, 204, respectively. * * @return the primary 2 color */ protected ColorUIResource getPrimary2() { return primary2; } /** {@collect.stats} * Returns the primary 3 color. This returns a color with rgb values * 204, 204, 255, respectively. * * @return the primary 3 color */ protected ColorUIResource getPrimary3() { return primary3; } /** {@collect.stats} * Returns the secondary 1 color. This returns a color with rgb values * 102, 102, and 102, respectively. * * @return the secondary 1 color */ protected ColorUIResource getSecondary1() { return secondary1; } /** {@collect.stats} * Returns the secondary 2 color. This returns a color with rgb values * 153, 153, and 153, respectively. * * @return the secondary 2 color */ protected ColorUIResource getSecondary2() { return secondary2; } /** {@collect.stats} * Returns the secondary 3 color. This returns a color with rgb values * 204, 204, and 204, respectively. * * @return the secondary 3 color */ protected ColorUIResource getSecondary3() { return secondary3; } /** {@collect.stats} * Returns the control text font. This returns Dialog, 12pt. If * plain fonts have been enabled as described in <a href="#fontStyle"> * font style</a>, the font style is plain. Otherwise the font style is * bold. * * @return the control text font */ public FontUIResource getControlTextFont() { return getFont(CONTROL_TEXT_FONT); } /** {@collect.stats} * Returns the system text font. This returns Dialog, 12pt, plain. * * @return the sytem text font */ public FontUIResource getSystemTextFont() { return getFont(SYSTEM_TEXT_FONT); } /** {@collect.stats} * Returns the user text font. This returns Dialog, 12pt, plain. * * @return the user text font */ public FontUIResource getUserTextFont() { return getFont(USER_TEXT_FONT); } /** {@collect.stats} * Returns the menu text font. This returns Dialog, 12pt. If * plain fonts have been enabled as described in <a href="#fontStyle"> * font style</a>, the font style is plain. Otherwise the font style is * bold. * * @return the menu text font */ public FontUIResource getMenuTextFont() { return getFont(MENU_TEXT_FONT); } /** {@collect.stats} * Returns the window title font. This returns Dialog, 12pt, bold. * * @return the window title font */ public FontUIResource getWindowTitleFont() { return getFont(WINDOW_TITLE_FONT); } /** {@collect.stats} * Returns the sub-text font. This returns Dialog, 10pt, plain. * * @return the sub-text font */ public FontUIResource getSubTextFont() { return getFont(SUB_TEXT_FONT); } private FontUIResource getFont(int key) { return fontDelegate.getFont(key); } void install() { if (MetalLookAndFeel.isWindows() && MetalLookAndFeel.useSystemFonts()) { fontDelegate = new WindowsFontDelegate(); } else { fontDelegate = new FontDelegate(); } } /** {@collect.stats} * Returns true if this is a theme provided by the core platform. */ boolean isSystemTheme() { return (getClass() == DefaultMetalTheme.class); } /** {@collect.stats} * FontDelegates add an extra level of indirection to obtaining fonts. */ private static class FontDelegate { private static int[] defaultMapping = { CONTROL_TEXT_FONT, SYSTEM_TEXT_FONT, USER_TEXT_FONT, CONTROL_TEXT_FONT, CONTROL_TEXT_FONT, SUB_TEXT_FONT }; FontUIResource fonts[]; // menu and window are mapped to controlFont public FontDelegate() { fonts = new FontUIResource[6]; } public FontUIResource getFont(int type) { int mappedType = defaultMapping[type]; if (fonts[type] == null) { Font f = getPrivilegedFont(mappedType); if (f == null) { f = new Font(getDefaultFontName(type), getDefaultFontStyle(type), getDefaultFontSize(type)); } fonts[type] = new FontUIResource(f); } return fonts[type]; } /** {@collect.stats} * This is the same as invoking * <code>Font.getFont(key)</code>, with the exception * that it is wrapped inside a <code>doPrivileged</code> call. */ protected Font getPrivilegedFont(final int key) { return (Font)java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() { public Object run() { return Font.getFont(getDefaultPropertyName(key)); } } ); } } /** {@collect.stats} * The WindowsFontDelegate uses DesktopProperties to obtain fonts. */ private static class WindowsFontDelegate extends FontDelegate { private MetalFontDesktopProperty[] props; private boolean[] checkedPriviledged; public WindowsFontDelegate() { props = new MetalFontDesktopProperty[6]; checkedPriviledged = new boolean[6]; } public FontUIResource getFont(int type) { if (fonts[type] != null) { return fonts[type]; } if (!checkedPriviledged[type]) { Font f = getPrivilegedFont(type); checkedPriviledged[type] = true; if (f != null) { fonts[type] = new FontUIResource(f); return fonts[type]; } } if (props[type] == null) { props[type] = new MetalFontDesktopProperty(type); } // While passing null may seem bad, we don't actually use // the table and looking it up is rather expensive. return (FontUIResource)props[type].createValue(null); } } }
Java
/* * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.*; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Insets; import java.awt.Rectangle; import javax.swing.plaf.*; import javax.swing.plaf.basic.BasicSeparatorUI; /** {@collect.stats} * A Metal L&F implementation of SeparatorUI. This implementation * is a "combined" view/controller. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Jeff Shapiro */ public class MetalSeparatorUI extends BasicSeparatorUI { public static ComponentUI createUI( JComponent c ) { return new MetalSeparatorUI(); } protected void installDefaults( JSeparator s ) { LookAndFeel.installColors( s, "Separator.background", "Separator.foreground" ); } public void paint( Graphics g, JComponent c ) { Dimension s = c.getSize(); if ( ((JSeparator)c).getOrientation() == JSeparator.VERTICAL ) { g.setColor( c.getForeground() ); g.drawLine( 0, 0, 0, s.height ); g.setColor( c.getBackground() ); g.drawLine( 1, 0, 1, s.height ); } else // HORIZONTAL { g.setColor( c.getForeground() ); g.drawLine( 0, 0, s.width, 0 ); g.setColor( c.getBackground() ); g.drawLine( 0, 1, s.width, 1 ); } } public Dimension getPreferredSize( JComponent c ) { if ( ((JSeparator)c).getOrientation() == JSeparator.VERTICAL ) return new Dimension( 2, 0 ); else return new Dimension( 0, 2 ); } }
Java
/* * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.plaf.basic.BasicSliderUI; import java.awt.Graphics; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.Color; import java.beans.*; import javax.swing.*; import javax.swing.plaf.*; /** {@collect.stats} * A Java L&F implementation of SliderUI. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Tom Santos */ public class MetalSliderUI extends BasicSliderUI { protected final int TICK_BUFFER = 4; protected boolean filledSlider = false; // NOTE: these next five variables are currently unused. protected static Color thumbColor; protected static Color highlightColor; protected static Color darkShadowColor; protected static int trackWidth; protected static int tickLength; private int safeLength; /** {@collect.stats} * A default horizontal thumb <code>Icon</code>. This field might not be * used. To change the <code>Icon</code> used by this delgate directly set it * using the <code>Slider.horizontalThumbIcon</code> UIManager property. */ protected static Icon horizThumbIcon; /** {@collect.stats} * A default vertical thumb <code>Icon</code>. This field might not be * used. To change the <code>Icon</code> used by this delgate directly set it * using the <code>Slider.verticalThumbIcon</code> UIManager property. */ protected static Icon vertThumbIcon; private static Icon SAFE_HORIZ_THUMB_ICON; private static Icon SAFE_VERT_THUMB_ICON; protected final String SLIDER_FILL = "JSlider.isFilled"; public static ComponentUI createUI(JComponent c) { return new MetalSliderUI(); } public MetalSliderUI() { super( null ); } private static Icon getHorizThumbIcon() { if (System.getSecurityManager() != null) { return SAFE_HORIZ_THUMB_ICON; } else { return horizThumbIcon; } } private static Icon getVertThumbIcon() { if (System.getSecurityManager() != null) { return SAFE_VERT_THUMB_ICON; } else { return vertThumbIcon; } } public void installUI( JComponent c ) { trackWidth = ((Integer)UIManager.get( "Slider.trackWidth" )).intValue(); tickLength = safeLength = ((Integer)UIManager.get( "Slider.majorTickLength" )).intValue(); horizThumbIcon = SAFE_HORIZ_THUMB_ICON = UIManager.getIcon( "Slider.horizontalThumbIcon" ); vertThumbIcon = SAFE_VERT_THUMB_ICON = UIManager.getIcon( "Slider.verticalThumbIcon" ); super.installUI( c ); thumbColor = UIManager.getColor("Slider.thumb"); highlightColor = UIManager.getColor("Slider.highlight"); darkShadowColor = UIManager.getColor("Slider.darkShadow"); scrollListener.setScrollByBlock( false ); Object sliderFillProp = c.getClientProperty( SLIDER_FILL ); if ( sliderFillProp != null ) { filledSlider = ((Boolean)sliderFillProp).booleanValue(); } } protected PropertyChangeListener createPropertyChangeListener( JSlider slider ) { return new MetalPropertyListener(); } protected class MetalPropertyListener extends BasicSliderUI.PropertyChangeHandler { public void propertyChange( PropertyChangeEvent e ) { // listen for slider fill super.propertyChange( e ); String name = e.getPropertyName(); if ( name.equals( SLIDER_FILL ) ) { if ( e.getNewValue() != null ) { filledSlider = ((Boolean)e.getNewValue()).booleanValue(); } else { filledSlider = false; } } } } public void paintThumb(Graphics g) { Rectangle knobBounds = thumbRect; g.translate( knobBounds.x, knobBounds.y ); if ( slider.getOrientation() == JSlider.HORIZONTAL ) { getHorizThumbIcon().paintIcon( slider, g, 0, 0 ); } else { getVertThumbIcon().paintIcon( slider, g, 0, 0 ); } g.translate( -knobBounds.x, -knobBounds.y ); } /** {@collect.stats} * If <code>chooseFirst</code>is true, <code>c1</code> is returned, * otherwise <code>c2</code>. */ private Color chooseColor(boolean chooseFirst, Color c1, Color c2) { if (chooseFirst) { return c2; } return c1; } /** {@collect.stats} * Returns a rectangle enclosing the track that will be painted. */ private Rectangle getPaintTrackRect() { int trackLeft = 0, trackRight = 0, trackTop = 0, trackBottom = 0; if (slider.getOrientation() == JSlider.HORIZONTAL) { trackBottom = (trackRect.height - 1) - getThumbOverhang(); trackTop = trackBottom - (getTrackWidth() - 1); trackRight = trackRect.width - 1; } else { if (MetalUtils.isLeftToRight(slider)) { trackLeft = (trackRect.width - getThumbOverhang()) - getTrackWidth(); trackRight = (trackRect.width - getThumbOverhang()) - 1; } else { trackLeft = getThumbOverhang(); trackRight = getThumbOverhang() + getTrackWidth() - 1; } trackBottom = trackRect.height - 1; } return new Rectangle(trackRect.x + trackLeft, trackRect.y + trackTop, trackRight - trackLeft, trackBottom - trackTop); } public void paintTrack(Graphics g) { if (MetalLookAndFeel.usingOcean()) { oceanPaintTrack(g); return; } Color trackColor = !slider.isEnabled() ? MetalLookAndFeel.getControlShadow() : slider.getForeground(); boolean leftToRight = MetalUtils.isLeftToRight(slider); g.translate( trackRect.x, trackRect.y ); int trackLeft = 0; int trackTop = 0; int trackRight = 0; int trackBottom = 0; // Draw the track if ( slider.getOrientation() == JSlider.HORIZONTAL ) { trackBottom = (trackRect.height - 1) - getThumbOverhang(); trackTop = trackBottom - (getTrackWidth() - 1); trackRight = trackRect.width - 1; } else { if (leftToRight) { trackLeft = (trackRect.width - getThumbOverhang()) - getTrackWidth(); trackRight = (trackRect.width - getThumbOverhang()) - 1; } else { trackLeft = getThumbOverhang(); trackRight = getThumbOverhang() + getTrackWidth() - 1; } trackBottom = trackRect.height - 1; } if ( slider.isEnabled() ) { g.setColor( MetalLookAndFeel.getControlDarkShadow() ); g.drawRect( trackLeft, trackTop, (trackRight - trackLeft) - 1, (trackBottom - trackTop) - 1 ); g.setColor( MetalLookAndFeel.getControlHighlight() ); g.drawLine( trackLeft + 1, trackBottom, trackRight, trackBottom ); g.drawLine( trackRight, trackTop + 1, trackRight, trackBottom ); g.setColor( MetalLookAndFeel.getControlShadow() ); g.drawLine( trackLeft + 1, trackTop + 1, trackRight - 2, trackTop + 1 ); g.drawLine( trackLeft + 1, trackTop + 1, trackLeft + 1, trackBottom - 2 ); } else { g.setColor( MetalLookAndFeel.getControlShadow() ); g.drawRect( trackLeft, trackTop, (trackRight - trackLeft) - 1, (trackBottom - trackTop) - 1 ); } // Draw the fill if ( filledSlider ) { int middleOfThumb = 0; int fillTop = 0; int fillLeft = 0; int fillBottom = 0; int fillRight = 0; if ( slider.getOrientation() == JSlider.HORIZONTAL ) { middleOfThumb = thumbRect.x + (thumbRect.width / 2); middleOfThumb -= trackRect.x; // To compensate for the g.translate() fillTop = !slider.isEnabled() ? trackTop : trackTop + 1; fillBottom = !slider.isEnabled() ? trackBottom - 1 : trackBottom - 2; if ( !drawInverted() ) { fillLeft = !slider.isEnabled() ? trackLeft : trackLeft + 1; fillRight = middleOfThumb; } else { fillLeft = middleOfThumb; fillRight = !slider.isEnabled() ? trackRight - 1 : trackRight - 2; } } else { middleOfThumb = thumbRect.y + (thumbRect.height / 2); middleOfThumb -= trackRect.y; // To compensate for the g.translate() fillLeft = !slider.isEnabled() ? trackLeft : trackLeft + 1; fillRight = !slider.isEnabled() ? trackRight - 1 : trackRight - 2; if ( !drawInverted() ) { fillTop = middleOfThumb; fillBottom = !slider.isEnabled() ? trackBottom - 1 : trackBottom - 2; } else { fillTop = !slider.isEnabled() ? trackTop : trackTop + 1; fillBottom = middleOfThumb; } } if ( slider.isEnabled() ) { g.setColor( slider.getBackground() ); g.drawLine( fillLeft, fillTop, fillRight, fillTop ); g.drawLine( fillLeft, fillTop, fillLeft, fillBottom ); g.setColor( MetalLookAndFeel.getControlShadow() ); g.fillRect( fillLeft + 1, fillTop + 1, fillRight - fillLeft, fillBottom - fillTop ); } else { g.setColor( MetalLookAndFeel.getControlShadow() ); g.fillRect( fillLeft, fillTop, fillRight - fillLeft, trackBottom - trackTop ); } } g.translate( -trackRect.x, -trackRect.y ); } private void oceanPaintTrack(Graphics g) { boolean leftToRight = MetalUtils.isLeftToRight(slider); boolean drawInverted = drawInverted(); Color sliderAltTrackColor = (Color)UIManager.get( "Slider.altTrackColor"); // Translate to the origin of the painting rectangle Rectangle paintRect = getPaintTrackRect(); g.translate(paintRect.x, paintRect.y); // Width and height of the painting rectangle. int w = paintRect.width; int h = paintRect.height; if (!slider.isEnabled()) { g.setColor(MetalLookAndFeel.getControlShadow()); g.drawRect(0, 0, w - 1, h - 1); } else if (slider.getOrientation() == JSlider.HORIZONTAL) { int middleOfThumb = thumbRect.x + (thumbRect.width / 2) - paintRect.x; int fillMinX; int fillMaxX; if (middleOfThumb > 0) { g.setColor(chooseColor(drawInverted, MetalLookAndFeel.getPrimaryControlDarkShadow(), MetalLookAndFeel.getControlDarkShadow())); g.drawRect(0, 0, middleOfThumb - 1, h - 1); } if (middleOfThumb < w) { g.setColor(chooseColor(drawInverted, MetalLookAndFeel.getControlDarkShadow(), MetalLookAndFeel.getPrimaryControlDarkShadow())); g.drawRect(middleOfThumb, 0, w - middleOfThumb - 1, h - 1); } g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); if (drawInverted) { fillMinX = middleOfThumb; fillMaxX = w - 2; g.drawLine(1, 1, middleOfThumb, 1); } else { fillMinX = 1; fillMaxX = middleOfThumb; g.drawLine(middleOfThumb, 1, w - 1, 1); } if (h == 6) { g.setColor(MetalLookAndFeel.getWhite()); g.drawLine(fillMinX, 1, fillMaxX, 1); g.setColor(sliderAltTrackColor); g.drawLine(fillMinX, 2, fillMaxX, 2); g.setColor(MetalLookAndFeel.getControlShadow()); g.drawLine(fillMinX, 3, fillMaxX, 3); g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); g.drawLine(fillMinX, 4, fillMaxX, 4); } } else { int middleOfThumb = thumbRect.y + (thumbRect.height / 2) - paintRect.y; int fillMinY; int fillMaxY; if (middleOfThumb > 0) { g.setColor(chooseColor(drawInverted, MetalLookAndFeel.getControlDarkShadow(), MetalLookAndFeel.getPrimaryControlDarkShadow())); g.drawRect(0, 0, w - 1, middleOfThumb - 1); } if (middleOfThumb < h) { g.setColor(chooseColor(drawInverted, MetalLookAndFeel.getPrimaryControlDarkShadow(), MetalLookAndFeel.getControlDarkShadow())); g.drawRect(0, middleOfThumb, w - 1, h - middleOfThumb - 1); } g.setColor(MetalLookAndFeel.getPrimaryControlShadow()); if (drawInverted()) { fillMinY = 1; fillMaxY = middleOfThumb; if (leftToRight) { g.drawLine(1, middleOfThumb, 1, h - 1); } else { g.drawLine(w - 2, middleOfThumb, w - 2, h - 1); } } else { fillMinY = middleOfThumb; fillMaxY = h - 2; if (leftToRight) { g.drawLine(1, 1, 1, middleOfThumb); } else { g.drawLine(w - 2, 1, w - 2, middleOfThumb); } } if (w == 6) { g.setColor(chooseColor(!leftToRight, MetalLookAndFeel.getWhite(), MetalLookAndFeel.getPrimaryControlShadow())); g.drawLine(1, fillMinY, 1, fillMaxY); g.setColor(chooseColor(!leftToRight, sliderAltTrackColor, MetalLookAndFeel.getControlShadow())); g.drawLine(2, fillMinY, 2, fillMaxY); g.setColor(chooseColor(!leftToRight, MetalLookAndFeel.getControlShadow(), sliderAltTrackColor)); g.drawLine(3, fillMinY, 3, fillMaxY); g.setColor(chooseColor(!leftToRight, MetalLookAndFeel.getPrimaryControlShadow(), MetalLookAndFeel.getWhite())); g.drawLine(4, fillMinY, 4, fillMaxY); } } g.translate(-paintRect.x, -paintRect.y); } public void paintFocus(Graphics g) { } protected Dimension getThumbSize() { Dimension size = new Dimension(); if ( slider.getOrientation() == JSlider.VERTICAL ) { size.width = getVertThumbIcon().getIconWidth(); size.height = getVertThumbIcon().getIconHeight(); } else { size.width = getHorizThumbIcon().getIconWidth(); size.height = getHorizThumbIcon().getIconHeight(); } return size; } /** {@collect.stats} * Gets the height of the tick area for horizontal sliders and the width of the * tick area for vertical sliders. BasicSliderUI uses the returned value to * determine the tick area rectangle. */ public int getTickLength() { return slider.getOrientation() == JSlider.HORIZONTAL ? safeLength + TICK_BUFFER + 1 : safeLength + TICK_BUFFER + 3; } /** {@collect.stats} * Returns the shorter dimension of the track. */ protected int getTrackWidth() { // This strange calculation is here to keep the // track in proportion to the thumb. final double kIdealTrackWidth = 7.0; final double kIdealThumbHeight = 16.0; final double kWidthScalar = kIdealTrackWidth / kIdealThumbHeight; if ( slider.getOrientation() == JSlider.HORIZONTAL ) { return (int)(kWidthScalar * thumbRect.height); } else { return (int)(kWidthScalar * thumbRect.width); } } /** {@collect.stats} * Returns the longer dimension of the slide bar. (The slide bar is only the * part that runs directly under the thumb) */ protected int getTrackLength() { if ( slider.getOrientation() == JSlider.HORIZONTAL ) { return trackRect.width; } return trackRect.height; } /** {@collect.stats} * Returns the amount that the thumb goes past the slide bar. */ protected int getThumbOverhang() { return (int)(getThumbSize().getHeight()-getTrackWidth())/2; } protected void scrollDueToClickInTrack( int dir ) { scrollByUnit( dir ); } protected void paintMinorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) { g.setColor( slider.isEnabled() ? slider.getForeground() : MetalLookAndFeel.getControlShadow() ); g.drawLine( x, TICK_BUFFER, x, TICK_BUFFER + (safeLength / 2) ); } protected void paintMajorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) { g.setColor( slider.isEnabled() ? slider.getForeground() : MetalLookAndFeel.getControlShadow() ); g.drawLine( x, TICK_BUFFER , x, TICK_BUFFER + (safeLength - 1) ); } protected void paintMinorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) { g.setColor( slider.isEnabled() ? slider.getForeground() : MetalLookAndFeel.getControlShadow() ); if (MetalUtils.isLeftToRight(slider)) { g.drawLine( TICK_BUFFER, y, TICK_BUFFER + (safeLength / 2), y ); } else { g.drawLine( 0, y, safeLength/2, y ); } } protected void paintMajorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) { g.setColor( slider.isEnabled() ? slider.getForeground() : MetalLookAndFeel.getControlShadow() ); if (MetalUtils.isLeftToRight(slider)) { g.drawLine( TICK_BUFFER, y, TICK_BUFFER + safeLength, y ); } else { g.drawLine( 0, y, safeLength, y ); } } }
Java
/* * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.plaf.*; import javax.swing.border.*; import javax.swing.plaf.basic.*; import java.io.Serializable; import java.beans.*; /** {@collect.stats} * Metal UI for JComboBox * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @see MetalComboBoxEditor * @see MetalComboBoxButton * @author Tom Santos */ public class MetalComboBoxUI extends BasicComboBoxUI { public static ComponentUI createUI(JComponent c) { return new MetalComboBoxUI(); } public void paint(Graphics g, JComponent c) { if (MetalLookAndFeel.usingOcean()) { super.paint(g, c); } } /** {@collect.stats} * If necessary paints the currently selected item. * * @param g Graphics to paint to * @param bounds Region to paint current value to * @param hasFocus whether or not the JComboBox has focus * @throws NullPointerException if any of the arguments are null. * @since 1.5 */ public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus) { // This is really only called if we're using ocean. if (MetalLookAndFeel.usingOcean()) { bounds.x += 2; bounds.width -= 3; if (arrowButton != null) { Insets buttonInsets = arrowButton.getInsets(); bounds.y += buttonInsets.top; bounds.height -= (buttonInsets.top + buttonInsets.bottom); } else { bounds.y += 2; bounds.height -= 4; } super.paintCurrentValue(g, bounds, hasFocus); } else if (g == null || bounds == null) { throw new NullPointerException( "Must supply a non-null Graphics and Rectangle"); } } /** {@collect.stats} * If necessary paints the background of the currently selected item. * * @param g Graphics to paint to * @param bounds Region to paint background to * @param hasFocus whether or not the JComboBox has focus * @throws NullPointerException if any of the arguments are null. * @since 1.5 */ public void paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus) { // This is really only called if we're using ocean. if (MetalLookAndFeel.usingOcean()) { g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height - 1); g.setColor(MetalLookAndFeel.getControlShadow()); g.drawRect(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 3); if (hasFocus && !isPopupVisible(comboBox) && arrowButton != null) { g.setColor(listBox.getSelectionBackground()); Insets buttonInsets = arrowButton.getInsets(); if (buttonInsets.top > 2) { g.fillRect(bounds.x + 2, bounds.y + 2, bounds.width - 3, buttonInsets.top - 2); } if (buttonInsets.bottom > 2) { g.fillRect(bounds.x + 2, bounds.y + bounds.height - buttonInsets.bottom, bounds.width - 3, buttonInsets.bottom - 2); } } } else if (g == null || bounds == null) { throw new NullPointerException( "Must supply a non-null Graphics and Rectangle"); } } /** {@collect.stats} * Returns the baseline. * * @throws NullPointerException {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} * @see javax.swing.JComponent#getBaseline(int, int) * @since 1.6 */ public int getBaseline(JComponent c, int width, int height) { int baseline; if (MetalLookAndFeel.usingOcean()) { height -= 4; baseline = super.getBaseline(c, width, height); if (baseline >= 0) { baseline += 2; } } else { baseline = super.getBaseline(c, width, height); } return baseline; } protected ComboBoxEditor createEditor() { return new MetalComboBoxEditor.UIResource(); } protected ComboPopup createPopup() { return super.createPopup(); } protected JButton createArrowButton() { boolean iconOnly = (comboBox.isEditable() || MetalLookAndFeel.usingOcean()); JButton button = new MetalComboBoxButton( comboBox, new MetalComboBoxIcon(), iconOnly, currentValuePane, listBox ); button.setMargin( new Insets( 0, 1, 1, 3 ) ); if (MetalLookAndFeel.usingOcean()) { // Disabled rollover effect. button.putClientProperty(MetalBorders.NO_BUTTON_ROLLOVER, Boolean.TRUE); } updateButtonForOcean(button); return button; } /** {@collect.stats} * Resets the necessary state on the ComboBoxButton for ocean. */ private void updateButtonForOcean(JButton button) { if (MetalLookAndFeel.usingOcean()) { // Ocean renders the focus in a different way, this // would be redundant. button.setFocusPainted(comboBox.isEditable()); } } public PropertyChangeListener createPropertyChangeListener() { return new MetalPropertyChangeListener(); } /** {@collect.stats} * This inner class is marked &quot;public&quot; due to a compiler bug. * This class should be treated as a &quot;protected&quot; inner class. * Instantiate it only within subclasses of <FooUI>. */ public class MetalPropertyChangeListener extends BasicComboBoxUI.PropertyChangeHandler { public void propertyChange(PropertyChangeEvent e) { super.propertyChange( e ); String propertyName = e.getPropertyName(); if ( propertyName == "editable" ) { if(arrowButton instanceof MetalComboBoxButton) { MetalComboBoxButton button = (MetalComboBoxButton)arrowButton; button.setIconOnly( comboBox.isEditable() || MetalLookAndFeel.usingOcean() ); } comboBox.repaint(); updateButtonForOcean(arrowButton); } else if ( propertyName == "background" ) { Color color = (Color)e.getNewValue(); arrowButton.setBackground(color); listBox.setBackground(color); } else if ( propertyName == "foreground" ) { Color color = (Color)e.getNewValue(); arrowButton.setForeground(color); listBox.setForeground(color); } } } /** {@collect.stats} * As of Java 2 platform v1.4 this method is no longer used. Do not call or * override. All the functionality of this method is in the * MetalPropertyChangeListener. * * @deprecated As of Java 2 platform v1.4. */ @Deprecated protected void editablePropertyChanged( PropertyChangeEvent e ) { } protected LayoutManager createLayoutManager() { return new MetalComboBoxLayoutManager(); } /** {@collect.stats} * This inner class is marked &quot;public&quot; due to a compiler bug. * This class should be treated as a &quot;protected&quot; inner class. * Instantiate it only within subclasses of <FooUI>. */ public class MetalComboBoxLayoutManager extends BasicComboBoxUI.ComboBoxLayoutManager { public void layoutContainer( Container parent ) { layoutComboBox( parent, this ); } public void superLayout( Container parent ) { super.layoutContainer( parent ); } } // This is here because of a bug in the compiler. // When a protected-inner-class-savvy compiler comes out we // should move this into MetalComboBoxLayoutManager. public void layoutComboBox( Container parent, MetalComboBoxLayoutManager manager ) { if (comboBox.isEditable() && !MetalLookAndFeel.usingOcean()) { manager.superLayout( parent ); return; } if (arrowButton != null) { if (MetalLookAndFeel.usingOcean() ) { Insets insets = comboBox.getInsets(); int buttonWidth = arrowButton.getMinimumSize().width; arrowButton.setBounds(MetalUtils.isLeftToRight(comboBox) ? (comboBox.getWidth() - insets.right - buttonWidth) : insets.left, insets.top, buttonWidth, comboBox.getHeight() - insets.top - insets.bottom); } else { Insets insets = comboBox.getInsets(); int width = comboBox.getWidth(); int height = comboBox.getHeight(); arrowButton.setBounds( insets.left, insets.top, width - (insets.left + insets.right), height - (insets.top + insets.bottom) ); } } if (editor != null && MetalLookAndFeel.usingOcean()) { Rectangle cvb = rectangleForCurrentValue(); editor.setBounds(cvb); } } /** {@collect.stats} * As of Java 2 platform v1.4 this method is no * longer used. * * @deprecated As of Java 2 platform v1.4. */ @Deprecated protected void removeListeners() { if ( propertyChangeListener != null ) { comboBox.removePropertyChangeListener( propertyChangeListener ); } } // These two methods were overloaded and made public. This was probably a // mistake in the implementation. The functionality that they used to // provide is no longer necessary and should be removed. However, // removing them will create an uncompatible API change. public void configureEditor() { super.configureEditor(); } public void unconfigureEditor() { super.unconfigureEditor(); } public Dimension getMinimumSize( JComponent c ) { if ( !isMinimumSizeDirty ) { return new Dimension( cachedMinimumSize ); } Dimension size = null; if ( !comboBox.isEditable() && arrowButton != null) { Insets buttonInsets = arrowButton.getInsets(); Insets insets = comboBox.getInsets(); size = getDisplaySize(); size.width += insets.left + insets.right; size.width += buttonInsets.right; size.width += arrowButton.getMinimumSize().width; size.height += insets.top + insets.bottom; size.height += buttonInsets.top + buttonInsets.bottom; } else if ( comboBox.isEditable() && arrowButton != null && editor != null ) { size = super.getMinimumSize( c ); Insets margin = arrowButton.getMargin(); size.height += margin.top + margin.bottom; size.width += margin.left + margin.right; } else { size = super.getMinimumSize( c ); } cachedMinimumSize.setSize( size.width, size.height ); isMinimumSizeDirty = false; return new Dimension( cachedMinimumSize ); } /** {@collect.stats} * This inner class is marked &quot;public&quot; due to a compiler bug. * This class should be treated as a &quot;protected&quot; inner class. * Instantiate it only within subclasses of <FooUI>. * * This class is now obsolete and doesn't do anything and * is only included for backwards API compatibility. Do not call or * override. * * @deprecated As of Java 2 platform v1.4. */ @Deprecated public class MetalComboPopup extends BasicComboPopup { public MetalComboPopup( JComboBox cBox) { super( cBox ); } // This method was overloaded and made public. This was probably // mistake in the implementation. The functionality that they used to // provide is no longer necessary and should be removed. However, // removing them will create an uncompatible API change. public void delegateFocus(MouseEvent e) { super.delegateFocus(e); } } }
Java
/* * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; /** {@collect.stats} * Metal split pane. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Steve Wilson */ public class MetalSplitPaneUI extends BasicSplitPaneUI { /** {@collect.stats} * Creates a new MetalSplitPaneUI instance */ public static ComponentUI createUI(JComponent x) { return new MetalSplitPaneUI(); } /** {@collect.stats} * Creates the default divider. */ public BasicSplitPaneDivider createDefaultDivider() { return new MetalSplitPaneDivider(this); } }
Java
/* * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import java.awt.*; import java.beans.*; import javax.swing.*; import javax.swing.text.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; /** {@collect.stats} * Basis of a look and feel for a JTextField. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Steve Wilson */ public class MetalTextFieldUI extends BasicTextFieldUI { public static ComponentUI createUI(JComponent c) { return new MetalTextFieldUI(); } /** {@collect.stats} * This method gets called when a bound property is changed * on the associated JTextComponent. This is a hook * which UI implementations may change to reflect how the * UI displays bound properties of JTextComponent subclasses. * * @param evt the property change event */ public void propertyChange(PropertyChangeEvent evt) { super.propertyChange(evt); } }
Java
/* * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.*; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Insets; import java.awt.Rectangle; import javax.swing.plaf.*; /** {@collect.stats} * A Metal L&F implementation of PopupMenuSeparatorUI. This implementation * is a "combined" view/controller. * * @author Jeff Shapiro */ public class MetalPopupMenuSeparatorUI extends MetalSeparatorUI { public static ComponentUI createUI( JComponent c ) { return new MetalPopupMenuSeparatorUI(); } public void paint( Graphics g, JComponent c ) { Dimension s = c.getSize(); g.setColor( c.getForeground() ); g.drawLine( 0, 1, s.width, 1 ); g.setColor( c.getBackground() ); g.drawLine( 0, 2, s.width, 2 ); g.drawLine( 0, 0, 0, 0 ); g.drawLine( 0, 3, 0, 3 ); } public Dimension getPreferredSize( JComponent c ) { return new Dimension( 0, 4 ); } }
Java
/* * Copyright (c) 1998, 2000, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.plaf.*; import javax.swing.border.*; import java.io.Serializable; import javax.swing.plaf.basic.BasicComboBoxUI; /** {@collect.stats} * This utility class draws the horizontal bars which indicate a MetalComboBox * * @see MetalComboBoxUI * @author Tom Santos */ public class MetalComboBoxIcon implements Icon, Serializable { /** {@collect.stats} * Paints the horizontal bars for the */ public void paintIcon(Component c, Graphics g, int x, int y){ JComponent component = (JComponent)c; int iconWidth = getIconWidth(); g.translate( x, y ); g.setColor( component.isEnabled() ? MetalLookAndFeel.getControlInfo() : MetalLookAndFeel.getControlShadow() ); g.drawLine( 0, 0, iconWidth - 1, 0 ); g.drawLine( 1, 1, 1 + (iconWidth - 3), 1 ); g.drawLine( 2, 2, 2 + (iconWidth - 5), 2 ); g.drawLine( 3, 3, 3 + (iconWidth - 7), 3 ); g.drawLine( 4, 4, 4 + (iconWidth - 9), 4 ); g.translate( -x, -y ); } /** {@collect.stats} * Created a stub to satisfy the interface. */ public int getIconWidth() { return 10; } /** {@collect.stats} * Created a stub to satisfy the interface. */ public int getIconHeight() { return 5; } }
Java
/* * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import sun.swing.SwingUtilities2; import sun.awt.AppContext; import javax.swing.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import java.awt.*; /** {@collect.stats} * A Windows L&F implementation of LabelUI. This implementation * is completely static, i.e. there's only one UIView implementation * that's shared by all JLabel objects. * * @author Hans Muller */ public class MetalLabelUI extends BasicLabelUI { /** {@collect.stats} * The default <code>MetalLabelUI</code> instance. This field might * not be used. To change the default instance use a subclass which * overrides the <code>createUI</code> method, and place that class * name in defaults table under the key "LabelUI". */ protected static MetalLabelUI metalLabelUI = new MetalLabelUI(); private static final Object METAL_LABEL_UI_KEY = new Object(); public static ComponentUI createUI(JComponent c) { if (System.getSecurityManager() != null) { AppContext appContext = AppContext.getAppContext(); MetalLabelUI safeMetalLabelUI = (MetalLabelUI) appContext.get(METAL_LABEL_UI_KEY); if (safeMetalLabelUI == null) { safeMetalLabelUI = new MetalLabelUI(); appContext.put(METAL_LABEL_UI_KEY, safeMetalLabelUI); } return safeMetalLabelUI; } return metalLabelUI; } /** {@collect.stats} * Just paint the text gray (Label.disabledForeground) rather than * in the labels foreground color. * * @see #paint * @see #paintEnabledText */ protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY) { int mnemIndex = l.getDisplayedMnemonicIndex(); g.setColor(UIManager.getColor("Label.disabledForeground")); SwingUtilities2.drawStringUnderlineCharAt(l, g, s, mnemIndex, textX, textY); } }
Java
/* * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import java.awt.event.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import java.awt.*; import java.io.*; import java.security.*; /** {@collect.stats} * Provides the metal look and feel implementation of <code>RootPaneUI</code>. * <p> * <code>MetalRootPaneUI</code> provides support for the * <code>windowDecorationStyle</code> property of <code>JRootPane</code>. * <code>MetalRootPaneUI</code> does this by way of installing a custom * <code>LayoutManager</code>, a private <code>Component</code> to render * the appropriate widgets, and a private <code>Border</code>. The * <code>LayoutManager</code> is always installed, regardless of the value of * the <code>windowDecorationStyle</code> property, but the * <code>Border</code> and <code>Component</code> are only installed/added if * the <code>windowDecorationStyle</code> is other than * <code>JRootPane.NONE</code>. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Terry Kellerman * @since 1.4 */ public class MetalRootPaneUI extends BasicRootPaneUI { /** {@collect.stats} * Keys to lookup borders in defaults table. */ private static final String[] borderKeys = new String[] { null, "RootPane.frameBorder", "RootPane.plainDialogBorder", "RootPane.informationDialogBorder", "RootPane.errorDialogBorder", "RootPane.colorChooserDialogBorder", "RootPane.fileChooserDialogBorder", "RootPane.questionDialogBorder", "RootPane.warningDialogBorder" }; /** {@collect.stats} * The amount of space (in pixels) that the cursor is changed on. */ private static final int CORNER_DRAG_WIDTH = 16; /** {@collect.stats} * Region from edges that dragging is active from. */ private static final int BORDER_DRAG_THICKNESS = 5; /** {@collect.stats} * Window the <code>JRootPane</code> is in. */ private Window window; /** {@collect.stats} * <code>JComponent</code> providing window decorations. This will be * null if not providing window decorations. */ private JComponent titlePane; /** {@collect.stats} * <code>MouseInputListener</code> that is added to the parent * <code>Window</code> the <code>JRootPane</code> is contained in. */ private MouseInputListener mouseInputListener; /** {@collect.stats} * The <code>LayoutManager</code> that is set on the * <code>JRootPane</code>. */ private LayoutManager layoutManager; /** {@collect.stats} * <code>LayoutManager</code> of the <code>JRootPane</code> before we * replaced it. */ private LayoutManager savedOldLayout; /** {@collect.stats} * <code>JRootPane</code> providing the look and feel for. */ private JRootPane root; /** {@collect.stats} * <code>Cursor</code> used to track the cursor set by the user. * This is initially <code>Cursor.DEFAULT_CURSOR</code>. */ private Cursor lastCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); /** {@collect.stats} * Creates a UI for a <code>JRootPane</code>. * * @param c the JRootPane the RootPaneUI will be created for * @return the RootPaneUI implementation for the passed in JRootPane */ public static ComponentUI createUI(JComponent c) { return new MetalRootPaneUI(); } /** {@collect.stats} * Invokes supers implementation of <code>installUI</code> to install * the necessary state onto the passed in <code>JRootPane</code> * to render the metal look and feel implementation of * <code>RootPaneUI</code>. If * the <code>windowDecorationStyle</code> property of the * <code>JRootPane</code> is other than <code>JRootPane.NONE</code>, * this will add a custom <code>Component</code> to render the widgets to * <code>JRootPane</code>, as well as installing a custom * <code>Border</code> and <code>LayoutManager</code> on the * <code>JRootPane</code>. * * @param c the JRootPane to install state onto */ public void installUI(JComponent c) { super.installUI(c); root = (JRootPane)c; int style = root.getWindowDecorationStyle(); if (style != JRootPane.NONE) { installClientDecorations(root); } } /** {@collect.stats} * Invokes supers implementation to uninstall any of its state. This will * also reset the <code>LayoutManager</code> of the <code>JRootPane</code>. * If a <code>Component</code> has been added to the <code>JRootPane</code> * to render the window decoration style, this method will remove it. * Similarly, this will revert the Border and LayoutManager of the * <code>JRootPane</code> to what it was before <code>installUI</code> * was invoked. * * @param c the JRootPane to uninstall state from */ public void uninstallUI(JComponent c) { super.uninstallUI(c); uninstallClientDecorations(root); layoutManager = null; mouseInputListener = null; root = null; } /** {@collect.stats} * Installs the appropriate <code>Border</code> onto the * <code>JRootPane</code>. */ void installBorder(JRootPane root) { int style = root.getWindowDecorationStyle(); if (style == JRootPane.NONE) { LookAndFeel.uninstallBorder(root); } else { LookAndFeel.installBorder(root, borderKeys[style]); } } /** {@collect.stats} * Removes any border that may have been installed. */ private void uninstallBorder(JRootPane root) { LookAndFeel.uninstallBorder(root); } /** {@collect.stats} * Installs the necessary Listeners on the parent <code>Window</code>, * if there is one. * <p> * This takes the parent so that cleanup can be done from * <code>removeNotify</code>, at which point the parent hasn't been * reset yet. * * @param parent The parent of the JRootPane */ private void installWindowListeners(JRootPane root, Component parent) { if (parent instanceof Window) { window = (Window)parent; } else { window = SwingUtilities.getWindowAncestor(parent); } if (window != null) { if (mouseInputListener == null) { mouseInputListener = createWindowMouseInputListener(root); } window.addMouseListener(mouseInputListener); window.addMouseMotionListener(mouseInputListener); } } /** {@collect.stats} * Uninstalls the necessary Listeners on the <code>Window</code> the * Listeners were last installed on. */ private void uninstallWindowListeners(JRootPane root) { if (window != null) { window.removeMouseListener(mouseInputListener); window.removeMouseMotionListener(mouseInputListener); } } /** {@collect.stats} * Installs the appropriate LayoutManager on the <code>JRootPane</code> * to render the window decorations. */ private void installLayout(JRootPane root) { if (layoutManager == null) { layoutManager = createLayoutManager(); } savedOldLayout = root.getLayout(); root.setLayout(layoutManager); } /** {@collect.stats} * Uninstalls the previously installed <code>LayoutManager</code>. */ private void uninstallLayout(JRootPane root) { if (savedOldLayout != null) { root.setLayout(savedOldLayout); savedOldLayout = null; } } /** {@collect.stats} * Installs the necessary state onto the JRootPane to render client * decorations. This is ONLY invoked if the <code>JRootPane</code> * has a decoration style other than <code>JRootPane.NONE</code>. */ private void installClientDecorations(JRootPane root) { installBorder(root); JComponent titlePane = createTitlePane(root); setTitlePane(root, titlePane); installWindowListeners(root, root.getParent()); installLayout(root); if (window != null) { root.revalidate(); root.repaint(); } } /** {@collect.stats} * Uninstalls any state that <code>installClientDecorations</code> has * installed. * <p> * NOTE: This may be called if you haven't installed client decorations * yet (ie before <code>installClientDecorations</code> has been invoked). */ private void uninstallClientDecorations(JRootPane root) { uninstallBorder(root); uninstallWindowListeners(root); setTitlePane(root, null); uninstallLayout(root); // We have to revalidate/repaint root if the style is JRootPane.NONE // only. When we needs to call revalidate/repaint with other styles // the installClientDecorations is always called after this method // imediatly and it will cause the revalidate/repaint at the proper // time. int style = root.getWindowDecorationStyle(); if (style == JRootPane.NONE) { root.repaint(); root.revalidate(); } // Reset the cursor, as we may have changed it to a resize cursor if (window != null) { window.setCursor(Cursor.getPredefinedCursor (Cursor.DEFAULT_CURSOR)); } window = null; } /** {@collect.stats} * Returns the <code>JComponent</code> to render the window decoration * style. */ private JComponent createTitlePane(JRootPane root) { return new MetalTitlePane(root, this); } /** {@collect.stats} * Returns a <code>MouseListener</code> that will be added to the * <code>Window</code> containing the <code>JRootPane</code>. */ private MouseInputListener createWindowMouseInputListener(JRootPane root) { return new MouseInputHandler(); } /** {@collect.stats} * Returns a <code>LayoutManager</code> that will be set on the * <code>JRootPane</code>. */ private LayoutManager createLayoutManager() { return new MetalRootLayout(); } /** {@collect.stats} * Sets the window title pane -- the JComponent used to provide a plaf a * way to override the native operating system's window title pane with * one whose look and feel are controlled by the plaf. The plaf creates * and sets this value; the default is null, implying a native operating * system window title pane. * * @param content the <code>JComponent</code> to use for the window title pane. */ private void setTitlePane(JRootPane root, JComponent titlePane) { JLayeredPane layeredPane = root.getLayeredPane(); JComponent oldTitlePane = getTitlePane(); if (oldTitlePane != null) { oldTitlePane.setVisible(false); layeredPane.remove(oldTitlePane); } if (titlePane != null) { layeredPane.add(titlePane, JLayeredPane.FRAME_CONTENT_LAYER); titlePane.setVisible(true); } this.titlePane = titlePane; } /** {@collect.stats} * Returns the <code>JComponent</code> rendering the title pane. If this * returns null, it implies there is no need to render window decorations. * * @return the current window title pane, or null * @see #setTitlePane */ private JComponent getTitlePane() { return titlePane; } /** {@collect.stats} * Returns the <code>JRootPane</code> we're providing the look and * feel for. */ private JRootPane getRootPane() { return root; } /** {@collect.stats} * Invoked when a property changes. <code>MetalRootPaneUI</code> is * primarily interested in events originating from the * <code>JRootPane</code> it has been installed on identifying the * property <code>windowDecorationStyle</code>. If the * <code>windowDecorationStyle</code> has changed to a value other * than <code>JRootPane.NONE</code>, this will add a <code>Component</code> * to the <code>JRootPane</code> to render the window decorations, as well * as installing a <code>Border</code> on the <code>JRootPane</code>. * On the other hand, if the <code>windowDecorationStyle</code> has * changed to <code>JRootPane.NONE</code>, this will remove the * <code>Component</code> that has been added to the <code>JRootPane</code> * as well resetting the Border to what it was before * <code>installUI</code> was invoked. * * @param e A PropertyChangeEvent object describing the event source * and the property that has changed. */ public void propertyChange(PropertyChangeEvent e) { super.propertyChange(e); String propertyName = e.getPropertyName(); if(propertyName == null) { return; } if(propertyName.equals("windowDecorationStyle")) { JRootPane root = (JRootPane) e.getSource(); int style = root.getWindowDecorationStyle(); // This is potentially more than needs to be done, // but it rarely happens and makes the install/uninstall process // simpler. MetalTitlePane also assumes it will be recreated if // the decoration style changes. uninstallClientDecorations(root); if (style != JRootPane.NONE) { installClientDecorations(root); } } else if (propertyName.equals("ancestor")) { uninstallWindowListeners(root); if (((JRootPane)e.getSource()).getWindowDecorationStyle() != JRootPane.NONE) { installWindowListeners(root, root.getParent()); } } return; } /** {@collect.stats} * A custom layout manager that is responsible for the layout of * layeredPane, glassPane, menuBar and titlePane, if one has been * installed. */ // NOTE: Ideally this would extends JRootPane.RootLayout, but that // would force this to be non-static. private static class MetalRootLayout implements LayoutManager2 { /** {@collect.stats} * Returns the amount of space the layout would like to have. * * @param the Container for which this layout manager is being used * @return a Dimension object containing the layout's preferred size */ public Dimension preferredLayoutSize(Container parent) { Dimension cpd, mbd, tpd; int cpWidth = 0; int cpHeight = 0; int mbWidth = 0; int mbHeight = 0; int tpWidth = 0; int tpHeight = 0; Insets i = parent.getInsets(); JRootPane root = (JRootPane) parent; if(root.getContentPane() != null) { cpd = root.getContentPane().getPreferredSize(); } else { cpd = root.getSize(); } if (cpd != null) { cpWidth = cpd.width; cpHeight = cpd.height; } if(root.getMenuBar() != null) { mbd = root.getMenuBar().getPreferredSize(); if (mbd != null) { mbWidth = mbd.width; mbHeight = mbd.height; } } if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof MetalRootPaneUI)) { JComponent titlePane = ((MetalRootPaneUI)root.getUI()). getTitlePane(); if (titlePane != null) { tpd = titlePane.getPreferredSize(); if (tpd != null) { tpWidth = tpd.width; tpHeight = tpd.height; } } } return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right, cpHeight + mbHeight + tpWidth + i.top + i.bottom); } /** {@collect.stats} * Returns the minimum amount of space the layout needs. * * @param the Container for which this layout manager is being used * @return a Dimension object containing the layout's minimum size */ public Dimension minimumLayoutSize(Container parent) { Dimension cpd, mbd, tpd; int cpWidth = 0; int cpHeight = 0; int mbWidth = 0; int mbHeight = 0; int tpWidth = 0; int tpHeight = 0; Insets i = parent.getInsets(); JRootPane root = (JRootPane) parent; if(root.getContentPane() != null) { cpd = root.getContentPane().getMinimumSize(); } else { cpd = root.getSize(); } if (cpd != null) { cpWidth = cpd.width; cpHeight = cpd.height; } if(root.getMenuBar() != null) { mbd = root.getMenuBar().getMinimumSize(); if (mbd != null) { mbWidth = mbd.width; mbHeight = mbd.height; } } if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof MetalRootPaneUI)) { JComponent titlePane = ((MetalRootPaneUI)root.getUI()). getTitlePane(); if (titlePane != null) { tpd = titlePane.getMinimumSize(); if (tpd != null) { tpWidth = tpd.width; tpHeight = tpd.height; } } } return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right, cpHeight + mbHeight + tpWidth + i.top + i.bottom); } /** {@collect.stats} * Returns the maximum amount of space the layout can use. * * @param the Container for which this layout manager is being used * @return a Dimension object containing the layout's maximum size */ public Dimension maximumLayoutSize(Container target) { Dimension cpd, mbd, tpd; int cpWidth = Integer.MAX_VALUE; int cpHeight = Integer.MAX_VALUE; int mbWidth = Integer.MAX_VALUE; int mbHeight = Integer.MAX_VALUE; int tpWidth = Integer.MAX_VALUE; int tpHeight = Integer.MAX_VALUE; Insets i = target.getInsets(); JRootPane root = (JRootPane) target; if(root.getContentPane() != null) { cpd = root.getContentPane().getMaximumSize(); if (cpd != null) { cpWidth = cpd.width; cpHeight = cpd.height; } } if(root.getMenuBar() != null) { mbd = root.getMenuBar().getMaximumSize(); if (mbd != null) { mbWidth = mbd.width; mbHeight = mbd.height; } } if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof MetalRootPaneUI)) { JComponent titlePane = ((MetalRootPaneUI)root.getUI()). getTitlePane(); if (titlePane != null) { tpd = titlePane.getMaximumSize(); if (tpd != null) { tpWidth = tpd.width; tpHeight = tpd.height; } } } int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight); // Only overflows if 3 real non-MAX_VALUE heights, sum to > MAX_VALUE // Only will happen if sums to more than 2 billion units. Not likely. if (maxHeight != Integer.MAX_VALUE) { maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom; } int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth); // Similar overflow comment as above if (maxWidth != Integer.MAX_VALUE) { maxWidth += i.left + i.right; } return new Dimension(maxWidth, maxHeight); } /** {@collect.stats} * Instructs the layout manager to perform the layout for the specified * container. * * @param the Container for which this layout manager is being used */ public void layoutContainer(Container parent) { JRootPane root = (JRootPane) parent; Rectangle b = root.getBounds(); Insets i = root.getInsets(); int nextY = 0; int w = b.width - i.right - i.left; int h = b.height - i.top - i.bottom; if(root.getLayeredPane() != null) { root.getLayeredPane().setBounds(i.left, i.top, w, h); } if(root.getGlassPane() != null) { root.getGlassPane().setBounds(i.left, i.top, w, h); } // Note: This is laying out the children in the layeredPane, // technically, these are not our children. if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof MetalRootPaneUI)) { JComponent titlePane = ((MetalRootPaneUI)root.getUI()). getTitlePane(); if (titlePane != null) { Dimension tpd = titlePane.getPreferredSize(); if (tpd != null) { int tpHeight = tpd.height; titlePane.setBounds(0, 0, w, tpHeight); nextY += tpHeight; } } } if(root.getMenuBar() != null) { Dimension mbd = root.getMenuBar().getPreferredSize(); root.getMenuBar().setBounds(0, nextY, w, mbd.height); nextY += mbd.height; } if(root.getContentPane() != null) { Dimension cpd = root.getContentPane().getPreferredSize(); root.getContentPane().setBounds(0, nextY, w, h < nextY ? 0 : h - nextY); } } public void addLayoutComponent(String name, Component comp) {} public void removeLayoutComponent(Component comp) {} public void addLayoutComponent(Component comp, Object constraints) {} public float getLayoutAlignmentX(Container target) { return 0.0f; } public float getLayoutAlignmentY(Container target) { return 0.0f; } public void invalidateLayout(Container target) {} } /** {@collect.stats} * Maps from positions to cursor type. Refer to calculateCorner and * calculatePosition for details of this. */ private static final int[] cursorMapping = new int[] { Cursor.NW_RESIZE_CURSOR, Cursor.NW_RESIZE_CURSOR, Cursor.N_RESIZE_CURSOR, Cursor.NE_RESIZE_CURSOR, Cursor.NE_RESIZE_CURSOR, Cursor.NW_RESIZE_CURSOR, 0, 0, 0, Cursor.NE_RESIZE_CURSOR, Cursor.W_RESIZE_CURSOR, 0, 0, 0, Cursor.E_RESIZE_CURSOR, Cursor.SW_RESIZE_CURSOR, 0, 0, 0, Cursor.SE_RESIZE_CURSOR, Cursor.SW_RESIZE_CURSOR, Cursor.SW_RESIZE_CURSOR, Cursor.S_RESIZE_CURSOR, Cursor.SE_RESIZE_CURSOR, Cursor.SE_RESIZE_CURSOR }; /** {@collect.stats} * MouseInputHandler is responsible for handling resize/moving of * the Window. It sets the cursor directly on the Window when then * mouse moves over a hot spot. */ private class MouseInputHandler implements MouseInputListener { /** {@collect.stats} * Set to true if the drag operation is moving the window. */ private boolean isMovingWindow; /** {@collect.stats} * Used to determine the corner the resize is occuring from. */ private int dragCursor; /** {@collect.stats} * X location the mouse went down on for a drag operation. */ private int dragOffsetX; /** {@collect.stats} * Y location the mouse went down on for a drag operation. */ private int dragOffsetY; /** {@collect.stats} * Width of the window when the drag started. */ private int dragWidth; /** {@collect.stats} * Height of the window when the drag started. */ private int dragHeight; public void mousePressed(MouseEvent ev) { JRootPane rootPane = getRootPane(); if (rootPane.getWindowDecorationStyle() == JRootPane.NONE) { return; } Point dragWindowOffset = ev.getPoint(); Window w = (Window)ev.getSource(); if (w != null) { w.toFront(); } Point convertedDragWindowOffset = SwingUtilities.convertPoint( w, dragWindowOffset, getTitlePane()); Frame f = null; Dialog d = null; if (w instanceof Frame) { f = (Frame)w; } else if (w instanceof Dialog) { d = (Dialog)w; } int frameState = (f != null) ? f.getExtendedState() : 0; if (getTitlePane() != null && getTitlePane().contains(convertedDragWindowOffset)) { if ((f != null && ((frameState & Frame.MAXIMIZED_BOTH) == 0) || (d != null)) && dragWindowOffset.y >= BORDER_DRAG_THICKNESS && dragWindowOffset.x >= BORDER_DRAG_THICKNESS && dragWindowOffset.x < w.getWidth() - BORDER_DRAG_THICKNESS) { isMovingWindow = true; dragOffsetX = dragWindowOffset.x; dragOffsetY = dragWindowOffset.y; } } else if (f != null && f.isResizable() && ((frameState & Frame.MAXIMIZED_BOTH) == 0) || (d != null && d.isResizable())) { dragOffsetX = dragWindowOffset.x; dragOffsetY = dragWindowOffset.y; dragWidth = w.getWidth(); dragHeight = w.getHeight(); dragCursor = getCursor(calculateCorner( w, dragWindowOffset.x, dragWindowOffset.y)); } } public void mouseReleased(MouseEvent ev) { if (dragCursor != 0 && window != null && !window.isValid()) { // Some Window systems validate as you resize, others won't, // thus the check for validity before repainting. window.validate(); getRootPane().repaint(); } isMovingWindow = false; dragCursor = 0; } public void mouseMoved(MouseEvent ev) { JRootPane root = getRootPane(); if (root.getWindowDecorationStyle() == JRootPane.NONE) { return; } Window w = (Window)ev.getSource(); Frame f = null; Dialog d = null; if (w instanceof Frame) { f = (Frame)w; } else if (w instanceof Dialog) { d = (Dialog)w; } // Update the cursor int cursor = getCursor(calculateCorner(w, ev.getX(), ev.getY())); if (cursor != 0 && ((f != null && (f.isResizable() && (f.getExtendedState() & Frame.MAXIMIZED_BOTH) == 0)) || (d != null && d.isResizable()))) { w.setCursor(Cursor.getPredefinedCursor(cursor)); } else { w.setCursor(lastCursor); } } private void adjust(Rectangle bounds, Dimension min, int deltaX, int deltaY, int deltaWidth, int deltaHeight) { bounds.x += deltaX; bounds.y += deltaY; bounds.width += deltaWidth; bounds.height += deltaHeight; if (min != null) { if (bounds.width < min.width) { int correction = min.width - bounds.width; if (deltaX != 0) { bounds.x -= correction; } bounds.width = min.width; } if (bounds.height < min.height) { int correction = min.height - bounds.height; if (deltaY != 0) { bounds.y -= correction; } bounds.height = min.height; } } } public void mouseDragged(MouseEvent ev) { Window w = (Window)ev.getSource(); Point pt = ev.getPoint(); if (isMovingWindow) { Point eventLocationOnScreen = ev.getLocationOnScreen(); w.setLocation(eventLocationOnScreen.x - dragOffsetX, eventLocationOnScreen.y - dragOffsetY); } else if (dragCursor != 0) { Rectangle r = w.getBounds(); Rectangle startBounds = new Rectangle(r); Dimension min = w.getMinimumSize(); switch (dragCursor) { case Cursor.E_RESIZE_CURSOR: adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0); break; case Cursor.S_RESIZE_CURSOR: adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height); break; case Cursor.N_RESIZE_CURSOR: adjust(r, min, 0, pt.y -dragOffsetY, 0, -(pt.y - dragOffsetY)); break; case Cursor.W_RESIZE_CURSOR: adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0); break; case Cursor.NE_RESIZE_CURSOR: adjust(r, min, 0, pt.y - dragOffsetY, pt.x + (dragWidth - dragOffsetX) - r.width, -(pt.y - dragOffsetY)); break; case Cursor.SE_RESIZE_CURSOR: adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, pt.y + (dragHeight - dragOffsetY) - r.height); break; case Cursor.NW_RESIZE_CURSOR: adjust(r, min, pt.x - dragOffsetX, pt.y - dragOffsetY, -(pt.x - dragOffsetX), -(pt.y - dragOffsetY)); break; case Cursor.SW_RESIZE_CURSOR: adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), pt.y + (dragHeight - dragOffsetY) - r.height); break; default: break; } if (!r.equals(startBounds)) { w.setBounds(r); // Defer repaint/validate on mouseReleased unless dynamic // layout is active. if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) { w.validate(); getRootPane().repaint(); } } } } public void mouseEntered(MouseEvent ev) { Window w = (Window)ev.getSource(); lastCursor = w.getCursor(); mouseMoved(ev); } public void mouseExited(MouseEvent ev) { Window w = (Window)ev.getSource(); w.setCursor(lastCursor); } public void mouseClicked(MouseEvent ev) { Window w = (Window)ev.getSource(); Frame f = null; if (w instanceof Frame) { f = (Frame)w; } else { return; } Point convertedPoint = SwingUtilities.convertPoint( w, ev.getPoint(), getTitlePane()); int state = f.getExtendedState(); if (getTitlePane() != null && getTitlePane().contains(convertedPoint)) { if ((ev.getClickCount() % 2) == 0 && ((ev.getModifiers() & InputEvent.BUTTON1_MASK) != 0)) { if (f.isResizable()) { if ((state & Frame.MAXIMIZED_BOTH) != 0) { f.setExtendedState(state & ~Frame.MAXIMIZED_BOTH); } else { f.setExtendedState(state | Frame.MAXIMIZED_BOTH); } return; } } } } /** {@collect.stats} * Returns the corner that contains the point <code>x</code>, * <code>y</code>, or -1 if the position doesn't match a corner. */ private int calculateCorner(Window w, int x, int y) { Insets insets = w.getInsets(); int xPosition = calculatePosition(x - insets.left, w.getWidth() - insets.left - insets.right); int yPosition = calculatePosition(y - insets.top, w.getHeight() - insets.top - insets.bottom); if (xPosition == -1 || yPosition == -1) { return -1; } return yPosition * 5 + xPosition; } /** {@collect.stats} * Returns the Cursor to render for the specified corner. This returns * 0 if the corner doesn't map to a valid Cursor */ private int getCursor(int corner) { if (corner == -1) { return 0; } return cursorMapping[corner]; } /** {@collect.stats} * Returns an integer indicating the position of <code>spot</code> * in <code>width</code>. The return value will be: * 0 if < BORDER_DRAG_THICKNESS * 1 if < CORNER_DRAG_WIDTH * 2 if >= CORNER_DRAG_WIDTH && < width - BORDER_DRAG_THICKNESS * 3 if >= width - CORNER_DRAG_WIDTH * 4 if >= width - BORDER_DRAG_THICKNESS * 5 otherwise */ private int calculatePosition(int spot, int width) { if (spot < BORDER_DRAG_THICKNESS) { return 0; } if (spot < CORNER_DRAG_WIDTH) { return 1; } if (spot >= (width - BORDER_DRAG_THICKNESS)) { return 4; } if (spot >= (width - CORNER_DRAG_WIDTH)) { return 3; } return 2; } } }
Java
/* * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import sun.swing.SwingUtilities2; import sun.awt.SunToolkit; import java.awt.*; import java.awt.event.*; import java.beans.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.InternalFrameEvent; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import java.util.Locale; import javax.accessibility.*; /** {@collect.stats} * Class that manages a JLF awt.Window-descendant class's title bar. * <p> * This class assumes it will be created with a particular window * decoration style, and that if the style changes, a new one will * be created. * * @author Terry Kellerman * @since 1.4 */ class MetalTitlePane extends JComponent { private static final Border handyEmptyBorder = new EmptyBorder(0,0,0,0); private static final int IMAGE_HEIGHT = 16; private static final int IMAGE_WIDTH = 16; /** {@collect.stats} * PropertyChangeListener added to the JRootPane. */ private PropertyChangeListener propertyChangeListener; /** {@collect.stats} * JMenuBar, typically renders the system menu items. */ private JMenuBar menuBar; /** {@collect.stats} * Action used to close the Window. */ private Action closeAction; /** {@collect.stats} * Action used to iconify the Frame. */ private Action iconifyAction; /** {@collect.stats} * Action to restore the Frame size. */ private Action restoreAction; /** {@collect.stats} * Action to restore the Frame size. */ private Action maximizeAction; /** {@collect.stats} * Button used to maximize or restore the Frame. */ private JButton toggleButton; /** {@collect.stats} * Button used to maximize or restore the Frame. */ private JButton iconifyButton; /** {@collect.stats} * Button used to maximize or restore the Frame. */ private JButton closeButton; /** {@collect.stats} * Icon used for toggleButton when window is normal size. */ private Icon maximizeIcon; /** {@collect.stats} * Icon used for toggleButton when window is maximized. */ private Icon minimizeIcon; /** {@collect.stats} * Image used for the system menu icon */ private Image systemIcon; /** {@collect.stats} * Listens for changes in the state of the Window listener to update * the state of the widgets. */ private WindowListener windowListener; /** {@collect.stats} * Window we're currently in. */ private Window window; /** {@collect.stats} * JRootPane rendering for. */ private JRootPane rootPane; /** {@collect.stats} * Room remaining in title for bumps. */ private int buttonsWidth; /** {@collect.stats} * Buffered Frame.state property. As state isn't bound, this is kept * to determine when to avoid updating widgets. */ private int state; /** {@collect.stats} * MetalRootPaneUI that created us. */ private MetalRootPaneUI rootPaneUI; // Colors private Color inactiveBackground = UIManager.getColor("inactiveCaption"); private Color inactiveForeground = UIManager.getColor("inactiveCaptionText"); private Color inactiveShadow = UIManager.getColor("inactiveCaptionBorder"); private Color activeBumpsHighlight = MetalLookAndFeel.getPrimaryControlHighlight(); private Color activeBumpsShadow = MetalLookAndFeel.getPrimaryControlDarkShadow(); private Color activeBackground = null; private Color activeForeground = null; private Color activeShadow = null; // Bumps private MetalBumps activeBumps = new MetalBumps( 0, 0, activeBumpsHighlight, activeBumpsShadow, MetalLookAndFeel.getPrimaryControl() ); private MetalBumps inactiveBumps = new MetalBumps( 0, 0, MetalLookAndFeel.getControlHighlight(), MetalLookAndFeel.getControlDarkShadow(), MetalLookAndFeel.getControl() ); public MetalTitlePane(JRootPane root, MetalRootPaneUI ui) { this.rootPane = root; rootPaneUI = ui; state = -1; installSubcomponents(); determineColors(); installDefaults(); setLayout(createLayout()); } /** {@collect.stats} * Uninstalls the necessary state. */ private void uninstall() { uninstallListeners(); window = null; removeAll(); } /** {@collect.stats} * Installs the necessary listeners. */ private void installListeners() { if (window != null) { windowListener = createWindowListener(); window.addWindowListener(windowListener); propertyChangeListener = createWindowPropertyChangeListener(); window.addPropertyChangeListener(propertyChangeListener); } } /** {@collect.stats} * Uninstalls the necessary listeners. */ private void uninstallListeners() { if (window != null) { window.removeWindowListener(windowListener); window.removePropertyChangeListener(propertyChangeListener); } } /** {@collect.stats} * Returns the <code>WindowListener</code> to add to the * <code>Window</code>. */ private WindowListener createWindowListener() { return new WindowHandler(); } /** {@collect.stats} * Returns the <code>PropertyChangeListener</code> to install on * the <code>Window</code>. */ private PropertyChangeListener createWindowPropertyChangeListener() { return new PropertyChangeHandler(); } /** {@collect.stats} * Returns the <code>JRootPane</code> this was created for. */ public JRootPane getRootPane() { return rootPane; } /** {@collect.stats} * Returns the decoration style of the <code>JRootPane</code>. */ private int getWindowDecorationStyle() { return getRootPane().getWindowDecorationStyle(); } public void addNotify() { super.addNotify(); uninstallListeners(); window = SwingUtilities.getWindowAncestor(this); if (window != null) { if (window instanceof Frame) { setState(((Frame)window).getExtendedState()); } else { setState(0); } setActive(window.isActive()); installListeners(); updateSystemIcon(); } } public void removeNotify() { super.removeNotify(); uninstallListeners(); window = null; } /** {@collect.stats} * Adds any sub-Components contained in the <code>MetalTitlePane</code>. */ private void installSubcomponents() { int decorationStyle = getWindowDecorationStyle(); if (decorationStyle == JRootPane.FRAME) { createActions(); menuBar = createMenuBar(); add(menuBar); createButtons(); add(iconifyButton); add(toggleButton); add(closeButton); } else if (decorationStyle == JRootPane.PLAIN_DIALOG || decorationStyle == JRootPane.INFORMATION_DIALOG || decorationStyle == JRootPane.ERROR_DIALOG || decorationStyle == JRootPane.COLOR_CHOOSER_DIALOG || decorationStyle == JRootPane.FILE_CHOOSER_DIALOG || decorationStyle == JRootPane.QUESTION_DIALOG || decorationStyle == JRootPane.WARNING_DIALOG) { createActions(); createButtons(); add(closeButton); } } /** {@collect.stats} * Determines the Colors to draw with. */ private void determineColors() { switch (getWindowDecorationStyle()) { case JRootPane.FRAME: activeBackground = UIManager.getColor("activeCaption"); activeForeground = UIManager.getColor("activeCaptionText"); activeShadow = UIManager.getColor("activeCaptionBorder"); break; case JRootPane.ERROR_DIALOG: activeBackground = UIManager.getColor( "OptionPane.errorDialog.titlePane.background"); activeForeground = UIManager.getColor( "OptionPane.errorDialog.titlePane.foreground"); activeShadow = UIManager.getColor( "OptionPane.errorDialog.titlePane.shadow"); break; case JRootPane.QUESTION_DIALOG: case JRootPane.COLOR_CHOOSER_DIALOG: case JRootPane.FILE_CHOOSER_DIALOG: activeBackground = UIManager.getColor( "OptionPane.questionDialog.titlePane.background"); activeForeground = UIManager.getColor( "OptionPane.questionDialog.titlePane.foreground"); activeShadow = UIManager.getColor( "OptionPane.questionDialog.titlePane.shadow"); break; case JRootPane.WARNING_DIALOG: activeBackground = UIManager.getColor( "OptionPane.warningDialog.titlePane.background"); activeForeground = UIManager.getColor( "OptionPane.warningDialog.titlePane.foreground"); activeShadow = UIManager.getColor( "OptionPane.warningDialog.titlePane.shadow"); break; case JRootPane.PLAIN_DIALOG: case JRootPane.INFORMATION_DIALOG: default: activeBackground = UIManager.getColor("activeCaption"); activeForeground = UIManager.getColor("activeCaptionText"); activeShadow = UIManager.getColor("activeCaptionBorder"); break; } activeBumps.setBumpColors(activeBumpsHighlight, activeBumpsShadow, activeBackground); } /** {@collect.stats} * Installs the fonts and necessary properties on the MetalTitlePane. */ private void installDefaults() { setFont(UIManager.getFont("InternalFrame.titleFont", getLocale())); } /** {@collect.stats} * Uninstalls any previously installed UI values. */ private void uninstallDefaults() { } /** {@collect.stats} * Returns the <code>JMenuBar</code> displaying the appropriate * system menu items. */ protected JMenuBar createMenuBar() { menuBar = new SystemMenuBar(); menuBar.setFocusable(false); menuBar.setBorderPainted(true); menuBar.add(createMenu()); return menuBar; } /** {@collect.stats} * Closes the Window. */ private void close() { Window window = getWindow(); if (window != null) { window.dispatchEvent(new WindowEvent( window, WindowEvent.WINDOW_CLOSING)); } } /** {@collect.stats} * Iconifies the Frame. */ private void iconify() { Frame frame = getFrame(); if (frame != null) { frame.setExtendedState(state | Frame.ICONIFIED); } } /** {@collect.stats} * Maximizes the Frame. */ private void maximize() { Frame frame = getFrame(); if (frame != null) { frame.setExtendedState(state | Frame.MAXIMIZED_BOTH); } } /** {@collect.stats} * Restores the Frame size. */ private void restore() { Frame frame = getFrame(); if (frame == null) { return; } if ((state & Frame.ICONIFIED) != 0) { frame.setExtendedState(state & ~Frame.ICONIFIED); } else { frame.setExtendedState(state & ~Frame.MAXIMIZED_BOTH); } } /** {@collect.stats} * Create the <code>Action</code>s that get associated with the * buttons and menu items. */ private void createActions() { closeAction = new CloseAction(); if (getWindowDecorationStyle() == JRootPane.FRAME) { iconifyAction = new IconifyAction(); restoreAction = new RestoreAction(); maximizeAction = new MaximizeAction(); } } /** {@collect.stats} * Returns the <code>JMenu</code> displaying the appropriate menu items * for manipulating the Frame. */ private JMenu createMenu() { JMenu menu = new JMenu(""); if (getWindowDecorationStyle() == JRootPane.FRAME) { addMenuItems(menu); } return menu; } /** {@collect.stats} * Adds the necessary <code>JMenuItem</code>s to the passed in menu. */ private void addMenuItems(JMenu menu) { Locale locale = getRootPane().getLocale(); JMenuItem mi = menu.add(restoreAction); int mnemonic = MetalUtils.getInt("MetalTitlePane.restoreMnemonic", -1); if (mnemonic != -1) { mi.setMnemonic(mnemonic); } mi = menu.add(iconifyAction); mnemonic = MetalUtils.getInt("MetalTitlePane.iconifyMnemonic", -1); if (mnemonic != -1) { mi.setMnemonic(mnemonic); } if (Toolkit.getDefaultToolkit().isFrameStateSupported( Frame.MAXIMIZED_BOTH)) { mi = menu.add(maximizeAction); mnemonic = MetalUtils.getInt("MetalTitlePane.maximizeMnemonic", -1); if (mnemonic != -1) { mi.setMnemonic(mnemonic); } } menu.add(new JSeparator()); mi = menu.add(closeAction); mnemonic = MetalUtils.getInt("MetalTitlePane.closeMnemonic", -1); if (mnemonic != -1) { mi.setMnemonic(mnemonic); } } /** {@collect.stats} * Returns a <code>JButton</code> appropriate for placement on the * TitlePane. */ private JButton createTitleButton() { JButton button = new JButton(); button.setFocusPainted(false); button.setFocusable(false); button.setOpaque(true); return button; } /** {@collect.stats} * Creates the Buttons that will be placed on the TitlePane. */ private void createButtons() { closeButton = createTitleButton(); closeButton.setAction(closeAction); closeButton.setText(null); closeButton.putClientProperty("paintActive", Boolean.TRUE); closeButton.setBorder(handyEmptyBorder); closeButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, "Close"); closeButton.setIcon(UIManager.getIcon("InternalFrame.closeIcon")); if (getWindowDecorationStyle() == JRootPane.FRAME) { maximizeIcon = UIManager.getIcon("InternalFrame.maximizeIcon"); minimizeIcon = UIManager.getIcon("InternalFrame.minimizeIcon"); iconifyButton = createTitleButton(); iconifyButton.setAction(iconifyAction); iconifyButton.setText(null); iconifyButton.putClientProperty("paintActive", Boolean.TRUE); iconifyButton.setBorder(handyEmptyBorder); iconifyButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, "Iconify"); iconifyButton.setIcon(UIManager.getIcon("InternalFrame.iconifyIcon")); toggleButton = createTitleButton(); toggleButton.setAction(restoreAction); toggleButton.putClientProperty("paintActive", Boolean.TRUE); toggleButton.setBorder(handyEmptyBorder); toggleButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, "Maximize"); toggleButton.setIcon(maximizeIcon); } } /** {@collect.stats} * Returns the <code>LayoutManager</code> that should be installed on * the <code>MetalTitlePane</code>. */ private LayoutManager createLayout() { return new TitlePaneLayout(); } /** {@collect.stats} * Updates state dependant upon the Window's active state. */ private void setActive(boolean isActive) { Boolean activeB = isActive ? Boolean.TRUE : Boolean.FALSE; closeButton.putClientProperty("paintActive", activeB); if (getWindowDecorationStyle() == JRootPane.FRAME) { iconifyButton.putClientProperty("paintActive", activeB); toggleButton.putClientProperty("paintActive", activeB); } // Repaint the whole thing as the Borders that are used have // different colors for active vs inactive getRootPane().repaint(); } /** {@collect.stats} * Sets the state of the Window. */ private void setState(int state) { setState(state, false); } /** {@collect.stats} * Sets the state of the window. If <code>updateRegardless</code> is * true and the state has not changed, this will update anyway. */ private void setState(int state, boolean updateRegardless) { Window w = getWindow(); if (w != null && getWindowDecorationStyle() == JRootPane.FRAME) { if (this.state == state && !updateRegardless) { return; } Frame frame = getFrame(); if (frame != null) { JRootPane rootPane = getRootPane(); if (((state & Frame.MAXIMIZED_BOTH) != 0) && (rootPane.getBorder() == null || (rootPane.getBorder() instanceof UIResource)) && frame.isShowing()) { rootPane.setBorder(null); } else if ((state & Frame.MAXIMIZED_BOTH) == 0) { // This is a croak, if state becomes bound, this can // be nuked. rootPaneUI.installBorder(rootPane); } if (frame.isResizable()) { if ((state & Frame.MAXIMIZED_BOTH) != 0) { updateToggleButton(restoreAction, minimizeIcon); maximizeAction.setEnabled(false); restoreAction.setEnabled(true); } else { updateToggleButton(maximizeAction, maximizeIcon); maximizeAction.setEnabled(true); restoreAction.setEnabled(false); } if (toggleButton.getParent() == null || iconifyButton.getParent() == null) { add(toggleButton); add(iconifyButton); revalidate(); repaint(); } toggleButton.setText(null); } else { maximizeAction.setEnabled(false); restoreAction.setEnabled(false); if (toggleButton.getParent() != null) { remove(toggleButton); revalidate(); repaint(); } } } else { // Not contained in a Frame maximizeAction.setEnabled(false); restoreAction.setEnabled(false); iconifyAction.setEnabled(false); remove(toggleButton); remove(iconifyButton); revalidate(); repaint(); } closeAction.setEnabled(true); this.state = state; } } /** {@collect.stats} * Updates the toggle button to contain the Icon <code>icon</code>, and * Action <code>action</code>. */ private void updateToggleButton(Action action, Icon icon) { toggleButton.setAction(action); toggleButton.setIcon(icon); toggleButton.setText(null); } /** {@collect.stats} * Returns the Frame rendering in. This will return null if the * <code>JRootPane</code> is not contained in a <code>Frame</code>. */ private Frame getFrame() { Window window = getWindow(); if (window instanceof Frame) { return (Frame)window; } return null; } /** {@collect.stats} * Returns the <code>Window</code> the <code>JRootPane</code> is * contained in. This will return null if there is no parent ancestor * of the <code>JRootPane</code>. */ private Window getWindow() { return window; } /** {@collect.stats} * Returns the String to display as the title. */ private String getTitle() { Window w = getWindow(); if (w instanceof Frame) { return ((Frame)w).getTitle(); } else if (w instanceof Dialog) { return ((Dialog)w).getTitle(); } return null; } /** {@collect.stats} * Renders the TitlePane. */ public void paintComponent(Graphics g) { // As state isn't bound, we need a convenience place to check // if it has changed. Changing the state typically changes the if (getFrame() != null) { setState(getFrame().getExtendedState()); } JRootPane rootPane = getRootPane(); Window window = getWindow(); boolean leftToRight = (window == null) ? rootPane.getComponentOrientation().isLeftToRight() : window.getComponentOrientation().isLeftToRight(); boolean isSelected = (window == null) ? true : window.isActive(); int width = getWidth(); int height = getHeight(); Color background; Color foreground; Color darkShadow; MetalBumps bumps; if (isSelected) { background = activeBackground; foreground = activeForeground; darkShadow = activeShadow; bumps = activeBumps; } else { background = inactiveBackground; foreground = inactiveForeground; darkShadow = inactiveShadow; bumps = inactiveBumps; } g.setColor(background); g.fillRect(0, 0, width, height); g.setColor( darkShadow ); g.drawLine ( 0, height - 1, width, height -1); g.drawLine ( 0, 0, 0 ,0); g.drawLine ( width - 1, 0 , width -1, 0); int xOffset = leftToRight ? 5 : width - 5; if (getWindowDecorationStyle() == JRootPane.FRAME) { xOffset += leftToRight ? IMAGE_WIDTH + 5 : - IMAGE_WIDTH - 5; } String theTitle = getTitle(); if (theTitle != null) { FontMetrics fm = SwingUtilities2.getFontMetrics(rootPane, g); g.setColor(foreground); int yOffset = ( (height - fm.getHeight() ) / 2 ) + fm.getAscent(); Rectangle rect = new Rectangle(0, 0, 0, 0); if (iconifyButton != null && iconifyButton.getParent() != null) { rect = iconifyButton.getBounds(); } int titleW; if( leftToRight ) { if (rect.x == 0) { rect.x = window.getWidth() - window.getInsets().right-2; } titleW = rect.x - xOffset - 4; theTitle = SwingUtilities2.clipStringIfNecessary( rootPane, fm, theTitle, titleW); } else { titleW = xOffset - rect.x - rect.width - 4; theTitle = SwingUtilities2.clipStringIfNecessary( rootPane, fm, theTitle, titleW); xOffset -= SwingUtilities2.stringWidth(rootPane, fm, theTitle); } int titleLength = SwingUtilities2.stringWidth(rootPane, fm, theTitle); SwingUtilities2.drawString(rootPane, g, theTitle, xOffset, yOffset ); xOffset += leftToRight ? titleLength + 5 : -5; } int bumpXOffset; int bumpLength; if( leftToRight ) { bumpLength = width - buttonsWidth - xOffset - 5; bumpXOffset = xOffset; } else { bumpLength = xOffset - buttonsWidth - 5; bumpXOffset = buttonsWidth + 5; } int bumpYOffset = 3; int bumpHeight = getHeight() - (2 * bumpYOffset); bumps.setBumpArea( bumpLength, bumpHeight ); bumps.paintIcon(this, g, bumpXOffset, bumpYOffset); } /** {@collect.stats} * Actions used to <code>close</code> the <code>Window</code>. */ private class CloseAction extends AbstractAction { public CloseAction() { super(UIManager.getString("MetalTitlePane.closeTitle", getLocale())); } public void actionPerformed(ActionEvent e) { close(); } } /** {@collect.stats} * Actions used to <code>iconfiy</code> the <code>Frame</code>. */ private class IconifyAction extends AbstractAction { public IconifyAction() { super(UIManager.getString("MetalTitlePane.iconifyTitle", getLocale())); } public void actionPerformed(ActionEvent e) { iconify(); } } /** {@collect.stats} * Actions used to <code>restore</code> the <code>Frame</code>. */ private class RestoreAction extends AbstractAction { public RestoreAction() { super(UIManager.getString ("MetalTitlePane.restoreTitle", getLocale())); } public void actionPerformed(ActionEvent e) { restore(); } } /** {@collect.stats} * Actions used to <code>restore</code> the <code>Frame</code>. */ private class MaximizeAction extends AbstractAction { public MaximizeAction() { super(UIManager.getString("MetalTitlePane.maximizeTitle", getLocale())); } public void actionPerformed(ActionEvent e) { maximize(); } } /** {@collect.stats} * Class responsible for drawing the system menu. Looks up the * image to draw from the Frame associated with the * <code>JRootPane</code>. */ private class SystemMenuBar extends JMenuBar { public void paint(Graphics g) { if (isOpaque()) { g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); } if (systemIcon != null) { g.drawImage(systemIcon, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); } else { Icon icon = UIManager.getIcon("InternalFrame.icon"); if (icon != null) { icon.paintIcon(this, g, 0, 0); } } } public Dimension getMinimumSize() { return getPreferredSize(); } public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); return new Dimension(Math.max(IMAGE_WIDTH, size.width), Math.max(size.height, IMAGE_HEIGHT)); } } private class TitlePaneLayout implements LayoutManager { public void addLayoutComponent(String name, Component c) {} public void removeLayoutComponent(Component c) {} public Dimension preferredLayoutSize(Container c) { int height = computeHeight(); return new Dimension(height, height); } public Dimension minimumLayoutSize(Container c) { return preferredLayoutSize(c); } private int computeHeight() { FontMetrics fm = rootPane.getFontMetrics(getFont()); int fontHeight = fm.getHeight(); fontHeight += 7; int iconHeight = 0; if (getWindowDecorationStyle() == JRootPane.FRAME) { iconHeight = IMAGE_HEIGHT; } int finalHeight = Math.max( fontHeight, iconHeight ); return finalHeight; } public void layoutContainer(Container c) { boolean leftToRight = (window == null) ? getRootPane().getComponentOrientation().isLeftToRight() : window.getComponentOrientation().isLeftToRight(); int w = getWidth(); int x; int y = 3; int spacing; int buttonHeight; int buttonWidth; if (closeButton != null && closeButton.getIcon() != null) { buttonHeight = closeButton.getIcon().getIconHeight(); buttonWidth = closeButton.getIcon().getIconWidth(); } else { buttonHeight = IMAGE_HEIGHT; buttonWidth = IMAGE_WIDTH; } // assumes all buttons have the same dimensions // these dimensions include the borders x = leftToRight ? w : 0; spacing = 5; x = leftToRight ? spacing : w - buttonWidth - spacing; if (menuBar != null) { menuBar.setBounds(x, y, buttonWidth, buttonHeight); } x = leftToRight ? w : 0; spacing = 4; x += leftToRight ? -spacing -buttonWidth : spacing; if (closeButton != null) { closeButton.setBounds(x, y, buttonWidth, buttonHeight); } if( !leftToRight ) x += buttonWidth; if (getWindowDecorationStyle() == JRootPane.FRAME) { if (Toolkit.getDefaultToolkit().isFrameStateSupported( Frame.MAXIMIZED_BOTH)) { if (toggleButton.getParent() != null) { spacing = 10; x += leftToRight ? -spacing -buttonWidth : spacing; toggleButton.setBounds(x, y, buttonWidth, buttonHeight); if (!leftToRight) { x += buttonWidth; } } } if (iconifyButton != null && iconifyButton.getParent() != null) { spacing = 2; x += leftToRight ? -spacing -buttonWidth : spacing; iconifyButton.setBounds(x, y, buttonWidth, buttonHeight); if (!leftToRight) { x += buttonWidth; } } } buttonsWidth = leftToRight ? w - x : x; } } /** {@collect.stats} * PropertyChangeListener installed on the Window. Updates the necessary * state as the state of the Window changes. */ private class PropertyChangeHandler implements PropertyChangeListener { public void propertyChange(PropertyChangeEvent pce) { String name = pce.getPropertyName(); // Frame.state isn't currently bound. if ("resizable".equals(name) || "state".equals(name)) { Frame frame = getFrame(); if (frame != null) { setState(frame.getExtendedState(), true); } if ("resizable".equals(name)) { getRootPane().repaint(); } } else if ("title".equals(name)) { repaint(); } else if ("componentOrientation" == name) { revalidate(); repaint(); } else if ("iconImage" == name) { updateSystemIcon(); revalidate(); repaint(); } } } /** {@collect.stats} * Update the image used for the system icon */ private void updateSystemIcon() { Window window = getWindow(); if (window == null) { systemIcon = null; return; } java.util.List<Image> icons = window.getIconImages(); assert icons != null; if (icons.size() == 0) { systemIcon = null; } else if (icons.size() == 1) { systemIcon = icons.get(0); } else { systemIcon = SunToolkit.getScaledIconImage(icons, IMAGE_WIDTH, IMAGE_HEIGHT); } } /** {@collect.stats} * WindowListener installed on the Window, updates the state as necessary. */ private class WindowHandler extends WindowAdapter { public void windowActivated(WindowEvent ev) { setActive(true); } public void windowDeactivated(WindowEvent ev) { setActive(false); } } }
Java
/* * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import java.awt.*; import java.beans.*; import javax.swing.*; /** {@collect.stats} * DesktopProperty that only uses font height in configuring font. This * is only used on Windows. * */ class MetalFontDesktopProperty extends com.sun.java.swing.plaf.windows.DesktopProperty { /** {@collect.stats} * Maps from metal font theme type as defined in MetalTheme * to the corresponding desktop property name. */ private static final String[] propertyMapping = { "win.ansiVar.font.height", "win.tooltip.font.height", "win.ansiVar.font.height", "win.menu.font.height", "win.frame.captionFont.height", "win.menu.font.height" }; /** {@collect.stats} * Corresponds to a MetalTheme font type. */ private int type; /** {@collect.stats} * Creates a MetalFontDesktopProperty. The key used to lookup the * desktop property is determined from the type of font. * * @param type MetalTheme font type. */ MetalFontDesktopProperty(int type) { this(propertyMapping[type], Toolkit.getDefaultToolkit(), type); } /** {@collect.stats} * Creates a MetalFontDesktopProperty. * * @param key Key used in looking up desktop value. * @param toolkit Toolkit used to fetch property from, can be null * in which default will be used. * @param type Type of font being used, corresponds to MetalTheme font * type. */ MetalFontDesktopProperty(String key, Toolkit kit, int type) { super(key, null, kit); this.type = type; } /** {@collect.stats} * Overriden to create a Font with the size coming from the desktop * and the style and name coming from DefaultMetalTheme. */ protected Object configureValue(Object value) { if (value instanceof Integer) { value = new Font(DefaultMetalTheme.getDefaultFontName(type), DefaultMetalTheme.getDefaultFontStyle(type), ((Integer)value).intValue()); } return super.configureValue(value); } /** {@collect.stats} * Returns the default font. */ protected Object getDefaultValue() { return new Font(DefaultMetalTheme.getDefaultFontName(type), DefaultMetalTheme.getDefaultFontStyle(type), DefaultMetalTheme.getDefaultFontSize(type)); } }
Java
/* * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import javax.swing.plaf.*; import java.io.Serializable; import javax.swing.plaf.basic.BasicTabbedPaneUI; /** {@collect.stats} * The Metal subclass of BasicTabbedPaneUI. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Tom Santos */ public class MetalTabbedPaneUI extends BasicTabbedPaneUI { protected int minTabWidth = 40; // Background color for unselected tabs that don't have an explicitly // set color. private Color unselectedBackground; protected Color tabAreaBackground; protected Color selectColor; protected Color selectHighlight; private boolean tabsOpaque = true; // Whether or not we're using ocean. This is cached as it is used // extensively during painting. private boolean ocean; // Selected border color for ocean. private Color oceanSelectedBorderColor; public static ComponentUI createUI( JComponent x ) { return new MetalTabbedPaneUI(); } protected LayoutManager createLayoutManager() { if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) { return super.createLayoutManager(); } return new TabbedPaneLayout(); } protected void installDefaults() { super.installDefaults(); tabAreaBackground = UIManager.getColor("TabbedPane.tabAreaBackground"); selectColor = UIManager.getColor("TabbedPane.selected"); selectHighlight = UIManager.getColor("TabbedPane.selectHighlight"); tabsOpaque = UIManager.getBoolean("TabbedPane.tabsOpaque"); unselectedBackground = UIManager.getColor( "TabbedPane.unselectedBackground"); ocean = MetalLookAndFeel.usingOcean(); if (ocean) { oceanSelectedBorderColor = UIManager.getColor( "TabbedPane.borderHightlightColor"); } } protected void paintTabBorder( Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { int bottom = y + (h-1); int right = x + (w-1); switch ( tabPlacement ) { case LEFT: paintLeftTabBorder(tabIndex, g, x, y, w, h, bottom, right, isSelected); break; case BOTTOM: paintBottomTabBorder(tabIndex, g, x, y, w, h, bottom, right, isSelected); break; case RIGHT: paintRightTabBorder(tabIndex, g, x, y, w, h, bottom, right, isSelected); break; case TOP: default: paintTopTabBorder(tabIndex, g, x, y, w, h, bottom, right, isSelected); } } protected void paintTopTabBorder( int tabIndex, Graphics g, int x, int y, int w, int h, int btm, int rght, boolean isSelected ) { int currentRun = getRunForTab( tabPane.getTabCount(), tabIndex ); int lastIndex = lastTabInRun( tabPane.getTabCount(), currentRun ); int firstIndex = tabRuns[ currentRun ]; boolean leftToRight = MetalUtils.isLeftToRight(tabPane); int selectedIndex = tabPane.getSelectedIndex(); int bottom = h - 1; int right = w - 1; // // Paint Gap // if (shouldFillGap( currentRun, tabIndex, x, y ) ) { g.translate( x, y ); if ( leftToRight ) { g.setColor( getColorForGap( currentRun, x, y + 1 ) ); g.fillRect( 1, 0, 5, 3 ); g.fillRect( 1, 3, 2, 2 ); } else { g.setColor( getColorForGap( currentRun, x + w - 1, y + 1 ) ); g.fillRect( right - 5, 0, 5, 3 ); g.fillRect( right - 2, 3, 2, 2 ); } g.translate( -x, -y ); } g.translate( x, y ); // // Paint Border // if (ocean && isSelected) { g.setColor(oceanSelectedBorderColor); } else { g.setColor( darkShadow ); } if ( leftToRight ) { // Paint slant g.drawLine( 1, 5, 6, 0 ); // Paint top g.drawLine( 6, 0, right, 0 ); // Paint right if ( tabIndex==lastIndex ) { // last tab in run g.drawLine( right, 1, right, bottom ); } if (ocean && tabIndex - 1 == selectedIndex && currentRun == getRunForTab( tabPane.getTabCount(), selectedIndex)) { g.setColor(oceanSelectedBorderColor); } // Paint left if ( tabIndex != tabRuns[ runCount - 1 ] ) { // not the first tab in the last run if (ocean && isSelected) { g.drawLine(0, 6, 0, bottom); g.setColor(darkShadow); g.drawLine(0, 0, 0, 5); } else { g.drawLine( 0, 0, 0, bottom ); } } else { // the first tab in the last run g.drawLine( 0, 6, 0, bottom ); } } else { // Paint slant g.drawLine( right - 1, 5, right - 6, 0 ); // Paint top g.drawLine( right - 6, 0, 0, 0 ); // Paint left if ( tabIndex==lastIndex ) { // last tab in run g.drawLine( 0, 1, 0, bottom ); } // Paint right if (ocean && tabIndex - 1 == selectedIndex && currentRun == getRunForTab( tabPane.getTabCount(), selectedIndex)) { g.setColor(oceanSelectedBorderColor); g.drawLine(right, 0, right, bottom); } else if (ocean && isSelected) { g.drawLine(right, 6, right, bottom); if (tabIndex != 0) { g.setColor(darkShadow); g.drawLine(right, 0, right, 5); } } else { if ( tabIndex != tabRuns[ runCount - 1 ] ) { // not the first tab in the last run g.drawLine( right, 0, right, bottom ); } else { // the first tab in the last run g.drawLine( right, 6, right, bottom ); } } } // // Paint Highlight // g.setColor( isSelected ? selectHighlight : highlight ); if ( leftToRight ) { // Paint slant g.drawLine( 1, 6, 6, 1 ); // Paint top g.drawLine( 6, 1, (tabIndex == lastIndex) ? right - 1 : right, 1 ); // Paint left g.drawLine( 1, 6, 1, bottom ); // paint highlight in the gap on tab behind this one // on the left end (where they all line up) if ( tabIndex==firstIndex && tabIndex!=tabRuns[runCount - 1] ) { // first tab in run but not first tab in last run if (tabPane.getSelectedIndex()==tabRuns[currentRun+1]) { // tab in front of selected tab g.setColor( selectHighlight ); } else { // tab in front of normal tab g.setColor( highlight ); } g.drawLine( 1, 0, 1, 4 ); } } else { // Paint slant g.drawLine( right - 1, 6, right - 6, 1 ); // Paint top g.drawLine( right - 6, 1, 1, 1 ); // Paint left if ( tabIndex==lastIndex ) { // last tab in run g.drawLine( 1, 1, 1, bottom ); } else { g.drawLine( 0, 1, 0, bottom ); } } g.translate( -x, -y ); } protected boolean shouldFillGap( int currentRun, int tabIndex, int x, int y ) { boolean result = false; if (!tabsOpaque) { return false; } if ( currentRun == runCount - 2 ) { // If it's the second to last row. Rectangle lastTabBounds = getTabBounds( tabPane, tabPane.getTabCount() - 1 ); Rectangle tabBounds = getTabBounds( tabPane, tabIndex ); if (MetalUtils.isLeftToRight(tabPane)) { int lastTabRight = lastTabBounds.x + lastTabBounds.width - 1; // is the right edge of the last tab to the right // of the left edge of the current tab? if ( lastTabRight > tabBounds.x + 2 ) { return true; } } else { int lastTabLeft = lastTabBounds.x; int currentTabRight = tabBounds.x + tabBounds.width - 1; // is the left edge of the last tab to the left // of the right edge of the current tab? if ( lastTabLeft < currentTabRight - 2 ) { return true; } } } else { // fill in gap for all other rows except last row result = currentRun != runCount - 1; } return result; } protected Color getColorForGap( int currentRun, int x, int y ) { final int shadowWidth = 4; int selectedIndex = tabPane.getSelectedIndex(); int startIndex = tabRuns[ currentRun + 1 ]; int endIndex = lastTabInRun( tabPane.getTabCount(), currentRun + 1 ); int tabOverGap = -1; // Check each tab in the row that is 'on top' of this row for ( int i = startIndex; i <= endIndex; ++i ) { Rectangle tabBounds = getTabBounds( tabPane, i ); int tabLeft = tabBounds.x; int tabRight = (tabBounds.x + tabBounds.width) - 1; // Check to see if this tab is over the gap if ( MetalUtils.isLeftToRight(tabPane) ) { if ( tabLeft <= x && tabRight - shadowWidth > x ) { return selectedIndex == i ? selectColor : getUnselectedBackgroundAt( i ); } } else { if ( tabLeft + shadowWidth < x && tabRight >= x ) { return selectedIndex == i ? selectColor : getUnselectedBackgroundAt( i ); } } } return tabPane.getBackground(); } protected void paintLeftTabBorder( int tabIndex, Graphics g, int x, int y, int w, int h, int btm, int rght, boolean isSelected ) { int tabCount = tabPane.getTabCount(); int currentRun = getRunForTab( tabCount, tabIndex ); int lastIndex = lastTabInRun( tabCount, currentRun ); int firstIndex = tabRuns[ currentRun ]; g.translate( x, y ); int bottom = h - 1; int right = w - 1; // // Paint part of the tab above // if ( tabIndex != firstIndex && tabsOpaque ) { g.setColor( tabPane.getSelectedIndex() == tabIndex - 1 ? selectColor : getUnselectedBackgroundAt( tabIndex - 1 ) ); g.fillRect( 2, 0, 4, 3 ); g.drawLine( 2, 3, 2, 3 ); } // // Paint Highlight // if (ocean) { g.setColor(isSelected ? selectHighlight : MetalLookAndFeel.getWhite()); } else { g.setColor( isSelected ? selectHighlight : highlight ); } // Paint slant g.drawLine( 1, 6, 6, 1 ); // Paint left g.drawLine( 1, 6, 1, bottom ); // Paint top g.drawLine( 6, 1, right, 1 ); if ( tabIndex != firstIndex ) { if (tabPane.getSelectedIndex() == tabIndex - 1) { g.setColor(selectHighlight); } else { g.setColor(ocean ? MetalLookAndFeel.getWhite() : highlight); } g.drawLine( 1, 0, 1, 4 ); } // // Paint Border // if (ocean) { if (isSelected) { g.setColor(oceanSelectedBorderColor); } else { g.setColor( darkShadow ); } } else { g.setColor( darkShadow ); } // Paint slant g.drawLine( 1, 5, 6, 0 ); // Paint top g.drawLine( 6, 0, right, 0 ); // Paint bottom if ( tabIndex == lastIndex ) { g.drawLine( 0, bottom, right, bottom ); } // Paint left if (ocean) { if (tabPane.getSelectedIndex() == tabIndex - 1) { g.drawLine(0, 5, 0, bottom); g.setColor(oceanSelectedBorderColor); g.drawLine(0, 0, 0, 5); } else if (isSelected) { g.drawLine( 0, 6, 0, bottom ); if (tabIndex != 0) { g.setColor(darkShadow); g.drawLine(0, 0, 0, 5); } } else if ( tabIndex != firstIndex ) { g.drawLine( 0, 0, 0, bottom ); } else { g.drawLine( 0, 6, 0, bottom ); } } else { // metal if ( tabIndex != firstIndex ) { g.drawLine( 0, 0, 0, bottom ); } else { g.drawLine( 0, 6, 0, bottom ); } } g.translate( -x, -y ); } protected void paintBottomTabBorder( int tabIndex, Graphics g, int x, int y, int w, int h, int btm, int rght, boolean isSelected ) { int tabCount = tabPane.getTabCount(); int currentRun = getRunForTab( tabCount, tabIndex ); int lastIndex = lastTabInRun( tabCount, currentRun ); int firstIndex = tabRuns[ currentRun ]; boolean leftToRight = MetalUtils.isLeftToRight(tabPane); int bottom = h - 1; int right = w - 1; // // Paint Gap // if ( shouldFillGap( currentRun, tabIndex, x, y ) ) { g.translate( x, y ); if ( leftToRight ) { g.setColor( getColorForGap( currentRun, x, y ) ); g.fillRect( 1, bottom - 4, 3, 5 ); g.fillRect( 4, bottom - 1, 2, 2 ); } else { g.setColor( getColorForGap( currentRun, x + w - 1, y ) ); g.fillRect( right - 3, bottom - 3, 3, 4 ); g.fillRect( right - 5, bottom - 1, 2, 2 ); g.drawLine( right - 1, bottom - 4, right - 1, bottom - 4 ); } g.translate( -x, -y ); } g.translate( x, y ); // // Paint Border // if (ocean && isSelected) { g.setColor(oceanSelectedBorderColor); } else { g.setColor( darkShadow ); } if ( leftToRight ) { // Paint slant g.drawLine( 1, bottom - 5, 6, bottom ); // Paint bottom g.drawLine( 6, bottom, right, bottom ); // Paint right if ( tabIndex == lastIndex ) { g.drawLine( right, 0, right, bottom ); } // Paint left if (ocean && isSelected) { g.drawLine(0, 0, 0, bottom - 6); if ((currentRun == 0 && tabIndex != 0) || (currentRun > 0 && tabIndex != tabRuns[currentRun - 1])) { g.setColor(darkShadow); g.drawLine(0, bottom - 5, 0, bottom); } } else { if (ocean && tabIndex == tabPane.getSelectedIndex() + 1) { g.setColor(oceanSelectedBorderColor); } if ( tabIndex != tabRuns[ runCount - 1 ] ) { g.drawLine( 0, 0, 0, bottom ); } else { g.drawLine( 0, 0, 0, bottom - 6 ); } } } else { // Paint slant g.drawLine( right - 1, bottom - 5, right - 6, bottom ); // Paint bottom g.drawLine( right - 6, bottom, 0, bottom ); // Paint left if ( tabIndex==lastIndex ) { // last tab in run g.drawLine( 0, 0, 0, bottom ); } // Paint right if (ocean && tabIndex == tabPane.getSelectedIndex() + 1) { g.setColor(oceanSelectedBorderColor); g.drawLine(right, 0, right, bottom); } else if (ocean && isSelected) { g.drawLine(right, 0, right, bottom - 6); if (tabIndex != firstIndex) { g.setColor(darkShadow); g.drawLine(right, bottom - 5, right, bottom); } } else if ( tabIndex != tabRuns[ runCount - 1 ] ) { // not the first tab in the last run g.drawLine( right, 0, right, bottom ); } else { // the first tab in the last run g.drawLine( right, 0, right, bottom - 6 ); } } // // Paint Highlight // g.setColor( isSelected ? selectHighlight : highlight ); if ( leftToRight ) { // Paint slant g.drawLine( 1, bottom - 6, 6, bottom - 1 ); // Paint left g.drawLine( 1, 0, 1, bottom - 6 ); // paint highlight in the gap on tab behind this one // on the left end (where they all line up) if ( tabIndex==firstIndex && tabIndex!=tabRuns[runCount - 1] ) { // first tab in run but not first tab in last run if (tabPane.getSelectedIndex()==tabRuns[currentRun+1]) { // tab in front of selected tab g.setColor( selectHighlight ); } else { // tab in front of normal tab g.setColor( highlight ); } g.drawLine( 1, bottom - 4, 1, bottom ); } } else { // Paint left if ( tabIndex==lastIndex ) { // last tab in run g.drawLine( 1, 0, 1, bottom - 1 ); } else { g.drawLine( 0, 0, 0, bottom - 1 ); } } g.translate( -x, -y ); } protected void paintRightTabBorder( int tabIndex, Graphics g, int x, int y, int w, int h, int btm, int rght, boolean isSelected ) { int tabCount = tabPane.getTabCount(); int currentRun = getRunForTab( tabCount, tabIndex ); int lastIndex = lastTabInRun( tabCount, currentRun ); int firstIndex = tabRuns[ currentRun ]; g.translate( x, y ); int bottom = h - 1; int right = w - 1; // // Paint part of the tab above // if ( tabIndex != firstIndex && tabsOpaque ) { g.setColor( tabPane.getSelectedIndex() == tabIndex - 1 ? selectColor : getUnselectedBackgroundAt( tabIndex - 1 ) ); g.fillRect( right - 5, 0, 5, 3 ); g.fillRect( right - 2, 3, 2, 2 ); } // // Paint Highlight // g.setColor( isSelected ? selectHighlight : highlight ); // Paint slant g.drawLine( right - 6, 1, right - 1, 6 ); // Paint top g.drawLine( 0, 1, right - 6, 1 ); // Paint left if ( !isSelected ) { g.drawLine( 0, 1, 0, bottom ); } // // Paint Border // if (ocean && isSelected) { g.setColor(oceanSelectedBorderColor); } else { g.setColor( darkShadow ); } // Paint bottom if ( tabIndex == lastIndex ) { g.drawLine( 0, bottom, right, bottom ); } // Paint slant if (ocean && tabPane.getSelectedIndex() == tabIndex - 1) { g.setColor(oceanSelectedBorderColor); } g.drawLine( right - 6, 0, right, 6 ); // Paint top g.drawLine( 0, 0, right - 6, 0 ); // Paint right if (ocean && isSelected) { g.drawLine(right, 6, right, bottom); if (tabIndex != firstIndex) { g.setColor(darkShadow); g.drawLine(right, 0, right, 5); } } else if (ocean && tabPane.getSelectedIndex() == tabIndex - 1) { g.setColor(oceanSelectedBorderColor); g.drawLine(right, 0, right, 6); g.setColor(darkShadow); g.drawLine(right, 6, right, bottom); } else if ( tabIndex != firstIndex ) { g.drawLine( right, 0, right, bottom ); } else { g.drawLine( right, 6, right, bottom ); } g.translate( -x, -y ); } public void update( Graphics g, JComponent c ) { if ( c.isOpaque() ) { g.setColor( tabAreaBackground ); g.fillRect( 0, 0, c.getWidth(),c.getHeight() ); } paint( g, c ); } protected void paintTabBackground( Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected ) { int slantWidth = h / 2; if ( isSelected ) { g.setColor( selectColor ); } else { g.setColor( getUnselectedBackgroundAt( tabIndex ) ); } if (MetalUtils.isLeftToRight(tabPane)) { switch ( tabPlacement ) { case LEFT: g.fillRect( x + 5, y + 1, w - 5, h - 1); g.fillRect( x + 2, y + 4, 3, h - 4 ); break; case BOTTOM: g.fillRect( x + 2, y, w - 2, h - 4 ); g.fillRect( x + 5, y + (h - 1) - 3, w - 5, 3 ); break; case RIGHT: g.fillRect( x, y + 2, w - 4, h - 2); g.fillRect( x + (w - 1) - 3, y + 5, 3, h - 5 ); break; case TOP: default: g.fillRect( x + 4, y + 2, (w - 1) - 3, (h - 1) - 1 ); g.fillRect( x + 2, y + 5, 2, h - 5 ); } } else { switch ( tabPlacement ) { case LEFT: g.fillRect( x + 5, y + 1, w - 5, h - 1); g.fillRect( x + 2, y + 4, 3, h - 4 ); break; case BOTTOM: g.fillRect( x, y, w - 5, h - 1 ); g.fillRect( x + (w - 1) - 4, y, 4, h - 5); g.fillRect( x + (w - 1) - 4, y + (h - 1) - 4, 2, 2); break; case RIGHT: g.fillRect( x + 1, y + 1, w - 5, h - 1); g.fillRect( x + (w - 1) - 3, y + 5, 3, h - 5 ); break; case TOP: default: g.fillRect( x, y + 2, (w - 1) - 3, (h - 1) - 1 ); g.fillRect( x + (w - 1) - 3, y + 5, 3, h - 3 ); } } } /** {@collect.stats} * Overridden to do nothing for the Java L&F. */ protected int getTabLabelShiftX( int tabPlacement, int tabIndex, boolean isSelected ) { return 0; } /** {@collect.stats} * Overridden to do nothing for the Java L&F. */ protected int getTabLabelShiftY( int tabPlacement, int tabIndex, boolean isSelected ) { return 0; } /** {@collect.stats} * {@inheritDoc} * * @since 1.6 */ protected int getBaselineOffset() { return 0; } public void paint( Graphics g, JComponent c ) { int tabPlacement = tabPane.getTabPlacement(); Insets insets = c.getInsets(); Dimension size = c.getSize(); // Paint the background for the tab area if ( tabPane.isOpaque() ) { Color bg = UIManager.getColor("TabbedPane.tabAreaBackground"); if (bg != null) { g.setColor(bg); } else { g.setColor( c.getBackground() ); } switch ( tabPlacement ) { case LEFT: g.fillRect( insets.left, insets.top, calculateTabAreaWidth( tabPlacement, runCount, maxTabWidth ), size.height - insets.bottom - insets.top ); break; case BOTTOM: int totalTabHeight = calculateTabAreaHeight( tabPlacement, runCount, maxTabHeight ); g.fillRect( insets.left, size.height - insets.bottom - totalTabHeight, size.width - insets.left - insets.right, totalTabHeight ); break; case RIGHT: int totalTabWidth = calculateTabAreaWidth( tabPlacement, runCount, maxTabWidth ); g.fillRect( size.width - insets.right - totalTabWidth, insets.top, totalTabWidth, size.height - insets.top - insets.bottom ); break; case TOP: default: g.fillRect( insets.left, insets.top, size.width - insets.right - insets.left, calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight) ); paintHighlightBelowTab(); } } super.paint( g, c ); } protected void paintHighlightBelowTab( ) { } protected void paintFocusIndicator(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected) { if ( tabPane.hasFocus() && isSelected ) { Rectangle tabRect = rects[tabIndex]; boolean lastInRun = isLastInRun( tabIndex ); g.setColor( focus ); g.translate( tabRect.x, tabRect.y ); int right = tabRect.width - 1; int bottom = tabRect.height - 1; boolean leftToRight = MetalUtils.isLeftToRight(tabPane); switch ( tabPlacement ) { case RIGHT: g.drawLine( right - 6,2 , right - 2,6 ); // slant g.drawLine( 1,2 , right - 6,2 ); // top g.drawLine( right - 2,6 , right - 2,bottom ); // right g.drawLine( 1,2 , 1,bottom ); // left g.drawLine( 1,bottom , right - 2,bottom ); // bottom break; case BOTTOM: if ( leftToRight ) { g.drawLine( 2, bottom - 6, 6, bottom - 2 ); // slant g.drawLine( 6, bottom - 2, right, bottom - 2 ); // bottom g.drawLine( 2, 0, 2, bottom - 6 ); // left g.drawLine( 2, 0, right, 0 ); // top g.drawLine( right, 0, right, bottom - 2 ); // right } else { g.drawLine( right - 2, bottom - 6, right - 6, bottom - 2 ); // slant g.drawLine( right - 2, 0, right - 2, bottom - 6 ); // right if ( lastInRun ) { // last tab in run g.drawLine( 2, bottom - 2, right - 6, bottom - 2 ); // bottom g.drawLine( 2, 0, right - 2, 0 ); // top g.drawLine( 2, 0, 2, bottom - 2 ); // left } else { g.drawLine( 1, bottom - 2, right - 6, bottom - 2 ); // bottom g.drawLine( 1, 0, right - 2, 0 ); // top g.drawLine( 1, 0, 1, bottom - 2 ); // left } } break; case LEFT: g.drawLine( 2, 6, 6, 2 ); // slant g.drawLine( 2, 6, 2, bottom - 1); // left g.drawLine( 6, 2, right, 2 ); // top g.drawLine( right, 2, right, bottom - 1 ); // right g.drawLine( 2, bottom - 1, right, bottom - 1 ); // bottom break; case TOP: default: if ( leftToRight ) { g.drawLine( 2, 6, 6, 2 ); // slant g.drawLine( 2, 6, 2, bottom - 1); // left g.drawLine( 6, 2, right, 2 ); // top g.drawLine( right, 2, right, bottom - 1 ); // right g.drawLine( 2, bottom - 1, right, bottom - 1 ); // bottom } else { g.drawLine( right - 2, 6, right - 6, 2 ); // slant g.drawLine( right - 2, 6, right - 2, bottom - 1); // right if ( lastInRun ) { // last tab in run g.drawLine( right - 6, 2, 2, 2 ); // top g.drawLine( 2, 2, 2, bottom - 1 ); // left g.drawLine( right - 2, bottom - 1, 2, bottom - 1 ); // bottom } else { g.drawLine( right - 6, 2, 1, 2 ); // top g.drawLine( 1, 2, 1, bottom - 1 ); // left g.drawLine( right - 2, bottom - 1, 1, bottom - 1 ); // bottom } } } g.translate( -tabRect.x, -tabRect.y ); } } protected void paintContentBorderTopEdge( Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h ) { boolean leftToRight = MetalUtils.isLeftToRight(tabPane); int right = x + w - 1; Rectangle selRect = selectedIndex < 0? null : getTabBounds(selectedIndex, calcRect); if (ocean) { g.setColor(oceanSelectedBorderColor); } else { g.setColor(selectHighlight); } // Draw unbroken line if tabs are not on TOP, OR // selected tab is not in run adjacent to content, OR // selected tab is not visible (SCROLL_TAB_LAYOUT) // if (tabPlacement != TOP || selectedIndex < 0 || (selRect.y + selRect.height + 1 < y) || (selRect.x < x || selRect.x > x + w)) { g.drawLine(x, y, x+w-2, y); if (ocean && tabPlacement == TOP) { g.setColor(MetalLookAndFeel.getWhite()); g.drawLine(x, y + 1, x+w-2, y + 1); } } else { // Break line to show visual connection to selected tab boolean lastInRun = isLastInRun(selectedIndex); if ( leftToRight || lastInRun ) { g.drawLine(x, y, selRect.x + 1, y); } else { g.drawLine(x, y, selRect.x, y); } if (selRect.x + selRect.width < right - 1) { if ( leftToRight && !lastInRun ) { g.drawLine(selRect.x + selRect.width, y, right - 1, y); } else { g.drawLine(selRect.x + selRect.width - 1, y, right - 1, y); } } else { g.setColor(shadow); g.drawLine(x+w-2, y, x+w-2, y); } if (ocean) { g.setColor(MetalLookAndFeel.getWhite()); if ( leftToRight || lastInRun ) { g.drawLine(x, y + 1, selRect.x + 1, y + 1); } else { g.drawLine(x, y + 1, selRect.x, y + 1); } if (selRect.x + selRect.width < right - 1) { if ( leftToRight && !lastInRun ) { g.drawLine(selRect.x + selRect.width, y + 1, right - 1, y + 1); } else { g.drawLine(selRect.x + selRect.width - 1, y + 1, right - 1, y + 1); } } else { g.setColor(shadow); g.drawLine(x+w-2, y + 1, x+w-2, y + 1); } } } } protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) { boolean leftToRight = MetalUtils.isLeftToRight(tabPane); int bottom = y + h - 1; int right = x + w - 1; Rectangle selRect = selectedIndex < 0? null : getTabBounds(selectedIndex, calcRect); g.setColor(darkShadow); // Draw unbroken line if tabs are not on BOTTOM, OR // selected tab is not in run adjacent to content, OR // selected tab is not visible (SCROLL_TAB_LAYOUT) // if (tabPlacement != BOTTOM || selectedIndex < 0 || (selRect.y - 1 > h) || (selRect.x < x || selRect.x > x + w)) { if (ocean && tabPlacement == BOTTOM) { g.setColor(oceanSelectedBorderColor); } g.drawLine(x, y+h-1, x+w-1, y+h-1); } else { // Break line to show visual connection to selected tab boolean lastInRun = isLastInRun(selectedIndex); if (ocean) { g.setColor(oceanSelectedBorderColor); } if ( leftToRight || lastInRun ) { g.drawLine(x, bottom, selRect.x, bottom); } else { g.drawLine(x, bottom, selRect.x - 1, bottom); } if (selRect.x + selRect.width < x + w - 2) { if ( leftToRight && !lastInRun ) { g.drawLine(selRect.x + selRect.width, bottom, right, bottom); } else { g.drawLine(selRect.x + selRect.width - 1, bottom, right, bottom); } } } } protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) { Rectangle selRect = selectedIndex < 0? null : getTabBounds(selectedIndex, calcRect); if (ocean) { g.setColor(oceanSelectedBorderColor); } else { g.setColor(selectHighlight); } // Draw unbroken line if tabs are not on LEFT, OR // selected tab is not in run adjacent to content, OR // selected tab is not visible (SCROLL_TAB_LAYOUT) // if (tabPlacement != LEFT || selectedIndex < 0 || (selRect.x + selRect.width + 1 < x) || (selRect.y < y || selRect.y > y + h)) { g.drawLine(x, y + 1, x, y+h-2); if (ocean && tabPlacement == LEFT) { g.setColor(MetalLookAndFeel.getWhite()); g.drawLine(x + 1, y, x + 1, y + h - 2); } } else { // Break line to show visual connection to selected tab g.drawLine(x, y, x, selRect.y + 1); if (selRect.y + selRect.height < y + h - 2) { g.drawLine(x, selRect.y + selRect.height + 1, x, y+h+2); } if (ocean) { g.setColor(MetalLookAndFeel.getWhite()); g.drawLine(x + 1, y + 1, x + 1, selRect.y + 1); if (selRect.y + selRect.height < y + h - 2) { g.drawLine(x + 1, selRect.y + selRect.height + 1, x + 1, y+h+2); } } } } protected void paintContentBorderRightEdge(Graphics g, int tabPlacement, int selectedIndex, int x, int y, int w, int h) { Rectangle selRect = selectedIndex < 0? null : getTabBounds(selectedIndex, calcRect); g.setColor(darkShadow); // Draw unbroken line if tabs are not on RIGHT, OR // selected tab is not in run adjacent to content, OR // selected tab is not visible (SCROLL_TAB_LAYOUT) // if (tabPlacement != RIGHT || selectedIndex < 0 || (selRect.x - 1 > w) || (selRect.y < y || selRect.y > y + h)) { if (ocean && tabPlacement == RIGHT) { g.setColor(oceanSelectedBorderColor); } g.drawLine(x+w-1, y, x+w-1, y+h-1); } else { // Break line to show visual connection to selected tab if (ocean) { g.setColor(oceanSelectedBorderColor); } g.drawLine(x+w-1, y, x+w-1, selRect.y); if (selRect.y + selRect.height < y + h - 2) { g.drawLine(x+w-1, selRect.y + selRect.height, x+w-1, y+h-2); } } } protected int calculateMaxTabHeight( int tabPlacement ) { FontMetrics metrics = getFontMetrics(); int height = metrics.getHeight(); boolean tallerIcons = false; for ( int i = 0; i < tabPane.getTabCount(); ++i ) { Icon icon = tabPane.getIconAt( i ); if ( icon != null ) { if ( icon.getIconHeight() > height ) { tallerIcons = true; break; } } } return super.calculateMaxTabHeight( tabPlacement ) - (tallerIcons ? (tabInsets.top + tabInsets.bottom) : 0); } protected int getTabRunOverlay( int tabPlacement ) { // Tab runs laid out vertically should overlap // at least as much as the largest slant if ( tabPlacement == LEFT || tabPlacement == RIGHT ) { int maxTabHeight = calculateMaxTabHeight(tabPlacement); return maxTabHeight / 2; } return 0; } // Don't rotate runs! protected boolean shouldRotateTabRuns( int tabPlacement, int selectedRun ) { return false; } // Don't pad last run protected boolean shouldPadTabRun( int tabPlacement, int run ) { return runCount > 1 && run < runCount - 1; } private boolean isLastInRun( int tabIndex ) { int run = getRunForTab( tabPane.getTabCount(), tabIndex ); int lastIndex = lastTabInRun( tabPane.getTabCount(), run ); return tabIndex == lastIndex; } /** {@collect.stats} * Returns the color to use for the specified tab. */ private Color getUnselectedBackgroundAt(int index) { Color color = tabPane.getBackgroundAt(index); if (color instanceof UIResource) { if (unselectedBackground != null) { return unselectedBackground; } } return color; } /** {@collect.stats} * Returns the tab index of JTabbedPane the mouse is currently over */ int getRolloverTabIndex() { return getRolloverTab(); } /** {@collect.stats} * This inner class is marked &quot;public&quot; due to a compiler bug. * This class should be treated as a &quot;protected&quot; inner class. * Instantiate it only within subclasses of MetalTabbedPaneUI. */ public class TabbedPaneLayout extends BasicTabbedPaneUI.TabbedPaneLayout { public TabbedPaneLayout() { MetalTabbedPaneUI.this.super(); } protected void normalizeTabRuns( int tabPlacement, int tabCount, int start, int max ) { // Only normalize the runs for top & bottom; normalizing // doesn't look right for Metal's vertical tabs // because the last run isn't padded and it looks odd to have // fat tabs in the first vertical runs, but slimmer ones in the // last (this effect isn't noticeable for horizontal tabs). if ( tabPlacement == TOP || tabPlacement == BOTTOM ) { super.normalizeTabRuns( tabPlacement, tabCount, start, max ); } } // Don't rotate runs! protected void rotateTabRuns( int tabPlacement, int selectedRun ) { } // Don't pad selected tab protected void padSelectedTab( int tabPlacement, int selectedIndex ) { } } }
Java
/* * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.plaf.*; import javax.swing.*; import java.awt.*; import java.awt.image.*; import java.lang.ref.*; import java.util.*; import sun.swing.CachedPainter; import sun.swing.ImageIconUIResource; /** {@collect.stats} * This is a dumping ground for random stuff we want to use in several places. * * @author Steve Wilson */ class MetalUtils { static void drawFlush3DBorder(Graphics g, Rectangle r) { drawFlush3DBorder(g, r.x, r.y, r.width, r.height); } /** {@collect.stats} * This draws the "Flush 3D Border" which is used throughout the Metal L&F */ static void drawFlush3DBorder(Graphics g, int x, int y, int w, int h) { g.translate( x, y); g.setColor( MetalLookAndFeel.getControlDarkShadow() ); g.drawRect( 0, 0, w-2, h-2 ); g.setColor( MetalLookAndFeel.getControlHighlight() ); g.drawRect( 1, 1, w-2, h-2 ); g.setColor( MetalLookAndFeel.getControl() ); g.drawLine( 0, h-1, 1, h-2 ); g.drawLine( w-1, 0, w-2, 1 ); g.translate( -x, -y); } /** {@collect.stats} * This draws a variant "Flush 3D Border" * It is used for things like pressed buttons. */ static void drawPressed3DBorder(Graphics g, Rectangle r) { drawPressed3DBorder( g, r.x, r.y, r.width, r.height ); } static void drawDisabledBorder(Graphics g, int x, int y, int w, int h) { g.translate( x, y); g.setColor( MetalLookAndFeel.getControlShadow() ); g.drawRect( 0, 0, w-1, h-1 ); g.translate(-x, -y); } /** {@collect.stats} * This draws a variant "Flush 3D Border" * It is used for things like pressed buttons. */ static void drawPressed3DBorder(Graphics g, int x, int y, int w, int h) { g.translate( x, y); drawFlush3DBorder(g, 0, 0, w, h); g.setColor( MetalLookAndFeel.getControlShadow() ); g.drawLine( 1, 1, 1, h-2 ); g.drawLine( 1, 1, w-2, 1 ); g.translate( -x, -y); } /** {@collect.stats} * This draws a variant "Flush 3D Border" * It is used for things like active toggle buttons. * This is used rarely. */ static void drawDark3DBorder(Graphics g, Rectangle r) { drawDark3DBorder(g, r.x, r.y, r.width, r.height); } /** {@collect.stats} * This draws a variant "Flush 3D Border" * It is used for things like active toggle buttons. * This is used rarely. */ static void drawDark3DBorder(Graphics g, int x, int y, int w, int h) { g.translate( x, y); drawFlush3DBorder(g, 0, 0, w, h); g.setColor( MetalLookAndFeel.getControl() ); g.drawLine( 1, 1, 1, h-2 ); g.drawLine( 1, 1, w-2, 1 ); g.setColor( MetalLookAndFeel.getControlShadow() ); g.drawLine( 1, h-2, 1, h-2 ); g.drawLine( w-2, 1, w-2, 1 ); g.translate( -x, -y); } static void drawButtonBorder(Graphics g, int x, int y, int w, int h, boolean active) { if (active) { drawActiveButtonBorder(g, x, y, w, h); } else { drawFlush3DBorder(g, x, y, w, h); } } static void drawActiveButtonBorder(Graphics g, int x, int y, int w, int h) { drawFlush3DBorder(g, x, y, w, h); g.setColor( MetalLookAndFeel.getPrimaryControl() ); g.drawLine( x+1, y+1, x+1, h-3 ); g.drawLine( x+1, y+1, w-3, x+1 ); g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() ); g.drawLine( x+2, h-2, w-2, h-2 ); g.drawLine( w-2, y+2, w-2, h-2 ); } static void drawDefaultButtonBorder(Graphics g, int x, int y, int w, int h, boolean active) { drawButtonBorder(g, x+1, y+1, w-1, h-1, active); g.translate(x, y); g.setColor( MetalLookAndFeel.getControlDarkShadow() ); g.drawRect( 0, 0, w-3, h-3 ); g.drawLine( w-2, 0, w-2, 0); g.drawLine( 0, h-2, 0, h-2); g.translate(-x, -y); } static void drawDefaultButtonPressedBorder(Graphics g, int x, int y, int w, int h) { drawPressed3DBorder(g, x + 1, y + 1, w - 1, h - 1); g.translate(x, y); g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(0, 0, w - 3, h - 3); g.drawLine(w - 2, 0, w - 2, 0); g.drawLine(0, h - 2, 0, h - 2); g.setColor(MetalLookAndFeel.getControl()); g.drawLine(w - 1, 0, w - 1, 0); g.drawLine(0, h - 1, 0, h - 1); g.translate(-x, -y); } /* * Convenience function for determining ComponentOrientation. Helps us * avoid having Munge directives throughout the code. */ static boolean isLeftToRight( Component c ) { return c.getComponentOrientation().isLeftToRight(); } static int getInt(Object key, int defaultValue) { Object value = UIManager.get(key); if (value instanceof Integer) { return ((Integer)value).intValue(); } if (value instanceof String) { try { return Integer.parseInt((String)value); } catch (NumberFormatException nfe) {} } return defaultValue; } // // Ocean specific stuff. // /** {@collect.stats} * Draws a radial type gradient. The gradient will be drawn vertically if * <code>vertical</code> is true, otherwise horizontally. * The UIManager key consists of five values: * r1 r2 c1 c2 c3. The gradient is broken down into four chunks drawn * in order from the origin. * <ol> * <li>Gradient r1 % of the size from c1 to c2 * <li>Rectangle r2 % of the size in c2. * <li>Gradient r1 % of the size from c2 to c1 * <li>The remaining size will be filled with a gradient from c1 to c3. * </ol> * * @param c Component rendering to * @param g Graphics to draw to. * @param key UIManager key used to look up gradient values. * @param x X coordinate to draw from * @param y Y coordinate to draw from * @param w Width to draw to * @param h Height to draw to * @param vertical Direction of the gradient * @return true if <code>key</code> exists, otherwise false. */ static boolean drawGradient(Component c, Graphics g, String key, int x, int y, int w, int h, boolean vertical) { java.util.List gradient = (java.util.List)UIManager.get(key); if (gradient == null || !(g instanceof Graphics2D)) { return false; } if (w <= 0 || h <= 0) { return true; } GradientPainter.INSTANCE.paint( c, (Graphics2D)g, gradient, x, y, w, h, vertical); return true; } private static class GradientPainter extends CachedPainter { /** {@collect.stats} * Instance used for painting. This is the only instance that is * ever created. */ public static final GradientPainter INSTANCE = new GradientPainter(8); // Size of images to create. For vertical gradients this is the width, // otherwise it's the height. private static final int IMAGE_SIZE = 64; /** {@collect.stats} * This is the actual width we're painting in, or last painted to. */ private int w; /** {@collect.stats} * This is the actual height we're painting in, or last painted to */ private int h; GradientPainter(int count) { super(count); } public void paint(Component c, Graphics2D g, java.util.List gradient, int x, int y, int w, int h, boolean isVertical) { int imageWidth; int imageHeight; if (isVertical) { imageWidth = IMAGE_SIZE; imageHeight = h; } else { imageWidth = w; imageHeight = IMAGE_SIZE; } synchronized(c.getTreeLock()) { this.w = w; this.h = h; paint(c, g, x, y, imageWidth, imageHeight, gradient, isVertical); } } protected void paintToImage(Component c, Image image, Graphics g, int w, int h, Object[] args) { Graphics2D g2 = (Graphics2D)g; java.util.List gradient = (java.util.List)args[0]; boolean isVertical = ((Boolean)args[1]).booleanValue(); // Render to the VolatileImage if (isVertical) { drawVerticalGradient(g2, ((Number)gradient.get(0)).floatValue(), ((Number)gradient.get(1)).floatValue(), (Color)gradient.get(2), (Color)gradient.get(3), (Color)gradient.get(4), w, h); } else { drawHorizontalGradient(g2, ((Number)gradient.get(0)).floatValue(), ((Number)gradient.get(1)).floatValue(), (Color)gradient.get(2), (Color)gradient.get(3), (Color)gradient.get(4), w, h); } } protected void paintImage(Component c, Graphics g, int x, int y, int imageW, int imageH, Image image, Object[] args) { boolean isVertical = ((Boolean)args[1]).booleanValue(); // Render to the screen g.translate(x, y); if (isVertical) { for (int counter = 0; counter < w; counter += IMAGE_SIZE) { int tileSize = Math.min(IMAGE_SIZE, w - counter); g.drawImage(image, counter, 0, counter + tileSize, h, 0, 0, tileSize, h, null); } } else { for (int counter = 0; counter < h; counter += IMAGE_SIZE) { int tileSize = Math.min(IMAGE_SIZE, h - counter); g.drawImage(image, 0, counter, w, counter + tileSize, 0, 0, w, tileSize, null); } } g.translate(-x, -y); } private void drawVerticalGradient(Graphics2D g, float ratio1, float ratio2, Color c1,Color c2, Color c3, int w, int h) { int mid = (int)(ratio1 * h); int mid2 = (int)(ratio2 * h); if (mid > 0) { g.setPaint(getGradient((float)0, (float)0, c1, (float)0, (float)mid, c2)); g.fillRect(0, 0, w, mid); } if (mid2 > 0) { g.setColor(c2); g.fillRect(0, mid, w, mid2); } if (mid > 0) { g.setPaint(getGradient((float)0, (float)mid + mid2, c2, (float)0, (float)mid * 2 + mid2, c1)); g.fillRect(0, mid + mid2, w, mid); } if (h - mid * 2 - mid2 > 0) { g.setPaint(getGradient((float)0, (float)mid * 2 + mid2, c1, (float)0, (float)h, c3)); g.fillRect(0, mid * 2 + mid2, w, h - mid * 2 - mid2); } } private void drawHorizontalGradient(Graphics2D g, float ratio1, float ratio2, Color c1,Color c2, Color c3, int w, int h) { int mid = (int)(ratio1 * w); int mid2 = (int)(ratio2 * w); if (mid > 0) { g.setPaint(getGradient((float)0, (float)0, c1, (float)mid, (float)0, c2)); g.fillRect(0, 0, mid, h); } if (mid2 > 0) { g.setColor(c2); g.fillRect(mid, 0, mid2, h); } if (mid > 0) { g.setPaint(getGradient((float)mid + mid2, (float)0, c2, (float)mid * 2 + mid2, (float)0, c1)); g.fillRect(mid + mid2, 0, mid, h); } if (w - mid * 2 - mid2 > 0) { g.setPaint(getGradient((float)mid * 2 + mid2, (float)0, c1, w, (float)0, c3)); g.fillRect(mid * 2 + mid2, 0, w - mid * 2 - mid2, h); } } private GradientPaint getGradient(float x1, float y1, Color c1, float x2, float y2, Color c2) { return new GradientPaint(x1, y1, c1, x2, y2, c2, true); } } /** {@collect.stats} * Returns true if the specified widget is in a toolbar. */ static boolean isToolBarButton(JComponent c) { return (c.getParent() instanceof JToolBar); } static Icon getOceanToolBarIcon(Image i) { ImageProducer prod = new FilteredImageSource(i.getSource(), new OceanToolBarImageFilter()); return new ImageIconUIResource(Toolkit.getDefaultToolkit().createImage(prod)); } static Icon getOceanDisabledButtonIcon(Image image) { Object[] range = (Object[])UIManager.get("Button.disabledGrayRange"); int min = 180; int max = 215; if (range != null) { min = ((Integer)range[0]).intValue(); max = ((Integer)range[1]).intValue(); } ImageProducer prod = new FilteredImageSource(image.getSource(), new OceanDisabledButtonImageFilter(min , max)); return new ImageIconUIResource(Toolkit.getDefaultToolkit().createImage(prod)); } /** {@collect.stats} * Used to create a disabled Icon with the ocean look. */ private static class OceanDisabledButtonImageFilter extends RGBImageFilter{ private float min; private float factor; OceanDisabledButtonImageFilter(int min, int max) { canFilterIndexColorModel = true; this.min = (float)min; this.factor = (max - min) / 255f; } public int filterRGB(int x, int y, int rgb) { // Coefficients are from the sRGB color space: int gray = Math.min(255, (int)(((0.2125f * ((rgb >> 16) & 0xFF)) + (0.7154f * ((rgb >> 8) & 0xFF)) + (0.0721f * (rgb & 0xFF)) + .5f) * factor + min)); return (rgb & 0xff000000) | (gray << 16) | (gray << 8) | (gray << 0); } } /** {@collect.stats} * Used to create the rollover icons with the ocean look. */ private static class OceanToolBarImageFilter extends RGBImageFilter { OceanToolBarImageFilter() { canFilterIndexColorModel = true; } public int filterRGB(int x, int y, int rgb) { int r = ((rgb >> 16) & 0xff); int g = ((rgb >> 8) & 0xff); int b = (rgb & 0xff); int gray = Math.max(Math.max(r, g), b); return (rgb & 0xff000000) | (gray << 16) | (gray << 8) | (gray << 0); } } }
Java
/* * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import sun.swing.SwingUtilities2; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.BorderFactory; import javax.swing.border.Border; import javax.swing.plaf.*; import javax.swing.plaf.basic.BasicToolTipUI; import javax.swing.plaf.basic.BasicHTML; import javax.swing.text.View; /** {@collect.stats} * A Metal L&F extension of BasicToolTipUI. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Steve Wilson */ public class MetalToolTipUI extends BasicToolTipUI { static MetalToolTipUI sharedInstance = new MetalToolTipUI(); private Font smallFont; // Refer to note in getAcceleratorString about this field. private JToolTip tip; public static final int padSpaceBetweenStrings = 12; private String acceleratorDelimiter; public MetalToolTipUI() { super(); } public static ComponentUI createUI(JComponent c) { return sharedInstance; } public void installUI(JComponent c) { super.installUI(c); tip = (JToolTip)c; Font f = c.getFont(); smallFont = new Font( f.getName(), f.getStyle(), f.getSize() - 2 ); acceleratorDelimiter = UIManager.getString( "MenuItem.acceleratorDelimiter" ); if ( acceleratorDelimiter == null ) { acceleratorDelimiter = "-"; } } public void uninstallUI(JComponent c) { super.uninstallUI(c); tip = null; } public void paint(Graphics g, JComponent c) { JToolTip tip = (JToolTip)c; Font font = c.getFont(); FontMetrics metrics = SwingUtilities2.getFontMetrics(c, g, font); Dimension size = c.getSize(); int accelBL; g.setColor(c.getForeground()); // fix for bug 4153892 String tipText = tip.getTipText(); if (tipText == null) { tipText = ""; } String accelString = getAcceleratorString(tip); FontMetrics accelMetrics = SwingUtilities2.getFontMetrics(c, g, smallFont); int accelSpacing = calcAccelSpacing(c, accelMetrics, accelString); Insets insets = tip.getInsets(); Rectangle paintTextR = new Rectangle( insets.left + 3, insets.top, size.width - (insets.left + insets.right) - 6 - accelSpacing, size.height - (insets.top + insets.bottom)); View v = (View) c.getClientProperty(BasicHTML.propertyKey); if (v != null) { v.paint(g, paintTextR); accelBL = BasicHTML.getHTMLBaseline(v, paintTextR.width, paintTextR.height); } else { g.setFont(font); SwingUtilities2.drawString(tip, g, tipText, paintTextR.x, paintTextR.y + metrics.getAscent()); accelBL = metrics.getAscent(); } if (!accelString.equals("")) { g.setFont(smallFont); g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() ); SwingUtilities2.drawString(tip, g, accelString, tip.getWidth() - 1 - insets.right - accelSpacing + padSpaceBetweenStrings - 3, paintTextR.y + accelBL); } } private int calcAccelSpacing(JComponent c, FontMetrics fm, String accel) { return accel.equals("") ? 0 : padSpaceBetweenStrings + SwingUtilities2.stringWidth(c, fm, accel); } public Dimension getPreferredSize(JComponent c) { Dimension d = super.getPreferredSize(c); String key = getAcceleratorString((JToolTip)c); if (!(key.equals(""))) { d.width += calcAccelSpacing(c, c.getFontMetrics(smallFont), key); } return d; } protected boolean isAcceleratorHidden() { Boolean b = (Boolean)UIManager.get("ToolTip.hideAccelerator"); return b != null && b.booleanValue(); } private String getAcceleratorString(JToolTip tip) { this.tip = tip; String retValue = getAcceleratorString(); this.tip = null; return retValue; } // NOTE: This requires the tip field to be set before this is invoked. // As MetalToolTipUI is shared between all JToolTips the tip field is // set appropriately before this is invoked. Unfortunately this means // that subclasses that randomly invoke this method will see varying // results. If this becomes an issue, MetalToolTipUI should no longer be // shared. public String getAcceleratorString() { if (tip == null || isAcceleratorHidden()) { return ""; } JComponent comp = tip.getComponent(); if (!(comp instanceof AbstractButton)) { return ""; } KeyStroke[] keys = comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).keys(); if (keys == null) { return ""; } String controlKeyStr = ""; for (int i = 0; i < keys.length; i++) { int mod = keys[i].getModifiers(); controlKeyStr = KeyEvent.getKeyModifiersText(mod) + acceleratorDelimiter + KeyEvent.getKeyText(keys[i].getKeyCode()); break; } return controlKeyStr; } }
Java
/* * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import java.awt.*; import java.beans.*; import java.awt.event.*; /** {@collect.stats} * A Metal L&F implementation of ScrollPaneUI. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Steve Wilson */ public class MetalScrollPaneUI extends BasicScrollPaneUI { private PropertyChangeListener scrollBarSwapListener; public static ComponentUI createUI(JComponent x) { return new MetalScrollPaneUI(); } public void installUI(JComponent c) { super.installUI(c); JScrollPane sp = (JScrollPane)c; updateScrollbarsFreeStanding(); } public void uninstallUI(JComponent c) { super.uninstallUI(c); JScrollPane sp = (JScrollPane)c; JScrollBar hsb = sp.getHorizontalScrollBar(); JScrollBar vsb = sp.getVerticalScrollBar(); if (hsb != null) { hsb.putClientProperty( MetalScrollBarUI.FREE_STANDING_PROP, null); } if (vsb != null) { vsb.putClientProperty( MetalScrollBarUI.FREE_STANDING_PROP, null); } } public void installListeners(JScrollPane scrollPane) { super.installListeners(scrollPane); scrollBarSwapListener = createScrollBarSwapListener(); scrollPane.addPropertyChangeListener(scrollBarSwapListener); } public void uninstallListeners(JScrollPane scrollPane) { super.uninstallListeners(scrollPane); scrollPane.removePropertyChangeListener(scrollBarSwapListener); } /** {@collect.stats} * If the border of the scrollpane is an instance of * <code>MetalBorders.ScrollPaneBorder</code>, the client property * <code>FREE_STANDING_PROP</code> of the scrollbars * is set to false, otherwise it is set to true. */ private void updateScrollbarsFreeStanding() { if (scrollpane == null) { return; } Border border = scrollpane.getBorder(); Object value; if (border instanceof MetalBorders.ScrollPaneBorder) { value = Boolean.FALSE; } else { value = Boolean.TRUE; } JScrollBar sb = scrollpane.getHorizontalScrollBar(); if (sb != null) { sb.putClientProperty (MetalScrollBarUI.FREE_STANDING_PROP, value); } sb = scrollpane.getVerticalScrollBar(); if (sb != null) { sb.putClientProperty (MetalScrollBarUI.FREE_STANDING_PROP, value); } } protected PropertyChangeListener createScrollBarSwapListener() { return new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String propertyName = e.getPropertyName(); if (propertyName.equals("verticalScrollBar") || propertyName.equals("horizontalScrollBar")) { JScrollBar oldSB = (JScrollBar)e.getOldValue(); if (oldSB != null) { oldSB.putClientProperty( MetalScrollBarUI.FREE_STANDING_PROP, null); } JScrollBar newSB = (JScrollBar)e.getNewValue(); if (newSB != null) { newSB.putClientProperty( MetalScrollBarUI.FREE_STANDING_PROP, Boolean.FALSE); } } else if ("border".equals(propertyName)) { updateScrollbarsFreeStanding(); } }}; } }
Java
/* * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.plaf.*; /** {@collect.stats} * CheckboxIcon implementation for OrganicCheckBoxUI * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Steve Wilson */ public class MetalCheckBoxIcon implements Icon, UIResource, Serializable { protected int getControlSize() { return 13; } public void paintIcon(Component c, Graphics g, int x, int y) { JCheckBox cb = (JCheckBox)c; ButtonModel model = cb.getModel(); int controlSize = getControlSize(); boolean drawCheck = model.isSelected(); if (model.isEnabled()) { if(cb.isBorderPaintedFlat()) { g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.drawRect(x+1, y, controlSize-1, controlSize-1); } if (model.isPressed() && model.isArmed()) { if(cb.isBorderPaintedFlat()) { g.setColor(MetalLookAndFeel.getControlShadow()); g.fillRect(x+2, y+1, controlSize-2, controlSize-2); } else { g.setColor(MetalLookAndFeel.getControlShadow()); g.fillRect(x, y, controlSize-1, controlSize-1); MetalUtils.drawPressed3DBorder(g, x, y, controlSize, controlSize); } } else if(!cb.isBorderPaintedFlat()) { MetalUtils.drawFlush3DBorder(g, x, y, controlSize, controlSize); } g.setColor( MetalLookAndFeel.getControlInfo() ); } else { g.setColor( MetalLookAndFeel.getControlShadow() ); g.drawRect( x, y, controlSize-1, controlSize-1); } if(drawCheck) { if (cb.isBorderPaintedFlat()) { x++; } drawCheck(c,g,x,y); } } protected void drawCheck(Component c, Graphics g, int x, int y) { int controlSize = getControlSize(); g.fillRect( x+3, y+5, 2, controlSize-8 ); g.drawLine( x+(controlSize-4), y+3, x+5, y+(controlSize-6) ); g.drawLine( x+(controlSize-4), y+4, x+5, y+(controlSize-5) ); } public int getIconWidth() { return getControlSize(); } public int getIconHeight() { return getControlSize(); } }
Java
/* * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.swing.plaf.metal; import javax.swing.*; import javax.swing.plaf.*; import javax.swing.plaf.basic.*; import java.awt.*; /** {@collect.stats} * The Metal implementation of ProgressBarUI. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @author Michael C. Albers */ public class MetalProgressBarUI extends BasicProgressBarUI { private Rectangle innards; private Rectangle box; public static ComponentUI createUI(JComponent c) { return new MetalProgressBarUI(); } /** {@collect.stats} * Draws a bit of special highlighting on the progress bar. * The core painting is deferred to the BasicProgressBar's * <code>paintDeterminate</code> method. * @since 1.4 */ public void paintDeterminate(Graphics g, JComponent c) { super.paintDeterminate(g,c); if (!(g instanceof Graphics2D)) { return; } if (progressBar.isBorderPainted()) { Insets b = progressBar.getInsets(); // area for border int barRectWidth = progressBar.getWidth() - (b.left + b.right); int barRectHeight = progressBar.getHeight() - (b.top + b.bottom); int amountFull = getAmountFull(b, barRectWidth, barRectHeight); boolean isLeftToRight = MetalUtils.isLeftToRight(c); int startX, startY, endX, endY; // The progress bar border is painted according to a light source. // This light source is stationary and does not change when the // component orientation changes. startX = b.left; startY = b.top; endX = b.left + barRectWidth - 1; endY = b.top + barRectHeight - 1; Graphics2D g2 = (Graphics2D)g; g2.setStroke(new BasicStroke(1.f)); if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { // Draw light line lengthwise across the progress bar. g2.setColor(MetalLookAndFeel.getControlShadow()); g2.drawLine(startX, startY, endX, startY); if (amountFull > 0) { // Draw darker lengthwise line over filled area. g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); if (isLeftToRight) { g2.drawLine(startX, startY, startX + amountFull - 1, startY); } else { g2.drawLine(endX, startY, endX - amountFull + 1, startY); if (progressBar.getPercentComplete() != 1.f) { g2.setColor(MetalLookAndFeel.getControlShadow()); } } } // Draw a line across the width. The color is determined by // the code above. g2.drawLine(startX, startY, startX, endY); } else { // VERTICAL // Draw light line lengthwise across the progress bar. g2.setColor(MetalLookAndFeel.getControlShadow()); g2.drawLine(startX, startY, startX, endY); if (amountFull > 0) { // Draw darker lengthwise line over filled area. g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); g2.drawLine(startX, endY, startX, endY - amountFull + 1); } // Draw a line across the width. The color is determined by // the code above. g2.setColor(MetalLookAndFeel.getControlShadow()); if (progressBar.getPercentComplete() == 1.f) { g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); } g2.drawLine(startX, startY, endX, startY); } } } /** {@collect.stats} * Draws a bit of special highlighting on the progress bar * and bouncing box. * The core painting is deferred to the BasicProgressBar's * <code>paintIndeterminate</code> method. * @since 1.4 */ public void paintIndeterminate(Graphics g, JComponent c) { super.paintIndeterminate(g, c); if (!progressBar.isBorderPainted() || (!(g instanceof Graphics2D))) { return; } Insets b = progressBar.getInsets(); // area for border int barRectWidth = progressBar.getWidth() - (b.left + b.right); int barRectHeight = progressBar.getHeight() - (b.top + b.bottom); int amountFull = getAmountFull(b, barRectWidth, barRectHeight); boolean isLeftToRight = MetalUtils.isLeftToRight(c); int startX, startY, endX, endY; Rectangle box = null; box = getBox(box); // The progress bar border is painted according to a light source. // This light source is stationary and does not change when the // component orientation changes. startX = b.left; startY = b.top; endX = b.left + barRectWidth - 1; endY = b.top + barRectHeight - 1; Graphics2D g2 = (Graphics2D)g; g2.setStroke(new BasicStroke(1.f)); if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { // Draw light line lengthwise across the progress bar. g2.setColor(MetalLookAndFeel.getControlShadow()); g2.drawLine(startX, startY, endX, startY); g2.drawLine(startX, startY, startX, endY); // Draw darker lengthwise line over filled area. g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); g2.drawLine(box.x, startY, box.x + box.width - 1, startY); } else { // VERTICAL // Draw light line lengthwise across the progress bar. g2.setColor(MetalLookAndFeel.getControlShadow()); g2.drawLine(startX, startY, startX, endY); g2.drawLine(startX, startY, endX, startY); // Draw darker lengthwise line over filled area. g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); g2.drawLine(startX, box.y, startX, box.y + box.height - 1); } } }
Java