You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by bi...@apache.org on 2001/01/16 16:39:04 UTC

cvs commit: xml-batik/sources/org/apache/batik/apps/svgviewer StatusBar.java

billh       01/01/16 07:39:03

  Modified:    sources/org/apache/batik/apps/svgviewer StatusBar.java
  Log:
  Created inner MessageArea class (extends JComponent), to replace
  the message JLabel.  This was done to extend the range of environments
  where non-latin characters can be displayed in the message field
  (on some platforms, the font used in JLabel was not doing proper
  substitution for missing glyphs).
  
  Revision  Changes    Path
  1.4       +62 -7     xml-batik/sources/org/apache/batik/apps/svgviewer/StatusBar.java
  
  Index: StatusBar.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/apps/svgviewer/StatusBar.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StatusBar.java	2000/11/02 08:55:27	1.3
  +++ StatusBar.java	2001/01/16 15:39:02	1.4
  @@ -10,12 +10,26 @@
   
   import java.awt.BorderLayout;
   import java.awt.Dimension;
  +import java.awt.Graphics;
  +import java.awt.Graphics2D;
  +import java.awt.Insets;
  +import java.awt.Color;
  +
  +import java.awt.geom.AffineTransform;
  +
  +import java.awt.Font;
  +import java.awt.font.FontRenderContext;
  +import java.awt.font.TextLayout;
  +import java.awt.font.TextAttribute;
   
   import java.util.Locale;
   import java.util.ResourceBundle;
  +import java.util.HashMap;
   
   import javax.swing.BorderFactory;
  +import javax.swing.JComponent;
   import javax.swing.JLabel;
  +import javax.swing.JTextArea;
   import javax.swing.JPanel;
   import javax.swing.border.BevelBorder;
   
  @@ -25,7 +39,7 @@
    * This class represents a viewer status bar.
    *
    * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
  - * @version $Id: StatusBar.java,v 1.3 2000/11/02 08:55:27 hillion Exp $
  + * @version $Id: StatusBar.java,v 1.4 2001/01/16 15:39:02 billh Exp $
    */
   public class StatusBar extends JPanel {
       /**
  @@ -52,21 +66,21 @@
        * The x position/width label.
        */
       protected JLabel xPosition;
  -    
  +
       /**
        * The y position/height label.
        */
       protected JLabel yPosition;
  -    
  +
       /**
        * The zoom label.
        */
       protected JLabel zoom;
  -    
  +
       /**
        * The message label
        */
  -    protected JLabel message;
  +    protected MessageArea message;
   
       /**
        * The main message
  @@ -105,7 +119,8 @@
           p.add("East", zoom);
   
           p = new JPanel(new BorderLayout(0, 0));
  -        message = new JLabel();
  +        message = new MessageArea();
  +        message.setForeground(zoom.getForeground());
           message.setBorder(bb);
           p.add(message);
           add(p);
  @@ -169,7 +184,7 @@
        * @param s the message
        */
       public void setMessage(String s) {
  -        message.setText(s);
  +        mainMessage = s;
           setPreferredSize(new Dimension(0, getPreferredSize().height));
           new DisplayThread().start();
       }
  @@ -179,6 +194,7 @@
        * @param s the message
        */
       public void setMainMessage(String s) {
  +        mainMessage = s;
           message.setText(mainMessage = s);
           setPreferredSize(new Dimension(0, getPreferredSize().height));
       }
  @@ -196,7 +212,46 @@
                   Thread.sleep(3000);
               } catch(InterruptedException e) {
               }
  +
               message.setText(mainMessage);
           }
  +    }
  +
  +    public class MessageArea extends JComponent {
  +
  +        String text = "";
  +        TextLayout layout;
  +        FontRenderContext frc;
  +        HashMap textAttMap;
  +
  +        public MessageArea() {
  +            super();
  +            textAttMap = new HashMap(2);
  +            textAttMap.put(TextAttribute.SIZE, new Float(12f));
  +            textAttMap.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
  +            frc = new FontRenderContext(new AffineTransform(), true, true);
  +        }
  +
  +        public void setText(String s) {
  +            text = s;
  +            if (s.length() > 0) {
  +                layout = new TextLayout(text, textAttMap, frc);
  +            } else {
  +                layout = null;
  +            }
  +            repaint();
  +        }
  +
  +        public void paint(Graphics g) {
  +            super.paint(g);
  +            Insets insets = getInsets();
  +            g.setColor(getForeground());
  +            if (layout != null)  {
  +                layout.draw((Graphics2D) g,
  +                    (float) getX()+insets.left+2,
  +                    (float) (getY()+getHeight()-insets.bottom-2));
  +            }
  +        }
  +
       }
   }
  
  
  

Re: cvs commit: xml-batik/sources/org/apache/batik/apps/svgviewer StatusBar.java

Posted by Thierry Kormann <Th...@sophia.inria.fr>.
Bill,

>   Created inner MessageArea class (extends JComponent), to replace
>   the message JLabel.  This was done to extend the range of environments
>   where non-latin characters can be displayed in the message field
>   (on some platforms, the font used in JLabel was not doing proper
>   substitution for missing glyphs).

I found some minor bugs.

The status bar has sometimes incorrect size. When selecting arabic text, some
glyphs are painted outside the component's bounding box. 

The font is not the same than the JLabel default one. It seems that the font
size is 'hard-coded' (which may be a problem for accessibility, I think).

Could you fix that or does your new code makes it difficult?

At last, I though that when subclassing a swing component, we have to override
the paintComponent and not paint method. Am I wrong?

Thierry.

-- 
Thierry Kormann
email: Thierry.Kormann@sophia.inria.fr  http://www.inria.fr/koala/tkormann/
Koala/Dyade/Bull @ INRIA - Sophia Antipolis