Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Visual languages.

Started by Antonios Aug 6, 2007 at 5:00 PM 1 replies 750+ views
Original Post
Antonios
Antonios
There are programs that are using blocks of code for representing data and then you link them with lines and make a logical diagram. UML works like that and Quartz composer e.g. http://en.wikipedia.org/wiki/Image:Quartz_Composer.png . In Quartz there are blocks of code that you drop on a canvas and then by drawing lines between the blocks they produce something. My question is simple: 1) How are these projects made? I should use photoshop to make the boxes and how would I populate the box with attributes? 2) The lines that are used to connect the boxes are being drawn using java 2d? 3) Where could I find links how to start?
Antheus
Antheus
In Java, you'd create a custom Container component that would hold the blocks.

Each block would then be a JComponent with custom rendering.

To move components around, you'd listen to mouse events. Container component would draw the lines in the background with the connector information provided by your blocks.

The whole concept is relatively trivial:
public interface Connectable{  // returns list of all inputs and outputs,   // entries can be null if not connected  public List<Connectable> getInputs();  public List<Connectable> getOUtputs();  // returns location of the connector  // adjusted for parent's coordinates  public Point getOffsetFor( Connectable c );}


public class Block extends JComponent implements Connectable{  public Point getOffsetFor( Connectable c ) {    // find the connectable, calculate its position within parent    // using this components coordinates  }  public void paintComponent( Graphics g ) {    // do your stuff    // render connectors, fancy background, etc  }}


The container then just needs to take care of drawing the lines:
public class BlockContainer extends JComponent{  public void paintComponent( Graphics g ) {    // for every Block b contained within this component    {      List<Connectable> others = b.getOutputs();      for (Connectable c : others ) {        Point p1 = b.getOffsetFor( c );        Point p2 = c.getOffsetFor( b );        // draw line from p1 to p2      }    }  }}
pinacolada
pinacolada
The kind of language you're talking about is a Dataflow Language, and you can find a lot of good information on the Wikipedia page

As far as drawing the boxes, you could just draw a rectangle. That's like Drawing 101, you could consult any tutorial on drawing stuff with Java.

You could also use something like Graphviz, but it might be easier to just do the drawing yourself.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.