Source code: org/incenter/ngbclient/planetInfo.java
1
2 package org.incenter.ngbclient;
3 import org.incenter.ngbclient.*;
4 import org.incenter.gb.*;
5
6 import java.awt.*;
7 import java.awt.event.*;
8 import java.net.*;
9 import java.io.*;
10 import java.lang.*;
11 import java.util.*;
12
13
14 /**
15 *
16 * @author
17 * @version
18 */
19 public class planetInfo extends java.awt.Panel
20 implements MouseListener, MouseMotionListener, ActionListener, Observer, ItemListener
21 {
22
23 planetMap map;
24 planetOrbit orbit;
25 Checkbox fromSpace;
26 Panel pnl;
27 governor_remote gov;
28 race_remote race;
29 Point currentPoint;
30 sector_remote currentSector;
31 frmGetSector getSector;
32 ScrollPane cpanel;
33
34 /** Initializes the Form */
35 public planetInfo(planetArea p, planet_remote pl, objSocket sock) throws Exception {
36 try {
37 parent = p;
38 gov = parent.getClient().getGovernor();
39 race = gov.getRace();
40 socket = sock;
41 planet = pl;
42 if(planet == null) throw new Exception("NULL Planet");
43
44 initComponents();
45 //setSize(p.getSize());
46
47 // remove btnShips
48 panel1.remove(btnShips);
49
50 tareaInfo.setEditable(false);
51 tareaInfo.setColumns(30);
52 tareaInfo.setRows(20);
53 tareaInfo.setBackground(Color.black);
54 tareaInfo.setForeground(Color.white);
55
56 pnl = new Panel();
57
58 orbit = new planetOrbit(parent.getClient(), planet);
59
60 map = new planetMap(parent.getClient(), planet);
61 map.addMouseListener(this);
62 map.addMouseMotionListener(this);
63 pnl.add(map);
64
65 // create container for ships and such
66 int inum = planet.getFactories().size();
67 inum += planet.getShips().size();
68 cpanel = new ScrollPane();
69 cpanel.setSize(200, 350);
70
71 Panel cp = new Panel();
72 Panel lp = new Panel();
73 Panel lcp = new Panel();
74
75 lp.setLayout(new BorderLayout());
76 cp.setLayout(new GridLayout(10, 3));
77 lcp.setLayout(new GridLayout(3,1));
78
79 Label lbl = new Label("Factories and Ships");
80 lbl.setBackground(Color.black);
81 lbl.setForeground(Color.white);
82 lcp.add(lbl);
83
84 lbl = new Label("Click on one (if present)");
85 lbl.setBackground(Color.black);
86 lbl.setForeground(Color.white);
87 lcp.add(lbl);
88
89 lbl = new Label("for more Information");
90 lbl.setBackground(Color.black);
91 lbl.setForeground(Color.white);
92 lcp.add(lbl);
93 lp.add(lcp, "North");
94
95 addFactories(cp);
96 addShips(cp);
97 lp.add(cp, "Center");
98
99 cpanel.add(lp);
100 pnl.add(cpanel);
101
102 pnl.doLayout();
103
104 // setup get sector
105 getSector = new frmGetSector(parent.getClient(), map, new location(planet));
106
107 scrollCenter.add(pnl);
108
109 add(scrollCenter, "Center");
110
111 setBackground(Color.black);
112 reportBasic();
113 btnBasic.addActionListener(this);
114 btnModules.addActionListener(this);
115 btnMaterials.addActionListener(this);
116 btnShips.addActionListener(this);
117 btnFactories.addActionListener(this);
118
119 lblXY = new Label("X,Y:(0,0)");
120 panel1.add(lblXY,0);
121 fromSpace = new Checkbox("Orbit?", false);
122 fromSpace.addItemListener(this);
123 panel1.add(fromSpace, 0);
124
125 scrollCenter.setSize(400,400);
126 scrollCenter.doLayout();
127 doLayout();
128
129 } catch(Exception e) { throw new Exception("Error in planetInfo::" + e.toString()); }
130 }
131
132 public Point getCurrentPoint() { return currentPoint; }
133
134 public void getCurrentSector(sectorUser su) {
135 getSector.show(su);
136 }
137
138 /**
139 * call this before asking for a sector
140 */
141 public void initCurrentSector() { currentSector = null; }
142
143 /** This method is called from within the constructor to
144 * initialize the form.
145 * WARNING: Do NOT modify this code. The content of this method is
146 * always regenerated by the FormEditor.
147 */
148 private void initComponents () {//GEN-BEGIN:initComponents
149 setForeground (java.awt.Color.white);
150 setBackground (java.awt.Color.black);
151 setLayout (new java.awt.BorderLayout ());
152
153 lblPlanetName = new java.awt.Label ();
154 lblPlanetName.setText ("Planet Name");
155 lblPlanetName.setAlignment (java.awt.Label.CENTER);
156 add (lblPlanetName, "North");
157
158 panel1 = new java.awt.Panel ();
159 panel1.setLayout (new java.awt.FlowLayout ());
160
161 btnBasic = new java.awt.Button ();
162 btnBasic.setLabel ("Basic");
163 panel1.add (btnBasic);
164
165 btnModules = new java.awt.Button ();
166 btnModules.setLabel ("Modules");
167 panel1.add (btnModules);
168
169 btnMaterials = new java.awt.Button ();
170 btnMaterials.setLabel ("Materials");
171 panel1.add (btnMaterials);
172
173 btnShips = new java.awt.Button ();
174 btnShips.setLabel ("Ships");
175 panel1.add (btnShips);
176
177 btnFactories = new java.awt.Button ();
178 btnFactories.setLabel ("Factories");
179 panel1.add (btnFactories);
180
181 add (panel1, "South");
182
183 scrollCenter = new java.awt.ScrollPane ();
184
185 add (scrollCenter, "Center");
186
187 tareaInfo = new java.awt.TextArea ();
188 add (tareaInfo, "West");
189
190 }//GEN-END:initComponents
191
192
193 // Variables declaration - do not modify//GEN-BEGIN:variables
194 private java.awt.Label lblPlanetName;
195 private java.awt.Panel panel1;
196 private java.awt.Button btnBasic;
197 private java.awt.Button btnModules;
198 private java.awt.Button btnMaterials;
199 private java.awt.Button btnShips;
200 private java.awt.Button btnFactories;
201 private java.awt.ScrollPane scrollCenter;
202 private java.awt.TextArea tareaInfo;
203 // End of variables declaration//GEN-END:variables
204
205 objSocket socket;
206 planetArea parent;
207 planet_remote planet;
208 Label lblXY;
209 TextArea tareaInfo2;
210
211 private void reportBasic() {
212 String txt = null;
213 try {
214 lblPlanetName.setText("Planet:" + planet.getName() +
215 " Star:" + planet.getStar().getName());
216 tareaInfo.setText("Sectors(" + planet.getXsize().intValue() *
217 planet.getYsize().intValue() + ")\n\n" +
218 planet.getAtmosphere().print() + "\n" +
219 "Type: " + planet.getType().name() + "\n" +
220 "Resources: " + planet.getResources() +
221 " Waste: " + planet.getWaste() + "\n" +
222 "Total Population: " + planet.getTotalPopulation(null) + "\n" +
223 race.getName() + " Population: " + planet.getTotalPopulation(race));
224 } catch(Exception e) {
225 tareaInfo.setText("Bad Planet");
226 }
227 }
228
229 private void reportModules() {
230 String txt = null;
231 try {
232 txt = "Modules:\n";
233 Enumeration en = buildLists.getAvailableModuleTypes().elements();
234 while(en.hasMoreElements()) {
235 String type = (String)en.nextElement();
236 txt += "\nType:" + type + "\n";
237 Enumeration mn = buildLists.getAvailableModules(type).elements();
238 while(mn.hasMoreElements()) {
239 buildCore bl = (buildCore)mn.nextElement();
240 txt += bl.getName() + "\n";
241 }
242 }
243 tareaInfo.setText(txt);
244 } catch(Exception e) {
245 tareaInfo.setText("Error getting modules:" + e);
246 }
247 }
248
249
250 private void addShips(Panel p) {
251 try {
252 if(planet.getShips().size() == 0) {
253 return;
254 }
255 Enumeration en = planet.getShips().elements();
256 while(en.hasMoreElements()) {
257 ship_remote ship = (ship_remote)en.nextElement();
258 shipPanel sp = new shipPanel(parent.getClient(), ship);
259 p.add(sp);
260 }
261 } catch(Exception e) {
262 tareaInfo.setText("Error getting ships:" + e);
263 }
264 }
265
266 private void addFactories(Panel p) {
267 try {
268 if(planet.getFactories().size() == 0) {
269 return;
270 }
271 Enumeration en = planet.getFactories().elements();
272 while(en.hasMoreElements()) {
273 factory_remote fac = (factory_remote)en.nextElement();
274 factoryImage fi = new factoryImage(parent.getClient(), fac);
275 p.add(fi);
276 }
277 } catch(Exception e) {
278 tareaInfo.setText("Error getting factories:" + e);
279 }
280 }
281
282 public void update(Observable oB, Object arg) {;}
283
284 // mouse listener
285 public void mouseClicked(MouseEvent evt) {
286 ;
287 }
288
289 public void mouseEntered(MouseEvent evt) {
290 ;
291 }
292
293 public void mouseExited(MouseEvent evt) {
294 ;
295 }
296
297 public void mouseMoved(MouseEvent evt) {
298 int x = evt.getX(), y = evt.getY();
299 currentPoint = map.getPoint(x,y);
300 lblXY.setText("X,Y:(" + currentPoint.x + "," + currentPoint.y + ")");
301 }
302
303 public void mouseDragged(MouseEvent evt) {
304 ;
305 }
306
307 public void mousePressed(MouseEvent evt) {
308 try {
309 if((evt.getModifiers() & InputEvent.BUTTON2_MASK) != 0 ||
310 (evt.getModifiers() & InputEvent.BUTTON3_MASK) != 0) {
311 int x, y;
312 Component c = evt.getComponent();
313 Point p = c.getLocation();
314 x = evt.getX();
315 y = evt.getY();
316 c.add(parent.getPopup());
317 parent.getPopup().show(c, x, y);
318 }
319 if((evt.getModifiers() & InputEvent.BUTTON1_MASK) != 0) {
320 if(evt.getSource().equals(map)) {
321 int x = evt.getX(), y = evt.getY();
322 try {
323 sector_remote sec = map.getSector(x,y);
324 currentSector = sec;
325
326 tareaInfo.setText("Sector:(" + sec.getX() + "," + sec.getY() + ") " +
327 "Type: " + sec.getType().name() + "\n" +
328 "Efficiency: " + sec.getEff() + "\n" +
329 "Fertilization: " + sec.getFert() + "\n" +
330 "Resources: " + sec.getResources() + "\n" +
331 "Population: " + sec.getPopn() + "\n");
332
333 } catch(Exception e) {
334 parent.addMessage("planetInfo.mousePressed:" + e);
335 return;
336 }
337 }
338 }
339
340 } catch(Exception e) {
341 parent.addMessage("(Mouse)Error:" + e + ", " + evt);
342 }
343 }
344
345 public void mouseReleased(MouseEvent evt) {
346 ;
347 }
348 public void itemStateChanged(ItemEvent evt) {
349 if(fromSpace.getState()) {
350 // orbit is set
351 pnl.remove(map);
352 pnl.add(orbit, 0);
353 } else { // map
354 if(orbit != null)
355 pnl.remove(orbit);
356 pnl.add(map, 0);
357 }
358 doLayout();
359 }
360
361 public void actionPerformed(ActionEvent evt) {
362 String cmd = evt.getActionCommand();
363 if(cmd.equals("Basic"))
364 reportBasic();
365 else if(cmd.equals("Modules"))
366 reportModules();
367 else if(cmd.equals("Factories")) {
368
369 }
370 }
371
372 }
373