View Javadoc

1   /*
2    * Copyright 2006 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  import java.util.HashMap;
19  import java.util.Iterator;
20  import java.util.Map;
21  
22  /**
23   * @author <a href="mailto:ivalo@iki.fi">Markku Saarela</a>
24   *
25   */
26  public class KeyBindings
27  {
28  
29      private Map keyBindings;
30      
31      /**
32       * @param keyBindingFile
33       */
34      public KeyBindings( String keyBindings )
35      {
36          super();
37          
38          this.keyBindings = new HashMap();
39          
40          String[] strings = keyBindings.split( "," );
41          
42          for ( int i = 0; i < strings.length; i++ )
43          {
44              String[] binding = strings[i].trim().split( "=" );
45              
46              this.keyBindings.put( binding[0]
47                      , new CustomKeyBinding( binding[0], binding[1] ) );
48              
49          }
50          
51      }
52      
53      public CustomKeyBinding getKeyBinding( String name )
54      {
55          return ( CustomKeyBinding ) this.keyBindings.get( name );
56      }
57      
58      public String toString()
59      {
60  
61          StringBuffer sb = new StringBuffer();
62          
63          for ( Iterator iter = 
64              this.keyBindings.entrySet().iterator()
65              ; iter.hasNext(); )
66          {
67              Map.Entry element = ( Map.Entry ) iter.next();
68              
69              sb.append( element.getKey() );
70              sb.append( "=" );
71              sb.append( element.getValue() );
72              if ( iter.hasNext() )
73              {
74                  sb.append( "," );
75              }
76          }
77          
78          return sb.toString();
79      }
80  }