[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: various Metal fixes
From: |
Roman Kennke |
Subject: |
[cp-patches] FYI: various Metal fixes |
Date: |
Mon, 13 Jun 2005 17:20:27 +0200 |
User-agent: |
Mozilla Thunderbird 1.0.2 (X11/20050317) |
The attached patch fixes some things in the Metal LaF. Visually, it
gives JSplitPanes a nice Metalish LaF, and some restructuring of code.
2005-06-13 Roman Kennke <address@hidden>
* javax/swing/plaf/metal/MetalUtils.java:
Added new package-private helper class.
* javax/swing/plaf/metal/MetalSplitPaneDivider.java:
Added new package-private class. This is the divider used
by JSplitPane.
* javax/swing/plaf/metal/MetalScrollBarUI.java
(paintThumb): Use new MetalUtils class for drawing the typical
Metal pattern on the thumb.
* javax/swing/plaf/metal/MetalScrollBarUI.java
(initComponentDefaults): Added color defaults for SplitPane.
* javax/swing/plaf/metal/MetalSplitPaneUI.java:
(createDefaultDivider): Implemented new method. This creates
the Metal divider for JSplitPane.
/Roman
Index: javax/swing/plaf/metal/MetalLookAndFeel.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java,v
retrieving revision 1.21
diff -u -r1.21 MetalLookAndFeel.java
--- javax/swing/plaf/metal/MetalLookAndFeel.java 27 Apr 2005 12:39:08
-0000 1.21
+++ javax/swing/plaf/metal/MetalLookAndFeel.java 13 Jun 2005 15:15:42
-0000
@@ -501,6 +501,12 @@
new ColorUIResource(getPrimaryControlDarkShadow()),
"ScrollBar.thumbHighlight",
new ColorUIResource(getPrimaryControl()),
+
+ "SplitPane.darkShadow",
+ new ColorUIResource(getControlDarkShadow()),
+ "SplitPane.highlight",
+ new ColorUIResource(getControlHighlight()),
+
"PopupMenu.border", new MetalBorders.PopupMenuBorder()
};
defaults.putDefaults(myDefaults);
Index: javax/swing/plaf/metal/MetalScrollBarUI.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalScrollBarUI.java,v
retrieving revision 1.3
diff -u -r1.3 MetalScrollBarUI.java
--- javax/swing/plaf/metal/MetalScrollBarUI.java 27 Apr 2005 12:39:08
-0000 1.3
+++ javax/swing/plaf/metal/MetalScrollBarUI.java 13 Jun 2005 15:15:42
-0000
@@ -129,28 +129,9 @@
thumbBounds.y + thumbBounds.height);
// draw the pattern
- int xOff = 0;
- for (int y = thumbBounds.y + 4;
- y < (thumbBounds.y + thumbBounds.height - 4); y++)
- {
- // set color alternating with every line
- if ((y % 2) == 0)
- g.setColor(thumbHighlightColor);
- else
- g.setColor(thumbDarkShadowColor);
-
- for (int x = thumbBounds.x + 3 + (xOff);
- x < (thumbBounds.x + thumbBounds.width - 3); x = x + 4)
- {
- g.drawLine(x, y, x, y);
- }
-
- // increase x offset
- xOff++;
- if (xOff > 3)
- xOff = 0;
-
- }
+ MetalUtils.fillMetalPattern(g, thumbBounds.x + 3, thumbBounds.y + 3,
+ thumbBounds.width - 6, thumbBounds.height - 6,
+ thumbHighlightColor, thumbDarkShadowColor);
}
/**
Index: javax/swing/plaf/metal/MetalSplitPaneDivider.java
===================================================================
RCS file: javax/swing/plaf/metal/MetalSplitPaneDivider.java
diff -N javax/swing/plaf/metal/MetalSplitPaneDivider.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ javax/swing/plaf/metal/MetalSplitPaneDivider.java 13 Jun 2005 15:15:42
-0000
@@ -0,0 +1,84 @@
+/* MetalSplitPaneDivider.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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+
+import javax.swing.plaf.basic.BasicSplitPaneDivider;
+
+/**
+ * The divider that is used by the MetalSplitPaneUI.
+ *
+ * @author Roman Kennke (address@hidden)
+ *
+ */
+class MetalSplitPaneDivider extends BasicSplitPaneDivider
+{
+ /** The dark color in the pattern. */
+ Color dark;
+
+ /** The light color in the pattern. */
+ Color light;
+
+ /**
+ * Creates a new instance of MetalSplitPaneDivider.
+ *
+ * @param ui the <code>MetalSplitPaneUI</code> that uses this divider
+ */
+ public MetalSplitPaneDivider(MetalSplitPaneUI ui, Color light, Color dark)
+ {
+ super(ui);
+ this.light = light;
+ this.dark = dark;
+ }
+
+ /**
+ * Paints the divider.
+ *
+ * @param g the <code>Graphics</code> context to use for painting
+ */
+ public void paint(Graphics g)
+ {
+ //super.paint(g);
+ Dimension s = getSize();
+ MetalUtils.fillMetalPattern(g, 2, 2, s.width - 4, s.height - 4,
+ light, dark);
+ }
+}
Index: javax/swing/plaf/metal/MetalSplitPaneUI.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalSplitPaneUI.java,v
retrieving revision 1.2
diff -u -r1.2 MetalSplitPaneUI.java
--- javax/swing/plaf/metal/MetalSplitPaneUI.java 30 May 2005 14:00:38
-0000 1.2
+++ javax/swing/plaf/metal/MetalSplitPaneUI.java 13 Jun 2005 15:15:42
-0000
@@ -38,11 +38,15 @@
package javax.swing.plaf.metal;
+import java.awt.Color;
import java.util.HashMap;
import javax.swing.JComponent;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicSplitPaneUI;
+import javax.swing.plaf.basic.BasicSplitPaneDivider;
public class MetalSplitPaneUI
extends BasicSplitPaneUI
@@ -83,4 +87,20 @@
return instance;
}
+
+ /**
+ * Returns the divider that is used by the <code>JSplitPane</code>.
+ *
+ * The divider returned by this method is a address@hidden
BasicSplitPaneDivider}
+ * that is drawn using the Metal look.
+ *
+ * @return the default divider to use for <code>JSplitPane</code>s.
+ */
+ public BasicSplitPaneDivider createDefaultDivider()
+ {
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+ Color light = defaults.getColor("SplitPane.highlight");
+ Color dark = defaults.getColor("SplitPane.darkShadow");
+ return new MetalSplitPaneDivider(this, light, dark);
+ }
}
Index: javax/swing/plaf/metal/MetalUtils.java
===================================================================
RCS file: javax/swing/plaf/metal/MetalUtils.java
diff -N javax/swing/plaf/metal/MetalUtils.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ javax/swing/plaf/metal/MetalUtils.java 13 Jun 2005 15:15:42 -0000
@@ -0,0 +1,87 @@
+/* Metaltils.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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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.Color;
+import java.awt.Graphics;
+
+/**
+ * Some utility and helper methods for the Metal Look & Feel.
+ *
+ * @author Roman Kennke (address@hidden)
+ */
+class MetalUtils
+{
+
+ /**
+ * Fills a rectangle with the typical Metal pattern.
+ *
+ * @param g the <code>Graphics</code> context to use
+ * @param x the X coordinate of the upper left corner of the rectangle to
+ * fill
+ * @param y the Y coordinate of the upper left corner of the rectangle to
+ * fill
+ * @param w the width of the rectangle to fill
+ * @param w the height of the rectangle to fill
+ * @param light the light color to use
+ * @param dark the dark color to use
+ */
+ static void fillMetalPattern(Graphics g, int x, int y, int w, int h,
+ Color light, Color dark)
+ {
+ int xOff = 0;
+ for (int mY = y; mY < (y + h); mY++)
+ {
+ // set color alternating with every line
+ if ((mY % 2) == 0)
+ g.setColor(light);
+ else
+ g.setColor(dark);
+
+ for (int mX = x + (xOff); mX < (x + w); mX += 4)
+ {
+ g.drawLine(mX, mY, mX, mY);
+ }
+
+ // increase x offset
+ xOff++;
+ if (xOff > 3)
+ xOff = 0;
+ }
+ }
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: various Metal fixes,
Roman Kennke <=