Search in sources :

Example 1 with Property

use of org.opt4j.core.config.Property in project opt4j by felixreimann.

the class PropertyPanel method fillComponentsMap.

protected void fillComponentsMap() {
    for (final Property property : module.getProperties()) {
        Component component = createComponent(property);
        components.put(property, component);
    }
}
Also used : Component(java.awt.Component) Property(org.opt4j.core.config.Property)

Example 2 with Property

use of org.opt4j.core.config.Property in project opt4j by felixreimann.

the class Opt4JModule method configure.

/*
	 * (non-Javadoc)
	 * 
	 * @see com.google.inject.AbstractModule#configure()
	 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void configure() {
    /**
     * Configure injected constants.
     */
    PropertyModule module = new PropertyModule(this);
    for (Property property : module.getProperties()) {
        for (Annotation annotation : property.getAnnotations()) {
            if (annotation.annotationType().getAnnotation(BindingAnnotation.class) != null) {
                Class<?> type = property.getType();
                Object value = property.getValue();
                ConstantBindingBuilder builder = bindConstant(annotation);
                if (type.equals(Integer.TYPE)) {
                    builder.to((Integer) value);
                } else if (type.equals(Long.TYPE)) {
                    builder.to((Long) value);
                } else if (type.equals(Double.TYPE)) {
                    builder.to((Double) value);
                } else if (type.equals(Float.TYPE)) {
                    builder.to((Float) value);
                } else if (type.equals(Byte.TYPE)) {
                    builder.to((Byte) value);
                } else if (type.equals(Short.TYPE)) {
                    builder.to((Short) value);
                } else if (type.equals(Boolean.TYPE)) {
                    builder.to((Boolean) value);
                } else if (type.equals(Character.TYPE)) {
                    builder.to((Character) value);
                } else if (type.equals(String.class)) {
                    builder.to((String) value);
                } else if (type.equals(Class.class)) {
                    builder.to((Class<?>) value);
                } else if (value instanceof Enum<?>) {
                    builder.to((Enum) value);
                } else {
                    String message = "Constant type not bindable: " + type + " of field " + property.getName() + " in module " + this.getClass().getName();
                    throw new ConfigurationException(Arrays.asList(new Message(message)));
                }
            }
        }
    }
    multi(OptimizerStateListener.class);
    multi(OptimizerIterationListener.class);
    multi(IndividualStateListener.class);
    config();
}
Also used : Message(com.google.inject.spi.Message) BindingAnnotation(com.google.inject.BindingAnnotation) Annotation(java.lang.annotation.Annotation) ConstantBindingBuilder(com.google.inject.binder.ConstantBindingBuilder) ConfigurationException(com.google.inject.ConfigurationException) BindingAnnotation(com.google.inject.BindingAnnotation) PropertyModule(org.opt4j.core.config.PropertyModule) Property(org.opt4j.core.config.Property)

Example 3 with Property

use of org.opt4j.core.config.Property in project opt4j by felixreimann.

the class PropertyPanel method updatePropertyPanel.

protected void updatePropertyPanel() {
    panel.removeAll();
    for (final Property property : module.getProperties()) {
        if (property.isActive()) {
            String name = property.getName();
            int i = getIndent(property);
            String s = "";
            for (int j = 0; j < i; j++) {
                s += "     ";
            }
            if (i > 0) {
                s = s.substring(2) + "\u21aa ";
            }
            JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
            JLabel label = new JLabel(s + name);
            label.setFocusable(false);
            String tooltip = format.getTooltip(property);
            if (tooltip != null) {
                label.setToolTipText(tooltip);
            }
            labelPanel.add(label);
            File file = property.getAnnotation(File.class);
            if (file != null) {
                JButton browse = new JButton(Icons.getIcon(Icons.FOLDER));
                browse.setFocusable(false);
                browse.setBorderPainted(false);
                browse.setContentAreaFilled(false);
                browse.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0));
                browse.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        selectFile(property);
                    }
                });
                browse.setCursor(new Cursor(Cursor.HAND_CURSOR));
                browse.setToolTipText("Browse ...");
                labelPanel.add(browse);
            }
            panel.add(labelPanel);
            Component component = components.get(property);
            panel.add(component);
        }
    }
    if (module.getModule().getClass().isAnnotationPresent(Citation.class)) {
        Citation citation = module.getModule().getClass().getAnnotation(Citation.class);
        addReferenceRow(citation);
    }
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Cursor(java.awt.Cursor) ActionListener(java.awt.event.ActionListener) Citation(org.opt4j.core.config.annotations.Citation) Component(java.awt.Component) Property(org.opt4j.core.config.Property) File(org.opt4j.core.config.annotations.File)

Aggregations

Property (org.opt4j.core.config.Property)3 Component (java.awt.Component)2 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 Cursor (java.awt.Cursor)1 FlowLayout (java.awt.FlowLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 Annotation (java.lang.annotation.Annotation)1 JButton (javax.swing.JButton)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 PropertyModule (org.opt4j.core.config.PropertyModule)1 Citation (org.opt4j.core.config.annotations.Citation)1 File (org.opt4j.core.config.annotations.File)1