Back to index

wims  3.65+svn20090927
Static Public Member Functions | Static Package Functions | Static Package Attributes
rene.gui.Keyboard Class Reference

A static class, which contains tranlations for key events. More...

Collaboration diagram for rene.gui.Keyboard:
Collaboration graph
[legend]

List of all members.

Static Public Member Functions

static void makeKeys ()
 Read the keys from the Global names and parameters, and put into a vector and two hash tables for easy access.
static KeyboardItem findMenu (String menu)
 Find a menu string in the key definitions.
static String shortcut (String tag)
 Generate a shortcut for the menu item.
static String findKey (KeyEvent event, int type)
 See, if the key event matches any of my translations, and get the menu entry.
static String toCharKey (KeyEvent e, int type)
 Make a keychar string from the event.
static void edit (Frame f)
 Edit the translations.
static Vector getKeys ()
 Append a list of keyboard shortcuts to a text area.
static String commandShortcut (int type)
 Find a shortcut for the command.

Static Package Functions

 [static initializer]

Static Package Attributes

static Vector V
static Hashtable Hmenu
static Hashtable Hcharkey

Detailed Description

A static class, which contains tranlations for key events.

It keeps the translations in a vector of KeyboardItem.

The class will statically generate the list of translations from the default local properties and the JE configuration.

Definition at line 39 of file Keyboard.java.


Member Function Documentation

rene.gui.Keyboard.[static initializer] ( ) [inline, static, package]
static String rene.gui.Keyboard.commandShortcut ( int  type) [inline, static]

Find a shortcut for the command.

Definition at line 237 of file Keyboard.java.

       {      Object o=Hmenu.get("command."+type);
              if (o==null) return "";
              return ((KeyboardItem)o).shortcut();
       }

Here is the caller graph for this function:

static void rene.gui.Keyboard.edit ( Frame  f) [inline, static]

Edit the translations.

Definition at line 137 of file Keyboard.java.

       {      KeyboardItem keys[]=new KeyboardItem[V.size()];
              V.copyInto(keys);
              Sorter.sort(keys);
              Vector v=new Vector();
              for (int i=0; i<keys.length; i++) v.addElement(keys[i]);
              KeyboardPanel p=new KeyboardPanel();
              ItemEditor d=new ItemEditor(f,p,v,"keyeditor",
                     Global.name("keyeditor.prompt"),true,false,true,
                     Global.name("keyeditor.clearall"));
              p.setItemEditor(d);
              p.makeCommandChoice();
              d.center(f);
              d.setVisible(true);
              if (d.isAborted()) return;
              Global.removeAllParameters("key.");
              V=d.getElements();
              Enumeration e=V.elements();
              while (e.hasMoreElements())
              {      KeyboardItem k=(KeyboardItem)e.nextElement();
                     if (!k.getCharKey().equals("default"))
                     {      String keytag="key."+k.getMenuString();
                            String description=k.keyDescription();
                            if (!Global.name(keytag).toLowerCase().equals(description))
                            {      Global.setParameter(keytag,description);
                            }
                     }
              }
              makeKeys();
              if (d.getAction()==ItemEditor.SAVE)
              {      Properties parameters=new Properties();
                     e=Global.properties();
                     while (e.hasMoreElements())
                     {      String key=(String)e.nextElement();
                            if (key.startsWith("key."))
                                   parameters.put(key,Global.getParameter(key,"default"));
                     }
                     MyFileDialog save=new MyFileDialog(f,Global.name("save"),
                            Global.name("save"),true);
                     save.setPattern("*.keys");
                     save.center(f);
                     save.update();
                     save.setVisible(true);
                     if (save.isAborted()) return;
                     String filename=save.getFilePath();
                     if (filename.equals("")) return; // aborted dialog!
                     try
                     {      FileOutputStream o=new FileOutputStream(filename);
                            parameters.save(o,"JE Keyboard Definition");
                     }
                     catch (Exception ex) {}
              }
              else if (d.getAction()==ItemEditor.LOAD)
              {      Properties parameters=new Properties();
                     MyFileDialog load=new MyFileDialog(f,Global.name("load"),
                            Global.name("load"),true);
                     load.setPattern("*.keys");
                     load.center(f);
                     load.update();
                     load.setVisible(true);
                     if (load.isAborted()) return;
                     String filename=load.getFilePath();
                     if (filename.equals("")) return; // aborted dialog!
                     try
                     {      FileInputStream in=new FileInputStream(filename);
                            parameters.load(in);
                     }
                     catch (Exception ex) {}
                     Global.removeAllParameters("key.");
                     e=parameters.keys();
                     while (e.hasMoreElements())
                     {      String key=(String)e.nextElement();
                            Global.setParameter(key,(String)parameters.get(key));
                     }
                     makeKeys();
              }
       }

