View Javadoc

1   /*
2      Copyright 2002-2006 Martin van den Bemt
3   
4      Licensed under the Apache License, Version 2.0 (the "License");
5      you may not use this file except in compliance with the License.
6      You may obtain a copy of the License at
7   
8          http://www.apache.org/licenses/LICENSE-2.0
9   
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15  */
16  package org.xulux.guilayer.swing.extensions;
17  
18  import java.awt.Color;
19  import java.awt.Component;
20  import java.awt.Graphics;
21  
22  import javax.swing.border.LineBorder;
23  
24  /**
25   *
26   * @author Martin van den Bemt
27   * @version $Id: NyxLineBorder.java,v 1.1 2005/12/18 12:58:18 mvdb Exp $
28   */
29  public class NyxLineBorder extends LineBorder {
30  
31      /**
32       * @param color
33       */
34      public NyxLineBorder(Color color) {
35          super(color);
36      }
37  
38      /**
39       * @param color
40       * @param thickness
41       */
42      public NyxLineBorder(Color color, int thickness) {
43          super(color, thickness);
44      }
45  
46      /**
47       * @param color
48       * @param thickness
49       * @param roundedCorners
50       */
51      public NyxLineBorder(Color color, int thickness, boolean roundedCorners) {
52          super(color, thickness, roundedCorners);
53      }
54  
55      /**
56       * Paints the border for the specified component with the
57       * specified position and size.
58       * @param c the component for which this border is being painted
59       * @param g the paint graphics
60       * @param x the x position of the painted border
61       * @param y the y position of the painted border
62       * @param width the width of the painted border
63       * @param height the height of the painted border
64       */
65      public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
66          Color oldColor = g.getColor();
67          int i;
68  
69      /// PENDING(klobad) How/should do we support Roundtangles?
70          g.setColor(lineColor);
71          for (i = 0; i < thickness; i++)  {
72              if (!roundedCorners) {
73                  System.out.println("Without rounded corners");
74                  System.out.println("x+i = " + (x + i));
75                  System.out.println("y+i = " + (y + i));
76                  System.out.println("width-i-i-1 = " + (width - i - i - 1));
77                  System.out.println("height-i-i-1 = " + (height - i - i - 1));
78                  g.drawRect(x + i, y + i, width - i - i - 1, height - i - i - 1);
79              } else {
80                  g.drawRoundRect(x + i, y + i, width - i - i - 1, height - i - i - 1, thickness, thickness);
81              }
82          }
83          g.setColor(oldColor);
84      }
85  
86  
87  }