package DataLoader; import java.util.List; import java.util.Hashtable; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import java.io.*; import SBEAMS.*; //----------------------------------------------------------------------------------------------- public class FileChooserWizardPanel extends WizardPanel implements ActionListener, ListSelectionListener{ //----------------------------------------------------------------------------------------------- private static String NEW_EXPERIMENT = "New Experiment"; private JButton chooseFileButton; private JPanel imagePanel; private JList conditionList; private String experimentName = NEW_EXPERIMENT; private String dataFile; private JTextField experimentNameField; private String[] conditionNames; private BufferedReader bufferedReader; private StringBuffer strbuf; private Hashtable tempData; private SBEAMSClient sc; private Integer project_id; private static String expNameURL="http://db/sbeams/cgi/Microarray/ManageTable.cgi?TABLE_NAME=project&output_mode=tsv"; //----------------------------------------------------------------------------------------------- public FileChooserWizardPanel() { initialize(); }// constructor //----------------------------------------------------------------------------------------------- public FileChooserWizardPanel(String dataFile) { this.dataFile = dataFile; initialize(); handleDataFile(dataFile); }// constructor //----------------------------------------------------------------------------------------------- public FileChooserWizardPanel(String dataFile, String translatorFile, Integer project_id) { this.dataFile = dataFile; this.project_id = project_id; initialize(); handleDataFile(dataFile, translatorFile); }// constructor //----------------------------------------------------------------------------------------------- public void initialize(){ if (project_id != null) { try{ if (sc == null) sc = new SBEAMSClient(true); Hashtable h = sc.fetchSbeamsResultSetHash(expNameURL, "project_id", "name"); if ( h.containsKey( project_id.toString() ) ) { experimentName = (String) ( h.get(project_id.toString()) ); experimentName = experimentName.trim(); experimentName = experimentName.replaceAll("\\s","_"); } }catch (Exception e) { e.printStackTrace(); } } tempData = new Hashtable(); setLayout(new BorderLayout()); setBorder(new TitledBorder("Step 1. Select File to Load")); JPanel experimentNamePanel = new JPanel(); experimentNamePanel.add(new JLabel("Experiment Name: ")); experimentNameField = new JTextField(15); experimentNameField.requestFocus(); experimentNamePanel.add(experimentNameField); add(experimentNamePanel, BorderLayout.NORTH); JPanel leftPanel = new JPanel(new BorderLayout()); leftPanel.add(new JLabel("Conditions"), BorderLayout.NORTH); conditionList = new JList(); conditionList.addListSelectionListener(this); leftPanel.add(new JScrollPane(conditionList), BorderLayout.CENTER); imagePanel = new JPanel(new BorderLayout()); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, imagePanel); splitPane.setDividerLocation(150); add(splitPane, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(); chooseFileButton = new JButton ("Select File"); chooseFileButton.addActionListener(this); buttonPanel.add(chooseFileButton); add(buttonPanel, BorderLayout.SOUTH); }// initialize //----------------------------------------------------------------------------------------------- private boolean readFile(String filePath){ try{ bufferedReader = new BufferedReader(new FileReader(filePath)); }catch (IOException e) { e.printStackTrace(); return false; } strbuf = new StringBuffer(); String newLineOfText; int conditionMax = 0; try { // Read file into a big string while ( (newLineOfText = bufferedReader.readLine()) != null ) { strbuf.append(newLineOfText +"\n"); } String all = strbuf.toString(); String [] dataLines = all.split("\\n"); // Look at 1st line (header) String[] line = (dataLines[0]).split("\\s"); int conditions = (int)(line.length-2)/2; conditionNames = new String[conditions]; for (int m=0;m