Here is the call graph for this function:

static String rene.gui.Keyboard.findKey ( KeyEvent  event,
int  type 
) [inline, static]

See, if the key event matches any of my translations, and get the menu entry.

Definition at line 114 of file Keyboard.java.

       {      Object o=Hcharkey.get(toCharKey(event,type));
              if (o==null) return "";
              String s=((KeyboardItem)o).getMenuString();
              while (s.endsWith("*")) s=s.substring(0,s.length()-1);
              return s;
       }

Here is the call graph for this function:

Here is the caller graph for this function:

static KeyboardItem rene.gui.Keyboard.findMenu ( String  menu) [inline, static]

Find a menu string in the key definitions.

Definition at line 88 of file Keyboard.java.

       {      Object o=Hmenu.get(menu);
              if (o==null) return null;
              else return (KeyboardItem)o;
       }

Here is the caller graph for this function:

static Vector rene.gui.Keyboard.getKeys ( ) [inline, static]

Append a list of keyboard shortcuts to a text area.

Definition at line 218 of file Keyboard.java.

       {      Vector keys=new Vector();
              Sorter.sort(V);
              Enumeration e=V.elements();
              while (e.hasMoreElements())
              {      KeyboardItem k=(KeyboardItem)e.nextElement();
                     if (!k.getCharKey().equals("none"))
                     {      String shortcut=k.shortcut();
                            int n=shortcut.length();
                            for (int i=0; i<30-n; i++) shortcut=shortcut+" ";
                            keys.addElement(shortcut+" = "+k.getActionName());
                     }
              }
              return keys;
       }

Here is the call graph for this function:

static void rene.gui.Keyboard.makeKeys ( ) [inline, static]

Read the keys from the Global names and parameters, and put into a vector and two hash tables for easy access.

Definition at line 51 of file Keyboard.java.

       {      V=new Vector();
              Hmenu=new Hashtable(); Hcharkey=new Hashtable();
              // collect all predefined keys
              Enumeration e=Global.names();
              if (e==null) return;
              while (e.hasMoreElements())
              {      String key=(String)e.nextElement();
                     if (key.startsWith("key."))
                     {      String menu=key.substring(4);
                            String charkey=Global.getParameter(key,"default");
                            String normalcharkey=Global.name(key);
                            if (charkey.equals("default")) charkey=normalcharkey;
                            KeyboardItem k=new KeyboardItem(menu,charkey);
                            V.addElement(k);
                            Hmenu.put(menu,k); Hcharkey.put(charkey,k);
                     }
              }
              // collect all user defined (double defined) keys
              e=Global.properties();
              while (e.hasMoreElements())
              {      String key=(String)e.nextElement();
                     if (key.startsWith("key."))
                     {      String menu=key.substring(4);
                            if (findMenu(menu)!=null) continue;
                            String charkey=Global.getParameter(key,"default");
                            if (charkey.equals("default")) continue;
                            KeyboardItem k=new KeyboardItem(menu,charkey);
                            V.addElement(k);
                            Hmenu.put(menu,k); Hcharkey.put(charkey,k);
                     }
              }
       }

Here is the call graph for this function:

Here is the caller graph for this function:

static String rene.gui.Keyboard.shortcut ( String  tag) [inline, static]

Generate a shortcut for the menu item.

Definition at line 97 of file Keyboard.java.

       {      Enumeration e=V.elements();
              while (e.hasMoreElements())
              {      KeyboardItem item=(KeyboardItem)e.nextElement();
                     if (item.getMenuString().equals(tag))
                     {      String shortcut=item.shortcut();
                            if (!shortcut.equals("")) shortcut=" ("+shortcut+")";
                            return shortcut;
                     }
              }
              return "";
       }

Here is the call graph for this function:

Here is the caller graph for this function:

static String rene.gui.Keyboard.toCharKey ( KeyEvent  e,
int  type 
) [inline, static]

Make a keychar string from the event.

Definition at line 125 of file Keyboard.java.

       {      String s="";
              if (type>0) s=s+"esc"+type+".";
              if (e.isShiftDown()) s=s+"shift.";
              if (e.isControlDown()) s=s+"control.";
              if (e.isAltDown()) s=s+"alt.";
              return s+KeyDictionary.translate(e.getKeyCode()).toLowerCase();
       }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Hashtable rene.gui.Keyboard.Hcharkey [static, package]

Definition at line 41 of file Keyboard.java.

Hashtable rene.gui.Keyboard.Hmenu [static, package]

Definition at line 41 of file Keyboard.java.

Vector rene.gui.Keyboard.V [static, package]

Definition at line 40 of file Keyboard.java.


The documentation for this class was generated from the following file: