[platform-dev] Visual API and Making Widgets Operate Strictly In A Single Quadrant

  • From: Wade Chandler < >
  • To: "dev@platform;netbeans. org" < >
  • Subject: [platform-dev] Visual API and Making Widgets Operate Strictly In A Single Quadrant
  • Date: Tue, 27 Nov 2012 11:02:27 -0500


Thank you for reading. I have a project where I'm using the visual API. There is another visual editor we are using to create some things, and part of that I need to mimic here. It operates on the notion of quadrants of a plane. Right now I just need to operate in the top right quadrant or quadrant 1 from the illustration here:

So (and I hope this comes out OK in your email readers...no ascii art master),

.........| I'm working here

Next, I have a scale of meters going from what would be considered in standard geometry as 0,0 of the top right coordinate:
10m  assuming this comes out OK it looks ugly
|        but like a quadrant

I have a MoveStrategy which works to keep one from moving below the bottom or left of the quadrant, and that is fine. The issue I'm having is that 0,0 in the Java coordinate space is the top left of the graphics space, and my 0,0 is from the bottom. I place a widget there, and the user can move it around to the meters they want on either axis in the quadrant. However, if the scene resizes (due to user movement or say the application is maximized or the window resized), or due to the way the scene works a component is moved up and causes the Y of the scene to become more negative, my components no longer match where they should be on the meter scale. In general Java 2D the answer is simple. Just recalculate some points and repaint where needed. But, as I'm using the Visual API I want to take advantage of it as it already gives me layers, drag and drop, user interaction, an object model, etc etc.

For my scale I have a LayerWidget I extended and in its paintWidget() method I draw the Y scale like so:
Point sxy = getScene().getBounds().getLocation();
//scene least x
double slx = sxy.getX();
//scene least y
double sly = sxy.getY();
//scene width
double width = getScene().getBounds().getWidth();
//scene height
double height = getScene().getBounds().getHeight();
//scene max x
double smx = slx + width;
//scene max y
double smy = sly + height;

Line2D mainLineYAxis = new Line2D.Double(slx + axisWidth, smy, slx + axisWidth, sly);

and plus other things including the numbers and labels it all looks fine and extends when then scene is resized and grown. But, what I'm trying to figure out is the best approach to locking those Widgets in place.

I'm looking at using a coupling between a Widget.Dependency and a MoveProvider to some how mark the widget the user is currently moving, and shifting other Widgets in the scene when the user does this to keep them from getting off the mark. I am concerned when I do this though that no widget will bump up against the bottom of the scene (quadrant transposed onto a scene) and this will cause the scene to essentially never resize, but I'm not sure until I get that idea coded up if I have anything to worry about. Too, I'm not sure my idea is the best way to solve this. It seems more hackish than it needs to be.

I'm kind of in the infancy in solving my problem though I have been trying some other things which haven't really solved the issue, and I figured someone else may have solved something similar if not the same thing.

Any help is greatly appreciated, and thank you so much for your time,



Wade Chandler

Software Engineer and Consultant
NetBeans Contributor
NetBeans Dream Team Member


[platform-dev] Visual API and Making Widgets Operate Strictly In A Single Quadrant

Wade Chandler 11/27/2012

[platform-dev] Re: Visual API and Making Widgets Operate Strictly In A Single Quadrant

Timon Veenstra 11/28/2012

Project Features

Project Links

About this Project

Platform was started in November 2009, is owned by Antonin Nebuzelsky, and has 149 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20160708.bf2ac18). © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
Please Confirm