//
// EbmApplet.java nach ScrollPaneTest.java
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
// Test only
// import java.io.*;
// ToDo:
// - Umbenennung instanzobjekte, _ entfernen
// - zu ueppige imports begrenzen
/**
* Main Program for the EBM with Graphical User Interface
* implemented as Applet. It consists mainly of:
*
* - the GUI-components
*
- the model
*
- the set of parameters
*
*
*
* - The GUI-components:
*
* - parameter-area (top) comprising the input-fields for
* the parameters
*
- button panel (left) with the "compute"-button
*
- graph panel to display the function value (Temp.)
* on the y-axis against time on the y-axis.
*
- the description (right) of the variables shown
* (here Temp. only)
*
- the message panel for error messages and to display
* the cursor position in the graph-panel
*
*
*
- The parameters comprise:
*
* - the functional parameters of the model
*
- the initial values of the model
*
- the sector (x and y) to be shown in the graph
*
*
*
- The Model:
*
* - is initialze with the parameters
*
- is integrated over timesteps, when the paint-method of
* the graph-panel is called.
*
*
*
* Nearly the entire logic is set up in the init-method, which is
* called by the browser when used as an applet.
* A main-method (which calls the init-method) is include; it is
* called when EbmApplet is used as a stand-alone-application,
* e.g. when called as "java EbmApplet" from a console, where
* the java-Runtime-Environment is installed.
*
* Central strategy of the applet is, not to store the computed
* data over time for the display. This means, that the model has
* to be rerun, when the graph has been covered by another window.
* The forward-stepping iteration of the model is therefore called
* from the paint-method of the graph-panel.
*
*/
public class EbmApplet extends java.applet.Applet {
// Main Areas on the GUI:
private Panel paramArea = new Panel();
private Panel buttonPanel = new Panel();
private Panel graphArea = new Panel();
private Panel descriptionArea = new Panel();
private Panel messagePanel = new Panel();
// Various single widgets:
private Button buttonCompute = new Button("Compute");
private TextField outputField;
TextField cursorFieldX = new TextField( "0", 8 );
TextField cursorFieldY = new TextField( "0", 8 );
// Error handle to collect error messages from parameters
private ErrorHandle errorHandle;
private Color[] colors = {
Color.blue, Color.green, Color.red, Color.cyan,
Color.magenta, Color.orange, Color.darkGray, Color.pink,
Color.yellow, Color.lightGray };
// The EBM-model:
private ModelEbm ebmModel = new ModelEbm();
// The set of parameters
// (read from the GUI and transferred to the model:
private ParameterSetEbm param = new ParameterSetEbm();
// Definitions of for the graph panel
private int aspectVariables = 1;
private int graphWidth = 600;
private int graphHeight = 350;
// The graph panel (to be placed in the graphArea):
private GraphPanel graphPanel =
new GraphPanel( graphWidth, graphHeight,
aspectVariables,
cursorFieldX, cursorFieldY,
colors);
// For testing only:
// PrintWriter printlog = new PrintWriter(System.out, true);
/**
* The init-method: constructs the GUI, successively adds the components,
* and provides a listener registered at the compute-button:
*
* - Set layout, color, and input-font for the entire area
*
- Assemble parameter-Input on one Panel (top = north)
*
- Assemble panel with button "Compute" (left = west)
* with a Listener for the "compte"-button defining the
* action to be performed when the button is pressed:
*
* - Reset the error message
*
- Read parameters from InputTextfields/checkboxes
*
- Initialize the EbmModel
*
- Draw GraphPanel (resets and iterates the ebmModel)
*
- Display the error message
*
* - Assemble Graph-panel (center)
*
- Assemble Description-Panel
*
- Assemble Message-Panel (bottom = south)
*
- Show the entire panel
*
*/
public void init() {
/* Set layout, color, and input-font for the entire area
*/
setLayout( new BorderLayout() );
setBackground(Color.lightGray);
setForeground(Color.black);
Font fontInput = new Font("Monospaced", Font.PLAIN, 11 );
/*
* Assemble parameter-Input on one Panel (top = north)
*/
paramArea.setLayout( new GridLayout( 0, 6 ) );
errorHandle = new ErrorHandle();
errorHandle.setMessageString("OK");
paramArea.add( param.Timesteps.ConstructLabelOnGUI() );
paramArea.add( param.Timesteps.ConstructInputOnGUI( 9, fontInput ) );
paramArea.add( param.TimeStepLength.ConstructLabelOnGUI() );
paramArea.add( param.TimeStepLength.ConstructInputOnGUI( 9, fontInput ) );
paramArea.add( param.TempBegin.ConstructLabelOnGUI() );
paramArea.add( param.TempBegin.ConstructInputOnGUI( 9, fontInput ) );
paramArea.add( param.HeatCapac.ConstructLabelOnGUI() );
paramArea.add( param.HeatCapac.ConstructInputOnGUI( 9, fontInput ) );
paramArea.add( param.AlbedoMean.ConstructLabelOnGUI() );
paramArea.add( param.AlbedoMean.ConstructInputOnGUI( 9, fontInput ) );
paramArea.add( param.AlbedoFeedback.ConstructLabelOnGUI() );
paramArea.add( param.AlbedoFeedback.ConstructInputOnGUI( "on ", "off" ) );
paramArea.add( param.TransmissMean.ConstructLabelOnGUI() );
paramArea.add( param.TransmissMean.ConstructInputOnGUI( 9, fontInput ) );
paramArea.add( param.FluxSwIn.ConstructLabelOnGUI() );
paramArea.add( param.FluxSwIn.ConstructInputOnGUI( 9, fontInput ) );
paramArea.add( param.NoiseOn.ConstructLabelOnGUI() );
paramArea.add( param.NoiseOn.ConstructInputOnGUI( "on ", "off") );
paramArea.add( param.X_val_min.ConstructLabelOnGUI() );
paramArea.add( param.X_val_min.ConstructInputOnGUI( 9, fontInput ) );
paramArea.add( param.X_val_max.ConstructLabelOnGUI() );
paramArea.add( param.X_val_max.ConstructInputOnGUI( 9, fontInput ) );
paramArea.add( param.NoiseAmplitude.ConstructLabelOnGUI() );
paramArea.add( param.NoiseAmplitude.ConstructInputOnGUI( 9, fontInput ) );
paramArea.add( param.Y_val_min.ConstructLabelOnGUI() );
paramArea.add( param.Y_val_min.ConstructInputOnGUI( 9, fontInput ) );
paramArea.add( param.Y_val_max.ConstructLabelOnGUI() );
paramArea.add( param.Y_val_max.ConstructInputOnGUI( 9, fontInput ) );
paramArea.add( param.NoiseBegin.ConstructLabelOnGUI() );
paramArea.add( param.NoiseBegin.ConstructInputOnGUI( 9, fontInput ) );
add(paramArea, BorderLayout.NORTH);
/* Assemble panel with button "Compute" (left = west)
* with a Listener for the "compte"-button defining the
* action to be performed when the button is pressed:
* - Reset the error message
* - Read parameters from InputTextfields/checkboxes
* - Initialize the EbmModel
* - Draw GraphPanel (resets and iterates the ebmModel)
* - Display the error message
*/
buttonPanel.setLayout( new FlowLayout(FlowLayout.LEFT, 4, 4) );
buttonCompute.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
/*
* Reset the error message
*/
errorHandle.setMessageString("OK");
/*
* Read parameters from InputTextfields/checkboxes
*/
param.Timesteps.updateValueFromGUI(errorHandle);
param.TimeStepLength.updateValueFromGUI(errorHandle);
param.TempBegin.updateValueFromGUI(errorHandle);
param.HeatCapac.updateValueFromGUI(errorHandle);
param.AlbedoMean.updateValueFromGUI(errorHandle);
param.AlbedoFeedback.updateValueFromGUI(errorHandle);
param.TransmissMean.updateValueFromGUI(errorHandle);
param.FluxSwIn.updateValueFromGUI(errorHandle);
param.NoiseOn.updateValueFromGUI(errorHandle);
param.X_val_min.updateValueFromGUI(errorHandle);
param.X_val_max.updateValueFromGUI(errorHandle);
param.NoiseAmplitude.updateValueFromGUI(errorHandle);
param.Y_val_min.updateValueFromGUI(errorHandle);
param.Y_val_max.updateValueFromGUI(errorHandle);
param.NoiseBegin.updateValueFromGUI(errorHandle);
/*
* Initialize the EbmModel
*/
ebmModel.state = ebmModel.initModel(
param
);
/*
* Draw GraphPanel (resets and iterates the ebmModel)
*/
graphPanel.drawGraph(
ebmModel,
param.X_val_min.getValue(),
param.X_val_max.getValue(),
param.Y_val_min.getValue(),
param.Y_val_max.getValue()
);
/*
* Display the error message
*/
outputField.setText( errorHandle.getMessageString() );
}
});
buttonPanel.add( buttonCompute );
add(buttonPanel, BorderLayout.WEST);
/* Assemble Graph-panel (center)
*/
graphArea.setLayout( new FlowLayout(FlowLayout.LEFT, 1, 1 ) );
graphArea.add( graphPanel );
add(graphArea, BorderLayout.CENTER);
graphArea.setBackground(Color.lightGray);
graphArea.add( new Label(" ",
Label.LEFT) );
graphArea.add( new Label(" ", Label.LEFT) );
/* Assemble Description-Panel
*/
Panel descriptionPanel = new Panel();
descriptionArea.setLayout( new BorderLayout() );
descriptionArea.add( new Label(" ", Label.LEFT),
BorderLayout.NORTH );
descriptionArea.add( new Label(" ", Label.LEFT),
BorderLayout.WEST );
descriptionArea.add( new Label(" ", Label.LEFT),
BorderLayout.EAST );
descriptionArea.add( new Label(" ", Label.LEFT),
BorderLayout.SOUTH );
descriptionPanel.setLayout( new FlowLayout() );
descriptionPanel.setBackground(Color.white);
Panel descriptionListPanel = new Panel();
descriptionListPanel.setLayout( new GridLayout( 0, 1 ) );
String aspectName = new String();
descriptionListPanel.add( new Label("Variables: ", Label.LEFT) );
for ( int iAspVarInd = 0; iAspVarInd < aspectVariables;
iAspVarInd++) {
aspectName = ebmModel.getAspectName( iAspVarInd ) ;
Label aspectLabel = new Label(aspectName, Label.LEFT);
aspectLabel.setForeground( colors[iAspVarInd] );
descriptionListPanel.add( aspectLabel );
};
descriptionPanel.add(descriptionListPanel);
descriptionArea.add(descriptionPanel, BorderLayout.CENTER);
add(descriptionArea, BorderLayout.EAST);
/* Assemble Message-Panel (bottom = south)
*/
messagePanel.setLayout( new GridLayout( 0, 1 ) );
Panel fieldBottom1 = new Panel();
fieldBottom1.setLayout( new FlowLayout(FlowLayout.LEFT, 10, 10) );
outputField = new TextField( errorHandle.getMessageString(), 60 );
outputField.setEditable( false );
fieldBottom1.add( new Label( " ", Label.RIGHT ) );
fieldBottom1.add( outputField );
cursorFieldX.setEditable( false );
cursorFieldY.setEditable( false );
fieldBottom1.add( new Label( " Cursor at X:", Label.LEFT ) );
fieldBottom1.add( cursorFieldX );
fieldBottom1.add( new Label( " Y:", Label.LEFT ) );
fieldBottom1.add( cursorFieldY );
messagePanel.add( fieldBottom1 );
add(messagePanel, BorderLayout.SOUTH);
/*Show the entire panel
*/
setVisible(true);
}
/** Method to give the graph-panel
* @return reference of the graph-panel
*/
public GraphPanel getGraphFunction() {
return graphPanel;
}
/** main-method to be called, when used as a stand-alone-
* application. Uses a EbmApplet and calls its init()-method.
*/
public static void main(String[] args) {
Frame frame = new Frame(" EbmApplet ");
EbmApplet ebmApplet = new EbmApplet();
ebmApplet.init();
frame.add( ebmApplet );
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
e.getWindow().dispose();
System.exit(0);
}
});
frame.setSize( 970, 620 );
frame.setVisible(true);
}
}