classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: MetalInternalFrameUI updates


From: David Gilbert
Subject: [cp-patches] FYI: MetalInternalFrameUI updates
Date: Thu, 25 Aug 2005 11:52:02 +0000
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050728)

This patch (committed) brings the JInternalFrame "look" a step closer to the Metal appearance:

2005-08-25  David Gilbert  <address@hidden>

        * javax/swing/plaf/basic/BasicInternalFrameTitlePane.java
        (activeBGColor): removed,
        (activeFGColor): removed,
        (inactiveBGColor): removed,
        (inactiveFGColor): removed,
        (installDefaults): replaced removed fields above with correct ones,
        (uninstallDefaults): likewise,
        (setButtonIcons): implemented,
        (paintComponent): replaced removed fields above with correct ones;
        * javax/swing/plaf/metal/MetalInternalFrameTitlePane.java: implemented,
        * javax/swing/plaf/metal/MetalInternalFrameUI.java
        (createNorthPane): implemented,
        * javax/swing/plaf/metal/MetalLookAndFeel.java
        (initComponentDefaults): added internal frame icons.

Regards,

Dave Gilbert

Index: javax/swing/plaf/basic/BasicInternalFrameTitlePane.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java,v
retrieving revision 1.12
diff -u -r1.12 BasicInternalFrameTitlePane.java
--- javax/swing/plaf/basic/BasicInternalFrameTitlePane.java     20 Jul 2005 
13:10:26 -0000      1.12
+++ javax/swing/plaf/basic/BasicInternalFrameTitlePane.java     25 Aug 2005 
10:40:12 -0000
@@ -47,7 +47,6 @@
 import java.awt.Graphics;
 import java.awt.Insets;
 import java.awt.LayoutManager;
-import java.awt.Polygon;
 import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
 import java.awt.event.KeyEvent;
@@ -514,18 +513,6 @@
   /** The button that maximizes the JInternalFrame. */
   protected JButton maxButton;
 
-  /** Active background color. */
-  protected Color activeBGColor;
-
-  /** Active foreground color. */
-  protected Color activeFGColor;
-
-  /** Inactive background color. */
-  protected Color inactiveBGColor;
-
-  /** Inactive foreground color. */
-  protected Color inactiveFGColor;
-
   /** The icon displayed in the restore button. */
   protected Icon minIcon = BasicIconFactory.createEmptyFrameIcon();
 
@@ -680,10 +667,10 @@
     UIDefaults defaults = UIManager.getLookAndFeelDefaults();
 
     setFont(defaults.getFont("InternalFrame.titleFont"));
