View Javadoc

1   /*
2    * Created on May 23, 2005, Copyright UC Regents
3    */
4   package org.telscenter.pas.service;
5   
6   import java.awt.Dimension;
7   import java.awt.Frame;
8   import java.awt.event.WindowAdapter;
9   import java.awt.event.WindowEvent;
10  import java.beans.BeanInfo;
11  
12  import javax.swing.ImageIcon;
13  import javax.swing.JComponent;
14  import javax.swing.JDialog;
15  import javax.swing.JPanel;
16  
17  import org.telscenter.pas.steps.INoteStep;
18  import org.telscenter.pas.steps.icons.PasStepIconProvider;
19  import org.telscenter.pas.ui.util.PasColors;
20  import org.xito.dialog.CustomDialog;
21  import org.xito.dialog.DialogDescriptor;
22  import org.xito.dialog.DialogManager;
23  
24  /***
25   * @author turadg
26   * @author aperritano
27   */
28  public class NoteService implements INoteService {
29  
30  	private Frame rootFrame;
31  
32  	public NoteService(Frame rootFrame) {
33  		this.rootFrame = rootFrame;
34  	}
35  
36  	public void popupNote(final INoteStep note, final int width,
37  			final int height) {
38  		final DialogDescriptor descriptor = new DialogDescriptor();
39  
40  		final JComponent component = (JComponent) note.getComponent();
41  		descriptor.setIcon(new ImageIcon(PasStepIconProvider.getIcon("note",
42  				BeanInfo.ICON_COLOR_32x32)));
43  		descriptor.setWindowTitle(note.getTitle());
44  		descriptor.setTitle("Note");
45  		descriptor.setSubtitle("Fill out each note part and save your answer.");
46  		descriptor.setCustomPanel((JPanel) component);
47  		descriptor.setGradiantColor(PasColors.noteGradiantColor);
48  
49  		descriptor.setWidth(width);
50  		descriptor.setHeight(height);
51  		descriptor.setShowButtonSeparator(false);
52  		descriptor.setGradiantOffsetRatio(.30f);
53  		descriptor.setResizable(true);
54  		descriptor.setType(DialogManager.NONE);
55  		// descriptor.setButtonTypes(new ButtonType[] {new ButtonType("OK", 1),
56  		// new ButtonType("Close", 0) });
57  
58  		final CustomDialog cd = new CustomDialog(rootFrame, descriptor, false);
59  		cd.setFocusable(true);
60  		cd.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
61  		cd.addWindowListener(new WindowAdapter() {
62  			public void windowActivated(final WindowEvent e) {
63  				
64  				note.getNoteUI().setNoteOpen(true);
65  				// // cd.toFront();
66  				// // component.requestFocusInWindow();
67  				// JTabbedPane noteTabpane = note.getNoteTabpane();
68  				//				
69  				// Component[] components = noteTabpane.getComponents();
70  				//				
71  				// for (int i = 0; i < components.length; i++) {
72  				// JComponent component2 = (JComponent) components[i];
73  				//					
74  				// System.out.println(i + " PRES "+
75  				// component2.getPreferredSize());
76  				// System.out.println( i + " SIZE "+ component2.getSize());
77  				// System.out.println( i + " MIN "+
78  				// component2.getMinimumSize());
79  				// }
80  			}
81  
82  			public void windowClosing(final WindowEvent we) {
83  				closeNote(note, cd);
84  			}// windowActivated
85  
86  			public void windowClosed(WindowEvent e) {
87  					note.getNoteUI().setNoteOpen(false);
88  				// note.getNoteUI().setNoteOpen(false);
89  			}
90  
91  		});
92  		// cd.setPreferredSize(new
93  		// Dimension(component.getPreferredSize().width,component.getPreferredSize().height+200));
94  		// cd.setSize(component.getPreferredSize());
95  		// cd.pack();
96  
97  		// JTabbedPane noteTabpane = note.getNoteTabpane();
98  		//		
99  		// Component[] components = noteTabpane.getComponents();
100 		//		
101 		// for (int i = 0; i < components.length; i++) {
102 		// JComponent component2 = (JComponent) components[i];
103 		//			
104 		// System.out.println(i + " PRES "+ component2.getPreferredSize());
105 		// System.out.println( i + " SIZE "+ component2.getSize());
106 		// System.out.println( i + " MIN "+ component2.getMinimumSize());
107 		// }
108 
109 		cd.setSize(new Dimension(450, 500));
110 
111 		// note.getNoteUI().setNoteOpen(true);
112 		cd.setVisible(true);
113 
114 	}
115 	
116 
117 	/***
118 	 * @param note
119 	 * @param cd
120 	 */
121 	protected void closeNote(final INoteStep note, final CustomDialog cd) {
122 
123 			//save it, no matter what
124 			note.getNoteUI().getSaveAction().actionPerformed(null);
125 			cd.dispose();
126 //			if (!note.getNoteUI().isCompleted()) {
127 //				note.showNotePartsCheckDialog();
128 //				cd.dispose();
129 //			} else {
130 //				//this is when
131 //				note.showNoteSaveCheckDialog();
132 //				cd.dispose();
133 //			}// if
134 			note.getNoteUI().setNoteOpen(false);
135 
136 	}
137 
138 }