Author: jflesch
Date: 2006-08-05 14:58:53 +0000 (Sat, 05 Aug 2006)
New Revision: 9903

Modified:
   trunk/apps/Thaw/src/thaw/core/Core.java
   trunk/apps/Thaw/src/thaw/core/IconBox.java
   trunk/apps/Thaw/src/thaw/i18n/thaw.properties
   trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
   trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueueTableModel.java
Log:
Column sorting is implemented

Modified: trunk/apps/Thaw/src/thaw/core/Core.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Core.java     2006-08-05 14:10:49 UTC (rev 
9902)
+++ trunk/apps/Thaw/src/thaw/core/Core.java     2006-08-05 14:58:53 UTC (rev 
9903)
@@ -97,8 +97,11 @@

                splashScreen.setProgressionAndStatus(10, "Connecting ...");
                if(!initNodeConnection())
-                       new WarningWindow(this, 
I18n.getMessage("thaw.warning.unableToConnectTo")+ " 
"+config.getValue("nodeAddress")+":"+ config.getValue("nodePort"));
+                       new WarningWindow(this, 
I18n.getMessage("thaw.warning.unableToConnectTo")+
+                                         " "+config.getValue("nodeAddress")+
+                                         ":"+ config.getValue("nodePort"));

+
                splashScreen.setProgressionAndStatus(30, "Preparing the main 
window ...");
                if(!initGraphics())
                        return false;

Modified: trunk/apps/Thaw/src/thaw/core/IconBox.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/IconBox.java  2006-08-05 14:10:49 UTC (rev 
9902)
+++ trunk/apps/Thaw/src/thaw/core/IconBox.java  2006-08-05 14:58:53 UTC (rev 
9903)
@@ -26,6 +26,12 @@
        public static ImageIcon downloads;
        public static ImageIcon minDownloads;

+       public static ImageIcon indexEditor;
+       public static ImageIcon minIndexEditor;
+
+       public static ImageIcon indexBrowser;
+       public static ImageIcon minIndexBrowser;
+
        public static ImageIcon settings;
        public static ImageIcon minSettings;

@@ -86,6 +92,17 @@
                                new ImageIcon((new 
IconBox()).getClass().getClassLoader().getResource("min-preferences-system.png"));


+                       indexEditor =
+                               new ImageIcon((new 
IconBox()).getClass().getClassLoader().getResource("edit-find-replace.png"));
+                       minIndexEditor =
+                               new ImageIcon((new 
IconBox()).getClass().getClassLoader().getResource("min-edit-find-replace.png"));
+
+
+                       indexBrowser =
+                               new ImageIcon((new 
IconBox()).getClass().getClassLoader().getResource("edit-find.png"));
+                       minIndexBrowser =
+                               new ImageIcon((new 
IconBox()).getClass().getClassLoader().getResource("min-edit-find.png"));
+
                        reconnectAction =
                                new ImageIcon((new 
IconBox()).getClass().getClassLoader().getResource("view-refresh.png"));
                        minReconnectAction =

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2006-08-05 14:10:49 UTC 
(rev 9902)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2006-08-05 14:58:53 UTC 
(rev 9903)
@@ -158,6 +158,7 @@
 thaw.toolbar.button.settings=Settings
 thaw.toolbar.button.quit=Quit

+
 ## About
 thaw.about.title=About
 thaw.about.l1=Thaw
@@ -166,8 +167,11 @@
 thaw.about.l4=under GPLv2
 thaw.about.l6=Icon theme "Gorilla" created by Jimmac 
(http://jimmac.musichall.cz/icons.php)

+
 ## HsqlDb
 thaw.plugin.hsqldb.database=Database

+
 ## Index management
-thaw.plugin.index.editor=Index editor
+thaw.plugin.index.editor=Your shared files
+

Modified: trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java       
2006-08-05 14:10:49 UTC (rev 9902)
+++ trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java       
2006-08-05 14:58:53 UTC (rev 9903)
@@ -28,6 +28,7 @@
 import java.awt.event.ActionListener;
 import java.awt.event.ActionEvent;
 import javax.swing.ButtonGroup;
+import javax.swing.table.JTableHeader;

 import java.awt.Toolkit;
 import java.awt.datatransfer.Clipboard;
@@ -83,6 +84,11 @@

                table.setShowGrid(true);

+               JTableHeader header = table.getTableHeader();
+               header.setUpdateTableInRealTime(true);
+               header.addMouseListener(tableModel.new ColumnListener(table));
+               header.setReorderingAllowed(true);
+
                if(isForInsertionQueue) {
                        label = new 
JLabel(I18n.getMessage("thaw.common.insertions"));
                        label.setIcon(IconBox.insertions);

Modified: trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueueTableModel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueueTableModel.java  
2006-08-05 14:10:49 UTC (rev 9902)
+++ trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueueTableModel.java  
2006-08-05 14:58:53 UTC (rev 9903)
@@ -8,12 +8,21 @@
 import javax.swing.event.TableModelListener;
 import javax.swing.event.TableModelEvent;
 import javax.swing.JProgressBar;
+import javax.swing.JTable;
+import javax.swing.table.TableColumnModel;
+import javax.swing.table.TableColumn;

+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import java.util.Comparator;
+import java.util.Collections;
+
 import thaw.core.*;
 import thaw.fcp.*;

 public class QueueTableModel extends javax.swing.table.AbstractTableModel 
implements Observer {
-       private static final long serialVersionUID = 20060707;
+       private static final long serialVersionUID = 20060708;

        private Vector columnNames = new Vector();

@@ -21,6 +30,12 @@

        private boolean isForInsertions = false;

+       
+       private boolean isSortedAsc = false;
+       private int sortedColumn = -1;
+       
+
+
        public QueueTableModel(boolean isForInsertions) {
                super();

@@ -36,6 +51,7 @@
                columnNames.add(I18n.getMessage("thaw.common.progress"));

                resetTable();
+
        }


@@ -53,7 +69,16 @@
        }

        public String getColumnName(int col) {
-               return (String)columnNames.get(col);
+               String result = (String)columnNames.get(col);
+
+               if(col == sortedColumn) {
+                       if(isSortedAsc)
+                               result = result + " >>";
+                       else
+                               result = result + " <<";
+               }
+
+               return result;
        }


@@ -141,6 +166,8 @@

                queries.add(query);

+               sortTable();
+
                notifyObservers();
        }

@@ -149,6 +176,8 @@

                queries.remove(query);

+               sortTable();
+
                notifyObservers();
        }

@@ -187,8 +216,155 @@
        }

        public void update(Observable o, Object arg) {
+               sortTable();
                notifyObservers();
        }

+
+       /**
+        * @return false if nothing sorted
+        */
+       public boolean sortTable() {
+               if(sortedColumn < 0 || queries.size() <= 0)
+                       return false;
+
+               Collections.sort(queries, new QueryComparator(isSortedAsc, 
sortedColumn, isForInsertions));
+
+               return true;
+       }
+
+       
+       public class ColumnListener extends MouseAdapter {
+               private JTable table;
+                               
+               public ColumnListener(JTable t) {
+                       table = t;
+               }
+               
+               public void mouseClicked(MouseEvent e) {
+                       TableColumnModel colModel = table.getColumnModel();
+                       int columnModelIndex = 
colModel.getColumnIndexAtX(e.getX());
+                       int modelIndex = 
colModel.getColumn(columnModelIndex).getModelIndex();
+                       
+                       int columnsCount = table.getColumnCount();
+
+                       if (modelIndex < 0)
+                               return;
+
+                       if (sortedColumn == modelIndex)
+                               isSortedAsc = !isSortedAsc;
+                       else
+                               sortedColumn = modelIndex;
+
+                       
+                       for (int i = 0; i < columnsCount; i++) { 
+                               TableColumn column = colModel.getColumn(i);
+                               
column.setHeaderValue(getColumnName(column.getModelIndex()));
+                       }
+
+                       
+
+                       table.getTableHeader().repaint();
+
+                       sortTable();                    
+               }
+       }
+       
+
+       public class QueryComparator implements Comparator {
+               private boolean isSortedAsc;
+               private int column;
+               private boolean isForInsertionTable;
+
+               public QueryComparator(boolean sortedAsc, int column,
+                                      boolean isForInsertionTable) {
+                       this.isSortedAsc = sortedAsc;
+                       this.column = column;
+                       this.isForInsertionTable = isForInsertionTable;
+               }
+               
+               public int compare(Object o1, Object o2) {
+                       int result = 0;
+
+                       if(!(o1 instanceof FCPTransferQuery)
+                          || !(o2 instanceof FCPTransferQuery))
+                               return 0;
+
+                       FCPTransferQuery q1 = (FCPTransferQuery)o1;
+                       FCPTransferQuery q2 = (FCPTransferQuery)o2;
+
+                       
+                       if(column == 0) { /* File name */
+                               if(q1.getFilename() == null)
+                                       return -1;
+
+                               if(q2.getFilename() == null)
+                                       return 1;
+
+                               result = 
q1.getFilename().compareTo(q2.getFilename());
+                       }
+
+                       if(column == 1) { /* Size */
+                               result = (new 
Long(q1.getFileSize())).compareTo(new Long(q2.getFileSize()));
+                       }
+
+                       if( (column == 2 && !isForInsertionTable) ) { /* 
localPath */
+                               if(q1.getPath() == null)
+                                       return -1;
+
+                               if(q2.getPath() == null)
+                                       return 1;
+
+                               result = q1.getPath().compareTo(q2.getPath());
+                       }
+
+                       if( (column == 2 && isForInsertionTable)
+                           || (column == 3 && !isForInsertionTable) ) { /* 
status */
+
+                               if(q1.getStatus() == null)
+                                       return -1;
+
+                               if(q2.getStatus() == null)
+                                       return 1;
+
+                               result = 
q1.getStatus().compareTo(q2.getStatus());
+                       }
+
+                       if( (column == 3 && isForInsertionTable)
+                           || (column == 4 && !isForInsertionTable) ) { /* 
progress */
+                               if(q1.getProgression() <= 0 
+                                  && q2.getProgression() <= 0) {
+                                       if(q1.isRunning() && !q2.isRunning())
+                                               return 1;
+
+                                       if(q1.isRunning() && !q2.isRunning())
+                                               return -1;
+                               }
+
+                               result = (new 
Integer(q1.getProgression())).compareTo(new Integer(q2.getProgression()));
+                       }
+                       
+
+                       if (!isSortedAsc)
+                               result = -result;
+
+                       return result;
+               }
+               
+               public boolean isSortedAsc() {
+                       return isSortedAsc;
+               }
+
+               public boolean equals(Object obj) {
+                       if (obj instanceof QueryComparator) {
+                               QueryComparator compObj = (QueryComparator) obj;
+                               return compObj.isSortedAsc() == isSortedAsc();
+                       }
+                       return false;
+               }
+
+       }
+
 }

+


Reply via email to