Source Code Cross Referenced for JMDIMenuBar.java in  » Report » iReport-2.0.5 » it » businesslogic » ireport » gui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » iReport 2.0.5 » it.businesslogic.ireport.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2005 - 2008 JasperSoft Corporation.  All rights reserved. 
003:         * http://www.jaspersoft.com.
004:         *
005:         * Unless you have purchased a commercial license agreement from JasperSoft,
006:         * the following license terms apply:
007:         *
008:         * This program is free software; you can redistribute it and/or modify
009:         * it under the terms of the GNU General Public License version 2 as published by
010:         * the Free Software Foundation.
011:         *
012:         * This program is distributed WITHOUT ANY WARRANTY; and without the
013:         * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014:         * See the GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018:         * or write to:
019:         *
020:         * Free Software Foundation, Inc.,
021:         * 59 Temple Place - Suite 330,
022:         * Boston, MA  USA  02111-1307
023:         *
024:         *
025:         *
026:         *
027:         * JMDIMenuBar.java
028:         * 
029:         * Created on 5 febbraio 2003, 22.57
030:         *
031:         */
032:
033:        package it.businesslogic.ireport.gui;
034:
035:        /**
036:         * Similar to a javax.swing.JMenuBar, this menu bar is able to handle close, minimize e AltMaximize buttons for
037:         * JMDIFrame contained in a JMDIDesktopPane.
038:         * @author  Administrator
039:         */
040:        public class JMDIMenuBar extends javax.swing.JMenuBar implements 
041:                java.awt.event.ComponentListener, java.awt.event.ActionListener {
042:
043:            javax.swing.JButton closeButton = null;
044:            javax.swing.JButton resizeButton = null;
045:            javax.swing.JButton iconifyButton = null;
046:            JMDIFrame activeFrame = null;
047:            boolean isMaximized = false;
048:            int closeCount = 0;
049:
050:            /** Creates a new instance of JMDIMenuBar */
051:            public JMDIMenuBar() {
052:                closeButton = new javax.swing.JButton(
053:                        javax.swing.plaf.metal.MetalIconFactory
054:                                .getInternalFrameCloseIcon(16));
055:                closeButton.setBorder(new javax.swing.border.EmptyBorder(
056:                        new java.awt.Insets(0, 0, 0, 0)));
057:                resizeButton = new javax.swing.JButton(
058:                        javax.swing.plaf.metal.MetalIconFactory
059:                                .getInternalFrameAltMaximizeIcon(16));
060:                resizeButton.setBorder(new javax.swing.border.EmptyBorder(
061:                        new java.awt.Insets(0, 0, 0, 0)));
062:                iconifyButton = new javax.swing.JButton(
063:                        javax.swing.plaf.metal.MetalIconFactory
064:                                .getInternalFrameMinimizeIcon(16));
065:                iconifyButton.setBorder(new javax.swing.border.EmptyBorder(
066:                        new java.awt.Insets(0, 0, 0, 0)));
067:
068:                this .addComponentListener(this );
069:            }
070:
071:            public void componentHidden(java.awt.event.ComponentEvent e) {
072:            }
073:
074:            public void componentMoved(java.awt.event.ComponentEvent e) {
075:            }
076:
077:            public void componentResized(java.awt.event.ComponentEvent e) {
078:                if (this .getParent() != null && closeButton != null)
079:                    closeButton.setBounds(this .getParent().getWidth() - 16 - 2,
080:                            (this .getHeight() - 16) / 2, 16, 16);
081:                if (this .getParent() != null && closeButton != null)
082:                    resizeButton.setBounds(
083:                            this .getParent().getWidth() - 32 - 6, (this 
084:                                    .getHeight() - 16) / 2, 16, 16);
085:                if (this .getParent() != null && closeButton != null)
086:                    iconifyButton.setBounds(
087:                            this .getParent().getWidth() - 48 - 6, (this 
088:                                    .getHeight() - 16) / 2, 16, 16);
089:            }
090:
091:            public void removeFrameButtons() {
092:                isMaximized = false;
093:                activeFrame = null;
094:                closeButton.removeActionListener(this );
095:                resizeButton.removeActionListener(this );
096:                iconifyButton.removeActionListener(this );
097:                this .remove(closeButton);
098:                this .remove(resizeButton);
099:                this .remove(iconifyButton);
100:                //restoreButtonsPosition();
101:                this .update(this .getGraphics());
102:            }
103:
104:            public void setMaximizedFrame(JMDIFrame jf) {
105:                if (jf == null) {
106:                    removeFrameButtons();
107:                } else {
108:
109:                    if (!isMaximized) {
110:                        resizeButton.addActionListener(this );
111:                        iconifyButton.addActionListener(this );
112:                        closeButton.addActionListener(this );
113:                        this .add(iconifyButton);
114:                        this .add(resizeButton);
115:                        this .add(closeButton);
116:                        this .restoreButtonsPosition();
117:                        this .update(this .getGraphics());
118:                    }
119:                    activeFrame = jf;
120:                    isMaximized = true;
121:                }
122:            }
123:
124:            public JMDIFrame getMaximizedFrame() {
125:                return this .activeFrame;
126:            }
127:
128:            public void componentShown(java.awt.event.ComponentEvent e) {
129:            }
130:
131:            /** Paints this component.
132:             * <p>
133:             * This method is called when the contents of the component should
134:             * be painted in response to the component first being shown or
135:             * damage needing repair.  The clip rectangle in the
136:             * <code>Graphics</code> parameter will be set to the area
137:             * which needs to be painted.
138:             * Subclasses of Component that override this method need not call
139:             * super.paint(g).
140:             * <p>
141:             * For performance reasons, Components with zero width or height
142:             * aren't considered to need painting when they are first shown,
143:             * and also aren't considered to need repair.
144:             *
145:             * @param g the graphics context to use for painting
146:             * @see       #update
147:             * @since     JDK1.0
148:             *
149:             */
150:            public void paint(java.awt.Graphics g) {
151:                componentResized(null);
152:                super .paint(g);
153:            }
154:
155:            /** Invoked when an action occurs.
156:             *    This method handle the minimize,alt-maximize and close buttons
157:             *    for frames maximized in JMDIDestopPane
158:             */
159:            public void actionPerformed(java.awt.event.ActionEvent e) {
160:
161:                this .activeFrame = MainFrame.getMainInstance()
162:                        .getActiveReportFrame();
163:                // The simpler case...
164:                closeCount++;
165:                if (e.getSource() == resizeButton) {
166:                    if (this .activeFrame != null) {
167:                        try {
168:                            activeFrame.setMaximum(false);
169:                            activeFrame.getDesktopPane().getDesktopManager()
170:                                    .activateFrame(activeFrame);
171:                        } catch (Exception ex) {
172:                        }
173:                    }
174:                }
175:                // A bit more complex...
176:                else if (e.getSource() == iconifyButton) {
177:                    if (this .activeFrame != null) {
178:                        try {
179:                            //activeFrame.setMaximum( false);
180:                            activeFrame.setIcon(true);
181:                        } catch (Exception ex) {
182:                        }
183:                    }
184:                }
185:                // the camplex case....the user want close this form!
186:                // What we have to do?
187:                //
188:                else if (e.getSource() == closeButton) {
189:                    if (this .activeFrame != null) {
190:                        /*
191:                        if (activeFrame instanceof JReportFrame)
192:                        {
193:                            JReportFrame jrf = (JReportFrame)activeFrame;
194:                            //System.out.println( activeFrame.getTitle() );
195:                            boolean saveIt = true;
196:                            if (jrf.getReport().isModified() && !MainFrame.getMainInstance().getProperties().getProperty("AskToSave","true").equals("false"))
197:                            {
198:                                String message = "Would you like to save the report before exiting?";
199:                                String caption = "Unsaved file" + (jrf.getReport().isModified()?" (Changed)": " (Unchanged)") ;
200:                                int ret = javax.swing.JOptionPane.showConfirmDialog(this, message, caption, javax.swing.JOptionPane.YES_NO_CANCEL_OPTION);
201:                                
202:                                switch(ret)
203:                                {
204:                                    case javax.swing.JOptionPane.YES_OPTION:
205:                                        saveIt = true;
206:                                        break;
207:                                    case javax.swing.JOptionPane.NO_OPTION:
208:                                        saveIt = false;
209:                                        break;
210:                                    default:
211:                                        return;
212:                                }
213:                            }
214:                            if (saveIt)
215:                            {
216:                                java.awt.event.ActionEvent ae = new java.awt.event.ActionEvent(this,0, "");
217:                                MainFrame.getMainInstance().jMenuItemSaveActionPerformed(ae);
218:                                if (jrf.getReport().isModified()) return;
219:                            }
220:                        }
221:                         */
222:                        try {
223:
224:                            //System.out.println(closeCount+" "+activeFrame.getTitle());
225:                            //System.out.flush();
226:
227:                            javax.swing.JInternalFrame f = activeFrame;
228:                            int frames = 0;
229:                            if (activeFrame != null
230:                                    && activeFrame.getDesktopPane() != null) {
231:                                frames = activeFrame.getDesktopPane()
232:                                        .getAllFrames().length;
233:                            }
234:                            f.doDefaultCloseAction();
235:                            if (f.isClosed() && frames <= 1) {
236:                                removeFrameButtons();
237:                            }
238:
239:                            MainFrame.getMainInstance().updateMenuWindowList();
240:                            //activeFrame.setMaximum( false);
241:                            //activeFrame.setIcon(true);
242:                        } catch (Exception ex) {
243:                            ex.printStackTrace();
244:                        }
245:                    }
246:                }
247:            }
248:
249:            public void restoreButtonsPosition() {
250:                componentResized(null);
251:            }
252:
253:            public void closeFrame(javax.swing.JInternalFrame frameToClose) {
254:                closeFrame(frameToClose, false);
255:            }
256:
257:            public void closeFrame(javax.swing.JInternalFrame frameToClose,
258:                    boolean force) {
259:                try {
260:
261:                    javax.swing.JInternalFrame oldActive = this .activeFrame;
262:
263:                    if (oldActive == frameToClose)
264:                        oldActive = null;
265:                    if (frameToClose != null) {
266:
267:                        //if (!((JMDIFrame)frameToClose).closingFrame(force)) return;
268:                        //System.out.println("Closing...!!!");
269:                        try {
270:
271:                            //System.out.println(closeCount+" "+activeFrame.getTitle());
272:                            //System.out.flush();
273:                            int frames = frameToClose.getDesktopPane()
274:                                    .getAllFrames().length;
275:                            frameToClose
276:                                    .setDefaultCloseOperation(frameToClose.DISPOSE_ON_CLOSE);
277:                            frameToClose.doDefaultCloseAction();
278:
279:                            if (frameToClose.isClosed() && frames <= 1) {
280:                                removeFrameButtons();
281:                            }
282:
283:                            //activeFrame.setMaximum( false);
284:                            //activeFrame.setIcon(true);
285:                        } catch (Exception ex) {
286:                            ex.printStackTrace();
287:                            ;
288:                        }
289:                    }
290:
291:                    if (oldActive != null && oldActive instanceof  JReportFrame) {
292:                        MainFrame.getMainInstance().setActiveReportForm(
293:                                (JReportFrame) oldActive);
294:                    }
295:                } finally {
296:                    MainFrame.getMainInstance().updateMenuWindowList();
297:                }
298:            }
299:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.