Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/mandarax/eca/example/ActionMonitor.java


1   /*
2    * Copyright (C) 1998-2002 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   */
18  
19  package org.mandarax.eca.example;
20  
21  import java.awt.*;
22  import java.awt.event.ActionEvent;
23  
24  import javax.swing.*;
25  import org.mandarax.eca.*;
26  
27  /**
28   * Action implementation based on a swing panel.
29   * Performing the action means printing out information about the action in a text panel. 
30   * @author <A HREF="mailto:j.b.dietrich@massey.ac.nz">Jens Dietrich</A>
31   */
32  public class ActionMonitor extends JPanel {
33    
34    private Object target; 
35    private StringBuffer buf = new StringBuffer();
36    private javax.swing.Action actClear = null;
37    private javax.swing.Action actCopy = null;
38    private JTextArea txtArea = new JTextArea();
39    
40    /**
41     * Constructor.
42     */
43    public ActionMonitor() {
44      super();
45      initialize();
46    }
47    /**
48     * Set up the instance.
49     */
50    private void initialize() {
51  
52      setLayout(new BorderLayout(5, 5));
53      add(new JScrollPane(txtArea), BorderLayout.CENTER);
54      txtArea.setEditable(false);
55  
56      // initialize actions
57      actClear = new javax.swing.AbstractAction("clear") {
58        public void actionPerformed(ActionEvent e) {
59          buf = new StringBuffer();
60          txtArea.setText(buf.toString());
61        }
62      };
63      actCopy = new javax.swing.AbstractAction("copy") {
64        public void actionPerformed(ActionEvent e) {
65          txtArea.copy();
66        }
67      };    
68  
69      // toolbar
70      JToolBar toolbar = new JToolBar();
71      toolbar.setFloatable(false);
72      toolbar.add(actCopy);
73      toolbar.add(actClear);
74  
75      add(toolbar, BorderLayout.SOUTH);
76  
77  
78    }
79    /**
80       * Log an action.
81       * @param act an action
82       * @param parameters the action parameters
83       */
84      public void log(org.mandarax.eca.Action act,Object[] parameters) throws ActionException {
85        buf.append("Action performed: ");
86        buf.append(act);
87        if (parameters.length>0) {
88          buf.append(" ");
89          buf.append(parameters[0]);
90        }
91        buf.append("\n");
92        buf.append("\n");
93        txtArea.setText(buf.toString());
94      }
95  
96  }