wneuper@3727
|
1 |
/******************************************************************
|
wneuper@3727
|
2 |
* Copyright (c) 2003, Mario Hochreiter, Student of
|
wneuper@3727
|
3 |
* Software Engineering at FH-Hagenberg, Austria.
|
wneuper@3727
|
4 |
* Project member of the isac team at the Institute for
|
wneuper@3727
|
5 |
* Software-Technologie, Graz University of Technology, Austria.
|
wneuper@3727
|
6 |
*
|
wneuper@3727
|
7 |
* Use is subject to license terms.
|
wneuper@3727
|
8 |
******************************************************************/
|
wneuper@3727
|
9 |
|
wneuper@3727
|
10 |
//FIXXXXXME: still under construction!!!
|
wneuper@3727
|
11 |
package isac.gui;
|
wneuper@3727
|
12 |
|
wneuper@3727
|
13 |
import isac.session.IObjectManager;
|
wneuper@3727
|
14 |
import isac.useractions.EUIContext;
|
wneuper@3727
|
15 |
import isac.useractions.EUIElement;
|
wneuper@3727
|
16 |
import isac.useractions.IUIAction;
|
wneuper@3727
|
17 |
import isac.useractions.IUserAction;
|
wneuper@3727
|
18 |
import isac.useractions.UIActionOnBrowserDialog;
|
wneuper@3727
|
19 |
import isac.useractions.UIActionOnWSDialog;
|
wneuper@3727
|
20 |
import isac.useractions.UserAction;
|
wneuper@3727
|
21 |
import isac.users.IUserManager;
|
wneuper@3881
|
22 |
import isac.util.FixedPortRMISocketFactory;
|
rkoenig@3829
|
23 |
import isac.util.WindowApplicationRMISocketFactory;
|
wneuper@3727
|
24 |
import isac.util.WindowApplicationPaths;
|
wneuper@3881
|
25 |
import isac.gui.browser.BrowserFrameSwing;
|
wneuper@3727
|
26 |
import isac.gui.browser.BrowserFrameRMI;
|
wneuper@3727
|
27 |
import isac.interfaces.IToGUI;
|
wneuper@3727
|
28 |
import isac.wsdialog.DialogProtocolException;
|
wneuper@3727
|
29 |
import isac.wsdialog.IWorksheetDialog;
|
wneuper@3727
|
30 |
import isac.browserdialog.IBrowserDialog;
|
wneuper@3727
|
31 |
|
wneuper@3727
|
32 |
import java.awt.*;
|
wneuper@3727
|
33 |
import java.awt.event.ActionEvent;
|
wneuper@3727
|
34 |
import java.awt.event.ActionListener;
|
wneuper@3881
|
35 |
import java.awt.event.WindowAdapter;
|
wneuper@3881
|
36 |
import java.awt.event.WindowEvent;
|
wneuper@3881
|
37 |
import java.awt.event.WindowListener;
|
wneuper@3727
|
38 |
import java.beans.PropertyVetoException;
|
gkompach@3729
|
39 |
import java.io.FileInputStream;
|
gkompach@3729
|
40 |
import java.io.FileNotFoundException;
|
gkompach@3729
|
41 |
import java.io.IOException;
|
gkompach@3729
|
42 |
import java.io.InputStream;
|
wneuper@3727
|
43 |
import java.rmi.Naming;
|
wneuper@3727
|
44 |
import java.rmi.NotBoundException;
|
wneuper@3727
|
45 |
import java.rmi.RemoteException;
|
nsimic@3785
|
46 |
import java.rmi.server.RMISocketFactory;
|
wneuper@3727
|
47 |
import java.rmi.server.UnicastRemoteObject;
|
wneuper@3727
|
48 |
import java.util.HashMap;
|
gkompach@3729
|
49 |
import java.util.Properties;
|
wneuper@3727
|
50 |
|
wneuper@3727
|
51 |
import javax.swing.*;
|
wneuper@3727
|
52 |
import javax.swing.plaf.basic.BasicInternalFrameUI;
|
wneuper@3727
|
53 |
|
wneuper@3727
|
54 |
import org.apache.log4j.Logger;
|
wneuper@3727
|
55 |
|
wneuper@3727
|
56 |
/**
|
wneuper@3727
|
57 |
* Main window application for the ISAC system. Responsible for showing the user
|
wneuper@3727
|
58 |
* all requested information and for the interaction with the user.
|
wneuper@3727
|
59 |
*
|
wneuper@3727
|
60 |
* @author Mario Hochreiter
|
wneuper@3727
|
61 |
* @author Manuel Koschuch
|
wneuper@3727
|
62 |
* @version $Revision$
|
wneuper@3881
|
63 |
*
|
wneuper@3727
|
64 |
*/
|
wneuper@3727
|
65 |
public class WindowApplication extends UnicastRemoteObject implements
|
wneuper@3881
|
66 |
ActionListener, ILoginListener, IToWorksheetUser, IGuiConstants, IToGUI {
|
wneuper@3881
|
67 |
/**
|
wneuper@3881
|
68 |
* For serialization purposes
|
wneuper@3881
|
69 |
*/
|
wneuper@3881
|
70 |
private static final long serialVersionUID = 1L;
|
wneuper@3727
|
71 |
|
wneuper@3881
|
72 |
private static final Logger logger = Logger
|
wneuper@3881
|
73 |
.getLogger(WindowApplication.class.getName());
|
wneuper@3727
|
74 |
|
wneuper@3881
|
75 |
private static JFrame main_frame_;
|
wneuper@3727
|
76 |
|
wneuper@3881
|
77 |
private IUserManager user_manager_;
|
wneuper@3727
|
78 |
|
wneuper@3881
|
79 |
private static IBrowserDialog current_session_;
|
wneuper@3727
|
80 |
|
wneuper@3881
|
81 |
/** Container for the internal frames, which will contain the worksheets */
|
wneuper@3881
|
82 |
private JDesktopPane worksheetDesktopPane;
|
wneuper@3881
|
83 |
|
wneuper@3881
|
84 |
/** login dialoge */
|
wneuper@3881
|
85 |
private LoginScreen loginScreen;
|
wneuper@3881
|
86 |
|
wneuper@3881
|
87 |
// hash map containing the dynamical created buttons
|
wneuper@3727
|
88 |
protected HashMap<JButton, EUIElement> map_buttons_actions_;
|
wneuper@3881
|
89 |
|
wneuper@3727
|
90 |
protected HashMap<EUIElement, JButton> map_actions_buttons_;
|
wneuper@3727
|
91 |
|
wneuper@3881
|
92 |
private JMenuBar menu_bar_;
|
wneuper@3727
|
93 |
|
wneuper@3881
|
94 |
private boolean menu_separator_added_;
|
wneuper@3727
|
95 |
|
wneuper@3881
|
96 |
private int num_browser_frames_;
|
wneuper@3881
|
97 |
|
wneuper@3881
|
98 |
public WindowApplication() throws RemoteException {
|
wneuper@3881
|
99 |
|
wneuper@3881
|
100 |
menu_separator_added_ = false;
|
wneuper@3881
|
101 |
|
wneuper@3881
|
102 |
main_frame_ = new JFrame();
|
wneuper@3881
|
103 |
main_frame_.setSize(new Dimension(WINDOW_APPLICATION_INITIAL_SIZE_X,
|
wneuper@3881
|
104 |
WINDOW_APPLICATION_INITIAL_SIZE_Y));
|
wneuper@3881
|
105 |
Point screenCenter = this.screenCenter();
|
wneuper@3881
|
106 |
main_frame_.setLocation(screenCenter);
|
wneuper@3881
|
107 |
|
wneuper@3881
|
108 |
// initialize hashMaps
|
wneuper@3727
|
109 |
map_buttons_actions_ = new HashMap<JButton, EUIElement>();
|
wneuper@3727
|
110 |
map_actions_buttons_ = new HashMap<EUIElement, JButton>();
|
wneuper@3727
|
111 |
|
wneuper@3881
|
112 |
menu_bar_ = new JMenuBar();
|
wneuper@3727
|
113 |
|
wneuper@3881
|
114 |
main_frame_.setJMenuBar(menu_bar_);
|
wneuper@3727
|
115 |
|
wneuper@3881
|
116 |
num_browser_frames_ = 0;
|
wneuper@3727
|
117 |
|
wneuper@3881
|
118 |
this.createWorksheetPane();
|
wneuper@3727
|
119 |
|
wneuper@3881
|
120 |
main_frame_.add(worksheetDesktopPane);
|
wneuper@3727
|
121 |
|
wneuper@3881
|
122 |
JFrame.setDefaultLookAndFeelDecorated(true);
|
wneuper@3881
|
123 |
|
wneuper@3881
|
124 |
// WN071011 handle 'close WindowApplication' with windowListener
|
wneuper@3881
|
125 |
// main_frame_.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
wneuper@3881
|
126 |
main_frame_.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
wneuper@3881
|
127 |
|
wneuper@3881
|
128 |
main_frame_.setVisible(false);
|
wneuper@3881
|
129 |
|
wneuper@3881
|
130 |
loginScreen = new LoginScreen();
|
wneuper@3881
|
131 |
loginScreen.addListener(this);
|
wneuper@3881
|
132 |
loginScreen.setVisible(true);
|
wneuper@3881
|
133 |
}
|
wneuper@3881
|
134 |
|
wneuper@3881
|
135 |
/* LK 04.08.27 */
|
wneuper@3881
|
136 |
/**
|
wneuper@3881
|
137 |
* login method called from <code>LoginScreen</code> Initialize RMI
|
wneuper@3881
|
138 |
* connection to <code>ObjectManager</code> and
|
wneuper@3881
|
139 |
* <code>XSessionManager</code>.
|
wneuper@3881
|
140 |
*/
|
wneuper@3881
|
141 |
private void login(String username, String password) {
|
wneuper@3881
|
142 |
String name = WindowApplicationPaths.OBJECT_MANAGER_RMI;
|
wneuper@3881
|
143 |
|
wneuper@3881
|
144 |
try {
|
wneuper@3881
|
145 |
System.out.println("connect to ObjectManager in getSDialog : "
|
wneuper@3881
|
146 |
+ name);
|
wneuper@3881
|
147 |
Object lookup = Naming.lookup(name);
|
wneuper@3881
|
148 |
|
wneuper@3881
|
149 |
user_manager_ = ((IObjectManager) lookup).getUserManager();
|
wneuper@3881
|
150 |
} catch (RemoteException exc) {
|
wneuper@3881
|
151 |
System.err.println("no rmiregistry runing on server " + name
|
wneuper@3881
|
152 |
+ " no connection possible --- try later");
|
wneuper@3881
|
153 |
System.err.println("serverCom exception: " + exc.getMessage());
|
wneuper@3881
|
154 |
exc.printStackTrace();
|
wneuper@3881
|
155 |
} catch (NotBoundException exc) {
|
wneuper@3881
|
156 |
System.err.println("servercom: notboundexc: " + exc.getMessage());
|
wneuper@3881
|
157 |
System.err.println("server not found - try to connect to Proxy");
|
wneuper@3881
|
158 |
} catch (java.net.MalformedURLException exc) {
|
wneuper@3881
|
159 |
System.err.println("servercom: MalformedURLException: "
|
wneuper@3881
|
160 |
+ exc.getMessage());
|
wneuper@3881
|
161 |
exc.printStackTrace();
|
wneuper@3881
|
162 |
}
|
wneuper@3881
|
163 |
if (logger.isInfoEnabled())
|
wneuper@3881
|
164 |
logger.info("WA->UM: login");
|
wneuper@3881
|
165 |
try {
|
wneuper@3881
|
166 |
current_session_ = user_manager_.login(username, password);
|
wneuper@3881
|
167 |
System.out.println("Login success");
|
wneuper@3881
|
168 |
current_session_.registerBrowserFrame((IToGUI) this);
|
wneuper@3881
|
169 |
} catch (RemoteException e) {
|
wneuper@3881
|
170 |
System.err
|
wneuper@3881
|
171 |
.println("PANIC RK isac.gui.Windowapplication#login(String,String)");
|
wneuper@3881
|
172 |
System.err.println("login exception: " + e.getMessage());
|
wneuper@3881
|
173 |
if (logger.isDebugEnabled())
|
wneuper@3881
|
174 |
logger.error("login", e.detail);
|
wneuper@3881
|
175 |
}
|
wneuper@3881
|
176 |
if (current_session_ != null) {
|
wneuper@3881
|
177 |
loginScreen.dispose();
|
wneuper@3881
|
178 |
main_frame_.setVisible(true);
|
wneuper@3881
|
179 |
} else {
|
wneuper@3881
|
180 |
loginScreen.showErrorMsg();
|
wneuper@3881
|
181 |
}
|
wneuper@3881
|
182 |
}
|
wneuper@3881
|
183 |
|
wneuper@3881
|
184 |
/**
|
wneuper@3881
|
185 |
* To add dynamic buttons to the menu of the frame.
|
wneuper@3881
|
186 |
*
|
wneuper@3881
|
187 |
* @param action
|
wneuper@3881
|
188 |
* The action assigned to the button.
|
wneuper@3881
|
189 |
*/
|
wneuper@3727
|
190 |
public void addToMenuBar(IUIAction action) {
|
wneuper@3881
|
191 |
EUIElement action_id = action.getAction();
|
wneuper@3881
|
192 |
|
wneuper@3881
|
193 |
// / TODO: Really bad HACK ... This should be rewritten ...
|
wneuper@3881
|
194 |
// / One possible sollution is set the layout of the main frame to
|
wneuper@3881
|
195 |
// / BorderLayout, add a splitpane to the north part of the main_frame_
|
wneuper@3881
|
196 |
// / and add buttons that have UI_CONTEXT_WINDOW_APPLICATION to the
|
wneuper@3881
|
197 |
// panel
|
wneuper@3881
|
198 |
// / in the left part of the splitpane and the buttons that have
|
wneuper@3881
|
199 |
// / UI_CONTEXT_CALCULATION to the panel in the right part of the
|
wneuper@3881
|
200 |
// splitpane ...
|
wneuper@3881
|
201 |
if (!menu_separator_added_
|
wneuper@3881
|
202 |
&& action.getContext() == EUIContext.UI_CONTEXT_CALCULATION) {
|
wneuper@3881
|
203 |
menu_bar_.add(new JLabel(" "));
|
wneuper@3881
|
204 |
menu_bar_.add(new JLabel(" "));
|
wneuper@3881
|
205 |
menu_bar_.add(new JLabel(" "));
|
wneuper@3881
|
206 |
menu_bar_.add(new JLabel(" "));
|
wneuper@3881
|
207 |
menu_separator_added_ = true;
|
wneuper@3881
|
208 |
}
|
wneuper@3881
|
209 |
|
wneuper@3881
|
210 |
// check if a button is already in the menu
|
wneuper@3881
|
211 |
if (!map_actions_buttons_.containsKey(action_id)) {
|
wneuper@3881
|
212 |
JButton dynamic_button = new JButton(action.getLabel());
|
wneuper@3727
|
213 |
dynamic_button.setName(action.getLabel());
|
wneuper@3727
|
214 |
dynamic_button.addActionListener(this);
|
wneuper@3881
|
215 |
|
wneuper@3881
|
216 |
map_actions_buttons_.put(action_id, dynamic_button);
|
wneuper@3881
|
217 |
map_buttons_actions_.put(dynamic_button, action_id);
|
wneuper@3881
|
218 |
|
wneuper@3727
|
219 |
menu_bar_.add(dynamic_button);
|
wneuper@3727
|
220 |
menu_bar_.updateUI();
|
wneuper@3727
|
221 |
}
|
wneuper@3881
|
222 |
}
|
wneuper@3727
|
223 |
|
wneuper@3881
|
224 |
/**
|
wneuper@3881
|
225 |
* Removes item from menu.
|
wneuper@3881
|
226 |
*
|
wneuper@3881
|
227 |
* @param action
|
wneuper@3881
|
228 |
* @return true if done else false
|
wneuper@3881
|
229 |
*/
|
wneuper@3881
|
230 |
public boolean removeFromMenuBar(IUIAction action) {
|
wneuper@3727
|
231 |
|
wneuper@3881
|
232 |
// / get the ID of the action
|
wneuper@3881
|
233 |
EUIElement actionID = action.getAction();
|
wneuper@3727
|
234 |
|
wneuper@3881
|
235 |
// / check if the button is registered
|
wneuper@3881
|
236 |
if (!map_actions_buttons_.containsKey(actionID)) {
|
wneuper@3881
|
237 |
System.out
|
wneuper@3881
|
238 |
.println("In BrowserFrame::removeFromMenuBar() - The button is not registered !!");
|
wneuper@3881
|
239 |
return false;
|
wneuper@3881
|
240 |
} else {
|
wneuper@3881
|
241 |
JButton button_to_delete = (JButton) map_actions_buttons_
|
wneuper@3881
|
242 |
.get(actionID);
|
wneuper@3727
|
243 |
|
wneuper@3881
|
244 |
map_actions_buttons_.remove(actionID);
|
wneuper@3881
|
245 |
map_buttons_actions_.remove(button_to_delete);
|
wneuper@3727
|
246 |
|
wneuper@3881
|
247 |
menu_bar_.remove(button_to_delete);
|
wneuper@3881
|
248 |
menu_bar_.updateUI();
|
wneuper@3727
|
249 |
|
wneuper@3881
|
250 |
return true;
|
wneuper@3881
|
251 |
}
|
wneuper@3881
|
252 |
}
|
wneuper@3727
|
253 |
|
wneuper@3881
|
254 |
/**
|
wneuper@3881
|
255 |
* Open a new Worksheet and start the modeling and specification phase.
|
wneuper@3881
|
256 |
*
|
wneuper@3881
|
257 |
* @param fmz
|
wneuper@3881
|
258 |
* Formalization (can be empty see UC 2.5.4) that the math engine
|
wneuper@3881
|
259 |
* needs to start a calculation
|
wneuper@3881
|
260 |
* @param source
|
wneuper@3881
|
261 |
* Source of the Formalization (e.g. ExampleHierarchy or from
|
wneuper@3881
|
262 |
* Scratch)
|
wneuper@3881
|
263 |
* @param type
|
wneuper@3881
|
264 |
* Requested ViewType for the CalcHead
|
wneuper@3881
|
265 |
* @throws RemoteException
|
wneuper@3881
|
266 |
*/
|
wneuper@3881
|
267 |
private void openNewWorksheet(IWorksheetDialog dialog)
|
wneuper@3881
|
268 |
throws RemoteException {
|
wneuper@3727
|
269 |
|
wneuper@3881
|
270 |
// InternalFrame, holding the Frames for the Worksheet and the
|
wneuper@3881
|
271 |
// corresponding CalcHeadPanel
|
wneuper@3881
|
272 |
JInternalFrame internalFrame = createInternalFrame("Worksheet", true,
|
wneuper@3881
|
273 |
true, false, false);
|
wneuper@3881
|
274 |
internalFrame.setResizable(true);
|
wneuper@3881
|
275 |
internalFrame.setLayout(new BorderLayout());
|
wneuper@3727
|
276 |
|
wneuper@3881
|
277 |
// DesktopPane, added to internalFrame to be able to hae multiple
|
wneuper@3881
|
278 |
// InternalFrames in this InternalFrame
|
wneuper@3881
|
279 |
final JDesktopPane desktop = new JDesktopPane();
|
wneuper@3881
|
280 |
desktop.setSize(WORKSHEET_DESKTOP_PANE_INITIAL_SIZE_X,
|
wneuper@3881
|
281 |
WORKSHEET_DESKTOP_PANE_INITIAL_SIZE_Y);
|
wneuper@3727
|
282 |
|
wneuper@3881
|
283 |
desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
|
wneuper@3727
|
284 |
|
wneuper@3881
|
285 |
internalFrame.setContentPane(desktop); // , BorderLayout.CENTER);
|
wneuper@3727
|
286 |
|
wneuper@3881
|
287 |
main_frame_.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
wneuper@3727
|
288 |
|
wneuper@3881
|
289 |
Worksheet ws = new Worksheet(this, dialog, desktop);
|
wneuper@3881
|
290 |
// new InternalFrame for the Worksheet
|
wneuper@3881
|
291 |
JInternalFrame ws_frame = new JInternalFrame();
|
wneuper@3881
|
292 |
((BasicInternalFrameUI) ws_frame.getUI()).setNorthPane(null);
|
wneuper@3881
|
293 |
ws_frame.setSize(WORKSHEET_FRAME_INITIAL_SIZE_X, main_frame_
|
wneuper@3881
|
294 |
.getHeight()
|
wneuper@3881
|
295 |
- WORKSHEET_FRAME_INITIAL_OFFSET_Y);
|
wneuper@3727
|
296 |
|
wneuper@3881
|
297 |
Container c;
|
wneuper@3881
|
298 |
c = ws_frame.getContentPane();
|
wneuper@3881
|
299 |
c.setLayout(new BorderLayout());
|
wneuper@3881
|
300 |
c.add(ws, BorderLayout.CENTER);
|
wneuper@3727
|
301 |
|
wneuper@3881
|
302 |
// NC060726: The Worksheet desktop manager must not have the
|
wneuper@3881
|
303 |
// BorderLayout
|
wneuper@3881
|
304 |
// desktop.setLayout(new BorderLayout());
|
wneuper@3881
|
305 |
// desktop.add(ws_frame, BorderLayout.CENTER);
|
wneuper@3881
|
306 |
desktop.add(ws_frame);
|
wneuper@3727
|
307 |
|
wneuper@3881
|
308 |
try {
|
wneuper@3881
|
309 |
ws_frame.setMaximum(true);
|
wneuper@3881
|
310 |
} catch (PropertyVetoException e) {
|
wneuper@3881
|
311 |
e.printStackTrace();
|
wneuper@3881
|
312 |
}
|
wneuper@3727
|
313 |
|
wneuper@3881
|
314 |
ws_frame.setFocusable(false);
|
wneuper@3881
|
315 |
ws_frame.setVisible(true);
|
wneuper@3727
|
316 |
|
wneuper@3881
|
317 |
internalFrame.addInternalFrameListener(ws);
|
wneuper@3727
|
318 |
|
wneuper@3881
|
319 |
int width, height = 0;
|
wneuper@3881
|
320 |
height = internalFrame.getPreferredSize().height;
|
wneuper@3881
|
321 |
width = internalFrame.getPreferredSize().width;
|
wneuper@3881
|
322 |
// make Frame a little smaller than the window
|
wneuper@3881
|
323 |
height = main_frame_.getHeight() - WORKSHEET_FRAME_INITIAL_OFFSET_Y;
|
wneuper@3881
|
324 |
width = width < 600 ? WORKSHEET_FRAME_INITIAL_SIZE_X : width;
|
wneuper@3727
|
325 |
|
wneuper@3881
|
326 |
JInternalFrame[] frames = worksheetDesktopPane.getAllFrames();
|
wneuper@3881
|
327 |
int num_frames = frames.length - 4;
|
wneuper@3727
|
328 |
|
wneuper@3881
|
329 |
this.addInternalFrame(internalFrame);
|
wneuper@3727
|
330 |
|
wneuper@3881
|
331 |
internalFrame.setLocation(num_frames * 20, num_frames * 20);
|
wneuper@3881
|
332 |
internalFrame.setPreferredSize(new Dimension(width, height));
|
wneuper@3881
|
333 |
internalFrame.pack();
|
wneuper@3881
|
334 |
internalFrame.setVisible(true);
|
wneuper@3727
|
335 |
|
wneuper@3881
|
336 |
main_frame_.setCursor(Cursor.getDefaultCursor());
|
wneuper@3881
|
337 |
}
|
wneuper@3727
|
338 |
|
wneuper@3881
|
339 |
private JInternalFrame createInternalFrame(String title, boolean resizable,
|
wneuper@3881
|
340 |
boolean closable, boolean maximizable, boolean iconifiable) {
|
wneuper@3881
|
341 |
JInternalFrame internalFrame = new JInternalFrame(title, resizable,
|
wneuper@3881
|
342 |
closable, maximizable, iconifiable);
|
wneuper@3881
|
343 |
return internalFrame;
|
wneuper@3881
|
344 |
}
|
nsimic@3842
|
345 |
|
wneuper@3881
|
346 |
private void createWorksheetPane() {
|
wneuper@3881
|
347 |
worksheetDesktopPane = new JDesktopPane();
|
wneuper@3881
|
348 |
Dimension d = new Dimension();
|
wneuper@3881
|
349 |
d.setSize(main_frame_.getWidth() * 0.60, 0.0);
|
wneuper@3881
|
350 |
worksheetDesktopPane.setMinimumSize(d);
|
wneuper@3881
|
351 |
// "ghost frame" dragging; very fast but weired for some user
|
wneuper@3881
|
352 |
worksheetDesktopPane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
|
wneuper@3881
|
353 |
}
|
wneuper@3727
|
354 |
|
wneuper@3881
|
355 |
private Point screenCenter() {
|
wneuper@3881
|
356 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
wneuper@3881
|
357 |
int midX = screenSize.width / 2 - main_frame_.getWidth() / 2;
|
wneuper@3881
|
358 |
int midY = screenSize.height / 2 - main_frame_.getHeight() / 2;
|
wneuper@3881
|
359 |
return new Point(midX, midY);
|
wneuper@3881
|
360 |
}
|
wneuper@3727
|
361 |
|
wneuper@3881
|
362 |
private void addInternalFrame(JInternalFrame frame) {
|
wneuper@3881
|
363 |
worksheetDesktopPane.add(frame);
|
wneuper@3881
|
364 |
worksheetDesktopPane.getDesktopManager().activateFrame(frame);
|
wneuper@3881
|
365 |
frame.toFront();
|
wneuper@3881
|
366 |
frame.grabFocus();
|
wneuper@3881
|
367 |
}
|
wneuper@3727
|
368 |
|
wneuper@3881
|
369 |
// ----------ActionListener----------------------------------------
|
wneuper@3727
|
370 |
|
wneuper@3881
|
371 |
public void actionPerformed(ActionEvent event) {
|
wneuper@3881
|
372 |
System.out
|
wneuper@3881
|
373 |
.println("In WindowApplication::actionPerformed(ActionEvent event)");
|
wneuper@3727
|
374 |
|
wneuper@3881
|
375 |
// / get the source of the event
|
wneuper@3881
|
376 |
Object event_source = event.getSource();
|
wneuper@3727
|
377 |
|
wneuper@3881
|
378 |
// / check if it is a button
|
wneuper@3881
|
379 |
if (event_source instanceof JButton) {
|
wneuper@3881
|
380 |
JButton src_button = (JButton) event_source;
|
wneuper@3727
|
381 |
|
wneuper@3881
|
382 |
// / check the map and get the actionID
|
wneuper@3881
|
383 |
EUIElement actionID = map_buttons_actions_.get(src_button);
|
wneuper@3727
|
384 |
|
wneuper@3881
|
385 |
// / if the button is registered
|
wneuper@3881
|
386 |
if (actionID != null) {
|
wneuper@3881
|
387 |
notifySession(actionID);
|
wneuper@3881
|
388 |
} else {
|
wneuper@3881
|
389 |
System.out
|
wneuper@3881
|
390 |
.println("Got event from a button, but the button is not registered !!!");
|
wneuper@3881
|
391 |
}
|
wneuper@3881
|
392 |
} else {
|
wneuper@3881
|
393 |
System.out.println("Got event from someone else!!!");
|
wneuper@3881
|
394 |
}
|
wneuper@3881
|
395 |
}
|
wneuper@3727
|
396 |
|
wneuper@3881
|
397 |
private void notifySession(EUIElement action) {
|
wneuper@3881
|
398 |
try {
|
wneuper@3881
|
399 |
current_session_.notifyUserAction(new UserAction(action,
|
wneuper@3881
|
400 |
EUIContext.UI_CONTEXT_WINDOW_APPLICATION));
|
wneuper@3881
|
401 |
} catch (RemoteException e) {
|
wneuper@3881
|
402 |
e.printStackTrace();
|
wneuper@3881
|
403 |
} catch (DialogProtocolException e) {
|
wneuper@3881
|
404 |
e.printStackTrace();
|
wneuper@3881
|
405 |
}
|
wneuper@3881
|
406 |
}
|
wneuper@3727
|
407 |
|
wneuper@3881
|
408 |
/**
|
wneuper@3881
|
409 |
* creates a new browser frame, inserts it to the internal frames and
|
wneuper@3881
|
410 |
* registeres it to the browser dialog
|
wneuper@3881
|
411 |
*/
|
wneuper@3881
|
412 |
private void openNewBrowserFrame(IBrowserDialog browser_dialog,
|
wneuper@3881
|
413 |
String frame_name) {
|
wneuper@3881
|
414 |
try {
|
wneuper@3881
|
415 |
BrowserFrameSwing browser_frame = new BrowserFrameSwing(
|
wneuper@3881
|
416 |
browser_dialog, frame_name);
|
wneuper@3881
|
417 |
addInternalFrame(browser_frame);
|
wneuper@3727
|
418 |
|
wneuper@3881
|
419 |
num_browser_frames_++;
|
wneuper@3727
|
420 |
|
wneuper@3881
|
421 |
browser_frame.setSize(IGuiConstants.BROWSER_MIN_SIZE_X,
|
wneuper@3881
|
422 |
IGuiConstants.BROWSER_MIN_SIZE_Y);
|
wneuper@3881
|
423 |
browser_frame.setLocation(IGuiConstants.BROWSER_POS_X
|
wneuper@3881
|
424 |
+ (num_browser_frames_ * 20), IGuiConstants.BROWSER_POS_Y
|
wneuper@3881
|
425 |
+ (num_browser_frames_ * 20));
|
wneuper@3881
|
426 |
|
wneuper@3881
|
427 |
BrowserFrameRMI browser_framain_frame_rmi = new BrowserFrameRMI(
|
wneuper@3881
|
428 |
browser_frame);
|
wneuper@3881
|
429 |
|
wneuper@3881
|
430 |
browser_dialog.registerBrowserFrame(browser_framain_frame_rmi);
|
wneuper@3881
|
431 |
|
wneuper@3881
|
432 |
} catch (RemoteException remote_exception) {
|
wneuper@3881
|
433 |
remote_exception.printStackTrace();
|
wneuper@3881
|
434 |
}
|
wneuper@3881
|
435 |
}
|
wneuper@3881
|
436 |
|
wneuper@3881
|
437 |
public static void main(String[] args) {
|
wneuper@3881
|
438 |
|
wneuper@3881
|
439 |
if (args.length < 1) {
|
wneuper@3881
|
440 |
System.out.println("----------------------------");
|
wneuper@3881
|
441 |
System.out.println("invalid arguments for main()");
|
wneuper@3881
|
442 |
System.out.println("----------------------------");
|
wneuper@3881
|
443 |
System.exit(1);
|
wneuper@3881
|
444 |
}
|
wneuper@3881
|
445 |
|
wneuper@3881
|
446 |
Properties properties = new Properties();
|
wneuper@3881
|
447 |
InputStream is = null;
|
wneuper@3881
|
448 |
|
wneuper@3881
|
449 |
try {
|
wneuper@3881
|
450 |
is = new FileInputStream(args[0]);
|
wneuper@3881
|
451 |
} catch (FileNotFoundException e1) {
|
wneuper@3881
|
452 |
is = WindowApplication.class.getResourceAsStream(args[0]);
|
wneuper@3881
|
453 |
}
|
wneuper@3881
|
454 |
|
wneuper@3881
|
455 |
if (is == null) {
|
wneuper@3881
|
456 |
System.err.println("No property file found! - SYSTEM EXITING");
|
wneuper@3881
|
457 |
System.exit(-1);
|
wneuper@3881
|
458 |
}
|
wneuper@3881
|
459 |
|
wneuper@3881
|
460 |
try {
|
wneuper@3881
|
461 |
properties.load(is);
|
wneuper@3881
|
462 |
} catch (IOException e) {
|
wneuper@3881
|
463 |
e.printStackTrace();
|
wneuper@3881
|
464 |
}
|
wneuper@3881
|
465 |
|
wneuper@3881
|
466 |
if ((WindowApplicationPaths.WORKSHEET_RMI = properties
|
wneuper@3881
|
467 |
.getProperty("WORKSHEET_RMI")) == null) {
|
wneuper@3881
|
468 |
System.err
|
wneuper@3881
|
469 |
.println("No value for WORKSHEET_RMI found in property-file");
|
wneuper@3881
|
470 |
System.exit(-1);
|
wneuper@3881
|
471 |
}
|
wneuper@3881
|
472 |
|
wneuper@3881
|
473 |
if ((WindowApplicationPaths.BROWSER_FRAME_RMI = properties
|
wneuper@3881
|
474 |
.getProperty("BROWSER_FRAME_RMI")) == null) {
|
wneuper@3881
|
475 |
System.err
|
wneuper@3881
|
476 |
.println("No value for BROWSER_FRAME_RMI found in property-file");
|
wneuper@3881
|
477 |
System.exit(-1);
|
wneuper@3881
|
478 |
}
|
wneuper@3881
|
479 |
|
wneuper@3881
|
480 |
if ((WindowApplicationPaths.OBJECT_MANAGER_RMI = properties
|
wneuper@3881
|
481 |
.getProperty("OBJECT_MANAGER_RMI")) == null) {
|
wneuper@3881
|
482 |
System.err
|
wneuper@3881
|
483 |
.println("No value for OBJECT_MANAGER_RMI found in property-file");
|
wneuper@3881
|
484 |
System.exit(-1);
|
wneuper@3881
|
485 |
}
|
wneuper@3881
|
486 |
|
wneuper@3881
|
487 |
if ((WindowApplicationPaths.WINDOW_APPLICATION_REVERSE_RMI_SERVER = properties
|
wneuper@3881
|
488 |
.getProperty("WINDOW_APPLICATION_REVERSE_RMI_SERVER")) == null) {
|
wneuper@3881
|
489 |
System.err
|
wneuper@3881
|
490 |
.println("No value for WINDOW_APPLICATION_REVERSE_RMI_SERVER found in property-file");
|
wneuper@3881
|
491 |
System.exit(-1);
|
wneuper@3881
|
492 |
}
|
wneuper@3881
|
493 |
|
wneuper@3881
|
494 |
try {
|
wneuper@3881
|
495 |
if ((WindowApplicationPaths.WINDOW_APPLICATION_REVERSE_RMI_PORT = Integer
|
wneuper@3881
|
496 |
.parseInt(properties
|
wneuper@3881
|
497 |
.getProperty("WINDOW_APPLICATION_REVERSE_RMI_PORT"))) < 1) {
|
wneuper@3881
|
498 |
System.err
|
wneuper@3881
|
499 |
.println("No value for WINDOW_APPLICATION_REVERSE_RMI_PORT found in property-file");
|
wneuper@3881
|
500 |
System.exit(-1);
|
wneuper@3881
|
501 |
}
|
wneuper@3881
|
502 |
} catch (NumberFormatException e1) {
|
wneuper@3881
|
503 |
System.err
|
wneuper@3881
|
504 |
.println("No value for WINDOW_APPLICATION_REVERSE_RMI_PORT found in property-file");
|
wneuper@3881
|
505 |
System.exit(-1);
|
wneuper@3881
|
506 |
}
|
wneuper@3881
|
507 |
|
wneuper@3881
|
508 |
// Start the application
|
wneuper@3881
|
509 |
SwingUtilities.invokeLater(new Runnable() {
|
wneuper@3881
|
510 |
public void run() {
|
wneuper@3881
|
511 |
try {
|
wneuper@3881
|
512 |
try {
|
wneuper@3881
|
513 |
// Use ObjectManagerRMISocketFactory
|
wneuper@3881
|
514 |
RMISocketFactory
|
wneuper@3881
|
515 |
.setSocketFactory(new FixedPortRMISocketFactory(
|
wneuper@3881
|
516 |
WindowApplicationPaths.WINDOW_APPLICATION_REVERSE_RMI_PORT));
|
wneuper@3881
|
517 |
// new
|
wneuper@3881
|
518 |
// WindowApplicationRMISocketFactory(WindowApplicationPaths.WINDOW_APPLICATION_REVERSE_RMI_SERVER,
|
wneuper@3881
|
519 |
// WindowApplicationPaths.WINDOW_APPLICATION_REVERSE_RMI_PORT)
|
wneuper@3881
|
520 |
// );
|
wneuper@3881
|
521 |
} catch (IOException e) {
|
wneuper@3881
|
522 |
System.out.println("Exception: " + e.getMessage());
|
wneuper@3881
|
523 |
e.printStackTrace();
|
wneuper@3881
|
524 |
}
|
wneuper@3881
|
525 |
|
wneuper@3881
|
526 |
WindowApplication windowApplication = new WindowApplication();
|
wneuper@3881
|
527 |
System.out.println("Created: "
|
wneuper@3881
|
528 |
+ windowApplication.toString());
|
wneuper@3881
|
529 |
main_frame_.addWindowListener(windowListener);
|
wneuper@3881
|
530 |
} catch (RemoteException e) {
|
wneuper@3881
|
531 |
e.printStackTrace();
|
wneuper@3881
|
532 |
}
|
wneuper@3881
|
533 |
if (logger.isDebugEnabled())
|
wneuper@3881
|
534 |
logger.debug("WindowApplication started");
|
wneuper@3881
|
535 |
}
|
wneuper@3881
|
536 |
});
|
wneuper@3881
|
537 |
}
|
wneuper@3881
|
538 |
|
wneuper@3881
|
539 |
/**
|
wneuper@3881
|
540 |
* @see isac.gui.ILoginListener#loginEventOccured(isac.gui.LoginEvent)
|
wneuper@3881
|
541 |
*/
|
wneuper@3881
|
542 |
public void loginEventOccured(LoginEvent loginEvent) {
|
wneuper@3881
|
543 |
int type = loginEvent.getType();
|
wneuper@3881
|
544 |
switch (type) {
|
wneuper@3881
|
545 |
case (LoginEvent.LOGIN_TYPE_TRY_TO_LOGIN):
|
wneuper@3881
|
546 |
String username = loginEvent.getUsername();
|
wneuper@3881
|
547 |
String password = loginEvent.getPassword();
|
wneuper@3881
|
548 |
this.login(username, password);
|
wneuper@3881
|
549 |
break;
|
wneuper@3881
|
550 |
case (LoginEvent.LOGIN_TYPE_EXIT):
|
wneuper@3881
|
551 |
main_frame_.dispose();
|
wneuper@3881
|
552 |
System.exit(0);
|
wneuper@3881
|
553 |
break;
|
wneuper@3881
|
554 |
}
|
wneuper@3881
|
555 |
}
|
wneuper@3881
|
556 |
|
wneuper@3881
|
557 |
/**
|
wneuper@3881
|
558 |
* This method is called periodically by the ObjectManager to ensure that
|
wneuper@3881
|
559 |
* the RMI connection is still alive Added to fix a memory leak in
|
wneuper@3881
|
560 |
* ObjectManager.
|
wneuper@3881
|
561 |
*
|
wneuper@3881
|
562 |
* @return true if called over RMI and RMI connection is ok. If RMI
|
wneuper@3881
|
563 |
* connection is broken, the method throws RemoteException
|
wneuper@3881
|
564 |
*/
|
wneuper@3881
|
565 |
public boolean isUIRunning() throws RemoteException {
|
wneuper@3881
|
566 |
return true;
|
wneuper@3881
|
567 |
}
|
wneuper@3881
|
568 |
|
wneuper@3881
|
569 |
public void activateUIObject(int id, boolean active) throws RemoteException {
|
wneuper@3881
|
570 |
|
wneuper@3881
|
571 |
}
|
wneuper@3881
|
572 |
|
wneuper@3881
|
573 |
/**
|
wneuper@3881
|
574 |
* WN070719 late comment
|
wneuper@3881
|
575 |
*
|
wneuper@3881
|
576 |
* @deprecated in favour of isac.gui.WindowApplication#doUIAction(IUIAction
|
wneuper@3881
|
577 |
* action)
|
wneuper@3881
|
578 |
*/
|
wneuper@3881
|
579 |
public boolean doUIAction(IUserAction action) throws RemoteException {
|
wneuper@3881
|
580 |
|
wneuper@3881
|
581 |
return false;
|
wneuper@3881
|
582 |
}
|
wneuper@3881
|
583 |
|
wneuper@3881
|
584 |
/**
|
wneuper@3881
|
585 |
* only for lauching, handles UI_OPEN_WORKSHEET + UI_OPEN_BROWSER_FRAME only
|
wneuper@3881
|
586 |
*/
|
wneuper@3881
|
587 |
public void doUIAction(IUIAction action) throws RemoteException {
|
wneuper@3881
|
588 |
|
wneuper@3881
|
589 |
if (logger.isInfoEnabled())
|
wneuper@3881
|
590 |
logger.info(("WA<-DG: doUIAction(IUIAction action) : Action is "
|
wneuper@3881
|
591 |
+ action.getAction() + ", Context is " + action
|
wneuper@3881
|
592 |
.getContext()));
|
wneuper@3881
|
593 |
|
wneuper@3881
|
594 |
// if it is not our context go back
|
wneuper@3881
|
595 |
if (action.getContext() != EUIContext.UI_CONTEXT_WINDOW_APPLICATION)
|
wneuper@3881
|
596 |
return;
|
wneuper@3881
|
597 |
|
wneuper@3881
|
598 |
switch (action.getAction()) {
|
wneuper@3881
|
599 |
case UI_OPEN_WORKSHEET: {
|
wneuper@3881
|
600 |
UIActionOnWSDialog uaowd = (UIActionOnWSDialog) action;
|
wneuper@3881
|
601 |
openNewWorksheet(uaowd.getWorksheetDialog());
|
wneuper@3881
|
602 |
break;
|
wneuper@3881
|
603 |
}
|
wneuper@3881
|
604 |
case UI_OPEN_BROWSER_FRAME:
|
wneuper@3881
|
605 |
UIActionOnBrowserDialog uaobd = (UIActionOnBrowserDialog) action;
|
wneuper@3881
|
606 |
openNewBrowserFrame(uaobd.getBrowserDialog(), uaobd.getFrameName());
|
wneuper@3881
|
607 |
break;
|
wneuper@3881
|
608 |
}
|
wneuper@3881
|
609 |
}
|
wneuper@3881
|
610 |
|
wneuper@3881
|
611 |
/*
|
wneuper@3881
|
612 |
* (non-Javadoc)
|
wneuper@3881
|
613 |
*
|
wneuper@3881
|
614 |
* @see isac.interfaces.IToGUI#addUIElement(isac.useractions.IUIAction)
|
wneuper@3881
|
615 |
*/
|
wneuper@3881
|
616 |
public void addUIElement(IUIAction action) throws RemoteException {
|
wneuper@3881
|
617 |
if (action.getContext() == EUIContext.UI_CONTEXT_WINDOW_APPLICATION) {
|
wneuper@3881
|
618 |
addToMenuBar(action);
|
wneuper@3881
|
619 |
}
|
wneuper@3881
|
620 |
|
wneuper@3881
|
621 |
}
|
wneuper@3881
|
622 |
|
wneuper@3881
|
623 |
/*
|
wneuper@3881
|
624 |
* (non-Javadoc)
|
wneuper@3881
|
625 |
*
|
wneuper@3881
|
626 |
* @see isac.interfaces.IToGUI#removeUIElement(isac.useractions.IUIAction)
|
wneuper@3881
|
627 |
*/
|
wneuper@3881
|
628 |
public boolean removeUIElement(IUIAction action) throws RemoteException {
|
wneuper@3881
|
629 |
if (action.getContext() == EUIContext.UI_CONTEXT_WINDOW_APPLICATION) {
|
wneuper@3881
|
630 |
return removeFromMenuBar(action);
|
wneuper@3881
|
631 |
}
|
wneuper@3881
|
632 |
|
wneuper@3881
|
633 |
return false;
|
wneuper@3881
|
634 |
}
|
wneuper@3881
|
635 |
|
wneuper@3881
|
636 |
public void addCloseListener(Worksheet ws) {
|
wneuper@3881
|
637 |
main_frame_.addWindowListener(ws);
|
wneuper@3881
|
638 |
}
|
wneuper@3881
|
639 |
|
wneuper@3881
|
640 |
public void removeCloseListener(Worksheet ws) {
|
wneuper@3881
|
641 |
main_frame_.removeWindowListener(ws);
|
wneuper@3881
|
642 |
}
|
wneuper@3881
|
643 |
|
wneuper@3881
|
644 |
/**
|
wneuper@3881
|
645 |
* handles the user-action clicking X to close WindowApplication.
|
wneuper@3881
|
646 |
* WN071011 copied from http://mindprod.com/jgloss/close.html
|
wneuper@3881
|
647 |
*/
|
wneuper@3881
|
648 |
static WindowListener windowListener = new WindowAdapter() {
|
wneuper@3881
|
649 |
// anonymous WindowAdapter class
|
wneuper@3881
|
650 |
public void windowClosing(WindowEvent w) {
|
wneuper@3881
|
651 |
try {
|
wneuper@3881
|
652 |
current_session_.notifyUserAction(new UserAction(
|
wneuper@3881
|
653 |
EUIElement.UI_STOP_SESSION,
|
wneuper@3881
|
654 |
EUIContext.UI_CONTEXT_WINDOW_APPLICATION));
|
wneuper@3881
|
655 |
} catch (RemoteException e) {
|
wneuper@3881
|
656 |
// TODO Auto-generated catch block
|
wneuper@3881
|
657 |
e.printStackTrace();
|
wneuper@3881
|
658 |
} catch (DialogProtocolException e) {
|
wneuper@3881
|
659 |
// TODO Auto-generated catch block
|
wneuper@3881
|
660 |
e.printStackTrace();
|
wneuper@3881
|
661 |
}
|
wneuper@3881
|
662 |
main_frame_.setVisible(false);
|
wneuper@3881
|
663 |
main_frame_.dispose();
|
wneuper@3881
|
664 |
// WN071011 otherwise does not cancel WA in the VM
|
wneuper@3881
|
665 |
System.exit(0);
|
wneuper@3881
|
666 |
} // end windowClosing
|
wneuper@3881
|
667 |
};// end anonymous class
|
wneuper@3727
|
668 |
|
wneuper@3727
|
669 |
}
|