View Javadoc

1   /*
2    * Copyright 2007 Markku Saarela 
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, 
11   * software distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. 
14   * See the License for the specific language governing permissions and limitations under the License. 
15   */
16  package net.sourceforge.jivalo.editor.key;
17  
18  
19  /**
20   * @author <a href="mailto:ivalo@iki.fi">Markku Saarela</a>
21   *
22   */
23  public final class KeyAction
24  {
25  
26      /**
27       * Name of key action.
28       * @see javax.swing.text.DefaultEditorKit
29       */
30      private String name;
31      
32      /**
33       * Value of key action.
34       * @see javax.swing.text.DefaultEditorKit
35       */
36      private String action;
37      
38      /**
39       * Styled name of action.
40       */
41      private String actionName;
42  
43      /**
44       * @param name javax.swing.text.DefaultEditorKit static field name
45       * @param action javax.swing.text.DefaultEditorKit static field value
46       */
47      public KeyAction( String name, Object action )
48      {
49          super();
50          this.name = name;
51          this.action = action.toString();
52          
53          char[] cs = action.toString().replaceAll( "_", " " ).trim().toCharArray();
54  
55          StringBuffer sb = new StringBuffer();
56          
57          for ( int i = 0; i < cs.length; i++ )
58          {
59              if ( ( i == 0 )
60                      || ( i > 0 && cs[i - 1] == ' ' ) )
61              {
62                  sb.append( Character.toUpperCase( cs[i] ) );
63              }
64              else
65              {
66                  sb.append( cs[i] );
67              }
68          }
69      }
70  
71      /**
72       * @return the action
73       */
74      public String getAction()
75      {
76          return this.action;
77      }
78  
79      /**
80       * @return the actionName
81       */
82      public String getActionName()
83      {
84          return this.actionName;
85      }
86  
87      /**
88       * @return the name
89       */
90      public String getName()
91      {
92          return this.name;
93      }
94          
95  }