/* Copyright 2000 Charles G. Wright * This software may be distributed under the terms of the * GNU General Public License. * * $Id: SOLlocationControl.java,v 1.1 2000-06-15 10:15:01-05 chuckles Exp chuckles $ */ import java.awt.*; import java.awt.event.*; import java.math.*; import java.util.*; //--------------------------- SOLlocationControl ----------------------- /** This class provides a panel that displays pertinent information about * a SOLlocation object, including its name, latitude, longitude, and elevation. * It also provides a sub panel, managed by a CardLayout layout manager, in * which are displayed one or more SOLoientationControl objects. Also provded * are buttons to page through these SOLorientationControl panels, and to create * a new SOLorientationControl at this location. */ public class SOLlocationControl extends Panel implements ActionListener{ private Button bleft; private Button bright; private Button bnew; private int orientnum = 2; private Panel cp; private CardLayout cl; private SOLlocation loc; private Label label_name; private Label label_latitude; private Label label_longitude; private Label label_ele; private Label label_time_zone; private boolean have_loc = false; private GRAoutput output_panel; private SimBase top; private TMYdata tmystuff = null; //--------------- Constructors ----------------------------------------// /** Create a SOLlocationControl object, given a TMYdata object, which * also defines a location. */ public SOLlocationControl(TMYdata tmystuff, SimBase top){ this.top = top; this.output_panel = top.getOutputPanel(); loc = tmystuff.location; have_loc = true; buildit(); } /** Create a SOLlocationControl object, given a SOLlocation object, which * defines a location. */ public SOLlocationControl(SOLlocation location, SimBase top){ this.output_panel = top.getOutputPanel(); loc = location; have_loc = true; buildit(); } /** Constructor - if location doesn't exist already. */ public SOLlocationControl(SimBase top){ this.top = top; this.output_panel = top.getOutputPanel(); have_loc = false; buildit(); } // ------------------ Methods --------------------------------// /** create the user interface */ private void buildit(){ //System.out.println("building SOLlocationControl"); // Layout manager for horizontal panels: FlowLayout fl = new FlowLayout(FlowLayout.LEFT, 2, 2); GridBagLayout main_layout = new GridBagLayout(); setLayout(main_layout); GridBagConstraints c = new GridBagConstraints(); c.gridy = GridBagConstraints.RELATIVE; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; c.weighty = 0.0; c.insets = new Insets(3,3,3,3); c.anchor = GridBagConstraints.NORTHWEST; Panel p0 = new Panel(fl); p0.add(new Label("Location:")); p0.add(label_name = new Label()); main_layout.setConstraints(p0, c); add(p0); Panel p1 = new Panel(fl); p1.add(new Label("Latitude:")); p1.add(label_latitude = new Label()); main_layout.setConstraints(p1, c); add(p1); Panel p2 = new Panel(fl); p2.add(new Label("Longitude:")); p2.add(label_longitude = new Label()); main_layout.setConstraints(p2, c); add(p2); Panel p3 = new Panel(fl); p3.add(new Label("Elevation:")); p3.add(label_ele = new Label()); main_layout.setConstraints(p3, c); add(p3); Panel p4 = new Panel(fl); p4.add(new Label("Time Zone:")); p4.add(label_time_zone = new Label()); main_layout.setConstraints(p4, c); add(p4); updateLabels(); Panel p5 = new Panel(fl); bleft = new Button("<"); bleft.addActionListener(this); p5.add(bleft); bright = new Button(">"); bright.addActionListener(this); p5.add(bright); bnew = new Button("New"); bnew.addActionListener(this); p5.add(bnew); main_layout.setConstraints(p5, c); add(p5); //Panel p6 = new Panel(fl); //p6.add(new Label("Orientation:")); //main_layout.setConstraints(p6, c); //add(p6); // Panel p5 holds one or more surfaces, displaying 1 at a time. One is // created at start, more may be added later. cl = new CardLayout(); cp = new Panel(cl); //cp.setBackground(Color.pink); cp.setLayout(cl); // add an orientation (if location is defined) addOrientation(); // Arrange this one to take up the rest of the space. c.fill = GridBagConstraints.BOTH; c.weighty = 1.0; main_layout.setConstraints(cp, c); add(cp); } public void paint(Graphics g){ setForeground(Color.black); Dimension d = getSize(); g.drawRect(0, 0, d.width - 1, d.height - 1); } public void updateLabels(){ if (have_loc){ label_name.setText(loc.name); label_latitude.setText(Double.toString(loc.latitude)); label_longitude.setText(Double.toString(loc.longitude)); label_ele.setText(Double.toString(loc.elevation)); label_time_zone.setText(Integer.toString(loc.time_zone)); }else{ label_name.setText("NOT LOADED"); label_latitude.setText("--"); label_longitude.setText("--"); label_ele.setText("--"); label_time_zone.setText("--"); } } public void setLocation(SOLlocation location){ loc = location; have_loc = true; updateLabels(); } public void setTMY(TMYdata tmystuff){ this.tmystuff = tmystuff; } public void addOrientation(){ if (have_loc){ String orientation_name = "Orientation " + SOLorientationControl.nextInstanceNumber(); System.out.println("adding orientation"); SOLorientationControl orient = new SOLorientationControl(tmystuff, loc, 0.0, 90.0, orientation_name, top); cp.add(orient, orientation_name); cl.next(cp); } } /** Action processor. */ public void actionPerformed(ActionEvent e){ Object source = e.getSource(); if (source == bleft){ cl.previous(cp); } else if (source == bright){ cl.next(cp); } else if (source == bnew){ addOrientation(); } } } /* end of class */