1 7 package org.ejtools.graph; 8 9 import java.awt.Color ; 10 import java.awt.Graphics ; 11 import java.awt.GridLayout ; 12 import java.util.Collection ; 13 import java.util.Iterator ; 14 import java.util.Vector ; 15 16 import javax.swing.JComponent ; 17 import javax.swing.JPanel ; 18 19 26 public class CompositeTrack implements GraphElement, LabelElement 27 { 28 29 protected JPanel component; 30 31 protected GridLayout layout; 32 33 protected Collection tracks = new Vector (); 34 35 36 37 public CompositeTrack() 38 { 39 this.layout = new GridLayout (1, 1, 1, 1); 40 this.component = new JPanel (this.layout); 41 } 42 43 44 49 public void addTrack(Track t) 50 { 51 this.tracks.add(t); 52 this.layout.setRows(this.tracks.size()); 53 this.component.add(t.getComponent()); 54 } 55 56 57 58 public void clear() 59 { 60 synchronized (this.tracks) 61 { 62 for (Iterator it = this.tracks.iterator(); it.hasNext(); ) 63 { 64 ((Track) it.next()).clear(); 65 } 66 } 67 } 68 69 70 77 public void draw(Graphics graphics, double scaleX, double offsetX, double scaleY, double offsetY) 78 { 79 synchronized (this.tracks) 80 { 81 for (Iterator it = this.tracks.iterator(); it.hasNext(); ) 82 { 83 ((GraphElement) it.next()).draw(graphics, scaleX, offsetX, scaleY, offsetY); 84 } 85 } 86 } 87 88 89 92 public Color getColor() 93 { 94 return Color.black; 95 } 96 97 98 101 public JComponent getComponent() 102 { 103 return this.component; 104 } 105 106 107 110 public Range getXRange() 111 { 112 synchronized (this.tracks) 113 { 114 Range result = new Range(Double.MAX_VALUE, Double.MIN_VALUE); 115 for (Iterator it = this.tracks.iterator(); it.hasNext(); ) 116 { 117 result = result.compose(((GraphElement) it.next()).getXRange()); 118 } 119 return result; 120 } 121 } 122 123 124 127 public Range getYRange() 128 { 129 synchronized (this.tracks) 130 { 131 Range result = new Range(Double.MAX_VALUE, Double.MIN_VALUE); 132 for (Iterator it = this.tracks.iterator(); it.hasNext(); ) 133 { 134 result = result.compose(((GraphElement) it.next()).getYRange()); 135 } 136 return result; 137 } 138 } 139 140 141 146 public void removeTrack(Track t) 147 { 148 if (this.tracks.contains(t)) 149 { 150 this.component.remove(t.getComponent()); 151 this.tracks.remove(t); 152 this.layout.setRows(this.tracks.size()); 153 } 154 } 155 } 156 | Popular Tags |