17,17c17,17 < import CH.ifa.draw.figures.*; --- > import CH.ifa.draw.contrib.dnd.DragNDropTool; 17a18,18 > 18,18d17 < import CH.ifa.draw.util.*; 20,22d19 < import javax.swing.event.*; < import java.awt.*; < import java.util.*; 31,31c28,28 < * @author Wolfram Kaiser --- > * @author Wolfram Kaiser 33a31,31 > public class MDI_DrawApplication extends DrawApplication { 34,50d30 < public class MDI_DrawApplication extends DrawApplication implements InternalFrameListener { < < /** < * Internal frame, which is currently activated. This frame receives all < * mouse input and displays the Drawing to be manipulated. < */ < private MDI_InternalFrame currentFrame; < < /** < * This component acts as a desktop for the content. < */ < private JComponent desktop; < < /** < * List of listeners which adhere to the InternalFrameListener interface < */ < private Vector mdiListeners; 64,67d44 < setDesktop(new MDIDesktopPane()); < getDesktop().setAlignmentX(JComponent.LEFT_ALIGNMENT); < mdiListeners = new Vector(); < addInternalFrameListener(this); 93a71,71 > * Opens a new internal frame containing a new drawing. 94,147d70 < * Creates the contents component of the application < * frame. By default the DrawingView is returned in < * a JScrollPane. < */ < protected JComponent createContents(DrawingView view) { < if (view.isInteractive()) { < MDI_InternalFrame internalFrame = createInternalFrame(view); < JComponent contents = super.createContents(view); < internalFrame.getContentPane().add(contents); < getDesktop().add(internalFrame); < internalFrame.setVisible(true); < try { < internalFrame.setSelected(true); < } < catch (java.beans.PropertyVetoException e) { < // ignore < } < } < // return container in which the internal frame is embedded < return getDesktop(); < < } < < /** < * Factory method which creates an internal frame. Subclasses may override this < * method to provide their own implementations of MDI_InternalFrame < */ < protected MDI_InternalFrame createInternalFrame(DrawingView view) { < String applicationTitle = null; < if ((view == null) || (view.drawing() == null) || (view.drawing().getTitle() == null)) { < applicationTitle = getApplicationName() + " - " + getDefaultDrawingTitle(); < } < else { < applicationTitle = getApplicationName() + " - " + view.drawing().getTitle(); < } < MDI_InternalFrame internalFrame = new MDI_InternalFrame(applicationTitle, true, true, true, true); < internalFrame.setDrawingView(view); < internalFrame.setSize(200, 200); < < // all registered listeners to the new internal frame < Enumeration enum = mdiListeners.elements(); < while (enum.hasMoreElements()) { < internalFrame.addInternalFrameListener((InternalFrameListener)enum.nextElement()); < } < < fireViewCreatedEvent(view); // frame now has connection all the way to heavyweight component < < // return container in which the internal frame is embedded < return internalFrame; < } < < /** < * Resets the drawing to a new empty drawing. If no internal frame < * exists then open a new internal frame. 150,153d73 < if (hasInternalFrames()) { < super.promptNew(); < } < else { 156,156d75 < } 163,163c82,82 < DrawingView newView = createDrawingView(); --- > DrawingView newView = createDrawingView(newDrawing); 163a83,83 > getDesktop().addToDesktop(newView, Desktop.PRIMARY); 164,165d82 < newView.setDrawing(newDrawing); < createContents(newView); 179a98,98 > getDesktop().addToDesktop(newView, Desktop.PRIMARY); 180,180d97 < createContents(newView); 182,182c100,100 < setDrawingTitle(copyTitle + " (View)"); --- > setDrawingTitle(copyTitle); 185,185c103,103 < setDrawingTitle( getDefaultDrawingTitle() + " (View)"); --- > setDrawingTitle(getDefaultDrawingTitle()); 189a108,109 > protected Desktop createDesktop() { > return new MDIDesktopPane(this); 190,335d107 < /** < * Set the component, in which the content is embedded. This component < * acts as a desktop for the content. < */ < protected void setDesktop(JComponent newDesktop) { < desktop = newDesktop; < } < < /** < * Get the component, in which the content is embedded. This component < * acts as a desktop for the content. < */ < public JComponent getDesktop() { < return desktop; < } < < /** < * Add a new listener to the applications internal frames. If a new internal < * frame is created, all currently registered InternalFrameListeners are < * added as listeners to that internal frame as well. < * < * @param newMDIListener listener to be added < */ < public void addInternalFrameListener(InternalFrameListener newMDIListener) { < mdiListeners.addElement(newMDIListener); < } < < /** < * Remove a InternalFrameListeners from the application. < * < * @param oldMDIListener listener to be removed < */ < public void removeInternalFrameListener(InternalFrameListener oldMDIListener) { < mdiListeners.removeElement(oldMDIListener); < } < < /** < * Activate an internal frame upon which the selected tools operate. < * The currently activated DrawgingView is backed up for later restorage. < */ < public void activateFrame(MDI_InternalFrame newFrame) { < if (currentFrame != newFrame) { < // check, whether drawing has been already initialised < if (newFrame.getDrawingView().drawing() != null) { < newFrame.getDrawingView().unfreezeView(); < } < if (currentFrame != null ) { < currentFrame.getDrawingView().freezeView(); < } < currentFrame = newFrame; < } < setView( currentFrame.getDrawingView() ); < } < < /** < * If the frame we are deactivating is the current frame, set the < * currentFrame to null < */ < public void deactivateFrame(MDI_InternalFrame frame) { < if (frame != null) { < frame.getDrawingView().clearSelection(); < } < if (currentFrame == frame ) { < currentFrame = null; < } < } < < /** < * Notification method from InternalFrameListener, which is called < * if a internal frame gets selected. < */ < public void internalFrameActivated(InternalFrameEvent e) { < activateFrame((MDI_InternalFrame)e.getSource()); < } < < /** < * Notification method from InternalFrameListener, which is called < * if a internal frame is opend. < */ < public void internalFrameOpened(InternalFrameEvent e) { < } < < /** < * Notification method from InternalFrameListener, which is called < * before a internal frame is closed. < */ < public void internalFrameClosing(InternalFrameEvent e) { < MDI_InternalFrame mdf = (MDI_InternalFrame)e.getSource(); < DrawingView dv = mdf.getDrawingView(); < fireViewDestroyingEvent( dv ); < if( mdf == currentFrame) { < currentFrame = null; < setView(NullDrawingView.getManagedDrawingView(this)); < } < } < < /** < * Notification method from InternalFrameListener, which is called < * if a internal frame is closed. < */ < public void internalFrameClosed(InternalFrameEvent e) { < } < < /** < * Notification method from InternalFrameListener, which is called < * if a internal frame gets iconified. < */ < public void internalFrameIconified(InternalFrameEvent e) { < } < < /** < * Notification method from InternalFrameListener, which is called < * if a internal frame gets deiconified. < */ < public void internalFrameDeiconified(InternalFrameEvent e) { < //activateFrame((MDI_InternalFrame)e.getSource()); < } < < /** < * Notification method from InternalFrameListener, which is called < * if a internal frame gets deactivated. < */ < public void internalFrameDeactivated(InternalFrameEvent e) { < deactivateFrame((MDI_InternalFrame)e.getSource()); < } < < /** < * Set the title for the drawing. The title also appears in the < * internal frame title bar. A name is assigned when a drawing < * saved or a saved drawing is loaded. The file name is the < * drawing title. If the drawing has not been saved before then < * the drawing title is "untitled". < */ < protected void setDrawingTitle(String newDrawingTitle) { < currentFrame.setTitle( getApplicationName() + " - " + newDrawingTitle ); < } < < /** < * Get the title for the drawing. < */ < protected String getDrawingTitle() { < return currentFrame.getDrawing().getTitle(); < } < < public boolean hasInternalFrames() { < return ((JDesktopPane)getDesktop()).getAllFrames().length > 0; 341a116,116 > return getDesktop().getAllFromDesktop(Desktop.PRIMARY); 342,357d115 < DrawingView[] views; < ArrayList frames = new ArrayList(); < < JInternalFrame[] ifs = ((JDesktopPane)getDesktop()).getAllFrames(); < for(int x=0; x < ifs.length ; x++) { < if( MDI_InternalFrame.class.isInstance( ifs[x] ) ) { < DrawingView dv = ((MDI_InternalFrame)ifs[x]).getDrawingView(); < if( DrawingView.class.isInstance( dv ) ) { < frames.add( dv ); < } < } < } < views = new DrawingView[ frames.size() ]; < frames.toArray( views ); < < return views;