/* Copyright 2000 Charles G. Wright * This software may be distributed under the terms of the * GNU General Public License. * * $Id: SOLwindowControl.java,v 1.1 2000-06-15 10:15:06-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 SOLwindow object. * It is similar to the SOLsurfaceControl object, so it * contains fields for specifying the surface's name, its * area, and the ground reflectance associated with it. * It also contains fields for specifying the window's U value, solar heat gain * coefficient, and the temperature inside the window. * The SOLwindowControl * object refers to a single SOLwindow object, which can either be created * when creating the control object, or created first and passed to the * constructor. */ public class SOLwindowControl extends Panel implements ActionListener, Observer { TextField tf0; // name InputField p1; // area InputField p2; // ground reflectance InputField p3; // uvalue InputField p4; // shgc //InputField p5; // indoor temp private SOLwindow surf; private CWObservable obs; private SimBase top; private GRAoutput output_panel; private String name; private SOLmonitorPanel surfmon; private SOLmonitorPanel surfmon1; private SOLmonitorPanel surfmon2; private TMYdata tmystuff; /** Create a SOLwindowControl object, given a SOLorientation, an area, * a ground reflectance, a and a name. This first creates a SOLsurface object, * then the panel that controls it. */ public SOLwindowControl(TMYdata tmystuff, SOLorientation orientation, double area, double rho, double uvalue, double shgc, double indoor_temp, String name, SimBase top){ this.obs = top.getObservable(); this.top = top; this.name = name; this.tmystuff = tmystuff; surf = new SOLwindow(tmystuff, orientation, area, rho, uvalue, shgc, top.getHVAC(), name); System.out.println("Built new window with Area = " + surf.area); buildit(); } /** Constructor - given an existing SOLsurface object, create a control * panel for it. */ public SOLwindowControl(SOLwindow win, SimBase top){ this.obs = top.getObservable(); this.top = top; this.surf = win; System.out.println("Built new surface control 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("Window:")); tf0 = new TextField(10); // following means that this class provides the actionPerformed() method, which will handle // processing of text box changes. 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); // U Value p3 = new InputField(UnitConverter.UVALUE, 5.67, 0.1); p3.addActionListener(this); // Solar Heat Gain Coefficient p4 = new InputField(UnitConverter.NOTHING, 0.8, 0.1); p4.setNameText("SHGC"); p4.addActionListener(this); // Indoor temperature //p5 = new InputField(UnitConverter.TEMPERATURE, 25.0, 1.0); //p5.addActionListener(this); Panel plast = new Panel(); main_layout.setConstraints(p0, c); add(p0); main_layout.setConstraints(p1, c); add(p1); main_layout.setConstraints(p2, c); add(p2); main_layout.setConstraints(p3, c); add(p3); main_layout.setConstraints(p4, c); add(p4); //main_layout.setConstraints(p5, c); //add(p5); c.weighty = 1.0; main_layout.setConstraints(p3, c); add(plast); // Create and register a SOLmonitorPanel object // to display statistics. int[] monitor_indices = {SOLwindow.DIRECT_GAIN, SOLwindow.DIFFUSE_GAIN, SOLwindow.GROUND_REFLECTED_GAIN, SOLwindow.TOTAL_RADIANT_GAIN, SOLwindow.CONDUCTIVE_GAIN, SOLwindow.TOTAL_GAIN}; String[] monitor_labels = {"direct", "diffuse", "ground", "total radiant", "conductive", "total"}; String[] monitor_labels1 = {"(Kwh/day)", "(Kwh/day)", "(Kwh/day)", "(Kwh/day)", "(Kwh/day)", "(Kwh/day)"}; String[] monitor_labels1_ip = {"(BTU/day)", "(BTU/day)", "(BTU/day)", "(BTU/day)", "(BTU/day)", "(BTU/day)"}; double[] divisors = {1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0}; double[] divisors_ip = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0}; int[] types = {SOLmonitorPanel.DAILY_AVERAGE, SOLmonitorPanel.DAILY_AVERAGE, SOLmonitorPanel.DAILY_AVERAGE, SOLmonitorPanel.DAILY_AVERAGE, SOLmonitorPanel.DAILY_AVERAGE, SOLmonitorPanel.DAILY_AVERAGE}; //surfmon = new SOLsurfaceMonitor(surf); surfmon = new SOLmonitorPanel(surf, monitor_indices, monitor_labels, monitor_labels1, monitor_labels1_ip, divisors, divisors_ip, types, "Heat Gain Totals for " + name); top.getOutputPanel().addOutputPanel(surfmon, name); // Create and register a second SOLmonitorPanel object // to display statistics about daily heat gains. int[] amonitor_indices = {SOLwindow.DIRECT_RADIATION, SOLwindow.DIFFUSE_RADIATION, SOLwindow.GROUND_REFLECTED_RADIATION, SOLwindow.TOTAL_RADIATION}; String[] amonitor_labels = {"direct", "diffuse", "ground", "total"}; String[] amonitor_labels1 = {"(kwh/day)", "(kwh/day)", "(kwh/day)", "(kwh/day)"}; String[] amonitor_labels1_ip = {"(BTU/day)", "(BTU/day)", "(BTU/day)", "(BTU/day)"}; double[] adivisors = {1000.0, 1000.0, 1000.0, 1000.0}; double[] adivisors_ip = {1.0, 1.0, 1.0, 1.0}; int[] atypes = {SOLmonitorPanel.DAILY_AVERAGE, SOLmonitorPanel.DAILY_AVERAGE, SOLmonitorPanel.DAILY_AVERAGE, SOLmonitorPanel.DAILY_AVERAGE}; surfmon1 = new SOLmonitorPanel(surf, amonitor_indices, amonitor_labels, amonitor_labels1, amonitor_labels1_ip, adivisors, adivisors_ip, atypes, "Daily Incident Radiation averages for " + name); top.getOutputPanel().addOutputPanel(surfmon1, name); // Create and register a third SOLmonitorPanel object // to display statistics about monthly energy cost. int[] bmonitor_indices = {SOLwindow.DIRECT_RADIATION_COST, SOLwindow.DIFFUSE_RADIATION_COST, SOLwindow.GROUND_REFLECTED_RADIATION_COST, SOLwindow.TOTAL_RADIATION_COST, SOLwindow.CONDUCTIVE_COST, SOLwindow.TOTAL_COST}; String[] bmonitor_labels = {"direct", "diffuse", "ground", "total rad", "conductive", "total"}; String[] bmonitor_labels1 = {"($)", "($)", "($)", "($)", "($)", "($)"}; String[] bmonitor_labels1_ip = {"($)", "($)", "($)", "($)", "($)", "($)"}; double[] bdivisors = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0}; double[] bdivisors_ip = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0}; int[] btypes = {SOLmonitorPanel.TOTAL, SOLmonitorPanel.TOTAL, SOLmonitorPanel.TOTAL, SOLmonitorPanel.TOTAL, SOLmonitorPanel.TOTAL, SOLmonitorPanel.TOTAL}; surfmon2 = new SOLmonitorPanel(surf, bmonitor_indices, bmonitor_labels, bmonitor_labels1, bmonitor_labels1_ip, bdivisors, bdivisors_ip, btypes, "HVAC Costs for " + name); top.getOutputPanel().addOutputPanel(surfmon2, 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(); surfmon1.update(); surfmon2.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(); //System.out.println(source); if (source == tf0) { // Name has changed. Get/set new value. surf.name = tf0.getText(); } else { if (source == p1) { // area has changed. Get & set the new value. surf.area = p1.getValue(); } else if (source == p2){ // rho has changed. Get & set the new value. surf.rho = p2.getValue(); } else if (source == p3){ // U-value has changed. Get & set the new value. surf.uvalue = p3.getValue(); } else if (source == p4){ // shgc has changed. Get & set the new value. surf.shgc = p4.getValue(); } } obs.setChanged(); obs.notifyObservers(); surfmon.update(); surfmon1.update(); surfmon2.update(); } } /* end of class */