source: src/main/java/weka/gui/treevisualizer/Edge.java @ 19

Last change on this file since 19 was 4, checked in by gnappo, 14 years ago

Import di weka.

File size: 4.8 KB
Line 
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 *    Edge.java
19 *    Copyright (C) 1999 University of Waikato, Hamilton, New Zealand
20 *
21 */
22
23package weka.gui.treevisualizer;
24
25import java.util.*;
26import java.awt.*;
27
28
29/**
30 * This class is used in conjunction with the Node class to form a tree
31 * structure.
32 * This in particular contains information about an edges in the tree.
33 *
34 * @author Malcolm Ware (mfw4@cs.waikato.ac.nz)
35 * @version $Revision: 1.4 $
36 */
37public class Edge {
38  /** The text caption for the edge. */
39  private String m_label;
40
41  /** The ID string of the parent Node of this edge (used for consrtuction
42   * purposes). */
43  private String m_rsource;
44
45  /** The ID string of the child Node of this edge (used for construction
46   * purposes). */
47  private String m_rtarget;
48
49  /** The parent Node of this edge. */
50  private Node m_source;
51
52  /** The child Node of this edge. */
53  private Node m_target;
54
55  /** The label broken up into lines. */
56  private Vector m_lines;
57
58  /**
59   * This constructs an Edge with the specified label
60   * and parent , child serial tags.
61   *
62   * @param label The text caption for the edge.
63   * @param source The ID string for this edges parent.
64   * @param target The ID string for this edges child.
65   */
66  public Edge(String label,String source,String target) {
67    m_label = label;
68    m_rsource = source;
69    m_rtarget = target;
70    m_lines = new Vector(3,2);
71    breakupLabel();
72  }
73
74 
75  /**
76   * Get the value of label.
77   *
78   * @return Value of label.
79   */
80  public String getLabel() {
81   
82    return m_label;
83  }
84 
85  /**
86   * This function is called to break the label of the edge up in to
87   * seperate lines
88   */
89  private void breakupLabel() {
90    int prev = 0,noa;
91    for (noa = 0;noa < m_label.length();noa++) {
92      if (m_label.charAt(noa) == '\n') {
93        m_lines.addElement(m_label.substring(prev,noa));
94        prev = noa+1;
95      }
96    }
97    m_lines.addElement(m_label.substring(prev,noa));
98  }
99 
100  /**
101   * This will calculate how large a rectangle using the <i>FontMetrics</i>
102   * passed that the lines of the label will take up
103   *
104   * @param f The size information for a particular Font
105   * @return A Dimension containing the size and width of the text
106   */
107  public Dimension stringSize(FontMetrics f) {
108    Dimension d = new Dimension();
109    int old = 0;
110    String s;
111    int noa = 0;
112    while ((s = getLine(noa)) != null) {
113      noa++;
114      old = f.stringWidth(s);
115     
116      if (old > d.width) {
117        d.width = old;
118      }
119    }
120    d.height = noa * f.getHeight();
121    return d;
122  }
123 
124  /**
125   * Returns line number <i>n</i>
126   *
127   * @param n The number of the line requested
128   * @return The string for the line number or NULL if it didn't exist
129   */ 
130  public String getLine(int n) {
131    if (n < m_lines.size()) {
132      return (String)m_lines.elementAt(n);
133    }
134    else {
135      return null;
136    }
137  }
138 
139 
140  /**
141   * Get the value of rsource.
142   *
143   * @return Value of rsource.
144   */
145  public String getRsource() {
146   
147    return m_rsource;
148  }
149 
150  /**
151   * Set the value of rsource.
152   *
153   * @param v  Value to assign to rsource.
154   */
155  public void setRsource(String v) {
156   
157    m_rsource = v;
158  }
159 
160 
161 
162  /**
163   * Get the value of rtarget.
164   *
165   * @return Value of rtarget.
166   */
167  public String getRtarget() {
168   
169    return m_rtarget;
170  }
171 
172  /**
173   * Set the value of rtarget.
174   *
175   * @param v Value to assign to rtarget.
176   */
177  public void setRtarget(String v) {
178   
179    m_rtarget = v;
180  }
181 
182  /**
183   * Get the value of source.
184   *
185   * @return Value of source.
186   */
187  public Node getSource() {
188   
189    return m_source;
190  }
191 
192  /**
193   * Set the value of source. And then call v.addChild to add the edge to
194   * the Node.
195   *
196   * @param v  Value to assign to source.
197   */
198  public void setSource(Node v) {
199   
200    m_source = v;
201    v.addChild(this);
202  }
203 
204  /**
205   * Get the value of target.
206   *
207   * @return Value of target.
208   */
209  public Node getTarget() {
210   
211    return m_target;
212  }
213 
214  /**
215   * Set the value of target. And then call v.addParent to add the edge to
216   * the Node.
217   *
218   * @param v Value to assign to target.
219   */
220  public void setTarget(Node v) {
221   
222    m_target = v;
223    v.setParent(this);
224  }
225}
226
227
228
229
230
Note: See TracBrowser for help on using the repository browser.