View Javadoc

1   /*
2    * Copyright (C) 2004 TiongHiang Lee
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not,  write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   *
18   * Email: thlee@onemindsoft.org
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              //alternate the bounds
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  }