/* Copyright @ 2003, The Institute for Genomic Research (TIGR). All rights reserved. */ /*************************************************************************** * Author: Jianwei(Jerry) Li * Name: ImaGenePanel (Version 1.0) * Date: Created: 04/02/2003 and modified: 04/02/2003 * Descp: the interface for ImaGene output files as input for the ExpressConveter ***************************************************************************/ package org.tigr.microarray.converter; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; import javax.swing.Timer; import org.tigr.util.awt.GBA; import org.tigr.util.*; import org.tigr.util.io.IOUtil; import org.tigr.util.MadamFileFilter; import org.tigr.util.LongTextChanger; public class ImaGenePanel extends ConvertPanel implements ItemListener, MouseListener, ActionListener { private Icon upIcon, downIcon, leftIcon, rightIcon; private JPanel genePanel, ch1FilePL, ch2FilePL; private JPanel tavPanel, pairButtonPL; private JList ch1FileList, ch2FileList; private JList outputFileList; private JButton upBtn, downBtn, leftBtn, rightBtn; private JCheckBox keepAllCB; private JCheckBox ch1CB, ch2CB; private JLabel fileNumLB, igFileLB, outputFileLB; private JLabel ch1FileLB, ch2FileLB; private JScrollPane inputFilesSP, tFilesSP, ch1FileSP, ch2FileSP; private JSplitPane fileSplitPane, inputSplitPane; private ButtonGroup btnGroup; // variable declare private String gfType[] = {"txt"}; private long curTime; private boolean dirtyData; private boolean keepAll; private boolean ch1Selected; // indicates if working on channel 1 file private Vector selectedCh1Files; // input files for channel 1 to be converted. private Vector selectedCh2Files; // input files for channel 2 to be converted. private final String NUM_FILE = " Number of Files: "; public ImaGenePanel(){ this(null); } public ImaGenePanel(ExpressConverter ec) { super(ec); keepAll = false; ch1Selected = true; dirtyData = false; selectedCh1Files = new Vector(10, 3); selectedCh2Files = new Vector(10, 3); createGUI(); adjustInputSelection(ch1Selected); } /************************************************************************** * Description: * activate left and right buttons based on seleced input channel. **************************************************************************/ private void adjustInputSelection(boolean ch1){ rightBtn.setEnabled(ch1); leftBtn.setEnabled(!ch1); } /**************************************************************************** * Description: * modifies the output file names. *

Parameter: *
path -- the new directory. ***************************************************************************/ public void editDirectory(String path){ int selected = -1; int num; String tempName, tempPath; tempPath = path; selected = outputFileList.getSelectedIndex(); num = outputFileNames.size(); for(int i=0; i=0){ outputFileList.setSelectedIndex(selected); } else { outputFileList.setSelectedIndex(0); } } /**************************************************************************** * Description: * modifies the output file names. ***************************************************************************/ public void editFileName(){ int selected = -1; String tempName; selected = outputFileList.getSelectedIndex(); if(selected >= 0){ tempName = (String)(outputFileList.getModel()).getElementAt(selected); LongTextChanger changer = new LongTextChanger(null, true, tempName); changer.show(); if(changer.isTextChanged()){ tempName = changer.getText(); StringTokenizer token = new StringTokenizer(tempName, ":"); if(token.countTokens() <= 1){ tempName = "c:\\" + tempName; } tempName = IOUtil.dropExtension(tempName); if(tempName.lastIndexOf('.') == tempName.length()-1){ tempName += FILE_TYPE[outputType]; } else { tempName += "." + FILE_TYPE[outputType]; } outputFileNames.setElementAt(tempName, selected); outputFileList.setListData(outputFileNames); outputFileList.setSelectedIndex(selected); } } } /**************************************************************************** * Description: * alters the interface to meet the requirement for output file type. *

Parameter: *
index -- the selected index of the combobox. ***************************************************************************/ public void adjustGUI(int index){ int numFiles; String tmpName = new String(""); outputType = index; if(outputType == TAV_OUT){ outputFileLB.setText(TAV_FILE); keepAllCB.setEnabled(true); this.activeIntensityWay(false); } else { outputFileLB.setText(MEV_FILE); keepAllCB.setEnabled(false); this.activeIntensityWay(true); } numFiles = outputFileNames.size(); for(int i=0; iDescription: * changes the number of input and output files based on testing on the * system to see if an exsiting file is to be overwritten. *

Paramters: *
in1Files -- the input channel 1 files. *
in2Files == the input channel 2 files. *
outFiles -- the output files. ***************************************************************************/ public void changeFileList(Vector in1Files, Vector in2Files, Vector outFiles){ selectedCh1Files = in1Files; selectedCh2Files = in2Files; ch1FileList.setListData(selectedCh1Files); ch2FileList.setListData(selectedCh2Files); outputFileList.setListData(outputFileNames); fileNumLB.setText(NUM_FILE + selectedCh1Files.size()); } /***************************************************************************** * Description: * override the abstract method to create a GUI for program ****************************************************************************/ protected void createGUI(){ Dimension screenSize; Dimension btnSize = new Dimension(20, 20); BevelBorder high = new BevelBorder(0); BevelBorder low = new BevelBorder(1); int sizeX = (int)(parent.scrWidth * 0.85); int sizeY = (int)(parent.scrHeight * 0.85); this.setLayout(new GridBagLayout()); upIcon = new ImageIcon(Toolkit.getDefaultToolkit(). getImage(ClassLoader.getSystemResource("images/uparow.gif"))); downIcon = new ImageIcon(Toolkit.getDefaultToolkit(). getImage(ClassLoader.getSystemResource("images/downarow.gif"))); leftIcon = new ImageIcon(Toolkit.getDefaultToolkit(). getImage(ClassLoader.getSystemResource("images/leftarow.gif"))); rightIcon = new ImageIcon(Toolkit.getDefaultToolkit(). getImage(ClassLoader.getSystemResource("images/rightarow.gif"))); genePanel = new JPanel(new GridBagLayout()); ch1FilePL = new JPanel(new GridBagLayout()); ch2FilePL = new JPanel(new GridBagLayout()); pairButtonPL = new JPanel(new GridBagLayout()); igFileLB = new JLabel("ImaGene Files:"); outputFileLB = new JLabel(MEV_FILE); ch1FileLB = new JLabel("Channel A:"); ch2FileLB = new JLabel("Channel B:"); ch1CB = new JCheckBox(); // for Cy3 ch1CB.setBackground(Color.green); ch1CB.setBorder(low); ch1CB.setBorderPainted(false); ch1CB.setSelected(true); ch1CB.addItemListener(this); ch2CB = new JCheckBox(); ch2CB.setBackground(Color.red); ch2CB.setBorder(low); ch2CB.setBorderPainted(false); ch2CB.addItemListener(this); btnGroup = new ButtonGroup(); btnGroup.add(ch1CB); btnGroup.add(ch2CB); ch1FileList = new JList(); ch1FileList.setBorder(low); ch1FileList.addMouseListener(this); handleList(ch1FileList); ch1FileSP = new JScrollPane(ch1FileList); ch1FileSP.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); ch2FileList = new JList(); ch2FileList.setBorder(low); ch2FileList.addMouseListener(this); handleList(ch2FileList); ch2FileSP = new JScrollPane(ch2FileList); ch2FileSP.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); inputSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, ch1FilePL, ch2FilePL); inputSplitPane.setSize(sizeX-20, (sizeY-100)>>1); inputSplitPane.setDividerSize(4); inputSplitPane.setDividerLocation(0.5); inputFilesSP = new JScrollPane(inputSplitPane); upBtn = new JButton(upIcon); upBtn.setToolTipText("Move up the selected file by one line."); upBtn.setBorder(high); upBtn.setPreferredSize(btnSize); upBtn.setMaximumSize(btnSize); upBtn.setMinimumSize(btnSize); upBtn.addActionListener(this); downBtn = new JButton(downIcon); downBtn.setToolTipText("Move down the selected file by one line."); downBtn.setBorder(high); downBtn.setPreferredSize(btnSize); downBtn.setMaximumSize(btnSize); downBtn.setMinimumSize(btnSize); downBtn.addActionListener(this); leftBtn = new JButton(leftIcon); leftBtn.setToolTipText("Move the selected file to the left list."); leftBtn.setBorder(high); leftBtn.setPreferredSize(btnSize); leftBtn.setMaximumSize(btnSize); leftBtn.setMinimumSize(btnSize); leftBtn.addActionListener(this); rightBtn = new JButton(rightIcon); rightBtn.setToolTipText("Move the selected file to the right list."); rightBtn.setBorder(high); rightBtn.setPreferredSize(btnSize); rightBtn.setMaximumSize(btnSize); rightBtn.setMinimumSize(btnSize); rightBtn.addActionListener(this); keepAllCB = new JCheckBox("Keep Gene ID for Manually Checking."); keepAllCB.setToolTipText("Attach the gene id at the end of each spot."); keepAllCB.setSelected(keepAll); keepAllCB.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ce){ if(keepAllCB.isSelected()){ keepAll = true; } else { keepAll = false; } } }); tavPanel = new JPanel(); tavPanel.setLayout(new GridBagLayout()); tavPanel.setPreferredSize(new Dimension(sizeX-10, (sizeY-120)>>1)); outputFileList = new JList(); outputFileList.setBorder(low); outputFileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); handleList(outputFileList); fileNumLB = new JLabel(NUM_FILE); fileNumLB.setBorder(low); tFilesSP = new JScrollPane(outputFileList); fileSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, genePanel, tavPanel); fileSplitPane.setDividerSize(4); fileSplitPane.setSize(sizeX-10, (sizeY)>>1); fileSplitPane.setPreferredSize(new Dimension(sizeX-10, (sizeY-130)>>1)); fileSplitPane.setDividerLocation(0.5); gba.add(this, fileSplitPane, 0, 0, 2, 1, 1, 1, GBA.B, GBA.C, 5, 5, 10, 5); gba.add(this, sortCB, 0, 1, 1, 1, 1, 0, GBA.H, GBA.C, 10, 15, 3, 5); gba.add(this, keepAllCB, 0, 2, 1, 1, 1, 0, GBA.H, GBA.C, 3, 15, 3, 5); gba.add(this, gIntenPanel, 1, 1, 1, 2, 1, 0, GBA.H, GBA.W, 10, 0, 3, 5); gba.add(ch1FilePL, igFileLB, 0, 0, 1, 1, 1, 0, GBA.H, GBA.C, 5, 10, 5, 2); gba.add(ch1FilePL, ch1FileLB, 1, 0, 1, 1, 0, 0, GBA.NONE, GBA.E, 5, 10, 5, 2); gba.add(ch1FilePL, ch1CB, 2, 0, 1, 1, 0, 0, GBA.NONE, GBA.E, 5, 1, 5, 5); gba.add(ch1FilePL, ch1FileSP, 0, 1, 3, 1, 1, 1, GBA.B, GBA.C, 5, 2, 5, 0); gba.add(ch2FilePL, new JLabel(" "), 0, 0, 1, 1, 1, 0, GBA.H, GBA.C, 5, 10, 5, 2); gba.add(ch2FilePL, ch2FileLB, 1, 0, 1, 1, 0, 0, GBA.NONE, GBA.E, 5, 10, 5, 2); gba.add(ch2FilePL, ch2CB, 2, 0, 1, 1, 0, 0, GBA.NONE, GBA.E, 5, 1, 5, 5); gba.add(ch2FilePL, ch2FileSP, 0, 1, 3, 1, 1, 1, GBA.B, GBA.C, 5, 0, 5, 2); gba.add(genePanel, inputFilesSP, 0, 0, 1, 1, 1, 1, GBA.B, GBA.C, 1, 2, 1, 2); gba.add(genePanel, pairButtonPL, 0, 1, 1, 1, 1, 0, GBA.H, GBA.C, 3, 2, 5, 2); gba.add(pairButtonPL, upBtn, 0, 0, 1, 1, 0, 0, GBA.NONE, GBA.C, 1, 10, 1, 5); gba.add(pairButtonPL, downBtn, 1, 0, 1, 1, 0, 0, GBA.NONE, GBA.C, 1, 5, 1, 5); gba.add(pairButtonPL, leftBtn, 2, 0, 1, 1, 0, 0, GBA.NONE, GBA.C, 1, 5, 1, 5); gba.add(pairButtonPL, rightBtn, 3, 0, 1, 1, 0, 0, GBA.NONE, GBA.C, 1, 5, 1, 10); gba.add(tavPanel, outputFileLB, 0, 0, 1, 1, 1, 0, GBA.H, GBA.W, 5, 10, 2, 2); gba.add(tavPanel, tFilesSP, 0, 1, 1, 1, 1, 1, GBA.B, GBA.C, 1, 2, 5, 2); gba.add(tavPanel, fileNumLB, 0, 2, 1, 1, 1, 0, GBA.H, GBA.C, 1, 2, 5, 2); } /*************************************************************************** * Description: Description: * activate the buttons based on the contents of a JList object. *

Parameter: *
l -- the Jlist object that emit the action event. **************************************************************************/ private void handleList(JList l){ final JList list = l; list.addListSelectionListener(new ListSelectionListener(){ public void valueChanged(ListSelectionEvent lse){ setOuputSituation(); } }); } /**************************************************************************** * Description: * assigns outputReady and active parent buttons ***************************************************************************/ private void setOuputSituation(){ int numCh1, numCh2, numOut; numCh1 = ch1FileList.getModel().getSize(); numCh2 = ch2FileList.getModel().getSize(); numOut = outputFileList.getModel().getSize(); if(numOut > 0 || numCh1 > 0 || numCh2 > 0){ dirtyData = true; } else { dirtyData = false; } if(numOut > 0 && numCh1 == numCh2){ outputReady = true; } else { outputReady = false; } parent.activateButton(outputReady, dirtyData); } /************************************************************************** * Description: * moves the selected file between the two lists. ***************************************************************************/ private void moveBetweenLists(){ String tempName = new String(""); String tempOut = new String(""); int indx = 0; if(ch1Selected && selectedCh1Files.size() > 0){ indx = ch1FileList.getSelectedIndex(); if(indx >= 0){ tempName = (String)selectedCh1Files.remove(indx); tempOut = (String)outputFileNames.remove(indx); if(!selectedCh2Files.contains(tempName)){ if(indx < selectedCh2Files.size()){ selectedCh2Files.insertElementAt(tempName, indx); } else { selectedCh2Files.add(tempName); } ch2FileList.setListData(selectedCh2Files); } ch1FileList.setListData(selectedCh1Files); ch1FileList.setSelectedIndex(indx); outputFileList.setListData(outputFileNames); ch2FileList.setSelectedIndex(ch1FileList.getSelectedIndex()); } } else if(!ch1Selected && selectedCh2Files.size() > 0){ indx = ch2FileList.getSelectedIndex(); if(indx >= 0){ tempName = (String)selectedCh2Files.remove(indx); if(!selectedCh1Files.contains(tempName)){ if(indx < selectedCh1Files.size()){ selectedCh1Files.insertElementAt(tempName, indx); outputFileNames.insertElementAt(IOUtil.dropExtension(tempName) + "." + FILE_TYPE[outputType], indx); } else { selectedCh1Files.add(tempName); outputFileNames.add(IOUtil.dropExtension(tempName) + "." + FILE_TYPE[outputType]); } ch1FileList.setListData(selectedCh1Files); } ch2FileList.setListData(selectedCh2Files); ch2FileList.setSelectedIndex(indx); outputFileList.setListData(outputFileNames); ch1FileList.setSelectedIndex(ch2FileList.getSelectedIndex()); } } if(outputFileNames.size() > 0){ outputFileList.setSelectedIndex(0); fileNumLB.setText(NUM_FILE + selectedCh1Files.size()); } else { fileNumLB.setText(NUM_FILE); } } /*************************************************************************** * Description: * move the selected file up or down in the list. *

Parameter: *
up -- a boolean indicates up or down. **************************************************************************/ private void moveWithinList(boolean up){ String tempName = new String(""); String tempOut = new String(""); int indx = 0; if(ch1Selected && selectedCh1Files.size() > 0){ // moving channel 1 files needs to adjust output file list. indx = ch1FileList.getSelectedIndex(); if(up){ if(indx > 0){ tempName = (String)selectedCh1Files.remove(indx); tempOut = (String)outputFileNames.remove(indx); selectedCh1Files.insertElementAt(tempName, indx-1); outputFileNames.insertElementAt(tempOut, indx-1); ch1FileList.setListData(selectedCh1Files); ch1FileList.setSelectedIndex(indx-1); outputFileList.setListData(outputFileNames); } } else { // moving down if(indx < selectedCh1Files.size()-1){ tempName = (String)selectedCh1Files.remove(indx); tempOut = (String)outputFileNames.remove(indx); selectedCh1Files.insertElementAt(tempName, indx+1); outputFileNames.insertElementAt(tempOut, indx+1); ch1FileList.setListData(selectedCh1Files); ch1FileList.setSelectedIndex(indx+1); outputFileList.setListData(outputFileNames); } } ch2FileList.setSelectedIndex(ch1FileList.getSelectedIndex()); } else if (selectedCh2Files.size() > 0){ // moving channel 2 files does not need to adjust output file list. indx = ch2FileList.getSelectedIndex(); if(up){ if(indx > 0){ tempName = (String)selectedCh2Files.remove(indx); selectedCh2Files.insertElementAt(tempName, indx-1); ch2FileList.setListData(selectedCh2Files); ch2FileList.setSelectedIndex(indx-1); } } else { // moving down if(indx < selectedCh2Files.size()-1){ tempName = (String)selectedCh2Files.remove(indx); selectedCh2Files.insertElementAt(tempName, indx+1); ch2FileList.setListData(selectedCh2Files); ch2FileList.setSelectedIndex(indx+1); } } ch1FileList.setSelectedIndex(ch2FileList.getSelectedIndex()); } if(outputFileNames.size() > 0){ outputFileList.setSelectedIndex(0); } } /*************************************************************************** * Description: * removes a set of files from the selected list. ***************************************************************************/ public void removeFileFromList(){ int addrs[], i, indx; if(selectedCh1Files.size() > 0){ addrs = ch1FileList.getSelectedIndices(); if(addrs.length > 0){ for(i=0; i 0){ outputFileList.setSelectedIndex(0); fileNumLB.setText(NUM_FILE + selectedCh1Files.size()); } else { fileNumLB.setText(NUM_FILE); } } } } /**************************************************************************** * Description: * set the interface to its original status. **************************************************************************/ public void reset(){ selectedCh1Files.removeAllElements(); selectedCh2Files.removeAllElements(); outputFileNames.removeAllElements(); fileNumLB.setText(NUM_FILE); ch1FileList.setListData(selectedCh1Files); ch2FileList.setListData(selectedCh2Files); outputFileList.setListData(outputFileNames); wantSort = true; keepAll = false; ch1Selected = true; outputReady = false; dirtyData = false; sortCB.setSelected(wantSort); keepAllCB.setSelected(keepAll); ch1CB.setSelected(ch1Selected); parent.activateButton(outputReady, dirtyData); } public Vector getOutputFileNames() { return outputFileNames; } public Vector getSelectedChAFiles() { return selectedCh1Files; } public Vector getSelectedChBFiles() { return selectedCh2Files; } public boolean isOutputReady() { return outputReady; } public boolean isDataDirty() { return dirtyData; } /*************************************************************************** * Description: * overrides the abstract method to handle even from check box. **************************************************************************/ public void itemStateChanged(ItemEvent ie){ if(ie.getSource() == ch1CB && ie.getStateChange() == ItemEvent.SELECTED){ ch1Selected = true; } else if(ie.getSource() == ch2CB && ie.getStateChange() == ItemEvent.SELECTED){ ch1Selected = false; } adjustInputSelection(ch1Selected); } /************************************************************************** * Description: * overrides the abastract method to handle event from mouse. *************************************************************************/ public void mouseClicked(MouseEvent me){ if(me.getSource() == ch1FileList){ ch2FileList.setSelectedIndex(ch1FileList.getSelectedIndex()); } else { ch1FileList.setSelectedIndex(ch2FileList.getSelectedIndex()); } } public void mouseEntered(MouseEvent me){} public void mouseExited(MouseEvent me){} public void mousePressed(MouseEvent me){} public void mouseReleased(MouseEvent me){} /*************************************************************************** * Description: * places the selected file names to both input and output file lists. **************************************************************************/ public void setSelectedFiles(String[] newFiles){ int num, i; String temp = new String(""); num = newFiles.length; if(ch1Selected){ for(i=0; iDescription: * check if an entered file is qualified for saving. *

Parameter: *
fName -- the file name. *
needTest -- indicates if the passed file name need to be tested. *

Return: the test results: -1 -- quit; 0 -- no overwrite; * 1 -- overwrite one file; 2 -- overwrite all files. **************************************************************************/ private int validFile(String fName, boolean needTest){ String name = new String(fName); String folder = new String(""); int confirm = 1; JFrame jf = new JFrame(); File targFile = null; folder = IOUtil.extractPath(name); folder = IOUtil.makeDir(folder); if(needTest){ targFile = new File(name); if(targFile.exists()) { jf.getToolkit().beep(); } } else { confirm = 2; } return confirm; } }