classpath-patches@gnu.org

2005-04-15 Thread Roman Kennke
This fixes the font and color of JLabel in the Metal L&F.

2005-04-15  Roman Kennke  <[EMAIL PROTECTED]>

* javax/swing/plaf/metal/MetalLookAndFeel.java
(initComponentDefaults): Added Label.font.
(initSystemColorDefaults): Added this method and adjusted the
general control color.

/Roman

Index: javax/swing/plaf/metal/MetalLookAndFeel.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java,v
retrieving revision 1.13
diff -u -r1.13 MetalLookAndFeel.java
--- javax/swing/plaf/metal/MetalLookAndFeel.java	15 Apr 2005 12:01:01 -	1.13
+++ javax/swing/plaf/metal/MetalLookAndFeel.java	15 Apr 2005 22:09:09 -
@@ -439,6 +439,8 @@
* 
* Label.background0xcc
* 
+   * Label.font[EMAIL PROTECTED] #getControlTextFont}
+   * 
* Menu.background0xcc
* 
* MenuBar.background0xcc
@@ -468,6 +470,7 @@
   "ProgressBar.background", new ColorUIResource(getControl()),
   "TabbedPane.background", new ColorUIResource(getControl()),
   "Label.background", new ColorUIResource(getControl()),
+  "Label.font", getControlTextFont(),
   "Menu.background", new ColorUIResource(getControl()),
   "MenuBar.background", new ColorUIResource(getControl()),
   "MenuItem.background", new ColorUIResource(getControl()),
@@ -475,4 +478,28 @@
 };
 defaults.putDefaults(myDefaults);
   }
+
+  /**
+   * Initializes the system color defaults.
+   *
+   * In particular this sets the following keys:
+   *
+   * 
+   * 
+   * KeyValueDescription
+   * 
+   * control0xccThe default color for components
+   * 
+   * 
+   */
+  protected void initSystemColorDefaults(UIDefaults defaults)
+  {
+super.initSystemColorDefaults(defaults);
+Object[] uiDefaults;
+uiDefaults = new Object[] {
+  "control", new ColorUIResource(getControl())
+};
+defaults.putDefaults(uiDefaults);
+  }
+
 }
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


[cp-patches] FYI: MetalTabbedPaneUI fixlet

2005-04-15 Thread Roman Kennke
I have done some small changes to MetalTabbedPaneUI as suggested by
Michael.

2005-04-15  Roman Kennke  <[EMAIL PROTECTED]>

* javax/swing/plaf/metal/MetalTabbedPaneUI.java:
Added newline between import blocks. Changed Map to
HashMap in field declarations.

/Roman

Index: javax/swing/plaf/metal/MetalTabbedPaneUI.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalTabbedPaneUI.java,v
retrieving revision 1.2
diff -u -r1.2 MetalTabbedPaneUI.java
--- javax/swing/plaf/metal/MetalTabbedPaneUI.java	14 Apr 2005 13:58:51 -	1.2
+++ javax/swing/plaf/metal/MetalTabbedPaneUI.java	15 Apr 2005 18:56:53 -
@@ -38,6 +38,8 @@
 
 package javax.swing.plaf.metal;
 
+import java.util.HashMap;
+
 import javax.swing.JComponent;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.basic.BasicTabbedPaneUI;
@@ -46,9 +48,8 @@
   extends BasicTabbedPaneUI
 {
 
-  // FIXME: maybe replace by a Map of instances when this becomes stateful
   /** The shared UI instance for JTabbedPanes. */
-  private static MetalTabbedPaneUI instance = null;
+  private static HashMap instances = null;
 
   /**
* Constructs a new instance of MetalTabbedPaneUI.
@@ -67,8 +68,19 @@
*/
   public static ComponentUI createUI(JComponent component)
   {
-if (instance == null)
-  instance = new MetalTabbedPaneUI();
+if (instances == null)
+  instances = new HashMap();
+
+Object o = instances.get(component);
+MetalTabbedPaneUI instance;
+if (o == null)
+  {
+	instance = new MetalTabbedPaneUI();
+	instances.put(component, instance);
+  }
+else
+  instance = (MetalTabbedPaneUI) o;
+
 return instance;
   }
 }
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


Re: [cp-patches] Reindented native/jni code

2005-04-15 Thread Tom Tromey
> "Mark" == Mark Wielaard <[EMAIL PROTECTED]> writes:

