1 package org.telscenter.pas.ui.frames;
2
3 import java.awt.BorderLayout;
4 import java.awt.Color;
5 import java.awt.Component;
6 import java.awt.Dimension;
7 import java.awt.GraphicsDevice;
8 import java.awt.GraphicsEnvironment;
9 import java.awt.GridLayout;
10 import java.beans.PropertyChangeEvent;
11 import java.beans.PropertyChangeListener;
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.Iterator;
15
16 import javax.swing.BorderFactory;
17 import javax.swing.ImageIcon;
18 import javax.swing.JComponent;
19 import javax.swing.JFrame;
20 import javax.swing.JLabel;
21 import javax.swing.JPanel;
22 import javax.swing.JSplitPane;
23 import javax.swing.SwingConstants;
24 import javax.swing.ToolTipManager;
25
26 import net.sf.sail.core.beans.service.SessionService;
27 import net.sf.sail.core.entity.User;
28
29 import org.apache.commons.lang.StringUtils;
30 import org.telscenter.pas.beans.PasStep;
31 import org.telscenter.pas.common.ui.border.CustomLineBorder;
32 import org.telscenter.pas.navigation.PasProjectNavigationPanel;
33 import org.telscenter.pas.navigation.PasProjectNavigationTaskPanel;
34 import org.telscenter.pas.service.PasProjectServiceProvider;
35 import org.telscenter.pas.ui.icons.PasCommonIconProvider;
36 import org.telscenter.pas.ui.sidebar.SidebarMeditor;
37 import org.telscenter.pas.ui.util.PasColors;
38 import org.telscenter.pas.ui.util.UserDisplayNameIterator;
39
40 public class PasFrame extends JFrame implements PropertyChangeListener {
41
42 private static final long serialVersionUID = 1L;
43
44 private transient JPanel wholeLayoutPanel;
45
46 private PasProjectNavigationTaskPanel pasProjectNavigationPanel;
47
48 private PasProjectServiceProvider pasServiceProvider;
49
50 private transient Component stepComponent;
51
52 private boolean isFullScreen;
53
54 private SessionService sessionService;
55
56 private JPanel rightViewPanel;
57
58 private JSplitPane splitPane;
59
60 private SidebarMeditor sidebarMediator;
61
62 private JPanel compactNavigationViewPanel;
63
64 private Dimension compactViewPreferredSize;
65
66 public PasFrame() {
67
68
69 try {
70
71
72
73
74
75
76
77
78
79
80
81 } catch (Exception e) {
82 }
83
84
85
86
87 ToolTipManager.sharedInstance().setInitialDelay(500);
88 ToolTipManager.sharedInstance().setReshowDelay(500);
89 ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
90
91
92 sidebarMediator = new SidebarMeditor(this);
93 setSize(800, 600);
94 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
95 }
96
97 public void propertyChange(PropertyChangeEvent evt) {
98 if (evt.getPropertyName() == "title") {
99 String longTitle = (String) evt.getNewValue();
100 setTitle(longTitle);
101 }
102 }
103
104 public void setFullScreen(boolean doFullScreen) {
105 if (isFullScreen == doFullScreen)
106 return;
107
108 GraphicsEnvironment env = GraphicsEnvironment
109 .getLocalGraphicsEnvironment();
110 GraphicsDevice[] devices = env.getScreenDevices();
111 GraphicsDevice device = devices[0];
112
113 if (doFullScreen && !device.isFullScreenSupported())
114 throw new RuntimeException("full screen mode not supported");
115
116 isFullScreen = doFullScreen;
117
118 setUndecorated(isFullScreen);
119 setResizable(!isFullScreen);
120 if (isFullScreen) {
121
122 device.setFullScreenWindow(this);
123 validate();
124 } else {
125
126 pack();
127 setVisible(true);
128 }
129 }
130
131 public void showFrame() {
132
133 JPanel dummyPanel = new JPanel();
134 dummyPanel.setLayout(new GridLayout(1, 1));
135 Component waterMarkPanel = makeWelcomeWaterMark();
136 dummyPanel.add(waterMarkPanel);
137 dummyPanel.validate();
138
139 stepComponent = dummyPanel;
140
141 rightViewPanel = new JPanel(new BorderLayout(0, 0));
142 rightViewPanel.setBorder(new CustomLineBorder(Color.white,0,Color.white,0,Color.white,0,PasColors.innerStripBackgroundColor,1));
143 rightViewPanel.setBorder(BorderFactory.createEmptyBorder());
144 splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
145 pasProjectNavigationPanel, rightViewPanel);
146 splitPane.setOneTouchExpandable(true);
147 splitPane.setBorder(BorderFactory.createEmptyBorder());
148
149 splitPane.setDividerSize(0);
150
151
152
153 wholeLayoutPanel = new JPanel();
154 wholeLayoutPanel.setLayout(new BorderLayout(0, 0));
155
156 wholeLayoutPanel.add(splitPane, BorderLayout.CENTER);
157
158
159 compactNavigationViewPanel = pasProjectNavigationPanel.getCompactNavigationViewPanel();
160
161 wholeLayoutPanel.add(compactNavigationViewPanel, BorderLayout.WEST);
162
163
164
165
166 compactViewPreferredSize = pasProjectNavigationPanel.getCompactNavigationViewPanel().getPreferredSize();
167 compactNavigationViewPanel.setPreferredSize(new Dimension(0, compactNavigationViewPanel.getPreferredSize().height));
168 compactNavigationViewPanel.revalidate();
169
170
171 updateMainPanel(dummyPanel);
172
173
174 getContentPane().removeAll();
175 getContentPane().add(wholeLayoutPanel);
176
177
178 setVisible(true);
179 }
180
181 protected Component makeWelcomeWaterMark() {
182 JPanel imagePanel = new JPanel(new BorderLayout(4, 4));
183 imagePanel
184 .setBackground(PasColors.navigationPanelBackgroundColor);
185 JLabel waterMark = new JLabel();
186 waterMark.setOpaque(false);
187 waterMark.setHorizontalAlignment(SwingConstants.CENTER);
188 waterMark.setIcon(new ImageIcon(PasCommonIconProvider
189 .getImage("blankPas.png")));
190 imagePanel.add(waterMark, BorderLayout.CENTER);
191
192
193 return imagePanel;
194
195 }
196
197 public String getWelcomeMessageForUsers() {
198 Collection<User> users = this.getUsers();
199
200 if (users == null)
201 return Messages.getString("PasFrame.welcome_noone");
202
203 UserDisplayNameIterator iter = new UserDisplayNameIterator(users);
204 String usernames = StringUtils.join(iter, Messages
205 .getString("PasFrame.user_displayname_separator"));
206
207 return Messages.getString("PasFrame.welcome_someone") + usernames;
208 }
209
210 public String getUserNames(){
211 Collection<User> users = this.getUsers();
212 UserDisplayNameIterator iter = new UserDisplayNameIterator(users);
213 String usernames = StringUtils.join(iter, Messages
214 .getString("PasFrame.user_displayname_separator"));
215 return usernames;
216 }
217
218 public Collection<User> getUsers() {
219 if (sessionService == null)
220 return null;
221 return sessionService.getUsers();
222 }
223
224 /***
225 * @return
226 */
227 public String getUserDisplayNames() {
228 if (sessionService == null) {
229
230 return Messages.getString("PasFrame.guest_displayname");
231 }
232 Collection<User> users = sessionService.getUsers();
233
234 UserDisplayNameIterator iter = new UserDisplayNameIterator(users);
235
236 StringBuilder sb = new StringBuilder();
237
238 if( users.size() > 1 ) {
239 sb.append("\n");
240 }
241
242 while (iter.hasNext()) {
243 String displayName = (String) iter.next();
244 sb.append(displayName);
245 if( iter.hasNext() == true ) {
246 sb.append(",\n");
247 }
248
249 }
250
251
252 return sb.toString();
253 }
254
255 public void updateMainPanel(Component comp) {
256
257 rightViewPanel.remove(stepComponent);
258 stepComponent = comp;
259 ((JComponent) stepComponent).setBorder(new CustomLineBorder(Color.WHITE,0,Color.white,0,Color.white,0,PasColors.innerStripBackgroundColor,1));
260 rightViewPanel.add(stepComponent, BorderLayout.CENTER);
261 rightViewPanel.updateUI();
262 }
263
264 public void setPasServiceProvider(
265 PasProjectServiceProvider pasServiceProvider) {
266 Object old = this.pasServiceProvider;
267 this.pasServiceProvider = pasServiceProvider;
268 firePropertyChange("pasServiceProvider", old, pasServiceProvider);
269 }
270
271 public void setSessionService(SessionService sessionService) {
272 this.sessionService = sessionService;
273 }
274
275 public void setPasProjectNavigationPanel(
276 PasProjectNavigationPanel pasProjectNavigationPanel) {
277 Object old = this.pasProjectNavigationPanel;
278 this.pasProjectNavigationPanel = (PasProjectNavigationTaskPanel) pasProjectNavigationPanel;
279 firePropertyChange("pasProjectNavigationPanel", old,
280 pasProjectNavigationPanel);
281 }
282
283 public PasProjectNavigationPanel getNavigationPanel() {
284 return this.pasProjectNavigationPanel;
285 }
286
287 /***
288 * @return the splitPane
289 */
290 public JSplitPane getSplitPane() {
291 return splitPane;
292 }
293
294 /***
295 * @param splitPane the splitPane to set
296 */
297 public void setSplitPane(JSplitPane splitPane) {
298 this.splitPane = splitPane;
299 }
300
301 /***
302 * @return the rightViewPanel
303 */
304 public JPanel getRightViewPanel() {
305 return rightViewPanel;
306 }
307
308 /***
309 * @param rightViewPanel the rightViewPanel to set
310 */
311 public void setRightViewPanel(JPanel rightViewPanel) {
312 this.rightViewPanel = rightViewPanel;
313 }
314
315 /***
316 * @return the wholeLayoutPanel
317 */
318 public JPanel getWholeLayoutPanel() {
319 return wholeLayoutPanel;
320 }
321
322 /***
323 * @param wholeLayoutPanel the wholeLayoutPanel to set
324 */
325 public void setWholeLayoutPanel(JPanel wholeLayoutPanel) {
326 this.wholeLayoutPanel = wholeLayoutPanel;
327 }
328
329 /***
330 * @return the compactNavigationViewPanel
331 */
332 public JPanel getCompactNavigationViewPanel() {
333 return compactNavigationViewPanel;
334 }
335
336 /***
337 * @param compactNavigationViewPanel the compactNavigationViewPanel to set
338 */
339 public void setCompactNavigationViewPanel(JPanel compactViewPanel) {
340 this.compactNavigationViewPanel = compactViewPanel;
341 }
342
343 /***
344 * @return the compactViewPreferredSize
345 */
346 public Dimension getCompactViewPreferredSize() {
347 return compactViewPreferredSize;
348 }
349
350 /***
351 * @param compactViewPreferredSize the compactViewPreferredSize to set
352 */
353 public void setCompactViewPreferredSize(Dimension compactViewPreferredSize) {
354 this.compactViewPreferredSize = compactViewPreferredSize;
355 }
356
357 /***
358 * @return the sidebarMediator
359 */
360 public SidebarMeditor getSidebarMediator() {
361 return sidebarMediator;
362 }
363
364 /***
365 * @param sidebarMediator the sidebarMediator to set
366 */
367 public void setSidebarMediator(SidebarMeditor sidebarMediator) {
368 this.sidebarMediator = sidebarMediator;
369 }
370
371 /***
372 *
373 */
374 public void showFirstStep() {
375 pasProjectNavigationPanel.showFirstStep();
376
377 }
378
379
380 }