001 // This file is part of AceWiki.
002 // Copyright 2008-2012, AceWiki developers.
003 //
004 // AceWiki is free software: you can redistribute it and/or modify it under the terms of the GNU
005 // Lesser General Public License as published by the Free Software Foundation, either version 3 of
006 // the License, or (at your option) any later version.
007 //
008 // AceWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
010 // Lesser General Public License for more details.
011 //
012 // You should have received a copy of the GNU Lesser General Public License along with AceWiki. If
013 // not, see http://www.gnu.org/licenses/.
014
015 package ch.uzh.ifi.attempto.acewiki.core;
016
017 import java.util.ArrayList;
018 import java.util.HashMap;
019 import java.util.List;
020 import java.util.Map;
021
022 /**
023 * This class controls the behavior and content of the predictive editor.
024 *
025 * @author Tobias Kuhn
026 */
027 public class EditorController {
028
029 private List<String> menuGroups = new ArrayList<String>();
030 private List<String> extensibleCategories = new ArrayList<String>();
031 private Map<String, String> wordTypesForCat = new HashMap<String, String>();
032 private Map<String, Integer> wordNumbersForCat = new HashMap<String, Integer>();
033 private Map<String, String> menuGroupsForCat = new HashMap<String, String>();
034 private Map<String, Integer> colorShifts = new HashMap<String, Integer>();
035 private String[] autocompleteTokens = new String[] {};
036 private String defaultMenuGroup = "word";
037
038 /**
039 * Adds a menu group. The order of the method-calls define the order in which the menu groups
040 * will appear in the editor. Color shifts can be set to give the menu groups different colors.
041 *
042 * @param menuGroup The name of the menu group to be added.
043 * @param colorShift The color shift.
044 */
045 public void addMenuGroup(String menuGroup, int colorShift) {
046 menuGroups.add(menuGroup);
047 colorShifts.put(menuGroup, colorShift);
048 }
049
050 /**
051 * Sets the menu group for all words that have no menu group assigned otherwise.
052 *
053 * @param defaultMenuGroup The name of the default menu group.
054 */
055 public void setDefaultMenuGroup(String defaultMenuGroup) {
056 this.defaultMenuGroup = defaultMenuGroup;
057 }
058
059 /**
060 * Returns all menu groups in the order they appear in the editor.
061 *
062 * @return All menu groups.
063 */
064 public List<String> getMenuGroups() {
065 return menuGroups;
066 }
067
068 /**
069 * Returns a list of all extensible categories.
070 *
071 * @return All extensible categories.
072 */
073 public List<String> getExtensibleCategories() {
074 return extensibleCategories;
075 }
076
077 /**
078 * Returns the color shift for the given menu group.
079 *
080 * @param menuBlockName The name of the menu group.
081 * @return The color shift.
082 */
083 public int getColorShift(String menuBlockName) {
084 if (colorShifts.containsKey(menuBlockName)) {
085 return colorShifts.get(menuBlockName);
086 } else {
087 return 0;
088 }
089 }
090
091 /**
092 * Adds a grammatical category that is extensible. Extensible means that users can define
093 * new words in this category.
094 *
095 * @param category The extensible category name.
096 * @param menuGroup The menu group for the category.
097 * @param type The type of the respective ontology elements.
098 * @param wordNumber The word number.
099 */
100 public void addExtensibleCategory(String category, String menuGroup, String type,
101 int wordNumber) {
102 extensibleCategories.add(category);
103 menuGroupsForCat.put(category, menuGroup);
104 wordTypesForCat.put(category, type);
105 wordNumbersForCat.put(category, wordNumber);
106 }
107
108 /**
109 * Adds a grammatical category that is not extensible.
110 *
111 * @param category The category name.
112 * @param menuGroup The menu group for the category.
113 */
114 public void addPlainCategory(String category, String menuGroup) {
115 menuGroupsForCat.put(category, menuGroup);
116 }
117
118 /**
119 * Returns the menu group for the given category.
120 *
121 * @param category The category name.
122 * @return The name of the menu group.
123 */
124 public String getMenuGroup(String category) {
125 String mg = menuGroupsForCat.get(category);
126 if (mg != null) {
127 return mg;
128 } else {
129 return defaultMenuGroup;
130 }
131 }
132
133 /**
134 * Returns the word type for the given extensible category, or null if the category is not
135 * extensible.
136 *
137 * @param category The category name.
138 * @return The word type.
139 */
140 public String getWordType(String category) {
141 return wordTypesForCat.get(category);
142 }
143
144 /**
145 * Returns the word number for the given extensible category, or null if the category is not
146 * extensible.
147 *
148 * @param category The category name.
149 * @return The word number.
150 */
151 public int getWordNumber(String category) {
152 return wordNumbersForCat.get(category);
153 }
154
155 /**
156 * Sets the tokens that normally form the end of a sentence and that should be used to
157 * automatically complete sentences. These tokens are usually punctuation symbols like a dot or
158 * a question mark.
159 *
160 * @param autocompleteTokens
161 */
162 public void setAutocompleteTokens(String... autocompleteTokens) {
163 this.autocompleteTokens = autocompleteTokens;
164 }
165
166 /**
167 * Returns the tokens used for autocompletion of sentences.
168 *
169 * @return The autocompletion tokens.
170 */
171 public String[] getAutocompleteTokens() {
172 return autocompleteTokens;
173 }
174
175 }