/*************************************************************************\ * Copyright (c) 2002 The University of Chicago, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. * This file is distributed subject to a Software License Agreement found * in the file LICENSE that is included with this distribution. \*************************************************************************/ package SDDS.java.SDDS3Dplot; import java.io.*; import java.awt.*; import java.awt.image.*; import java.awt.event.*; import javax.swing.*; import java.lang.reflect.*; import visad.*; import visad.util.*; import visad.java3d.DisplayImplJ3D; import visad.java3d.ProjectionControlJ3D; import java.rmi.RemoteException; import SDDS.java.SDDS.*; import SDDS.java.SDDS.SDDSUtil; import javax.swing.event.*; import com.sun.image.codec.jpeg.*; public class Frame1 extends JFrame { protected FileDialog fileDialog; JPanel contentPane; JMenuBar jMenuBar1 = new JMenuBar(); JMenu jMenuFile = new JMenu(); JMenuItem jMenuFileExit = new JMenuItem(); BorderLayout borderLayout1 = new BorderLayout(); static DisplayImpl display; // AnimationWidget animWid; static ScalarMap xMap, yMap, zMap, zColorMap, selValMap, xRangeMap, yRangeMap, zRangeMap; SDDSFile sdds; int contourType; boolean firstPlot; static int colorCount = 6; boolean scatterPlot = false; JMenuItem jMenuItem1 = new JMenuItem(); JMenu jMenu1 = new JMenu(); JMenu jMenu2 = new JMenu(); JMenuItem jMenuItem2 = new JMenuItem(); JMenuItem jMenuItem3 = new JMenuItem(); JMenuItem jMenuItem4 = new JMenuItem(); JPanel jPanel1 = new JPanel(); JLabel jLabel1 = new JLabel(); GridBagLayout gridBagLayout1 = new GridBagLayout(); JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JTextField jTextField1 = new JTextField(); JTextField jTextField2 = new JTextField(); JLabel jLabel4 = new JLabel(); JPanel jPanel2 = new JPanel(); JComboBox jComboBox1 = new JComboBox(); JComboBox jComboBox2 = new JComboBox(); JButton jButton1 = new JButton(); JLabel jLabel5 = new JLabel(); JComboBox jComboBox3 = new JComboBox(); JMenuItem jMenuItem5 = new JMenuItem(); JMenuItem jMenuItem7 = new JMenuItem(); JComboBox jComboBox4 = new JComboBox(); JComboBox jComboBox5 = new JComboBox(); JMenuItem jMenuItem10 = new JMenuItem(); private GridBagLayout gridBagLayout2 = new GridBagLayout(); private JCheckBox jCheckBox1 = new JCheckBox(); /**Construct the frame*/ public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception,RemoteException { //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(borderLayout1); this.setSize(new Dimension(400, 520)); this.setTitle("Frame Title"); JPopupMenu.setDefaultLightWeightPopupEnabled(false); jMenuFile.setText("File"); jMenuFileExit.setText("Exit"); jMenuFileExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jMenuFileExit_actionPerformed(e); } }); jMenuItem1.setText("Open"); jMenuItem1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jMenuItem1_actionPerformed(e); } }); jMenu1.setText("Options"); jMenu2.setText("Background"); jMenuItem2.setText("White"); jMenuItem2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jMenuItem2_actionPerformed(e); } }); jMenuItem3.setText("Black"); jMenuItem3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jMenuItem3_actionPerformed(e); } }); jMenuItem4.setText("Grey"); jMenuItem4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jMenuItem4_actionPerformed(e); } }); jLabel1.setText("X"); jPanel1.setLayout(gridBagLayout1); jLabel2.setText("Y"); jLabel3.setText("Z"); jLabel4.setText("Color"); jTextField1.setMargin(new Insets(0, 3, 0, 0)); jTextField1.setColumns(10); jTextField2.setMinimumSize(new Dimension(7, 21)); jTextField2.setMargin(new Insets(0, 3, 0, 0)); jTextField2.setColumns(10); jButton1.setText("Plot"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); jLabel5.setText("Page"); jMenuItem5.setText("Save JPEG"); jMenuItem5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jMenuItem5_actionPerformed(e); } }); jMenuItem7.setText("Color"); jMenuItem7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jMenuItem7_actionPerformed(e); } }); jMenuItem10.setText("Controls"); jMenuItem10.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jMenuItem10_actionPerformed(e); } }); jPanel2.setLayout(gridBagLayout2); jCheckBox1.setText("Force 3 column plot"); jCheckBox1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jCheckBox1_actionPerformed(e); } }); jMenuFile.add(jMenuItem1); jMenuFile.add(jMenuItem5); jMenuFile.add(jMenuFileExit); jMenuBar1.add(jMenuFile); jMenuBar1.add(jMenu1); display = new DisplayImplJ3D("display1"); GraphicsModeControl dispGMC = (GraphicsModeControl) display.getGraphicsModeControl(); dispGMC.setScaleEnable(true); dispGMC.setTextureEnable(false); contentPane.add(display.getComponent(), BorderLayout.CENTER); jMenu1.add(jMenu2); jMenu1.add(jMenuItem7); jMenu1.add(jMenuItem10); jMenu2.add(jMenuItem2); jMenu2.add(jMenuItem3); jMenu2.add(jMenuItem4); contentPane.add(jPanel1, BorderLayout.SOUTH); jPanel1.add(jTextField1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jPanel1.add(jTextField2, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jPanel1.add(jLabel4, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 10), 0, 0)); jPanel1.add(jLabel2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 10, 0, 10), 0, 0)); jPanel1.add(jLabel3, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 10, 0, 10), 0, 0)); jPanel1.add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 0, 10), 0, 0)); jPanel1.add(jPanel2, new GridBagConstraints(2, 1, 3, 1, 1.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); jPanel2.add(jCheckBox1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jPanel1.add(jComboBox1, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jPanel1.add(jComboBox2, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0 ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jPanel1.add(jButton1, new GridBagConstraints(3, 2, 1, 2, 0.0, 0.0 ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jPanel1.add(jLabel5, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.SOUTH, GridBagConstraints.NONE, new Insets(0, 20, 0, 10), 0, 0)); jPanel1.add(jComboBox3, new GridBagConstraints(3, 0, 2, 1, 0.0, 0.0 ,GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jPanel1.add(jComboBox4, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 ,GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jPanel1.add(jComboBox5, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 ,GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); jComboBox4.setVisible(false); jComboBox5.setVisible(false); jCheckBox1.setVisible(false); this.setJMenuBar(jMenuBar1); firstPlot = true; } /**File | Exit action performed*/ public void jMenuFileExit_actionPerformed(ActionEvent e) { System.exit(0); } /**Overridden so we can exit when window is closed*/ protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { jMenuFileExit_actionPerformed(null); } } public void readFile(String fileName) throws RemoteException, VisADException { sdds = new SDDSFile(fileName); if (!sdds.readFile()) { sdds.printErrors(); return; } loadFile(); } public void loadFile() throws RemoteException, VisADException { int index, pages; contourType = 1; index = sdds.getParameterIndex("Variable1Name"); if ((index == -1) || (jCheckBox1.isSelected() == true)) { loadFile2(); return; } jComboBox4.setVisible(false); jTextField1.setVisible(true); jComboBox5.setVisible(false); jTextField2.setVisible(true); jCheckBox1.setVisible(true); jTextField1.setText((String)sdds.getParameterValue(index,1,false)); index = sdds.getParameterIndex("Variable2Name"); if (index == -1) { return; } jTextField2.setText((String)sdds.getParameterValue(index,1,false)); jComboBox1.removeAllItems(); jComboBox2.removeAllItems(); jComboBox3.removeAllItems(); String[] columnNames = sdds.getColumnNames(); for (int i = 0; i < Array.getLength(columnNames); i++) { jComboBox1.addItem(columnNames[i]); jComboBox2.addItem(columnNames[i]); } pages = sdds.pageCount(); for (int i = 1; i <= pages; i++) { jComboBox3.addItem(String.valueOf(i)); } } public void loadFile2() throws RemoteException, VisADException { int pages, i, j, length, maxhits, hits; Double test; String colPrefix = new String(); contourType = 2; jComboBox1.removeAllItems(); jComboBox2.removeAllItems(); jComboBox3.removeAllItems(); jComboBox4.removeAllItems(); jComboBox5.removeAllItems(); String[] columnNames = sdds.getColumnNames(); length = Array.getLength(columnNames); String[] columnNamesWithoutNumbers = new String[length]; boolean[] checked = new boolean[length]; for (i = 0; i < length; i++) { columnNamesWithoutNumbers[i] = columnNames[i]; for (j = columnNames[i].length() - 1; j > 0; j--) { try { test = new Double(columnNames[i].substring(j)); } catch (NumberFormatException ex) { columnNamesWithoutNumbers[i] = columnNames[i].substring(0,j+1); break; } } } i = 0; maxhits = 0; while (i < length) { if (checked[i]) { i++; continue; } checked[i] = true; hits = 0; for (j = i+1; j < length; j++) { if (columnNamesWithoutNumbers[i].equals(columnNamesWithoutNumbers[j])) { checked[j] = true; hits++; if (hits > maxhits) { maxhits = hits; if (colPrefix.equals(columnNamesWithoutNumbers[i]) == false) { colPrefix = columnNamesWithoutNumbers[i]; } } } } i++; } jTextField1.setVisible(false); jComboBox4.setVisible(true); jTextField1.setText(""); jTextField2.setText(""); if ((maxhits < 2) || (jCheckBox1.isSelected() == true)) { contourType = 3; jTextField2.setVisible(false); jComboBox5.setVisible(true); jCheckBox1.setVisible(true); for (i = 0; i < length; i++) { /* if (colPrefix.equals(columnNamesWithoutNumbers[i]) == false) {*/ j = sdds.getColumnType(i); if ((j != SDDSUtil.SDDS_CHARACTER) && (j != SDDSUtil.SDDS_STRING)) { jComboBox1.addItem(columnNames[i]); jComboBox2.addItem(columnNames[i]); jComboBox4.addItem(columnNames[i]); jComboBox5.addItem(columnNames[i]); } /* }*/ } if (jComboBox1.getItemCount() >= 3) { jComboBox4.setSelectedIndex(0); jComboBox5.setSelectedIndex(1); jComboBox1.setSelectedIndex(2); jComboBox2.setSelectedIndex(2); } } else { jTextField2.setVisible(true); jComboBox5.setVisible(false); jCheckBox1.setVisible(true); for (i = 0; i < length; i++) { if (colPrefix.equals(columnNamesWithoutNumbers[i]) == false) { j = sdds.getColumnType(i); if ((j != SDDSUtil.SDDS_CHARACTER) && (j != SDDSUtil.SDDS_STRING)) { jComboBox4.addItem(columnNames[i]); } } } jComboBox1.addItem(colPrefix); jComboBox2.addItem(colPrefix); } pages = sdds.pageCount(); for (i = 1; i <= pages; i++) { jComboBox3.addItem(String.valueOf(i)); } } public void plotFile() throws RemoteException, VisADException { RealType x, y, z, zColor, frame; RealTupleType domain_tuple, range_tuple; FunctionType func_domain_range, func_domain_range_frame; Set domain_set; Set frame_set; FlatField vals_ff; FieldImpl frameField; DataReferenceImpl data_ref; boolean fourDimensional = false; int index, index2, pages, page; if (sdds == null) return; float[][] myColorTable; if (firstPlot) { myColorTable = new float[][]{{0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f}, // red {0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f}, // green {1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}}; // blue } else { ColorControl colCont = (ColorControl) zColorMap.getControl(); myColorTable = new float[3][colorCount]; float[][] colorTable = colCont.getTable(); for (int i=0; i