/* Copyright @ 2003-2004, The Institute for Genomic Research (TIGR). All rights reserved. */ /*************************************************************************** * Author: Jerry Li * Name: CustomerPanel (Version 1.0) * Date: Created: 09/29/2004 and modified: 10/06/2004 * Descp: the interface for customized file as an input for the ExpressConveter ***************************************************************************/ package org.tigr.microarray.converter; import java.awt.*; import java.awt.datatransfer.*; import java.awt.dnd.*; import java.awt.event.*; import java.beans.*; import java.io.*; import java.util.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; import javax.swing.table.*; import org.tigr.microarray.*; import org.tigr.util.*; import org.tigr.util.awt.*; import org.tigr.util.formula.*; import org.tigr.util.io.*; import org.tigr.util.swing.*; import org.tigr.util.swing.InputHeaderSelector; public class CustomerPanel extends ConvertPanel implements PropertyChangeListener, DropTargetListener, ItemListener, MouseListener, MevAttributes, Variant, ChangeListener, ListSelectionListener { private final Font smallFont = new Font("Arial", Font.PLAIN, 11); private Icon gAddIcon, gCellCleanIcon, gDivIcon, gHeaderSelIcon, gLeftBraceIcon; private Icon gMulIcon, gRightBraceIcon, gSubIcon; private JCheckBox gAnnClearAllCB, gClearAllCB; private JLabel gAnnHeaderLB, gMevHeaderLB, gInHeaderLB; private JList gAnnColList; private JPanel gSymbolPL, gHeaderPL, gInHeaders, gMevHeaderPL, gAnnHeaderPL; private JScrollPane gAnnColSP, gMevColSP, gInputColSP; private JTable gMevCol; private JTabbedPane gMevTP; private MessageDropper gAdd, gCellClean, gDiv, gHeaderSel, gLeftBrace, gMul, gRightBrace, gSub; private MessageDropper[] gInputHeaders; private MevTableModel gMtm; private MultiInputOutputs inOut; private final String ADD = "+"; private final String CLEAR = "c"; private final String DIV = "/"; private final String HEADER = "h"; private final String LEFT_BRACE = "("; private final String MEV_HEADER[] = {UID, IA, IB, R, C, MR, MC, SR, SC, BKGA, BKGB, FLAGA, FLAGB, SAA, SAB, QC_SCORE, QCA, QCB, SDA, SDB, MEDA, MEDB}; private final String MUL = "*"; private final String RIGHT_BRACE = ")"; private final String SUB = "-"; private final String gHdType[] = {"ech"}; private boolean gAnnTab, gClearAllMev, gClearAllAnn, gHeaderReady, gHeaderSelected; private DropTarget gDropTarget, gAnnDrop; private int gSelMevCol, gSelInputCol, gInHeaderAddr; private int[] gSelAnnHdx; private String[] gEquation, gEqShow, gHeader; private String[][] gMevColData; private Vector gAnnCols, gAnnColShow; public CustomerPanel() { this(null); } public CustomerPanel(ExpressConverter ec) { super(ec); gHeaderReady = false; gHeaderSelected = false; gClearAllMev = false; gClearAllAnn = false; gAnnTab = false; gSelMevCol = 0; gSelInputCol = -1; gInHeaderAddr = -1; gMevColData = new String[1][MEV_HEADER.length]; gEquation = new String[MEV_HEADER.length]; gEqShow = new String[MEV_HEADER.length]; for(int i=0; iDescription: * 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; inOut.setOutputLabel("MEV Files:"); 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: *
inFiles -- the input files. *
outFiles -- the output files. ***************************************************************************/ public void changeFileList(Vector inFiles, Vector outFiles){ selectedFiles = inFiles; outputFileNames = outFiles; inOut.setInputListData(inFiles); inOut.setOutputListData(outFiles); inOut.showNumberOfFiles(selectedFiles.size()); } /*************************************************************************** * Description: * overrides the abstract methodh to handle drop conseqenece. **************************************************************************/ public void drop(DropTargetDropEvent e) { if(e.getSource() == gDropTarget){ updateMevHeader(e); } else if(e.getSource() == gAnnDrop){ updateAnnHeader(e); } } public void dropActionChanged(DropTargetDragEvent e) { } public void dragEnter(DropTargetDragEvent e) {} public void dragExit(DropTargetEvent e) { } public void dragOver(DropTargetDragEvent e) {} /**************************************************************************** * 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 = inOut.getSelectedOutputIndex(); num = outputFileNames.size(); for(int i=0; i=0){ inOut.setOutputSelectedIndex(selected); } else { inOut.setOutputSelectedIndex(0); } } /**************************************************************************** * Description: * modifies the output file names. ***************************************************************************/ public void editFileName(){ int selected = -1; String tempName; selected = inOut.getSelectedOutputIndex(); if(selected >= 0){ tempName = inOut.getSelectedOutputName(selected); LongTextChanger changer = new LongTextChanger(parent, true, tempName); changer.setTitle(parent.TITLE); 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); inOut.setOutputListData(outputFileNames); inOut.setOutputSelectedIndex(selected); } } } public String[] getConvertEquations() { return gEquation; } public String[] getInputHeaders() { return gHeader; } public int getInputHeaderOffset(){ return gInHeaderAddr; } public String[] getMevHeaders() { return MEV_HEADER; } public Vector getOutputFileNames() { return outputFileNames; } public boolean getOutputReady() { return inOut.isOutputReady(); } public Vector getSelectedFiles() { return selectedFiles; } /************************************************************************** * Description: * returns the offsets of those columns in input file for ann. **************************************************************************/ public int[] getSelecteColumnForAnn() { int num = gAnnCols.size(); int[] temp = new int[num]; for(int i=0; iDescription: * validate the equations defined by users. *

Return: true if they are valid; otherwise, false. **************************************************************************/ public boolean isValidEquation(){ boolean res = true; String eq[] = null; for(int i=0; i 1){ if(!parenthesisPaired(gEquation[i])){ showError("Invalid parenthesis in " + gEqShow[i]); return false; } if(isOperator(gEquation[i].charAt(gEquation[i].length()-1))){ showError("Uncompleted formula: " + gEqShow[i]); return false; } } } return res; } public void itemStateChanged(ItemEvent ie){ if(ie.getSource() == gClearAllCB){ if(ie.getStateChange() == ItemEvent.SELECTED){ gClearAllMev = true; } else { gClearAllMev = false; } } else if(ie.getSource() == gAnnClearAllCB){ if(ie.getStateChange() == ItemEvent.SELECTED){ gClearAllAnn = true; } else { gClearAllAnn = false; } } } /**************************************************************************** * Descripiton: * Open the header file to load saved header information. *

Parameter: *
file -- the header file. *************************************************************************/ public void loadHeader(File file){ FileInputStream fis; ObjectInputStream ois; CustomerHeader ch; String temp; try{ fis = new FileInputStream(file); ois = new ObjectInputStream(fis); ch = (CustomerHeader)ois.readObject(); gInHeaderAddr = ch.getHeaderOffset(); gHeader = ch.getHeaders(); gEquation = ch.getFormula(); gEqShow = ch.getReadibleFormula(); gAnnColShow = ch.getAnnColumn(); gAnnCols = ch.getAnnColumnIndices(); initInputHeader(); for(int i=0; i 0){ gMevCol.setValueAt(temp, 0, i); } } gAnnColList.setListData(gAnnColShow); this.validate(); toolsReady(); } catch (FileNotFoundException fnfx){ showError("Failed to find the file " + file.getName()); parent.logFileContent.add("\n***********\n" + "Failed to find the file " + file.getPath() + "due to:\n" + fnfx.toString()); } catch (IOException ie){ showError("Failed to open/read the file " + file.getName()); parent.logFileContent.add("\n***********\n" + "Failed to open/read the file " + file.getPath() + "due to:\n" + ie.toString()); } catch (ClassNotFoundException ce){ showError("Failed to read " + file.getName()); parent.logFileContent.add("\n***********\n" + "Failed to read the file " + file.getPath() + "due to:\n" + ce.toString()); } } /**************************************************************************** * Description: * overrides the abastrat method to handle moues event. ***************************************************************************/ public void mouseClicked(MouseEvent me){ gSelMevCol = gMevCol.getSelectedColumn(); } public void mouseEntered(MouseEvent me) {} public void mouseExited(MouseEvent me){} /**************************************************************************** * Description: * overrides the abastrat method to handle moues event. ***************************************************************************/ public void mousePressed(MouseEvent me) { if(me.getSource() != gMevCol){ gSelInputCol = getInputSelectedColum(((MessageDropper)me.getSource()).getName()); } } public void mouseReleased(MouseEvent me) {} /*************************************************************************** * Description: * overrides the abstract method to hand event. **************************************************************************/ public void propertyChange(PropertyChangeEvent pce){ String pName = pce.getPropertyName(); if(pName.equals(inOut.OUT_READY)){ if(pce.getNewValue().toString().equals("true") && gHeaderReady){ parent.activateButton(inOut.isOutputReady(), inOut.isOutputReady()); } } else if (pName.equals(HEADER)){ if(selectedFiles.size() > 0){ setInputHeader((String)selectedFiles.elementAt(0)); } } else if (pName.equals(CLEAR)){ if(gAnnTab){ clearAnnHeader(gClearAllAnn); } else { clearEquations(gClearAllMev); } } } /*************************************************************************** * Description: * removes a set of files from the selected list. ***************************************************************************/ public void removeFileFromList(){ int addrs[], i, indx; addrs = inOut.getSelectedInputIndices(); if(addrs.length > 0){ for(i=0; i 0){ inOut.setOutputSelectedIndex(0); } inOut.showNumberOfFiles(selectedFiles.size()); } } /**************************************************************************** * Descripiton: * save the header information to a file for Customize conversion. **************************************************************************/ public String saveHeader(String dir){ CustomerHeader header = new CustomerHeader(parent.getVersion()); File file; FileOutputStream fos; ObjectOutputStream hdOut; int result; String fName, tempName[]; JFileChooser fileChooser = new JFileChooser(dir); MadamFileFilter wanted = new MadamFileFilter(gHdType, "Customer Header File"); fileChooser.setFileFilter(wanted); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setMultiSelectionEnabled(false); fileChooser.setDialogTitle(parent.TITLE + " -- Saving a header file"); result = fileChooser.showSaveDialog(this); if(result == JFileChooser.CANCEL_OPTION || result < 0){ return dir; } file = fileChooser.getSelectedFile(); fName = file.getPath(); dir = IOUtil.extractPath(fName); fName = IOUtil.dropExtension(fName); fName += "." + gHdType[0]; result = parent.validFile(fName, true, ConfirmUsers.YES_NO_CANCEL); if(result <= 0){ return dir; } header.setFormula(gEquation); header.setReadilbeFormula(gEqShow); header.setAnnColumn(gAnnColShow); header.setAnnColumnIndices(gAnnCols); header.setHeaderOffset(gInHeaderAddr); header.setHeaders(gHeader); try{ fos = new FileOutputStream(fName); hdOut = new ObjectOutputStream(fos); hdOut.writeObject(header); hdOut.flush(); hdOut.close(); } catch (IOException ie){ parent.logFileContent.add("\n***********\n" + "Error in saving header info: " + ie.toString()); } return dir; } /*************************************************************************** * 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; for(i=0; iDescription: * set the interface to its original status. **************************************************************************/ public void reset(){ selectedFiles.removeAllElements(); outputFileNames.removeAllElements(); inOut.showNumberOfFiles(0); inOut.setInputListData(selectedFiles); inOut.setOutputListData(outputFileNames); sortCB.setSelected(true); wantSort = true; outputReady = false; gClearAllMev = false; gClearAllAnn = false; gHeaderReady = false; gHeaderSelected = false; clearEquations(true); clearAnnHeader(true); gInHeaders.removeAll(); gInHeaders.repaint(); this.validate(); } /*************************************************************************** * Description: * overrides the abstract method to handle the change event. **************************************************************************/ public void stateChanged(ChangeEvent ce){ if(gMevTP.getSelectedComponent() == gMevHeaderPL){ gAnnTab = false; } else { gAnnTab = true; } } /*************************************************************************** * Description: * overrides the abstract method to handle the ListSelectionEvent. **************************************************************************/ public void valueChanged(ListSelectionEvent lse){ gSelAnnHdx = gAnnColList.getSelectedIndices(); } /************************************************************************** * Description: * create an interface. ***************************************************************************/ protected void createGUI(){ int sizeX = (int)(parent.scrWidth * 0.83); int sizeY = (int)(parent.scrHeight * 0.70); BevelBorder low = new BevelBorder(1); Dimension iconSize = new Dimension(19, 19); this.setLayout(new GridBagLayout()); gHeaderSelIcon = new ImageIcon(Toolkit.getDefaultToolkit(). getImage(ClassLoader.getSystemResource("images/selheader.gif"))); gCellCleanIcon = new ImageIcon(Toolkit.getDefaultToolkit(). getImage(ClassLoader.getSystemResource("images/cellerase.gif"))); gAddIcon = new ImageIcon(Toolkit.getDefaultToolkit(). getImage(ClassLoader.getSystemResource("images/add.gif"))); gSubIcon = new ImageIcon(Toolkit.getDefaultToolkit(). getImage(ClassLoader.getSystemResource("images/minus.gif"))); gMulIcon = new ImageIcon(Toolkit.getDefaultToolkit(). getImage(ClassLoader.getSystemResource("images/multip.gif"))); gDivIcon = new ImageIcon(Toolkit.getDefaultToolkit(). getImage(ClassLoader.getSystemResource("images/divsion.gif"))); gLeftBraceIcon = new ImageIcon(Toolkit.getDefaultToolkit(). getImage(ClassLoader.getSystemResource("images/lbrace.gif"))); gRightBraceIcon = new ImageIcon(Toolkit.getDefaultToolkit(). getImage(ClassLoader.getSystemResource("images/rbrace.gif"))); gSymbolPL = new JPanel(new GridBagLayout()); gHeaderPL = new JPanel(new GridBagLayout()); // set-up the icons gHeaderSel = new MessageDropper(gHeaderSelIcon); gHeaderSel.setPreferredSize(iconSize); gHeaderSel.setName(HEADER); gHeaderSel.setToolTipText("Select the header from your input file."); gHeaderSel.addPropertyChangeListener(this); gCellClean = new MessageDropper(gCellCleanIcon); gCellClean.setPreferredSize(iconSize); gCellClean.setName(CLEAR); gCellClean.setToolTipText("Clear the header matches."); gCellClean.addPropertyChangeListener(this); gAdd = new MessageDropper(gAddIcon, ADD); gAdd.setPreferredSize(iconSize); gAdd.setName(ADD); gAdd.setToolTipText("Add addtion symbol."); gSub = new MessageDropper(gSubIcon, SUB); gSub.setPreferredSize(iconSize); gSub.setName(SUB); gSub.setToolTipText("Add subtraction symbol."); gMul = new MessageDropper(gMulIcon, MUL); gMul.setPreferredSize(iconSize); gMul.setName(MUL); gMul.setToolTipText("Add multiplication symbol."); gDiv = new MessageDropper(gDivIcon, DIV); gDiv.setPreferredSize(iconSize); gDiv.setName(DIV); gDiv.setToolTipText("Add division symbol."); gLeftBrace = new MessageDropper(gLeftBraceIcon, LEFT_BRACE); gLeftBrace.setPreferredSize(iconSize); gLeftBrace.setName(LEFT_BRACE); gLeftBrace.setToolTipText("Add left parenthesis."); gRightBrace = new MessageDropper(gRightBraceIcon, RIGHT_BRACE); gRightBrace.setPreferredSize(iconSize); gRightBrace.setName(RIGHT_BRACE); gRightBrace.setToolTipText("Add right parenthesis."); // set-up the mev header definer gMevHeaderPL = new JPanel(new GridBagLayout()); gAnnHeaderPL = new JPanel(new GridBagLayout()); gMevTP = new JTabbedPane(JTabbedPane.LEFT); gMevTP.add("Mev", gMevHeaderPL); gMevTP.add("Ann", gAnnHeaderPL); gMevTP.addChangeListener(this); gMevHeaderLB = new JLabel("Header:"); gClearAllCB = new JCheckBox("Clean All:"); gClearAllCB.setHorizontalTextPosition(JCheckBox.LEFT); gClearAllCB.setFont(smallFont); gClearAllCB.setBorder(low); gClearAllCB.addItemListener(this); gMtm = new MevTableModel(gMevColData, MEV_HEADER); gMevCol = new JTable(gMtm); gMevCol.setRowHeight(23); gMevCol.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); gMevCol.setDragEnabled(false); gMevCol.getTableHeader().setReorderingAllowed(false); gMevCol.setSelectionBackground(Color.white); gMevCol.setSelectionForeground(Color.black); gMevCol.addMouseListener(this); gMevColSP = new JScrollPane(gMevCol, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); gMevColSP.setBorder(low); gAnnHeaderLB = new JLabel("Header:"); gAnnClearAllCB = new JCheckBox("Clean All:"); gAnnClearAllCB.setHorizontalTextPosition(JCheckBox.LEFT); gAnnClearAllCB.setFont(smallFont); gAnnClearAllCB.setBorder(low); gAnnClearAllCB.addItemListener(this); gAnnColList = new JList(); gAnnColList.setVisibleRowCount(1); gAnnColList.setCellRenderer(new AnnCellRenderer()); gAnnColList.setLayoutOrientation(JList.HORIZONTAL_WRAP); gAnnColList.addListSelectionListener(this); gAnnColSP = new JScrollPane(gAnnColList, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); gAnnColSP.setBorder(low); gInHeaderLB = new JLabel("Input Header:"); gInHeaders = new JPanel(new GridBagLayout()); gInputSP = new JScrollPane(gInHeaders, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); gInputSP.setBorder(low); gDropTarget = new DropTarget(gMevCol, DnDConstants.ACTION_COPY_OR_MOVE, this); gAnnDrop = new DropTarget(gAnnColList, DnDConstants.ACTION_COPY_OR_MOVE, this); inOut = new MultiInputOutputs(sizeX, sizeY); inOut.setLabelTexts("Files to be Converted:", "MEV Files:"); inOut.setDividerLocation(0.3); inOut.addPropertyChangeListener(this); gIntenPanel.remove(emptyLB); gIntenPanel.remove(gBkgCB); gba.add(this, gSymbolPL, 0, 0, 2, 1, 1, 0, GBA.H, GBA.W, 5, 55, 5, 5); gba.add(this, gHeaderPL, 0, 1, 2, 1, 1, 0, GBA.H, GBA.C, 0, 5, 5, 5); gba.add(this, inOut, 0, 2, 2, 2, 1, 1, GBA.B, GBA.C, 5, 5, 10, 5); gba.add(this, sortCB, 0, 4, 1, 1, 1, 0, GBA.H, GBA.C, 10, 15, 3, 5); gba.add(this, gIntenPanel, 1, 4, 1, 2, 1, 0, GBA.H, GBA.W, 10, 0, 3, 5); gba.add(gSymbolPL, gHeaderSel, 0, 0, 1, 1, 0, 0, GBA.NONE, GBA.W, 4, 5, 5, 1); gba.add(gSymbolPL, gCellClean, 1, 0, 1, 1, 0, 0, GBA.NONE, GBA.W, 4, 1, 5, 1); gba.add(gSymbolPL, gAdd, 2, 0, 1, 1, 0, 0, GBA.NONE, GBA.W, 4, 1, 5, 1); gba.add(gSymbolPL, gSub, 3, 0, 1, 1, 0, 0, GBA.NONE, GBA.W, 4, 1, 5, 1); gba.add(gSymbolPL, gMul, 4, 0, 1, 1, 0, 0, GBA.NONE, GBA.W, 4, 1, 5, 1); gba.add(gSymbolPL, gDiv, 5, 0, 1, 1, 0, 0, GBA.NONE, GBA.W, 4, 1, 5, 1); gba.add(gSymbolPL, gLeftBrace, 6, 0, 1, 1, 0, 0, GBA.NONE, GBA.W, 4, 1, 5, 1); gba.add(gSymbolPL, gRightBrace, 7, 0, 1, 1, 0, 0, GBA.NONE, GBA.W, 4, 1, 5, 1); gba.add(gSymbolPL, new JLabel(" "), 8, 0, 1, 1, 1, 0, GBA.H, GBA.W, 4, 1, 5, 5); gba.add(gHeaderPL, gMevTP, 0, 0, 2, 1, 1, 1, GBA.B, GBA.C, 0, 0, 0, 5); gba.add(gHeaderPL, gInHeaderLB, 0, 1, 1, 1, 0, 0, GBA.NONE, GBA.W, 5, 5, 5, 5); gba.add(gHeaderPL, gInputSP, 1, 1, 1, 2, 1, 1, GBA.B, GBA.W, 5, 5, 5, 5); gba.add(gHeaderPL, new JLabel(" "), 0, 2, 1, 1, 0, 0, GBA.NONE, GBA.W, 5, 5, 5, 5); gba.add(gMevHeaderPL, gMevHeaderLB, 0, 0, 1, 1, 0, 0, GBA.NONE, GBA.W, 4, 5, 5, 5); gba.add(gMevHeaderPL, gMevColSP, 1, 0, 1, 3, 1, 1, GBA.B, GBA.W, 2, 5, 5, 5); gba.add(gMevHeaderPL, gClearAllCB, 0, 1, 1, 1, 0, 0, GBA.NONE, GBA.W, 1, 5, 5, 5); gba.add(gMevHeaderPL, new JLabel(" "), 0, 2, 1, 1, 0, 0, GBA.NONE, GBA.W, 1, 5, 1, 5); gba.add(gAnnHeaderPL, gAnnHeaderLB, 0, 0, 1, 1, 0, 0, GBA.NONE, GBA.W, 4, 5, 5, 5); gba.add(gAnnHeaderPL, gAnnColSP, 1, 0, 1, 2, 1, 1, GBA.B, GBA.W, 2, 0, 0, 5); gba.add(gAnnHeaderPL, gAnnClearAllCB, 0, 1, 1, 1, 0, 0, GBA.NONE, GBA.W, 1, 5, 5, 5); gba.add(gAnnHeaderPL, new JLabel(" "), 0, 2, 1, 1, 0, 0, GBA.NONE, GBA.W, 1, 5, 1, 5); } /*************************************************************************** * Description: * checks if the passed character is an operator. *

Parameters: *
ch -- the character. *

Return: true if it is; otherwise, false. **************************************************************************/ private boolean isOperator(char ch){ boolean yes = false; int numOps = 4; for(int i=0; iDescription: * check if an entry for an equation is legal. *

Parameter: *
entry -- the entry *
eq -- the equation to which the entry will be conctanated. *

Return: 0: legal enty, otherwise, invalid entry. **************************************************************************/ private int isRightEntry(String entry, String eq){ char eqEnd; int right = 0; int eqLength = eq.length(); boolean inSym = false; boolean eqSym = false; boolean inRb = false; boolean inLb = false; boolean eqRb = false; boolean eqLb = false; if(entry.equals(ADD) || entry.equals(SUB) || entry.equals(MUL) || entry.equals(DIV)){ inSym = true; } else if(entry.equals(LEFT_BRACE)){ inLb = true; } else if(entry.equals(RIGHT_BRACE)){ inRb = true; } if(eqLength < 1 && !inSym && !inRb){ return right; } if(inRb && parenthesisPaired(eq)){ return 3; } if(eqLength > 0){ eqEnd = eq.charAt(eq.length()-1); if(eqEnd == '+' || eqEnd == '-' || eqEnd == '*' || eqEnd == '/'){ eqSym = true; } else if(eqEnd == '('){ eqLb = true; } else if(eqEnd == ')'){ eqRb = true; } } if(inSym && eqSym && !inRb && !eqLb){ right = 1; } else if(!inSym && !eqSym &&!inRb && !inLb && !eqLb){ right = 2; } else if((eqLength < 1 && (inRb || inSym)) || (!eqSym && inLb && !eqLb) || (eqLb && (inSym || inRb)) || (eqSym && inRb)){ right = 3; } else { right = 0; } return right; } /************************************************************************** * Description: * presents the header names of input files **************************************************************************/ private void initInputHeader(){ int count; String temp; gInputHeaders = new MessageDropper[gHeader.length]; gInHeaders.removeAll(); gInHeaders.repaint(); count = 0; for(int i=0; iDescription: * check if a drop object is a math symbol. *

Parameter: *
dropIn -- the what has been dropped. *

Return: true if it is; otherwise, false. ***************************************************************************/ private boolean isMathSymbol(String dropIn){ if(dropIn.equals(ADD) || dropIn.equals(SUB) || dropIn.equals(MUL) || dropIn.equals(DIV) || dropIn.equals(LEFT_BRACE) || dropIn.equals(RIGHT_BRACE)){ return true; } else { return false; } } /************************************************************************** * Description: * enables the Sort checkbox. *

Parameter: *
b -- the boolean value. **************************************************************************/ private void activateSort(boolean b) { wantSort = b; sortCB.setEnabled(wantSort); } /*************************************************************************** * Description: * set the ann header to be empty. ***************************************************************************/ private void clearAnnHeader(boolean all){ if(all){ gAnnCols.removeAllElements(); gAnnColShow.removeAllElements(); } else { if(gSelAnnHdx != null){ for(int i=gSelAnnHdx.length-1; i >= 0; i--){ gAnnCols.remove(gSelAnnHdx[i]); gAnnColShow.remove(gSelAnnHdx[i]); } } } gAnnColList.setListData(gAnnColShow); } /*************************************************************************** * Description: * set the equation variable to be empty. ***************************************************************************/ private void clearEquations(boolean all){ boolean empty = true; if(all){ for(int i=0; iDescription: * converts the input header name to header address (index). *

Parameter: *
sName -- the name of the property source. *

Return: the index. **************************************************************************/ private int getInputSelectedColum(String sName){ int addr = -1; try{ addr = Integer.parseInt(sName); } catch (NumberFormatException nfe){ addr = -1; } return addr; } /************************************************************************** * Description: * checks if the parenthesis in the equation is paired. *

Parameter: *
equ -- the equation to be checked. *

Return: true if paired; otherwise, false. **************************************************************************/ private boolean parenthesisPaired(String equ){ boolean pair = true; int numLeft, numRight; if(equ.lastIndexOf('(') < 0){ return true; } numLeft = 0; numRight = 0; for(int i=0; iDescription: * splittes an quation to its math symbols and items. *

Parameter: *
eq -- the equation to be splitted. *

Return: an string array that contains the symbols and items. ***************************************************************************/ private String[] parseEquation(String eq){ int count = 0; String[] temp; MyStringTokenizer token = new MyStringTokenizer(eq, OPERATORS, true); temp = new String[token.countTokens()]; while(token.hasMoreTokens()){ temp[count++] = token.nextToken(); } return temp; } /*************************************************************************** * Description: * displays first section of the first input file to allow users to select * the header. *

Parameter: *
fName -- file name. ****************************************************************************/ private void setInputHeader(String fName){ String[] partFile = null; InputHeaderSelector ihs; try{ FileReading fr = new FileReading(fName, FileReading.OUT_AS_ARRAY, parent.getPreviewLine()); if(fr.done){ partFile = fr.getFileContentAsArray(); ihs = new InputHeaderSelector((JFrame)parent, partFile, parent.TITLE + " -- " + IOUtil.extractFileNameFromPath(fName), true); ihs.show(true); if(ihs.isDataReady()){ gInHeaderAddr = ihs.getHeaderOffset(); gHeader = ihs.getHeader(); initInputHeader(); this.validate(); clearEquations(true); gHeaderSelected = true; ihs = null; } } else { parent.logFileContent.add("\n***********\n" + fr.getProcessMessage()); gHeaderReady = false; } } catch (IOException e){ parent.logFileContent.add("\n***********\n" + e.getMessage()); gHeaderReady = false; } } /*************************************************************************** * Description: * activate icons and menu items based on check qualified entry. ***************************************************************************/ private void toolsReady(){ if(gEquation[1].length() > 0 && gEquation[2].length() > 0){ gHeaderReady = true; parent.activateButton(inOut.isOutputReady(), inOut.isOutputReady()); } if(gEquation[3].length() > 0 && gEquation[4].length() > 0){ activateSort(true); } } /**************************************************************************** * Description: * sets the ann file header values. *

Parameter: *
de -- the DropTargetDropEvent object that contains target information. ***************************************************************************/ private void updateAnnHeader(DropTargetDropEvent de){ if(gSelMevCol >= 0 && gEquation != null){ String temp; try { DataFlavor stringFlavor = DataFlavor.stringFlavor; Transferable tr = de.getTransferable(); if(de.isDataFlavorSupported(stringFlavor)) { temp = (String)tr.getTransferData(stringFlavor); if(!isMathSymbol(temp)){ if(!gAnnCols.contains("" + gSelInputCol)){ gAnnCols.add("" + gSelInputCol); gAnnColShow.add(temp); } } de.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); gAnnColList.setListData(gAnnColShow); de.dropComplete(true); } else { de.rejectDrop(); } } catch(IOException ioe) { ioe.printStackTrace(); } catch(UnsupportedFlavorException ufe) { ufe.printStackTrace(); } } } /**************************************************************************** * Description: * sets the mev header values. *

Parameter: *
de -- the DropTargetDropEvent object that contains target information. ***************************************************************************/ private void updateMevHeader(DropTargetDropEvent de){ if(gSelMevCol >= 0 && gEquation != null){ String eqShow = gEqShow[gSelMevCol]; String equation = gEquation[gSelMevCol]; String temp; int eqType = 0; try { DataFlavor stringFlavor = DataFlavor.stringFlavor; Transferable tr = de.getTransferable(); if(de.isDataFlavorSupported(stringFlavor)) { temp = (String)tr.getTransferData(stringFlavor); eqType = isRightEntry(temp, equation); switch(eqType){ case 0: // just attache ... eqShow += temp; if(isMathSymbol(temp)){ equation += temp; } else { equation += gSelInputCol; } break; case 1: // replace a math symbol eqShow = eqShow.substring(0, eqShow.length()-1); eqShow += temp; equation = equation.substring(0, equation.length() - 1); equation += temp; break; case 2: // replace a header name try{ String offset[] = parseEquation(equation); String lastItem = offset[(offset.length-1)]; String hn = gHeader[Integer.parseInt(lastItem)]; eqShow = eqShow.substring(0, eqShow.length() - hn.length()); eqShow += temp; equation = equation.substring(0, equation.length() - lastItem.length()); equation += gSelInputCol; } catch (NumberFormatException nfe){ } break; } de.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); gMevCol.setValueAt(eqShow, 0, gSelMevCol); gEqShow[gSelMevCol] = eqShow; gEquation[gSelMevCol] = equation; de.dropComplete(true); toolsReady(); } else { de.rejectDrop(); } } catch(IOException ioe) { ioe.printStackTrace(); } catch(UnsupportedFlavorException ufe) { ufe.printStackTrace(); } } } class MevTableModel extends DefaultTableModel { MevTableModel(String[][] data, String[] h) { super(data, h); } public boolean isCellEditable(int x, int y) { return false; } } class AnnCellRenderer extends JLabel implements ListCellRenderer { private Color lightBlue; private final Font smallFont = new Font("Arial", Font.PLAIN, 12); public AnnCellRenderer() { setOpaque(true); lightBlue = new Color(209, 210, 249); } public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { setText(value.toString()); setFont(smallFont); setBorder(new LineBorder(Color.gray, 1)); setBackground(isSelected ? lightBlue : Color.white); return this; } } }