-    activeFGColor = defaults.getColor("InternalFrame.activeTitleForeground");
-    activeBGColor = defaults.getColor("InternalFrame.activeTitleBackground");
-    inactiveFGColor = 
defaults.getColor("InternalFrame.inactiveTitleForeground");
-    inactiveBGColor = 
defaults.getColor("InternalFrame.inactiveTitleBackground");
+    selectedTextColor = 
defaults.getColor("InternalFrame.activeTitleForeground");
+    selectedTitleColor = 
defaults.getColor("InternalFrame.activeTitleBackground");
+    notSelectedTextColor = 
defaults.getColor("InternalFrame.inactiveTitleForeground");
+    notSelectedTitleColor = 
defaults.getColor("InternalFrame.inactiveTitleBackground");
   }
 
   /**
@@ -692,10 +679,10 @@
   protected void uninstallDefaults()
   {
     setFont(null);
-    activeFGColor = null;
-    activeBGColor = null;
-    inactiveFGColor = null;
-    inactiveBGColor = null;
+    selectedTextColor = null;
+    selectedTitleColor = null;
+    notSelectedTextColor = null;
+    notSelectedTitleColor = null;
   }
 
   /**
@@ -715,12 +702,19 @@
   }
 
   /**
-   * This method sets the icons in the buttons. This is a no-op method here, it
-   * can be overridden by subclasses to set icons for the minimize-, maximize-
-   * and close-buttons.
+   * Set icons for the minimize-, maximize- and close-buttons.
    */
   protected void setButtonIcons()
   {
+    Icon icon = UIManager.getIcon("InternalFrame.closeIcon");
+    if (icon != null)
+      closeButton.setIcon(icon);
+    icon = UIManager.getIcon("InternalFrame.iconifyIcon");
+    if (icon != null)
+      iconButton.setIcon(icon);
+    icon = UIManager.getIcon("InternalFrame.maximizeIcon");
+    if (icon != null)
+      maxButton.setIcon(icon);
   }
 
   /**
@@ -828,9 +822,9 @@
       {
        Color saved = g.getColor();
        if (frame.isSelected())
-         g.setColor(activeFGColor);
+         g.setColor(selectedTextColor);
        else
-         g.setColor(inactiveFGColor);
+         g.setColor(notSelectedTextColor);
        title.setText(getTitle(frame.getTitle(), fm, title.getBounds().width));
        SwingUtilities.paintComponent(g, title, null, title.getBounds());
        g.setColor(saved);
@@ -849,9 +843,9 @@
 
     Color bg = getBackground();
     if (frame.isSelected())
-      bg = activeBGColor;
+      bg = selectedTitleColor;
     else
-      bg = inactiveBGColor;
+      bg = notSelectedTitleColor;
     g.setColor(bg);
     g.fillRect(0, 0, dims.width, dims.height);
     g.setColor(saved);
Index: javax/swing/plaf/metal/MetalInternalFrameTitlePane.java
===================================================================
RCS file: javax/swing/plaf/metal/MetalInternalFrameTitlePane.java
diff -N javax/swing/plaf/metal/MetalInternalFrameTitlePane.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ javax/swing/plaf/metal/MetalInternalFrameTitlePane.java     25 Aug 2005 
10:40:12 -0000
@@ -0,0 +1,171 @@
+/* MetalInternalFrameTitlePane.java
+   Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.plaf.metal;
+
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.LayoutManager;
+
+import javax.swing.Icon;
+import javax.swing.JInternalFrame;
+import javax.swing.JMenu;
+import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
+
+/**
+ * The title pane for a address@hidden JInternalFrame}.
+ */
+public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane 
+{
+ 
+  protected boolean isPalette;
+  
+  protected Icon paletteCloseIcon = 
MetalIconFactory.getInternalFrameCloseIcon(16);
+  
+  protected int paletteTitleHeight = 12;
+ 
+  /**
+   * Creates a new title pane.
+   * 
+   * @param f  the internal frame.
+   */
+  public MetalInternalFrameTitlePane(JInternalFrame f)
+  {
+    super(f);
+    isPalette = false;
+  }
+  
+  /**
+   * Fetches the colors used in the title pane.
+   */
+  protected void installDefaults()
+  {
+    super.installDefaults();
+    selectedTextColor = MetalLookAndFeel.getControlTextColor();
+    selectedTitleColor = MetalLookAndFeel.getWindowTitleBackground();
+    notSelectedTextColor = MetalLookAndFeel.getInactiveControlTextColor();
+    notSelectedTitleColor = 
MetalLookAndFeel.getWindowTitleInactiveBackground();
+  }
+  
+  /**
+   * Clears the colors used for the title pane.
+   */
+  protected void uninstallDefaults()
+  {  
+    super.uninstallDefaults();
+    selectedTextColor = null;
+    selectedTitleColor = null;
+    notSelectedTextColor = null;
+    notSelectedTitleColor = null;
+  }
+  
+  /**
+   * Calls the super class to create the buttons, then calls
+   * <code>setBorderPainted(false)</code> and 
+   * <code>setContentAreaFilled(false)</code> for each button.
+   */
+  protected void createButtons()
+  { 
+    super.createButtons();
+    closeButton.setBorderPainted(false);
+    closeButton.setContentAreaFilled(false);
+    iconButton.setBorderPainted(false);
+    iconButton.setContentAreaFilled(false);
+    maxButton.setBorderPainted(false);
+    maxButton.setContentAreaFilled(false);
+  }
+  
+  /**
+   * Overridden to do nothing.
+   */
+  protected void addSystemMenuItems(JMenu systemMenu)
+  {
+    // do nothing
+  }
+  
+  /**
+   * Overridden to do nothing.
+   */
+  protected void showSystemMenu()
+  {
+      // do nothing    
+  }
+  
+  /**
+   * Creates a layout manager for the components in the title pane.
+   * 
+   * @return A layout manager.
+   */   
+  protected LayoutManager createLayout()
+  {
+    return new TitlePaneLayout()
+    {
+      public Dimension preferredLayoutSize(Container c)
+      {
+        return new Dimension(24, 24);
+      }
+    };
+  }
+  
+  public void paintPalette(Graphics g)
+  {
+    // FIXME:  needs implementing
+    // most likely this is equivalent to paintComponent(g) when the isPalette
+    // flag is true
+  }
+  
+  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());
+    else
+      g.setColor(MetalLookAndFeel.getControlDarkShadow());
+    g.drawLine(0, d.height - 1, d.width - 1, d.height - 1);
+  }
+  
+  public void setPalette(boolean b)
+  {
+    isPalette = b;  
+  }
+}
+
Index: javax/swing/plaf/metal/MetalInternalFrameUI.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalInternalFrameUI.java,v
retrieving revision 1.3
diff -u -r1.3 MetalInternalFrameUI.java
--- javax/swing/plaf/metal/MetalInternalFrameUI.java    2 Jul 2005 20:32:51 
-0000       1.3
+++ javax/swing/plaf/metal/MetalInternalFrameUI.java    25 Aug 2005 10:40:12 
-0000
@@ -42,9 +42,11 @@
 
 import javax.swing.JComponent;
 import javax.swing.JInternalFrame;
