1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.cb.jset.client.ui;
21
22 import javax.swing.JPanel;
23 import javax.swing.BorderFactory;
24 import javax.swing.JComponent;
25 import javax.swing.JWindow;
26 import java.awt.FlowLayout;
27 import java.awt.Color;
28 import java.awt.Image;
29
30 import org.cb.jset.CardProperties;
31 import org.cb.jset.JSetCard;
32
33 /***
34 * A small class to help build a logo.
35 *
36 * Would be nice to have a way to close it...
37 * @author jerome@coffeebreaks.org - last modified by $LastChangedBy: jerome $
38 * @version $Id: JSetClientUI.java 85 2004-04-13 14:29:08Z jerome $
39 */
40 public class JSetLogo extends JWindow
41 {
42 private final JPanel _logoPanel = new JPanel();
43
44 /***
45 * Constructs a JSetLogo instance.
46 */
47 public JSetLogo()
48 {
49 init();
50 }
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 /***
96 * initialize the contents of the JWindow representing the logo.
97 */
98 private void init()
99 {
100
101 this.getContentPane().add(_logoPanel);
102 _logoPanel.setLayout(null);
103 this.pack();
104 this.setBounds(50, 50, 82, 108);
105
106 JPanel lPanel;
107 final int distanceFromCenter = 18;
108 final int centerX = 20;
109 final int centerY = 20;
110
111
112
113
114
115
116
117
118
119
120
121 {
122 final org.cb.jset.JSetCard card3 =
123 new JSetCard(new CardProperties((byte) 3, (byte) 3, (byte) 1, (byte) 3));
124 final int x = centerX;
125 final int y = centerY + distanceFromCenter;
126 lPanel = createCardPanel(card3, x, y);
127 _logoPanel.add(lPanel);
128 }
129 {
130 final org.cb.jset.JSetCard card1 =
131 new JSetCard(new CardProperties((byte) 1, (byte) 1, (byte) 1, (byte) 1));
132 final int x = (int) (centerX - distanceFromCenter * Math.sqrt(3) / 2);
133 final int y = (int) (centerY - distanceFromCenter / 2);
134 lPanel = createCardPanel(card1, x, y);
135 _logoPanel.add(lPanel);
136 }
137 {
138 final org.cb.jset.JSetCard card2 =
139 new JSetCard(new CardProperties((byte) 2, (byte) 2, (byte) 1, (byte) 2));
140 final int x = (int) (centerX + distanceFromCenter * Math.sqrt(3) / 2);
141 final int y = (int) (centerY - distanceFromCenter);
142 lPanel = createCardPanel(card2, x, y);
143 _logoPanel.add(lPanel);
144 }
145 }
146
147 /***
148 * Saves the logo in a file.
149 * Note: not implemented right now
150 *
151 * @param filePath the path where the image will be contained
152 * @todo implement the save image functionality. We probably need to specify image type (e.g. png)
153 */
154 void saveLogo(final String filePath)
155 {
156 Image image = this.createImage(this.getWidth(), this.getHeight());
157
158 }
159
160 /***
161 * Helper method to create a small panel containing the specified card, located
162 * at the specified coordinates.
163 * @param card1
164 * @param x
165 * @param y
166 * @return
167 */
168 private JPanel createCardPanel(final JSetCard card1, final int x, final int y)
169 {
170 JComponent lCard;
171 JPanel lPanel;
172 lCard = new JSetCardComponent(card1).getShape(0);
173 lCard.setSize(32, 52);
174 lCard.setPreferredSize(lCard.getSize());
175 lPanel = new JPanel();
176 lPanel.setLayout(new FlowLayout());
177 lPanel.setSize(42, 64);
178 lPanel.setBackground(Color.white);
179 lPanel.setPreferredSize(lPanel.getSize());
180 lPanel.add(lCard);
181 lPanel.setBounds(x, y, lPanel.getWidth(), lPanel.getHeight());
182 lPanel.setBorder(BorderFactory.createLineBorder(Color.black));
183 return lPanel;
184 }
185
186 /***
187 * Start and show the logo.
188 * @param args the arguments
189 */
190 public static void main(final String[] args)
191 {
192 final JSetLogo logo = new JSetLogo();
193 logo.show();
194 }
195 }