Java2d and Paintable Canvas

First off, I LOVE the paintable canvas.

Only one problem… Not familiar with Java2d code. So, here’s my question: Is there some way to DRAW and image, say in a program SIMILAR to AutoCAD and then have it RENDER the Java2d code?? I have a buddy here at work that has used RSView or some sort of AllenBradley software to do animation on PanelViews and he does something similar. He just draws the object and then animates it.

So, Is there any software out there that I can use to draw an object and then have it give me the Java2d code? Or is this a waste of time and I just need to start READING??? lol :open_mouth:

Actually, yes you might be able to approximate this.

  1. Draw a simple shape in a vector-based image editing app like Inkscape or Illustrator. Save it as an SVG.

  2. Download the super-barebones program “SvgShapeExtractor.jar” (it’s an executable jar - just double click on it to run it) from here: jasperpotts.com/blogfiles/SvgShapeExtractor.jar

  3. Run that program and feed it your SVG file - it should spit out Java2D code that you can coerce into powering the paintable canvas.

Just my two cents…

I knew nothing about java two years ago, but as soon as IA added the paintable canvas, I saw unreal possibilities, and am doing some pretty unreal things with it now. Maybe I’m biased, but if I were you, I would just start reading even if you could come up with a converter. :slight_smile: It’s amazingly easy once you get the hang of it.

Question about animation. I have a rubber mixer with 2 rotors inside and I am doing an “Overview” screen for the equipment. I used java2d to draw rotor but need to animate it and make it turn. How would I do that?

What I have done in the mean time is to take a “Snapshot” of the object drawn and save it as a png file, and then used a timer to rotate the picture. That is fine for now, but I am trying to keep the future in mind. I would very much like to animate conveyors and products ON the conveyors too.

Any solution for this besides using MULTIPLE images(png’s) and toggling visibility??

I wouldn’t use png or any other image at all, and just use pure Java2d for the animation. Whether you use a timer or system feedback to trigger the repaint is up to you.

When I do animation, I make sure I plan all of the geometry ahead and “redraw” the object dynamically. For instance, if I were drawing a windmill, I would draw the blades as a bufferedImage and then “paint” their dynamic position based on the rotational position. It isn’t too bad once you get the hang of it. In any event, there isn’t a need to use png images unless you want to.

While you could certainly animate using Java2D, and the end result would probably look good and be scalabale, it would definitely be easier to just use normal png frame-based animation.

It doesn’t have to be as nasty as using multiple image objects and toggling their visibility. Suppose you have 4 frames of your animation. Take 1 image component and 1 timer. Set the timer’s bound to 4. The bind the image’s path to an expression like:

"MyImages/windmill_anim_frame" + {Root Container.Timer.value} + ".png"

Definately take you much less time than drawing it in Java2d…

It depends. If there are only a few drawings and they will probably never change, then using images will be pretty simple to implement.

But, take the project I’m working on right now: I have 100+ conveyors to display, all of which are individually controlled. Some are straight, some curved, some are belt style and some are link style. They cross each other, sit on top of each other, and are obscured by other devices. So, by using the paint component, I just draw the belts using parameters that I pass into a function (length of the belt, radius, etc) and it becomes a bufferedImage that I draw on the canvas. And by using things like transparency, I can make belts semi-transparent, completely invisible, or give them tints and shading to indicate status. And, since I treat them as objects, they can become buttons, labels or whatever. And in huge plants, I can zoom in and out and pan, like Google Maps. The possibilities are endless.

The disadvantage? It was pretty freakin’ hard to figure out in the beginning. :slight_smile: If I wasn’t going to be doing a lot of projects and didn’t need this flexibility, I would have just used images.

At the end of the day though, I don’t care how anyone does it. FPMI blows away any other software for screen design.

Yeah, I guess it all comes down to a complexity calculation. If what you’re doing is relatively simple, it probably doesn’t warrant the complexity of the paintable canvas. But if you’re doing something highly complex and dynamic, and want the scalability of vector painting, then the complexity of the paintable canvas is totally worth it.

Karl - what you’re doing sounds amazing! I may need to borrow your approach for inspiration for another screen on our demo project (in the NOT FOR BEGINNERS section). Or I could use the content for a training video. I would recognize you, of course.

No problem Nathan. I’d be glad to show you what I’ve done. I have a meeting tomorrow with a prospective customer where I would be using a lot of j2d screens, and another progress meeting on Friday with an existing customer. I’ll ask them both about how they feel about screenshots and demos. At the least, I can send you a project and let you hack it until it’s unrecognizable to a specific customer.

It would be great to have some other screens to look at and see if there are better ways to do what I’m doing. There is at least one thing that I have to fix but I haven’t had time yet to figure it out.

Lastly, this doesn’t mean we can’t do awesome screens without this stuff. I just happened to stumble onto a couple of complex projects where it was warranted.