/* * FileOutputSelector.java * * Created on January 3, 2002, 4:15 AM */ package dods.clients.importwizard; import java.io.*; import javax.swing.*; /** * * @author rhonhart */ public class FileOutputSelector extends DataFormatSelector { private DodsURL[] urls; /** Creates new form FileOutputSelector */ public FileOutputSelector() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() {//GEN-BEGIN:initComponents java.awt.GridBagConstraints gridBagConstraints; outputMethodGroup = new javax.swing.ButtonGroup(); outputFormatGroup = new javax.swing.ButtonGroup(); outputFormatPanel = new javax.swing.JPanel(); urlsButton = new javax.swing.JRadioButton(); idlButton = new javax.swing.JRadioButton(); outputMethodPanel = new javax.swing.JPanel(); stdoutButton = new javax.swing.JRadioButton(); fileButton = new javax.swing.JRadioButton(); fileNameField = new javax.swing.JTextField(); namingPanel = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); varPrefixField = new javax.swing.JTextField(); setLayout(new java.awt.GridBagLayout()); setBorder(new javax.swing.border.TitledBorder("Output Options")); //set size java.awt.Dimension d = new java.awt.Dimension(230, 40); outputFormatPanel.setPreferredSize(d); outputMethodPanel.setPreferredSize(d); namingPanel.setPreferredSize(d); outputFormatPanel.setLayout(new javax.swing.BoxLayout(outputFormatPanel, javax.swing.BoxLayout.X_AXIS)); outputFormatPanel.setBorder(new javax.swing.border.TitledBorder("Output Format")); urlsButton.setSelected(true); urlsButton.setText("Just URLs"); outputFormatGroup.add(urlsButton); outputFormatPanel.add(urlsButton); idlButton.setText("IDL GUI"); outputFormatGroup.add(idlButton); outputFormatPanel.add(idlButton); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; add(outputFormatPanel, gridBagConstraints); outputMethodPanel.setLayout(new javax.swing.BoxLayout(outputMethodPanel, javax.swing.BoxLayout.X_AXIS)); outputMethodPanel.setBorder(new javax.swing.border.TitledBorder("Output Method")); stdoutButton.setSelected(true); stdoutButton.setText("Standard Out"); outputMethodGroup.add(stdoutButton); outputMethodPanel.add(stdoutButton); fileButton.setText("File:"); outputMethodGroup.add(fileButton); outputMethodPanel.add(fileButton); fileNameField.setText("dodsurls.txt"); outputMethodPanel.add(fileNameField); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; add(outputMethodPanel, gridBagConstraints); namingPanel.setLayout(new javax.swing.BoxLayout(namingPanel, javax.swing.BoxLayout.X_AXIS)); namingPanel.setBorder(new javax.swing.border.TitledBorder("Naming")); jLabel1.setText("Prefix:"); jLabel1.setForeground(new java.awt.Color(0, 0, 0)); namingPanel.add(jLabel1); varPrefixField.setText("data"); namingPanel.add(varPrefixField); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; add(namingPanel, gridBagConstraints); }//GEN-END:initComponents public void setURLs(DodsURL[] newURLs) { urls = newURLs; } public DodsURL[] getURLs() { return urls; } public void outputURLs() { PrintWriter pw; String fileName = fileNameField.getText(); String prefix = varPrefixField.getText(); if(fileButton.isSelected()) { try { FileWriter fw = new FileWriter(fileName, true); pw = new PrintWriter(fw); } catch(IOException e) { JOptionPane.showMessageDialog(this, "Couldn't open file for writing", "Error", JOptionPane.ERROR_MESSAGE); return; } for(int i=0;i<urls.length;i++) { pw.print(urls[i].getFullURL()); if(idlButton.isSelected()) pw.println(";" + prefix + String.valueOf(i)); else pw.println(""); } } else { for(int i=0;i<urls.length;i++) { System.out.print(urls[i].getFullURL()); if(idlButton.isSelected()) System.out.println(";" + prefix + String.valueOf(i)); else System.out.println(""); } } } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JRadioButton stdoutButton; private javax.swing.JRadioButton urlsButton; private javax.swing.ButtonGroup outputFormatGroup; private javax.swing.ButtonGroup outputMethodGroup; private javax.swing.JPanel namingPanel; private javax.swing.JTextField varPrefixField; private javax.swing.JPanel outputFormatPanel; private javax.swing.JRadioButton idlButton; private javax.swing.JPanel outputMethodPanel; private javax.swing.JLabel jLabel1; private javax.swing.JRadioButton fileButton; private javax.swing.JTextField fileNameField; // End of variables declaration//GEN-END:variables }