1 71 72 73 package swingwtx.swing; 74 75 import swingwt.awt.*; 76 import swingwtx.swing.event.*; 77 78 import org.eclipse.swt.widgets.*; 79 80 import java.util.*; 81 82 public class JInternalFrame extends JComponent implements WindowConstants, RootPaneContainer { 83 84 protected org.eclipse.swt.widgets.Composite ppeer = null; 85 protected Vector internalFrameListeners = new Vector(); 86 protected JDesktopPane parentpane = null; 87 protected Icon pImage = null; 88 protected String pTitle = ""; 89 protected int pCloseOperation = DISPOSE_ON_CLOSE; 90 protected JButton defaultButton = null; 91 protected boolean disposed = true; 92 protected JRootPane rootPane = null; 93 94 public JInternalFrame() { this("", true, true, true, true); } 95 public JInternalFrame(String title) { this(title, true, true, true, true); } 96 public JInternalFrame(String title, boolean resizable) { this(title, resizable, true, true, true); } 97 public JInternalFrame(String title, boolean resizable, boolean closable) { this(title, resizable, closable, true, true); } 98 public JInternalFrame(String title, boolean resizable, boolean closable, boolean maximizable) { this(title, resizable, closable, maximizable, true); } 99 100 public JInternalFrame(String title, boolean resizable, boolean closable, boolean maximizable, boolean iconifiable) { 101 102 setTitle(title); 103 104 setLayoutImpl(new FillLayout()); 106 rootPane = new JRootPane(); 107 doAdd(rootPane); 108 } 109 110 111 public Component add(swingwt.awt.Component c) { rootPane.getContentPane().add(c); return c; } 112 113 public void add(swingwt.awt.Component c, Object layoutModifier) { rootPane.getContentPane().add(c, layoutModifier); } 114 115 public void remove(swingwt.awt.Component c) { rootPane.getContentPane().remove(c); } 116 117 public LayoutManager getLayout() { 118 return rootPane.getContentPane().getLayout(); 119 } 120 121 public void setLayout(LayoutManager l) { 122 rootPane.getContentPane().setLayout(l); 123 } 124 125 public void setLayout(LayoutManager2 l) { 126 rootPane.getContentPane().setLayout(l); 127 } 128 129 public void dispose() { 130 if (!disposed) { 131 super.dispose(); 133 parentpane.removeFrame(this); 135 processInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED); 136 disposed = true; 137 } 138 } 139 140 public void addInternalFrameListener(InternalFrameListener l) { internalFrameListeners.add(l); } 141 public int getDefaultCloseOperation() { return pCloseOperation; } 142 public void setDefaultCloseOperation(int operation) { pCloseOperation = operation; } 143 public JDesktopPane getJDesktopPane() { return parentpane; } 144 public Icon getFrameIcon() { return pImage; } 145 public void setFrameIcon(Icon icon) { pImage = icon; refreshFrame(); } 146 public String getTitle() { return pTitle; } 147 public void setTitle(String title) { pTitle = title; refreshFrame(); } 148 public Control getPeer() { return ppeer; } 149 public void show() { } 150 public void hide() { } 151 public void pack() { if (ppeer != null) ppeer.pack(); } 152 protected void setParentPane(JDesktopPane jdp) { parentpane = jdp; } 153 public boolean isClosable() { return false; } 154 public boolean isResizable() { return false; } 155 public boolean isMaximizable() { return true; } 156 public boolean isIconifiable() { return false; } 157 public boolean isMaximum() { return true; } 158 public void setClosed(boolean b) { if (b) dispose(); } 159 public void setClosable(boolean b) {} 160 public void setResizable(boolean b) {} 161 public void setMaximizable(boolean b) {} 162 public void setIconifiable(boolean b) {} 163 public void setMaximum(boolean b) {} 164 public void setIcon(boolean b) { try { setSelected(false); } catch (java.beans.PropertyVetoException e) {}} 165 public void toFront() { try { setSelected(true); } catch (java.beans.PropertyVetoException e) {} } 166 public void toBack() {try { setSelected(false); } catch (java.beans.PropertyVetoException e) {}} 167 168 173 protected void refreshFrame() { 174 if (parentpane != null) parentpane.refreshFrame(this); 175 } 176 177 public Dimension getSize() { 178 if (ppeer == null) 179 return new Dimension(0, 0); 180 else 181 return new Dimension(ppeer.getBounds().width, ppeer.getBounds().height); 182 } 183 public void setSize(Dimension d) { } 184 public void setSize(int width, int height) { } 185 public void setLocation(int x, int y) {} 186 public boolean isSelected() { if (parentpane != null) return (parentpane.getSelectedFrame() == this); else return false; } 187 public void setSelected(boolean b) throws java.beans.PropertyVetoException { 188 if (parentpane != null) if (b) parentpane.setSelectedFrame(this); 189 } 190 191 public void registerEvents() { 192 super.registerEvents(); 193 } 194 195 199 protected boolean processFrameClosing() { 200 processInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING); 201 try { 202 switch (pCloseOperation) { 203 case DO_NOTHING_ON_CLOSE: return false; 204 case DISPOSE_ON_CLOSE: if (!disposed) dispose(); return true; 205 case EXIT_ON_CLOSE: if (!disposed) dispose(); return true; 206 case HIDE_ON_CLOSE: if (!disposed) dispose(); return true; 207 default: 208 return true; 209 } 210 } 211 finally { 212 processInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED); 214 } 215 } 216 217 public Container getContentPane() { 218 return rootPane.getContentPane(); 219 } 220 221 public Component getGlassPane() { 222 return rootPane.getGlassPane(); 223 } 224 225 public JLayeredPane getLayeredPane() { 226 return rootPane.getLayeredPane(); 227 } 228 229 public JRootPane getRootPane() { 230 return rootPane; 231 } 232 233 public void setContentPane(Container contentPane) { 234 rootPane.setContentPane(contentPane); 235 } 236 237 public void setGlassPane(Component glassPane) { 238 rootPane.setGlassPane(glassPane); 239 } 240 241 public void setLayeredPane(JLayeredPane layeredPane) { 242 rootPane.setLayeredPane(layeredPane); 243 } 244 245 public void setJMenuBar(JMenuBar menu) { 246 rootPane.setJMenuBar(menu); 247 } 248 249 public JMenuBar getJMenuBar() { 250 return rootPane.getJMenuBar(); 251 } 252 253 public void setMenuBar(MenuBar menu) { 254 rootPane.setMenuBar(menu); 255 } 256 257 public MenuBar getMenuBar() { 258 return rootPane.getMenuBar(); 259 } 260 261 public void setDefaultButton(JButton button) { 262 rootPane.setDefaultButton(button); 263 } 264 265 public JButton getDefaultButton() { 266 return rootPane.getDefaultButton(); 267 } 268 269 270 public void processInternalFrameEvent(int eventID) { 271 InternalFrameEvent e = new InternalFrameEvent(this, eventID); 272 Iterator i = internalFrameListeners.iterator(); 273 while (i.hasNext()) { 274 InternalFrameListener l = (InternalFrameListener) i.next(); 275 switch (eventID) { 276 case (InternalFrameEvent.INTERNAL_FRAME_ACTIVATED): l.internalFrameActivated(e); break; 277 case (InternalFrameEvent.INTERNAL_FRAME_CLOSED): l.internalFrameClosed(e); break; 278 case (InternalFrameEvent.INTERNAL_FRAME_CLOSING): l.internalFrameClosing(e); break; 279 case (InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED): l.internalFrameDeactivated(e); break; 280 case (InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED): l.internalFrameDeiconified(e); break; 281 case (InternalFrameEvent.INTERNAL_FRAME_ICONIFIED): l.internalFrameDeiconified(e); break; 282 case (InternalFrameEvent.INTERNAL_FRAME_OPENED): l.internalFrameOpened(e); break; 283 } 284 } 285 } 286 287 public void setSwingWTParent(Container parent) throws Exception { 288 descendantHasPeer = true; 289 disposed = false; 290 ppeer = new org.eclipse.swt.widgets.Composite(parent.getComposite(), 0); 291 peer = ppeer; 292 composite = ppeer; 293 this.parent = parent; 294 super.setSwingWTParent(parent); 295 processInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_OPENED); 296 } 297 298 } 299 | Popular Tags |