View Javadoc

1   /***
2    * Redistribution  and use  in source  and binary  forms, with  or without
3    * modification, are permitted provided  that the following conditions are
4    * met :
5    *
6    * . Redistributions  of  source  code  must  retain  the  above copyright
7    *   notice, this list of conditions and the following disclaimer.
8    *
9    * . Redistributions in  binary form  must reproduce  the above  copyright
10   *   notice, this list of conditions  and the following disclaimer in  the
11   *   documentation and/or other materials provided with the distribution.
12   *
13   * . The name of the author may not be used to endorse or promote products
14   *   derived from this software without specific prior written permission.
15   *
16   * THIS SOFTWARE IS  PROVIDED BY THE  AUTHOR ``AS IS''  AND ANY EXPRESS  OR
17   * IMPLIED  WARRANTIES,  INCLUDING,  BUT   NOT  LIMITED  TO,  THE   IMPLIED
18   * WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE ARE
19   * DISCLAIMED.  IN NO  EVENT SHALL  THE AUTHOR  BE LIABLE  FOR ANY  DIRECT,
20   * INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL  DAMAGES
21   * (INCLUDING,  BUT  NOT LIMITED  TO,  PROCUREMENT OF  SUBSTITUTE  GOODS OR
22   * SERVICES;  LOSS  OF USE,  DATA,  OR PROFITS;  OR  BUSINESS INTERRUPTION)
23   * HOWEVER CAUSED  AND ON  ANY THEORY  OF LIABILITY,  WHETHER IN  CONTRACT,
24   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25   * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE, EVEN  IF  ADVISED OF  THE
26   * POSSIBILITY OF SUCH DAMAGE.
27   *
28   * $Id$
29   */
30  
31  package palmed.edit.selection;
32  
33  import java.io.IOException;
34  import java.io.InputStream;
35  import palmed.util.ChainedException;
36  
37  /***
38   * This class implements an action to paste text replacing the current selection.
39   *
40   * @author Mathieu Champlon
41   * @version $Revision$ $Date$
42   */
43  public final class Paste extends AbstractAction
44  {
45      /***
46       * The selection.
47       */
48      private final ISelection selection_;
49      /***
50       * The stream.
51       */
52      private final InputStream stream_;
53  
54      /***
55       * Create a paste action.
56       *
57       * @param selection the selection
58       * @param stream the stream
59       */
60      public Paste( final ISelection selection, final InputStream stream )
61      {
62          super( selection );
63          selection_ = selection;
64          stream_ = stream;
65      }
66  
67      /***
68       * {@inheritDoc}
69       */
70      protected void onPerform()
71      {
72          backupData();
73          try
74          {
75              selection_.paste( stream_ );
76          }
77          catch( IOException e )
78          {
79              throw new ChainedException( e ); // FIXME custom exception
80          }
81      }
82  
83      /***
84       * {@inheritDoc}
85       */
86      protected boolean onUndo()
87      {
88          restoreData();
89          return true;
90      }
91  
92      /***
93       * {@inheritDoc}
94       */
95      protected boolean onRedo()
96      {
97          try
98          {
99              stream_.reset(); // FIXME hmm
100             selection_.paste( stream_ );
101             return true;
102         }
103         catch( IOException e )
104         {
105             throw new ChainedException( e ); // FIXME custom exception
106         }
107     }
108 
109     /***
110      * {@inheritDoc}
111      */
112     public boolean merge( final IAction action )
113     {
114         return false;
115     }
116 }