Mark> Thanks. But next time please give people a little while before actually
Mark> checking a large automatic change like this in. Someone might be working
Mark> on one of the files and then you would create an unnecessary merge
Mark> conflict.

If the recipe to do this is well-known and automated, folks can just
run indent on their local copies and this should minimize the diffs.

gdb has a script to reindent in their cvs repository, and they just
run it on their sources routinely.  The "correct coding style" is just
defined as the output of this script.  This seems like a nice approach
to me, a script for Classpath would be nice, even if it just wraps
"indent -gnu" or whatever.

Tom


___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


[cp-patches] Nio-charset patch commited

2005-04-15 Thread Sven de Marothy
The final version has been comitted. It differs somewhat, so here's that
patch again.

2005-04-15  Sven de Marothy  <[EMAIL PROTECTED]>

* gnu/java/nio/charset/EncodingHelper.java: Added method
* java/io/InputStreamReader.java,
* java/io/OutputStreamWriter.java,
* java/lang/String.java: Move to NIO charsets.
* java/io/PrintStream.java: Inline conversion using String.


Index: gnu/java/nio/charset/EncodingHelper.java
===
RCS file: /cvsroot/classpath/classpath/gnu/java/nio/charset/EncodingHelper.java,v
retrieving revision 1.1
diff -u -r1.1 EncodingHelper.java
--- gnu/java/nio/charset/EncodingHelper.java	8 Apr 2005 21:46:05 -	1.1
+++ gnu/java/nio/charset/EncodingHelper.java	15 Apr 2005 15:54:44 -
@@ -116,6 +116,18 @@
 	return (oldCanonical != null)?oldCanonical : newCanonical;
 }
 