+import javax.swing.border.EmptyBorder;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.basic.BasicInternalFrameUI;
 
+
 public class MetalInternalFrameUI
   extends BasicInternalFrameUI
 {
@@ -85,4 +87,13 @@
 
     return instance;
   }
+  
+  protected JComponent createNorthPane(JInternalFrame w)
+  {
+    titlePane = new MetalInternalFrameTitlePane(w);
+    titlePane.setBorder(new EmptyBorder(2, 2, 2, 2));
+    return titlePane;  
+  }
+  
+
 }
Index: javax/swing/plaf/metal/MetalLookAndFeel.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java,v
retrieving revision 1.41
diff -u -r1.41 MetalLookAndFeel.java
--- javax/swing/plaf/metal/MetalLookAndFeel.java        24 Aug 2005 09:00:32 
-0000      1.41
+++ javax/swing/plaf/metal/MetalLookAndFeel.java        25 Aug 2005 10:40:14 
-0000
@@ -791,6 +791,12 @@
       "TabbedPane.background", new ColorUIResource(getControl()),
       "InternalFrame.border", new MetalBorders.InternalFrameBorder(),
       "InternalFrame.icon", MetalIconFactory.getInternalFrameDefaultMenuIcon(),
+      "InternalFrame.closeIcon", 
+        MetalIconFactory.getInternalFrameCloseIcon(16),
+      "InternalFrame.maximizeIcon", 
+        MetalIconFactory.getInternalFrameMaximizeIcon(16),
+      "InternalFrame.iconifyIcon", 
+        MetalIconFactory.getInternalFrameMinimizeIcon(16),
       "Label.background", new ColorUIResource(getControl()),
       "Label.font", getControlTextFont(),
       "Label.disabledForeground", new ColorUIResource(getControlDisabled()),

reply via email to

[Prev in Thread] Current Thread [Next in Thread]