1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sourceforge.jivalo.editor.key;
17
18 import java.lang.reflect.Field;
19 import java.lang.reflect.Modifier;
20 import java.util.ArrayList;
21 import java.util.HashMap;
22 import java.util.Iterator;
23 import java.util.List;
24
25 import javax.swing.text.DefaultEditorKit;
26
27 /**
28 * @author <a href="mailto:ivalo@iki.fi">Markku Saarela</a>
29 *
30 */
31 public class DefaultEditorKitActionFactory
32 {
33
34 private static final HashMap ACTIONS;
35
36 private static List VALUES;
37
38 static
39 {
40 ACTIONS = new HashMap();
41
42 Field[] fields = DefaultEditorKit.class.getFields();
43
44 for ( int i = 0; i < fields.length; i++ )
45 {
46 Field field = fields[i];
47
48 if ( field.getName().toLowerCase().endsWith( "action" ))
49 {
50 try
51 {
52
53 if ( Modifier.isPublic( field.getModifiers() )
54 && Modifier.isStatic( field.getModifiers() )
55 && Modifier.isFinal( field.getModifiers() ) )
56 {
57 ACTIONS.put( field.getName()
58 , new KeyAction( field.getName(),
59 field.get( DefaultEditorKit.class ) ) );
60 }
61 }
62 catch ( Exception e )
63 {
64
65 e.printStackTrace();
66 }
67 }
68
69 }
70 }
71
72 private DefaultEditorKitActionFactory()
73 {
74 super();
75 }
76
77 public static KeyAction getAction( String actionName )
78 {
79
80 return ( KeyAction ) ACTIONS.get( actionName );
81 }
82
83 public static synchronized List getActions()
84 {
85
86 if ( VALUES == null )
87 {
88 VALUES = new ArrayList();
89
90 for ( Iterator iter = ACTIONS.values().iterator(); iter.hasNext(); )
91 {
92 VALUES.add( ( KeyAction ) iter.next() );
93 }
94
95 }
96
97 return VALUES;
98 }
99 }