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.Component;
7   import java.awt.Container;
8   import java.awt.event.ActionEvent;
9   import java.awt.event.ActionListener;
10  import java.util.List;
11  
12  import javax.swing.JButton;
13  import javax.swing.JFrame;
14  
15  import org.telscenter.pas.hint.Hint;
16  import org.telscenter.pas.properties.HintSet;
17  import org.telscenter.pas.steps.quickEditors.qti.assessment.AbstractCardContainerUI;
18  import org.telscenter.pas.steps.quickEditors.qti.assessment.AbstractCardUI;
19  import org.telscenter.pas.ui.util.PasColors;
20  
21  
22  /***
23   * @author aperritano
24   *
25   */
26  public class HintInteractionCardContainerUI extends AbstractCardContainerUI<Hint>  {
27  
28  	
29  	public HintInteractionCardContainerUI(List hintSet) {
30  		this.listOfObjects = hintSet;
31  		super.init();
32  		
33  		setDefaultMessage("This Hint Collection has zero hints");
34  	}
35  	
36  	/* (non-Javadoc)
37  	 * @see org.telscenter.pas.steps.quickEditors.qti.assessment.AbstractCardContainerUI#init()
38  	 */
39  	protected void init() {
40  		// TODO Auto-generated method stub
41  		super.init();
42  		this.setBackground(PasColors.hintCardContainerBackgroundColor);
43  	}
44  	
45  	public void trashCard(AbstractCardUI<Hint> cardUI) {
46  		
47  		HintInteractionCardUI hc = (HintInteractionCardUI)cardUI;
48  		
49  		if( hc.getHint() == null )
50  			return;
51  		
52  		this.listOfObjects.remove(hc.getHint());
53  		this.remove(cardUI);
54  		
55  		
56  		interactionCardIndex--;
57  		
58  		if( this.getComponents().length == 0 ) {
59  			this.add(noCardsLabel);
60  			this.repaint();
61  			this.revalidate();
62  			return;
63  		}
64  		//re index all of them
65  		Component[] components = this.getComponents();
66  		for (int i = 0; i < components.length; i++) {
67  			AbstractCardUI<Hint> nc = (AbstractCardUI<Hint>) components[i];
68  			nc.setIndex(i);
69  			
70  		}
71  		modButtons();
72  		this.revalidate();
73  	}
74  	
75  	
76  	protected void trashCard(int currentCardIndex) {
77  		HintInteractionCardUI hc = (HintInteractionCardUI) this.getComponent(currentCardIndex);
78  		if( hc.getHint() == null )
79  			return;
80  		
81  		this.listOfObjects.remove(hc.getHint());
82  		this.remove(hc);
83  		
84  		interactionCardIndex--;
85  		
86  		if( this.getComponents().length == 0 ) {
87  			this.add(noCardsLabel);
88  			this.repaint();
89  			this.revalidate();
90  			return;
91  		}
92  		//re index all of them
93  		Component[] components = this.getComponents();
94  		for (int i = 0; i < components.length; i++) {
95  			AbstractCardUI<Hint> nc = (AbstractCardUI<Hint>) components[i];
96  			nc.setIndex(i);
97  			
98  		}
99  		modButtons();
100 		this.revalidate();
101 	}
102 	public static void main(String[] args) {
103 		JFrame frame = new JFrame("hint card test");
104 
105 		Container contentPane = frame.getContentPane();
106 
107 		JButton showButton = new JButton("show ui");
108 
109 		showButton.addActionListener(new ActionListener() {
110 
111 			public void actionPerformed(ActionEvent e) {
112 
113 				JFrame frame = new JFrame("hint card test");
114 
115 				Container contentPane = frame.getContentPane();
116 				
117 				HintSet hintSet = new HintSet();
118 				
119 				Hint hint;
120 
121 				(hint = new Hint())
122 						.setText("Think about what Hydrogen gas would look like magnified many times. Is it a single atom? Is it diatomic? Are gases clumpy");
123 				hintSet.add(hint);
124 				(hint = new Hint()).setText(" something");
125 				hintSet.add(hint);
126 				(hint = new Hint()).setText("hint  something");
127 				hintSet.add(hint);
128 				(hint = new Hint()).setText("something something");
129 				hintSet.add(hint);
130 				//for (Suit suit : suits)
131 				HintInteractionCardContainerUI h = new HintInteractionCardContainerUI(hintSet);
132 				for (Hint aHint : hintSet) {
133 					AbstractCardUI<Hint> abs = new HintInteractionCardUI(aHint, null);
134 					h.addInteractionCard(abs);
135 				}
136 				
137 				contentPane.add(h);
138 				frame.setSize(h.getPreferredSize());
139 				frame.setVisible(true);
140 			}
141 
142 		});
143 		contentPane.add(showButton);
144 
145 		frame.setSize(200, 200);
146 		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
147 		frame.setVisible(true);
148 	}
149 
150 
151 	
152 }