Search in sources :

Example 6 with IconPersistent

use of com.ramussoft.core.attribute.simple.IconPersistent in project ramus by Vitaliy-Yakovchuk.

the class IconFactory method getDefaultIcons.

@SuppressWarnings("unchecked")
private static Hashtable<Long, ImageIcon> getDefaultIcons(Engine engine, String key, Attribute attribute) {
    Hashtable<Long, ImageIcon> result = (Hashtable<Long, ImageIcon>) engine.getPluginProperty("Core", key);
    if (result == null) {
        result = new Hashtable<Long, ImageIcon>();
        Qualifier qualifier = StandardAttributesPlugin.getIconsQualifier(engine);
        List<Attribute> attributes = new ArrayList<Attribute>(2);
        Attribute iconsAttribute = StandardAttributesPlugin.getIconsAttribute(engine);
        attributes.add(iconsAttribute);
        attributes.add(attribute);
        Hashtable<Element, Object[]> res = engine.getElements(qualifier, attributes);
        Enumeration<Element> keys = res.keys();
        while (keys.hasMoreElements()) {
            Element element = keys.nextElement();
            Object[] objects = res.get(element);
            if ((objects[0] != null) && (((IconPersistent) objects[0]).getIcon() != null) && (objects[1] != null)) {
                StringTokenizer st = new StringTokenizer((String) objects[1]);
                ImageIcon icon = new ImageIcon(((IconPersistent) objects[0]).getIcon());
                while (st.hasMoreElements()) {
                    result.put(Long.parseLong(st.nextToken()), icon);
                }
            }
        }
        engine.setPluginProperty("Core", key, result);
    }
    return result;
}
Also used : ImageIcon(javax.swing.ImageIcon) IconPersistent(com.ramussoft.core.attribute.simple.IconPersistent) Attribute(com.ramussoft.common.Attribute) Hashtable(java.util.Hashtable) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) StringTokenizer(java.util.StringTokenizer) Qualifier(com.ramussoft.common.Qualifier)

Example 7 with IconPersistent

use of com.ramussoft.core.attribute.simple.IconPersistent in project ramus by Vitaliy-Yakovchuk.

the class QualifierPreferencesPanel method ok.

public boolean ok() {
    if (box.getSelectedItem() == null) {
        JOptionPane.showMessageDialog(this, GlobalResourcesManager.getString("Error.SetAttributeForName"));
        return false;
    }
    String[] errors = new String[] {};
    for (QualifierSetupEditor editor : editors) {
        String[] add = editor.getErrors();
        int start = errors.length;
        errors = Arrays.copyOf(errors, errors.length + add.length);
        for (int i = start; i < errors.length; i++) {
            errors[i] = add[i - start];
        }
    }
    if (errors.length > 0) {
        StringBuffer sb = new StringBuffer();
        sb.append("<html><body>");
        for (String error : errors) {
            sb.append(error);
            sb.append("<br>");
        }
        sb.append("</body></html>");
        JOptionPane.showMessageDialog(this, sb.toString());
        return false;
    }
    if (engine instanceof Journaled) {
        ((Journaled) engine).startUserTransaction();
    }
    engine.setAttribute(element, attribute, attributeEditor.getValue());
    long id = (Long) engine.getAttribute(element, (Attribute) engine.getPluginProperty("Core", StandardAttributesPlugin.QUALIFIER_ID));
    Qualifier qualifier = engine.getQualifier(id);
    updateAttributesInOrder(attributeOrderEditPanel.getAttributes());
    qualifier.setAttributes(attributeOrderEditPanel.getAttributes());
    if (box.getSelectedItem() == null) {
        qualifier.setAttributeForName(-1l);
    } else {
        Attribute attributeId = (Attribute) engine.getPluginProperty("Core", StandardAttributesPlugin.ATTRIBUTE_ID);
        Long id2 = (Long) engine.getAttribute((Element) box.getSelectedItem(), attributeId);
        Attribute a = engine.getAttribute(id2);
        qualifier.setAttributeForName(a.getId());
    }
    engine.updateQualifier(qualifier);
    IconPersistent selectedValue = open.getSelectedValue();
    if (selectedValue != null)
        IconFactory.setOpenIcon(engine, selectedValue, qualifier);
    selectedValue = leaf.getSelectedValue();
    if (selectedValue != null)
        IconFactory.setLeafIcon(engine, selectedValue, qualifier);
    selectedValue = closed.getSelectedValue();
    if (selectedValue != null)
        IconFactory.setClosedIcon(engine, selectedValue, qualifier);
    for (QualifierSetupEditor editor : editors) {
        editor.save(engine, qualifier);
    }
    if (engine instanceof Journaled) {
        ((Journaled) engine).commitUserTransaction();
    }
    return true;
}
Also used : Journaled(com.ramussoft.common.journal.Journaled) IconPersistent(com.ramussoft.core.attribute.simple.IconPersistent) Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) Qualifier(com.ramussoft.common.Qualifier) QualifierSetupEditor(com.ramussoft.gui.common.QualifierSetupEditor)

Aggregations

IconPersistent (com.ramussoft.core.attribute.simple.IconPersistent)7 Attribute (com.ramussoft.common.Attribute)5 Element (com.ramussoft.common.Element)5 Qualifier (com.ramussoft.common.Qualifier)5 ArrayList (java.util.ArrayList)4 ImageIcon (javax.swing.ImageIcon)4 Hashtable (java.util.Hashtable)2 Journaled (com.ramussoft.common.journal.Journaled)1 QualifierSetupEditor (com.ramussoft.gui.common.QualifierSetupEditor)1 File (java.io.File)1 InputStream (java.io.InputStream)1 StringTokenizer (java.util.StringTokenizer)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1