01: /*
02: * Copyright (c) 2004 JETA Software, Inc. All rights reserved.
03: *
04: * Redistribution and use in source and binary forms, with or without modification,
05: * are permitted provided that the following conditions are met:
06: *
07: * o Redistributions of source code must retain the above copyright notice,
08: * this list of conditions and the following disclaimer.
09: *
10: * o Redistributions in binary form must reproduce the above copyright notice,
11: * this list of conditions and the following disclaimer in the documentation
12: * and/or other materials provided with the distribution.
13: *
14: * o Neither the name of JETA Software nor the names of its contributors may
15: * be used to endorse or promote products derived from this software without
16: * specific prior written permission.
17: *
18: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21: * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22: * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23: * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26: * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28: */
29:
30: package com.jeta.forms.components.line;
31:
32: import java.awt.Color;
33: import java.awt.Graphics;
34: import java.awt.Graphics2D;
35: import java.awt.Insets;
36: import java.awt.Stroke;
37: import java.util.Iterator;
38:
39: import com.jeta.forms.store.properties.LineProperty;
40:
41: public class VerticalLineComponent extends LineComponent {
42: public static final int CENTER = 0;
43: public static final int LEFT = 1;
44: public static final int RIGHT = 2;
45:
46: /**
47: * @return true if this line is oriented horizontally
48: */
49: public boolean isHorizontal() {
50: return false;
51: }
52:
53: /**
54: * Paints the line
55: */
56: public void paintComponent(Graphics g) {
57: int x1 = 0;
58: int y1 = 0, y2 = 0;
59: Insets insets = getInsets();
60:
61: y1 = insets.top;
62: int height = getHeight() - (insets.top + insets.bottom);
63: if (height < 0)
64: return;
65:
66: y2 = height + y1;
67:
68: int total_thickness = getThickness();
69: if (getPosition() == CENTER) {
70: x1 = (getWidth() - total_thickness) / 2;
71: } else if (getPosition() == LEFT) {
72: // x1 = total_thickness/2;
73:
74: } else {
75: x1 = getWidth() - total_thickness;
76: }
77:
78: Graphics2D g2 = (Graphics2D) g;
79: Stroke old_stroke = g2.getStroke();
80: Color old_color = g2.getColor();
81: Iterator iter = iterator();
82: while (iter.hasNext()) {
83: LineProperty prop = (LineProperty) iter.next();
84: Stroke s = prop.getStroke();
85: g2.setStroke(s);
86: g2.setColor(prop.getColor());
87:
88: int x = x1 + prop.getThickness() / 2;
89: g2.drawLine(x, y1, x, y2);
90:
91: x1 = x1 + prop.getThickness();
92: }
93:
94: g2.setColor(old_color);
95: g2.setStroke(old_stroke);
96: }
97:
98: }
|