/[classpath]/classpath/javax/swing/plaf/metal/MetalBorders.java
ViewVC logotype

Diff of /classpath/javax/swing/plaf/metal/MetalBorders.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.2.4 by gnu_andrew, Sat Sep 10 15:31:52 2005 UTC revision 1.1.2.5 by gnu_andrew, Tue Sep 20 18:46:34 2005 UTC
# Line 44  import java.awt.Graphics; Line 44  import java.awt.Graphics;
44  import java.awt.Insets;  import java.awt.Insets;
45    
46  import javax.swing.AbstractButton;  import javax.swing.AbstractButton;
47    import javax.swing.BorderFactory;
48  import javax.swing.ButtonModel;  import javax.swing.ButtonModel;
49  import javax.swing.JInternalFrame;  import javax.swing.JInternalFrame;
50  import javax.swing.JMenu;  import javax.swing.JMenu;
51  import javax.swing.JMenuBar;  import javax.swing.JMenuBar;
52  import javax.swing.JMenuItem;  import javax.swing.JMenuItem;
53  import javax.swing.JTextField;  import javax.swing.JTextField;
54    import javax.swing.JToggleButton;
55  import javax.swing.border.AbstractBorder;  import javax.swing.border.AbstractBorder;
56  import javax.swing.border.Border;  import javax.swing.border.Border;
57  import javax.swing.plaf.BorderUIResource;  import javax.swing.plaf.BorderUIResource;
58  import javax.swing.plaf.UIResource;  import javax.swing.plaf.UIResource;
59  import javax.swing.plaf.basic.BasicBorders;  import javax.swing.plaf.basic.BasicBorders;
60    import javax.swing.text.JTextComponent;
61    
62    
63  /**  /**
# Line 69  public class MetalBorders Line 72  public class MetalBorders
72    /** The shared instance for getButtonBorder(). */    /** The shared instance for getButtonBorder(). */
73    private static Border buttonBorder;    private static Border buttonBorder;
74    
75      /** The shared instance for getToggleButtonBorder(). */
76      private static Border toggleButtonBorder;
77    
78      /** The shared instance for getDesktopIconBorder(). */
79      private static Border desktopIconBorder;
80    
81    /** The shared instance for getRolloverButtonBorder(). */    /** The shared instance for getRolloverButtonBorder(). */
82    private static Border toolbarButtonBorder;    private static Border toolbarButtonBorder;
83    
# Line 76  public class MetalBorders Line 85  public class MetalBorders
85    private static Border textFieldBorder;    private static Border textFieldBorder;
86    
87    /**    /**
88       * The shared instance for getTextBorder().
89       */
90      private static Border textBorder;
91    
92      /**
93     * A MarginBorder that gets shared by multiple components.     * A MarginBorder that gets shared by multiple components.
94     * Created on demand by the private helper function {@link     * Created on demand by the private helper function {@link
95     * #getMarginBorder()}.     * #getMarginBorder()}.
# Line 122  public class MetalBorders Line 136  public class MetalBorders
136        Color light = MetalLookAndFeel.getWhite();        Color light = MetalLookAndFeel.getWhite();
137        Color middle = MetalLookAndFeel.getControl();        Color middle = MetalLookAndFeel.getControl();
138    
139        // draw dark border        if (c.isEnabled())
140        g.setColor(darkShadow);        {
141        g.drawRect(x, y, w - 2, h - 2);          // draw dark border
142            g.setColor(darkShadow);
143        if (!bmodel.isPressed())          g.drawRect(x, y, w - 2, h - 2);
144    
145            if (!bmodel.isPressed())
146              {
147                // draw light border
148                g.setColor(light);
149                g.drawRect(x + 1, y + 1, w - 2, h - 2);
150    
151                // draw crossing pixels of both borders
152                g.setColor(middle);
153                g.drawRect(x + 1, y + h - 2, 0, 0);
154                g.drawRect(x + w - 2, y + 1, 0, 0);
155              }
156            else
157              {
158                // draw light border
159                g.setColor(light);
160                g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
161                g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
162    
163                // draw shadow border
164                g.setColor(middle);
165                g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
166                g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
167    
168                // draw crossing pixels of both borders
169                g.setColor(shadow);
170                g.drawRect(x + 1, y + h - 2, 0, 0);
171                g.drawRect(x + w - 2, y + 1, 0, 0);
172              }
173          }
174          else
175          {          {
176            // draw light border            // draw disabled border
177            g.setColor(light);            g.setColor(MetalLookAndFeel.getInactiveControlTextColor());
178            g.drawRect(x + 1, y + 1, w - 2, h - 2);            g.drawRect(x, y, w - 2, h - 2);          
   
           // draw crossing pixels of both borders  
           g.setColor(middle);  
           g.drawRect(x + 1, y + h - 2, 0, 0);  
           g.drawRect(x + w - 2, y + 1, 0, 0);  
         }  
       else  
         {  
           // draw light border  
           g.setColor(light);  
           g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);  
           g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);  
   
           // draw shadow border  
           g.setColor(middle);  
           g.drawLine(x + 1, y + 1, x + w - 2, y + 1);  
           g.drawLine(x + 1, y + 1, x + 1, y + h - 2);  
   
           // draw crossing pixels of both borders  
           g.setColor(shadow);  
           g.drawRect(x + 1, y + h - 2, 0, 0);  
           g.drawRect(x + w - 2, y + 1, 0, 0);  
179          }          }
180      }      }
181    
# Line 191  public class MetalBorders Line 214  public class MetalBorders
214    }    }
215    
216    /**    /**
217       * A border used when painting {@link JInternalFrame} instances.
218       */
219      static class DesktopIconBorder extends AbstractBorder
220        implements UIResource
221      {
222        /**
223         * Creates a new border instance.
224         */
225        public DesktopIconBorder()
226        {
227        }
228        
229        /**
230         * Returns the border insets.
231         *
232         * @param c  the component (ignored).
233         *
234         * @return The border insets.
235         */
236        public Insets getBorderInsets(Component c)
237        {
238          return getBorderInsets(c, null);
239        }
240        
241        /**
242         * Returns the border insets.
243         *
244         * @param c  the component (ignored).
245         * @return The border insets.
246         */
247        public Insets getBorderInsets(Component c, Insets newInsets)
248        {
249          if (newInsets == null)
250            newInsets = new Insets(3, 3, 2, 3);
251          else
252            {
253              newInsets.top = 3;
254              newInsets.left = 3;
255              newInsets.bottom = 2;
256              newInsets.right = 3;
257            }
258          return newInsets;  
259        }
260        
261        /**
262         * Paints the border for the specified component.
263         *
264         * @param c  the component.
265         * @param g  the graphics device.
266         * @param x  the x-coordinate.
267         * @param y  the y-coordinate.
268         * @param w  the width.
269         * @param h  the height.
270         */
271        public void paintBorder(Component c, Graphics g, int x, int y, int w,
272            int h)
273        {
274          g.setColor(MetalLookAndFeel.getControlDarkShadow());      
275          g.drawRect(x, y, w - 1, h - 1);
276        }
277        
278      }
279    
280      /**
281     * A simple 3D border.     * A simple 3D border.
282     */     */
283    public static class Flush3DBorder extends AbstractBorder    public static class Flush3DBorder extends AbstractBorder
# Line 262  public class MetalBorders Line 349  public class MetalBorders
349    }    }
350            
351    /**    /**
352       * A border used for a {@link JInternalFrame} when it is being used as a
353       * palette.
354       *
355       * @since 1.3
356       */
357      public static class PaletteBorder
358        extends AbstractBorder
359        implements UIResource
360      {
361        /**
362         * Creates a new <code>PaletteBorder</code>.
363         */
364        public PaletteBorder()
365        {
366        }
367        
368        /**
369         * Returns the border insets.
370         *
371         * @param c  the component (ignored).
372         *
373         * @return The border insets.
374         */
375        public Insets getBorderInsets(Component c)
376        {
377          return getBorderInsets(c, null);
378        }
379    
380        /**
381         * Returns the border insets.
382         *
383         * @param c  the component (ignored).
384         * @param newInsets  the insets object that, if non-<code>null</code>, will
385         *                   be populated with the result from this method.
386         *
387         * @return The border insets.
388         */
389        public Insets getBorderInsets(Component c, Insets newInsets)
390        {        
391          if (newInsets == null)
392            newInsets = new Insets(1, 1, 1, 1);
393          else
394            {
395              newInsets.top = 1;
396              newInsets.left = 1;
397              newInsets.bottom = 1;
398              newInsets.right = 1;
399            }
400          return newInsets;  
401        }
402        
403        /**
404         * Paints the border for the specified component.
405         *
406         * @param c  the component (ignored).
407         * @param g  the graphics device.
408         * @param x  the x-coordinate.
409         * @param y  the y-coordinate.
410         * @param w  the width.
411         * @param h  the height.
412         */
413        public void paintBorder(Component c, Graphics g, int x, int y, int w,
414                int h)
415        {
416          Color savedColor = g.getColor();
417          
418          // draw the outline
419          g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
420          g.drawRect(x, y, w - 1, h - 1);
421          
422          // put a dot in each corner
423          g.setColor(MetalLookAndFeel.getControl());
424          g.fillRect(x, y, 1, 1);
425          g.fillRect(x + w - 1, y, 1, 1);
426          g.fillRect(x + w - 1, y + h - 1, 1, 1);
427          g.fillRect(x, y + h - 1, 1, 1);      
428          g.setColor(savedColor);
429        }
430    
431      }
432        
433      /**
434     * A border used for the {@link JTextField} component.     * A border used for the {@link JTextField} component.
435     */     */
436    public static class TextFieldBorder extends Flush3DBorder    public static class TextFieldBorder extends Flush3DBorder
# Line 286  public class MetalBorders Line 455  public class MetalBorders
455       */       */
456      public void paintBorder(Component c, Graphics g, int x, int y, int w,      public void paintBorder(Component c, Graphics g, int x, int y, int w,
457          int h)          int h)
458      {              {
459        if (c.isEnabled())        JTextComponent tc = (JTextComponent) c;
460          if (tc.isEnabled() && tc.isEditable())
461          super.paintBorder(c, g, x, y, w, h);          super.paintBorder(c, g, x, y, w, h);
462        else        else
463          {          {
# Line 386  public class MetalBorders Line 556  public class MetalBorders
556        g.drawLine(x + w - 3, y + 14, x + w - 3, y + h - 15);        g.drawLine(x + w - 3, y + 14, x + w - 3, y + h - 15);
557                
558        // draw the line highlights        // draw the line highlights
559        g.setColor(MetalLookAndFeel.getControl());        if (f.isSelected())
560            g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
561          else
562            g.setColor(MetalLookAndFeel.getControlShadow());
563        g.drawLine(x + 15, y + 3, x + w - 14, y + 3);        g.drawLine(x + 15, y + 3, x + w - 14, y + 3);
564        g.drawLine(x + 15, y + h - 2, x + w - 14, y + h - 2);        g.drawLine(x + 15, y + h - 2, x + w - 14, y + h - 2);
565        g.drawLine(x + 3, y + 15, x + 3, y + h - 14);        g.drawLine(x + 3, y + 15, x + 3, y + h - 14);
# Line 770  public class MetalBorders Line 943  public class MetalBorders
943    }    }
944    
945    /**    /**
946       * A border used for {@link JToggleButton} components.
947       *
948       * @since 1.3
949       */
950      public static class ToggleButtonBorder
951        extends ButtonBorder
952      {
953        /**
954         * Creates a new border instance.
955         */
956        public ToggleButtonBorder()
957        {
958        }
959        
960        /**
961         * Paints the toggle button border.
962         *
963         * @param c the component for which we paint the border
964         * @param g the Graphics context to use
965         * @param x the X coordinate of the upper left corner of c
966         * @param y the Y coordinate of the upper left corner of c
967         * @param w the width of c
968         * @param h the height of c
969         */
970        public void paintBorder(Component c, Graphics g, int x, int y, int w,
971                                int h)
972        {
973          ButtonModel bmodel = null;
974          
975          if (c instanceof AbstractButton)
976            bmodel = ((AbstractButton) c).getModel();
977    
978          Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
979          Color shadow = MetalLookAndFeel.getControlShadow();
980          Color light = MetalLookAndFeel.getWhite();
981          Color middle = MetalLookAndFeel.getControl();
982    
983          if (c.isEnabled())
984            {
985              // draw dark border
986              g.setColor(darkShadow);
987              g.drawRect(x, y, w - 2, h - 2);
988    
989              if (!bmodel.isArmed())
990                {
991                  // draw light border
992                  g.setColor(light);
993                  g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
994                  g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
995                  if (bmodel.isSelected())
996                    g.setColor(middle);
997                  g.drawLine(x + 1, y + 1, x + w - 3, y + 1);
998                  g.drawLine(x + 1, y + 1, x + 1, y + h - 3);
999    
1000                  // draw crossing pixels of both borders
1001                  g.setColor(shadow);
1002                  g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
1003                  g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
1004                }
1005              else
1006                {
1007                  // draw light border
1008                  g.setColor(light);
1009                  g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
1010                  g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
1011    
1012                  // draw shadow border
1013                  g.setColor(shadow);
1014                  g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
1015                  g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
1016    
1017                  // draw crossing pixels of both borders
1018                  g.setColor(shadow);
1019                  g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
1020                  g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
1021                  
1022                }
1023              // draw corners
1024              g.setColor(middle);
1025              g.drawLine(x, y + h - 1, x, y + h - 1);
1026              g.drawLine(x + w - 1, y, x + w - 1, y);
1027            }
1028          else
1029            {
1030              // draw disabled border
1031              g.setColor(MetalLookAndFeel.getControlDisabled());
1032              g.drawRect(x, y, w - 2, h - 2);          
1033            }
1034        }
1035      }
1036    
1037      /**
1038       * A border for table header cells.
1039       *
1040       * @since 1.3
1041       */
1042      public static class TableHeaderBorder extends AbstractBorder
1043      {
1044        /**
1045         * The insets of this border.
1046         */
1047        // TODO: According to tests that I have done, this is really the border
1048        // that should be returned by getBorderInsets(). However, the name
1049        // is very distracting. Is there any deeper meaning in it?
1050        protected Insets editorBorderInsets;
1051    
1052        /**
1053         * Creates a new instance of <code>TableHeaderBorder</code>.
1054         */
1055        public TableHeaderBorder()
1056        {
1057          editorBorderInsets = new Insets(1, 1, 1, 1);
1058        }
1059    
1060        /**
1061         * Return the insets of this border.
1062         *
1063         * @return the insets of this border
1064         */
1065        public Insets getBorderInsets(Component c)
1066        {
1067          return editorBorderInsets;
1068        }
1069    
1070        /**
1071         * Paints the border.
1072         *
1073         * @param c the component for which to paint the border
1074         * @param g the graphics context to use
1075         * @param x the x cooridinate of the border rectangle
1076         * @param y the y cooridinate of the border rectangle
1077         * @param w the width of the border rectangle
1078         * @param h the height of the border rectangle
1079         */
1080        public void paintBorder(Component c, Graphics g, int x, int y, int w, int h)
1081        {
1082          Color dark = MetalLookAndFeel.getControlDarkShadow();
1083          Color light = MetalLookAndFeel.getWhite();
1084          Color old = g.getColor();
1085          g.setColor(light);
1086          g.drawLine(x, y, x + w - 2, y);
1087          g.drawLine(x, y, x, y + h - 2);
1088          g.setColor(dark);
1089          g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
1090          g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
1091          g.setColor(old);
1092        }
1093      }
1094    
1095      /**
1096     * Returns a border for Swing buttons in the Metal Look &amp; Feel.     * Returns a border for Swing buttons in the Metal Look &amp; Feel.
1097     *     *
1098     * @return a border for Swing buttons in the Metal Look &amp; Feel     * @return a border for Swing buttons in the Metal Look &amp; Feel
# Line 785  public class MetalBorders Line 1108  public class MetalBorders
1108        }        }
1109      return buttonBorder;      return buttonBorder;
1110    }    }
1111      
1112      /**
1113       * Returns a border for use with {@link JToggleButton} components.
1114       *
1115       * @return A border.
1116       *
1117       * @since 1.3
1118       */
1119      public static Border getToggleButtonBorder()
1120      {
1121        if (toggleButtonBorder == null)
1122          {
1123            Border outer = new ToggleButtonBorder();
1124            Border inner = getMarginBorder();
1125            toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource
1126                (outer, inner);
1127          }
1128        return toggleButtonBorder;
1129      }
1130    
1131      /**
1132       * Returns a border instance that is used with a {@link JInternalFrame} when
1133       * it is in the iconified state.
1134       *
1135       * @return A border.
1136       *
1137       * @since 1.3
1138       */
1139      public static Border getDesktopIconBorder()
1140      {
1141        if (desktopIconBorder == null)
1142          desktopIconBorder = new DesktopIconBorder();
1143        return desktopIconBorder;      
1144      }
1145    
1146    /**    /**
1147     * Returns a border for use by the {@link JTextField} component.     * Returns a border for use by the {@link JTextField} component.
# Line 796  public class MetalBorders Line 1153  public class MetalBorders
1153    public static Border getTextFieldBorder()    public static Border getTextFieldBorder()
1154    {    {
1155      if (textFieldBorder == null)      if (textFieldBorder == null)
1156        textFieldBorder = new TextFieldBorder();        {
1157            Border inner = getMarginBorder();
1158            Border outer = new TextFieldBorder();
1159            textFieldBorder = BorderFactory.createCompoundBorder(outer, inner);
1160          }
1161      return textFieldBorder;      return textFieldBorder;
1162    }    }
1163    
1164    /**    /**
1165       * Returns the border that is used for text components (except text fields,
1166       * which use {@link #getTextFieldBorder}.
1167       *
1168       * @return the border that is used for text components
1169       *
1170       * @since 1.3
1171       */
1172      public static Border getTextBorder()
1173      {
1174        if (textBorder == null)
1175          {
1176            Border inner = getMarginBorder();
1177            Border outer = new Flush3DBorder();
1178            textBorder =
1179              new BorderUIResource.CompoundBorderUIResource(outer, inner);
1180          }
1181        return textBorder;
1182      }
1183    
1184      /**
1185     * Returns a border for Toolbar buttons in the Metal Look &amp; Feel.     * Returns a border for Toolbar buttons in the Metal Look &amp; Feel.
1186     *     *
1187     * @return a border for Toolbar buttons in the Metal Look &amp; Feel     * @return a border for Toolbar buttons in the Metal Look &amp; Feel

Legend:
Removed from v.1.1.2.4  
changed lines
  Added in v.1.1.2.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26