KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > awt > viewer > Command


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: Command.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop.render.awt.viewer;
21
22 //Java
23
import java.awt.event.ActionEvent JavaDoc;
24 import javax.swing.AbstractAction JavaDoc;
25 import javax.swing.ImageIcon JavaDoc;
26 import java.net.URL JavaDoc;
27
28 /**
29  * This class represents UI-commands, which can be used as menu or toolbar
30  * items<br>.
31  * When the <code>Command</code> object receives action event, that object's
32  * <code>doit</code> method is invoked. <code>doit</code> method by default
33  * does nothing and the class customer have to override it to implement
34  * any action handling logic.
35  * Originally contributed by:
36  * Juergen Verwohlt: Juergen.Verwohlt@jcatalog.com,
37  * Rainer Steinkuhle: Rainer.Steinkuhle@jcatalog.com,
38  * Stanislav Gorkhover: Stanislav.Gorkhover@jcatalog.com
39  */

40 public class Command extends AbstractAction JavaDoc {
41
42     private static final String JavaDoc IMAGE_DIR = "images/";
43
44     /**
45      * Creates <code>Command</code> object with a given name and
46      * sets the name as a tooltip text. No associated icon image.
47      * @param name of the command
48      * @param mnemonic A Key
49      */

50     public Command(String JavaDoc name, int mnemonic) {
51         super(name);
52         putValue(SHORT_DESCRIPTION, name);
53         if (mnemonic > 0) {
54             putValue(MNEMONIC_KEY, new Integer JavaDoc(mnemonic));
55         }
56     }
57
58     /**
59      * Creates <code>Command</code> object with a given name, the same
60      * tooltip text and icon image if appropriate image file is found.
61      * @param name name of the command
62      * @param iconName name of the icon
63      */

64     public Command(String JavaDoc name, String JavaDoc iconName) {
65         super(name);
66         putValue(SHORT_DESCRIPTION, name);
67         URL JavaDoc url = getClass().getResource(IMAGE_DIR + iconName + ".gif");
68         if (url != null) {
69             putValue(SMALL_ICON, new ImageIcon JavaDoc(url));
70         }
71     }
72
73     /**
74      * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
75      */

76     public void actionPerformed(ActionEvent JavaDoc e) {
77         doit();
78     }
79
80     /**
81      * Action handler, have to be overrided by subclasses.
82      */

83     public void doit() {
84         //Do nothing
85
}
86 }
87
88
Popular Tags