View Javadoc

1   /*
2    * Copyright 2006-2016 The JGUIraffe Team.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License")
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.jguiraffe.examples.tutorial.createfile;
17  
18  import net.sf.jguiraffe.gui.forms.ComponentHandler;
19  
20  /**
21   * <p>
22   * A task for an action that appends a configurable text to a text component.
23   * </p>
24   * <p>
25   * This task class is used by actions of the create file dialog. It populates
26   * the text field for the file's content with predefined text fragments.
27   * </p>
28   *
29   * @author Oliver Heger
30   * @version $Id: AppendTextActionTask.java 205 2012-01-29 18:29:57Z oheger $
31   */
32  public class AppendTextActionTask implements Runnable
33  {
34      /** The handler for the text field. */
35      private final ComponentHandler<String> textHandler;
36  
37      /** The text to be appended. */
38      private final String text;
39  
40      /**
41       * Creates a new instance of {@code AppendTextActionTask} and initializes
42       * it.
43       *
44       * @param handler the handler to be updated
45       * @param txt the text to be appended
46       */
47      public AppendTextActionTask(ComponentHandler<String> handler, String txt)
48      {
49          textHandler = handler;
50          text = txt;
51      }
52  
53      /**
54       * Executes this task. This implementation obtains the current text of the
55       * managed text handler. Then it appends the text and writes it back.
56       */
57      @Override
58      public void run()
59      {
60          String currentText = textHandler.getData();
61          textHandler.setData(currentText + text);
62      }
63  }