1 | /* |
---|
2 | * $Id: PanelModelCustomizer.java,v 1.3 2003/08/27 23:29:40 dwd Exp $ |
---|
3 | * |
---|
4 | * This software is provided by NOAA for full, free and open release. It is |
---|
5 | * understood by the recipient/user that NOAA assumes no liability for any |
---|
6 | * errors contained in the code. Although this software is released without |
---|
7 | * conditions or restrictions in its use, it is expected that appropriate |
---|
8 | * credit be given to its author and to the National Oceanic and Atmospheric |
---|
9 | * Administration should the software be included by the recipient as an |
---|
10 | * element in other product development. |
---|
11 | */ |
---|
12 | |
---|
13 | package gov.noaa.pmel.sgt.beans; |
---|
14 | |
---|
15 | import java.beans.Customizer; |
---|
16 | import java.io.File; |
---|
17 | import java.io.FileNotFoundException; |
---|
18 | import java.io.BufferedOutputStream; |
---|
19 | import java.io.FileOutputStream; |
---|
20 | import javax.swing.filechooser.FileFilter; |
---|
21 | import java.awt.*; |
---|
22 | import javax.swing.*; |
---|
23 | import javax.swing.table.DefaultTableModel; |
---|
24 | import javax.swing.table.TableModel; |
---|
25 | import javax.swing.table.TableColumnModel; |
---|
26 | import javax.swing.table.TableColumn; |
---|
27 | import javax.swing.ListSelectionModel; |
---|
28 | import javax.swing.border.*; |
---|
29 | import java.util.Vector; |
---|
30 | import java.util.Iterator; |
---|
31 | import java.awt.event.*; |
---|
32 | import java.beans.PropertyChangeEvent; |
---|
33 | import java.beans.PropertyChangeListener; |
---|
34 | |
---|
35 | import java.awt.event.MouseEvent; |
---|
36 | import java.awt.event.MouseListener; |
---|
37 | import java.awt.event.MouseMotionListener; |
---|
38 | |
---|
39 | import gov.noaa.pmel.sgt.SGLabel; |
---|
40 | import gov.noaa.pmel.util.Point2D; |
---|
41 | import gov.noaa.pmel.util.Rectangle2D; |
---|
42 | import gov.noaa.pmel.util.SimpleFileFilter; |
---|
43 | import gov.noaa.pmel.swing.MRJUtil; |
---|
44 | import javax.swing.event.AncestorEvent; |
---|
45 | import javax.swing.event.AncestorListener; |
---|
46 | /** |
---|
47 | * Used at design time to customize a <code>PanelModel</code>. This class is also |
---|
48 | * used by <code>PanelModelEditor</code> for run-time changes to the <code>PanelModel</code>. |
---|
49 | * |
---|
50 | * @author Donald Denbo |
---|
51 | * @version $Revision: 1.3 $, $Date: 2003/08/27 23:29:40 $ |
---|
52 | * @since 3.0 |
---|
53 | * @see PanelModelEditor |
---|
54 | * @see PanelModel |
---|
55 | */ |
---|
56 | public class PanelModelCustomizer extends JComponent implements Customizer, PropertyChangeListener { |
---|
57 | /** |
---|
58 | * @supplierCardinality 1 |
---|
59 | */ |
---|
60 | private PanelModel panelModel_ = null; |
---|
61 | private JFileChooser fileChooser_ = null; |
---|
62 | private BorderLayout borderLayout1 = new BorderLayout(); |
---|
63 | private JPanel messagePanel = new JPanel(); |
---|
64 | private JTextField message = new JTextField(); |
---|
65 | private BorderLayout borderLayout2 = new BorderLayout(); |
---|
66 | private JPanel mainPanel = new JPanel(); |
---|
67 | private BorderLayout borderLayout3 = new BorderLayout(); |
---|
68 | private JPanel layoutPanel = new JPanel(); |
---|
69 | private BorderLayout borderLayout4 = new BorderLayout(); |
---|
70 | private JPanel toolPanel = new JPanel(); |
---|
71 | private JButton newPanelButton = new JButton(); |
---|
72 | |
---|
73 | /** |
---|
74 | *@link aggregationByValue |
---|
75 | * @associates <{PanelView}> |
---|
76 | * @supplierCardinality * |
---|
77 | */ |
---|
78 | /* private Vector lnkPanelView; */ |
---|
79 | private DesignPanel designPanel_ = new DesignPanel(); |
---|
80 | private FlowLayout flowLayout1 = new FlowLayout(); |
---|
81 | private JButton alignBottomButton = new JButton(); |
---|
82 | private JButton alignTopButton = new JButton(); |
---|
83 | private JButton alignLeftButton = new JButton(); |
---|
84 | private JButton alignRightButton = new JButton(); |
---|
85 | private JButton justVerticalButton = new JButton(); |
---|
86 | private JButton justHorizontalButton = new JButton(); |
---|
87 | private ImageIcon alignBottom_ = new ImageIcon(getClass().getResource("images/AlignBottom24.gif"),"Align Bottom"); |
---|
88 | private ImageIcon alignTop_ = new ImageIcon(getClass().getResource("images/AlignTop24.gif"),"Align Top"); |
---|
89 | private ImageIcon alignLeft_ = new ImageIcon(getClass().getResource("images/AlignLeft24.gif"),"Align Left"); |
---|
90 | private ImageIcon alignRight_ = new ImageIcon(getClass().getResource("images/AlignRight24.gif"),"Align Right"); |
---|
91 | private ImageIcon justifyVertical_ = new ImageIcon(getClass().getResource("images/AlignJustifyVertical24.gif"),"Justify Vertical"); |
---|
92 | private ImageIcon justifyHorizontal_ = new ImageIcon(getClass().getResource("images/AlignJustifyHorizontal24.gif"),"Justify Horizontal"); |
---|
93 | private ImageIcon newPanel_ = new ImageIcon(getClass().getResource("images/New24.gif"), "New Panel"); |
---|
94 | private ImageIcon newDataGroup_ = new ImageIcon(getClass().getResource("images/NewDataGroup24.gif"), "New Data Group"); |
---|
95 | private ImageIcon newLabel_ = new ImageIcon(getClass().getResource("images/NewLabel24.gif"), "New Label"); |
---|
96 | private ImageIcon newLegend_ = new ImageIcon(getClass().getResource("images/NewLegend24.gif"), "New Legend"); |
---|
97 | private ImageIcon removePanel_ = new ImageIcon(getClass().getResource("images/Remove24.gif"), "Remove Panel"); |
---|
98 | private ImageIcon saveAsPanel_ = new ImageIcon(getClass().getResource("images/SaveAs24.gif"), "Save PanelModel"); |
---|
99 | private ImageIcon openPanel_ = new ImageIcon(getClass().getResource("images/Open24.gif"), "Open PanelModel"); |
---|
100 | private Component component2; |
---|
101 | private Component component3; |
---|
102 | private JButton removeButton = new JButton(); |
---|
103 | private Component component1; |
---|
104 | private JPanel propertyPanel = new JPanel(); |
---|
105 | private JPanel leftPanel = new JPanel(); |
---|
106 | private TitledBorder propertyBorder; |
---|
107 | private JScrollPane jScrollPane1 = new JScrollPane(); |
---|
108 | private BorderLayout borderLayout5 = new BorderLayout(); |
---|
109 | private JButton newDataGroupButton = new JButton(); |
---|
110 | private JButton newLabelButton = new JButton(); |
---|
111 | private JButton newLegendButton = new JButton(); |
---|
112 | private JScrollPane designScroller = new JScrollPane(); |
---|
113 | |
---|
114 | private PanelHolderPropertyPanel phPropertyPanel_ = null; |
---|
115 | private LabelPropertyPanel labelPropertyPanel_ = null; |
---|
116 | private LegendPropertyPanel legendPropertyPanel_ = null; |
---|
117 | private DataGroupPropertyPanel agPropertyPanel_ = null; |
---|
118 | private AxisHolderPropertyPanel ahPropertyPanel_ = null; |
---|
119 | private PanelModelPropertyPanel pmPropertyPanel_ = null; |
---|
120 | private PropertyPanel currentPropertyPanel_ = null; |
---|
121 | |
---|
122 | private JPanel grayPanel = new JPanel(); |
---|
123 | private BorderLayout borderLayout6 = new BorderLayout(); |
---|
124 | private BorderLayout borderLayout7 = new BorderLayout(); |
---|
125 | private JPanel jPanel1 = new JPanel(); |
---|
126 | private JCheckBox expertCB = new JCheckBox(); |
---|
127 | private GridBagLayout gridBagLayout2 = new GridBagLayout(); |
---|
128 | private JButton openPanelButton = new JButton(); |
---|
129 | private JButton saveAsPanelButton = new JButton(); |
---|
130 | private Component component5; |
---|
131 | |
---|
132 | /** |
---|
133 | * <code>PanelModelCustomizer</code> constructor. |
---|
134 | */ |
---|
135 | public PanelModelCustomizer() { |
---|
136 | try { |
---|
137 | jbInit(); |
---|
138 | } |
---|
139 | catch(Exception e) { |
---|
140 | e.printStackTrace(); |
---|
141 | } |
---|
142 | designPanel_.addPropertyChangeListener(this); |
---|
143 | setPanelButtons(0); |
---|
144 | } |
---|
145 | |
---|
146 | /** |
---|
147 | * Set a <code>PanelModel</code> to be customized. |
---|
148 | * @param panelModel PanelModel |
---|
149 | * @see PanelModel |
---|
150 | */ |
---|
151 | public void setObject(Object panelModel) { |
---|
152 | panelModel_ = (PanelModel)panelModel; |
---|
153 | designPanel_.setPanelModel(panelModel_); |
---|
154 | pmPropertyPanel_ = new PanelModelPropertyPanel(panelModel_); |
---|
155 | setDefaultPanel(); |
---|
156 | if(Page.DEBUG) System.out.println("Customizer setObject()"); |
---|
157 | } |
---|
158 | |
---|
159 | private void jbInit() throws Exception { |
---|
160 | component2 = Box.createHorizontalStrut(8); |
---|
161 | component3 = Box.createHorizontalStrut(8); |
---|
162 | component1 = Box.createHorizontalStrut(8); |
---|
163 | propertyBorder = new TitledBorder(BorderFactory.createLineBorder(new Color(153, 153, 153),2),"Parameter"); |
---|
164 | component5 = Box.createHorizontalStrut(8); |
---|
165 | this.setLayout(borderLayout1); |
---|
166 | message.setText("Important information will go here."); |
---|
167 | messagePanel.setLayout(borderLayout2); |
---|
168 | messagePanel.setBorder(BorderFactory.createLoweredBevelBorder()); |
---|
169 | mainPanel.setLayout(borderLayout3); |
---|
170 | layoutPanel.setLayout(borderLayout4); |
---|
171 | leftPanel.setLayout(borderLayout7); |
---|
172 | newPanelButton.addActionListener(new java.awt.event.ActionListener() { |
---|
173 | public void actionPerformed(ActionEvent e) { |
---|
174 | newPanelButton_actionPerformed(e); |
---|
175 | } |
---|
176 | }); |
---|
177 | toolPanel.setLayout(flowLayout1); |
---|
178 | toolPanel.setBorder(BorderFactory.createEtchedBorder()); |
---|
179 | designPanel_.setLayout(null); |
---|
180 | alignBottomButton.setToolTipText("Align Bottom"); |
---|
181 | alignBottomButton.setIcon(alignBottom_); |
---|
182 | alignBottomButton.addActionListener(new java.awt.event.ActionListener() { |
---|
183 | public void actionPerformed(ActionEvent e) { |
---|
184 | alignBottomButton_actionPerformed(e); |
---|
185 | } |
---|
186 | }); |
---|
187 | alignLeftButton.setToolTipText("Align Left"); |
---|
188 | alignLeftButton.setIcon(alignLeft_); |
---|
189 | alignLeftButton.addActionListener(new java.awt.event.ActionListener() { |
---|
190 | public void actionPerformed(ActionEvent e) { |
---|
191 | alignLeftButton_actionPerformed(e); |
---|
192 | } |
---|
193 | }); |
---|
194 | alignTopButton.setToolTipText("Align Top"); |
---|
195 | alignTopButton.setIcon(alignTop_); |
---|
196 | alignTopButton.addActionListener(new java.awt.event.ActionListener() { |
---|
197 | public void actionPerformed(ActionEvent e) { |
---|
198 | alignTopButton_actionPerformed(e); |
---|
199 | } |
---|
200 | }); |
---|
201 | alignRightButton.setToolTipText("Align Right"); |
---|
202 | alignRightButton.setIcon(alignRight_); |
---|
203 | alignRightButton.addActionListener(new java.awt.event.ActionListener() { |
---|
204 | public void actionPerformed(ActionEvent e) { |
---|
205 | alignRightButton_actionPerformed(e); |
---|
206 | } |
---|
207 | }); |
---|
208 | newPanelButton.setToolTipText("New Panel"); |
---|
209 | newPanelButton.setIcon(newPanel_); |
---|
210 | justVerticalButton.setToolTipText("Justify Vertically"); |
---|
211 | justVerticalButton.setIcon(justifyVertical_); |
---|
212 | justVerticalButton.addActionListener(new java.awt.event.ActionListener() { |
---|
213 | public void actionPerformed(ActionEvent e) { |
---|
214 | justVerticalButton_actionPerformed(e); |
---|
215 | } |
---|
216 | }); |
---|
217 | justHorizontalButton.setToolTipText("Justify Horizontally"); |
---|
218 | justHorizontalButton.setIcon(justifyHorizontal_); |
---|
219 | justHorizontalButton.addActionListener(new java.awt.event.ActionListener() { |
---|
220 | public void actionPerformed(ActionEvent e) { |
---|
221 | justHorizontalButton_actionPerformed(e); |
---|
222 | } |
---|
223 | }); |
---|
224 | removeButton.setToolTipText("Remove Panel"); |
---|
225 | removeButton.setIcon(removePanel_); |
---|
226 | removeButton.addActionListener(new java.awt.event.ActionListener() { |
---|
227 | public void actionPerformed(ActionEvent e) { |
---|
228 | removeButton_actionPerformed(e); |
---|
229 | } |
---|
230 | }); |
---|
231 | this.setPreferredSize(new Dimension(800, 600)); |
---|
232 | propertyPanel.setBorder(propertyBorder); |
---|
233 | propertyPanel.setMinimumSize(new Dimension(240, 10)); |
---|
234 | propertyPanel.setPreferredSize(new Dimension(240, 10)); |
---|
235 | propertyPanel.setLayout(borderLayout5); |
---|
236 | propertyBorder.setTitle("Properties"); |
---|
237 | newDataGroupButton.setToolTipText("New Data Group"); |
---|
238 | newDataGroupButton.setIcon(newDataGroup_); |
---|
239 | newDataGroupButton.addActionListener(new java.awt.event.ActionListener() { |
---|
240 | public void actionPerformed(ActionEvent e) { |
---|
241 | newDataGroupButton_actionPerformed(e); |
---|
242 | } |
---|
243 | }); |
---|
244 | newLabelButton.setToolTipText("New Label"); |
---|
245 | newLabelButton.setIcon(newLabel_); |
---|
246 | newLabelButton.addActionListener(new java.awt.event.ActionListener() { |
---|
247 | public void actionPerformed(ActionEvent e) { |
---|
248 | newLabelButton_actionPerformed(e); |
---|
249 | } |
---|
250 | }); |
---|
251 | newLegendButton.setToolTipText("New Legend"); |
---|
252 | newLegendButton.setIcon(newLegend_); |
---|
253 | newLegendButton.addActionListener(new java.awt.event.ActionListener() { |
---|
254 | public void actionPerformed(ActionEvent e) { |
---|
255 | newLegendButton_actionPerformed(e); |
---|
256 | } |
---|
257 | }); |
---|
258 | grayPanel.setBackground(Color.lightGray); |
---|
259 | grayPanel.setLayout(borderLayout6); |
---|
260 | expertCB.setText("Expert"); |
---|
261 | expertCB.addActionListener(new java.awt.event.ActionListener() { |
---|
262 | public void actionPerformed(ActionEvent e) { |
---|
263 | expertCB_actionPerformed(e); |
---|
264 | } |
---|
265 | }); |
---|
266 | jPanel1.setLayout(gridBagLayout2); |
---|
267 | openPanelButton.addActionListener(new java.awt.event.ActionListener() { |
---|
268 | public void actionPerformed(ActionEvent e) { |
---|
269 | openPanelButton_actionPerformed(e); |
---|
270 | } |
---|
271 | }); |
---|
272 | openPanelButton.setEnabled(false); |
---|
273 | openPanelButton.setToolTipText("Open Panel"); |
---|
274 | openPanelButton.setIcon(openPanel_); |
---|
275 | saveAsPanelButton.addActionListener(new java.awt.event.ActionListener() { |
---|
276 | public void actionPerformed(ActionEvent e) { |
---|
277 | saveAsPanelButton_actionPerformed(e); |
---|
278 | } |
---|
279 | }); |
---|
280 | saveAsPanelButton.setToolTipText("Save Panel"); |
---|
281 | saveAsPanelButton.setIcon(saveAsPanel_); |
---|
282 | this.add(messagePanel, BorderLayout.SOUTH); |
---|
283 | messagePanel.add(message, BorderLayout.CENTER); |
---|
284 | this.add(mainPanel, BorderLayout.CENTER); |
---|
285 | mainPanel.add(layoutPanel, BorderLayout.CENTER); |
---|
286 | toolPanel.add(openPanelButton, null); |
---|
287 | toolPanel.add(saveAsPanelButton, null); |
---|
288 | toolPanel.add(component5, null); |
---|
289 | toolPanel.add(newPanelButton, null); |
---|
290 | toolPanel.add(newDataGroupButton, null); |
---|
291 | toolPanel.add(newLabelButton, null); |
---|
292 | toolPanel.add(newLegendButton, null); |
---|
293 | toolPanel.add(component3, null); |
---|
294 | toolPanel.add(removeButton, null); |
---|
295 | toolPanel.add(component1, null); |
---|
296 | toolPanel.add(alignBottomButton, null); |
---|
297 | toolPanel.add(alignTopButton, null); |
---|
298 | toolPanel.add(alignLeftButton, null); |
---|
299 | toolPanel.add(alignRightButton, null); |
---|
300 | toolPanel.add(component2, null); |
---|
301 | toolPanel.add(justVerticalButton, null); |
---|
302 | toolPanel.add(justHorizontalButton, null); |
---|
303 | layoutPanel.add(designScroller, BorderLayout.CENTER); |
---|
304 | designScroller.getViewport().add(grayPanel, null); |
---|
305 | grayPanel.add(designPanel_, BorderLayout.CENTER); |
---|
306 | leftPanel.add(propertyPanel, BorderLayout.CENTER); |
---|
307 | layoutPanel.add(leftPanel, BorderLayout.WEST); |
---|
308 | propertyPanel.add(jScrollPane1, BorderLayout.CENTER); |
---|
309 | leftPanel.add(jPanel1, BorderLayout.NORTH); |
---|
310 | jPanel1.add(expertCB, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0 |
---|
311 | ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); |
---|
312 | layoutPanel.add(toolPanel, BorderLayout.NORTH); |
---|
313 | |
---|
314 | if(!MRJUtil.isAquaLookAndFeel()) { |
---|
315 | alignBottomButton.setMargin(new Insets(0, 0, 0, 0)); |
---|
316 | alignLeftButton.setMargin(new Insets(0, 0, 0, 0)); |
---|
317 | alignTopButton.setMargin(new Insets(0, 0, 0, 0)); |
---|
318 | alignRightButton.setMargin(new Insets(0, 0, 0, 0)); |
---|
319 | newPanelButton.setMargin(new Insets(0, 0, 0, 0)); |
---|
320 | justVerticalButton.setMargin(new Insets(0, 0, 0, 0)); |
---|
321 | justHorizontalButton.setMargin(new Insets(0, 0, 0, 0)); |
---|
322 | removeButton.setMargin(new Insets(0, 0, 0, 0)); |
---|
323 | newDataGroupButton.setMargin(new Insets(0, 0, 0, 0)); |
---|
324 | newLabelButton.setMargin(new Insets(0, 0, 0, 0)); |
---|
325 | newLegendButton.setMargin(new Insets(0, 0, 0, 0)); |
---|
326 | openPanelButton.setMargin(new Insets(0, 0, 0, 0)); |
---|
327 | saveAsPanelButton.setMargin(new Insets(0,0,0,0)); |
---|
328 | } |
---|
329 | openPanelButton.setFocusable(false); |
---|
330 | saveAsPanelButton.setFocusable(false); |
---|
331 | } |
---|
332 | |
---|
333 | public Dimension getMinimumSize() { |
---|
334 | return new Dimension(600, 400); |
---|
335 | } |
---|
336 | |
---|
337 | public Dimension getMaximumSize() { |
---|
338 | return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); |
---|
339 | } |
---|
340 | |
---|
341 | public Dimension getPreferredSize() { |
---|
342 | return new Dimension(800, 600); |
---|
343 | } |
---|
344 | |
---|
345 | void newPanelButton_actionPerformed(ActionEvent e) { |
---|
346 | PanelHolder ph = new PanelHolder("Panel" + panelModel_.getPanelCount(), |
---|
347 | panelModel_, |
---|
348 | new Rectangle(20, 20, 200, 300), |
---|
349 | null, null, null); |
---|
350 | PanelHolderDragBox pi = new PanelHolderDragBox(ph); |
---|
351 | panelModel_.addPanel(ph); |
---|
352 | designPanel_.addPanel(pi); |
---|
353 | designPanel_.repaint(); |
---|
354 | } |
---|
355 | |
---|
356 | void newDataGroupButton_actionPerformed(ActionEvent e) { |
---|
357 | PanelHolder ph = designPanel_.getSelectedPanel(); |
---|
358 | if(ph == null) return; |
---|
359 | DataGroup ag = new DataGroup("DataGroup" + ph.getDataGroupSize(), ph); |
---|
360 | designPanel_.addDataGroup(ag); |
---|
361 | designPanel_.repaint(); |
---|
362 | } |
---|
363 | |
---|
364 | void newLabelButton_actionPerformed(ActionEvent e) { |
---|
365 | PanelHolder ph = designPanel_.getSelectedPanel(); |
---|
366 | if(ph == null) return; |
---|
367 | Label label = new Label("Label" + ph.getLabelSize(), |
---|
368 | new Point2D.Double(1.5, 1.5), |
---|
369 | 0.75, 0.25); |
---|
370 | designPanel_.addLabel(label); |
---|
371 | designPanel_.repaint(); |
---|
372 | } |
---|
373 | |
---|
374 | void newLegendButton_actionPerformed(ActionEvent e) { |
---|
375 | PanelHolder ph = designPanel_.getSelectedPanel(); |
---|
376 | if(ph == null) return; |
---|
377 | Legend legend = new Legend("Legend" + ph.getLegendSize(), |
---|
378 | new Rectangle2D.Double(1.0, 1.0, 1.5, 0.25)); |
---|
379 | designPanel_.addLegend(legend); |
---|
380 | designPanel_.repaint(); |
---|
381 | |
---|
382 | } |
---|
383 | |
---|
384 | public void propertyChange(PropertyChangeEvent evt) { |
---|
385 | String pName = evt.getPropertyName(); |
---|
386 | Object val = evt.getNewValue(); |
---|
387 | if(Page.DEBUG) System.out.println("PanelModelCustomizer.propertyChange: " + pName + ", " + evt.getNewValue()); |
---|
388 | setPanelButtons(designPanel_.getSelectedCount()); |
---|
389 | if(designPanel_.getSelectedCount() > 1) { |
---|
390 | setDefaultPanel(); |
---|
391 | return; |
---|
392 | } |
---|
393 | if(pName.equals("message")) { |
---|
394 | message.setText((String)evt.getNewValue()); |
---|
395 | } else if(pName.equals("allUnselected")) { |
---|
396 | setDefaultPanel(); |
---|
397 | } else if(pName.equals("panelSelected")) { |
---|
398 | if(val instanceof PanelHolderDragBox) { |
---|
399 | PanelHolderDragBox pdb = (PanelHolderDragBox)val; |
---|
400 | if(pdb.isSelected()) { |
---|
401 | setPanelPropertyPanel(pdb.getPanelHolder()); |
---|
402 | } else { |
---|
403 | setDefaultPanel(); |
---|
404 | } |
---|
405 | } |
---|
406 | } else if(pName.equals("dataGroupSelected")) { |
---|
407 | if(val instanceof DataGroupDragBox) { |
---|
408 | DataGroupDragBox ag = (DataGroupDragBox)val; |
---|
409 | if(ag.isSelected()) { |
---|
410 | setDataGroupPropertyPanel(ag.getDataGroup()); |
---|
411 | } else { |
---|
412 | setDefaultPanel(); |
---|
413 | } |
---|
414 | } |
---|
415 | } else if(pName.equals("axisSelected")) { |
---|
416 | if(val instanceof AxisHolderDragBox) { |
---|
417 | AxisHolderDragBox ah = (AxisHolderDragBox)val; |
---|
418 | if(ah.isSelected()) { |
---|
419 | setAxisHolderPropertyPanel(ah.getAxisHolder()); |
---|
420 | } else { |
---|
421 | setDefaultPanel(); |
---|
422 | } |
---|
423 | } |
---|
424 | } else if(pName.equals("labelSelected")) { |
---|
425 | if(val instanceof LabelDragBox) { |
---|
426 | LabelDragBox ldb = (LabelDragBox)val; |
---|
427 | if(ldb.isSelected()) { |
---|
428 | setLabelPropertyPanel(ldb.getLabel()); |
---|
429 | } else { |
---|
430 | setDefaultPanel(); |
---|
431 | } |
---|
432 | } |
---|
433 | } else if(pName.equals("legendSelected")) { |
---|
434 | if(val instanceof LegendDragBox) { |
---|
435 | LegendDragBox ldb = (LegendDragBox)val; |
---|
436 | if(ldb.isSelected()) { |
---|
437 | setLegendPropertyPanel(ldb.getLegend()); |
---|
438 | } else { |
---|
439 | setDefaultPanel(); |
---|
440 | } |
---|
441 | } |
---|
442 | } else if(pName.equals("ancestor")) { |
---|
443 | /* if(Page.DEBUG) { |
---|
444 | System.out.println("PanelModelCustomizer.propertyChange()"); |
---|
445 | System.out.println(" propertyName = " + evt.getPropertyName()); |
---|
446 | System.out.println(" source = " + evt.getSource()); |
---|
447 | System.out.println(" oldValue = " + evt.getOldValue()); |
---|
448 | System.out.println(" newValue = " + evt.getNewValue()); |
---|
449 | System.out.println(" propagationId = " + evt.getPropagationId()); |
---|
450 | } */ |
---|
451 | // panelModel_.getPage().setBackground(panelModel_.getPageBackgroundColor()); |
---|
452 | // panelModel_.getPage().setSize(panelModel_.getPageSize()); |
---|
453 | if(evt.getNewValue() == null) { |
---|
454 | // clean up ChangeListeners |
---|
455 | Iterator iter; |
---|
456 | if(panelModel_ == null) return; |
---|
457 | Iterator pIter = panelModel_.panelIterator(); |
---|
458 | while(pIter.hasNext()) { |
---|
459 | PanelHolder ph = (PanelHolder)pIter.next(); |
---|
460 | iter = ph.labelIterator(); |
---|
461 | while(iter.hasNext()) { |
---|
462 | Label label = (Label)iter.next(); |
---|
463 | label.removeDesignChangeListeners(); |
---|
464 | } |
---|
465 | iter = ph.legendIterator(); |
---|
466 | while(iter.hasNext()) { |
---|
467 | Legend legend = (Legend)iter.next(); |
---|
468 | legend.removeDesignChangeListeners(); |
---|
469 | } |
---|
470 | iter = ph.dataGroupIterator(); |
---|
471 | while(iter.hasNext()) { |
---|
472 | DataGroup dg = (DataGroup)iter.next(); |
---|
473 | dg.getXAxisHolder().removeDesignChangeListeners(); |
---|
474 | dg.getYAxisHolder().removeDesignChangeListeners(); |
---|
475 | dg.removeDesignChangeListeners(); |
---|
476 | } |
---|
477 | ph.removeDesignChangeListeners(); |
---|
478 | } |
---|
479 | panelModel_.removeDesignChangeListeners(); |
---|
480 | } /* else { |
---|
481 | System.out.println("change focus here?"); |
---|
482 | System.out.println("PanelModelCustomizer.isVisible() = " + isVisible()); |
---|
483 | if(newPanelButton.requestFocusInWindow()) { |
---|
484 | System.out.println("focus may be granted"); |
---|
485 | } else { |
---|
486 | System.out.println("focus wont be granted"); |
---|
487 | } |
---|
488 | KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner(); |
---|
489 | // KeyboardFocusManager.getCurrentKeyboardFocusManager().upFocusCycle(); |
---|
490 | // KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent(); |
---|
491 | |
---|
492 | } */ |
---|
493 | } |
---|
494 | } |
---|
495 | |
---|
496 | private void setDefaultPanel() { |
---|
497 | jScrollPane1.getViewport().removeAll(); |
---|
498 | jScrollPane1.getViewport().add(pmPropertyPanel_, null); |
---|
499 | currentPropertyPanel_ = pmPropertyPanel_; |
---|
500 | } |
---|
501 | |
---|
502 | private void setPanelPropertyPanel(PanelHolder ph) { |
---|
503 | if(ph == null) { |
---|
504 | setDefaultPanel(); |
---|
505 | return; |
---|
506 | } |
---|
507 | if(phPropertyPanel_ == null) { |
---|
508 | phPropertyPanel_ = new PanelHolderPropertyPanel(ph, expertCB.isSelected()); |
---|
509 | } else { |
---|
510 | phPropertyPanel_.setPanelHolder(ph, expertCB.isSelected()); |
---|
511 | } |
---|
512 | jScrollPane1.getViewport().removeAll(); |
---|
513 | jScrollPane1.getViewport().add(phPropertyPanel_); |
---|
514 | currentPropertyPanel_ = phPropertyPanel_; |
---|
515 | } |
---|
516 | |
---|
517 | private void setDataGroupPropertyPanel(DataGroup dg) { |
---|
518 | if(dg == null) { |
---|
519 | setDefaultPanel(); |
---|
520 | return; |
---|
521 | } |
---|
522 | if(agPropertyPanel_ == null) { |
---|
523 | agPropertyPanel_ = new DataGroupPropertyPanel(dg, expertCB.isSelected()); |
---|
524 | } else { |
---|
525 | agPropertyPanel_.setDataGroup(dg, expertCB.isSelected()); |
---|
526 | } |
---|
527 | jScrollPane1.getViewport().removeAll(); |
---|
528 | jScrollPane1.getViewport().add(agPropertyPanel_); |
---|
529 | currentPropertyPanel_ = agPropertyPanel_; |
---|
530 | } |
---|
531 | |
---|
532 | private void setAxisHolderPropertyPanel(AxisHolder ah) { |
---|
533 | if(ah == null) { |
---|
534 | setDefaultPanel(); |
---|
535 | return; |
---|
536 | } |
---|
537 | if(ahPropertyPanel_ == null) { |
---|
538 | ahPropertyPanel_ = new AxisHolderPropertyPanel(ah, expertCB.isSelected()); |
---|
539 | } else { |
---|
540 | ahPropertyPanel_.setAxisHolder(ah, expertCB.isSelected()); |
---|
541 | } |
---|
542 | jScrollPane1.getViewport().removeAll(); |
---|
543 | jScrollPane1.getViewport().add(ahPropertyPanel_); |
---|
544 | currentPropertyPanel_ = ahPropertyPanel_; |
---|
545 | } |
---|
546 | |
---|
547 | private void setLabelPropertyPanel(Label lab) { |
---|
548 | if(lab == null) { |
---|
549 | setDefaultPanel(); |
---|
550 | return; |
---|
551 | } |
---|
552 | if(labelPropertyPanel_ == null) { |
---|
553 | labelPropertyPanel_ = new LabelPropertyPanel(lab, expertCB.isSelected()); |
---|
554 | } else { |
---|
555 | labelPropertyPanel_.setLabel(lab, expertCB.isSelected()); |
---|
556 | } |
---|
557 | jScrollPane1.getViewport().removeAll(); |
---|
558 | jScrollPane1.getViewport().add(labelPropertyPanel_); |
---|
559 | currentPropertyPanel_ = labelPropertyPanel_; |
---|
560 | } |
---|
561 | |
---|
562 | private void setLegendPropertyPanel(Legend legend) { |
---|
563 | if(legend == null) { |
---|
564 | setDefaultPanel(); |
---|
565 | return; |
---|
566 | } |
---|
567 | if(legendPropertyPanel_ == null) { |
---|
568 | legendPropertyPanel_ = new LegendPropertyPanel(legend, expertCB.isSelected()); |
---|
569 | } else { |
---|
570 | legendPropertyPanel_.setLegend(legend, expertCB.isSelected()); |
---|
571 | } |
---|
572 | jScrollPane1.getViewport().removeAll(); |
---|
573 | jScrollPane1.getViewport().add(legendPropertyPanel_); |
---|
574 | currentPropertyPanel_ = legendPropertyPanel_; |
---|
575 | } |
---|
576 | |
---|
577 | private void setPanelButtons(int enabledCount) { |
---|
578 | boolean enabled = enabledCount >= 2; |
---|
579 | |
---|
580 | alignBottomButton.setEnabled(enabled); |
---|
581 | alignTopButton.setEnabled(enabled); |
---|
582 | alignLeftButton.setEnabled(enabled); |
---|
583 | alignRightButton.setEnabled(enabled); |
---|
584 | |
---|
585 | enabled = enabledCount >= 1; |
---|
586 | justVerticalButton.setEnabled(enabled); |
---|
587 | justHorizontalButton.setEnabled(enabled); |
---|
588 | |
---|
589 | enabled = enabledCount == 1; |
---|
590 | removeButton.setEnabled(enabled); |
---|
591 | newDataGroupButton.setEnabled(enabled); |
---|
592 | newLabelButton.setEnabled(enabled); |
---|
593 | newLegendButton.setEnabled(enabled); |
---|
594 | |
---|
595 | enabled = designPanel_.isChildDragBoxSelected(); |
---|
596 | if(enabled) { |
---|
597 | removeButton.setEnabled(!designPanel_.isAxisHolderDragBoxSelected()); |
---|
598 | } |
---|
599 | } |
---|
600 | |
---|
601 | void alignBottomButton_actionPerformed(ActionEvent e) { |
---|
602 | designPanel_.alignBoxes(DesignPanel.ALIGN_BOTTOM); |
---|
603 | } |
---|
604 | |
---|
605 | void alignTopButton_actionPerformed(ActionEvent e) { |
---|
606 | designPanel_.alignBoxes(DesignPanel.ALIGN_TOP); |
---|
607 | } |
---|
608 | |
---|
609 | void alignLeftButton_actionPerformed(ActionEvent e) { |
---|
610 | designPanel_.alignBoxes(DesignPanel.ALIGN_LEFT); |
---|
611 | } |
---|
612 | |
---|
613 | void alignRightButton_actionPerformed(ActionEvent e) { |
---|
614 | designPanel_.alignBoxes(DesignPanel.ALIGN_RIGHT); |
---|
615 | } |
---|
616 | |
---|
617 | void justVerticalButton_actionPerformed(ActionEvent e) { |
---|
618 | designPanel_.alignBoxes(DesignPanel.JUSTIFY_VERTICAL); |
---|
619 | } |
---|
620 | |
---|
621 | void justHorizontalButton_actionPerformed(ActionEvent e) { |
---|
622 | designPanel_.alignBoxes(DesignPanel.JUSTIFY_HORIZONTAL); |
---|
623 | } |
---|
624 | |
---|
625 | void removeButton_actionPerformed(ActionEvent e) { |
---|
626 | designPanel_.removeSelected(); |
---|
627 | setDefaultPanel(); |
---|
628 | setPanelButtons(0); |
---|
629 | } |
---|
630 | |
---|
631 | void expertCB_actionPerformed(ActionEvent e) { |
---|
632 | currentPropertyPanel_.setExpert(expertCB.isSelected()); |
---|
633 | } |
---|
634 | |
---|
635 | void openPanelButton_actionPerformed(ActionEvent e) { |
---|
636 | // problem with open since PanelModelCustomizer work on the original |
---|
637 | // object. Right now there isn't a method for replacing the PanelModel |
---|
638 | // inside the customizer. However, I can save it! |
---|
639 | } |
---|
640 | |
---|
641 | void saveAsPanelButton_actionPerformed(ActionEvent e) { |
---|
642 | File file; |
---|
643 | FileFilter filt; |
---|
644 | String ext; |
---|
645 | String outpath; |
---|
646 | String[] xmlFile = new String[]{".xml"}; |
---|
647 | SimpleFileFilter xmlFilt = new SimpleFileFilter(xmlFile, "XML Serialized Bean"); |
---|
648 | |
---|
649 | if(fileChooser_ == null) { |
---|
650 | fileChooser_ = new JFileChooser(); |
---|
651 | } |
---|
652 | fileChooser_.setFileFilter(fileChooser_.getAcceptAllFileFilter()); |
---|
653 | fileChooser_.resetChoosableFileFilters(); |
---|
654 | fileChooser_.addChoosableFileFilter(xmlFilt); |
---|
655 | fileChooser_.setFileFilter(xmlFilt); |
---|
656 | |
---|
657 | int result = fileChooser_.showSaveDialog(this); |
---|
658 | if(result == JFileChooser.APPROVE_OPTION) { |
---|
659 | file = fileChooser_.getSelectedFile(); |
---|
660 | filt = fileChooser_.getFileFilter(); |
---|
661 | outpath = file.getPath(); |
---|
662 | if(filt instanceof SimpleFileFilter) { |
---|
663 | ext = ((SimpleFileFilter)filt).getExtension(); |
---|
664 | String name = file.getName().toLowerCase(); |
---|
665 | if(!name.endsWith(ext)) { |
---|
666 | outpath += ext; |
---|
667 | } |
---|
668 | } |
---|
669 | try { |
---|
670 | panelModel_.saveToXML(new BufferedOutputStream( |
---|
671 | new FileOutputStream(outpath, false))); |
---|
672 | } catch (FileNotFoundException fnfe) { |
---|
673 | JOptionPane.showMessageDialog(this, "Error creating file, rename and try again", |
---|
674 | "File Save Error", JOptionPane.ERROR_MESSAGE); |
---|
675 | return; |
---|
676 | } |
---|
677 | } |
---|
678 | } |
---|
679 | } |
---|