1 /***
2 * Created on Feb 8, 2006, Copyright UC Regents
3 */
4 package org.telscenter.pas.steps.quickEditors.hints;
5
6 import java.awt.BorderLayout;
7 import java.awt.Container;
8 import java.awt.FlowLayout;
9 import java.awt.event.ActionEvent;
10 import java.awt.event.ActionListener;
11 import java.util.Iterator;
12
13 import javax.swing.BorderFactory;
14 import javax.swing.JButton;
15 import javax.swing.JFrame;
16 import javax.swing.JPanel;
17 import javax.swing.JScrollPane;
18 import javax.swing.undo.UndoManager;
19
20 import org.telscenter.pas.beans.PasStep;
21 import org.telscenter.pas.common.ui.CommonUI;
22 import org.telscenter.pas.hint.Hint;
23 import org.telscenter.pas.properties.HintSet;
24 import org.telscenter.pas.steps.quickEditors.IQuickEditorControllable;
25 import org.telscenter.pas.steps.quickEditors.qti.assessment.AssessmentQuickEditorUI;
26 import org.telscenter.pas.ui.util.PasColors;
27
28
29 /***
30 * @author aperritano
31 *
32 */
33 public class HintQuickEditorUI extends JPanel implements IQuickEditorControllable {
34
35
36 private HintInteractionCardContainerUI interactionCardContainerUI;
37
38 private JScrollPane listScroller;
39 private HintInteractionCardContainerUI hintContainer;
40 private JPanel buttonPanel;
41 private PasStep pasStep;
42
43 private UndoManager undoManager;
44
45
46 /***
47 * @param undoManager
48 * @param s
49 */
50 public HintQuickEditorUI(PasStep pasStep, UndoManager undoManager) {
51 this.undoManager = undoManager;
52 this.pasStep = pasStep;
53 removeAll();
54 createUI();
55
56 }
57
58 protected JPanel createButtonPanel() {
59 buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
60
61
62
63 JButton addTextItem = new JButton("Add New Hint");
64
65 addTextItem.addActionListener(new ActionListener() {
66
67 public void actionPerformed(ActionEvent e) {
68
69 Hint newHint = new Hint();
70
71 HintInteractionCardUI innyCard = new HintInteractionCardUI(newHint,undoManager);
72 pasStep.getHintSet().add(newHint);
73 hintContainer.addInteractionCard(innyCard, true);
74 listScroller.getVerticalScrollBar().setValue(listScroller.getVerticalScrollBar().getMaximum());
75 HintQuickEditorUI.this.revalidate();
76 }} );
77
78
79
80 buttonPanel.add(addTextItem);
81 buttonPanel.setOpaque(false);
82 return buttonPanel;
83 }
84
85 protected void createUI() {
86 setLayout(new BorderLayout(0,0));
87 setBackground(PasColors.hintQuickEditorBackgroundColor);
88
89 HintSet hintSet = pasStep.getHintSet();
90 hintContainer = new HintInteractionCardContainerUI(hintSet);
91 hintContainer.setBackground(PasColors.hintQuickEditorBackgroundColor);
92 for (Hint hint : hintSet) {
93 hintContainer.addInteractionCard(new HintInteractionCardUI(hint,undoManager));
94 }
95
96 listScroller = new JScrollPane();
97 listScroller.getViewport().add(hintContainer);
98 listScroller.setBackground(PasColors.hintQuickEditorListScrollerBackgroundColor);
99 listScroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
100 listScroller
101 .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
102 listScroller.setBorder(BorderFactory.createEmptyBorder(0, 1, 0, 0));
103
104 JPanel scrollerPanel = new JPanel(new BorderLayout(0,0));
105 scrollerPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 0, 4));
106 scrollerPanel.add(listScroller,BorderLayout.CENTER);
107 scrollerPanel.setOpaque(false);
108
109 add(scrollerPanel,BorderLayout.CENTER);
110 createButtonPanel();
111
112 }
113
114 /***
115 * @return Returns the hintSet.
116 */
117 public HintSet getHintSet() {
118 return pasStep.getHintSet();
119 }
120
121
122
123
124
125
126 public JPanel getControllPanel() {
127
128 return buttonPanel;
129 }
130
131
132
133
134 public UndoManager getUndoManager() {
135 return undoManager;
136 }
137
138
139
140
141 public void setUndoManager(UndoManager undoManager) {
142 this.undoManager = undoManager;
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 }