Search in sources :

Example 1 with PropertyModule

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);
}
Also used : ModuleLoader(org.opt4j.core.config.ModuleLoader) PropertyModule(org.opt4j.core.config.PropertyModule) Module(com.google.inject.Module) PropertyModule(org.opt4j.core.config.PropertyModule)

Example 2 with PropertyModule

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());
        }
    }
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Point(java.awt.Point) PropertyModule(org.opt4j.core.config.PropertyModule) JMenuItem(javax.swing.JMenuItem)

Example 3 with PropertyModule

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);
    }
}
Also used : Multi(org.opt4j.core.config.annotations.Multi) PropertyModule(org.opt4j.core.config.PropertyModule) Module(com.google.inject.Module) PropertyModule(org.opt4j.core.config.PropertyModule)

Example 4 with PropertyModule

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();
}
Also used : HashMap(java.util.HashMap) PropertyModule(org.opt4j.core.config.PropertyModule) Module(com.google.inject.Module) PropertyModule(org.opt4j.core.config.PropertyModule) HashSet(java.util.HashSet)

Example 5 with PropertyModule

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);
    }
}
Also used : ArrayList(java.util.ArrayList) PropertyModule(org.opt4j.core.config.PropertyModule)

Aggregations

PropertyModule (org.opt4j.core.config.PropertyModule)7 Module (com.google.inject.Module)3 BindingAnnotation (com.google.inject.BindingAnnotation)1 ConfigurationException (com.google.inject.ConfigurationException)1 ConstantBindingBuilder (com.google.inject.binder.ConstantBindingBuilder)1 Message (com.google.inject.spi.Message)1 Point (java.awt.Point)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 JMenuItem (javax.swing.JMenuItem)1 ModuleLoader (org.opt4j.core.config.ModuleLoader)1 ModuleSaver (org.opt4j.core.config.ModuleSaver)1 Property (org.opt4j.core.config.Property)1 Multi (org.opt4j.core.config.annotations.Multi)1