X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FJalviewFileChooser.java;h=556bb7254940ef0db86bd4477cb4b2bb15fcfcdc;hb=7bc226b58110fa26d9dbd3f0c78095d06909ffc3;hp=c8248ef69cb7a92247f3f6833f75efe5d89b341c;hpb=2c012a6c95ee7a4017b9896a4cdcfe0dd280fcd2;p=jalview.git diff --git a/src/jalview/io/JalviewFileChooser.java b/src/jalview/io/JalviewFileChooser.java index c8248ef..556bb72 100755 --- a/src/jalview/io/JalviewFileChooser.java +++ b/src/jalview/io/JalviewFileChooser.java @@ -1,355 +1,276 @@ - -/*/////////////////////////////////////////////////////////////////// -// This file was taken from java forum -// Re: JFileChooser functioning like normal Windows Apps FileChooser -// Author: ddanimal -// http://forum.java.sun.com/thread.jspa?forumID=57&threadID=327712 -*/////////////////////////////////////////////////////////////////// - +/* + * Jalview - A Sequence Alignment Editor and Viewer + * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +////////////////////////////////////////////////////////////////// package jalview.io; -import java.awt.*; -import java.awt.event.*; import java.io.*; import java.util.*; +import java.awt.*; +import java.awt.event.*; import javax.swing.*; -import javax.swing.plaf.*; -import javax.swing.plaf.basic.*; -import javax.swing.plaf.metal.*; -import javax.swing.table.*; -public class JalviewFileChooser extends JFileChooser +public class JalviewFileChooser + extends JFileChooser { - private static final int COLUMN_FILENAME = 0; - private static final int COLUMN_FILESIZE = 1; - private static final int COLUMN_FILETYPE = 2; - private static final int COLUMN_FILEDATE = 3; - private static final int COLUMN_FILEATTR = 4; - private static final int COLUMN_COLCOUNT = 5; - private static String[] COLUMNS = null; + public JalviewFileChooser(String dir) + { + super(dir); + setAccessory(new RecentlyOpened()); + } + public JalviewFileChooser(String dir, + String[] suffix, + String[] desc, + String selected, + boolean selectAll) + { + super(dir); + init(suffix, desc, selected, selectAll); + } - public JalviewFileChooser(String dir, String [] suffix, String [] desc, String selected) + public JalviewFileChooser(String dir, + String[] suffix, + String[] desc, + String selected) { super(dir); + init(suffix, desc, selected, true); + } + + void init(String[] suffix, + String[] desc, + String selected, + boolean selectAll) + { JalviewFileFilter chosen = null; - for(int i=0; i 1) return; - e.consume(); - final int col = tbl.getTableHeader().columnAtPoint(e.getPoint()); - if (col == COLUMN_FILENAME || col == COLUMN_FILESIZE || - col == COLUMN_FILEDATE) - model.sort(col,tbl); - } - }); - } - return panel; - } - - /************************************************************************** - * Finds the JTable in the panel so we can add MouseListener - * @param comp - * @return - *************************************************************************/ - private final static JTable findJTable(Component[] comp) - { - for (int i=0;i b.lastModified(); - break; - case COLUMN_FILESIZE: - less = a.length() > b.length(); - break; - default: - less = a.getName().compareToIgnoreCase(b.getName()) > 0; - break; - } - if (ascending) return less = !less; - return less; - } - - /************************************************************************** - * Resorts the JFileChooser table based on new column - * @param c - *************************************************************************/ - protected final void sort(int c, JTable tbl) - { - //Set column and order - col = c; - ascending = !ascending; - String indicator = " (^)"; - if (ascending) - indicator = " (v)"; - - final JTableHeader th = tbl.getTableHeader(); - final TableColumnModel tcm = th.getColumnModel(); - - for (int i=0;i b.lastModified()) - ret = -1; - else if (a.lastModified() == b.lastModified()) - ret = 0; - - if (ascending) - ret *= -1; - return ret; - } - - }); - break; - case COLUMN_FILESIZE: - Collections.sort(data,new Comparator(){ - public int compare(Object o1,Object o2) - { - int ret = 1; - final File a = (File)o1; - final File b = (File)o2; - if (a.length() > b.length()) - ret = -1; - else if (a.length() == b.length()) - ret = 0; - - if (ascending) - ret *= -1; - return ret; - } - - }); - break; - case COLUMN_FILENAME: - Collections.sort(data,new Comparator(){ - public int compare(Object o1,Object o2) - { - final File a = (File)o1; - final File b = (File)o2; - if (ascending) - return a.getName().compareToIgnoreCase(b.getName()); - else - return -1 * a.getName().compareToIgnoreCase(b.getName()); - } - - }); - break; - } - } } } -