| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AbstractHCClusteringInfo |
|
| 1.6666666666666667;1.667 |
| 1 | /* ======================================================================= | |
| 2 | * A visualisation library extension for JFreeChart. Please see JFreeChart | |
| 3 | * for further information. | |
| 4 | * ======================================================================= | |
| 5 | * Copyright (C) 2006 University of Helsinki, Department of Computer Science | |
| 6 | * | |
| 7 | * This library is free software; you can redistribute it and/or | |
| 8 | * modify it under the terms of the GNU Lesser General Public | |
| 9 | * License as published by the Free Software Foundation; either | |
| 10 | * version 2.1 of the License, or (at your option) any later version. | |
| 11 | * | |
| 12 | * This library is distributed in the hope that it will be useful, | |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 | * Lesser General Public License for more details. | |
| 16 | * | |
| 17 | * You should have received a copy of the GNU Lesser General Public | |
| 18 | * License along with this library; if not, write to the Free Software | |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | * ----------------------------- | |
| 21 | * Contact: ohtu@cs.helsinki.fi | |
| 22 | * ----------------------------- | |
| 23 | * | |
| 24 | */ | |
| 25 | ||
| 26 | package org.jfree.chart.plot; | |
| 27 | ||
| 28 | import java.util.Iterator; | |
| 29 | import java.util.LinkedList; | |
| 30 | import java.util.List; | |
| 31 | ||
| 32 | import javax.swing.event.ChangeEvent; | |
| 33 | import javax.swing.event.ChangeListener; | |
| 34 | ||
| 35 | import org.jfree.data.hc.HCTreeNode; | |
| 36 | import org.jfree.data.hc.DataRange; | |
| 37 | ||
| 38 | /** | |
| 39 | * A class that stores information about the state of a clustering tree. | |
| 40 | * used in {@link HCPlot}. This is organized as a tree with the same topology | |
| 41 | * as the original clustering tree. | |
| 42 | * | |
| 43 | * @author viski project | |
| 44 | */ | |
| 45 | 62 | public abstract class AbstractHCClusteringInfo { |
| 46 | ||
| 47 | protected LinkedList listeners; | |
| 48 | protected int location; | |
| 49 | protected String[] names; | |
| 50 | ||
| 51 | /** | |
| 52 | * Return the names of visible rows/columns corresponding to | |
| 53 | * this clustering info object. | |
| 54 | * | |
| 55 | * @return a list object containing the names. | |
| 56 | */ | |
| 57 | public abstract List getNames(); | |
| 58 | ||
| 59 | /** | |
| 60 | * Return the HCTreeNodeInfo corresponding to the root node | |
| 61 | * of the clustering tree. | |
| 62 | * | |
| 63 | * @return the root node, or null, if the clustering tree does not exist. | |
| 64 | */ | |
| 65 | public abstract HCTreeNodeInfo getRootNode(); | |
| 66 | ||
| 67 | /** | |
| 68 | * Returns the indices of the dataset that | |
| 69 | * correspond to specified visible index | |
| 70 | * | |
| 71 | * @param row the row. | |
| 72 | * @return The datarange specifying the indices. | |
| 73 | */ | |
| 74 | public abstract DataRange getDataRangeForVisibleIndex(int row); | |
| 75 | ||
| 76 | /** | |
| 77 | * Returns the visible data range. i.e. number of rows/columns | |
| 78 | * of a heatmap currently seen on the screen. | |
| 79 | * | |
| 80 | * @return The datarange specifying the visible indices. | |
| 81 | */ | |
| 82 | public abstract int getNumberOfVisibleItems(); | |
| 83 | ||
| 84 | /** | |
| 85 | * Returns a visible name for specified datarange. | |
| 86 | * | |
| 87 | * @param range The datarange. | |
| 88 | * @return The name. | |
| 89 | */ | |
| 90 | public String getName(DataRange range) { | |
| 91 | ||
| 92 | int leftBound; | |
| 93 | int rightBound; | |
| 94 | String leftName; | |
| 95 | String rightName; | |
| 96 | try { | |
| 97 | ||
| 98 | 119 | leftBound = range.getLeftBound(); |
| 99 | 113 | rightBound = range.getRightBound(); |
| 100 | ||
| 101 | 6 | } catch (Exception e) { |
| 102 | ||
| 103 | 6 | return "[]"; // this doesn't happen if used properly |
| 104 | ||
| 105 | 113 | } |
| 106 | try { | |
| 107 | ||
| 108 | 113 | leftName = names[leftBound]; |
| 109 | 111 | rightName = names[rightBound]; |
| 110 | ||
| 111 | 2 | } catch (Exception e) { |
| 112 | ||
| 113 | 2 | leftName = ""+leftBound; |
| 114 | 2 | rightName = ""+rightBound; |
| 115 | ||
| 116 | 111 | } |
| 117 | 113 | if (leftBound == rightBound) return leftName; |
| 118 | 36 | else return leftName + " - " + rightName; |
| 119 | ||
| 120 | } | |
| 121 | ||
| 122 | /** | |
| 123 | * Returns the location of this clustering tree. | |
| 124 | * | |
| 125 | * @return The location. Either HCPlot.LEFT or HCPlot.TOP. | |
| 126 | */ | |
| 127 | public int getLocation() { | |
| 128 | ||
| 129 | 3 | return this.location; |
| 130 | ||
| 131 | } | |
| 132 | ||
| 133 | /** | |
| 134 | * Adds a change listener | |
| 135 | * | |
| 136 | * @param listener the listener. | |
| 137 | */ | |
| 138 | public void addChangeListener(ChangeListener listener) { | |
| 139 | ||
| 140 | 43 | this.listeners.add((Object)listener); |
| 141 | ||
| 142 | 43 | } |
| 143 | ||
| 144 | /** | |
| 145 | * Removes a change listener | |
| 146 | * | |
| 147 | * @param listener the listener. | |
| 148 | */ | |
| 149 | public void removeChangeListener(ChangeListener listener) { | |
| 150 | ||
| 151 | 2 | this.listeners.remove((Object)listener); |
| 152 | ||
| 153 | 2 | } |
| 154 | ||
| 155 | /** | |
| 156 | * Notifies listeners of an event | |
| 157 | * | |
| 158 | * @param event the event. | |
| 159 | */ | |
| 160 | public void notifyChangeListeners(ChangeEvent event) { | |
| 161 | ||
| 162 | 14 | Iterator iterator = listeners.iterator(); |
| 163 | ChangeListener listener; | |
| 164 | ||
| 165 | 21 | while(iterator.hasNext()) { |
| 166 | ||
| 167 | 9 | listener = (ChangeListener)(iterator.next()); |
| 168 | 9 | listener.stateChanged (event); |
| 169 | ||
| 170 | 7 | } |
| 171 | ||
| 172 | 12 | } |
| 173 | ||
| 174 | } |