1 32 33 package it.businesslogic.ireport.gui; 34 35 40 public class JMDIMenuBar extends javax.swing.JMenuBar implements java.awt.event.ComponentListener , java.awt.event.ActionListener { 41 42 javax.swing.JButton closeButton = null; 43 javax.swing.JButton resizeButton = null; 44 javax.swing.JButton iconifyButton = null; 45 JMDIFrame activeFrame = null; 46 boolean isMaximized = false; 47 int closeCount=0; 48 49 50 public JMDIMenuBar() { 51 closeButton = new javax.swing.JButton (javax.swing.plaf.metal.MetalIconFactory.getInternalFrameCloseIcon(16)); 52 closeButton.setBorder( new javax.swing.border.EmptyBorder ( new java.awt.Insets ( 0,0,0,0 ) )); 53 resizeButton = new javax.swing.JButton (javax.swing.plaf.metal.MetalIconFactory.getInternalFrameAltMaximizeIcon(16)); 54 resizeButton.setBorder( new javax.swing.border.EmptyBorder ( new java.awt.Insets ( 0,0,0,0 ) )); 55 iconifyButton = new javax.swing.JButton (javax.swing.plaf.metal.MetalIconFactory.getInternalFrameMinimizeIcon(16) ); 56 iconifyButton.setBorder( new javax.swing.border.EmptyBorder ( new java.awt.Insets ( 0,0,0,0 ) )); 57 58 this.addComponentListener(this); 59 } 60 61 public void componentHidden(java.awt.event.ComponentEvent e) {} 62 public void componentMoved(java.awt.event.ComponentEvent e) {} 63 public void componentResized(java.awt.event.ComponentEvent e) { 64 if (this.getParent()!= null && closeButton != null) closeButton.setBounds(this.getParent().getWidth()-16-2,(this.getHeight()-16)/2,16,16); 65 if (this.getParent()!= null && closeButton != null) resizeButton.setBounds(this.getParent().getWidth()-32-6,(this.getHeight()-16)/2,16,16); 66 if (this.getParent()!= null && closeButton != null) iconifyButton.setBounds(this.getParent().getWidth()-48-6,(this.getHeight()-16)/2,16,16); 67 } 68 69 public void removeFrameButtons() 70 { 71 isMaximized = false; 72 activeFrame = null; 73 closeButton.removeActionListener(this); 74 resizeButton.removeActionListener(this); 75 iconifyButton.removeActionListener(this); 76 this.remove( closeButton); 77 this.remove( resizeButton); 78 this.remove( iconifyButton); 79 this.update(this.getGraphics()); 81 } 82 83 public void setMaximizedFrame(JMDIFrame jf) 84 { 85 if (jf == null) 86 { 87 removeFrameButtons(); 88 } 89 else 90 { 91 92 if (!isMaximized) 93 { 94 resizeButton.addActionListener(this); 95 iconifyButton.addActionListener(this); 96 closeButton.addActionListener(this); 97 this.add ( iconifyButton ); 98 this.add( resizeButton); 99 this.add( closeButton); 100 this.restoreButtonsPosition(); 101 this.update(this.getGraphics()); 102 } 103 activeFrame = jf; 104 isMaximized = true; 105 } 106 } 107 108 public JMDIFrame getMaximizedFrame() 109 { 110 return this.activeFrame; 111 } 112 113 public void componentShown(java.awt.event.ComponentEvent e) {} 114 115 134 public void paint(java.awt.Graphics g) { 135 componentResized(null); 136 super.paint(g); 137 } 138 139 143 public void actionPerformed(java.awt.event.ActionEvent e) { 144 145 this.activeFrame = MainFrame.getMainInstance().getActiveReportFrame(); 146 closeCount++; 148 if (e. getSource() == resizeButton) 149 { 150 if (this.activeFrame != null) 151 { 152 try { 153 activeFrame.setMaximum( false); 154 activeFrame.getDesktopPane().getDesktopManager().activateFrame(activeFrame); 155 } catch (Exception ex){} 156 } 157 } 158 else if (e. getSource() == iconifyButton) 160 { 161 if (this.activeFrame != null) 162 { 163 try { 164 activeFrame.setIcon(true); 166 } catch (Exception ex){} 167 } 168 } 169 else if (e. getSource() == closeButton) 173 { 174 if (this.activeFrame != null) 175 { 176 208 try { 209 210 213 javax.swing.JInternalFrame f = activeFrame; 214 int frames = 0; 215 if (activeFrame != null && activeFrame.getDesktopPane() != null) 216 { 217 frames = activeFrame.getDesktopPane().getAllFrames().length; 218 } 219 f.doDefaultCloseAction(); 220 if (f.isClosed() && frames <= 1) 221 { 222 removeFrameButtons(); 223 } 224 225 MainFrame.getMainInstance().updateMenuWindowList(); 226 } catch (Exception ex){ 229 ex.printStackTrace(); 230 } 231 } 232 } 233 } 234 235 public void restoreButtonsPosition() 236 { 237 componentResized(null); 238 } 239 240 public void closeFrame( javax.swing.JInternalFrame frameToClose) 241 { 242 closeFrame( frameToClose, false ); 243 } 244 245 public void closeFrame( javax.swing.JInternalFrame frameToClose, boolean force ) 246 { 247 try { 248 249 javax.swing.JInternalFrame oldActive = this.activeFrame; 250 251 if (oldActive == frameToClose) oldActive = null; 252 if (frameToClose != null) 253 { 254 255 try { 258 259 int frames = frameToClose.getDesktopPane().getAllFrames().length; 262 frameToClose.setDefaultCloseOperation(frameToClose.DISPOSE_ON_CLOSE); 263 frameToClose.doDefaultCloseAction(); 264 265 if (frameToClose.isClosed() && frames <= 1) 266 { 267 removeFrameButtons(); 268 } 269 270 } catch (Exception ex){ 273 ex.printStackTrace();; 274 } 275 } 276 277 if (oldActive != null && oldActive instanceof JReportFrame) 278 { 279 MainFrame.getMainInstance().setActiveReportForm( (JReportFrame)oldActive ); 280 } 281 } finally 282 { 283 MainFrame.getMainInstance().updateMenuWindowList(); 284 } 285 } 286 } 287 | Popular Tags |