[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: MetalInternalFrame* updates
From: |
David Gilbert |
Subject: |
[cp-patches] FYI: MetalInternalFrame* updates |
Date: |
Tue, 13 Sep 2005 00:07:01 +0000 |
User-agent: |
Mozilla Thunderbird 1.0.6 (X11/20050728) |
I committed this patch to implement more of the JInternalFrame rendering under the
MetalLookAndFeel (including floating palette style frames):
2005-09-12 David Gilbert <address@hidden>
* examples/gnu/classpath/examples/swing/Demo.java
(mkDesktopWorld): add palette style frame,
* javax/swing/plaf/basic/BasicInternalFrameTitlePane.java
(closeIcon): new field,
(installListeners): call createPropertyChangeListener() to create the
new listener to allow for overriding,
(installDefaults): set the font in the title, read closeIcon from
defaults,
(uninstallDefaults): clear closeIcon,
(setButtonIcons): set icon for closeButton,
(paintComponent): set font for title,
* javax/swing/plaf/metal/MetalInternalFrameTitlePane.java
(MetalInternalFrameTitlePanePropertyChangeHandler): new support class,
(MetalTitlePaneLayout): likewise,
(paletteTitleHeight): initialise from defaults elsewhere,
(title): new private field,
(installDefaults): initialise various defaults,
(uninstallDefaults): clear defaults,
(addSubComponents): add sub-components used in this look and feel,
(createLayout): return new instance of MetalTitlePaneLayout,
(paintPalette): renders the title pane using the palette style,
(paintComponent): call paintPalette() if the internal frame uses the
palette style, otherwise handle painting without calling superclass
anymore,
(setPalette): update the icon visibility,
(createPropertyChangeListener): return a new change handler,
* javax/swing/plaf/metal/MetalInternalFrameUI.java
(IS_PALETTE): new static field,
(installUI): check IS_PALETTE property,
(createNorthPane): removed empty border,
(setPalette): update border as appropriate,
(paletteListener): new private field,
(installListeners): install a listener to handle changes in the
IS_PALETTE property,
(uninstallListeners): clear the listener from installListeners(),
* javax/swing/plaf/metal/MetalLookAndFeel.java
(initComponentDefaults): added defaults for 'DesktopIcon.border',
'InternalFrame.paletteBorder', 'InternalFrame.paletteCloseIcon', and
'InternalFrame.paletteTitleHeight'.
Regards,
Dave Gilbert
Index: examples/gnu/classpath/examples/swing/Demo.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/examples/gnu/classpath/examples/swing/Demo.java,v
retrieving revision 1.20
diff -u -r1.20 Demo.java
--- examples/gnu/classpath/examples/swing/Demo.java 30 Aug 2005 20:46:31
-0000 1.20
+++ examples/gnu/classpath/examples/swing/Demo.java 12 Sep 2005 22:40:10
-0000
@@ -640,6 +640,14 @@
panel.add(but, BorderLayout.NORTH);
but.doClick();
but.doClick();
+ JInternalFrame palette = new JInternalFrame("Palette", true, true, true,
+ true);
+ palette.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
+ desk.add(palette, JDesktopPane.PALETTE_LAYER);
+ JLabel label = new JLabel("This is a floating palette!");
+ palette.getContentPane().add(label);
+ palette.pack();
+ palette.setVisible(true);
return panel;
}
Index: javax/swing/plaf/basic/BasicInternalFrameTitlePane.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java,v
retrieving revision 1.13
diff -u -r1.13 BasicInternalFrameTitlePane.java
--- javax/swing/plaf/basic/BasicInternalFrameTitlePane.java 25 Aug 2005
10:48:58 -0000 1.13
+++ javax/swing/plaf/basic/BasicInternalFrameTitlePane.java 12 Sep 2005
22:40:22 -0000
@@ -522,6 +522,9 @@
/** The icon displayed in the iconify button. */
protected Icon iconIcon = BasicIconFactory.createEmptyFrameIcon();
+ /** The icon displayed in the close button. */
+ protected Icon closeIcon;
+
/** The JInternalFrame that this TitlePane is used in. */
protected JInternalFrame frame;
@@ -645,7 +648,7 @@
*/
protected void installListeners()
{
- propertyChangeListener = new PropertyChangeHandler();
+ propertyChangeListener = createPropertyChangeListener();
frame.addPropertyChangeListener(propertyChangeListener);
}
@@ -663,14 +666,16 @@
*/
protected void installDefaults()
{
- // FIXME: move icons to defaults.
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- setFont(defaults.getFont("InternalFrame.titleFont"));
+ title.setFont(defaults.getFont("InternalFrame.titleFont"));
selectedTextColor =
defaults.getColor("InternalFrame.activeTitleForeground");
selectedTitleColor =
defaults.getColor("InternalFrame.activeTitleBackground");
notSelectedTextColor =
defaults.getColor("InternalFrame.inactiveTitleForeground");
notSelectedTitleColor =
defaults.getColor("InternalFrame.inactiveTitleBackground");
+
+ // FIXME: move other icons to here too.
+ closeIcon = UIManager.getIcon("InternalFrame.closeIcon");
}
/**
@@ -683,6 +688,8 @@
selectedTitleColor = null;
notSelectedTextColor = null;
notSelectedTitleColor = null;
+
+ closeIcon = null;
}
/**
@@ -706,10 +713,10 @@
*/
protected void setButtonIcons()
{
- Icon icon = UIManager.getIcon("InternalFrame.closeIcon");
- if (icon != null)
- closeButton.setIcon(icon);
- icon = UIManager.getIcon("InternalFrame.iconifyIcon");
+ if (closeIcon != null)
+ closeButton.setIcon(closeIcon);
+ // FIXME: fetch these icons in the installDefaults() method
+ Icon icon = UIManager.getIcon("InternalFrame.iconifyIcon");
if (icon != null)
iconButton.setIcon(icon);
icon = UIManager.getIcon("InternalFrame.maximizeIcon");
@@ -816,11 +823,12 @@
public void paintComponent(Graphics g)
{
paintTitleBackground(g);
- Font f = g.getFont();
- FontMetrics fm = g.getFontMetrics(f);
if (frame.getTitle() != null && title != null)
{
Color saved = g.getColor();
+ Font f = title.getFont();
+ g.setFont(f);
+ FontMetrics fm = g.getFontMetrics(f);
if (frame.isSelected())
g.setColor(selectedTextColor);
else
Index: javax/swing/plaf/metal/MetalInternalFrameTitlePane.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java,v
retrieving revision 1.1
diff -u -r1.1 MetalInternalFrameTitlePane.java
--- javax/swing/plaf/metal/MetalInternalFrameTitlePane.java 25 Aug 2005
10:48:59 -0000 1.1
+++ javax/swing/plaf/metal/MetalInternalFrameTitlePane.java 12 Sep 2005
22:40:22 -0000
@@ -38,30 +38,206 @@
package javax.swing.plaf.metal;
+import java.awt.Color;
+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.Icon;
import javax.swing.JInternalFrame;
+import javax.swing.JLabel;
import javax.swing.JMenu;
+import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
+
/**
- * The title pane for a address@hidden JInternalFrame}.
+ * The title pane for a address@hidden JInternalFrame}. This can be displayed
in two
+ * styles: one for regular internal frames, and the other for "palette" style
+ * internal frames.
*/
public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane
{
+ /**
+ * A property change handler that listens for changes to the
+ * <code>JInternalFrame.isPalette</code> property and updates the title
+ * pane as appropriate.
+ */
+ class MetalInternalFrameTitlePanePropertyChangeHandler
+ extends PropertyChangeHandler
+ {
+ /**
+ * Creates a new handler.
+ */
+ public MetalInternalFrameTitlePanePropertyChangeHandler()
+ {
+ super();
+ }
+
+ /**
+ * Handles <code>JInternalFrame.isPalette</code> property changes, with all
+ * other propert changes being passed to the superclass.
+ *
+ * @param e the event.
+ */
+ public void propertyChange(PropertyChangeEvent e)
+ {
+ String propName = e.getPropertyName();
+ if (propName.equals("JInternalFrame.isPalette"))
+ {
+ if (e.getNewValue().equals(Boolean.TRUE))
+ setPalette(true);
+ else
+ setPalette(false);
+ }
+ else
+ super.propertyChange(e);
+ }
+ }
+
+ /**
+ * A layout manager for the title pane.
+ *
+ * @see #createLayout()
+ */
+ private class MetalTitlePaneLayout implements LayoutManager
+ {
+ /**
+ * Creates a new <code>TitlePaneLayout</code> object.
+ */
+ public MetalTitlePaneLayout()
+ {
+ // Do nothing.
+ }
+
+ /**
+ * Adds a Component to the Container.
+ *
+ * @param name The name to reference the added Component by.
+ * @param c The Component to add.
+ */
+ public void addLayoutComponent(String name, Component c)
+ {
+ // Do nothing.
+ }
+
+ /**
+ * This method is called to lay out the children of the Title Pane.
+ *
+ * @param c The Container to lay out.
+ */
+ public void layoutContainer(Container c)
+ {
+
+ Dimension size = c.getSize();
+ Insets insets = c.getInsets();
+ int width = size.width - insets.left - insets.right;
+ int height = size.height - insets.top - insets.bottom;
+
+
+ int loc = width - insets.right - 1;
+ int top = insets.top + 2;
+ int buttonHeight = height - 4;
+ if (closeButton.isVisible())
+ {
+ int buttonWidth = closeIcon.getIconWidth();
+ loc -= buttonWidth + 2;
+ closeButton.setBounds(loc, top, buttonWidth, buttonHeight);
+ loc -= 6;
+ }
+
+ if (maxButton.isVisible())
+ {
+ int buttonWidth = maxIcon.getIconWidth();
+ loc -= buttonWidth + 4;
+ maxButton.setBounds(loc, top, buttonWidth, buttonHeight);
+ }
+
+ if (iconButton.isVisible())
+ {
+ int buttonWidth = minIcon.getIconWidth();
+ loc -= buttonWidth + 4;
+ iconButton.setBounds(loc, top, buttonWidth, buttonHeight);
+ loc -= 2;
+ }
+
+ Dimension titlePreferredSize = title.getPreferredSize();
+ title.setBounds(insets.left + 5, insets.top,
+ Math.min(titlePreferredSize.width, loc - insets.left - 10),
+ height);
+
+ }
+
+ /**
+ * This method returns the minimum size of the given Container given the
+ * children that it has.
+ *
+ * @param c The Container to get a minimum size for.
+ *
+ * @return The minimum size of the Container.
+ */
+ public Dimension minimumLayoutSize(Container c)
+ {
+ return preferredLayoutSize(c);
+ }
+
+ /**
+ * Returns the preferred size of the given Container taking
+ * into account the children that it has.
+ *
+ * @param c The Container to lay out.
+ *
+ * @return The preferred size of the Container.
+ */
+ public Dimension preferredLayoutSize(Container c)
+ {
+ if (isPalette)
+ return new Dimension(paletteTitleHeight, paletteTitleHeight);
+ else
+ return new Dimension(22, 22);
+ }
+
+ /**
+ * Removes a Component from the Container.
+ *
+ * @param c The Component to remove.
+ */
+ public void removeLayoutComponent(Component c)
+ {
+ }
+ }
+
+ /** A flag indicating whether the title pane uses the palette style. */
protected boolean isPalette;
- protected Icon paletteCloseIcon =
MetalIconFactory.getInternalFrameCloseIcon(16);
+ /**
+ * The icon used for the close button - this is fetched from the look and
+ * feel defaults using the key <code>InternalFrame.paletteCloseIcon</code>.
+ */
+ protected Icon paletteCloseIcon;
+
+ /**
+ * The height of the title pane when <code>isPalette</code> is
+ * <code>true</code>. This value is fetched from the look and feel defaults
+ * using the key <code>InternalFrame.paletteTitleHeight</code>.
+ */
+ protected int paletteTitleHeight;
+
+ /** The label used to display the title for the internal frame. */
+ private JLabel title;
- protected int paletteTitleHeight = 12;
-
/**
- * Creates a new title pane.
+ * Creates a new title pane for the specified frame.
*
* @param f the internal frame.
*/
@@ -81,6 +257,15 @@
selectedTitleColor = MetalLookAndFeel.getWindowTitleBackground();
notSelectedTextColor = MetalLookAndFeel.getInactiveControlTextColor();
notSelectedTitleColor =
MetalLookAndFeel.getWindowTitleInactiveBackground();
+
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+ paletteTitleHeight = defaults.getInt("InternalFrame.paletteTitleHeight");
+ paletteCloseIcon = defaults.getIcon("InternalFrame.paletteCloseIcon");
+ minIcon = MetalIconFactory.getInternalFrameAltMaximizeIcon(16);
+
+ title = new JLabel(frame.getTitle(),
+ MetalIconFactory.getInternalFrameDefaultMenuIcon(),
+ SwingConstants.LEFT);
}
/**
@@ -93,6 +278,9 @@
selectedTitleColor = null;
notSelectedTextColor = null;
notSelectedTitleColor = null;
+ paletteCloseIcon = null;
+ minIcon = null;
+ title = null;
}
/**
@@ -127,45 +315,116 @@
// do nothing
}
+ protected void addSubComponents()
+ {
+ // FIXME: this method is probably overridden to only add the required
+ // buttons
+ add(title);
+ add(closeButton);
+ add(iconButton);
+ add(maxButton);
+ }
+
/**
- * Creates a layout manager for the components in the title pane.
+ * Creates a new instance of address@hidden MetalTitlePaneLayout}.
*
- * @return A layout manager.
- */
+ * @return A new instance of address@hidden MetalTitlePaneLayout}.
+ */
protected LayoutManager createLayout()
{
- return new TitlePaneLayout()
- {
- public Dimension preferredLayoutSize(Container c)
- {
- return new Dimension(24, 24);
- }
- };
+ return new MetalTitlePaneLayout();
}
+ /**
+ * Draws the title pane in the palette style.
+ *
+ * @param g the graphics device.
+ *
+ * @see #paintComponent(Graphics)
+ */
public void paintPalette(Graphics g)
{
- // FIXME: needs implementing
- // most likely this is equivalent to paintComponent(g) when the isPalette
- // flag is true
+ Color savedColor = g.getColor();
+ Rectangle b = SwingUtilities.getLocalBounds(this);
+ g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
+ g.fillRect(b.x, b.y, b.width, b.height);
+ MetalUtils.fillMetalPattern(g, b.x + 4, b.y + 2, b.width
+ - paletteCloseIcon.getIconWidth() - 13, b.height - 5,
+ MetalLookAndFeel.getPrimaryControlHighlight(),
+ MetalLookAndFeel.getBlack());
+
+ // draw a line separating the title pane from the frame content
+ Dimension d = getSize();
+ g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
+ g.drawLine(0, d.height - 1, d.width - 1, d.height - 1);
+
+ g.setColor(savedColor);
}
-
+
+ /**
+ * Paints a representation of the current state of the internal frame.
+ *
+ * @param g the graphics device.
+ */
public void paintComponent(Graphics g)
{
- // probably need to check the isPalette flag here, if true pass over to
- // paintPalette(Graphics)
- super.paintComponent(g);
- Dimension d = getSize();
- if (frame.isSelected())
- g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
+ Color savedColor = g.getColor();
+ if (isPalette)
+ paintPalette(g);
else
- g.setColor(MetalLookAndFeel.getControlDarkShadow());
- g.drawLine(0, d.height - 1, d.width - 1, d.height - 1);
+ {
+ paintTitleBackground(g);
+ paintChildren(g);
+ Dimension d = getSize();
+ if (frame.isSelected())
+ g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
+ else
+ g.setColor(MetalLookAndFeel.getControlDarkShadow());
+
+ // put a dot in each of the top corners
+ g.drawLine(0, 0, 0, 0);
+ g.drawLine(d.width - 1, 0, d.width - 1, 0);
+
+ g.drawLine(0, d.height - 1, d.width - 1, d.height - 1);
+
+ // draw the metal pattern
+ Rectangle b = title.getBounds();
+ int startX = b.x + b.width + 5;
+ int endX = startX;
+ if (iconButton.isVisible())
+ endX = Math.max(iconButton.getX(), endX);
+ else if (maxButton.isVisible())
+ endX = Math.max(maxButton.getX(), endX);
+ else if (closeButton.isVisible())
+ endX = Math.max(closeButton.getX(), endX);
+ endX -= 7;
+ if (endX > startX)
+ MetalUtils.fillMetalPattern(g, startX, 3, endX - startX, getHeight()
- 6, Color.white, Color.gray);
+ }
+ g.setColor(savedColor);
}
+ /**
+ * Sets the flag that controls whether the title pane is drawn in the
+ * palette style or the regular style.
+ *
+ * @param b the new value of the flag.
+ */
public void setPalette(boolean b)
{
- isPalette = b;
+ isPalette = b;
+ title.setVisible(!isPalette);
+ iconButton.setVisible(!isPalette && frame.isIconifiable());
+ maxButton.setVisible(!isPalette && frame.isMaximizable());
+ if (isPalette)
+ closeButton.setIcon(paletteCloseIcon);
+ else
+ closeButton.setIcon(closeIcon);
+ }
+
+ protected PropertyChangeListener createPropertyChangeListener()
+ {
+ return new MetalInternalFrameTitlePanePropertyChangeHandler();
}
}
Index: javax/swing/plaf/metal/MetalInternalFrameUI.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalInternalFrameUI.java,v
retrieving revision 1.5
diff -u -r1.5 MetalInternalFrameUI.java
--- javax/swing/plaf/metal/MetalInternalFrameUI.java 10 Sep 2005 20:52:47
-0000 1.5
+++ javax/swing/plaf/metal/MetalInternalFrameUI.java 12 Sep 2005 22:40:23
-0000
@@ -38,9 +38,11 @@
package javax.swing.plaf.metal;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
import javax.swing.JComponent;
import javax.swing.JInternalFrame;
-import javax.swing.border.EmptyBorder;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicInternalFrameUI;
@@ -51,6 +53,11 @@
public class MetalInternalFrameUI
extends BasicInternalFrameUI
{
+ /**
+ * The key for the client property that controls whether the internal frame
+ * is displayed using the palette style.
+ */
+ protected static String IS_PALETTE = "JInternalFrame.isPalette";
/**
* Constructs a new instance of <code>MetalInternalFrameUI</code>.
@@ -65,9 +72,9 @@
/**
* Returns an instance of <code>MetalInternalFrameUI</code>.
*
- * @param component the component for which we return an UI instance
+ * @param component the internal frame.
*
- * @return an instance of MetalInternalFrameUI
+ * @return an instance of <code>MetalInternalFrameUI</code>.
*/
public static ComponentUI createUI(JComponent component)
{
@@ -75,6 +82,22 @@
}
/**
+ * Sets the fields and properties for the component.
+ *
+ * @param c the component.
+ */
+ public void installUI(JComponent c)
+ {
+ super.installUI(c);
+ JInternalFrame f = (JInternalFrame) c;
+ boolean isPalette = false;
+ Boolean p = (Boolean) f.getClientProperty(IS_PALETTE);
+ if (p != null)
+ isPalette = p.booleanValue();
+ setPalette(isPalette);
+ }
+
+ /**
* Creates and returns the component that will be used for the north pane
* of the address@hidden JInternalFrame}.
*
@@ -85,9 +108,58 @@
protected JComponent createNorthPane(JInternalFrame w)
{
titlePane = new MetalInternalFrameTitlePane(w);
- titlePane.setBorder(new EmptyBorder(2, 2, 2, 2));
return titlePane;
}
-
+ /**
+ * Sets the state of the address@hidden JInternalFrame} to reflect whether
or not
+ * it is using the palette style. When a frame is displayed as a palette,
+ * it uses a different border and the title pane is drawn differently.
+ *
+ * @param isPalette use the palette style?
+ */
+ public void setPalette(boolean isPalette)
+ {
+ MetalInternalFrameTitlePane title = (MetalInternalFrameTitlePane)
northPane;
+ title.setPalette(isPalette);
+ if (isPalette)
+ frame.setBorder(new MetalBorders.PaletteBorder());
+ else
+ frame.setBorder(new MetalBorders.InternalFrameBorder());
+ }
+
+ /** A listener that is used to handle IS_PALETTE property changes. */
+ private PropertyChangeListener paletteListener;
+
+ /**
+ * Adds the required listeners.
+ */
+ protected void installListeners()
+ {
+ super.installListeners();
+ paletteListener = new PropertyChangeListener()
+ {
+ public void propertyChange(PropertyChangeEvent e)
+ {
+ if (e.getPropertyName().equals(IS_PALETTE))
+ {
+ if (Boolean.TRUE.equals(e.getNewValue()))
+ setPalette(true);
+ else
+ setPalette(false);
+ }
+ }
+ };
+ frame.addPropertyChangeListener(paletteListener);
+ }
+
+ /**
+ * Removes the listeners used.
+ */
+ protected void uninstallListeners()
+ {
+ super.uninstallListeners();
+ frame.removePropertyChangeListener(IS_PALETTE, paletteListener);
+ paletteListener = null;
+ }
}
Index: javax/swing/plaf/metal/MetalLookAndFeel.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java,v
retrieving revision 1.54
diff -u -r1.54 MetalLookAndFeel.java
--- javax/swing/plaf/metal/MetalLookAndFeel.java 12 Sep 2005 14:49:52
-0000 1.54
+++ javax/swing/plaf/metal/MetalLookAndFeel.java 12 Sep 2005 22:40:24
-0000
@@ -824,6 +824,7 @@
"DesktopIcon.background", getControl(),
"DesktopIcon.foreground", getControlTextColor(),
"DesktopIcon.width", new Integer(160),
+ "DesktopIcon.border", MetalBorders.getDesktopIconBorder(),
"EditorPane.background", getWindowBackground(),
"EditorPane.caretForeground", getUserTextColor(),
@@ -860,6 +861,9 @@
MetalIconFactory.getInternalFrameMaximizeIcon(16),
"InternalFrame.iconifyIcon",
MetalIconFactory.getInternalFrameMinimizeIcon(16),
+ "InternalFrame.paletteBorder", new MetalBorders.PaletteBorder(),
+ "InternalFrame.paletteCloseIcon", new
MetalIconFactory.PaletteCloseIcon(),
+ "InternalFrame.paletteTitleHeight", new Integer(11),
"Label.background", getControl(),
"Label.disabledForeground", getInactiveSystemTextColor(),
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: MetalInternalFrame* updates,
David Gilbert <=