File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes SWT XML Sprite Sheet Utility Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "SWT XML Sprite Sheet Utility" Watch "SWT XML Sprite Sheet Utility" New topic
Author

SWT XML Sprite Sheet Utility

Lance Colton
Ranch Hand

Joined: Nov 25, 2010
Posts: 64

I'm trying to create a class, which will take a path to an Image, and an XML file which defines sub-images within the image, and return each sub image as SWT Image objects.

It basically should work like this



with the XML Sprite sheet looking like this



I think the problem is SWT doesn't like for the display object to be passed to an outside class, is there any way to resolve this?

The stack trace:


The is the result of me trying to draw a returned image to a Canvas in a Shell with the same Display.


~tak
irc.esper.net - tak, irc.freenode.com - tak11, irc.efnet.org - tak11
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Are you sure that sprites.containsKey("play.png") returns true? In other words, that sprites.get("play.png") does not return null?
You are calling sprites.get("name") - using the String literal "name" instead of the parameter name. As a results, the returned Image probably is null.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Lance Colton
Ranch Hand

Joined: Nov 25, 2010
Posts: 64

Rob Spoor wrote:Are you sure that sprites.containsKey("play.png") returns true? In other words, that sprites.get("play.png") does not return null?
You are calling sprites.get("name") - using the String literal "name" instead of the parameter name. As a results, the returned Image probably is null.


Yes, each name in the <String, Image> HashMap is there, however the Image objects are all null. something is wrong with the image construction through GC, and I think it might have something to do with the Display object that had to be passed.

let me post the entire source code,



Here is the XML:
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

But you're not calling sprites.get("play.png"), you're calling sprites.get("name").
Lance Colton
Ranch Hand

Joined: Nov 25, 2010
Posts: 64

Rob Spoor wrote:But you're not calling sprites.get("play.png"), you're calling sprites.get("name").


There are no words, to express, how retarded I feel for that XD

Thank you so much, it works perfectly now.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

It's the kind of mistake everybody makes at least once. But you're welcome
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SWT XML Sprite Sheet Utility