Icon Support - 3.2

Joel, Rodney,

Is it possible to get a reference to the Vengine.jar DataArchive to determine a list of the images inside it?

Thanks,
B.

Thus spake “Brent Easton”:

String[] DataArchive.getImageNames() or SortedSet getImageNameSet()
either of will do it, and in both cases they’ll be in alphabetical order.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

That will get me the image names from the module, but I need the image names from the Vassal Engine.

B.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Brent Easton”:

Sorry, I misread. No, there’s nothing I know of right now to do that.
But I think it shouldn’t go in DataArchive.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Isn’t Vengine.jar a DataArchive?

Anyway, I don’t mind just treating it as a Zip, is there a way to access the pathname of the resource that contains an image or class?

I’ll try having a play with ClassLoader stuff.

Thanks,
B.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Hi Joel,

The only way I have been able to work out how to do this so far is to read the Manifest in the Vengine.jar file. However, in the svnxxxx distributions you are making, the Vengine.jar doesn’t include any of the file names in the Jar.

Is there a particular reason for this? Is it something you can easily turn back on? Some older versions I checked had a full manifest. I only need a listing of the files in the images folder and any sub-folders.

For the Icon stuff I have in mind, we need to basically create a cross-reference of all available Icons of all sizes. I want to keep away from having to manually register all of the icons in a static block somewhere.

Another thought was to have a perl job that builds a Java stub that registers the available files, but the Jar Manifest seemed an easier way.

Thanks,
Brent.


Brent Easton
Analyst/Programmer
University of Western Sydney
Email: b.easton@uws.edu.au


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Brent Easton”:

I went back to the Vengine.jar from 3.0.17 to look at this, because I didn’t
recall there being any listing of contained files in the MANIFEST.MF. the
Name keys there are for associating files with cryptographic hashes, for
verifying the JAR. You could parse these to make a file list, as they’re
in a regular, simple format, but then we’d have to start signing our JARs.
That wouldn’t be hard, but I suspect that signing for the purpose of getting
a file list is the long way around.

On looking into this, I discovered something which we should probably be
doing anyway, which is generating an INDEX.LIST, so that the JVM doesn’t
have to do a linear search through all of our JARs in order to find
classes to load. (Also, while trying to build an INDEX.LIST, I think I
discovered the cause of Bug #2045426, which I found unfathomable at the
time: We’re not shiping xercesImpl.jar, which xalan-2.6.0.jar depends on,
and it just happens that xercesImpl.jar doesn’t exist on some Macs.)
However, the INDEX.LIST only catalogs packages/directories, not individual
files. So that’s of no use for this problem, either.

Could you do the following at start-up?

final Set icons = new HashSet();
JarFile jar = null;
try {
jar = new JarFile(“Vengine.jar”);
for (JarEntry entry : iterate(jar.entries())) {
final String name = entry.getName();
if (name.startsWith(“icons/”)) {
final String basename = new File(name).getName();
icons.add(basename.substr(0, basename.lastIndexOf(’.’)));
}
}
jar.close();
}
catch (IOException e) {
}
finally {
IOUtils.closeQuietly(jar);
}

Here, I’m assuming the following:

(1) All of the icons are under icons/{16x16,22x22,32x32,scalable} in the JAR.
(2) All fixed-size icons are PNGs and named *.png. All scalable icons are
SVG and named *.svg.
(3) Because of (1) and (2), all you need is the filename without the
extension and the size you want in order to find any particular icon. This
is why I’m putting the names into a Set, becuase we’re sure to get duplicate
basenames, and we don’t want those.

Now, I don’t know how fast this will be. Possibly it will be too slow to
run at startup. If it is, we could write out a file containing this list
at build-time. That would be a trivial bit of shell scripting.

Do you actually need the sizes in the list?


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

This couldn’t find the jar file

but building on what I already had, this did:

JarArchive archive = new JarArchive();
URL url = archive.getURL(DataArchive.IMAGE_DIR);
JarURLConnection j = (JarURLConnection) url.openConnection();
jar = j.getJarFile();

This actually runs extremely quickly and seems like a good solution to me.

I had thought of having the /{16x16,22x22,32x32,scalable} directories under images, but perhaps it will be better to have them under their own icons directory. It doesn’t really matter for Vassal, but will make them easier to find in a Module.

I had originally thought along these lines as well, but have decided there is no reason to enforce this restriction. Accessing the JarFile means having to read every entry anyway, so I can determine exactly what files are available, collected into sets based on the base name.

Within Vassal, I expect we will follow this convention, but we will allow user-defined Icon sets in modules that might consist of anything.

I don’t think we will need this, accessing the JarFile is very fast.

Yes, I believe so for efficiency. It is not required to supply the individually sized Icons and my earlier testing indicated that attempting to load a non-existent Zip entry is an expensive process. I have already built this part of the code, creating missing Icons automatically from the scalable icon as required. A minimal IconSet consists on a single scalable Icon that is used to generate all of the other sizes.

B.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Brent Easton”:

Ok. I didn’t test that, I wrote it off the top of my head.

This because it has to prove that the entry isn’t there by iterating over
all of them.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)