Search in sources :

Example 1 with Citation

use of org.opt4j.core.config.annotations.Citation in project opt4j by felixreimann.

the class Format method getTooltip.

/**
 * Returns the formatted (html) tooltip of a {@link Property}.
 *
 * @param property
 *            the property
 * @return the tooltip
 */
public String getTooltip(Property property) {
    String text = "<html><b>" + getName(property) + "</b>";
    String info = property.getInfo();
    if (info != null) {
        text += xmlBreak + info;
    }
    if (property.getType().isEnum()) {
        Class<?> type = property.getType();
        text += xmlBreak;
        Field[] fields = type.getDeclaredFields();
        for (Field field : fields) {
            if (field.isEnumConstant()) {
                String name = field.getName();
                Icon icon = field.getAnnotation(Icon.class);
                Info i = field.getAnnotation(Info.class);
                text += "&nbsp;" + name;
                if (icon != null || i != null) {
                    text += " - ";
                }
                if (icon != null) {
                    text += "<img src=\"" + Icons.getURL(icon.value()) + "\">";
                    System.out.println(text + " " + icon.value());
                }
                if (i != null) {
                    text += i.value();
                }
                Citation c = field.getAnnotation(Citation.class);
                if (c != null)
                    text += "&nbsp;&nbsp;<span style='color: gray;'>[" + formatIEEE(c) + "]</span>";
                text += xmlBreak;
            }
        }
    }
    text += "</html>";
    return text;
}
Also used : Field(java.lang.reflect.Field) Icon(org.opt4j.core.config.annotations.Icon) ImageIcon(javax.swing.ImageIcon) Citation(org.opt4j.core.config.annotations.Citation) Info(org.opt4j.core.config.annotations.Info)

Example 2 with Citation

use of org.opt4j.core.config.annotations.Citation in project opt4j by felixreimann.

the class Format method getTooltip.

/**
 * Returns the tooltip of a {@link Class}.
 *
 * @param c
 *            the class
 * @return the tooltip
 */
public String getTooltip(Class<?> c) {
    String name = getName(c);
    String info = getInfo(c);
    String text = "<html><b>" + name + "</b>";
    if (info != null) {
        text += xmlBreak + info;
    }
    Citation citation = c.getAnnotation(Citation.class);
    if (citation != null)
        text += xmlBreak + xmlBreak + "<span style='color: gray;'>[" + formatIEEE(citation) + "]</span>";
    text += "</html>";
    return text;
}
Also used : Citation(org.opt4j.core.config.annotations.Citation)

Example 3 with Citation

use of org.opt4j.core.config.annotations.Citation 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

Citation (org.opt4j.core.config.annotations.Citation)3 Component (java.awt.Component)1 Cursor (java.awt.Cursor)1 FlowLayout (java.awt.FlowLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 Field (java.lang.reflect.Field)1 ImageIcon (javax.swing.ImageIcon)1 JButton (javax.swing.JButton)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 Property (org.opt4j.core.config.Property)1 File (org.opt4j.core.config.annotations.File)1 Icon (org.opt4j.core.config.annotations.Icon)1 Info (org.opt4j.core.config.annotations.Info)1