/* Copyright 2000 Charles G. Wright * This software may be distributed under the terms of the * GNU General Public License. * * $Id: SOLmonitorPanel.java,v 1.1 2000-06-15 10:15:02-05 chuckles Exp chuckles $ */ import java.math.*; import java.awt.*; import java.awt.event.*; import java.text.*; import java.util.*; /**

This class implements a generic monitor panel for a CWmonitorable. * It displays in tabular form monthly statistics for a selected * subset of the monitorable values in the CWmonitorable. *

As it stands, it cannot display values from multiple * CWmonitorable objects. */ public class SOLmonitorPanel extends Panel implements Observer{ // ultimately, these don't belong here, but for now... public static double hdd_base = 20.0; public static double cdd_base = 26.0; public static final int TOTAL = 1; public static final int DAILY_AVERAGE = 2; public static final int AVERAGE = 3; public static final int HDD = 4; public static final int CDD = 5; // Holds all of the data values. private Label[][] lvalues; private Label[] unit_labels; private Panel[] columns; private UnitConverter[] unit_converters; // The element that we are going to monitor: private CWmonitorable element; // The indices that are to be monitored. private int[] value_indices; // Strings to use as column headers. private String[] headers; private String[] headers1; private String[] headers1_ip; private double[] divisors; private double[] divisors_ip; private int[] types; private int num_columns; /**

Create a SOLmonitorPanel object, given

*

For example: new SOLmonitorPanel(window1, {SOLsurface.DIRECT_RADIATION, * SOLSurface.TOTAL_RADIATION}, {"Direct", "Total"}). */ public SOLmonitorPanel(CWmonitorable element, int[] value_indices, String[] headers, String[] headers1, String[] headers1_ip, double[] divisors, double[] divisors_ip, int[] types, String title){ Panel output_panel = new Panel(); Panel title_panel = new Panel(); Label title_label = new Label(title); title_panel.add(title_label); int i; int col; int dcol; this.element = element; this.value_indices = new int[value_indices.length]; for (i = 0; i < value_indices.length; i++) this.value_indices[i] = value_indices[i]; this.headers = headers; this.headers1 = headers1; this.headers1_ip = headers1_ip; this.divisors = divisors; this.divisors_ip = divisors_ip; this.types = new int[types.length]; for (i = 0; i < types.length; i++) this.types[i] = types[i]; GridLayout gl = new GridLayout(15, 1); num_columns = value_indices.length; unit_labels = new Label[num_columns]; lvalues = new Label[13][num_columns]; Panel label_column = new Panel(gl); columns = new Panel[num_columns]; unit_converters = new UnitConverter[num_columns]; // left column...month labels label_column.add(new Label("Month:")); label_column.add(new Label("")); for (i = 0; i < 12; i++){ label_column.add(new Label(TMYdata.MONTHS[i])); } label_column.add(new Label("Year:")); output_panel.add(label_column); // Create the panels to hold the columns of data for (col = 0; col < num_columns; col++){ columns[col] = new Panel(gl); // Add Column labels unit_labels[col] = new Label(headers1[col]); columns[col].add(new Label(headers[col])); columns[col].add(unit_labels[col]); // one entry for each month, plus one for yearly total for (i = 0; i < 13; i++){ columns[col].add(lvalues[i][col] = new Label(" ------.-")); } unit_converters[col] = new UnitConverter(element.getFieldTypes()[value_indices[col]]); // see that unit changes update this monitor. unit_converters[col].addObserver(this); output_panel.add(columns[col]); // create a unit converter appropriate to this data. } //-------- top panel layout ----------- GridBagLayout top_layout = new GridBagLayout(); setLayout(top_layout); GridBagConstraints ct = new GridBagConstraints(); ct.fill = GridBagConstraints.BOTH; ct.gridwidth = GridBagConstraints.REMAINDER; ct.weightx = 1.0; ct.weighty = 0.0; ct.gridx = 0; ct.insets = new Insets(3,3,3,3); top_layout.setConstraints(title_panel, ct); GridBagConstraints cb = new GridBagConstraints(); ct.weighty = 1.0; top_layout.setConstraints(output_panel, ct); add(title_panel); add(output_panel); update(); } /* end of buildit() */ /** Implements the Observer interface. */ public void update(Observable obs, Object parent){ update(); } /** Method called to update the monitor display. Accesses * the surface object associated with this monitor, and * calculates totals. */ public void update(){ int hour; int day; int month; double val; int col; // represents data column number DecimalFormat fmt = new DecimalFormat("#,##0.#"); double monthly_total = 0.0; double divisor; for (col = 0; col < num_columns; col++){ if (UnitConverter.getUnitSystem() == UnitConverter.METRIC){ unit_labels[col].setText(headers1[col]); divisor = divisors[col]; } else { unit_labels[col].setText(headers1_ip[col]); divisor = divisors_ip[col]; } double yearly_total = 0.0; int value_index = value_indices[col]; // System.out.println("value_index: " + value_index); for(month = 0; month < 12; month++){ monthly_total = 0.0; for( day = 0; day < TMYdata.MONTHLENGTH[month]; day++){ for(hour = 0; hour < 24; hour++){ val = element.getValue(month, day, hour, value_index); monthly_total += val; if (types[col] == AVERAGE){ monthly_total /= 24.0; } } } if (types[col] == DAILY_AVERAGE || types[col] == AVERAGE){ monthly_total /= TMYdata.MONTHLENGTH[month]; } val = unit_converters[col].getConvertedValue(monthly_total); //System.out.println(monthly_total + " " + val + " " + // unit_converters[col].getConversionFactor() + " " + // unit_converters[col].getUnitType()); lvalues[month][col].setText(fmt.format(val / divisor)); yearly_total += monthly_total; } // end of month loop if (types[col] == DAILY_AVERAGE || types[col] == AVERAGE){ yearly_total /= 12.0; } lvalues[12][col].setText(fmt.format (unit_converters[col].getConvertedValue (yearly_total/divisor))); } // end of column loop } // end of update() } /* end of class */