]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.ui/src/org/simantics/spreadsheet/ui/SheetBorder.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.spreadsheet.ui / src / org / simantics / spreadsheet / ui / SheetBorder.java
1 package org.simantics.spreadsheet.ui;
2
3 import java.awt.Graphics;
4 import java.awt.Insets;
5 import java.awt.Component;
6 import java.awt.Color;
7
8 import javax.swing.Icon;
9 import javax.swing.border.EmptyBorder;
10
11 import org.simantics.ui.colors.Colors;
12
13 public class SheetBorder extends EmptyBorder
14 {
15         private static final long serialVersionUID = 1L;
16         protected boolean bottomColor;
17         protected boolean rightColor;
18         
19         final Color NONE = Colors.awt(Colors.rgb(0.9,0.9,0.9));
20         
21
22
23     /**
24      * Creates a matte border with the specified insets and color.
25      * @param top the top inset of the border
26      * @param left the left inset of the border
27      * @param bottom the bottom inset of the border
28      * @param right the right inset of the border
29      * @param matteColor the color rendered for the border
30      */
31     public SheetBorder(int top, int left, int bottom, int right, boolean bottomColor, boolean rightColor)   {
32         super(top, left, bottom, right);
33         this.bottomColor = bottomColor;
34         this.rightColor = rightColor;
35     }
36
37     /**
38      * Paints the matte border.
39      */
40     public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
41         
42         Insets insets = getBorderInsets(c);
43         Color oldColor = g.getColor();
44         g.translate(x, y);
45
46         boolean same = bottomColor == rightColor;
47         
48         if(same) {
49                 
50                 g.setColor(bottomColor ? Color.BLACK : NONE);
51                 g.fillRect(0, height - insets.bottom, 2 + width - insets.left, insets.bottom);
52                 g.fillRect(width - insets.right, 0, insets.right, height - insets.bottom + 2);
53                 
54         } else {
55         
56                 // Not the same color - paint black on top
57
58                 if(bottomColor) {
59                         // Black bottom - no right
60                         g.setColor(NONE);
61                         g.fillRect(width - insets.right, 0, insets.right, height - insets.bottom + 2);
62                         g.setColor(Color.BLACK);
63                         g.fillRect(0, height - insets.bottom, 2 + width - insets.left, insets.bottom);
64                 } else {
65                         // Black right - no bottom
66                         g.setColor(NONE);
67                         g.fillRect(0, height - insets.bottom, 2 + width - insets.left, insets.bottom);
68                         g.setColor(Color.BLACK);
69                         g.fillRect(width - insets.right, 0, insets.right, height - insets.bottom + 2);
70                 }
71         
72         }
73         
74         g.translate(-x, -y);
75         g.setColor(oldColor);
76
77     }
78
79     /**
80      * Reinitialize the insets parameter with this Border's current Insets.
81      * @param c the component for which this border insets value applies
82      * @param insets the object to be reinitialized
83      * @since 1.3
84      */
85     public Insets getBorderInsets(Component c, Insets insets) {
86         return computeInsets(insets);
87     }
88
89     /**
90      * Returns the insets of the border.
91      * @since 1.3
92      */
93     public Insets getBorderInsets() {
94         return computeInsets(new Insets(0,0,0,0));
95     }
96
97     /* should be protected once api changes area allowed */
98     private Insets computeInsets(Insets insets) {
99         insets.left = left;
100         insets.top = top;
101         insets.right = right;
102         insets.bottom = bottom;
103         return insets;
104     }
105
106     /**
107      * Returns the color used for tiling the border or null
108      * if a tile icon is being used.
109      * @since 1.3
110      */
111     public Color getMatteColor() {
112         return NONE;
113     }
114
115    /**
116      * Returns the icon used for tiling the border or null
117      * if a solid color is being used.
118      * @since 1.3
119      */
120     public Icon getTileIcon() {
121         return null;
122     }
123
124     /**
125      * Returns whether or not the border is opaque.
126      */
127     public boolean isBorderOpaque() {
128         // If a tileIcon is set, then it may contain transparent bits
129         return true;
130     }
131
132 }