001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: TwoColoredLineBorder.java,v 1.7 2005/12/04 13:46:05 jesper Exp $
023: package net.infonode.tabbedpanel.internal;
024:
025: import net.infonode.gui.GraphicsUtil;
026: import net.infonode.gui.colorprovider.ColorProvider;
027: import net.infonode.gui.shaped.border.RoundedCornerBorder;
028: import net.infonode.tabbedpanel.TabbedPanel;
029: import net.infonode.tabbedpanel.TabbedUtils;
030: import net.infonode.tabbedpanel.titledtab.TitledTab;
031: import net.infonode.util.Direction;
032:
033: import java.awt.*;
034:
035: /**
036: * TwoColoredLineBorder draws a 1 pixel wide line. The border can have
037: * one color for the top and left line and another color for the bottom
038: * and right line.
039: *
040: * @author $Author: jesper $
041: * @version $Revision: 1.7 $
042: * @see TitledTab
043: * @see TabbedPanel
044: * @since ITP 1.2.0
045: */
046: public class TwoColoredLineBorder extends RoundedCornerBorder {
047: private static final long serialVersionUID = 1;
048:
049: private ColorProvider topLeftColor;
050: private ColorProvider bottomRightColor;
051: private boolean roundCorners;
052: private boolean open;
053:
054: /**
055: * Constructs a TwoColoredLineBorder
056: *
057: * @param topLeftColor the colorprovider for the top and left lines
058: * @param bottomRightColor the colorprovider for the bottom and right lines
059: * @param roundCorners true for round corners on the side facing away from the tab area
060: * @param open true for no border on the side towards the tab area
061: */
062: public TwoColoredLineBorder(ColorProvider topLeftColor,
063: ColorProvider bottomRightColor, boolean roundCorners,
064: boolean open) {
065: super (topLeftColor, null, roundCorners ? 2 : 0,
066: roundCorners ? 2 : 0, roundCorners && !open ? 2 : 0,
067: roundCorners && !open ? 2 : 0, true, true, !open, true);
068: this .topLeftColor = topLeftColor;
069: this .bottomRightColor = bottomRightColor;
070: this .roundCorners = roundCorners;
071: this .open = open;
072: }
073:
074: protected void paintPolygon(Component c, Graphics2D g,
075: Polygon polygon, int width, int height) {
076: TabbedPanel tp = TabbedUtils.getParentTabbedPanel(c);
077: if (tp != null) {
078: Direction d = tp.getProperties().getTabAreaOrientation();
079:
080: int i = 0;
081:
082: Color c1 = topLeftColor.getColor();
083: Color c2 = bottomRightColor.getColor();
084:
085: if (d == Direction.UP) {
086: g.setColor(c1);
087: while (i < (roundCorners ? 3 : 1)) {
088: GraphicsUtil.drawOptimizedLine(g,
089: polygon.xpoints[i], polygon.ypoints[i],
090: polygon.xpoints[i + 1],
091: polygon.ypoints[i + 1]);
092: i++;
093: }
094:
095: g.setColor(c2);
096: while (i < polygon.npoints - 1) {
097: GraphicsUtil.drawOptimizedLine(g,
098: polygon.xpoints[i], polygon.ypoints[i],
099: polygon.xpoints[i + 1],
100: polygon.ypoints[i + 1]);
101: i++;
102: }
103:
104: g.setColor(c1);
105: GraphicsUtil.drawOptimizedLine(g, polygon.xpoints[i],
106: polygon.ypoints[i], polygon.xpoints[0],
107: polygon.ypoints[0]);
108:
109: } else if (d == Direction.RIGHT) {
110: g.setColor(c2);
111: while (i < polygon.npoints
112: - (open ? 2 : roundCorners ? 3 : 2)) {
113: GraphicsUtil.drawOptimizedLine(g,
114: polygon.xpoints[i], polygon.ypoints[i],
115: polygon.xpoints[i + 1],
116: polygon.ypoints[i + 1]);
117: i++;
118: }
119:
120: g.setColor(c1);
121: for (int k = i - 1; k < polygon.npoints - 2; k++) {
122: GraphicsUtil.drawOptimizedLine(g,
123: polygon.xpoints[i], polygon.ypoints[i],
124: polygon.xpoints[i + 1],
125: polygon.ypoints[i + 1]);
126: i++;
127: }
128: GraphicsUtil.drawOptimizedLine(g, polygon.xpoints[i],
129: polygon.ypoints[i], polygon.xpoints[0],
130: polygon.ypoints[0]);
131:
132: } else if (d == Direction.DOWN) {
133: g.setColor(c2);
134: while (i < (roundCorners ? 5 : 2)) {
135: GraphicsUtil.drawOptimizedLine(g,
136: polygon.xpoints[i], polygon.ypoints[i],
137: polygon.xpoints[i + 1],
138: polygon.ypoints[i + 1]);
139: i++;
140: }
141:
142: g.setColor(c1);
143: while (i < polygon.npoints - 1) {
144: GraphicsUtil.drawOptimizedLine(g,
145: polygon.xpoints[i], polygon.ypoints[i],
146: polygon.xpoints[i + 1],
147: polygon.ypoints[i + 1]);
148: i++;
149: }
150:
151: GraphicsUtil.drawOptimizedLine(g, polygon.xpoints[i],
152: polygon.ypoints[i], polygon.xpoints[0],
153: polygon.ypoints[0]);
154: } else {
155: g.setColor(c1);
156: while (i < (roundCorners ? 3 : 1)) {
157: GraphicsUtil.drawOptimizedLine(g,
158: polygon.xpoints[i], polygon.ypoints[i],
159: polygon.xpoints[i + 1],
160: polygon.ypoints[i + 1]);
161: i++;
162: }
163:
164: g.setColor(c2);
165: while (i < polygon.npoints - 1) {
166: GraphicsUtil.drawOptimizedLine(g,
167: polygon.xpoints[i], polygon.ypoints[i],
168: polygon.xpoints[i + 1],
169: polygon.ypoints[i + 1]);
170: i++;
171: }
172:
173: g.setColor(c1);
174:
175: GraphicsUtil.drawOptimizedLine(g, polygon.xpoints[i],
176: polygon.ypoints[i], polygon.xpoints[0],
177: polygon.ypoints[0]);
178: }
179: }
180: }
181: }
|