1 19 20 package swingwtx.swing; 21 22 import swingwt.awt.*; 23 24 32 public class JRootPane extends JPanel { 33 34 public static final int NONE = 0; 35 public static final int FRAME = 1; 36 public static final int PLAIN_DIALOG = 2; 37 public static final int INFORMATION_DIALOG = 3; 38 public static final int ERROR_DIALOG = 4; 39 public static final int COLOR_CHOOSER_DIALOG = 5; 40 public static final int FILE_CHOOSER_DIALOG = 6; 41 public static final int QUESTION_DIALOG = 7; 42 public static final int WARNING_DIALOG = 8; 43 44 protected int windowDecorationStyle = 0; 45 protected Container contentPane = null; 46 protected JMenuBar menu = null; 47 protected JButton defaultButton = null; 48 protected Component glassPane = null; protected JLayeredPane layeredPane = null; 51 protected Window parentWindow = null; 52 53 public JRootPane() { 54 this(null); 55 } 56 57 public JRootPane(Window parentWindow) { 58 this.parentWindow = parentWindow; 59 setLayout(new JRootPane.RootPaneLayout()); 60 setGlassPane(createGlassPane()); 61 setLayeredPane(createLayeredPane()); 62 setContentPane(createContentPane()); 63 } 64 65 protected Container createContentPane() { 66 JPanel content = new JPanel(); 67 content.setLayout(new BorderLayout()); return content; 69 } 70 71 protected Component createGlassPane() { 72 return new JPanel(); 73 } 74 75 protected JLayeredPane createLayeredPane() { 76 return new JLayeredPane(); 77 } 78 79 public int getWindowDecorationStyle() { 80 return windowDecorationStyle; 81 } 82 83 public void setWindowDecorationStyle(int windowStyle) { 84 windowDecorationStyle = windowStyle; 85 } 86 87 public Container getContentPane() { 88 return contentPane; 89 } 90 91 public void setContentPane(Container content) { 92 if (contentPane != null) 93 this.removeAll(); 94 contentPane = content; 95 this.add(contentPane); 96 } 97 98 public Component getGlassPane() { 99 return glassPane; 100 } 101 102 public JLayeredPane getLayeredPane() { 103 return layeredPane; 104 } 105 106 public void setGlassPane(Component glassPane) { 107 this.glassPane = glassPane; 108 } 109 110 public void setLayeredPane(JLayeredPane layeredPane) { 111 this.layeredPane = layeredPane; 112 } 113 114 public void setJMenuBar(final JMenuBar menu) { 115 this.menu = menu; 116 try { 117 SwingUtilities.invokeSync(new Runnable () { 118 public void run() { 119 try { 120 menu.setSwingWTParent(((org.eclipse.swt.widgets.Shell)parentWindow.getPeer())); 121 } 122 catch (Exception e) { 123 e.printStackTrace(); 124 } 125 } 126 }); 127 } 128 catch (Exception e) { 129 e.printStackTrace(); 130 } 131 } 132 133 public void setMenuBar(MenuBar menu) { setJMenuBar((JMenuBar) menu); } 134 public MenuBar getMenuBar() { return (MenuBar) menu; } 135 public JMenuBar getJMenuBar() { return this.menu; } 136 137 public JButton getDefaultButton() { return defaultButton; } 138 139 public void setDefaultButton(final JButton defaultButton) { 140 this.defaultButton = defaultButton; 141 defaultButton.setDefaultButtonParent(this); 142 SwingUtilities.invokeSync(new Runnable () { 143 public void run() { 144 if (SwingWTUtils.isSWTControlAvailable(peer) && defaultButton.getPeer() != null) 145 peer.getShell().setDefaultButton((org.eclipse.swt.widgets.Button) defaultButton.getPeer()); 146 } 147 }); 148 } 149 150 155 public boolean isValidateRoot() { 156 return true; 157 } 158 159 160 public boolean isOptimizedDrawingEnabled() { 161 return true; 162 } 163 164 165 public void addNotify() { } 166 167 public void removeNotify() { } 168 169 170 private class RootPaneLayout extends FillLayout { } 171 172 } 173 | Popular Tags |