guk.editIM
Class FileCommands

java.lang.Object
  |
  +--guk.editIM.FileCommands
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener

public class FileCommands
extends java.lang.Object
implements java.awt.event.ActionListener

Helper for the EditIM Input Method Editor: Responsible for reading, writing and merging files into / from the editor tables. It can pop up confirmation dialogues, but things like selection of file names and file types are done by another component. Knows the MapTable objects to communicate with. When needed, fileCommandProcessor throws an ActionEvent to the assigned listener (given as constructor argument). Receives commands by being an ActionListener through actionPerformed, which is triggered after postEvent on us.


Field Summary
(package private)  java.lang.String headers
          All headers that are recognized as such: Lines beginning with option in the case of GIM.
(package private)  java.lang.String inComments
          All comments after the first parseable assignment that do not belong to an assignment themselves.
(package private)  java.lang.String localeName
          The locale name and variant, taken from the inputmethod header of GIM.
(package private)  java.lang.String localeNameVariant
           
(package private)  MenuHelpers menu
          The MenuHelpers class provides functions like creating menu items and buttons.
(package private)  java.lang.String preComments
          All comments in the header area.
(package private)  MapTable tableLong
           
(package private)  MapTable tableShort
          two tables, one for at most one key sequence for each glyph and one where we can produce several glyphs by one key sequence or assign several key sequences to the same glyphs.
 
Constructor Summary
FileCommands(MenuHelpers menuHelper, MapTable glyphTable, MapTable stringTable)
          The constructor initializes important variables, mostly from passed arguments.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           This is an ActionListener, so it must handle actionPerformed.
 boolean loadFile(java.lang.String encoding, int filetype, java.lang.String filename, boolean merge)
          Load or merge a file into the tables.
static java.lang.String nameAOType(int type)
          Describes an AssignObject data type.
 boolean saveFile(java.lang.String encoding, int filetype, java.lang.String filename)
          Save the tables into a file.
 void showLog(java.lang.String title, java.lang.String text, boolean okay)
          Shows a probably long log text in a popup window with a given title.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

menu

MenuHelpers menu
The MenuHelpers class provides functions like creating menu items and buttons. Initially, no action listener is set.

tableShort

MapTable tableShort
two tables, one for at most one key sequence for each glyph and one where we can produce several glyphs by one key sequence or assign several key sequences to the same glyphs.

tableLong

MapTable tableLong

localeName

java.lang.String localeName
The locale name and variant, taken from the inputmethod header of GIM.

localeNameVariant

java.lang.String localeNameVariant

headers

java.lang.String headers
All headers that are recognized as such: Lines beginning with option in the case of GIM. No other formats have real headers. Yudit has a format variant marked by a special line (the additive format which ":multiplies out" several sub-keymaps), but the Input Method Editor does not handle that one anyway.

preComments

java.lang.String preComments
All comments in the header area. Everything up to the first parseable assignment. Useful for all formats that allow comments or unparseable lines.

inComments

java.lang.String inComments
All comments after the first parseable assignment that do not belong to an assignment themselves. An alternative would be to Add standalone comments to the next or previous assignment rather than keeping them in one big inComments String.
Constructor Detail

FileCommands

public FileCommands(MenuHelpers menuHelper,
                    MapTable glyphTable,
                    MapTable stringTable)
The constructor initializes important variables, mostly from passed arguments. the constructor needs an ActionListener where all results will be sent to, and an Unicode capable font. In addition, it needs a Component relative to which popups will be places, and two MapTable objects that allow storing and editing of keymap data!
Parameters:
menuHelper -  
glyphTable - A MapTable object which is first tried as data source or destination. Half of the editor window.
stringTable - Elements which do not fit glyphTable are put into this stringTable. When we export to a file, first the glyphTable and then the stringTable elements are written, unless some kind of reordering overrides this (may happen for some export file formats).
Method Detail

showLog

public void showLog(java.lang.String title,
                    java.lang.String text,
                    boolean okay)
Shows a probably long log text in a popup window with a given title.
Parameters:
title - The title of the window
text - The content of the window.
okay - If false, the icon will be that of a warning instead of that of an information.

nameAOType

public static java.lang.String nameAOType(int type)
Describes an AssignObject data type.
Parameters:
type - An AssignObject type constant.
Returns:
A short name for the selected type.

loadFile

public boolean loadFile(java.lang.String encoding,
                        int filetype,
                        java.lang.String filename,
                        boolean merge)
Load or merge a file into the tables.
Parameters:
encoding - The encoding, typically ISO-8859-1 or UTF-8 (both are implemented on all Java platforms).
filetype - The file type code as used by the AssignObject parsing system.
filename - The name of the file to be loaded / merged.
merge - True for merge mode, false for load mode. Load will flush the tables before importing a file.
Returns:
False if a really fatal error occurred (true if only warnings occurred or if everything went right).

saveFile

public boolean saveFile(java.lang.String encoding,
                        int filetype,
                        java.lang.String filename)
Save the tables into a file.
Parameters:
encoding - The encoding, typically ISO-8859-1 or UTF-8 (both are implemented on all Java platforms).
filetype - The file type code as used by the AssignObject parsing system.
filename - The name of the file to be loaded / merged.
Returns:
False if a really fatal error occurred (true if only warnings occurred or if everything went right).

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)

This is an ActionListener, so it must handle actionPerformed. All requests are coming in through this method. Each type of request should be handled by calling one or more of the private methods of this class. This is the common parser for all. Some of the methods above throw events back at myListener, in turn.

 Accepted commands:
 loadlocalefile encoding filetype filename - load for editing!
    ... similar to: ...
 mergelocalefile encoding filetype filename - ADD to edited!
 savelocalefile encoding filetype filename - create file.
    headers, footers and comments should be preserved from most
    recently loaded / merged file if possible!
 

Specified by:
actionPerformed in interface java.awt.event.ActionListener