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();
}
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;
}
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);
}
}
}
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;
}
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;
}
}
Aggregations