13a14,16 > import CH.ifa.draw.framework.DrawingView; > import CH.ifa.draw.application.DrawApplication; > 14a18,20 > import javax.swing.event.InternalFrameListener; > import javax.swing.event.InternalFrameAdapter; > import javax.swing.event.InternalFrameEvent; 16,16d21 < import java.awt.event.*; 20,20c25,25 < * An extension of WDesktopPane that supports often used MDI functionality. This --- > * An extension of JDesktopPane that supports often used MDI functionality. This 22a28,30 > * Note by dnoyeb: I dont know why the container does not fire frame close events when the frames > * are removed from the container with remove as opposed to simply closed with the > * "x". so if you say removeAll from container you wont be notified. No biggie. 24a33,33 > * @author C.L.Gilbert 27,27c36,36 < public class MDIDesktopPane extends JDesktopPane { --- > public class MDIDesktopPane extends JDesktopPane implements Desktop { 29a39,46 > private DrawApplication myDrawApplication; > > /** > * You need this if you are not using a component that inherits from > * JComponent > */ > //private final EventListenerList listenerList = new EventListenerList(); > protected DrawingView selectedView; 31,31c48,48 < public MDIDesktopPane() { --- > public MDIDesktopPane(DrawApplication newDrawApplication) { 31a49,49 > setDrawApplication(newDrawApplication); 34a53,87 > setAlignmentX(JComponent.LEFT_ALIGNMENT); > } > > protected InternalFrameListener internalFrameListener = new InternalFrameAdapter() { > /** > * Invoked when a internal frame has been opened. > * @see javax.swing.JInternalFrame#show > * if dv is null assert > */ > public void internalFrameOpened(InternalFrameEvent e){ > DrawingView dv = Helper.getDrawingView(e.getInternalFrame()); > fireDrawingViewAddedEvent(dv); > } > > /** > * Invoked when an internal frame is in the process of being closed. > * The close operation can be overridden at this point. > * @see javax.swing.JInternalFrame#setDefaultCloseOperation > */ > //public void internalFrameClosing(InternalFrameEvent e){ > //} > > /** > * Invoked when an internal frame has been closed. > * if dv is null assert > * if this is the last view set it to null > * @see javax.swing.JInternalFrame#setClosed > */ > public void internalFrameClosed(InternalFrameEvent e){ > DrawingView dv = Helper.getDrawingView(e.getInternalFrame()); > if (getComponentCount() == 0){ > selectedView = null; > fireDrawingViewSelectedEvent(selectedView); > } > fireDrawingViewRemovedEvent(dv); 36a90,165 > /** > * Invoked when an internal frame is iconified. > * @see javax.swing.JInternalFrame#setIcon > */ > //public void internalFrameIconified(InternalFrameEvent e){ > //} > > /** > * Invoked when an internal frame is de-iconified. > * @see javax.swing.JInternalFrame#setIcon > */ > //public void internalFrameDeiconified(InternalFrameEvent e){ > //} > > /** > * Invoked when an internal frame is activated. > * @see javax.swing.JInternalFrame#setSelected > * if this frame has a null drawingView then assert > * because their should be no null frames being selected > * this does not include NullDrawingView which is acceptable > */ > public void internalFrameActivated(InternalFrameEvent e){ > DrawingView dv = Helper.getDrawingView(e.getInternalFrame()); > selectedView = dv; > fireDrawingViewSelectedEvent(selectedView); > } > > //public void internalFrameDeactivated(InternalFrameEvent e){ > //} > }; > > > private void fireDrawingViewAddedEvent(final DrawingView dv) { > final Object[] listeners = listenerList.getListenerList(); > DesktopListener dpl; > DesktopEvent dpe = null; > for (int i = listeners.length-2; i>=0 ; i-=2) { > if (listeners[i] == DesktopListener.class) { > if (dpe == null) { > dpe = new DesktopEvent(MDIDesktopPane.this, dv); > } > dpl = (DesktopListener)listeners[i+1]; > dpl.drawingViewAdded(dpe); > } > } > } > > private void fireDrawingViewRemovedEvent(final DrawingView dv) { > final Object[] listeners = listenerList.getListenerList(); > DesktopListener dpl; > DesktopEvent dpe= null; > for (int i = listeners.length-2; i>=0 ; i-=2) { > if (listeners[i] == DesktopListener.class) { > if (dpe == null) { > dpe = new DesktopEvent(MDIDesktopPane.this, dv); > } > dpl = (DesktopListener)listeners[i+1]; > dpl.drawingViewRemoved(dpe); > } > } > } > > private void fireDrawingViewSelectedEvent(final DrawingView dv) { > final Object[] listeners = listenerList.getListenerList(); > DesktopListener dpl; > DesktopEvent dpe = null; > for (int i = listeners.length-2; i>=0 ; i-=2) { > if (listeners[i] == DesktopListener.class) { > if (dpe == null) { > dpe = new DesktopEvent(MDIDesktopPane.this, dv); > } > dpl = (DesktopListener)listeners[i+1]; > dpl.drawingViewSelected(dpe); > } > } > } 41a171,210 > > protected Component createContents(DrawingView dv) { > JScrollPane sp = new JScrollPane((Component) dv); > sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); > sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); > sp.setAlignmentX(LEFT_ALIGNMENT); > > String applicationTitle; > if (dv.drawing().getTitle() == null) { > applicationTitle = getDrawApplication().getApplicationName() + " - " + getDrawApplication().getDefaultDrawingTitle(); > } > else { > applicationTitle = getDrawApplication().getApplicationName() + " - " + dv.drawing().getTitle(); > } > JInternalFrame internalFrame = new JInternalFrame(applicationTitle, true, true, true, true); > internalFrame.setName(applicationTitle); > internalFrame.getContentPane().add(sp); > internalFrame.setSize(200,200); > return internalFrame; > } > > public DrawingView getActiveDrawingView(){ > return selectedView; > } > > /** > * This must match the signature of the superclass it is overriding or the > * method invocation may not resolve to this method unless it is called on > * a reference of specifically MDIDesktopPane type. So this must be > * Component add(Component comp) in order to override its super class and > * Component add(JInternalFrame frame) will not properly override the super- > * class, but instead overload it. > * > * Note be sure to call this method and not add() when you want to add to the > * desktop. This allows complex desktops to be created. For instance, you can > * add split panes and scroll panes and such as normal with the add() method > * but then to get to the actual desktop you would still call this method. > */ > public void addToDesktop(DrawingView dv, int location) { > JInternalFrame frame = (JInternalFrame)createContents(dv); 42,42d170 < public Component add(JInternalFrame frame) { 44,44c212,212 < Point p; --- > Point p = null; 47a216,216 > frame.addInternalFrameListener(internalFrameListener);//should be done before added to desktop 48a218,218 > 78,78d247 < return retval; 80a250,257 > public void removeFromDesktop(DrawingView dv, int location) { > Component[] comps = getComponents(); > for (int x=0; x if (dv == Helper.getDrawingView(comps[x])) { > ((JInternalFrame)comps[x]).dispose(); > break; > } > } 81,82d249 < public void remove(Component c) { < super.remove(c); 85a261,306 > public void removeAllFromDesktop(int location) { > JInternalFrame[] jifs = getAllFrames(); > for (int x=0; x < jifs.length; x++) { > jifs[x].dispose(); > } > } > > public DrawingView[] getAllFromDesktop(int location){ > Component[] comps = getComponents(); > java.util.ArrayList al = new java.util.ArrayList(); > for (int x=0; x DrawingView dv = Helper.getDrawingView(comps[x]); > if (dv != null) { > al.add(dv); > } > } > DrawingView[] dvs = new DrawingView[al.size()]; > al.toArray(dvs); > return dvs; > } > > public void setSelectedDrawingView(DrawingView dv) { > Component[] comps = getComponents(); > for (int x=0;x DrawingView dv2 = Helper.getDrawingView(comps[x]); > if (dv == dv2) { > JInternalFrame frame = (JInternalFrame) comps[x]; > try { > //moveToFront(frame); > frame.setSelected(true); > } > catch(java.beans.PropertyVetoException pve) { > System.out.println(pve); > } > } > } > } > > public void addDesktopListener(DesktopListener dpl){ > listenerList.add(DesktopListener.class, dpl); > } > > public void removeDesktopListener(DesktopListener dpl){ > listenerList.remove(DesktopListener.class, dpl); > } > 92,92c313,313 < JInternalFrame allFrames[] = getAllFrames(); --- > JInternalFrame[] allFrames = getAllFrames(); 130,130c351,351 < java.awt.Component allFrames[] = getAllFrames(); --- > Component[] allFrames = getAllFrames(); 157,157c378,378 < java.awt.Component allFrames[] = getAllFrames(); --- > Component[] allFrames = getAllFrames(); 188,188c409,409 < java.awt.Component allFrames[] = getAllFrames(); --- > Component[] allFrames = getAllFrames(); 196,198d416 < int horFrames; < int vertFrames; < 199,199c417,417 < vertFrames = (int)Math.floor(Math.sqrt(allFrames.length)); --- > int vertFrames = (int)Math.floor(Math.sqrt(allFrames.length)); 200,200c418,418 < horFrames = (int)Math.ceil(Math.sqrt(allFrames.length)); --- > int horFrames = (int)Math.ceil(Math.sqrt(allFrames.length)); 251,251c469,469 < java.awt.Component allFrames[] = getAllFrames(); --- > Component[] allFrames = getAllFrames(); 259,261d476 < int horFrames; < int vertFrames; < 262,262c477,477 < vertFrames = (int)Math.ceil(Math.sqrt(allFrames.length)); --- > int vertFrames = (int)Math.ceil(Math.sqrt(allFrames.length)); 263,263c478,478 < horFrames = (int)Math.floor(Math.sqrt(allFrames.length)); --- > int horFrames = (int)Math.floor(Math.sqrt(allFrames.length)); 292,292c507,507 < for (; frameIdx < allFrames.length; frameIdx++) --- > for (; frameIdx < allFrames.length; frameIdx++) { 293,293d507 < { 329a544,551 > > private void setDrawApplication(DrawApplication newDrawApplication) { > myDrawApplication = newDrawApplication; > } > > protected DrawApplication getDrawApplication() { > return myDrawApplication; > } 339,339c561,561 < public MDIDesktopManager(MDIDesktopPane desktop) { --- > public MDIDesktopManager(MDIDesktopPane newDesktop) { 340,340c562,562 < this.desktop = desktop; --- > this.desktop = newDesktop; 355,356d576 < int x = 0; < int y = 0;