- /**************************************************************************\r
- * Always create the local UI\r
- * @param comp\r
- *************************************************************************/\r
- public final void setUI(ComponentUI comp)\r
- {\r
- super.setUI(new UI(this));\r
- }\r
-\r
- /**************************************************************************\r
- * Internal implementation of Metal LookAndFeel to create the table sorting\r
- * ability.\r
- *************************************************************************/\r
- private class UI\r
- extends MetalFileChooserUI\r
- {\r
- private DirectoryModel model;\r
-\r
- /**************************************************************************\r
- * Must be overridden to extend\r
- * @param e\r
- *************************************************************************/\r
- public UI(JFileChooser e)\r
- {\r
- super(e);\r
- }\r
-\r
- /**************************************************************************\r
- * Overridden to create our own model\r
- *************************************************************************/\r
- protected final void createModel()\r
- {\r
- model = new DirectoryModel(getFileChooser());\r
- }\r
-\r
- /**************************************************************************\r
- * Overridden to get our own model\r
- * @return\r
- *************************************************************************/\r
- public final BasicDirectoryModel getModel()\r
- {\r
- return model;\r
- }\r
-\r
- /**************************************************************************\r
- * Calls the default method then adds a MouseListener to the JTable\r
- * @param chooser\r
- * @return\r
- *************************************************************************/\r
- protected final JPanel createDetailsView(JFileChooser chooser)\r
- {\r
- final JPanel panel = super.createDetailsView(chooser);\r
-\r
- //Since we can't access MetalFileChooserUI's private member detailsTable\r
- //directly, we have to find it in the JPanel\r
- final JTable tbl = findJTable(panel.getComponents());\r
-\r
- if (tbl != null)\r
- {\r
- //Add a mouselistener to listen for presses on column headers\r
- tbl.getTableHeader().addMouseListener(new MouseAdapter()\r
- {\r
- public void mousePressed(MouseEvent e)\r
- {\r
-\r
- e.consume();\r
-\r
- final int col = tbl.getTableHeader().columnAtPoint(e.getPoint());\r
- model.sort(col, tbl);\r
-\r
- }\r
- });\r
- }\r
-\r
- return panel;\r
- }\r
-\r
- /**************************************************************************\r
- * Finds the JTable in the panel so we can add MouseListener\r
- * @param comp\r
- * @return\r
- *************************************************************************/\r
- private JTable findJTable(Component[] comp)\r
- {\r
- for (int i = 0; i < comp.length; i++)\r
- {\r
- if (comp[i] instanceof JTable)\r
- {\r
- return (JTable) comp[i];\r
- }\r
-\r
- if (comp[i] instanceof Container)\r
- {\r
- JTable tbl = findJTable( ( (Container) comp[i]).getComponents());\r
-\r
- if (tbl != null)\r
- {\r
- return tbl;\r
- }\r
- }\r
- }\r
-\r
- return null;\r
- }\r
- }\r
-\r
- /***************************************************************************\r
- * Implementation of BasicDirectoryModel that sorts the Files by column\r
- **************************************************************************/\r
- private final class DirectoryModel\r
- extends BasicDirectoryModel\r
- {\r
- String sortingColumnName=null;\r
- int col = 0;\r
- boolean ascending;\r
-\r
- /**************************************************************************\r
- * Must be overridden to extend BasicDirectoryModel\r
- * @param chooser\r
- *************************************************************************/\r
- DirectoryModel(JFileChooser chooser)\r
- {\r
- super(chooser);\r
- }\r
-\r
-\r
- /**************************************************************************\r
- * Resorts the JFileChooser table based on new column\r
- * @param c\r
- *************************************************************************/\r
- protected final void sort(int c, JTable tbl)\r
- {\r
-\r
-\r
- //Set column and order\r
- col = c;\r
- ascending = !ascending;\r
-\r
- String indicator = " (^)";\r
-\r
- if (ascending)\r
- {\r
- indicator = " (v)";\r
- }\r
-\r
- final JTableHeader th = tbl.getTableHeader();\r
- final TableColumnModel tcm = th.getColumnModel();\r
- TableColumn tc = null;\r
- String title = null;\r
-\r
-\r
- //Remove indicator from old sort, and add to new\r
- for(int i=0; i<tcm.getColumnCount(); i++)\r
- {\r
- tc = tcm.getColumn(i);\r
- title = tc.getHeaderValue().toString();\r
- if (title.endsWith(" (^)") || title.endsWith(" (v)"))\r
- {\r
- title = title.substring(0, title.length() - 4);\r
- }\r
-\r
- if(i==col)\r
- {\r
- sortingColumnName = title;\r
- title = title + indicator;\r
- }\r
-\r
- tc.setHeaderValue(title);\r
- }\r
-\r
- //Requery the file listing\r
- validateFileCache();\r
- }\r
-\r
- /**************************************************************************\r
- * Sorts the data based on current column setting\r
- * @param data\r
- *************************************************************************/\r
- protected final void sort(Vector data)\r
- {\r
- /*\r
- UIManager.getString("FileChooser.fileTypeHeaderText", l),\r
- UIManager.getString("FileChooser.fileAttrHeaderText", l)\r
-*/\r
- if(sortingColumnName==null)\r
- return;\r
-\r
-\r
- if(sortingColumnName.equals(UIManager.getString("FileChooser.fileDateHeaderText")))\r
- {\r
- Collections.sort(data,\r
- new Comparator()\r
- {\r
-\r
- public int compare(Object o1, Object o2)\r
- {\r
- int ret = 1;\r
- final File a = (File) o1;\r
- final File b = (File) o2;\r
-\r
- if (a.lastModified() > b.lastModified())\r
- {\r
- ret = -1;\r
- }\r
- else if (a.lastModified() == b.lastModified())\r
- {\r
- ret = 0;\r
- }\r
-\r
- if (ascending)\r
- {\r
- ret *= -1;\r
- }\r
-\r
- return ret;\r
- }\r
- });\r
- }\r
- else if(sortingColumnName.equals(UIManager.getString("FileChooser.fileSizeHeaderText")))\r
- {\r
-\r
- Collections.sort(data,\r
- new Comparator()\r
- {\r
-\r
- public int compare(Object o1, Object o2)\r
- {\r
- int ret = 1;\r
- final File a = (File) o1;\r
- final File b = (File) o2;\r
-\r
- if (a.length() > b.length())\r
- {\r
- ret = -1;\r
- }\r
- else if (a.length() == b.length())\r
- {\r
- ret = 0;\r
- }\r
-\r
- if (ascending)\r
- {\r
- ret *= -1;\r
- }\r
-\r
- return ret;\r
- }\r
- });\r
- }\r
- else if(sortingColumnName.equals(UIManager.getString("FileChooser.fileTypeHeaderText")))\r
- {\r
- Collections.sort(data,\r
- new Comparator()\r
- {\r
- public int compare(Object o1, Object o2)\r
- {\r
- final String a = getFileSystemView().getSystemTypeDescription( (File)o1 );\r
- final String b = getFileSystemView().getSystemTypeDescription( (File)o2 );\r
- if (ascending)\r
- {\r
- return a.compareToIgnoreCase(b);\r
- }\r
- else\r
- {\r
- return -1 * a.compareToIgnoreCase(b);\r
- }\r
- }\r
- });\r
- }\r
- else if(sortingColumnName.equals(UIManager.getString("FileChooser.fileNameHeaderText")))\r
-{\r
- Collections.sort(data,\r
- new Comparator()\r
- {\r
- public int compare(Object o1, Object o2)\r
- {\r
- final String a = ((File) o1).getName();\r
- final String b = ((File) o2).getName();\r