Search in sources :

Example 1 with IconPersistent

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

the class IconPreviewPanel method loadZip.

private void loadZip(ZipFile file) throws IOException {
    Enumeration<? extends ZipEntry> e = file.entries();
    while (e.hasMoreElements()) {
        ZipEntry entry = e.nextElement();
        if ((!entry.isDirectory()) && (isImage(entry.getName().toLowerCase()))) {
            InputStream is = file.getInputStream(entry);
            byte[] bs = new byte[is.available()];
            is.read(bs);
            IconPersistent persistent = new IconPersistent();
            persistent.setIcon(bs);
            persistent.setName(entry.getName());
            data.add(persistent);
            is.close();
        }
    }
    file.close();
}
Also used : IconPersistent(com.ramussoft.core.attribute.simple.IconPersistent) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry)

Example 2 with IconPersistent

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

the class IconPreviewPanel method loadImages.

private void loadImages() throws IOException {
    if (data == null) {
        data = new ArrayList<IconPersistent>();
        for (File file : dir.listFiles()) if ((file.isFile()) && (file.getName().toLowerCase().endsWith(".zip"))) {
            loadZip(new ZipFile(file));
        }
        Collections.sort(data);
        IconPersistent e = new IconPersistent();
        data.add(0, e);
        e.setName(GlobalResourcesManager.getString("EmptyIcon"));
        images = new ImageIcon[data.size()];
    }
    lData = data;
    lImages = images;
}
Also used : IconPersistent(com.ramussoft.core.attribute.simple.IconPersistent) ZipFile(java.util.zip.ZipFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 3 with IconPersistent

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

the class IconFactory method updateIcons.

private static void updateIcons(Engine engine, IconPersistent p, Qualifier qualifier, Hashtable<Long, ImageIcon> icons, Attribute attribute) {
    if (p == null)
        p = new IconPersistent();
    if (p.getIcon() == null)
        icons.remove(qualifier.getId());
    else
        icons.put(qualifier.getId(), new ImageIcon(p.getIcon()));
    long index = getIconIndex(engine, p);
    Element element = engine.getElement(index);
    Qualifier q = StandardAttributesPlugin.getIconsQualifier(engine);
    List<Attribute> attrs = new ArrayList<Attribute>(1);
    attrs.add(attribute);
    Hashtable<Element, Object[]> res = engine.getElements(q, attrs);
    Enumeration<Element> keys = res.keys();
    long id = qualifier.getId();
    while (keys.hasMoreElements()) {
        Element e = keys.nextElement();
        String c = (String) res.get(e)[0];
        if (c == null) {
            c = "";
        }
        String c1 = removeId(c, id);
        if (!c1.equals(c)) {
            engine.setAttribute(e, attribute, c1);
        }
    }
    if (element != null) {
        String c = (String) engine.getAttribute(element, attribute);
        if (p.getIcon() != null) {
            c = addId(c, qualifier.getId());
            engine.setAttribute(element, attribute, c);
        }
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) IconPersistent(com.ramussoft.core.attribute.simple.IconPersistent) Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) Qualifier(com.ramussoft.common.Qualifier)

Example 4 with IconPersistent

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

the class IconFactory method getIconIndex.

private static long getIconIndex(Engine engine, IconPersistent p) {
    if ((p == null) || (p.getIcon() == null))
        return -1l;
    Qualifier qualifier = StandardAttributesPlugin.getIconsQualifier(engine);
    List<Attribute> attributes = new ArrayList<Attribute>(1);
    Attribute iconsAttribute = StandardAttributesPlugin.getIconsAttribute(engine);
    attributes.add(iconsAttribute);
    Hashtable<Element, Object[]> res = engine.getElements(qualifier, attributes);
    Enumeration<Element> e = res.keys();
    long index = -1l;
    while (e.hasMoreElements()) {
        Element element = e.nextElement();
        IconPersistent ip = (IconPersistent) res.get(element)[0];
        if (ip.getName().equals(p.getName())) {
            index = element.getId();
            break;
        }
    }
    if (index < 0l) {
        Element element = engine.createElement(qualifier.getId());
        engine.setAttribute(element, iconsAttribute, p);
        index = element.getId();
        getIcons(engine).put(index, new ImageIcon(p.getIcon()));
    }
    return index;
}
Also used : ImageIcon(javax.swing.ImageIcon) IconPersistent(com.ramussoft.core.attribute.simple.IconPersistent) Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) Qualifier(com.ramussoft.common.Qualifier)

Example 5 with IconPersistent

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

the class IconFactory method getIcons.

@SuppressWarnings("unchecked")
public static Hashtable<Long, ImageIcon> getIcons(Engine engine) {
    synchronized (engine) {
        Hashtable<Long, ImageIcon> res = (Hashtable<Long, ImageIcon>) engine.getPluginProperty("Core", "Icons buffer");
        if (res == null) {
            res = new Hashtable<Long, ImageIcon>();
            engine.setPluginProperty("Core", "Icons buffer", res);
            Qualifier qualifier = StandardAttributesPlugin.getIconsQualifier(engine);
            Attribute attribute = StandardAttributesPlugin.getIconsAttribute(engine);
            List<Attribute> list = new ArrayList<Attribute>(1);
            list.add(attribute);
            Hashtable<Element, Object[]> hash = engine.getElements(qualifier, list);
            Enumeration<Element> keys = hash.keys();
            while (keys.hasMoreElements()) {
                Element element = keys.nextElement();
                res.put(element.getId(), new ImageIcon(((IconPersistent) hash.get(element)[0]).getIcon()));
            }
        }
        return res;
    }
}
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) Qualifier(com.ramussoft.common.Qualifier)

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