Source Code Cross Referenced for JMDIDesktopPane.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:         * JMDIDesktopPane.java
028:         * 
029:         * Created on 7 febbraio 2003, 23.06
030:         *
031:         */
032:
033:        package it.businesslogic.ireport.gui;
034:
035:        import it.businesslogic.ireport.gui.event.*;
036:        import java.awt.Graphics;
037:        import java.beans.*;
038:        import javax.swing.*;
039:        import java.awt.datatransfer.DataFlavor;
040:        import java.awt.datatransfer.Transferable;
041:        import java.awt.dnd.DnDConstants;
042:        import java.awt.dnd.DropTarget;
043:        import java.awt.dnd.DropTargetContext;
044:        import java.awt.dnd.DropTargetDragEvent;
045:        import java.awt.dnd.DropTargetDropEvent;
046:        import java.awt.dnd.DropTargetEvent;
047:        import java.awt.dnd.DropTargetListener;
048:
049:        /**
050:         * JMDIDesktopPane is an evolution of the very trivial javax.swing.JDesktopPane.
051:         * This class add a lot of event for really handle a DesktopPane. With this
052:         * improvements we will able to handle internal windows menu list, activated window events,
053:         * and more...  
054:         * 
055:         *
056:         * @author  Administrator
057:         */
058:        public class JMDIDesktopPane extends javax.swing.JDesktopPane implements 
059:                java.io.Serializable {
060:
061:            private DropTarget dropTarget;
062:            private DropTargetListener dtListener;
063:            private int acceptableActions = DnDConstants.ACTION_COPY_OR_MOVE;
064:
065:            private static final String PROP_SAMPLE_PROPERTY = "SampleProperty";
066:
067:            private String sampleProperty;
068:
069:            //iR20    private ImageIcon background = new javax.swing.ImageIcon(JMDIDesktopPane.class.getResource("/it/businesslogic/ireport/gui/wp.jpg" ));
070:            private PropertyChangeSupport propertySupport;
071:
072:            /** Utility field used by event firing mechanism. */
073:            private javax.swing.event.EventListenerList listenerList = null;
074:
075:            /** Creates new JMDIDesktopPane */
076:            public JMDIDesktopPane() {
077:                super ();
078:                propertySupport = new PropertyChangeSupport(this );
079:
080:                this .dtListener = new DTListener();
081:
082:                // component, ops, listener, accepting
083:                this .dropTarget = new DropTarget(this , this .acceptableActions,
084:                        this .dtListener, true);
085:
086:                //iR20        this.setOpaque(false);
087:            }
088:
089:            //iR20    protected void paintComponent(Graphics g) {
090:            //iR20    
091:            //iR20        if (background != null)
092:            //iR20        {
093:            //iR20            g.drawImage(background.getImage(), 0,0, this);
094:            //iR20        }
095:            //iR20        super.paintComponents(g);
096:            //iR20    }
097:
098:            public void internalFrameActivated(JMDIFrame jMDIFrame) {
099:                this 
100:                        .fireInternalFrameActivatedListenerInternalFrameActivated(new InternalFrameActivatedEvent(
101:                                jMDIFrame));
102:            }
103:
104:            public void internalFrameClosed(JMDIFrame jMDIFrame) {
105:                if (this .getAllFrames().length == 1) {
106:                    this 
107:                            .fireInternalFrameActivatedListenerInternalFrameActivated(new InternalFrameActivatedEvent(
108:                                    null));
109:                }
110:                this 
111:                        .fireInternalFrameActivatedListenerInternalFrameActivated(new InternalFrameActivatedEvent(
112:                                jMDIFrame, InternalFrameActivatedEvent.CLOSED));
113:            }
114:
115:            public String getSampleProperty() {
116:                return sampleProperty;
117:            }
118:
119:            public void setSampleProperty(String value) {
120:                String oldValue = sampleProperty;
121:                sampleProperty = value;
122:                propertySupport.firePropertyChange(PROP_SAMPLE_PROPERTY,
123:                        oldValue, sampleProperty);
124:            }
125:
126:            public void addPropertyChangeListener(
127:                    PropertyChangeListener listener) {
128:                if (listener == null || propertySupport == null)
129:                    return;
130:                propertySupport.addPropertyChangeListener(listener);
131:            }
132:
133:            public void removePropertyChangeListener(
134:                    PropertyChangeListener listener) {
135:                propertySupport.removePropertyChangeListener(listener);
136:            }
137:
138:            /** Registers InternalFrameActivatedListener to receive events.
139:             * @param listener The listener to register.
140:             *
141:             */
142:            public synchronized void addInternalFrameActivatedListener(
143:                    it.businesslogic.ireport.gui.event.InternalFrameActivatedListener listener) {
144:                if (listenerList == null) {
145:                    listenerList = new javax.swing.event.EventListenerList();
146:                }
147:                listenerList
148:                        .add(
149:                                it.businesslogic.ireport.gui.event.InternalFrameActivatedListener.class,
150:                                listener);
151:            }
152:
153:            /** Removes InternalFrameActivatedListener from the list of listeners.
154:             * @param listener The listener to remove.
155:             *
156:             */
157:            public synchronized void removeInternalFrameActivatedListener(
158:                    it.businesslogic.ireport.gui.event.InternalFrameActivatedListener listener) {
159:                listenerList
160:                        .remove(
161:                                it.businesslogic.ireport.gui.event.InternalFrameActivatedListener.class,
162:                                listener);
163:            }
164:
165:            /** Notifies all registered listeners about the event.
166:             *
167:             * @param event The event to be fired
168:             *
169:             */
170:            private void fireInternalFrameActivatedListenerInternalFrameActivated(
171:                    it.businesslogic.ireport.gui.event.InternalFrameActivatedEvent event) {
172:                if (listenerList == null)
173:                    return;
174:                Object[] listeners = listenerList.getListenerList();
175:                for (int i = listeners.length - 2; i >= 0; i -= 2) {
176:                    if (listeners[i] == it.businesslogic.ireport.gui.event.InternalFrameActivatedListener.class) {
177:                        ((it.businesslogic.ireport.gui.event.InternalFrameActivatedListener) listeners[i + 1])
178:                                .internalFrameActivated(event);
179:                    }
180:                }
181:            }
182:
183:            public void cascade() {
184:                JInternalFrame[] frames = this .getAllFrames();
185:                if (frames.length == 0)
186:                    return;
187:
188:                JInternalFrame activeframe = this .getSelectedFrame();
189:
190:                int position = 0;
191:                for (int i = 0; i < frames.length; ++i) {
192:                    try {
193:                        frames[i].setMaximum(false);
194:                        frames[i].setIcon(false);
195:                        frames[i].moveToFront();
196:                    } catch (Exception ex) {
197:                    }
198:                    if (frames[i] != activeframe) {
199:                        frames[i].setLocation(position, position);
200:
201:                        position += 24;
202:                    }
203:                }
204:
205:                if (activeframe != null) {
206:                    activeframe.moveToFront();
207:                    activeframe.setLocation(position, position);
208:                }
209:            }
210:
211:            /* This method is ported from kdevelop'QextMdiChildArea
212:             */
213:            public void tileVertically() {
214:                JInternalFrame[] frames_tmp = this .getAllFrames();
215:
216:                if (frames_tmp.length == 0)
217:                    return;
218:
219:                JInternalFrame[] frames = new JInternalFrame[frames_tmp.length];
220:                if (this .getSelectedFrame() == null && frames_tmp[0].isIcon()) {
221:                    try {
222:                        frames_tmp[0].setIcon(false);
223:                        frames_tmp[0].setSelected(true);
224:                    } catch (Exception ex) {
225:                        return;
226:                    }
227:                }
228:                frames[0] = this .getSelectedFrame();
229:
230:                int k = 1;
231:                for (int i = 0; i < frames_tmp.length; ++i) {
232:                    if (frames_tmp[i] == frames[0])
233:                        continue;
234:                    frames[k] = frames_tmp[i];
235:                    k++;
236:                }
237:
238:                //adjust the arry to have the selected win in the first position....
239:
240:                int w = getWidth() / frames.length;
241:                int lastWidth = 0;
242:                if (frames.length > 1)
243:                    lastWidth = getWidth() - (w * (frames.length - 1));
244:                else
245:                    lastWidth = w;
246:
247:                int h = getHeight();
248:                int posX = 0;
249:                int countVisible = 0;
250:
251:                for (int i = 0; i < frames.length; ++i) {
252:                    try {
253:                        frames[i].setMaximum(false);
254:                        frames[i].setIcon(false);
255:                        frames[i].moveToFront();
256:                    } catch (Exception ex) {
257:                    }
258:
259:                    if (i < frames.length) {
260:                        frames[i].setLocation(posX, 0);
261:                        frames[i].setSize(w, h);
262:                        posX += w;
263:                    } else { // last visible childframe
264:                        frames[i].setLocation(posX, 0);
265:                        frames[i].setSize(lastWidth, h);
266:                    }
267:                }
268:            }
269:
270:            /* This method is ported from kdevelop'QextMdiChildArea
271:             */
272:            public void tileHorizontally() {
273:                JInternalFrame[] frames_tmp = this .getAllFrames();
274:
275:                if (frames_tmp.length == 0)
276:                    return;
277:
278:                JInternalFrame[] frames = new JInternalFrame[frames_tmp.length];
279:                if (this .getSelectedFrame() == null && frames_tmp[0].isIcon()) {
280:                    try {
281:                        frames_tmp[0].setIcon(false);
282:                        frames_tmp[0].setSelected(true);
283:                    } catch (Exception ex) {
284:                        return;
285:                    }
286:                }
287:                frames[0] = this .getSelectedFrame();
288:
289:                int k = 1;
290:                for (int i = 0; i < frames_tmp.length; ++i) {
291:                    if (frames_tmp[i] == frames[0])
292:                        continue;
293:                    else {
294:                        frames[k] = frames_tmp[i];
295:                        k++;
296:                    }
297:                }
298:
299:                //adjust the arry to have the selected win in the first position....
300:
301:                int w = getWidth();
302:
303:                int h = getHeight() / frames.length;
304:
305:                int lastHeight = 0;
306:                if (frames.length > 1)
307:                    lastHeight = getHeight() - (h * (frames.length - 1));
308:                else
309:                    lastHeight = h;
310:
311:                int posY = 0;
312:                int countVisible = 0;
313:
314:                for (int i = 0; i < frames.length; ++i) {
315:                    try {
316:                        frames[i].setMaximum(false);
317:                        frames[i].setIcon(false);
318:                        frames[i].moveToFront();
319:                    } catch (Exception ex) {
320:                    }
321:
322:                    if (i < frames.length) {
323:                        frames[i].setLocation(0, posY);
324:                        frames[i].setSize(w, h);
325:                        posY += h;
326:                    } else { // last visible childframe
327:                        frames[i].setLocation(0, posY);
328:                        frames[i].setSize(w, lastHeight);
329:                    }
330:                }
331:
332:            }
333:
334:            /* This method is ported from kdevelop'QextMdiChildArea
335:             */
336:            public void tileAnodine() {
337:                JInternalFrame[] frames_tmp = this .getAllFrames();
338:
339:                if (frames_tmp.length == 0)
340:                    return;
341:
342:                JInternalFrame[] frames = new JInternalFrame[frames_tmp.length];
343:
344:                if (this .getSelectedFrame() == null && frames_tmp[0].isIcon()) {
345:                    try {
346:                        frames_tmp[0].setIcon(false);
347:                        frames_tmp[0].setSelected(true);
348:                    } catch (Exception ex) {
349:                        return;
350:                    }
351:                }
352:
353:                frames[0] = this .getSelectedFrame();
354:                int k = 1;
355:                for (int i = 0; i < frames_tmp.length; ++i) {
356:                    if (frames_tmp[i] == frames[0])
357:                        continue;
358:                    frames[k] = frames_tmp[i];
359:                    k++;
360:                }
361:
362:                int numVisible = frames.length;
363:                if (numVisible < 1)
364:                    return;
365:                int numCols = (int) Math.sqrt(numVisible); // set columns to square root of visible count
366:                // create an array to form grid layout
367:                int[] numRows = new int[numCols];
368:                int numCurCol = 0;
369:                while (numCurCol < numCols) {
370:                    numRows[numCurCol] = numCols; // create primary grid values
371:                    numCurCol++;
372:                }
373:                int numDiff = numVisible - (numCols * numCols); // count extra rows
374:                int numCurDiffCol = numCols; // set column limiting for grid updates
375:                while (numDiff > 0) {
376:                    numCurDiffCol--;
377:                    numRows[numCurDiffCol]++; // add extra rows to column grid
378:                    if (numCurDiffCol < 1)
379:                        numCurDiffCol = numCols; // rotate through the grid
380:                    numDiff--;
381:                }
382:                numCurCol = 0;
383:                int numCurRow = 0;
384:                int curX = 0;
385:                int curY = 0;
386:                // the following code will size everything based on my grid above
387:                // there is no limit to the number of windows it will handle
388:                // it's great when a kick-ass theory works!!!                      // Pragma :)
389:                int xQuantum = getWidth() / numCols;
390:                int yQuantum = getHeight() / numRows[numCurCol];
391:
392:                for (int i = 0; i < frames.length; ++i) {
393:                    try {
394:                        frames[i].setMaximum(false);
395:                        frames[i].setIcon(false);
396:                        frames[i].moveToFront();
397:                    } catch (Exception ex) {
398:                    }
399:
400:                    frames[i].setLocation(curX, curY);
401:                    frames[i].setSize(xQuantum, yQuantum);
402:                    numCurRow++;
403:                    curY += yQuantum;
404:                    if (numCurRow == numRows[numCurCol]) {
405:                        numCurRow = 0;
406:                        numCurCol++;
407:                        curY = 0;
408:                        curX += xQuantum;
409:                        if (numCurCol != numCols)
410:                            yQuantum = getHeight() / numRows[numCurCol];
411:                    }
412:                }
413:            }
414:
415:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.