+public static boolean isISOLatin1(String s)
+{
+	if(s.equals("ISO-8859-1") ||
+	   s.equals("8859_1") ||
+	   s.equals("ISO_8859-1") ||
+	   s.equals("latin1") ||
+	   s.equals("ISO8859_1") || 
+	   s.equals("ISO_8859_1"))
+	return true;
+	return false;
+}
+
/**
 * Gets a charset, throwing the java.io exception and not 
 * the java.nio exception if an error occurs.
Index: java/io/InputStreamReader.java
===
RCS file: /cvsroot/classpath/classpath/java/io/InputStreamReader.java,v
retrieving revision 1.21
diff -u -r1.21 InputStreamReader.java
--- java/io/InputStreamReader.java	10 Mar 2005 19:35:51 -	1.21
+++ java/io/InputStreamReader.java	15 Apr 2005 15:54:46 -
@@ -38,12 +38,16 @@
 
 package java.io;
 
-import java.nio.channels.Channels;
+import java.nio.charset.UnsupportedCharsetException;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.CoderResult;
+import java.nio.charset.CodingErrorAction;
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
-
-import gnu.java.io.EncodingManager;
-import gnu.java.io.decode.Decoder;
+import java.nio.CharBuffer;
+import java.nio.ByteBuffer;
+import gnu.java.nio.charset.EncodingHelper;
 
 /**
  * This class reads characters from a byte input stream.   The characters
@@ -86,20 +90,50 @@
  * @see BufferedReader
  * @see InputStream
  *
+ * @author Robert Schuster
  * @author Aaron M. Renn ([EMAIL PROTECTED])
  * @author Per Bothner ([EMAIL PROTECTED])
  * @date April 22, 1998.  
  */
 public class InputStreamReader extends Reader
 {
-  /*
-   * This is the byte-character decoder class that does the reading and
-   * translation of bytes from the underlying stream.
+  /**
+   * The input stream.
+   */
+  private InputStream in;
+
+  /**
+   * The charset decoder.
+   */
+  private CharsetDecoder decoder;
+
+  /**
+   * End of stream reached.
+   */
+  private boolean isDone = false;
+
+  /**
+   * Need this.
*/
-  private Reader in;
+  private float maxBytesPerChar;
 
+  /**
+   * Buffer holding surplus loaded bytes (if any)
+   */
+  private ByteBuffer byteBuffer;
+
+  /**
+   * java.io canonical name of the encoding.
+   */
   private String encoding;
-  
+
+  /**
+   * We might decode to a 2-char UTF-16 surrogate, which won't fit in the
+   * output buffer. In this case we need to save the surrogate char.
+   */
+  private char savedSurrogate;
+  private boolean hasSavedSurrogate = false;
+
   /**
* This method initializes a new instance of InputStreamReader
* to read from the specified stream using the default encoding.
@@ -110,11 +144,38 @@
   {
 if (in == null)
   throw new NullPointerException();
-
-Decoder decoder =  EncodingManager.getDecoder(in);
-encoding = decoder.getSchemeName();
-
-this.in = decoder;
+this.in = in;
+try 
+	{ 
+	  encoding = System.getProperty("file.encoding");
+	  // Don't use NIO if avoidable
+	  if(EncodingHelper.isISOLatin1(encoding))
+	{
+	  encoding = "ISO8859_1";
+	  maxBytesPerChar = 1f;
+	  decoder = null;
+	  return;
+	}
+	  Charset cs = EncodingHelper.getCharset(encoding);
+	  decoder = cs.newDecoder();
+	  encoding = EncodingHelper.getOldCanonical(cs.name());
+	  try {
+	  maxBytesPerChar = cs.newEncoder().maxBytesPerChar();
+	  } catch(UnsupportedOperationException _){
+	  maxBytesPerChar = 1f;
+	  } 
+	  decoder.onMalformedInput(CodingErrorAction.REPLACE);
+	  decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
+	  decoder.reset();
+	} catch(RuntimeException e) {
+	  encoding = "ISO8859_1";
+	  maxBytesPerChar = 1f;
+	  decoder = null;
+	} catch(UnsupportedEncodingException e) {
+	  encoding = "ISO8859_1";
+	  maxBytesPerChar = 1f;
+	  decoder = null;
+	}
   }
 
   /**
@@ -136,41 +197,72 @@
 || encoding_name == null)
   throw new NullPointerException();
 
-Decoder decoder = EncodingManager.getDecoder(in, encoding_name);
-encoding = decod

[cp-patches] FYI: MetalButtonUI and some stuff

2005-04-15 Thread Roman Kennke
Hi,
I commit my work on MetalButtonUI stuff. The JButtons should now look 
nearly exactly like the real Metal Buttons.

The components background color is now initialized with the standard 
component color of the current theme.

2005-04-15  Roman Kennke  <[EMAIL PROTECTED]>
   * javax/swing/plaf/metal/MetalBorders.java:
   Added.
   * javax/swing/plaf/metal/MetalButtonUI.java:
   (installDefaults): Install button font.
   * javax/swing/plaf/metal/MetalLookAndFeel.java:
   (initComponentDefaults): Added button border, font and margin.
   Changed components background color to the Metal current themes
   standard color.
/Roman
Index: javax/swing/plaf/metal/MetalBorders.java
===
RCS file: javax/swing/plaf/metal/MetalBorders.java
diff -N javax/swing/plaf/metal/MetalBorders.java
--- /dev/null   1 Jan 1970 00:00:00 -
+++ javax/swing/plaf/metal/MetalBorders.java15 Apr 2005 12:01:01 -  
1.1
@@ -0,0 +1,205 @@
+/* MetalBorders.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.Component;
+import java.awt.Graphics;
+import java.awt.Insets;
+
+import javax.swing.AbstractButton;
+import javax.swing.ButtonModel;
+import javax.swing.JButton;
+import javax.swing.border.AbstractBorder;
+import javax.swing.border.Border;
+import javax.swing.plaf.BorderUIResource;
+import javax.swing.plaf.basic.BasicGraphicsUtils;
+import javax.swing.plaf.basic.BasicBorders;
+
+/**
+ * This factory class creates borders for the different Swing components
+ * UI.
+ *
+ * @author Roman Kennke ([EMAIL PROTECTED])
+ */
+public class MetalBorders
+{
+
+  /**
+   * A MarginBorder that gets shared by multiple components.
+   * Created on demand by the private helper function [EMAIL PROTECTED]
+   * #getMarginBorder()}.
+   */
+  private static BasicBorders.MarginBorder sharedMarginBorder;
+
+  /**
+   * The border that is drawn around Swing buttons.
+   */
+  public static class MetalButtonBorder
+extends AbstractBorder
+  {
+/** The borders insets. */
+protected static Insets borderInsets = new Insets(2, 2, 2, 2);
+
+/**
+ * Creates a new instance of ButtonBorder.
+ */
+public MetalButtonBorder()
+{
+}
+
+/**
+ * Paints the button border.
+ *
+ * @param c the component for which we paint the border
+ * @param g the Graphics context to use
+ * @param x the X coordinate of the upper left corner of c
+ * @param y the Y coordinate of the upper left corner of c
+ * @param w the width of c
+ * @param h the height of c
+ */
+public void paintBorder(Component c, Graphics g, int x, int y, int w,
+int h)
+{
+  ButtonModel bmodel = null;
+  
+  if (c instanceof AbstractButton)
+bmodel = ((AbstractButton) c).getModel();
+
+  Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
+  Color shadow = MetalLookAndFeel.getControlShadow();
+  Color light = MetalLookAndFeel.getWhite();
+  Color middle = MetalLookAndFeel.getControl();
+
+  // draw dark border
+  g.setColor(darkShadow);
+  g.drawRect(x, y, w - 2, h - 2);
+
+  if (!bmodel.isPressed())
+   

Re: [cp-patches] FYI: MetalTabbedPaneUI fix

2005-04-15 Thread Michael Koch
On Fri, Apr 15, 2005 at 11:03:45AM +0200, Roman Kennke wrote:
> The following fix lets MetalTabbedPaneUI create one instance of itself 
> instead of sharing a singleton.
> 
> 2005-04-15  Roman Kennke  <[EMAIL PROTECTED]>
> 
> * javax/swing/plaf/metal/MetalTabbedPaneUI.java
> (createUI): Create one MetalTabbedPaneUI per Component instead
> of sharing one instance.
> 
> 
> /Roman
> 

> Index: javax/swing/plaf/metal/MetalTabbedPaneUI.java
> ===
> RCS file: 
> /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalTabbedPaneUI.java,v
> retrieving revision 1.2
> diff -u -r1.2 MetalTabbedPaneUI.java
> --- javax/swing/plaf/metal/MetalTabbedPaneUI.java 14 Apr 2005 13:58:51 
> -  1.2
> +++ javax/swing/plaf/metal/MetalTabbedPaneUI.java 15 Apr 2005 09:00:03 
> -
> @@ -38,6 +38,8 @@
>  
>  package javax.swing.plaf.metal;
>  
> +import java.util.HashMap;
> +import java.util.Map;
>  import javax.swing.JComponent;
>  import javax.swing.plaf.ComponentUI;
>  import javax.swing.plaf.basic.BasicTabbedPaneUI;
> @@ -46,9 +48,8 @@
>extends BasicTabbedPaneUI
>  {
>  
> -  // FIXME: maybe replace by a Map of instances when this becomes stateful
>/** The shared UI instance for JTabbedPanes. */
> -  private static MetalTabbedPaneUI instance = null;
> +  private static Map instances = null;

As you know this will always contain a HashMap its better to make it a
HashMap as method calls to explicit classes is faster then calling
methods through interfaces. Speed doesnt really matter in this case but
this is a general rule.
  
>/**
> * Constructs a new instance of MetalTabbedPaneUI.
> @@ -67,8 +68,19 @@
> */
>public static ComponentUI createUI(JComponent component)
>{
> -if (instance == null)
> -  instance = new MetalTabbedPaneUI();
> +if (instances == null)
> +  instances = new HashMap();
> +
> +Object o = instances.get(component);
> +MetalTabbedPaneUI instance;
> +if (o == null)
> +  {
> + instance = new MetalTabbedPaneUI();
> + instances.put(component, instance);
> +  }
> +else
> +  instance = (MetalTabbedPaneUI) o;
> +
>  return instance;
>}
>  }

Michael
-- 
Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html

Join the community at http://planet.classpath.org/


___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


[cp-patches] FYI: MetalTabbedPaneUI fix

2005-04-15 Thread Roman Kennke
The following fix lets MetalTabbedPaneUI create one instance of itself 
instead of sharing a singleton.

2005-04-15  Roman Kennke  <[EMAIL PROTECTED]>
   * javax/swing/plaf/metal/MetalTabbedPaneUI.java
   (createUI): Create one MetalTabbedPaneUI per Component instead
   of sharing one instance.
/Roman
Index: javax/swing/plaf/metal/MetalTabbedPaneUI.java
===
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalTabbedPaneUI.java,v
retrieving revision 1.2
diff -u -r1.2 MetalTabbedPaneUI.java
--- javax/swing/plaf/metal/MetalTabbedPaneUI.java   14 Apr 2005 13:58:51 
-  1.2
+++ javax/swing/plaf/metal/MetalTabbedPaneUI.java   15 Apr 2005 09:00:03 
-
@@ -38,6 +38,8 @@
 
 package javax.swing.plaf.metal;
 
+import java.util.HashMap;
+import java.util.Map;
 import javax.swing.JComponent;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.basic.BasicTabbedPaneUI;
@@ -46,9 +48,8 @@
   extends BasicTabbedPaneUI
 {
 
-  // FIXME: maybe replace by a Map of instances when this becomes stateful
   /** The shared UI instance for JTabbedPanes. */
-  private static MetalTabbedPaneUI instance = null;
+  private static Map instances = null;
 
   /**
* Constructs a new instance of MetalTabbedPaneUI.
@@ -67,8 +68,19 @@
*/
   public static ComponentUI createUI(JComponent component)
   {
-if (instance == null)
-  instance = new MetalTabbedPaneUI();
+if (instances == null)
+  instances = new HashMap();
+
+Object o = instances.get(component);
+MetalTabbedPaneUI instance;
+if (o == null)
+  {
+   instance = new MetalTabbedPaneUI();
+   instances.put(component, instance);
+  }
+else
+  instance = (MetalTabbedPaneUI) o;
+
 return instance;
   }
 }
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


[cp-patches] FYI: Added initComponentDefaults to MetalLookAndFeel

2005-04-15 Thread Roman Kennke
Hi,
I added initComponentDefaults that initializes the component colors (and 
later other properties) for Metal.

2005-04-15  Roman Kennke  <[EMAIL PROTECTED]>
   * javax/swing/plaf/metal/MetalLookAndFeel.java
   (initComponentDefaults): Added to set Metal specific component
   defaults.
/Roman
Index: javax/swing/plaf/metal/MetalLookAndFeel.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java,v
retrieving revision 1.11
diff -u -r1.11 MetalLookAndFeel.java
--- javax/swing/plaf/metal/MetalLookAndFeel.java	14 Apr 2005 21:00:02 -	1.11
+++ javax/swing/plaf/metal/MetalLookAndFeel.java	15 Apr 2005 08:55:57 -
@@ -38,6 +38,7 @@
 
 package javax.swing.plaf.metal;
 
+import java.awt.Color;
 import javax.swing.UIDefaults;
 import javax.swing.plaf.ColorUIResource;
 import javax.swing.plaf.FontUIResource;
@@ -399,4 +400,68 @@
 defaults.putDefaults(uiDefaults);
   }
 
+  /**
+   * Initializes the component defaults for the Metal Look & Feel.
+   *
+   * In particular this sets the following keys (the colors are given
+   * as RGB hex values):
+   *
+   * 
+   * 
+   * KeyValue
+   * 
+   * Button.background0xcc
+   * 
+   * CheckBox.background0xcc
+   * 
+   * CheckBoxMenuItem.background0xcc
+   * 
+   * ToolBar.background0xcc
+   * 
+   * Panel.background0xcc
+   * 
+   * Slider.background0xcc
+   * 
+   * OptionPane.background0xcc
+   * 
+   * ProgressBar.background0xcc
+   * 
+   * TabbedPane.background0xcc
+   * 
+   * Label.background0xcc
+   * 
+   * Menu.background0xcc
+   * 
+   * MenuBar.background0xcc
+   * 
+   * MenuItem.background0xcc
+   * 
+   * ScrollBar.background0xcc
+   * 
+   * 
+   *
+   * @param defaults the UIDefaults instance to which the values are added
+   */
+  protected void initComponentDefaults(UIDefaults defaults)
+  {
+super.initComponentDefaults(defaults);
+Color background = "" Color(0xcc, 0xcc, 0xcc);
+Object[] myDefaults = new Object[] {
+  "Button.background", new ColorUIResource(background),
+  "CheckBox.background", new ColorUIResource(background),
+  "CheckBoxMenuItem.background", new ColorUIResource(background),
+  "ToolBar.background", new ColorUIResource(background),
+  "Panel.background", new ColorUIResource(background),
+  "Slider.background", new ColorUIResource(background),
+  "OptionPane.background", new ColorUIResource(background),
+  "ProgressBar.background", new ColorUIResource(background),
+  "TabbedPane.background", new ColorUIResource(background),
+  "Label.background", new ColorUIResource(background),
+  "Menu.background", new ColorUIResource(background),
+  "MenuBar.background", new ColorUIResource(background),
+  "MenuItem.background", new ColorUIResource(background),
+  "ScrollBar.background", new ColorUIResource(background)
+};
+defaults.putDefaults(myDefaults);
+  }
 }
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches