/* Copyright 2000 Charles G. Wright * This software may be distributed under the terms of the * GNU General Public License. * * $Id: SOLsurfaceControl.java,v 1.1 2000-06-15 10:15:05-05 chuckles Exp chuckles $ */ import java.math.*; import java.awt.*; import java.awt.event.*; import java.util.*; /** This class implements a control panel to control a SOLsurface object. * The control panel contains fields for specifying the surface's name, its * area, and the ground reflectance associated with it. The SOLsurfaceControl * object refers to a single SOLsurface object, which can either be created * when creating the control object, or created first and passed to the * constructor. */ public class SOLsurfaceControl extends Panel implements ActionListener, Observer { TextField tf0; InputField p1; InputField p2; private SOLsurface surf; private CWObservable obs; private SimBase top; private SOLmonitorPanel surfmon; // private SOLsurfaceMonitor surfmon; private String name; private TMYdata tmystuff; /** Create a SOLsurfaceControl object, given a SOLorientation, an area, * a ground reflectance, and a name. This first creates a SOLsurface object, * then the panel that controls it. */ public SOLsurfaceControl(TMYdata tmystuff, SOLorientation orientation, double area, double rho, String name, SimBase top){ this.obs = top.getObservable(); this.top = top; this.tmystuff = tmystuff; this.name = name; surf = new SOLsurface(tmystuff, orientation, area, rho, name); System.out.println("Built new surface with Area = " + surf.area); buildit(); } /** create the user interface */ private void buildit(){ // make a layout manager for the individual panels FlowLayout fl = new FlowLayout(FlowLayout.LEFT, 2, 2); GridBagLayout main_layout = new GridBagLayout(); setLayout(main_layout); // Line up elements along a vertical line. // Fill horizontal space. // Use minimal vertical space for each element // (except last). GridBagConstraints c = new GridBagConstraints(); c.gridy = GridBagConstraints.RELATIVE; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; c.weighty = 0.0; c.anchor = GridBagConstraints.NORTHWEST; c.insets = new Insets(3,3,3,3); // Surface name Panel p0 = new Panel(fl); p0.add(new Label("Surface:")); tf0 = new TextField(10); tf0.addActionListener(this); tf0.setText(surf.name); p0.add(tf0); // Surface area p1 = new InputField(UnitConverter.AREA, 1.0, 0.1); p1.addActionListener(this); // Ground reflectance for this surface p2 = new InputField(UnitConverter.NOTHING, 0.15, 0.01); p2.setNameText("Ground Reflectance"); p2.addActionListener(this); Panel p3 = new Panel(); main_layout.setConstraints(p0, c); add(p0); main_layout.setConstraints(p1, c); add(p1); main_layout.setConstraints(p2, c); add(p2); c.weighty = 1.0; main_layout.setConstraints(p3, c); add(p3); // Create and register a SOLsurfaceMonitor object // to display statistics. int[] monitor_indices = {SOLsurface.DIRECT_RADIATION, SOLsurface.DIFFUSE_RADIATION, SOLsurface.GROUND_REFLECTED_RADIATION, SOLsurface.TOTAL_RADIATION, SOLsurface.TOTAL_RADIATION}; String[] monitor_labels = {"direct", "diffuse", "ground", "total", "total avg"}; String[] monitor_labels1 = {"(Kwh/m2)", "(Kwh/m2)","(Kwh/m2)","(Kwh/m2)", "(Kwh/m2 day)"}; String[] monitor_labels1_ip = {"(BTU/ft2)", "(BTU/ft2)","(BTU/ft2)","(BTU/ft)", "(BTU/ft2 day)"}; double[] divisors = {1000.0, 1000.0, 1000.0, 1000.0, 1000.0}; double[] divisors_ip = {1.0, 1.0, 1.0, 1.0, 1.0}; int[] types = {SOLmonitorPanel.TOTAL, SOLmonitorPanel.TOTAL, SOLmonitorPanel.TOTAL, SOLmonitorPanel.TOTAL, SOLmonitorPanel.DAILY_AVERAGE}; //surfmon = new SOLsurfaceMonitor(surf); surfmon = new SOLmonitorPanel(surf, monitor_indices, monitor_labels, monitor_labels1, monitor_labels1_ip, divisors, divisors_ip, types, "Incident Radiation Totals for " + name); top.getOutputPanel().addOutputPanel(surfmon, name); } public void paint(Graphics g){ setForeground(Color.black); Dimension d = getSize(); g.drawRect(0, 0, d.width - 1, d.height - 1); } /** To implement the Observer interface.*/ public void update(Observable obs, Object arg){ System.out.println("SOLSurfaceControl observer interface..."); surfmon.update(); } /** Here is where we come when the enter key is pressed in the text field. */ public void actionPerformed(ActionEvent e){ Object source = e.getSource(); if (source == tf0) { // Name has changed. Get/set new value. surf.name = tf0.getText(); } else { if (source == p1) { surf.area = p1.getValue(); System.out.println("Setting surface area to " + surf.area); } else if (source == p2){ // rho has changed. Get & set the new value. surf.rho = p2.getValue(); } obs.setChanged(); obs.notifyObservers(); } surfmon.update(); } } /* end of class */