1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.onemind.swingweb.mapinput.peerdelegate.java.awt;
22
23 import java.awt.*;
24 import java.awt.Frame;
25 import java.util.Map;
26 import java.util.logging.Logger;
27 import org.onemind.awtbridge.input.BridgeInputContext;
28 import org.onemind.awtbridge.input.InputException;
29 import org.onemind.awtbridge.peer.BridgeComponentPeer;
30 import org.onemind.swingweb.mapinput.peerdelegate.MapInputDelegate;
31 /***
32 * The frame input delegate
33 * @author TiongHiang Lee (thlee@onemindsoft.org)
34 *
35 */
36 public class FrameInputDelegate extends WindowInputDelegate
37 {
38
39 /*** the logger **/
40 private static final Logger _logger = Logger.getLogger(FrameInputDelegate.class.getName());
41
42 /*** the instance **/
43 public static MapInputDelegate INSTANCE = new FrameInputDelegate();
44
45 /***
46 * {@inheritDoc}
47 */
48 public void processInput(BridgeComponentPeer peer, BridgeInputContext context, Map inputForm) throws InputException
49 {
50 Frame f = (Frame) peer.getComponent();
51 if (f.getMenuBar() != null)
52 {
53 context.handleInput(f.getMenuBar(), inputForm);
54 }
55 super.processInput(peer, context, inputForm);
56 }
57
58 public void processWindowEvent(BridgeComponentPeer peer, BridgeInputContext context, Map inputForm)
59 {
60 Frame f = (Frame) peer.getComponent();
61 String value = (String) inputForm.get(peer.getId());
62 if ("maximize".equals(value))
63 {
64 if (f.getMaximizedBounds() == null)
65 {
66 Dimension screenDim = context.getContext().getScreenSize();
67 f.setMaximizedBounds(new Rectangle(0, 0, (int)screenDim.getWidth(), (int)screenDim.getHeight()));
68 }
69
70 Rectangle current = f.getBounds();
71 f.setBounds(f.getMaximizedBounds());
72 f.setMaximizedBounds(current);
73 if (f.getExtendedState() == Frame.NORMAL)
74 {
75 f.setExtendedState(Frame.MAXIMIZED_BOTH);
76 } else
77 {
78 f.setExtendedState(Frame.NORMAL);
79 }
80 f.validate();
81 } else if ("minimize".equals(value))
82 {
83 if (f.getExtendedState() == Frame.ICONIFIED)
84 {
85 f.setExtendedState(Frame.NORMAL);
86 } else
87 {
88 f.setExtendedState(Frame.ICONIFIED);
89 }
90 } else
91 {
92 super.processWindowEvent(peer, context, inputForm);
93 }
94 return;
95 }
96 }