/* Copyright 2005 Virtual Observatory - India. All rights reserved. */ // java imports import java.awt.BorderLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Vector; // java swing related imports import javax.swing.JFrame; import javax.swing.JPanel; // VOPlot related imports import com.jvt.applets.PlotVOApplet; import com.jvt.ext.ColumnException; import com.jvt.ext.ColumnMetaData; import com.jvt.ext.DataNotFoundException; import com.jvt.ext.FilterException; import com.jvt.ext.PlotException; import com.jvt.ext.VOPlotExternalApp; import com.jvt.ext.VOTableParseException; /** *
VOPlot Launcher
Class to demonstrate the usage of the external interface to VOPlot.
*Copyright: Copyright (c) 2004 Persistent Systems
*Software developed under Virtual Observatory India initiative * by Persistent Systems, Pune and IUCAA. For feedback and comments * please contact voindia@vo.iucaa.ernet.in
* @version 1.0 */ public class VOPlotLauncher { /** * Default Constructor * */ public VOPlotLauncher(String str) { try { _panel = null; _voExtApp = null; //Create the File/URL object from the String File file = new File(str.trim()); _panel = new JPanel(); _panel.setLayout(new BorderLayout()); // Call the static method addVOPlot(Panel) of PlotVOApplet // to create a new VOPlot object and add it to the panel // passed as argument to the function. _voExtApp = PlotVOApplet.addVOPlot(_panel); try { _voExtApp.loadVOTable(file, true); System.out.println("Info: Loaded VOtable in VOPlot."); } catch (DataNotFoundException ex) { System.out.println("Error: DataNotFoundException : " + ex); } catch (VOTableParseException ex) { System.out.println("Error: VOTableParseException : " + ex); } catch (PlotException ex) { System.out.println("Error: PlotException : " + ex); } // Select points on the plot. selectPoints(); // Highlight points on the plot. highlightPoints(); // Add new columns. addNewColumns(); // Overlay plots on top of the current one. overlay(); // Add a filter for the data. addFilter(); // Set filter for the data. setFilter(); // Write data in VOTable format to a file. writeVOTable(); // Load Data into VOPlot which is not in VOTable format. loadDataIntoVOPlot(); // Create a frame to add the panel and a listener for closing // the application. createFrame(); } catch (Exception ex) { // print stack trace ex.printStackTrace(); } } /** * Select points on the plot. * This method has been written to demonstrate the use of selecting * various points on the plot. */ private void selectPoints() { _voExtApp.selectPoints(new int[] { 0 }); System.out.println("Info: Selected point at 0"); } /** * Highlight points on the plot. * This method has been written to demonstrate the use of highlighting * various points on the plot. */ private void highlightPoints() { _voExtApp.highlightPoints(new int[] { 0, 1 }); System.out.println("Info: Highlighted point at 0, 1"); } /** * Add new columns. * This method has been written to demonstrate the use of adding new * columns to the plot. */ private void addNewColumns() { try { _voExtApp.addColumn("$1 + $2", "deg", "$1 + $2"); System.out.println("Info: added new column '$1 + $2'"); _voExtApp.addColumn("$1 - $2", "deg", "$1 - $2"); System.out.println("Info: added new column '$1 - $2'"); } catch (ColumnException ex) { System.out.println(ex); } } /** * Overlay plots on top of the current one. * This method has been written to demonstrate the use of overlaying * of different plots. */ private void overlay() { try { _voExtApp.plotColumns(3, true, 4, true, true); _voExtApp.plotColumns(5, false, 6, false, true); } catch (PlotException ex) { System.out.println(ex); } // Show full range in case the data from new dataset is out of current // plot area. _voExtApp.showFullRange(); } /** * Add a filter for the data. * This method has been written to demonstrate the use of adding filters * for the data. */ private void addFilter() { try { _voExtApp.addFilter("($1 > 0.0)", "($1 > 0.0)"); System.out.println("Info: added new filter '$1 > 0.0'"); } catch (FilterException ex) { System.out.println("Error: " + ex); } } /** * Set filter for the data. * This method has been written to demonstrate the use of setting a * particular filter for the data. */ private void setFilter() { try { _voExtApp.setFilter("($1 > 0.0)"); } catch (FilterException ex) { System.out.println("Error: " + ex); } } /** * Write data in VOTable format to a file. * This method has been written to demonstrate the use of writing * the data in VOTable format. */ private void writeVOTable() { try { String savedVOTable = "c:/votable.xml"; _voExtApp.writeVOTable(new FileOutputStream(savedVOTable)); System.out.println("Info: Writing VOTable to " + savedVOTable); } catch (IOException ex) { System.out.println("Error: IOException : " + ex); } } /** * Load Data into VOPlot which is not in VOTable format. * */ private void loadDataIntoVOPlot() { // The sample data which we load is the following : // RecNum VMag BMag RA_Degrees DEC_Degrees RA DEC // '1.0' '15.0' '16.0' '07.8688' '77.5388' '03 10 57.65' '+66 34 02.6' // '2.0' '21.0' '14.0' '21.0974' '68.3253' '20 17 32.50' '+06 23 51.7' // Create a vector for MetaData Vector metaData = new Vector(); // Create com.jvt.ext.ColumnMetaData Objects for storing information // about columns. ColumnMetaData column1Info = new ColumnMetaData("RecNum", ColumnMetaData.DATATYPE_DOUBLE, "mag", " "); ColumnMetaData column2Info = new ColumnMetaData("VMag", ColumnMetaData.DATATYPE_DOUBLE, "deg", " "); ColumnMetaData column3Info = new ColumnMetaData("BMag", ColumnMetaData.DATATYPE_DOUBLE, "mag", " "); ColumnMetaData column4Info = new ColumnMetaData("RA_Degrees", ColumnMetaData.DATATYPE_DOUBLE, "deg", "POS_EQ_RA_MAIN"); ColumnMetaData column5Info = new ColumnMetaData("DEC_Degrees", ColumnMetaData.DATATYPE_DOUBLE, "deg", "POS_EQ_DEC_MAIN"); // Loading RA and DEC in sexagecimal. ColumnMetaData column6Info = new ColumnMetaData("RA", ColumnMetaData.DATATYPE_CHAR, "h:m:s", "POS_EQ_RA_MAIN"); ColumnMetaData column7Info = new ColumnMetaData("DEC", ColumnMetaData.DATATYPE_CHAR, "d:m:s", "POS_EQ_DEC_MAIN"); // Add ColumnMetaData objects to MetaData. metaData.add(column1Info); metaData.add(column2Info); metaData.add(column3Info); metaData.add(column4Info); metaData.add(column5Info); metaData.add(column6Info); metaData.add(column7Info); // Create a Vector of Vectors for the Data. Vector data = new Vector(); Vector row1 = new Vector(); Vector row2 = new Vector(); // add row 1 row1.add("1.0"); row1.add("15.0"); row1.add("16.0"); row1.add("7.8688"); row1.add("77.5366"); row1.add("03 10 57.65"); row1.add("+66 34 02.6"); data.add(row1); // add row 2 row2.add("2.0"); row2.add("21.0"); row2.add("14.0"); row2.add("21.0974"); row2.add("68.3253"); row2.add("20 17 32.50"); row2.add("+06 23 51.7"); data.add(row2); // Load the Data so created without erasing previous plot. try { _voExtApp.loadData(metaData, data, true, true); System.out.println("Info: loaded more data in VOPlot."); } catch (PlotException ex) { System.out.println("Error while loading data in VOPlot: " + ex); } } /** * Create a frame to add the panel and a listener for closing the * application. */ private void createFrame() { // Create a Frame and add VOPLot to it. final JFrame frame = new JFrame("VOPlot frame"); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.out.println("Info: Frame closed. "); frame.dispose(); System.exit(0); } }); frame.getContentPane().add(_panel, BorderLayout.CENTER); frame.setSize(800, 600); frame.setVisible(true); } /** * Main method * @param args Arguments to the VOPlotLauncher application */ public static void main(String[] args) { if(args.length != 1) { System.out.println("Please filepath/url as the command line argument"); System.exit(0); } new VOPlotLauncher(args[0]); } /** * Member variables * */ /** * The external application interface. * */ private VOPlotExternalApp _voExtApp = null; /** * The panel for displaying the VOPlot. * */ private JPanel _panel = null; }