ch.uzh.ifi.attempto.preditor
Class MenuCreator

java.lang.Object
  extended by ch.uzh.ifi.attempto.preditor.MenuCreator
Direct Known Subclasses:
ExampleMenuCreator, SimpleMenuCreator

public abstract class MenuCreator
extends java.lang.Object

This abstract class is used for the predictive editor to create menus on the basis of categories of the grammar.

Author:
Tobias Kuhn

Constructor Summary
MenuCreator()
          Initializes a new menu creator object.
 
Method Summary
 void addMenuEntry(java.lang.String menuBlockName, TextElement textElement)
          Adds a new menu entry containing the text element to the menu block.
 void addMenuEntry(java.lang.String menuBlockName, TextElement textElement, Category restriction)
          Adds a new menu entry containing the text element to the menu block.
 void addMenuItem(java.lang.String menuBlockName, MenuItem menuItem)
          Adds the menu item to the given menu block.
 void addReferenceEntries(java.lang.String menuBlockName, java.lang.String categoryName)
          This method looks for referenceable text elements earlier in the token list, given the category of the next token.
 void addVariableEntries(java.lang.String menuBlockName, int num, java.lang.String categoryName)
          This method adds text elements that contain variables (in the form of "X", "Y", "Z", "X1", "Y1", "Z1", "X2", and so on) to the menu block.
 java.util.List<TextElement> getAccessibleTextElements(java.lang.String nextToken)
          This method returns all text elements that are accessible for the given next token.
abstract  void initMenuCreation()
          This abstract method is called when the predictive editor is refreshed (before the first call of processCategory).
 void prepareMenuBlock(java.lang.String menuBlockName)
          Prepares a new menu block (if there is no such menu block already with the same name).
 void prepareMenuBlock(java.lang.String menuBlockName, boolean doSort)
          Prepares a new menu block (if there is no such menu block already with the same name).
protected abstract  void processCategory(Terminal category)
          An implementation of this abstract method should process the category by calling addMenuItem and/or addMenuEntry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MenuCreator

public MenuCreator()
Initializes a new menu creator object.

Method Detail

processCategory

protected abstract void processCategory(Terminal category)
An implementation of this abstract method should process the category by calling addMenuItem and/or addMenuEntry.

Parameters:
category - The category of the grammar to be processed.

initMenuCreation

public abstract void initMenuCreation()
This abstract method is called when the predictive editor is refreshed (before the first call of processCategory). This is a good place for calling prepareMenuBlock.


prepareMenuBlock

public void prepareMenuBlock(java.lang.String menuBlockName)
Prepares a new menu block (if there is no such menu block already with the same name). The menu blocks are shown in the predictive editor in the same order as they have been prepared.

Parameters:
menuBlockName - The name of the menu block.

prepareMenuBlock

public void prepareMenuBlock(java.lang.String menuBlockName,
                             boolean doSort)
Prepares a new menu block (if there is no such menu block already with the same name). The second parameter defines whether the items of the menu block should be sorted. The menu blocks are shown in the predictive editor in the same order as they have been prepared.

Parameters:
menuBlockName - The name of the menu block.
doSort - true if the items should be sorted.

addMenuItem

public void addMenuItem(java.lang.String menuBlockName,
                        MenuItem menuItem)
Adds the menu item to the given menu block. If no menu block of this name has been prepared at this point then the preparation is done first.

Parameters:
menuBlockName - The name of the menu block.
menuItem - The menu item to be added to the menu block.

addMenuEntry

public void addMenuEntry(java.lang.String menuBlockName,
                         TextElement textElement)
Adds a new menu entry containing the text element to the menu block. If no menu block of this name has been prepared at this point then the preparation is done first.

Parameters:
menuBlockName - The name of the menu block.
textElement - The text element of the menu entry that is created and then added to the menu block.

addMenuEntry

public void addMenuEntry(java.lang.String menuBlockName,
                         TextElement textElement,
                         Category restriction)
Adds a new menu entry containing the text element to the menu block. If no menu block of this name has been prepared at this point then the preparation is done first. The menu entry is only added if the category of the text element is subsumed by the restriction category.

Parameters:
menuBlockName - The name of the menu block.
textElement - The text element of the menu entry that is created and then added to the menu block.
restriction - The restriction category.

addReferenceEntries

public void addReferenceEntries(java.lang.String menuBlockName,
                                java.lang.String categoryName)
This method looks for referenceable text elements earlier in the token list, given the category of the next token. For each of those text elements, a new reference text element is created and added to the menu block.

Parameters:
menuBlockName - The name of the menu block.
categoryName - The category name for which the previous tokens should be checked for referenceability.
See Also:
getAccessibleTextElements(String), RefableTextElement, RefTextElement

addVariableEntries

public void addVariableEntries(java.lang.String menuBlockName,
                               int num,
                               java.lang.String categoryName)
This method adds text elements that contain variables (in the form of "X", "Y", "Z", "X1", "Y1", "Z1", "X2", and so on) to the menu block.

Parameters:
menuBlockName - The name of the menu block.
num - Variables are created up to this number.
categoryName - The category name of the variable tokens.
See Also:
VarTextElement

getAccessibleTextElements

public java.util.List<TextElement> getAccessibleTextElements(java.lang.String nextToken)
This method returns all text elements that are accessible for the given next token.

Parameters:
nextToken - The next token.
Returns:
A list of all accessible text elements.


Copyright 2008-2009, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch)