//
// RainSheet.java
//

/*
VisAD system for interactive analysis and visualization of numerical
data.  Copyright (C) 1996 - 2017 Bill Hibbard, Curtis Rueden, Tom
Rink and Dave Glowacki.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License in file NOTICE for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

package visad.rabin;

// import JFC packages
import javax.swing.*;
import javax.swing.border.*;

// import AWT package
import java.awt.*;
import java.awt.event.*;

// import needed Spread Sheet classes
import visad.ss.BasicSSCell;
import visad.ss.FancySSCell;

// import other needed classes
import visad.*;
import visad.util.VisADSlider;
import java.rmi.RemoteException;


/** RainSheet is a "toy" version of visad.ss.SpreadSheet,
    with only two cells.  It demonstrates how the developer can use
    the classes in the visad.ss package as GUI components for their
    own applications.

*/ public class RainSheet extends JFrame implements ActionListener { // type 'java RainSheet' to run this application static final int N_COLUMNS = 3; static final int N_ROWS = 4; static final JPanel[] row_panels = new JPanel[N_ROWS]; static final FancySSCell[] cells = new FancySSCell[N_ROWS * N_COLUMNS]; static final JTextField[] formulas = new JTextField[N_ROWS * N_COLUMNS]; static final JButton[] maps = new JButton[N_ROWS * N_COLUMNS]; /** the width and height of the UI frame */ static final int WIDTH = 1100; static final int HEIGHT = 900; static final int CELL_WIDTH = 200; static final int CELL_HEIGHT = 200; static String[] formula_name = {"A1", "B1", "C1", "A2", "B2", "C2", "A3", "B3", "C3", "A4", "B4", "C4"}; static String[] formula_array = {"file:dallas_2.5km_v5d.v5d", "A1(0)", "((10^((extract(B1,0))/10))/SLIDER300)^(1/SLIDER1_4)", "((10^((extract(B1,1))/10))/SLIDER300)^(1/SLIDER1_4)", "((10^((extract(B1,2))/10))/SLIDER300)^(1/SLIDER1_4)", "((10^((extract(B1,3))/10))/SLIDER300)^(1/SLIDER1_4)", "((10^((extract(B1,4))/10))/SLIDER300)^(1/SLIDER1_4)", "((10^((extract(B1,5))/10))/SLIDER300)^(1/SLIDER1_4)", "(10*C1+10*A2+10*B2+10*C2+10*A3+3*B3)/53", "extract(B1,6)", "extract(B1,7)", "extract(B1,8)"}; /** The main method just constructs a RainSheet, displays it, and exits */ public static void main(String[] argv) throws VisADException, RemoteException { RainSheet ms = new RainSheet(); ms.pack(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); ms.setSize(WIDTH, HEIGHT); Dimension appSize = ms.getSize(); ms.setLocation(screenSize.width/2 - appSize.width/2, screenSize.height/2 - appSize.height/2); ms.setVisible(true); } /** Creates a label with black text s and adds it to p */ private static void createLabel(JPanel p, String s) { JLabel l = new JLabel(s); l.setForeground(Color.black); p.add(l); } /** Two text fields */ private JTextField Formula1, Formula2; /** Constructs the RainSheet frame */ public RainSheet() throws VisADException, RemoteException { // construct a frame with appropriate title super("RainSheet"); // mapping dialog is the wrong color without this line setBackground(Color.white); // end program when this frame is closed addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { quitProgram(); } }); // construct main panel JPanel main = new JPanel(); setContentPane(main); main.setLayout(new BoxLayout(main, BoxLayout.X_AXIS)); // construct left panel JPanel left = new JPanel(); left.setBorder(new CompoundBorder(new EtchedBorder(), new EmptyBorder(5, 10, 5, 10))); left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS)); main.add(left); JPanel display_panel = new JPanel(); display_panel.setLayout(new BoxLayout(display_panel, BoxLayout.Y_AXIS)); display_panel.setAlignmentY(JPanel.TOP_ALIGNMENT); display_panel.setAlignmentX(JPanel.LEFT_ALIGNMENT); main.add(display_panel); // add JLabels to left panel createLabel(left, "RainSheet -- a custom spreadsheet"); createLabel(left, "for rain estimation"); DataReference ref300 = new DataReferenceImpl("num300"); DataReference ref1_4 = new DataReferenceImpl("num1_4"); VisADSlider slider300 = new VisADSlider("num300", 0, 600, 300, 1.0, ref300, RealType.Generic); VisADSlider slider1_4 = new VisADSlider("num1_4", 0, 280, 140, 0.01, ref1_4, RealType.Generic); left.add(slider300); left.add(slider1_4); BasicSSCell.createVar("SLIDER300", ref300); BasicSSCell.createVar("SLIDER1_4", ref1_4); // create panel for Quit button so the button can be centered JPanel qpanel = new JPanel(); qpanel.setAlignmentX(JPanel.LEFT_ALIGNMENT); qpanel.setLayout(new BoxLayout(qpanel, BoxLayout.X_AXIS)); left.add(Box.createRigidArea(new Dimension(0, 15))); left.add(qpanel); // add Quit button to its panel JButton quit = new JButton("Quit"); quit.addActionListener(this); quit.setActionCommand("quit"); qpanel.add(Box.createHorizontalGlue()); qpanel.add(quit); qpanel.add(Box.createHorizontalGlue()); // don't let left panel shrink or grow in size Dimension lps = left.getPreferredSize(); left.setMinimumSize(lps); left.setMaximumSize(lps); // construct two spreadsheet cells and related GUI components int i = 0; // create row JPanels for (int k=0; k

Ads help maintain this website.