NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
cruzianengineer
Joined: 04 May 2012 Posts: 7
|
Posted: Fri May 04, 2012 6:28 pm Post subject: Using Graphics2D to rotate IconNodeWidget ???? |
|
|
OK guys, I've been searching on how to implement this but having a hard time making it happen.
Reading the article, it seems like this is possible and would like some guidance or examples how to make it work using the Visual Library. I found this and hope David Kaspar can help: http://netbeans.org/bugzilla/show_bug.cgi?id=113456
I am able to use the Graphics2D object to rotate an image run the attached file, but having a hard time doing so with the IconNodeWidget. Any advice or guidance will be appreciated. Thanks
| Description: |
|
| Filesize: |
2.92 KB |
| Viewed: |
2846 Time(s) |

|
| Description: |
|
 Download |
| Filename: |
RotateImage.java |
| Filesize: |
2.02 KB |
| Downloaded: |
75 Time(s) |
|
|
| Back to top |
|
 |
Monezz
Joined: 18 Feb 2009 Posts: 254
|
Posted: Mon May 07, 2012 1:07 pm Post subject: [platform-dev] Re: Using Graphics2D to rotate IconNodeWidget ???? |
|
|
| Quote: | I am able to use the Graphics2D object to rotate an image run the attached file, but having a hard time doing so with the IconNodeWidget. Any advice or guidance will be appreciated. Thanks
| Do you have a specific problem, or are you looking for general approach tips?
|
|
| Back to top |
|
 |
cruzianengineer
Joined: 04 May 2012 Posts: 7
|
Posted: Mon May 07, 2012 6:43 pm Post subject: @Monezz |
|
|
Thanks for responding......
General Approach tips would be GREAT, to verify that my approach is workable.
So what I did, was I created a class called RotateIconNodeWidgetAction which extends WidgetAction.Adapter in the GraphScene class...., within that class theres a State mouseClicked(Widget widget, WidgetMouseEvent e) which should rotate the IconNodeWidget based on the mouse condition, using the code I provided. It add an image to the scene, but the image is not update on the Widget.
I'm also trying to implement MyIconNodeWidget which extends IconNodeWidget, then override the paintWidget method to rotate the image when called but no luck.
Hope you can understand, what I am trying to explain. David Kaspar stated that this is possible, but I think with better explanation or guidance I can accomplish this.
|
|
| Back to top |
|
 |
Monezz
Joined: 18 Feb 2009 Posts: 254
|
Posted: Tue May 08, 2012 11:06 am Post subject: [platform-dev] Re: Using Graphics2D to rotate IconNodeWidget ???? |
|
|
| Quote: | General Approach tips would be GREAT, to verify that my approach is workable.
So what I did, was I created a class called RotateIconNodeWidgetAction which extends WidgetAction.Adapter in the GraphScene class...., within that class theres a State mouseClicked(Widget widget, WidgetMouseEvent e) which should rotate the IconNodeWidget based on the mouse condition, using the code I provided. It add an image to the scene, but the image is not update on the Widget.
I'm also trying to implement MyIconNodeWidget which extends IconNodeWidget, then override the paintWidget method to rotate the image when called but no luck.
Hope you can understand, what I am trying to explain. David Kaspar stated that this is possible, but I think with better explanation or guidance I can accomplish this.
| I think you are on the right track.
You could perhaps paint the widget based on a variable on the widgets
(say int rotation with value between 0-360)
In your action (inner class of the widget) you could set a new value
to the variable and invoke repaint on the widget.
|
|
| Back to top |
|
 |
