aboutsummaryrefslogtreecommitdiff
path: root/src/StatPlotCreationDialog.java
blob: a1e4ee739645198690cecf8206a4dbf4f681acf4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*     */ import GUIComponents.PushablePanel;
/*     */ import java.awt.Color;
/*     */ import java.awt.Component;
/*     */ import java.awt.Dimension;
/*     */ import java.awt.FlowLayout;
/*     */ import java.awt.Graphics;
/*     */ import java.awt.event.ActionEvent;
/*     */ import java.awt.event.ActionListener;
/*     */ import java.awt.image.BufferedImage;
/*     */ import java.util.ArrayList;
/*     */ import javax.swing.AbstractButton;
/*     */ import javax.swing.BorderFactory;
/*     */ import javax.swing.BoxLayout;
/*     */ import javax.swing.Icon;
/*     */ import javax.swing.ImageIcon;
/*     */ import javax.swing.JButton;
/*     */ import javax.swing.JCheckBox;
/*     */ import javax.swing.JColorChooser;
/*     */ import javax.swing.JComboBox;
/*     */ import javax.swing.JComponent;
/*     */ import javax.swing.JDialog;
/*     */ import javax.swing.JLabel;
/*     */ import javax.swing.JPanel;
/*     */ import javax.swing.JSpinner;
/*     */ import javax.swing.JTextField;
/*     */ import javax.swing.event.ChangeEvent;
/*     */ import javax.swing.event.ChangeListener;
/*     */ 
/*     */ public class StatPlotCreationDialog extends JDialog
/*     */   implements ActionListener, ChangeListener
/*     */ {
/*     */   private static final int invoker_length = 3;
/*  34 */   private PushablePanel panel = new PushablePanel();
/*     */   private JButton add;
/*     */   private JButton cancel;
/*     */   private JButton delete;
/*     */   private JButton ok;
/*  36 */   private StatPlot ret = null;
/*     */   private GraphTranslator translate;
/*     */   private StatPlotDialog owner;
/*     */   private Color colorChosen;
/*     */   private JButton colorButton;
/*  41 */   private ExtendedPointInvoker[] invokers = { 
/*  42 */     new ExtendedPointInvoker.SquarePointInvoker(5, Color.black), 
/*  43 */     new ExtendedPointInvoker.SquareFillPointInvoker(5, Color.black), 
/*  44 */     new ExtendedPointInvoker.CirclePointInvoker(5, Color.black), 
/*  45 */     new ExtendedPointInvoker.PixelPointInvoker(Color.black) };
/*     */   private JComboBox combobox;
/*     */   private JSpinner spinner;
/*     */   private int editNumber;
/*     */ 
/*     */   public StatPlotCreationDialog(StatPlotDialog owner, GraphTranslator translate, int editNumber)
/*     */   {
/*  52 */     super(owner, "Statplot Maker", true);
/*  53 */     this.owner = owner;
/*  54 */     this.translate = translate;
/*  55 */     this.editNumber = editNumber;
/*  56 */     this.colorChosen = Color.black;
/*  57 */     this.colorButton = new JButton(getButtonIcon());
/*  58 */     this.colorButton.setPreferredSize(new Dimension(30, 30));
/*  59 */     this.colorButton.addActionListener(this);
/*  60 */     this.combobox = new JComboBox();
/*  61 */     hideArrow();
/*  62 */     this.combobox.setPreferredSize(new Dimension(80, 30));
/*  63 */     this.spinner = new JSpinner();
/*  64 */     this.spinner.addChangeListener(this);
/*  65 */     updateOptions();
/*  66 */     JPanel main = new JPanel();
/*  67 */     JPanel buttons = new JPanel(new FlowLayout());
/*  68 */     JPanel head = new JPanel(new FlowLayout());
/*  69 */     JPanel addDelete = new JPanel();
/*  70 */     this.panel = new PushablePanel();
/*  71 */     addDelete.setLayout(new BoxLayout(addDelete, 1));
/*  72 */     main.setLayout(new BoxLayout(main, 1));
/*     */ 
/*  74 */     addDelete.setPreferredSize(new Dimension(105, 250));
/*  75 */     this.panel.setPreferredSize(new Dimension(200, 250));
/*  76 */     buttons.setPreferredSize(new Dimension(350, 50));
/*     */ 
/*  78 */     this.add = new JButton("add");
/*  79 */     this.cancel = new JButton("Cancel");
/*  80 */     this.delete = new JButton("delete");
/*  81 */     this.ok = new JButton("Apply");
/*  82 */     JPanel addhold = new JPanel();
/*  83 */     JPanel deletehold = new JPanel();
/*  84 */     this.add.addActionListener(this);
/*  85 */     this.cancel.addActionListener(this);
/*  86 */     this.delete.addActionListener(this);
/*  87 */     this.ok.addActionListener(this);
/*  88 */     addhold.add(this.add);
/*  89 */     deletehold.add(this.delete);
/*  90 */     addDelete.add(addhold);
/*  91 */     addDelete.add(deletehold);
/*     */ 
/*  93 */     buttons.add(this.ok);
/*  94 */     buttons.add(this.cancel);
/*     */ 
/*  96 */     JPanel options = new JPanel();
/*  97 */     JPanel options1 = new JPanel(new FlowLayout());
/*  98 */     JPanel options2 = new JPanel(new FlowLayout());
/*  99 */     options.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLoweredBevelBorder(), "Options"));
/* 100 */     options.setLayout(new BoxLayout(options, 1));
/* 101 */     options.setPreferredSize(new Dimension(105, 175));
/* 102 */     options1.add(this.colorButton);
/* 103 */     options1.add(this.combobox);
/* 104 */     options2.add(this.spinner);
/* 105 */     options.add(options1);
/* 106 */     options.add(options2);
/*     */ 
/* 108 */     addDelete.add(options);
/* 109 */     head.add(this.panel);
/* 110 */     head.add(addDelete);
/*     */ 
/* 112 */     main.add(head);
/* 113 */     main.add(buttons);
/*     */ 
/* 115 */     add(main);
/* 116 */     setPreferredSize(new Dimension(325, 350));
/* 117 */     setResizable(false);
/* 118 */     pack();
/*     */   }
/*     */ 
/*     */   public StatPlot getPlot()
/*     */   {
/* 146 */     ArrayList comps = this.panel.getPushedComponents();
/* 147 */     ArrayList points = new ArrayList();
/* 148 */     for (int i = 0; i < comps.size(); i++) {
/* 149 */       if ((comps.get(i) instanceof StatPlotCreationDialog.PointPanel)) {
/* 150 */         StatPlotCreationDialog.PointPanel pointpanel = (StatPlotCreationDialog.PointPanel)comps.get(i);
/* 151 */         points.add(pointpanel.getPoint());
/*     */       }
/*     */     }
/* 154 */     return new StatPlot(points, this.invokers[this.combobox.getSelectedIndex()], this.translate);
/*     */   }
/*     */   private void sweep() {
/* 157 */     ArrayList delete = new ArrayList();
/* 158 */     ArrayList comps = this.panel.getPushedComponents();
/* 159 */     for (int i = 0; i < comps.size(); i++) {
/* 160 */       if ((comps.get(i) instanceof StatPlotCreationDialog.PointPanel)) {
/* 161 */         StatPlotCreationDialog.PointPanel comp = (StatPlotCreationDialog.PointPanel)comps.get(i);
/* 162 */         if (comp.isSelected()) {
/* 163 */           delete.add(comp);
/*     */         }
/*     */       }
/*     */     }
/* 167 */     for (int i = 0; i < delete.size(); i++)
/* 168 */       this.panel.removeComponent((JComponent)delete.get(i));
/*     */   }
/*     */ 
/*     */   public void actionPerformed(ActionEvent e)
/*     */   {
/* 173 */     if (e.getSource() == this.cancel) {
/* 174 */       setVisible(false);
/* 175 */     } else if (e.getSource() == this.add) {
/* 176 */       this.panel.pushComponent(new StatPlotCreationDialog.PointPanel());
/* 177 */     } else if (e.getSource() == this.delete) {
/* 178 */       sweep();
/* 179 */     } else if (e.getSource() == this.ok) {
/* 180 */       boolean upset = false;
/*     */       try {
/* 182 */         this.owner.setStatPlot(getPlot(), this.editNumber);
/*     */       }
/*     */       catch (Exception c) {
/* 185 */         upset = true;
/* 186 */         new ComplicationAlert(this, "One or more points cannot be parsed");
/* 187 */         c.printStackTrace();
/*     */       }
/*     */       finally {
/* 190 */         if (!upset)
/* 191 */           setVisible(false);
/*     */       }
/* 193 */     } else if (e.getSource() == this.colorButton) {
/* 194 */       this.colorChosen = JColorChooser.showDialog(this, "Choose a button color: ", this.colorChosen);
/* 195 */       updateOptions();
/*     */     }
/*     */   }
/*     */ 
/*     */   private Icon getButtonIcon() {
/* 200 */     BufferedImage bi = new BufferedImage(25, 25, 1);
/* 201 */     Graphics g = bi.getGraphics();
/* 202 */     g.setColor(this.colorChosen);
/* 203 */     g.fillRect(0, 0, 25, 25);
/* 204 */     return new ImageIcon(bi);
/*     */   }
/*     */   private Icon makeIconInstance(PointInvoker invoker, int spinneramt) {
/* 207 */     BufferedImage bi = new BufferedImage(25, 25, 1);
/* 208 */     Graphics g = bi.getGraphics();
/* 209 */     g.setColor(Color.white);
/* 210 */     g.fillRect(0, 0, 25, 25);
/* 211 */     invoker.drawPoint(g, 13, 13);
/* 212 */     return new ImageIcon(bi);
/*     */   }
/*     */   private void hideArrow() {
/* 215 */     Component[] c = this.combobox.getComponents();
/* 216 */     for (Component x : c)
/* 217 */       if ((x instanceof AbstractButton))
/* 218 */         ((AbstractButton)x).setVisible(false);
/*     */   }
/*     */ 
/*     */   private void updateOptions()
/*     */   {
/* 223 */     this.colorButton.setIcon(getButtonIcon());
/* 224 */     int selected = this.combobox.getSelectedIndex();
/* 225 */     int spinneramt = ((Integer)this.spinner.getValue()).intValue();
/* 226 */     this.combobox.removeAllItems();
/*     */ 
/* 228 */     for (ExtendedPointInvoker x : this.invokers) {
/* 229 */       x.setColor(this.colorChosen);
/* 230 */       x.setSize(spinneramt);
/*     */     }
/* 232 */     for (int i = 0; i < this.invokers.length; i++) {
/* 233 */       this.combobox.addItem(makeIconInstance(this.invokers[i], spinneramt));
/*     */     }
/* 235 */     this.combobox.setSelectedIndex(selected);
/* 236 */     this.combobox.updateUI();
/* 237 */     this.spinner.updateUI();
/* 238 */     this.colorButton.updateUI();
/*     */   }
/*     */ 
/*     */   public void stateChanged(ChangeEvent e)
/*     */   {
/* 243 */     if (e.getSource() == this.spinner) updateOptions();
/*     */   }
/*     */ 
/*     */   private class PointPanel extends JPanel
/*     */   {
/*     */     private JTextField xVal;
/*     */     private JTextField yVal;
/*     */     private JCheckBox box;
/*     */ 
/*     */     public PointPanel()
/*     */     {
/* 125 */       this.box = new JCheckBox();
/* 126 */       this.xVal = new JTextField("0.0", 4);
/* 127 */       this.yVal = new JTextField("0.0", 4);
/* 128 */       setLayout(new FlowLayout());
/* 129 */       add(this.box);
/* 130 */       add(new JLabel("("));
/* 131 */       add(this.xVal);
/* 132 */       add(new JLabel(","));
/* 133 */       add(this.yVal);
/* 134 */       add(new JLabel("),"));
/*     */     }
/*     */ 
/*     */     public Point2D getPoint() {
/* 138 */       return new Point2D(Double.parseDouble(this.xVal.getText()), Double.parseDouble(this.yVal.getText()));
/*     */     }
/*     */     public boolean isSelected() {
/* 141 */       return this.box.isSelected();
/*     */     }
/*     */   }
/*     */ }

/* Location:           Modulus.jar
 * Qualified Name:     StatPlotCreationDialog
 * JD-Core Version:    0.6.2
 */