- /**************************************************************************\r
- * Internal implementation of Metal LookAndFeel to create the table sorting\r
- * ability.\r
- *************************************************************************/\r
- private final static class UI 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() { return model; }\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
- if (tbl != null)\r
- {\r
- //Fix the columns so they can't be rearranged, if we don't do this\r
- //we would need to keep track when each column is moved\r
- tbl.getTableHeader().setReorderingAllowed(false);\r
-\r
- //Add a mouselistener to listen for clicks on column headers\r
- tbl.getTableHeader().addMouseListener(new MouseAdapter(){\r
- public void mouseClicked(MouseEvent e)\r
- {\r
- //Only process single clicks\r
- if (e.getClickCount() > 1) return;\r
- e.consume();\r
- final int col = tbl.getTableHeader().columnAtPoint(e.getPoint());\r
- if (col == COLUMN_FILENAME || col == COLUMN_FILESIZE ||\r
- col == COLUMN_FILEDATE)\r
- model.sort(col,tbl);\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 final static 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
- if (comp[i] instanceof Container)\r
- {\r
- JTable tbl = findJTable(((Container)comp[i]).getComponents());\r
- if (tbl != null) return tbl;\r
- }\r
- }\r
- return null;\r
- }\r
- }\r
-\r
- /***************************************************************************\r
- * Implementation of BasicDirectoryModel that sorts the Files by column\r
- **************************************************************************/\r
- private final static class DirectoryModel extends BasicDirectoryModel\r
- {\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
- * Supposedly this is not used anymore, hopefully not. We implemented\r
- * some basic attempt at sorting just in case\r
- * @param a\r
- * @param b\r
- * @return\r
- *************************************************************************/\r
- protected final boolean lt(File a, File b)\r
- {\r
- System.out.println("LT called?");\r
- boolean less = false;\r
- switch (col)\r
- {\r
- case COLUMN_FILEDATE:\r
- less = a.lastModified() > b.lastModified();\r
- break;\r
- case COLUMN_FILESIZE:\r
- less = a.length() > b.length();\r
- break;\r
- default:\r
- less = a.getName().compareToIgnoreCase(b.getName()) > 0;\r
- break;\r
- }\r
- if (ascending) return less = !less;\r
- return less;\r
- }\r