1 package de.lathanda.eos.config;
3 import java.awt.event.ActionListener;
4 import java.util.Collection;
5 import java.util.LinkedList;
6 import java.util.ResourceBundle;
8 import java.util.TreeMap;
9 import java.util.TreeSet;
11 import javax.swing.JMenu;
12 import javax.swing.JMenuBar;
13 import javax.swing.JMenuItem;
14 import javax.swing.JOptionPane;
16 import de.lathanda.eos.base.util.GuiToolkit;
17 import de.lathanda.eos.baseparser.AutoCompleteEntry;
18 import de.lathanda.eos.baseparser.SystemFunctionType;
19 import de.lathanda.eos.baseparser.SystemMethodType;
20 import de.lathanda.eos.baseparser.SystemType;
21 import de.lathanda.eos.baseparser.Type;
22 import de.lathanda.eos.baseparser.UserType;
23 import de.lathanda.eos.config.Help.HelpPage;
24 import de.lathanda.eos.vm.MissingTypeException;
25 import de.lathanda.eos.vm.ReservedVariables;
30 private TreeMap<String, LanguageConfig> langs =
new TreeMap<>();
35 private final TreeSet<AutoCompleteEntry> templates =
new TreeSet<>();
39 private final TreeMap<String, String> labels =
new TreeMap<>();
43 private Help helpEntries;
57 return langs.values();
67 for (String key : res.keySet()) {
68 labels.put(key, res.getString(key));
73 return labels.containsKey(
id);
77 return labels.getOrDefault(
id,
id);
98 if (langs.containsKey(extid)) {
99 lc = langs.get(extid);
102 langs.put(lc.
getID(), lc);
108 TreeMap<String, JMenuItem> menues =
new TreeMap<>();
112 al = (lmi.action ==
null || lmi.action.isEmpty())?
null:(ActionListener)Class.forName(lmi.action).getDeclaredConstructor().newInstance();
113 if (lmi.pid !=
null && !lmi.pid.isEmpty()) {
115 menues.put(lmi.id, mi);
119 menues.put(lmi.id, mi);
121 }
catch (Exception e) {
122 JOptionPane.showMessageDialog(
null,
123 "class not found " + lmi.action,
124 "fatal error", JOptionPane.OK_OPTION);
129 if (lmi.pid !=
null && !lmi.pid.isEmpty()) {
130 menues.get(lmi.pid).add(menues.get(lmi.id));
139 public void registerProperty(String cls_id, String property_id, String type, String getter, String setter, String view) {
147 public void registerMethod(String cls_id, String method_id, String javamethod, LinkedList<String> parametertypes, String return_type) {
151 for(String paratype : parametertypes) {
156 lm.
ret = return_type;
161 lm.
cls = Class.forName(javaclass);
162 }
catch (ClassNotFoundException e) {
163 JOptionPane.showMessageDialog(
null,
164 "class not found " + javaclass,
165 "fatal error", JOptionPane.OK_OPTION);
169 public void registerGlobalFunction(String module_id, String function_id, String javamethod, LinkedList<String> parametertypes, String return_type) {
172 lf.
ret = return_type;
174 for(String paratype : parametertypes) {
195 }
catch (Exception e) {
196 JOptionPane.showMessageDialog(
null,
197 e.getLocalizedMessage() ,
198 "fatal error", JOptionPane.OK_OPTION);
207 private void initSystem() throws NoSuchMethodException,
MissingTypeException, ClassNotFoundException {
213 }
catch (ClassNotFoundException e) {
214 JOptionPane.showMessageDialog(
null,
215 "class not found " + lc.javaclass,
216 "fatal error", JOptionPane.OK_OPTION);
222 if (lc.pid !=
null && !lc.pid.isEmpty()) {
228 for(LangProperty lp:lc.properties.values()) {
229 if (lp.getter !=
null && !lp.getter.isEmpty()) {
231 lc.type.registerReadProperty(
232 new SystemMethodType(lp.id, lc.type,
new SystemType[] {}, SystemType.getInstanceByID(lp.type), lp.getter, lp.label),
236 lc.type.registerAssignProperty(
237 new SystemMethodType(lp.id, lc.type,
new SystemType[] {SystemType.getInstanceByID(lp.type)}, SystemType.getVoid(), lp.setter, lp.label),
242 lc.type.registerViewProperty(
250 for(LangMethod lm:lc.methods.values()) {
251 SystemType[] parameters =
new SystemType[lm.parameters.size()];
253 for(LangParameter lpa:lm.parameters) {
254 parameters[i++] = SystemType.getInstanceByID(lpa.type);
257 lc.type.registerMethod(
new SystemMethodType(lm.id, lc.type, parameters, SystemType.getInstanceByID(lm.ret), lm.javamethod, lm.label));
262 lm.cls = Class.forName(lm.javaclass);
263 for(LangFunction lf:lm.functions.values()) {
264 SystemType[] parameters =
new SystemType[lf.parameters.size()];
266 for(LangParameter lpa:lf.parameters) {
267 parameters[i++] = SystemType.getInstanceByID(lpa.type);
270 SystemFunctionType.registerSystemFunction(lm.cls, parameters, SystemType.getInstanceByID(lf.ret), lf.javamethod, lf.label);
static void registerSuper(String id, String superType)
static SystemType registerType(String id, String[] names, ObjectSource objSrc, Class<?> cls)
TreeMap< String, HelpPage > getHelpPages()
LangProperty getOrCreateProperty(String id)
LangMethod getOrCreateMethod(String attribute)
boolean isLockProperties()
void setLockProperties(boolean lockProperties)
LinkedList< LangParameter > parameters
LinkedList< LangParameter > parameters
LangFunction getOrCreateFunction(String idf)
Collection< LangMenuItem > getMenuItems()
LangClass getOrCreateLangClass(String id)
Collection< LangModule > getModules()
Collection< LangClass > getClasses()
LangClass getLangClass(String id)
LangModule getOrCreateLangModule(String id)
LanguageConfig mergeSystem(LanguageConfig lco)
String getLabel(String id)
boolean containsLabel(String id)
String getClassLabel(Type t)
Collection< HelpPage > getHelpData()
LangClass getLangClassByID(String id)
void apply(LanguageConfig lc)
void registerMethod(String cls_id, String method_id, String javamethod, LinkedList< String > parametertypes, String return_type)
void registerGlobalFunction(String module_id, String function_id, String javamethod, LinkedList< String > parametertypes, String return_type)
void registerLabels(ResourceBundle res)
LanguageConfig getOrCreateLanguageConfig(String extid)
void addPluginMenues(JMenuBar mainMenu)
Collection< LanguageConfig > getAvailableLanguageConfigs()
Set< AutoCompleteEntry > getTemplates()
void registerClass(String id, String pid, String javaclass)
String getClassLabelForID(String id)
void registerHelp(Help help)
String getDefaultWindowName()
void registerModule(String id, String javaclass)
void setLockProperties(boolean lockProperties)
void registerProperty(String cls_id, String property_id, String type, String getter, String setter, String view)
boolean isLockProperties()
ObjectSource getObjectSource(LangClass lc)