View Javadoc

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  				//hint
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  		//CommonUI.makeEnhancedButton(addTextItem);
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 		//add(createButtonPanel(),BorderLayout.SOUTH);
112 	}
113 
114 	/***
115 	 * @return Returns the hintSet.
116 	 */
117 	public HintSet getHintSet() {
118 		return pasStep.getHintSet();
119 	}
120 
121 	
122 
123 	/* (non-Javadoc)
124 	 * @see org.telscenter.pas.steps.quickEditors.IQuickEditorControllable#getControllPanel()
125 	 */
126 	public JPanel getControllPanel() {
127 		// TODO Auto-generated method stub
128 		return  buttonPanel;
129 	}
130 	
131 	/* (non-Javadoc)
132 	 * @see org.telscenter.pas.steps.quickEditors.IQuickEditorControllable#getUndoManager()
133 	 */
134 	public UndoManager getUndoManager() {
135 		return undoManager;
136 	}
137 
138 	/* (non-Javadoc)
139 	 * @see org.telscenter.pas.steps.quickEditors.IQuickEditorControllable#setUndoManager(javax.swing.undo.UndoManager)
140 	 */
141 	public void setUndoManager(UndoManager undoManager) {
142 		this.undoManager = undoManager;
143 	}
144 	
145 //	public static void main(String[] args) {
146 //		JFrame frame = new JFrame("hint quick editor test");
147 //
148 //		Container contentPane = frame.getContentPane();
149 //
150 //		JButton showButton = new JButton("show ui");
151 //
152 //		showButton.addActionListener(new ActionListener() {
153 //
154 //			public void actionPerformed(ActionEvent e) {
155 //
156 //				JFrame frame = new JFrame("hint quick editor test");
157 //
158 //				Container contentPane = frame.getContentPane();
159 //				HintQuickEditorUI hintUI = new HintQuickEditorUI();
160 //				HintSet hintSet = new HintSet();
161 //				Hint hint;
162 //
163 //				(hint = new Hint())
164 //						.setText("Think about what Hydrogen gas would look like magnified many times. Is it a single atom? Is it diatomic? Are gases clumpy");
165 //				hintSet.add(hint);
166 //				(hint = new Hint()).setText(" something");
167 //				hintSet.add(hint);
168 //				(hint = new Hint()).setText("hint  something");
169 //				hintSet.add(hint);
170 //				(hint = new Hint()).setText("something something");
171 //				hintSet.add(hint);
172 //				hintUI.setHintSet(hintSet);
173 //				contentPane.add(hintUI);
174 //				frame.setSize(hintUI.getPreferredSize());
175 //				frame.setVisible(true);
176 //			}
177 //
178 //		});
179 //		contentPane.add(showButton);
180 //
181 //		frame.setSize(200, 200);
182 //		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
183 //		frame.setVisible(true);
184 //	}
185 }