/Users/lyon/j4p/src/ip/gui/frames/IconFrame.java

1    package ip.gui.frames; 
2     
3    import gui.Icons; 
4    import ip.graphics.Globals; 
5    import ip.gui.IconComponent; 
6     
7    import java.awt.*; 
8    import java.awt.event.ActionEvent; 
9    import java.awt.event.ActionListener; 
10   import java.util.Vector; 
11    
12   public class IconFrame 
13           extends ClosableFrame implements ActionListener { 
14    
15       private Panel iconPanel = new Panel(new FlowLayout()); 
16    
17    
18       private IconComponent polygonIcon = 
19               getIconComponent(Icons.polygon); 
20       private IconComponent eraserIcon = 
21               getIconComponent(Icons.eraser); 
22       private IconComponent pencilIcon = 
23               getIconComponent(Icons.pencil); 
24       private IconComponent brushIcon = 
25               getIconComponent(Icons.brush); 
26       private IconComponent handIcon = 
27               getIconComponent(Icons.hand); 
28       private IconComponent magnifyingGlassIcon = 
29               getIconComponent(Icons.magnifyingGlass); 
30       private IconComponent marqeeIcon = 
31               getIconComponent(Icons.marqee); 
32       private IconComponent paintCanIcon = 
33               getIconComponent(Icons.paintCan); 
34       private IconComponent eyeDropperIcon = 
35               getIconComponent(Icons.eyeDropper); 
36       private IconComponent xImageIcon = 
37               getIconComponent(Icons.xImage); 
38       private IconComponent ovalIcon = 
39               getIconComponent(Icons.oval); 
40       private IconComponent arcIcon = 
41               getIconComponent(Icons.arc); 
42       private IconComponent arrowIcon = 
43               getIconComponent(Icons.arrow); 
44       private IconComponent circleIcon = 
45               getIconComponent(Icons.circle); 
46    
47       //IconComponent warpIcon = 
48       //      getIconComponent(warp); 
49    
50    
51       private Vector iconList = new Vector(); 
52    
53       private void addIcons() { 
54           addIcon(getEraserIcon(), getIconPanel()); 
55           addIcon(getPencilIcon(), getIconPanel()); 
56           addIcon(getBrushIcon(), getIconPanel()); 
57           addIcon(getMagnifyingGlassIcon(), getIconPanel()); 
58           addIcon(getEyeDropperIcon(), getIconPanel()); 
59           addIcon(getXImageIcon(), getIconPanel()); 
60           //addIcon(warpIcon,iconPanel); 
61    
62    
63    
64           //addIcon(polygonIcon,iconPanel); 
65           //addIcon(circleIcon,iconPanel); 
66           //addIcon(arrowIcon,iconPanel); 
67           //addIcon(arcIcon,iconPanel); 
68           //addIcon(ovalIcon,iconPanel); 
69           //addIcon(paintCanIcon,iconPanel); 
70           addIcon(getMarqeeIcon(), getIconPanel()); 
71           addIcon(getHandIcon(), getIconPanel()); 
72           add(getIconPanel()); 
73       } 
74    
75       public IconComponent getIconComponent(byte icon[][]) { 
76           IconComponent ic = new IconComponent(icon); 
77           return ic; 
78       } 
79    
80       public void addIcon(IconComponent ic, Container c) { 
81           ic.addActionListener(this); 
82           c.add(ic); 
83           getIconList().addElement(ic); 
84       } 
85    
86       public void deselectOtherIcons(IconComponent selectedIcon) { 
87           for (int i = 0; i < getIconList().size(); i++) { 
88               IconComponent ic = (IconComponent) getIconList().elementAt(i); 
89               ic.invert(ic.equals(selectedIcon)); 
90           } 
91       } 
92    
93       private Label width = new Label("W:0   "); 
94       private Label height = new Label("H:0   "); 
95       private Label red = new Label("R:0   "); 
96       private Label green = new Label("G:0   "); 
97       private Label blue = new Label("B:0   "); 
98       private Label xPosition = new Label("x:0   "); 
99       private Label yPosition = new Label("y:0   "); 
100   
101      private void addInfo() { 
102          Panel p = new Panel(new GridLayout(1, 2)); 
103          p.add(width); 
104          p.add(height); 
105          p.add(red); 
106          p.add(green); 
107          p.add(blue); 
108          p.add(getXPosition()); 
109          p.add(getYPosition()); 
110   
111          add(p, BorderLayout.CENTER); 
112   
113      } 
114   
115      public IconFrame() { 
116          super(Globals.title); 
117          setLayout(new GridLayout(0, 1)); 
118          addIcons(); 
119          addInfo(); 
120          pack(); 
121      } 
122   
123      public void setLabels(int w, int h, int r, int g, int b) { 
124          width.setText("W:" + w); 
125          height.setText("H:" + h); 
126          red.setText("R:" + r); 
127          green.setText("G:" + g); 
128          blue.setText("B:" + b); 
129          repaint(); 
130      } 
131   
132      public void setPosition(int x, int y) { 
133          getXPosition().setText("x:" + x); 
134          getYPosition().setText("y:" + y); 
135      } 
136   
137   
138      public static void main(String args[]) { 
139          System.out.println("Icon concepts!"); 
140          IconFrame iconFrame = new IconFrame(); 
141          iconFrame.setVisible(true); 
142      } 
143   
144      private IconComponent selectedIcon; 
145   
146      public IconComponent getSelectedIcon() { 
147          return selectedIcon; 
148      } 
149   
150      public void actionPerformed(ActionEvent e) { 
151          //System.out.println(e); 
152   
153          setSelectedIcon((IconComponent) e.getSource()); 
154          deselectOtherIcons(getSelectedIcon()); 
155      } 
156   
157      public Panel getIconPanel() { 
158          return iconPanel; 
159      } 
160   
161      public void setIconPanel(Panel iconPanel) { 
162          this.iconPanel = iconPanel; 
163      } 
164   
165      public IconComponent getPolygonIcon() { 
166          return polygonIcon; 
167      } 
168   
169      public void setPolygonIcon(IconComponent polygonIcon) { 
170          this.polygonIcon = polygonIcon; 
171      } 
172   
173      public IconComponent getEraserIcon() { 
174          return eraserIcon; 
175      } 
176   
177      public void setEraserIcon(IconComponent eraserIcon) { 
178          this.eraserIcon = eraserIcon; 
179      } 
180   
181      public IconComponent getPencilIcon() { 
182          return pencilIcon; 
183      } 
184   
185      public void setPencilIcon(IconComponent pencilIcon) { 
186          this.pencilIcon = pencilIcon; 
187      } 
188   
189      public IconComponent getBrushIcon() { 
190          return brushIcon; 
191      } 
192   
193      public void setBrushIcon(IconComponent brushIcon) { 
194          this.brushIcon = brushIcon; 
195      } 
196   
197      public IconComponent getHandIcon() { 
198          return handIcon; 
199      } 
200   
201      public void setHandIcon(IconComponent handIcon) { 
202          this.handIcon = handIcon; 
203      } 
204   
205      public IconComponent getMagnifyingGlassIcon() { 
206          return magnifyingGlassIcon; 
207      } 
208   
209      public void setMagnifyingGlassIcon(IconComponent magnifyingGlassIcon) { 
210          this.magnifyingGlassIcon = magnifyingGlassIcon; 
211      } 
212   
213      public IconComponent getMarqeeIcon() { 
214          return marqeeIcon; 
215      } 
216   
217      public void setMarqeeIcon(IconComponent marqeeIcon) { 
218          this.marqeeIcon = marqeeIcon; 
219      } 
220   
221      public IconComponent getPaintCanIcon() { 
222          return paintCanIcon; 
223      } 
224   
225      public void setPaintCanIcon(IconComponent paintCanIcon) { 
226          this.paintCanIcon = paintCanIcon; 
227      } 
228   
229      public IconComponent getEyeDropperIcon() { 
230          return eyeDropperIcon; 
231      } 
232   
233      public void setEyeDropperIcon(IconComponent eyeDropperIcon) { 
234          this.eyeDropperIcon = eyeDropperIcon; 
235      } 
236   
237      public IconComponent getXImageIcon() { 
238          return xImageIcon; 
239      } 
240   
241      public void setXImageIcon(IconComponent xImageIcon) { 
242          this.xImageIcon = xImageIcon; 
243      } 
244   
245      public IconComponent getOvalIcon() { 
246          return ovalIcon; 
247      } 
248   
249      public void setOvalIcon(IconComponent ovalIcon) { 
250          this.ovalIcon = ovalIcon; 
251      } 
252   
253      public IconComponent getArcIcon() { 
254          return arcIcon; 
255      } 
256   
257      public void setArcIcon(IconComponent arcIcon) { 
258          this.arcIcon = arcIcon; 
259      } 
260   
261      public IconComponent getArrowIcon() { 
262          return arrowIcon; 
263      } 
264   
265      public void setArrowIcon(IconComponent arrowIcon) { 
266          this.arrowIcon = arrowIcon; 
267      } 
268   
269      public IconComponent getCircleIcon() { 
270          return circleIcon; 
271      } 
272   
273      public void setCircleIcon(IconComponent circleIcon) { 
274          this.circleIcon = circleIcon; 
275      } 
276   
277      public Vector getIconList() { 
278          return iconList; 
279      } 
280   
281      public void setIconList(Vector iconList) { 
282          this.iconList = iconList; 
283      } 
284   
285   
286      public void setRed(Label red) { 
287          this.red = red; 
288      } 
289   
290      public void setGreen(Label green) { 
291          this.green = green; 
292      } 
293   
294      public void setBlue(Label blue) { 
295          this.blue = blue; 
296      } 
297   
298      public Label getXPosition() { 
299          return xPosition; 
300      } 
301   
302      public void setXPosition(Label xPosition) { 
303          this.xPosition = xPosition; 
304      } 
305   
306      public Label getYPosition() { 
307          return yPosition; 
308      } 
309   
310      public void setYPosition(Label yPosition) { 
311          this.yPosition = yPosition; 
312      } 
313   
314      public void setSelectedIcon(IconComponent selectedIcon) { 
315          this.selectedIcon = selectedIcon; 
316      } 
317   
318  } 
319   
320   
321