1 package main;
2
3 import intellego.Intellego;
4 import util.*;
5 import interfaces.*;
6 import real.*;
7 import simworldobjects.*;
8 import main.*;
9 import NetBeansResources.*;
10
11 import java.awt.*;
12 import java.lang.*;
13 import javax.swing.plaf.basic.*;
14 import java.util.*;
15 import java.awt.event.*;
16 import javax.swing.*;
17 import java.io.*;
18
19
24 public class ColorOptionDialog extends JPanel implements ActionListener
25 {
26 private JLabel colorL,rL,bL,gL, previewL, title;
27 private JButton OK, cancel, tryW;
28 private JTextField rT, bT, gT;
29 private JTextArea preview;
30 private JComboBox colorSelection;
31 private Color desiredColor;
32 private String[] availableColors = {"Black","Blue","Cyan","Gray","Green","Magenta","Orange","Pink","Red","White","Yellow"};
33 private int index;
34 private SimDisplay display;
35 private SimWorld world;
36 private String objectName;
37 private SimGround simg;
38 private GridDisplay grid;
39 private SimUI sim;
40
41
45 public ColorOptionDialog(SimUI sim){
46 this.sim = sim;
47 this.setBackground(Color.darkGray);
48 }
49
50
51 public void createColorPopUp()
52 {
53 setSize(150,245);
54 setLocation(400,400);
55 setVisible(true);
56 this.setBorder(BasicBorders.getTextFieldBorder());
57 this.setLayout(new AbsoluteLayout());
58
59 title = new JLabel("Color Editor:");
60 previewL =new JLabel("Preview:");
61 colorL=new JLabel("Select Color:");
62 rL=new JLabel("R:");
63 bL=new JLabel("B:");
64 gL=new JLabel("G:");
65 previewL.setForeground(Color.lightGray);
67 colorL.setForeground(Color.lightGray);
68 title.setForeground(Color.yellow);
69 rL.setForeground(Color.red);
70 bL.setForeground(Color.blue);
71 gL.setForeground(Color.green);
72
73 preview = new JTextArea(3,5);
74 preview.setSize(20,20);
75 preview.setBackground(Color.white);
76 preview.setEditable(false);
77
78 rT=new JTextField(3);
79 bT=new JTextField(3);
80 gT=new JTextField(3);
81 rT.setEditable(false);
82 bT.setEditable(false);
83 gT.setEditable(false);
84 rT.setBackground(Color.yellow);
86 rT.setForeground(Color.darkGray);
87 bT.setBackground(Color.yellow);
88 bT.setForeground(Color.darkGray);
89 gT.setBackground(Color.yellow);
90 gT.setForeground(Color.darkGray);
91
92 colorSelection = new JComboBox(availableColors);
93 colorSelection.addActionListener(this);
94 colorSelection.setSelectedIndex(9);
95 colorSelection.setBackground(Color.yellow);
97 colorSelection.setForeground(Color.darkGray);
98
99 (OK=new JButton("OK")).addActionListener(this);
100 (tryW=new JButton("Try")).addActionListener(this);
101 (cancel=new JButton("Cancel")).addActionListener(this);
102 OK.setMargin(new Insets(1,1,1,1));
104 tryW.setMargin(new Insets(1,1,1,1));
105 cancel.setMargin(new Insets(1,1,1,1));
106
107 OK.setBackground(Color.yellow);
108 OK.setForeground(Color.darkGray);
109 tryW.setBackground(Color.yellow);
110 tryW.setForeground(Color.darkGray);
111 cancel.setBackground(Color.yellow);
112 cancel.setForeground(Color.darkGray);
113
114 this.add(title,new AbsoluteConstraints(6,7));
115 this.add(colorL,new AbsoluteConstraints(6,30));
116 this.add(colorSelection,new AbsoluteConstraints(50,50));
117 this.add(previewL,new AbsoluteConstraints(6,80));
118 this.add(preview,new AbsoluteConstraints(60,100));
119
120 this.add(rL,new AbsoluteConstraints(25,160));
121 this.add(rT,new AbsoluteConstraints(15,180));
122 this.add(gL,new AbsoluteConstraints(65,160));
123 this.add(gT,new AbsoluteConstraints(55,180));
124 this.add(bL,new AbsoluteConstraints(105,160));
125 this.add(bT,new AbsoluteConstraints(95,180));
126
127 this.add(OK,new AbsoluteConstraints(15,210));
128 this.add(tryW,new AbsoluteConstraints(45,210));
129 this.add(cancel,new AbsoluteConstraints(75,210));
130
131 this.setBackground(Color.darkGray);
132 this.show();
133 }
134
135
147 public void updateColorPopUp(String name, int index, SimDisplay d, SimWorld w, String objectName, SimGround simg, GridDisplay grid){
148
149 title.setText(name);
150 this.index = index;
151 this.display = d;
152 this.world = w;
153 this.objectName=objectName;
154 this.simg = simg;
155 this.grid = grid;
156
157 if(simg != null)deselectOtherObjects();
158 this.show();
159 }
160
161
164 private void deselectOtherObjects(){
165
166 LinkedList newList = world.getObjectList();
167
168 for(int i=0;i<newList.size();i++){
169 SimObject simObject2 = (SimObject)newList.get(i);
170 if(!this.simg.equals(simObject2)){
171 if(simObject2 instanceof SimGround){
172 ((SimGround)simObject2).setSelected(false);
173 ((SimGround)simObject2).setOutlineColor(Color.black);
174 display.repaint();
175 }
176 }
177 }
178 }
179
180
185 public void actionPerformed(ActionEvent e)
186 {
187 if (e.getSource()==OK || e.getSource()==tryW)
189 {
190 switch(index){
191 case 0: ((SimpleDisplay)display).setColorLibrary(this.objectName,this.desiredColor);
192 if(this.objectName.equals("road")){
193 for(int i=0;i<world.getObjectList().size();i++)
194 {
195 SimObject o=(SimObject)world.getObjectList().get(i);
196 if(o instanceof SimRoad)((SimRoad)o).setColor(this.desiredColor);
197
198 }
199 }
200
201 break;
202
203 case 1: ((BasicSimWorld)world).setWorldColor(this.desiredColor);
204 grid.updateWorldColor(this.desiredColor);
205 grid.repaint();
206 break;
207
208 case 2: simg.setColor(this.desiredColor);
209 if(e.getSource()==OK){
210 simg.setOutlineColor(Color.black);
211 simg.setSelected(false);
212 }
213
214 sim.pushUndoItem(sim.copyList((LinkedList)world.getObjectList()));
216
217 break;
218
219 case 6: grid.updateGridColor(this.desiredColor);
220
221 }
222 display.repaint();
223
224 if(e.getSource()==OK )this.hide();
225
226 }
227 else if(e.getSource()==colorSelection){
229 Color color= Color.white;
230 switch(colorSelection.getSelectedIndex()){
231
232 case 0: color = Color.black;
233 break;
234 case 1: color = Color.blue;
235 break;
236 case 2: color = Color.cyan;
237 break;
238 case 3: color = Color.gray;
239 break;
240 case 4: color = Color.green;
241 break;
242 case 5: color = Color.magenta;
243 break;
244 case 6: color = Color.orange;
245 break;
246 case 7: color = Color.pink;
247 break;
248 case 8: color = Color.red;
249 break;
250 case 9: color = Color.white;
251 break;
252 case 10: color = Color.yellow;
253 break;
254 }
255 this.preview.setBackground(color);
257
258 this.rT.setText(""+color.getRed());
260 this.bT.setText(""+color.getBlue());
261 this.gT.setText(""+color.getGreen());
262
263 this.desiredColor = color;
265
266 }
267
268 else
269 {
270 if(index == 2){
271 simg.setSelected(false);
272 simg.setOutlineColor(Color.black);
273 display.repaint();
274 }
275 this.hide();
276 }
277 try{sim.setSize(sim.getWidth(),sim.getHeight());}
278 catch(Exception e1){};
279 }
280 }