1 43 44 45 package swingwtx.swing; 46 47 import swingwt.awt.Component; 48 import swingwt.awt.Container; 49 import swingwt.awt.GraphicsConfiguration; 50 51 public class JFrame extends swingwt.awt.Frame implements WindowConstants, RootPaneContainer { 52 53 public final static int NORMAL = 0; 54 public final static int ICONIFIED = 1; 55 public final static int MAXIMIZED_HORIZ = 2; 56 public final static int MAXIMIZED_VERT = 3; 57 public final static int MAXIMIZED_BOTH = 4; 58 59 protected int closeOperation = WindowConstants.DISPOSE_ON_CLOSE; 60 61 protected boolean isMax = false; 62 63 public JFrame() { super();} 64 public JFrame(String title) {super(title); } 65 public JFrame(GraphicsConfiguration gc) { super(gc); } 66 67 public int getExtendedState() { 68 if (isIcon) return ICONIFIED; 69 return NORMAL; 70 } 71 72 public void setExtendedState(final int state) { 73 SwingUtilities.invokeSync(new Runnable () { 74 public void run() { 75 if ( ((state & MAXIMIZED_BOTH) > 0) || 76 ((state & MAXIMIZED_HORIZ) > 0) || 77 ((state & MAXIMIZED_VERT) > 0) ) { 78 peer.setMaximized(true); 79 isMax = true; 80 } 81 else { 82 peer.setMaximized(false); 83 isMax = false; 84 } 85 86 if ((state & ICONIFIED) > 0) { 87 peer.setMinimized(true); 88 isIcon = true; 89 } 90 else { 91 peer.setMinimized(false); 92 isIcon = false; 93 } 94 } 95 }); 96 } 97 98 102 public void toggleWindowState() { 103 SwingUtilities.invokeSync(new Runnable () { 104 public void run() { 105 if (isMax) { 106 peer.setMaximized(false); 107 peer.setMaximized(true); 108 } 109 else 110 { 111 peer.setMaximized(true); 112 peer.setMaximized(false); 113 } 114 } 115 }); 116 } 117 118 public int getDefaultCloseOperation() { 119 return closeOperation; 120 } 121 122 public void setDefaultCloseOperation(int operation) { 123 closeOperation = operation; 124 } 125 126 public Container getContentPane() { 127 return rootPane.getContentPane(); 128 } 129 130 public Component getGlassPane() { 131 return rootPane.getGlassPane(); 132 } 133 134 public JLayeredPane getLayeredPane() { 135 return rootPane.getLayeredPane(); 136 } 137 138 public JRootPane getRootPane() { 139 return rootPane; 140 } 141 142 public void setContentPane(Container contentPane) { 143 rootPane.setContentPane(contentPane); 144 } 145 146 public void setGlassPane(Component glassPane) { 147 rootPane.setGlassPane(glassPane); 148 } 149 150 public void setLayeredPane(JLayeredPane layeredPane) { 151 rootPane.setLayeredPane(layeredPane); 152 } 153 154 public void registerWindowEvents() { 155 156 158 peer.addShellListener(new org.eclipse.swt.events.ShellListener() { 159 public void shellActivated(org.eclipse.swt.events.ShellEvent e) { 160 processWindowEvent(swingwt.awt.event.WindowEvent.WINDOW_ACTIVATED); 161 } 162 public void shellClosed(org.eclipse.swt.events.ShellEvent e) { 163 isClosed = true; 164 processWindowEvent(swingwt.awt.event.WindowEvent.WINDOW_CLOSING); 165 processWindowEvent(swingwt.awt.event.WindowEvent.WINDOW_CLOSED); 166 switch (closeOperation) { 168 case WindowConstants.DISPOSE_ON_CLOSE: e.doit = true; SwingWTUtils.decrementWindowReferences(); break; 169 case WindowConstants.DO_NOTHING_ON_CLOSE: e.doit = false; break; 170 case WindowConstants.EXIT_ON_CLOSE: e.doit = true; SwingWTUtils.decrementWindowReferences(); System.exit(0); break; 171 case WindowConstants.HIDE_ON_CLOSE: e.doit = false; peer.setVisible(false); break; 172 } 173 } 174 public void shellDeactivated(org.eclipse.swt.events.ShellEvent e) { 175 processWindowEvent(swingwt.awt.event.WindowEvent.WINDOW_DEACTIVATED); 176 } 177 public void shellDeiconified(org.eclipse.swt.events.ShellEvent e) { 178 processWindowEvent(swingwt.awt.event.WindowEvent.WINDOW_DEICONIFIED); 179 } 180 public void shellIconified(org.eclipse.swt.events.ShellEvent e) { 181 processWindowEvent(swingwt.awt.event.WindowEvent.WINDOW_ICONIFIED); 182 } 183 }); 184 } 185 186 } 187 | Popular Tags |