File Source: DCCFrame.java

         /* 
    P/P   *  Method: com.dmdirc.addons.dcc.DCCFrame__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
     3   *
     4   * Permission is hereby granted, free of charge, to any person obtaining a copy
     5   * of this software and associated documentation files (the "Software"), to deal
     6   * in the Software without restriction, including without limitation the rights
     7   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     8   * copies of the Software, and to permit persons to whom the Software is
     9   * furnished to do so, subject to the following conditions:
    10   *
    11   * The above copyright notice and this permission notice shall be included in
    12   * all copies or substantial portions of the Software.
    13   *
    14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    20   * SOFTWARE.
    21   */
    22  
    23  package com.dmdirc.addons.dcc;
    24  
    25  import com.dmdirc.Main;
    26  import com.dmdirc.Server;
    27  import com.dmdirc.WritableFrameContainer;
    28  import com.dmdirc.addons.ui_swing.components.frames.InputTextFrame;
    29  import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
    30  import com.dmdirc.addons.ui_swing.SwingController;
    31  import com.dmdirc.addons.ui_swing.UIUtilities;
    32  import com.dmdirc.commandparser.PopupType;
    33  import com.dmdirc.commandparser.parsers.CommandParser;
    34  import com.dmdirc.commandparser.parsers.GlobalCommandParser;
    35  import com.dmdirc.config.IdentityManager;
    36  import com.dmdirc.ui.WindowManager;
    37  import com.dmdirc.ui.interfaces.InputWindow;
    38  
    39  import com.dmdirc.util.ReturnableThread;
    40  import java.awt.Container;
    41  
    42  import javax.swing.JPopupMenu;
    43  
    44  /**
    45   * This class links DCC objects to a window.
    46   *
    47   * @author Shane 'Dataforce' McCormack
    48   */
         /* 
    P/P   *  Method: Window getFrame()
          * 
          *  Preconditions:
          *    init'ed(this.myWindow)
          * 
          *  Postconditions:
          *    return_value == this.myWindow
          *    init'ed(return_value)
          */
    49  public abstract class DCCFrame extends WritableFrameContainer {
    50  	/**
    51  	 * Empty Frame.
    52  	 */
    53  	private class EmptyFrame extends InputTextFrame {
    54  			/** A version number for this class. */
    55  			private static final long serialVersionUID = 200711271;
    56  			
    57  			/**
    58  			 * Creates a new instance of EmptyFrame.
    59  			 *
    60  			 * @param owner The frame container that owns this frame
    61  			 */
        			 /* 
    P/P 			  *  Method: void com.dmdirc.addons.dcc.DCCFrame$EmptyFrame(DCCFrame, WritableFrameContainer)
        			  * 
        			  *  Preconditions:
        			  *    init'ed(com/dmdirc/Main.controller)
        			  */
    62  			public EmptyFrame(final WritableFrameContainer owner) {
    63  				super(owner, (SwingController) Main.getUI());
    64  				setTextPane(null);
    65  				pack();
    66  			}
    67  			
    68  			/**
    69  			 * Retrieves the command Parser for this input window.
    70  			 *
    71  			 * @return This window's command parser
    72  			 */
    73              @Override
    74  			public final CommandParser getCommandParser() {
        				 /* 
    P/P 				  *  Method: CommandParser getCommandParser()
        				  * 
        				  *  Postconditions:
        				  *    init'ed(return_value)
        				  */
    75  				return GlobalCommandParser.getGlobalCommandParser();
    76  			}
    77              
    78  			/** {@inheritDoc} */
    79  			@Override
    80  			public PopupType getNicknamePopupType() {
        				 /* 
    P/P 				  *  Method: PopupType getNicknamePopupType()
        				  * 
        				  *  Postconditions:
        				  *    return_value == null
        				  */
    81  				return null;
    82  			}
    83  
    84  			/** {@inheritDoc} */
    85  			@Override
    86  			public PopupType getChannelPopupType() {
        				 /* 
    P/P 				  *  Method: PopupType getChannelPopupType()
        				  * 
        				  *  Postconditions:
        				  *    return_value == null
        				  */
    87  				return null;
    88  			}
    89  
    90  			/** {@inheritDoc} */
    91  			@Override
    92  			public PopupType getHyperlinkPopupType() {
        				 /* 
    P/P 				  *  Method: PopupType getHyperlinkPopupType()
        				  * 
        				  *  Postconditions:
        				  *    return_value == null
        				  */
    93  				return null;
    94  			}
    95  			
    96  			/** {@inheritDoc} */
    97  			@Override
    98  			public PopupType getNormalPopupType() {
        				 /* 
    P/P 				  *  Method: PopupType getNormalPopupType()
        				  * 
        				  *  Postconditions:
        				  *    return_value == null
        				  */
    99  				return null;
   100  			}
   101  
   102  			/** {@inheritDoc} */
   103  			@Override
   104  			public void addCustomPopupItems(final JPopupMenu popupMenu) {
   105  				//Add no custom popup items
        			 /* 
    P/P 			  *  Method: void addCustomPopupItems(JPopupMenu)
        			  */
   106  			}
   107  	}
   108  
   109  	/** The window title. */
   110  	protected final String title;
   111  	/** The Window we're using. */
   112  	protected InputWindow myWindow = null;
   113  	/** The dcc plugin that owns this frame */
   114  	protected final DCCPlugin plugin;
   115  	/** The Window we're using. */
   116  	private boolean windowClosing = false;
   117  	
   118  	/**
   119  	 * Creates a new instance of DCCFrame with an empty window.
   120  	 *
   121  	 * @param plugin The DCCPlugin that owns this frame
   122  	 * @param title The title of this window
   123  	 * @param icon The icon to use
   124  	 */
   125  	public DCCFrame(final DCCPlugin plugin, final String title, final String icon) {
        		 /* 
    P/P 		  *  Method: void com.dmdirc.addons.dcc.DCCFrame(DCCPlugin, String, String)
        		  * 
        		  *  Presumptions:
        		  *    com.dmdirc.config.IdentityManager:getGlobalConfig(...)@138 != null
        		  *    init'ed(com/dmdirc/FrameContainer.java.awt.Color.BLACK)
        		  * 
        		  *  Postconditions:
        		  *    this.changer == &new FrameContainer$IconChanger(FrameContainer#2)
        		  *    this.config != null
        		  *    this.icon == icon
        		  *    init'ed(this.icon)
        		  *    this.listeners == &new ListenerList(FrameContainer#1)
        		  *    init'ed(this.myWindow)
        		  *    this.notification == com/dmdirc/FrameContainer.java.awt.Color.BLACK
        		  *    init'ed(this.notification)
        		  *    this.plugin == plugin
        		  *    init'ed(this.plugin)
        		  *    ...
        		  */
   126  		this(plugin, title, icon, true);
   127  	}
   128  	
   129  	/**
   130  	 * Creates a new instance of DCCFrame.
   131  	 *
   132  	 * @param plugin The DCCPlugin that owns this frame
   133  	 * @param title The title of this window
   134  	 * @param defaultWindow Create default (empty) window. (non-default = chat frame)
   135  	 * @param icon The icon to use
   136  	 */
   137  	public DCCFrame(final DCCPlugin plugin, final String title, final String icon ,final boolean defaultWindow) {
        		 /* 
    P/P 		  *  Method: void com.dmdirc.addons.dcc.DCCFrame(DCCPlugin, String, String, bool)
        		  * 
        		  *  Presumptions:
        		  *    com.dmdirc.config.IdentityManager:getGlobalConfig(...)@138 != null
        		  *    init'ed(com/dmdirc/FrameContainer.java.awt.Color.BLACK)
        		  * 
        		  *  Postconditions:
        		  *    this.changer == &new FrameContainer$IconChanger(FrameContainer#2)
        		  *    this.config != null
        		  *    this.icon == icon
        		  *    init'ed(this.icon)
        		  *    this.listeners == &new ListenerList(FrameContainer#1)
        		  *    init'ed(this.myWindow)
        		  *    this.notification == com/dmdirc/FrameContainer.java.awt.Color.BLACK
        		  *    init'ed(this.notification)
        		  *    this.plugin == plugin
        		  *    init'ed(this.plugin)
        		  *    ...
        		  * 
        		  *  Test Vectors:
        		  *    defaultWindow: {0}, {1}
        		  */
   138  		super(icon, IdentityManager.getGlobalConfig());
   139  		this.title = title;
   140  		this.plugin = plugin;
   141  
   142  		if (defaultWindow) {
                     /* 
    P/P               *  Method: void com.dmdirc.addons.dcc.DCCFrame$1(DCCFrame, String)
                      * 
                      *  Postconditions:
                      *    this.val$title == Param_2
                      *    init'ed(this.val$title)
                      */
   143              myWindow = UIUtilities.invokeAndWait(new ReturnableThread<EmptyFrame>() {
   144                  /** {@inheritDoc} */
   145                  @Override
   146                  public void run() {
                             /* 
    P/P                       *  Method: void run()
                              * 
                              *  Preconditions:
                              *    init'ed(com/dmdirc/Main.controller)
                              */
   147                      final EmptyFrame frame = new EmptyFrame(DCCFrame.this);
   148                      frame.setTitle(title);
   149                      setObject(frame);
   150                  }
   151              });
   152  		}
   153  	}
   154  	
   155  	/**
   156  	 * Sends a line of text to this container's source.
   157  	 *
   158  	 * @param line The line to be sent
   159  	 */
   160  	@Override
   161  	public void sendLine(final String line) {
   162  		
        	 /* 
    P/P 	  *  Method: void sendLine(String)
        	  */
   163  	}
   164  	
   165  	/**
   166  	 * Returns the maximum length that a line passed to sendLine() should be,
   167  	 * in order to prevent it being truncated or causing protocol violations.
   168  	 *
   169  	 * @return The maximum line length for this container
   170  	 */
   171  	@Override
   172  	public int getMaxLineLength() {
        		 /* 
    P/P 		  *  Method: int getMaxLineLength()
        		  * 
        		  *  Postconditions:
        		  *    return_value == 512
        		  */
   173  		return 512;
   174  	}
   175  	
   176  	/**
   177  	 * Returns the internal frame associated with this object.
   178  	 *
   179  	 * @return The internal frame associated with this object
   180  	 */
   181  	@Override
   182  	public InputWindow getFrame() {
        		 /* 
    P/P 		  *  Method: InputWindow getFrame()
        		  * 
        		  *  Preconditions:
        		  *    init'ed(this.myWindow)
        		  * 
        		  *  Postconditions:
        		  *    return_value == this.myWindow
        		  *    init'ed(return_value)
        		  */
   183  		return myWindow;
   184  	}
   185  	
   186  	/**
   187  	 * Returns the content pane of the internal frame associated with this object.
   188  	 *
   189  	 * @return The content pane of the internal frame associated with this object
   190  	 */
   191  	public Container getContentPane() {
        		 /* 
    P/P 		  *  Method: Container getContentPane()
        		  * 
        		  *  Preconditions:
        		  *    this.myWindow != null
        		  * 
        		  *  Postconditions:
        		  *    init'ed(return_value)
        		  */
   192  		return ((TextFrame)getFrame()).getContentPane();
   193  	}
   194  	
   195  	/**
   196  	 * Returns a string identifier for this object/its frame.
   197  	 *
   198  	 * @return String identifier
   199  	 */
   200  	@Override
   201  	public String toString() {
        		 /* 
    P/P 		  *  Method: String toString()
        		  * 
        		  *  Postconditions:
        		  *    return_value == this.title
        		  *    init'ed(return_value)
        		  */
   202  		return title;
   203  	}
   204  	
   205  	/**
   206  	 * Returns the server instance associated with this container.
   207  	 *
   208  	 * @return the associated server connection
   209  	 */
   210  	@Override
   211  	public Server getServer() {
        		 /* 
    P/P 		  *  Method: Server getServer()
        		  * 
        		  *  Postconditions:
        		  *    return_value == null
        		  */
   212  		return null;
   213  	}
   214  	
   215  	/**
   216  	 * Is the window closing?
   217  	 *
   218  	 * @return True if windowClosing has been called.
   219  	 */
   220  	public final boolean isWindowClosing() {
        		 /* 
    P/P 		  *  Method: bool isWindowClosing()
        		  * 
        		  *  Preconditions:
        		  *    init'ed(this.windowClosing)
        		  * 
        		  *  Postconditions:
        		  *    return_value == this.windowClosing
        		  *    init'ed(return_value)
        		  */
   221  		return windowClosing;
   222  	}
   223  	
   224  	/** {@inheritDoc} */
   225  	@Override
   226  	public void windowClosing() {
        		 /* 
    P/P 		  *  Method: void windowClosing()
        		  * 
        		  *  Preconditions:
        		  *    this.myWindow != null
        		  *    init'ed(this.plugin.container)
        		  *    this.plugin != null
        		  *    (soft) this.plugin.childFrames != null
        		  * 
        		  *  Postconditions:
        		  *    this.myWindow == null
        		  *    this.plugin.container == One-of{old this.plugin.container, null}
        		  *    init'ed(this.plugin.container)
        		  *    this.windowClosing == 1
        		  */
   227  		windowClosing = true;
   228  		
   229  		// 1: Make the window non-visible
   230  		myWindow.setVisible(false);
   231  		
   232  		// 2: Remove any callbacks or listeners
   233  		// 3: Trigger any actions neccessary
   234  		// 4: Trigger action for the window closing
   235  		
   236  		// 5: Inform any parents that the window is closing
   237  		plugin.delWindow(this);
   238  
   239  		// 6: Remove the window from the window manager
   240  		WindowManager.removeWindow(myWindow);
   241  
   242  		// 7: Remove any references to the window and parents
   243  		myWindow = null; // NOPMD
   244  	}   
   245  }








SofCheck Inspector Build Version : 2.17854
DCCFrame.java 2009-Jun-25 01:54:24
DCCFrame.class 2009-Sep-02 17:04:17
DCCFrame$1.class 2009-Sep-02 17:04:17
DCCFrame$EmptyFrame.class 2009-Sep-02 17:04:17