use of org.opt4j.core.config.PropertyModule in project opt4j by felixreimann.
the class FileOperations method load.
/**
* Loads the selected modules from the specified file.
*
* @param file
* the configuration file
*/
public void load(File file) {
setFile(file);
selectedModules.clear();
ModuleLoader loader = new ModuleLoader(moduleRegister);
Collection<? extends Module> modules = loader.load(file);
for (Module module : modules) {
PropertyModule m = new PropertyModule(module);
selectedModules.add(m);
}
System.out.println("Loaded configuration from " + file);
}
use of org.opt4j.core.config.PropertyModule in project opt4j by felixreimann.
the class DefaultModulesPanel method displayMenu.
/**
* Displays a popup menu for the tree elements.
*
* @param e
* the mouse event
*/
protected void displayMenu(MouseEvent e) {
if (e.isPopupTrigger()) {
Point pt = e.getPoint();
tree.setSelectionPath(tree.getPathForLocation(pt.x, pt.y));
Object object = tree.getLastSelectedPathComponent();
if (object instanceof ModuleTreeNode) {
ModuleTreeNode node = (ModuleTreeNode) object;
final PropertyModule module = node.getModule();
moduleMenu.removeAll();
JMenuItem add = new JMenuItem("Add Module", Icons.getIcon(Icons.ADD));
add.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
add(module);
}
});
JMenuItem remove = new JMenuItem("Remove Module", Icons.getIcon(Icons.DELETE));
remove.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
remove(module);
}
});
if (selectedModules.contains(module)) {
add.setEnabled(false);
} else {
remove.setEnabled(false);
}
moduleMenu.add(add);
moduleMenu.add(remove);
moduleMenu.show(e.getComponent(), e.getX(), e.getY());
}
}
}
use of org.opt4j.core.config.PropertyModule in project opt4j by felixreimann.
the class DefaultModulesPanel method add.
/**
* Adds a new {@link PropertyModule}.
*
* @param pm
* the property module to be added
*/
protected void add(PropertyModule pm) {
Module module = pm.getModule();
if (module.getClass().getAnnotation(Multi.class) != null) {
try {
Module m2 = module.getClass().newInstance();
PropertyModule pm2 = new PropertyModule(m2);
selectedModules.add(pm2);
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
}
} else {
selectedModules.add(pm);
}
}
use of org.opt4j.core.config.PropertyModule in project opt4j by felixreimann.
the class DefaultSelectedPanel method updateTabNames.
/**
* Update the tab names. Consider multiple tabs of the same module.
*/
protected void updateTabNames() {
Set<Class<? extends Module>> exist = new HashSet<Class<? extends Module>>();
Set<Class<? extends Module>> multi = new HashSet<Class<? extends Module>>();
for (PropertyModule pm : map.keySet()) {
Class<? extends Module> module = pm.getModule().getClass();
if (exist.contains(module)) {
multi.add(module);
} else {
exist.add(module);
}
}
Map<Class<? extends Module>, Integer> counter = new HashMap<Class<? extends Module>, Integer>();
for (Class<? extends Module> module : multi) {
counter.put(module, 1);
}
for (int i = 0; i < tabs.getTabCount(); i++) {
TabComponent comp = (TabComponent) tabs.getTabComponentAt(i);
Class<? extends Module> module = comp.getModule().getModule().getClass();
if (counter.containsKey(module)) {
int c = counter.get(module);
String name = "(" + c + ") " + format.getName(comp.getModule());
comp.setLabelName(name);
counter.put(module, c + 1);
}
}
tabs.repaint();
}
use of org.opt4j.core.config.PropertyModule in project opt4j by felixreimann.
the class SelectedModules method clear.
/*
* (non-Javadoc)
*
* @see java.util.HashSet#clear()
*/
@Override
public void clear() {
Collection<PropertyModule> modules = new ArrayList<PropertyModule>();
modules.addAll(this);
for (PropertyModule module : modules) {
remove(module);
}
}
Aggregations