/* Copyright @ 2004, The Institute for Genomic Research (TIGR). All rights reserved. */ /****************************************************************************** * Author: Jianwei (Jerry) Li. * Name: ConverterOption (ver. 1.0) * Date: Created on 09/30/04; modified on 11/18/04 * Descpt: A class that print a pup-up window for optional setting * Modification History: *****************************************************************************/ 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.tree.*; import javax.swing.event.*; import org.tigr.util.*; import org.tigr.util.awt.*; import org.tigr.util.io.MyIni; public class ConverterOption extends JDialog implements ActionListener, ListSelectionListener, ChangeListener { // Variables declaration for GUI private GBA gba; private JButton gCancelButn, gFileTypeAddButn, gFileTypeEditButn, gFileTypeRemoveButn; private JButton gOkButn; private JLabel gFileTypeLB, gFileLineLB; private JList gFileTypeList; private JPanel gFileTypeButnPL, gFileTypeEntryPL, gFileTypePL, gFxnPL, gNumPL; private JPanel gSelectionPL; private JScrollPane gFileTypeSP; private JSpinner gNumSP; private JTabbedPane gSetSelectionTP; // variable declaration for use public boolean dataEntered, dirtyData; private int gNumLine; private Dimension gParentSize; private int sizeX, sizeY, x, y; // the size of dialog private ExpressConverter parent; private String gFileExts; private Vector gFileTypes; /*************************************************************************** * Constructor: **************************************************************************/ public ConverterOption(ExpressConverter p, boolean modal) { super (p, modal); sizeX = 230; sizeY = 200; dataEntered = false; dirtyData = false; parent = p; gFileTypes = parent.getCustomizedFileTypes(); gNumLine = parent.getPreviewLine(); initComponents (parent); pack (); } public String getCustomizedFileNameExtensions() { return gFileExts; } public int getPreviewFileSize() { return gNumLine; } /***************************************************************************** * Description: * processes the differenct functions based on triggied components *
Parameter:
*
ae --- the action event.
***************************************************************************/
public void actionPerformed(ActionEvent ae){
if(ae.getSource() == gCancelButn){
dataEntered = false;
setVisible(false);
dispose();
} else if(ae.getSource() == gOkButn){
if(setData()){
dataEntered = true;
setVisible(false);
dispose();
}
} else if(ae.getSource() == gFileTypeAddButn){
addCustomizedFileType();
} else if (ae.getSource() == gFileTypeEditButn){
editFileTypes(true);
} else if (ae.getSource() == gFileTypeRemoveButn){
editFileTypes(false);
}
}
public void stateChanged(ChangeEvent ce){
gNumLine = Integer.parseInt(gNumSP.getValue().toString());
dirtyData = true;
if(gNumLine < 1){
gNumSP.setValue(new Integer(1));
}
}
public void valueChanged(ListSelectionEvent ie){
dirtyData = true;
}
/*****************************************************************************
* Description:
* adds a file type extenision to the list.
***************************************************************************/
private void addCustomizedFileType(){
String newName = new String("");
newName = JOptionPane.showInputDialog(this, "Please entey new file name extension.",
this.getTitle(), JOptionPane.INFORMATION_MESSAGE);
if(newName != null && !newName.equals("")){
if(isValidEntry(newName)){
updateFileTypes(newName);
} else {
showError("The file extension has 3 character limit and requires no space in it.");
}
}
}
/****************************************************************************
* Description:
* insert a string to a vector in its suitable position of order
*
Parameters:
*
vec -- String vector that constains ordered elements
*
str -- the element to be inserted
*
Return: the vector that constains new insert
***************************************************************************/
private Vector addAndOrderList(Vector vec, String str){
Vector temp = vec;
String tempStr;
int i, size;
boolean last = true;
size = vec.size();
for(i=0; i Parameter:
* Parameters:
* Return: true if everything is valid; otherwise, false.
***************************************************************************/
private boolean isValidEntry(String beTest){
boolean b = true;
int i, length;
String str = beTest;
length = beTest.length();
if(length != 3){
return false;
}
for(i=0; i Parameter:
*
p --- parent frame.
***************************************************************************/
private void initComponents (Frame p) {
int butnWide = 75;
int butnHigh = 27;
BevelBorder high = new BevelBorder(0);
BevelBorder low = new BevelBorder(1);
gba = new GBA();
setTitle(parent.TITLE + " -- Preference");
addWindowListener (new WindowAdapter () {
public void windowClosing (WindowEvent evt) {
dataEntered = false;
setVisible(false);
dispose();
}
}
);
gSelectionPL = new JPanel(new GridBagLayout()); // contains only gSetSelectionTP and fxnPanel
getContentPane ().add(gSelectionPL, BorderLayout.CENTER);
gFileTypePL = new JPanel(new GridBagLayout());
gFileTypePL.setPreferredSize(new Dimension(290, 240));
gFileTypeButnPL = new JPanel(new GridBagLayout());
gSetSelectionTP = new JTabbedPane();
gSetSelectionTP.setPreferredSize (new Dimension(sizeX - 10, sizeY - 10));
gSelectionPL.add(gSetSelectionTP);
gSetSelectionTP.addTab(" Customized Input File ", null, gFileTypePL);
gFileTypeEntryPL = new JPanel(new GridBagLayout());
gFileTypeEntryPL.setPreferredSize (new Dimension(270, 150));
gFileTypeLB = new JLabel("File Name Extension:");
gFileTypeList = new JList(gFileTypes);
gFileTypeList.addListSelectionListener(this);
gFileTypeSP = new JScrollPane(gFileTypeList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
gFileTypeList.setBorder(low);
gFileTypeList.setPreferredSize(new Dimension(sizeX /3, butnHigh));
gFileTypeAddButn = new JButton("Add");
gFileTypeAddButn.setBorder(high);
gFileTypeAddButn.setPreferredSize(new Dimension(60, 23));
gFileTypeAddButn.setMinimumSize(new Dimension(60, 23));
gFileTypeAddButn.addActionListener(this);
gFileTypeEditButn = new JButton("Edit");
gFileTypeEditButn.setBorder(high);
gFileTypeEditButn.setPreferredSize(new Dimension(60, 23));
gFileTypeEditButn.setMinimumSize(new Dimension(60, 23));
gFileTypeEditButn.addActionListener(this);
gFileTypeRemoveButn = new JButton("Remove");
gFileTypeRemoveButn.setBorder(high);
gFileTypeRemoveButn.setPreferredSize(new Dimension(60, 23));
gFileTypeRemoveButn.setMinimumSize(new Dimension(60, 23));
gFileTypeRemoveButn.addActionListener(this);
gNumPL = new JPanel(new GridBagLayout());
gFileLineLB = new JLabel("Preview Lines:");
gNumSP = new JSpinner();
gNumSP.setValue(new Integer(gNumLine));
gNumSP.setMinimumSize(new Dimension(50, 23));
gNumSP.addChangeListener(this);
gFxnPL = new JPanel ();
gFxnPL.setPreferredSize (new Dimension(290, 37));
gFxnPL.setMinimumSize (new Dimension(80, 37));
gFxnPL.setLayout (new GridBagLayout ());
gOkButn = new JButton("OK");
gOkButn.setPreferredSize (new Dimension(butnWide, butnHigh));
gOkButn.setBorder(new BevelBorder(0));
gOkButn.addActionListener(this);
gCancelButn = new JButton("Cancel");
gCancelButn.setPreferredSize (new java.awt.Dimension(butnWide, butnHigh));
gCancelButn.setBorder(new BevelBorder(0));
gCancelButn.addActionListener(this);
gba.add(gSelectionPL, gSetSelectionTP, 0, 0, 1, 1, 1, 1, GBA.B, GBA.C, 5, 5, 5, 5);
gba.add(gSelectionPL, gFxnPL, 0, 1, 1, 1, 0, 0, GBA.H, GBA.C, 5, 5, 5, 5);
gba.add(gFileTypePL, gFileTypeEntryPL, 0, 0, 1, 1, 1, 1, GBA.B, GBA.C, 10, 5, 5, 2);
gba.add(gFileTypePL, gFileTypeButnPL, 1, 0, 1, 1, 1, 1, GBA.B, GBA.C, 10, 2, 5, 5);
gba.add(gFileTypePL, gNumPL, 0, 1, 1, 1, 1, 0, GBA.H, GBA.C, 2, 5, 10, 5);
gba.add(gFileTypeEntryPL, gFileTypeLB, 0, 0, 1, 1, 0, 0, GBA.H, GBA.C, 5, 5, 2, 2);
gba.add(gFileTypeEntryPL, gFileTypeSP, 0, 1, 1, 1, 1, 1, GBA.B, GBA.C, 2, 5, 5, 5);
gba.add(gFileTypeButnPL, gFileTypeAddButn, 0, 0, 1, 1, 0, 0, GBA.NONE, GBA.E, 20, 2, 5, 5);
gba.add(gFileTypeButnPL, gFileTypeEditButn, 0, 1, 1, 1, 0, 0, GBA.NONE, GBA.E, 2, 2, 5, 5);
gba.add(gFileTypeButnPL, gFileTypeRemoveButn, 0, 2, 1, 1, 0, 0, GBA.NONE, GBA.E, 2, 2, 5, 5);
gba.add(gNumPL, gFileLineLB, 0, 0, 1, 1, 0, 0, GBA.NONE, GBA.W, 1, 10, 1, 5);
gba.add(gNumPL, gNumSP, 1, 0, 1, 1, 1, 0, GBA.H, GBA.W, 1, 10, 1, 2);
gba.add(gFxnPL, gOkButn, 0, 0, 1, 1, 0, 0, GBA.H, GBA.C, 5, 5, 5, 5);
gba.add(gFxnPL, gCancelButn, 1, 0, 1, 1, 0, 0, GBA.H, GBA.C, 5, 5, 5, 5);
resize(sizeX, sizeY);
gParentSize = parent.getSize();
x = (gParentSize.width-sizeX-25)>>1;
y = (gParentSize.height-sizeY-35)>>1;
x += parent.getLocationX();
y += parent.getLocationY();
setLocation(x, y);
}
/***************************************************************************
* Description:
* test if an entry contains a space at the beginning, middle, or the
* end, at the same time checks if it has only three characters.
*
beTest --- the data entry as a string.
*
name -- new file name extension
***************************************************************************/
private void updateFileTypes(String name){
if(name != null){
if(!gFileTypes.contains(name)){
gFileTypes = addAndOrderList(gFileTypes, name);
}
}
gFileTypeList.setListData(gFileTypes);
dirtyData = true;
}
}