cruzianengineer
Joined: 04 May 2012 Posts: 7
|
Posted: Tue May 08, 2012 7:39 pm Post subject: |
|
|
Thanks Monezz.....
So, I extended the IconNodeWidget to create MyWidget. As I stated earlier in the RotateIconNodeWidgetAction which extends WidgetAction.Adapter in the GraphScene, if mouseClicked State occurs the image is painted to the scene, and the image is rotated, sample code below:
I am not going to override the painWidget method because, I don't want to paint all Widget, only the widget that an action is performed on.
| Code: |
//@Override
protected void repaintWidget () {
super.paintWidget();
Image image = this.getImageWidget().getImage();
JComponent view = this.getScene().getView();
Graphics2D g2d = (Graphics2D) view.getGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
AffineTransform origXform = g2d.getTransform();
AffineTransform newXform = (AffineTransform) (origXform.clone());
//center of rotation is center of the panel
double xRot = this.getLocation().getX();//this.getImageWidget().getLocation().getX() - (this.getImageWidget().getImage().getWidth(view)/2);
System.out.println("xRot: " + xRot + " location: x->" + this.getLocation().x + " - " + this.getLocation().getX() + ": y->" + this.getLocation().y + "-" + this.getLocation().getY() );
double yRot = this.getLocation().getY();// - (this.getImageWidget().getImage().getHeight(view)/2);
System.out.println("yRot: "+ yRot);
newXform.rotate(theta* Math.PI / 180, xRot, yRot);
System.out.println("newXform.rotate(theta*Math.PI"+theta*Math.PI+"/180,xRot,yRot");
g2d.setTransform(newXform);
System.out.println("g2d.setTransform("+newXform+")");
//need to draw image, then update the MarciWidget image in the object
int x = (this.getLocation().x - this.getImageWidget().getImage().getWidth(view)/2);//(this.getScene().getView().getWidth() - this.getImageWidget().getImage().getWidth(this.getScene().getView())) / 2;
System.out.println("x: " + x + " location: "+ this.getLocation().x);
int y = (this.getLocation().y - this.getImageWidget().getImage().getHeight(view)/2);//(this.getScene().getView().getHeight() - this.getImageWidget().getImage().getHeight(this.getScene().getView())) / 2;
System.out.println("y: " + y + " location: "+ this.getLocation().y);
g2d.drawImage(image, x, y, view);
g2d.setTransform(origXform);
super.paintWidget();
theta = (theta + 15) % 360;
|
So now, questions...... so instead of painting the image to the scene, I would like to update the image of the IconNodeWidget. I tried this.setImage (image) after g2d.drawIamge(.....), that didn't work...., ????
I saw that the ImageWidget Class, look at link: https://www.java2s.com/Open-Source/Java/IDE-Netbeans/api/org/netbeans/api/visual/widget/ImageWidget.java.htm
has an ImageObserver Object, where the | Code: | | Graphics2D g2d.drawImage(Image, x, y, ImageObserver) | requires an observer, not getter to obtain or access the observer, might there be a work around or other way????[/code]
Last edited by cruzianengineer on Wed May 09, 2012 9:14 pm; edited 1 time in total |
|
| Back to top |
|
 |
Monezz
Joined: 18 Feb 2009 Posts: 254
|
Posted: Wed May 09, 2012 8:44 am Post subject: [platform-dev] Re: Using Graphics2D to rotate IconNodeWidget ???? |
|
|
| Quote: | I am not going to override the painWidget method because, I don't want to paint all Widget, only the widget that an action is performed on.
|
Instead of painting the widget only once when it is marked eligible
for (re)painting, you are now painting it thrice when the action is
performed.
We have created a widget to draw icons on the map.
It's not the exact situation of course, but perhaps it can point out
the validity of overriding the paintWidget method:
http://java.net/projects/agrosense/sources/core/content/geoviewer/render/src/main/java/nl/cloudfarming/client/geoviewer/render/IconWidget.java?rev=2202
If you remove the super.paintWidget(); calls from repaintWidget you
could use it as paintWidget override.
You could even store the transformed image in the widget and only
change it when the action is performed.
The action performed could look like this:
actionPerformed(){
transformImage(newRotation);
repaint();
}
The paint will only be invoked when there is a reason to repaint the
widget which makes it quite efficient point to put your own drawing
code in.
|
|
| Back to top |
|
 |
cruzianengineer
Joined: 04 May 2012 Posts: 7
|
Posted: Wed May 09, 2012 9:06 pm Post subject: |
|
|
Monezz,
It was beneficial to remove the super.paintWidget(), that helped. After the transformation was done I added this.getScene().repaint() to remove any trailing garbage when rotating or moving the widget.
I have a problem, I'm not sure if I've been looking at this problem too long that I'm missing a simple step But here goes.
| Code: | | Graphics2D g2d = (Graphics2D) this.getGraphics() | , allows me to rotate the widget, but will not allow me to add another widget to the scene.
| Code: | | Graphics2D g2d = (Graphics2D) this.getGraphics().create() | , allows me to add another widget to the scene but not rotate the widget.
I don't know what I'm missing, but I added a sample project, from the Netbeans visual.examples that I've been working on as my sample before implementing.
| Quote: | The paint will only be invoked when there is a reason to repaint the
widget which makes it quite efficient point to put your own drawing
code in. |
I'm guessing that your saying, if I am not going to rotate the widget and an Icon needs to be added to the scene, Implementing my own paint functionality in the paintWidget function is requried... right??/
| Description: |
|
 Download |
| Filename: |
freeconnect.tar.gz |
| Filesize: |
6.46 KB |
| Downloaded: |
81 Time(s) |
|
|
| Back to top |
|
 |
Monezz
Joined: 18 Feb 2009 Posts: 254
|
Posted: Thu May 10, 2012 7:51 am Post subject: [platform-dev] Re: Using Graphics2D to rotate IconNodeWidget ???? |
|
|
| Quote: | Code:
Graphics2D g2d = (Graphics2D) this.getGraphics()
, allows me to rotate the widget, but will not allow me to add another widget to the scene.
Code:
Graphics2D g2d = (Graphics2D) this.getGraphics().create()
, allows me to add another widget to the scene but not rotate the widget.
I don't know what I'm missing, but I added a sample project, from the Netbeans visual.examples that I've been working on as my sample before implementing.
|
You should not use graphics to add widgets to the scene.
The idea if widgets is that they are isolated, independent pieces of
graphics. They can be linked with connector widgets, but in general
each widget only have knowledge about itself and not about other
widgets.
Although it is possible, a widget should not paint outside its working
area (clientArea). (this will also prevent you from hours of debugging
why the widget context menu is not working).
getGraphics().create() is used to create a clone of the graphics.
You could clip the graphics area to the widgets client area, change
colors etc, without affecting other widgets which also use the scene's
graphics to paint themselves.
You should use create to get graphics and dispose them in the end of
your paint method.
This will keep the scene's graphics clean and again will save you
hours of wild goose chases. (widgets that appear to change colors at
random for example).
| Quote: | | Quote: | The paint will only be invoked when there is a reason to repaint the
widget which makes it quite efficient point to put your own drawing
code in.
|
I'm guessing that your saying, if I am not going to rotate the widget and an Icon needs to be added to the scene, Implementing my own paint functionality in the paintWidget function is requried... right??/
|
If you are just painting an icon on a widget you could use the
standard IconWidget (which overrides the paintWidget method for you).
But if you want to rotate that same widget later on, you are probably
better of writing your own RotatableIconWidget.
|
|
| Back to top |
|
 |
cruzianengineer
Joined: 04 May 2012 Posts: 7
|
Posted: Wed May 16, 2012 1:06 pm Post subject: |
|
|
Thanks Monezz that makes sense, Implementing my own RotateableIconWidget huh, OK I'm going to have to think more on how to implement. So putting this task on pause for a few days.
Another issue I'm having is the bringToFront and bringToBack doesn't seem to function as described. The last widget added to the Scene, does not seem to be added in front of the list to be placed in the back.
The task is to have rectangles representing Desk and Computer Icons, that can be placed on these desk via drag. The problem is if computer icons are painted in the scene before the Desk the computer icons are always under.
Any input or understanding of this issue, I did a few searches but not much information????
Thanks Monezz for your assistance
|
|
| Back to top |
|
 |
luca dazi Posted via mailing list.
|
Posted: Sat May 19, 2012 3:18 pm Post subject: [platform-dev] Re: Using Graphics2D to rotate IconNodeWidget ???? |
|
|
You could use layers in order do change the "z-order" of the elements on the scene.You could have a "Desk" layerWidget, and a "Pc" layerWidget, and put inside these layers only the relative elements.
L.
2012/5/16 cruzianengineer <address-removed ([email]address-removed[/email])>
| Quote: | Thanks Monezz that makes sense, Implementing my own RotateableIconWidget huh, OK I'm going to have to think more on how to implement. So putting this task on pause for a few days.
Another issue I'm having is the bringToFront and bringToBack doesn't seem to function as described. The last widget added to the Scene, does not seem to be added in front of the list to be placed in the back.
The task is to have rectangles representing Desk and Computer Icons, that can be placed on these desk via drag. The problem is if computer icons are painted in the scene before the Desk the computer icons are always under.
Any input or understanding of this issue, I did a few searches but not much information????
Thanks Monezz for your assistance
|
|
|
| Back to top |
|
 |
cruzianengineer
Joined: 04 May 2012 Posts: 7
|
Posted: Wed May 30, 2012 12:26 pm Post subject: |
|
|
| @luca dazi... Looking at the other examples I was able to see that LayerWidgets were available, which I used to accomplish what you described. Thanks for you feed back.
|
|
| Back to top |
|
 |
cruzianengineer
Joined: 04 May 2012 Posts: 7
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|