1 /***
2 * Created on Jan 26, 2006, Copyright UC Regents
3 */
4 package org.telscenter.pas.properties;
5
6 import java.awt.BorderLayout;
7 import java.awt.Component;
8 import java.awt.event.ActionEvent;
9 import java.awt.event.ActionListener;
10 import java.awt.event.WindowAdapter;
11 import java.awt.event.WindowEvent;
12 import java.beans.PropertyEditorSupport;
13
14 import javax.swing.JButton;
15 import javax.swing.JDialog;
16 import javax.swing.JLabel;
17 import javax.swing.JPanel;
18
19 import org.telscenter.pas.common.ui.CreateNewDialog;
20 import org.telscenter.pas.hint.Hint;
21 import org.telscenter.pas.steps.quickEditors.hints.HintQuickEditorUI;
22 import org.telscenter.pas.util.PipedDeepCopy;
23
24 /***
25 * @author turadg
26 */
27 public class HintSetPropertyEditor extends PropertyEditorSupport {
28
29 private HintQuickEditorUI editor;
30
31 public boolean supportsCustomEditor() {
32 return true;
33 }
34
35 @SuppressWarnings("unchecked")
36 public void setValue(Object value) {
37 super.setValue(value);
38 final HintSet hintSet = (HintSet) value;
39 HintSet newHintSet;
40 try {
41 newHintSet = (HintSet) PipedDeepCopy.copy(hintSet);
42
43 } catch (Exception e) {
44
45 e.printStackTrace();
46 }
47 }
48
49 @SuppressWarnings("unchecked")
50 public String getAsText() {
51 HintSet hs = (HintSet) getValue();
52 return hs.toString();
53 }
54
55 public Component getCustomEditor() {
56
57
58
59
60
61 JPanel longPanel = new JPanel(new BorderLayout(0, 0));
62 longPanel.setOpaque(false);
63 JLabel hintLabel = new JLabel(editor.getHintSet().toString());
64 hintLabel.setOpaque(false);
65
66 JButton hintButton = new JButton("...");
67 hintButton.addActionListener(new ActionListener() {
68
69 public void actionPerformed(ActionEvent e) {
70 JDialog hintDialog = CreateNewDialog.createDialog(editor,
71 "Hint Editor", "Add and remove hint cards",
72 "Hints can be rearraged using the arrows", null, 350,
73 450);
74 hintDialog.setVisible(true);
75
76 hintDialog.addWindowListener(new WindowAdapter() {
77
78 public void windowClosing(WindowEvent e) {
79 HintSetPropertyEditor.this
80 .setValue(editor.getHintSet());
81 System.out.println(".windowClosing()");
82 }
83
84 public void windowClosed(WindowEvent e) {
85
86 }
87 });
88
89 }
90 });
91
92 longPanel.add(hintLabel, BorderLayout.CENTER);
93 longPanel.add(hintButton, BorderLayout.EAST);
94 return longPanel;
95 }
96
97 }