~ubuntu-branches/ubuntu/precise/weka/precise

« back to all changes in this revision

Viewing changes to weka/clusterers/forOPTICSAndDBScan/OPTICS_GUI/ResultVectorTableModel.java

  • Committer: Bazaar Package Importer
  • Author(s): Soeren Sonnenburg
  • Date: 2008-02-24 09:18:45 UTC
  • Revision ID: james.westby@ubuntu.com-20080224091845-1l8zy6fm6xipbzsr
Tags: upstream-3.5.7+tut1
ImportĀ upstreamĀ versionĀ 3.5.7+tut1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *    This program is free software; you can redistribute it and/or modify
 
3
 *    it under the terms of the GNU General Public License as published by
 
4
 *    the Free Software Foundation; either version 2 of the License, or
 
5
 *    (at your option) any later version.
 
6
 *
 
7
 *    This program is distributed in the hope that it will be useful,
 
8
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
 *    GNU General Public License for more details.
 
11
 *
 
12
 *    You should have received a copy of the GNU General Public License
 
13
 *    along with this program; if not, write to the Free Software
 
14
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
15
 */
 
16
 
 
17
/*
 
18
 *    Copyright (C) 2004
 
19
 *    & Matthias Schubert (schubert@dbs.ifi.lmu.de)
 
20
 *    & Zhanna Melnikova-Albrecht (melnikov@cip.ifi.lmu.de)
 
21
 *    & Rainer Holzmann (holzmann@cip.ifi.lmu.de)
 
22
 */
 
23
 
 
24
package weka.clusterers.forOPTICSAndDBScan.OPTICS_GUI;
 
25
 
 
26
import weka.clusterers.forOPTICSAndDBScan.DataObjects.DataObject;
 
27
import weka.core.FastVector;
 
28
import weka.core.Utils;
 
29
 
 
30
import javax.swing.table.AbstractTableModel;
 
31
 
 
32
/**
 
33
 * <p>
 
34
 * ResultVectorTableModel.java <br/>
 
35
 * Authors: Rainer Holzmann, Zhanna Melnikova-Albrecht <br/>
 
36
 * Date: Sep 12, 2004 <br/>
 
37
 * Time: 9:23:31 PM <br/>
 
38
 * $ Revision 1.4 $ <br/>
 
39
 * </p>
 
40
 *
 
41
 * @author Zhanna Melnikova-Albrecht (melnikov@cip.ifi.lmu.de)
 
42
 * @author Rainer Holzmann (holzmann@cip.ifi.lmu.de)
 
43
 * @version $Revision: 1.3 $
 
44
 */
 
45
public class ResultVectorTableModel
 
46
    extends AbstractTableModel {
 
47
 
 
48
    /** for serialization */
 
49
    private static final long serialVersionUID = -7732711470435549210L;
 
50
 
 
51
    /**
 
52
     * Holds the ClusterOrder (dataObjects with their r_dist and c_dist) for the GUI
 
53
     */
 
54
    private FastVector resultVector;
 
55
 
 
56
    // *****************************************************************************************************************
 
57
    // constructors
 
58
    // *****************************************************************************************************************
 
59
 
 
60
    /**
 
61
     *  Constructs a default <code>DefaultTableModel</code>
 
62
     *  which is a table of zero columns and zero rows.
 
63
     */
 
64
    public ResultVectorTableModel(FastVector resultVector) {
 
65
        this.resultVector = resultVector;
 
66
    }
 
67
 
 
68
    // *****************************************************************************************************************
 
69
    // methods
 
70
    // *****************************************************************************************************************
 
71
 
 
72
    /**
 
73
     * Returns the number of rows of this model.
 
74
     * The number of rows is the number of dataObjects stored in the resultVector
 
75
     * @return the number of rows of this model
 
76
     */
 
77
    public int getRowCount() {
 
78
        if (resultVector == null)
 
79
            return 0;
 
80
        else
 
81
            return resultVector.size();
 
82
    }
 
83
 
 
84
    /**
 
85
     * Returns the number of columns of this model.
 
86
     * The number of columns is 4 (dataObject.key, dataobject, c_dist, r_dist)
 
87
     * @return int The number of columns of this model
 
88
     */
 
89
    public int getColumnCount() {
 
90
        if (resultVector == null)
 
91
            return 0;
 
92
 
 
93
        return 4;
 
94
    }
 
95
 
 
96
    /**
 
97
     * Returns the value for the JTable for a given position.
 
98
     * @param row The row of the value
 
99
     * @param column The column of the value
 
100
     * @return value
 
101
     * */
 
102
    public Object getValueAt(int row, int column) {
 
103
        DataObject dataObject = (DataObject) resultVector.elementAt(row);
 
104
 
 
105
        switch (column) {
 
106
            case 0:
 
107
                return dataObject.getKey();
 
108
            case 1:
 
109
                return dataObject;
 
110
            case 2:
 
111
                return ((dataObject.getCoreDistance() == DataObject.UNDEFINED) ?
 
112
                        "UNDEFINED" :
 
113
                        Utils.doubleToString(dataObject.getCoreDistance(), 3, 5));
 
114
            case 3:
 
115
                return ((dataObject.getReachabilityDistance() == DataObject.UNDEFINED) ?
 
116
                        "UNDEFINED" :
 
117
                        Utils.doubleToString(dataObject.getReachabilityDistance(), 3, 5));
 
118
            default:
 
119
                return "";
 
120
        }
 
121
    }
 
122
 
 
123
    // *****************************************************************************************************************
 
124
    // inner classes
 
125
    // *****************************************************************************************************************
 
126
 
 
127
}