source: 3thparty/jupload/src/main/java/wjhk/jupload2/gui/filepanel/ColumnComparator.java @ 3951

Revision 3951, 3.2 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1709 - Adicao de codigo fonte java do componente jupload

Line 
1//
2// $Id: ColumnComparator.java 95 2007-05-02 03:27:05Z
3// /C=DE/ST=Baden-Wuerttemberg/O=ISDN4Linux/OU=Fritz
4// Elfert/CN=svn-felfert@isdn4linux.de/emailAddress=fritz@fritz-elfert.de $
5//
6// jupload - A file upload applet.
7// Copyright 2007 The JUpload Team
8//
9// Created: ?
10// Creator: William JinHua Kwong
11// Last modified: $Date: 2009-07-01 17:32:39 -0300 (Qua, 01 Jul 2009) $
12//
13// This program is free software; you can redistribute it and/or modify it under
14// the terms of the GNU General Public License as published by the Free Software
15// Foundation; either version 2 of the License, or (at your option) any later
16// version. This program is distributed in the hope that it will be useful, but
17// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19// details. You should have received a copy of the GNU General Public License
20// along with this program; if not, write to the Free Software Foundation, Inc.,
21// 675 Mass Ave, Cambridge, MA 02139, USA.
22
23package wjhk.jupload2.gui.filepanel;
24
25import java.io.Serializable;
26import java.util.Comparator;
27
28import wjhk.jupload2.filedata.FileData;
29
30/**
31 * Technical class, used to sort rows in the
32 * wjhk.jupload2.gui.FilePanelDataModel2 class.
33 */
34public class ColumnComparator implements Comparator<FileData>, Serializable {
35
36    /** Unused SerialVerisonUID */
37    private static final long serialVersionUID = 1L;
38
39    protected int index;
40
41    protected boolean ascending;
42
43    /**
44     * Creates a new instance.
45     *
46     * @param index The column index of the table data to be compared
47     * @param ascending Specifies the sort order.
48     */
49    public ColumnComparator(int index, boolean ascending) {
50        this.index = index;
51        this.ascending = ascending;
52    }
53
54    /**
55     * @param one
56     * @param two
57     * @return -1, 0 or 1, as usual.
58     * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
59     */
60    @SuppressWarnings("unchecked")
61    public int compare(FileData one, FileData two) {
62        // if (one instanceof DefaultFileData && two instanceof DefaultFileData)
63        // {
64        Object oOne;
65        Object oTwo;
66        switch (this.index) {
67            case FilePanelDataModel2.COLINDEX_NAME:
68                oOne = (one).getFileName();
69                oTwo = (two).getFileName();
70                break;
71            case FilePanelDataModel2.COLINDEX_SIZE:
72                oOne = Long.valueOf((one).getFileLength());
73                oTwo = Long.valueOf((two).getFileLength());
74                break;
75            case FilePanelDataModel2.COLINDEX_DIRECTORY:
76                oOne = (one).getDirectory();
77                oTwo = (two).getDirectory();
78                break;
79            case FilePanelDataModel2.COLINDEX_MODIFIED:
80                oOne = (one).getLastModified();
81                oTwo = (two).getLastModified();
82                break;
83            default:
84                return 0;
85        }
86        if (oOne instanceof Comparable && oTwo instanceof Comparable) {
87            return ((Comparable) oOne).compareTo(oTwo)
88                    * (this.ascending ? 1 : -1);
89        }
90        // }
91        return 0;
92    }
93}
Note: See TracBrowser for help on using the repository browser.