View Javadoc

1   package org.indi.client.swing;
2   
3   import java.awt.Container;
4   import java.awt.GridBagConstraints;
5   import java.awt.GridBagLayout;
6   import java.awt.Insets;
7   import java.io.IOException;
8   import java.util.HashMap;
9   import java.util.Map;
10  
11  import javax.swing.JButton;
12  import javax.swing.JLabel;
13  import javax.swing.JPanel;
14  import javax.swing.JTabbedPane;
15  
16  import org.indi.client.IndiClient;
17  import org.indi.objects.Element;
18  import org.indi.objects.Vector;
19  import org.indi.reactor.Reactor;
20  
21  class SicElement {
22      private final int yPosition;
23  
24      SicElement(int y) {
25  	this.yPosition = y;
26      };
27  
28      public int getyPosition() {
29  	return this.yPosition;
30      }
31  }
32  
33  class SicVector {
34      private final Map<String, SicElement> elements;
35      private final int yPosition;
36      private int MaxYPosition;
37      private final JPanel panel;
38      private final JLabel statusLabel;
39      private final JLabel nameLabel;
40      private final JButton setButton;
41  
42      SicVector(int y, JLabel status, JLabel name, JPanel p, JButton button) {
43  	this.yPosition = y;
44  	this.statusLabel = status;
45  	this.nameLabel = name;
46  	this.panel = p;
47  	this.setButton = button;
48  	this.elements = new HashMap<String, SicElement>();
49      };
50  
51      public int getyPosition() {
52  	return this.yPosition;
53      }
54  
55      public JPanel getPanel() {
56  	return this.panel;
57      }
58  
59      public JLabel getStatusLabel() {
60  	return this.statusLabel;
61      };
62  
63      public JLabel getNameLabel() {
64  	return this.nameLabel;
65      };
66  
67      private JButton getSetButton() {
68  	return this.setButton;
69      };
70  
71      public SicElement getElement(Element e) {
72  	SicElement se;
73  	String name = e.getName();
74  	if (this.elements.containsKey(name)) {
75  	    se = this.elements.get(name);
76  	} else {
77  	    JPanel p = new JPanel();
78  	    se = new SicElement(this.MaxYPosition);
79  	    this.MaxYPosition++;
80  	    this.elements.put(name, se);
81  	}
82  	return se;
83      };
84  }
85  
86  class SicGroup {
87      private final Map<String, SicVector> vectors;
88      private final JPanel component;
89      private int MaxYPosition;
90  
91      SicGroup(JPanel c) {
92  	this.component = c;
93  	this.vectors = new HashMap<String, SicVector>();
94  	this.MaxYPosition = 0;
95      };
96  
97      public JPanel getComponent() {
98  	return this.component;
99      }
100 
101     public SicVector getVector(Vector v) {
102 	SicVector sv;
103 	String name = v.getName();
104 	if (this.vectors.containsKey(name)) {
105 	    sv = this.vectors.get(name);
106 	} else {
107 	    GridBagConstraints c = new GridBagConstraints();
108 	    c.gridx = 0;
109 	    c.gridy = 0;
110 	    c.gridwidth = 1;
111 	    c.gridheight = 1;
112 	    c.fill = GridBagConstraints.HORIZONTAL
113 		    | GridBagConstraints.VERTICAL;
114 	    c.ipadx = 3;
115 	    c.ipady = 3;
116 	    c.insets = new Insets(3, 3, 3, 3);
117 	    JLabel statusLabel = new JLabel("Status");
118 	    this.component.add(statusLabel, c);
119 	    c.gridx = 1;
120 	    JLabel nameLabel = new JLabel(name);
121 	    this.component.add(nameLabel, c);
122 	    c.gridx = 2;
123 	    JPanel p = new JPanel(new GridBagLayout());
124 	    this.component.add(p, c);
125 	    c.gridx = 3;
126 	    c.fill = GridBagConstraints.NONE;
127 	    JButton setButton = new JButton("Set");
128 	    this.component.add(setButton, c);
129 	    sv = new SicVector(this.MaxYPosition, statusLabel, nameLabel, p,
130 		    setButton);
131 	    this.MaxYPosition++;
132 	    this.vectors.put(name, sv);
133 	}
134 	return sv;
135     };
136 }
137 
138 class SicDevice {
139     private final Map<String, SicGroup> groups;
140     private final JTabbedPane component;
141 
142     SicDevice(JTabbedPane c) {
143 	this.component = c;
144 	this.groups = new HashMap<String, SicGroup>();
145     };
146 
147     public JTabbedPane getComponent() {
148 	return this.component;
149     }
150 
151     public SicGroup getGroup(Vector v) {
152 	SicGroup g;
153 	String group = v.getGroup();
154 	if (this.groups.containsKey(group)) {
155 	    g = this.groups.get(group);
156 	} else {
157 	    JPanel p = new JPanel(new GridBagLayout());
158 	    this.component.addTab(group, p);
159 	    g = new SicGroup(p);
160 	    this.groups.put(group, g);
161 	}
162 	return g;
163     };
164 }
165 
166 class SicDevices {
167     private final Map<String, SicDevice> devices;
168     private final JTabbedPane component;
169 
170     SicDevices(JTabbedPane c) {
171 	this.component = c;
172 	this.devices = new HashMap<String, SicDevice>();
173     };
174 
175     public JTabbedPane getComponent() {
176 	return this.component;
177     }
178 
179     public SicDevice getDevice(Vector v) {
180 	SicDevice d;
181 	String device = v.getDevice();
182 	if (this.devices.containsKey(device)) {
183 	    d = this.devices.get(device);
184 	} else {
185 	    JTabbedPane tp = new JTabbedPane();
186 	    this.component.addTab(device, tp);
187 	    d = new SicDevice(tp);
188 	    this.devices.put(device, d);
189 	}
190 	return d;
191     };
192 }
193 
194 public class SwingIndiClient extends IndiClient {
195     SicDevices devices;
196 
197     public SwingIndiClient(Reactor r, Container c) throws IOException {
198 	super(r);
199     }
200 
201     public void onNewVector(Vector v) {
202 
203     }
204 
205 }