KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdic > filetypes > Action


1 /*
2  * Copyright (C) 2004 Sun Microsystems, Inc. All rights reserved. Use is
3  * subject to license terms.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the Lesser GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  */

20
21 package org.jdesktop.jdic.filetypes;
22
23
24 /**
25  * This class represents an action that could be applied to a particular file type.
26  * An action could be added to an <code>Association</code> object as part of an
27  * association.
28  * <p>
29  * An <code>Action</code> object is a triple containing a description string,
30  * a verb string and a command string. Common examples of verb are "open", "edit",
31  * and "print". The command string consists of the executable file path followed
32  * by command line parameters.
33  *
34  * @see Association
35  */

36 public class Action {
37   
38     /**
39      * Description of this action.
40      * <P>
41      * This field is not required to create a valid Action object.
42      * It's used only on Windows, and on Gnome for Linux and Solaris, this field
43      * is not used.
44      */

45     private String JavaDoc description;
46   
47     /**
48      * Name of the verb field.
49      */

50     private String JavaDoc verb;
51   
52     /**
53      * Command field associated with the given verb.
54      */

55     private String JavaDoc command;
56     
57     /**
58      * Hash code for this action
59      */

60     private int hashcode = 0;
61   
62     /**
63      * Constructor of an <code>Action</code> object.
64      * <p>
65      * On Microsoft Windows platforms, the verb could be "open", "edit", or any given
66      * name; on Gnome/UNIX platforms, it could only be "open", other verbs will
67      * be ignored.
68      *
69      * @param verb a given verb string.
70      * @param command a given command string.
71      */

72     public Action(String JavaDoc verb, String JavaDoc command) {
73         this.verb = verb;
74         this.command = command;
75     }
76
77     /**
78      * Constructor of an <code>Action</code> object.
79      *
80      * @param verb a given verb value.
81      * @param command a given command value.
82      * @param desc a given description value.
83      */

84     public Action(String JavaDoc verb, String JavaDoc command, String JavaDoc desc) {
85         this.verb = verb;
86         this.command = command;
87         this.description = desc;
88     }
89   
90     /**
91      * Returns the value of the description field.
92      *
93      * @return the value of the description field.
94      */

95     public String JavaDoc getDescription() {
96         return description;
97     }
98   
99     /**
100      * Sets the description field.
101      * <P>
102      * This field is optional for a valid action, and only used for Microsoft
103      * Windows platforms.
104      *
105      * @param description a given description value.
106      */

107     public void setDescription(String JavaDoc description) {
108         this.description = description;
109     }
110   
111     /**
112      * Returns the value of the verb field.
113      *
114      * @return the value of the verb field.
115      */

116     public String JavaDoc getVerb() {
117         return verb;
118     }
119   
120     /**
121      * Sets the verb field.
122      *
123      * @param verb a given verb value.
124      */

125     public void setVerb(String JavaDoc verb) {
126         this.verb = verb;
127     }
128   
129     /**
130      * Returns the value of the command field.
131      *
132      * @return the value of the command field.
133      */

134     public String JavaDoc getCommand() {
135         return command;
136     }
137   
138     /**
139      * Sets the command field.
140      *
141      * @param command a given command value.
142      */

143     public void setCommand(String JavaDoc command) {
144         this.command = command;
145     }
146   
147     /**
148      * Overrides the same method of <code>java.lang.Object</code>.
149      * <p>
150      * Determines whether or not two actions are equal. Two instances
151      * of <code>Action</code> are equal if the values of all the fields
152      * are the same.
153      *
154      * @param otherObj an object to be compared with this <code>Action</code>
155      * @return <code>true</code> if the object to be compared is an instance of
156      * <code>Action</code> and has the same values;
157      * <code>false</code> otherwise.
158      */

159     public boolean equals(Object JavaDoc otherObj) {
160         if (otherObj instanceof Action) {
161             Action otherAction = (Action) otherObj;
162             String JavaDoc otherDescription = otherAction.getDescription();
163             String JavaDoc otherVerb = otherAction.getVerb();
164             String JavaDoc otherCommand = otherAction.getCommand();
165
166             if ((description == null
167                             ? otherDescription == null
168                             : description.equals(otherDescription))
169                     && (verb == null
170                             ? otherVerb == null
171                             : verb.equals(otherVerb))
172                     && (command == null
173                             ? otherCommand == null
174                             : command.equals(otherCommand))) {
175                 return true;
176             }
177         }
178         return false;
179     }
180     
181     /**
182      * Overrides the same method of <code>java.lang.Object</code>.
183      * <p>
184      * Returns the hashcode for this <code>Action</code>.
185      *
186      * @return a hash code for this <code>Action<code>.
187      */

188     public int hashCode() {
189         if (hashcode != 0) {
190             int result = 17;
191             if (this.description != null) {
192                 result = 37 * result + this.description.hashCode();
193             }
194             if (this.verb != null) {
195                 result = 37 * result + this.verb.hashCode();
196             }
197             if (this.command != null) {
198                 result = 37 * result + this.command.hashCode();
199             }
200             hashcode = result;
201         }
202         return hashcode;
203     }
204   
205     /**
206      * Overrides the same method of <code>java.lang.Object</code>.
207      * <p>
208      * Returns a <code>String</code> that represents the value of this
209      * <code>Action</code>.
210      *
211      * @return a string representation of this <code>Action</code>.
212      */

213     public String JavaDoc toString() {
214         String JavaDoc crlfString = "\r\n";
215         String JavaDoc content = "";
216         String JavaDoc tabString = "\t";
217     
218         content = content.concat(tabString);
219         content = content.concat("Description: ");
220         if (this.description != null) {
221             content = content.concat(description);
222         }
223         content = content.concat(crlfString);
224             
225         content = content.concat(tabString);
226         content = content.concat("Verb: ");
227         if (this.verb != null) {
228             content = content.concat(verb);
229         }
230         content = content.concat(crlfString);
231
232         content = content.concat(tabString);
233         content = content.concat("Command: ");
234         if (this.command != null) {
235             content = content.concat(command);
236         }
237         content = content.concat(crlfString);
238     
239         return content;
240     }
241 }
242
Popular Tags