Zoom in shape object

Hello, I am trying to zoom on a shape object with the AffineTransform class, and would like to know how to zoom from the center of my object graph, and this graphic object can be a circle, rectangle, polygon, etc. .. .
I'm lost in logic to perform the transformation.
Thanks.

Is there a question? Are you asking me to run your partial code snippet for you?
user2307826 wrote:
Here's part of my code, entered the getScaleInstance now as I could zoom in from the center of my object, assuming for example that my object is a rectangle?
thanks
@Override
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.RED);
AffineTransform tx = AffineTransform.getScaleInstance(scale, scale);
g2.draw(tx.createTransformedShape(rect1));

Similar Messages

  • How to make shape objects clickable/selectable in transformgroups in java 3

    I am building a visualizer program that has Java 3D components inside Swing components. I have a branchgroup inside a canvas3d inside a simpleuniverse, which is added to a JTabbedPane. Inside the branchgroup I have multiple transformgroups each with one shape in them (box, cone, sphere, cylinder). Each transformgroup has the ability to rotate, zoom, and tranlate objects because I have incorperated a MouseZoom, MouseRotate, and MouseTranslate object as from the Java 3D library functions (these are applied to each transformgroup every time one is created and added to the branchgroup). My problem is that I am trying to make these shapes clickable/sectable/dragable/dropable on the screen - currently when I try to translate ONE object all the shapes move on the screen and I cannot get just one shape to move (all shapes move when I only want one to). How do I make only one shape move when it is clicked?
    I know the question is kind of out there and specific so if anyone knows how to generically give transformgroups/shapes drag and drop properties that would also help a great deal. Does anyone know how to to this? Thanks a ton.

    shape uses the contains and intersects methods, is that what you need? Without code it is hard to guess what is required.

  • Problem in moving Rotated Shape object

    Hi All,
    I want to move the rotated shape object based on the mouse movement
    m able to move the object which is not rotated, but m facing the problem when i move the rotated object its moving position is not correct . I am expecting to maintain both shape objects movement is same, i mean if i did mouse movement to right rotated object moves upwards and normal object moves towards right insted of moving both r moving towards to right.
    Pls help me
    the following code is m using to moving the object
    The one which in red color is not rotated and the one which is in black color has rotated.
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.awt.Shape;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.awt.geom.AffineTransform;
    import java.awt.geom.Point2D;
    import java.awt.geom.Rectangle2D;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import com.clinapps.LDPConstants;
    public class MoveRotatedObj extends JFrame
         public MoveRotatedObj()
              JPanel pane = new Dorairaj();
              add(pane);
         public static void main(String[] args)
              MoveRotatedObj f = new MoveRotatedObj();
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              f.setSize(400, 400);
              f.setLocation(200, 200);
              f.setVisible(true);
         static class Dorairaj extends JPanel
              implements
                   MouseListener,
                   MouseMotionListener
              Shape o = null;
              Rectangle2D rect = new Rectangle2D.Double(
                   10, 10, 100, 100);
              Graphics2D g2 = null;
              boolean flag = true;
              int x=10,y=10,x1, y1, x2, y2;
              AffineTransform af = new AffineTransform();
              AffineTransform originalAt = new AffineTransform();
              int origin = 0;
              public Dorairaj()
                   addMouseListener(this);
                   addMouseMotionListener(this);
              protected void paintComponent(Graphics g)
                   super.paintComponent(g);
                   g2 = (Graphics2D) g;
                   g2.draw(new Rectangle2D.Double(0,0,500,500));
                   g2.translate(origin, origin);
                   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        RenderingHints.VALUE_ANTIALIAS_ON);
                   rect = new Rectangle2D.Double(
                        x, y, 150, 100);
                   g2.setColor(Color.RED);
                   g2.draw(rect);
                   g2.setColor(Color.black);
                   originalAt = g2.getTransform();
                   g2.rotate(Math.toRadians(270), 200, 200);               
                   g2.draw(rect);
                   g2.setTransform(originalAt);
              * Invoked when a mouse button has been pressed on a component.
              public void mousePressed(MouseEvent e)
                   e.translatePoint(-origin, -origin);
                   x1 = e.getX();
                   y1 = e.getY();
              public void mouseDragged(MouseEvent e)
                   x2 = e.getX();
                   y2 = e.getY();
                   x = x + x2 - x1;
                   y = y + y2 - y1;
                   x1 = x2;
                   y1 = y2;
                   repaint();
              public void mouseMoved(MouseEvent e)
              * Invoked when the mouse button has been clicked (pressed and released)
              * on a component.
              public void mouseClicked(MouseEvent e)
                   repaint();
              * Invoked when a mouse button has been released on a component.
              public void mouseReleased(MouseEvent e)
              * Invoked when the mouse enters a component.
              public void mouseEntered(MouseEvent e)
              * Invoked when the mouse exits a component.
              public void mouseExited(MouseEvent e)
    Edited by: DoraiRaj on Sep 16, 2009 12:51 PM
    Edited by: DoraiRaj on Sep 16, 2009 1:00 PM
    Edited by: DoraiRaj on Sep 16, 2009 1:07 PM

    Thanks for replay and suggestion morgalr,
    I mean MoveRotatedObj1 is MoveRotatedObj only jsut m maintaing a copy on my system like MoveRotatedObj1.
    finally i solved my problem like this ,
    Is this correct approach m followinig or not pls let me know .
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.awt.Shape;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.awt.geom.AffineTransform;
    import java.awt.geom.Point2D;
    import java.awt.geom.Rectangle2D;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import com.clinapps.LDPConstants;
    public class MoveRotatedObj extends JFrame
    public MoveRotatedObj()
      JPanel pane = new Dorairaj();
      add(pane);
    public static void main(String[] args)
      MoveRotatedObj f = new MoveRotatedObj();
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.setSize(400, 400);
      f.setLocation(200, 200);
      f.setVisible(true);
    static class Dorairaj extends JPanel
      implements
       MouseListener,
       MouseMotionListener
      Shape o = null;
      Rectangle2D rect = new Rectangle2D.Double(
       10, 10, 100, 100);
      Rectangle2D rect1 = new Rectangle2D.Double(
       10, 10, 100, 100);
      Graphics2D g2 = null;
      boolean flag = true;
      double lx, ly;
      int x = 10, y = 10, x1, y1, x2, y2;
      int l = 20, m = 20;
      int angle = 270;
      AffineTransform af = new AffineTransform();
      AffineTransform originalAt = new AffineTransform();
      int origin = 0;
      public Dorairaj()
       addMouseListener(this);
       addMouseMotionListener(this);
      protected void paintComponent(Graphics g)
       super.paintComponent(g);
       g2 = (Graphics2D) g;
       g2.draw(new Rectangle2D.Double(
        0, 0, 500, 500));
       g2.translate(origin, origin);
       g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
        RenderingHints.VALUE_ANTIALIAS_ON);
       rect = new Rectangle2D.Double(
        x, y, 150, 100);
       g2.setColor(Color.RED);
       g2.draw(rect);
       rect1 = new Rectangle2D.Double(
        l, m, 150, 100);
       g2.setColor(Color.black);
       originalAt = g2.getTransform();
       g2.rotate(Math.toRadians(angle), 200, 200);
       g2.draw(rect1);
       g2.setTransform(originalAt);
      public void mousePressed(MouseEvent e)
       e.translatePoint(-origin, -origin);
       x1 = e.getX();
       y1 = e.getY();
      public void mouseDragged(MouseEvent e)
       boolean left, right, up, bottm;
       int dx, dy;
       left = right = up = bottm = false;
       x2 = e.getX();
       y2 = e.getY();
       dx = x2 - x1;
       dy = y2 - y1;
       x = x + dx;
       y = y + dy;
       up = dy < 0;
       bottm = dy > 0;
       left = dx < 0;
       right = dx > 0;
       if (left || right)
        // b += dx;
        m += dx;
       if (up || bottm)
        // a -= dy;
        l -= dy;
       x1 = x2;
       y1 = y2;
       repaint();
      public void mouseMoved(MouseEvent e)
      public void mouseClicked(MouseEvent e)
       repaint();
      public void mouseReleased(MouseEvent e)
      public void mouseEntered(MouseEvent e)
      public void mouseExited(MouseEvent e)
    }

  • Shape Object panel disapear in french version of MOTION3 !

    I found a bug in motion 3. It's about shapes and paintings.
    When you draw a shape with the paint tools and make few changes in the in the shape object panel, this panel disapears. You can't access any paramaters after that.
    I found a solution
    This bug appears when you use the French version of motion 3 (PPC and Intel MAC).
    Use a litle program call LANGSWITCH to switch in the ENGLISH version of motion and the bug disapear. Very strange.
    Hope this topic can help the french users.
    Cheers
    Sorry for my ENGLICH, I'm french

    Thank you very much for your update, Ravikumar, I appreciate it.
    I run the command on English version OS and French version OS, please see the result below, the first one is from English version OS. 
    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.
    C:\Users\Administrator>systeminfo | findstr "Memory"
    Total Physical Memory: 955 MB
    Available Physical Memory: 375 MB
    Virtual Memory: Max Size: 1,979 MB
    Virtual Memory: Available: 1,380 MB
    Virtual Memory: In Use: 599 MB
    C:\Users\Administrator>
    I ran the command systeminfo | findstr "Mémoire" and got the result below.
    Microsoft Windows [version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. Tous droits réservés.
    C:\Users\Administrateur>systeminfo | findstr "Mémoire"
    Mémoire physique totale: 2 047 Mo
    Mémoire physique disponible: 1 213 Mo
    Mémoire virtuelle : taille maximale: 4 095 Mo
    Mémoire virtuelle : disponible: 3 095 Mo
    Mémoire virtuelle : en cours d'utilisation: 1 000 Mo
    C:\Users\Administrateur>
    Can guys who are in charge of French version OS have a look on this problem ? Thanks.
    Jemy

  • How do I tell my shape object what shape it is

    Hi - I'm pretty new to all this
    I'm trying to create an applet on which a number of different (non standard) shapes will be displayed. I want to be able to move these shapes around the applet. I know that I need to add a mouselistener to my shape object but how do I tell my shape object what area belongs to it.
    Previously I have given my shape object a draw method so the shape is displayed but the object has no knowledge of exactly what area it is made up of, does it?

    You have to go to Settings>iCloud, tap Delete Account, provide the password for the old ID when prompted to turn off Find My iPhone, then sign back in with the ID you wish to use.  If you don't know the password for your old ID, or if it isn't accepted, go to https//appleid.apple.com, click Manage my Apple ID and sign in with your current iCloud ID.  Tap edit next to the primary email account, tap Edit, change it back to your old email address and save the change.  Then edit the name of the account to change it back to your old email address.  You can now use your current password to turn off Find My iPhone on your device, even though it prompts you for the password for your old account ID. Then go to Settings>iCloud, tap Delete Account and choose Delete from My iDevice when prompted (your iCloud data will still be in iCloud).  Next, go back to https//appleid.apple.com and change your primary email address and iCloud ID name back to the way it was.  Now you can go to Settings>iCloud and sign in with your current iCloud ID and password.

  • Is there a way to zoom into selected objects in Pages?

    Working in the page layout mode in Pages and I note that there is no way to zoom into a particular object or selected objects. This is really a pain if you are working on a poster much larger than the screen and you want to zoom right to a particular object. Zooming only seems to go to upper left corner and you have to scrool around to find the object you were working on.
    Has anyone figured out some magical way to zoom into an object on a page?

    This may not be the perfect answer, but it's pretty good in some situations. Smart Scroll has a grab hand fetaure that you may like.
    http://download.cnet.com/Smart-Scroll/3000-18487_4-10003983.html
    Walt

  • How to shape objects

    How do I shape objects to follow the shape of something else? For example, I have text I want to put on a background of an opened book. (You know how the pages lay flat, then up where the spine is, down at the spine, up again on the other page, then flat again.) I want the text to look like it's really on the page, not just pasted on top of an image of a book, without having to manually distort each letter. Any ideas or tips?

    MLTB,
    You may
    1) Create a rectangle that corresponds to the full opening being flattened with a fill reflecting the paper colour;
    2) Make a copy of 1) and hide it;
    3) Create Live Type, either with the Type Tool grouped with the rectangle 1) or with the Area Type Tool based on the rectangle 1), in which case you will need an underlying copy with the fill reflecting the paper colour grouped with the Area Type;
    4) Show the copy 2) and change its shape so it reflects the curves of the fulle opening (you may remove the fill;
    5) Select 3) and 4) and Object Envelope Distort>Make with Top Object.
    You may need to change the shape, at least of the Type, to reflect the angle of observation (as a simple measure you may reduce the ratio of height to width of the Type).

  • Zooming of Shapes Problem - Shapes also translate

    Hi,
    i have the following problem, i wish to zoom a shape - the problem is - while the shape zooms - it also moves away from my screen - instead of staying at its original point and just growing and growing it grows & moves away - im not sure where the error is.
    Pseudo Code :
    zoomTrans = AffineTransform.getScaleInstance(1.1,1.1);
    while(true) {
    zoomingShape = mergeTrans.createTransformedShape(zoomingShape);
    zoomingShape.draw(g);
    Do i have to add a negative translation here which removes the translation done by the zooming ? Im quiet confused - i thought scaling was working like rotation..
    Thanks

    You have to translate like Dr Las said. One way is to
    translate the center of your shape to (0,0), scale it,
    then translate it back to the correct position.
    JonIndeed. Scaling has a fixed point: imagine pinning your shape to the X-Y plane; scaling won't cause that point to move. For the basic scale transform, that fixed point is the origin. So choose your fixed point (In the code below it is (1,2), the upper-left corner of the rectangle), and as Jon writes translate it to the origin, scale then translate it back:
    import java.awt.*;
    import java.awt.geom.*;
    public class X {
        public static void main(String[] args)  {
            Shape shape = new Rectangle2D.Float(1,2,3,4); //x,y,w,h
            dump(shape);
            AffineTransform xform = getScale(2, 2, 1, 2);
            dump(xform.createTransformedShape(shape));
        static void dump(Shape shape) {
            float[] coords = new float[6];
            System.out.println("Shape dump:");
            for (PathIterator i = shape.getPathIterator(null);!i.isDone(); i.next()) {
                switch(i.currentSegment(coords)) {
                case PathIterator.SEG_MOVETO:
                    System.out.println("move to (" + coords[0] + "," + coords[1] + ")");
                    break;
                case PathIterator.SEG_LINETO:
                    System.out.println("line to (" + coords[0] + "," + coords[1] + ")");
                    break;
                case PathIterator.SEG_CLOSE:
                    System.out.println("close");
                    break;
                default:
                    System.out.println("to lazy to write other cases");
        static AffineTransform getScale(double sx, double sy, double tx, double ty) {
            AffineTransform xform = AffineTransform.getTranslateInstance(tx, ty);
            xform.scale(sx, sy);
            xform.translate(-tx, -ty);
            return xform;

  • Altering a Shape Object

    How do I modify the contents of an existing shape object? I'd like to insert, move and delete points. From what I've read in the docs I can only create a new shape from the PathIterator of the existing one and build in the point-changes there (I'm not talking about appending points to a GeneralPath - which is achieved through the lineTo() etc. methods).
    Any hints?
    Steffen

    I'm developing a CAD-type application and would therefore like to have vertex manipulation as in Paint Shop Pro for example.
    The actual purpose of that application is to export the drawings into SVG files.

  • Zooming in on objects

    I've read a few posts regarding the question of how to make sure objects don't disappear when zooming in. The suggestion is that a low front clip distance (i.e., setFrontClipDistance()) will make that happen. I have played around with that with some improvement, but I still get some objects to disappear.
    My zooming is done by resetting the scale...is there something I should or should not be doing here? For what it's worth, here are some relevant snippets of code.
    In my method for creating the universe
    universe = new VirtualUniverse();
    parentLocale = new Locale( universe );
    viewplatform = new ViewPlatform();
    viewplatform.setActivationRadius( 5000.0f );
    // sceneGraph.addChild(viewplatform);
    view = new View();
    view.setVisibilityPolicy( View.VISIBILITY_DRAW_VISIBLE );
    PhysicalBody physicalbody = new PhysicalBody();
    PhysicalEnvironment physicalenvironment = new PhysicalEnvironment();
    view.setPhysicalBody( physicalbody );
    view.setPhysicalEnvironment( physicalenvironment );
    view.addCanvas3D( canvas );
    view.attachViewPlatform( viewplatform );
    viewGraph = new BranchGroup();
    ...a VisTransformGroup extends TransformGroup
    viewTransform = new VisTransformGroup( "Global Transform" );
    viewTransform.setScreenCenter(new Vector3d(0.,0.,0.));
    viewGraph.addChild( viewTransform );
    viewTransform.addLast( viewplatform );
    view.setFrontClipPolicy( view.VIRTUAL_SCREEN );
    view.setBackClipPolicy( view.VIRTUAL_SCREEN );
    view.setBackClipDistance( 3000.0 );
    view.setFrontClipDistance( -30.0 );
    viewGraph.setCapability( Node.ALLOW_AUTO_COMPUTE_BOUNDS_READ );
    ...I create a global TransformGroup, called scaleTG
    // Scale
    Transform3D scale = new Transform3D();
    scaleTG = new TransformGroup(scale);
    the zoom method modifies the scale transformation...
    public void zoom(int value) {
          Transform3D rotTrans = new Transform3D();
          rotateTG.getTransform(rotTrans);
          Transform3D translation1 = new Transform3D();
          translation1.setTranslation(screenCenter);
          double sfactor = 1.0 + Math.abs(value) / 200.0;
          if (value > 0) {
             sfactor = 1.0 / sfactor;
          Transform3D scale = new Transform3D();
          scale.setScale(sfactor);
          Transform3D translation2 = new Transform3D();
          screenCenter.negate();
          translation2.setTranslation(screenCenter);
          screenCenter.negate();
          Transform3D lastTransform = new Transform3D();
          scaleTG.getTransform(lastTransform);
          VisTransform3D curTransform = new VisTransform3D(
                "CurrentWorkingTransform");
          curTransform.mulInverse(rotTrans);
          curTransform.mul(translation1);
          curTransform.mul(scale);
          curTransform.mul(translation2);
          curTransform.mul(rotTrans);
          curTransform.mul(lastTransform);
          scaleTG.setTransform(curTransform);
          Vector3d vScale = new Vector3d( );
          curTransform.getScale( vScale );
          onScale( vScale );
       }

    Your objects will disappear regardless if your view platform is moved between them and the center point. One thing you can do is move the center point to the region of interest.

  • Unwanted drop shadow showing up on shape objects - BUG?

    Hi all,
    I am currently using photoshop cc 2014 and pasting vector objects in as a "Shape Layer" - for some reason a shadow is showing up around every object i create since i upgraded to cc 2014 but it is NOT a layer style. How do i remove this? is it a graphics issue or processor issue? Does anyone know the settings to allow me to create shapes with sharp edges?
    Any help would be greatly appreciated

    I'm running into a similar problem. I've pasted a shape from illustrator as a vector smart object. When I have a green rectangle below it, there is no drop shadow. But when I hide that layer, the drop shadow clearly shows above the white background.
    It appears to be controlled by the global light under layer styles, but I can't turn it off even when "Drop Shadow" is unclicked.
    Drop shadow clearly showing, even when it's unclicked in Layer Style.
    No Drop Shadow showing when there is a green rectangle underneath.
    Drop Shadow appears over white Background when the green rectangle is turned off.
    Drop Shadow appears to be controlled by Global Light, but there seems to be no way of turning it off.
    What am I missing here? Any help would be awesome. Thanks!

  • Can not Group text and shape/object

    I have previously made frequent use of grouping text and objects or images together. But in Keynote 4.0.2 this is not possible (for me at least). I am able to lock multiple images, but the group, mask and alpha buttons are not active when selecting a combination of the two (text and objects). Images or objects can be grouped together. Is this a bug or what ?

    Open a NEW presentation (it should default to the Title and Subtitle slide of the theme)
    Type some text into the Title
    Insert a shape (square)
    Select the shape and the Title
    You should see that you cannot group anything with either the Title or Subtitle object of a slide. If you want to group text to an object, you have to create a new text object. Would this describe your inability to group (ie. limited to when you have Title/Subtitle selected?)

  • Zoom 100%, Shape Tool Appears on Fraction of Pixel

    This has been an issue for a while since the shape tool got a major refactoring and was hoping that this would have been fixed by now, but since it hasn't I want to make sure this issue is known and people are aware.
    This used to be default behavior (before CC and CS6):
    When you were zoomed out to 100% and used a vector tool (shape tool), you could draw anywhere and the edges would be aligned on pixels by default because if you are zoomed out to 100% you literally cannot click on a fraction of a pixel.
    Since there is now the "snap vector tools and transforms to pixel grid" option, yes you can automatically snap to pixels, but you should still be able to have vector tools line up on the pixels when zoomed to 100% and have snap turned off. I do not understand why this change was made.
    Article regarding CS4/CS5 in how to align shape tools perfectly: If you have Snap to Pixels turned off, drawing at 100% zoom achieves the same result.
    Source: http://bjango.com/articles/roundrect/

    You need to file a bug report using https://bugreport.apple.com/ to make sure this is tracked by a specific bug report at Apple.
    You will need to convert your Apple ID account into a developer account, but you can sign up for free as a Safari developer here:  https://developer.apple.com/devcenter/safari/
    Information that will be useful:
    A list of all devices and iOS versions that this bug reproduces on.
    A list of all devices and iOS versions that this bug does NOT reproduce on.
    Attach a (reduced) stand-alone test case to the bug report.
    Looking at the web page briefly in Web Inspector from Safari 7.0 on Mavericks (Safari 6.1 on Lion/Mountain Lion would also work), there is a <canvas> element that's position: absolute that is being used as a background for the page.  Because this element is positon: absolute, it's put into a layer.  And because it's behind all the other content on the page, it puts everything else into a layer as well.  As seen on the Safari 6.1/7.0 Web Inspector when loaded in Safari 7.0 for Mavericks:
    Layers use a lot of memory, which is why Safari on iOS 7 crashes due to lack of memory when zooming back out--layers must be recreated at each zoom level.
    This is still a valid bug, but finding an alternate way to paint the background (using a repeating background image with CSS) would make the page use much less memory-intensive.  You can verify that there are fewer layers on the page after changing (or removing) the canvas element, and Safari for iOS should stop crashing on zoom out.

  • Auto-zoom to selected object?

    I have a mystery ghost path that I can't find. It shows up in the layer palette. But I can't see it on my artboard. I have Show Bounding Box and Show Edges turned on. I alt/option click the layer to select everything. But there's nothing selected on my artboard. (And my artboard is sized to fit artwork bounds).
    Are there any scripts to auto-zoom/scroll the canvas to a selected object? Most 3D apps have a "Frame Object" command that moves and zooms the camera to make the selected object centered on the screen. Is there something like that for Illustrator?

    I don't think so. Just lock down anything you want to keep, Select All, and hit delete. The phantom guide should go away.

  • How to draw a border around shape objects?

    How would I draw a border around something like an Ellipse2D object? I tried using using a BasicStroke in a sub-class of Ellipse but nothing showed.

    nvm, figured it out, I wasn't calling the draw method :)

Maybe you are looking for