Resizing et moving Components with aspect ratio constraint

hi all
i m creating a GUI application and i need to manipulate components in an internal fram .
thoose components must be moved and resized with the mousse with the constraint of aspect ratio keep
thx for your help

real thxno problem morfus
Don't know whether you've come up with anything, but I got bored and implemented it. Resizeable has been changed so now you can set an aspect ratio on it, either an angle or x and y lengths
package tjacobs.ui;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
//For testing
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
* tjacobs.ui.Resizeable<p>
* Makes a component resizeable. Does not work if there's a layout manager
* messing with things<p>
* <code>
*  usage:
*                 Component c = ...
*                 new Resizeable(c);
*                 parent.add(c);
*  </code>
public class Resizeable extends MouseAdapter implements MouseMotionListener {
     int fix_pt_x = -1;
     int fix_pt_y = -1;
    Component mResizeable;
     Cursor mOldcursor;
     private Double mAspectRatio;
     public Resizeable(Component c) {
          mResizeable = c;
          c.addMouseListener(this);
          c.addMouseMotionListener(this);
     public void setMaintainAspect(double x, double y) {
          setMaintainAspect(new Double(Math.atan2(y, x)));
     public void setMaintainAspect(Double angle) {
          mAspectRatio = angle;
     public void mouseEntered(MouseEvent me) {
          setCursorType(me.getPoint());
     private void setCursorType(Point p) {
          boolean n = p.y <= WindowUtilities.RESIZE_MARGIN_SIZE;
          boolean s = p.y + WindowUtilities.RESIZE_MARGIN_SIZE >= mResizeable.getHeight();
          boolean w = p.x <= WindowUtilities.RESIZE_MARGIN_SIZE;
          boolean e = p.x + WindowUtilities.RESIZE_MARGIN_SIZE >= mResizeable.getWidth();
          if (e) {
               if (s) {
                    mResizeable.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
                    return;
               mResizeable.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
               return;
          if(s) {
               mResizeable.setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
               return;
     public void mouseExited(MouseEvent me) {
          if (mOldcursor != null)
               ((Component)me.getSource()).setCursor(mOldcursor);
          mOldcursor = null;
    public void mousePressed(MouseEvent me) {
          Cursor c = mResizeable.getCursor();
          Point loc = mResizeable.getLocation();
          if (c.equals(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR))) {
               fix_pt_x = loc.x;
               fix_pt_y = loc.y;
               return;
          if (c.equals(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR))) {
               fix_pt_x = loc.x;
               fix_pt_y = -1;
               return;
          if (c.equals(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR))) {
               fix_pt_x = -1;
               fix_pt_y = loc.y;
               return;
     public void mouseReleased(MouseEvent me) {
          fix_pt_x = -1;
          fix_pt_y = -1;
     public void mouseMoved(MouseEvent me) {
          setCursorType(me.getPoint());
     public void mouseDragged(MouseEvent me) {
          Point p = me.getPoint();
          int width = fix_pt_x == -1 ? mResizeable.getWidth() : p.x;
          int height = fix_pt_y == -1 ? mResizeable.getHeight() : p.y;
          if (mAspectRatio == null) {
               mResizeable.setSize(new Dimension(width > 1 ? width : 1, height > 1 ? height : 1));
          else {
               //do something
               double distance = Math.sqrt(width * width + height * height);
               width = (int) (distance * Math.cos(mAspectRatio));
               height = (int) (distance * Math.sin(mAspectRatio));
               mResizeable.setSize(new Dimension(width > 1 ? width : 1, height > 1 ? height : 1));
     //For Testing
     public static void main(String args[]) {
          JPanel jp = new JPanel();
          JButton jb = new JButton("hello");
          JButton jb2 = new JButton("hello2");
          jp.setPreferredSize(new Dimension(300,300));
          jp.setSize(300,300);
          jp.setLayout(null);
          jp.add(jb);
          jp.add(jb2);
          jb.setSize(20,20);
          jb.setLocation(2,2);
          jb2.setSize(30,20);
          jb2.setLocation(30,10);
          new Resizeable(jb);
          Resizeable r = new Resizeable(jb2);
          r.setMaintainAspect(30, 20);
          JFrame jf = new JFrame();
          jf.add(jp);
          jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);
          jf.setLocation(100,100);
          jf.pack();
          jf.setVisible(true);
}

Similar Messages

  • CS 6 Shift-Circle with Aspect Ratio Correction

    In PhotoShop CS 4 & 5.5, with a NTSC D1, 720x 486 document, a Pixel Aspect Ratio of D1.DV NTSC (0.91), and ellipse options set to unconstrained, with Aspect Ratio Correction Turned on, to draw a perfect Circle, you could hold Shift-option-cmd and you'd get a perfect Circle.
    In PhotoShop CS 6, the circle is streched to the top and bottom when I do a shift-Drag to draw a circle in a non-square Pixel document with Aspect Ratio Correction turned off.
    So, at this point, In a Non-Square Pixel document, There's no way to draw a perfect circle.
    What's changed between 5.5 and 6?? Is there a Preference somewhere that I've missed???
    TIA
    jamie

    Looking into this a little more, what I think is going on is that in previous versions, Shift dragging compensated for the non-square pixels, so that drawn items show up correctly.  If you look at the Info Box in 5.5 when shift drawing a circle, the height is greater then the width, when working in a non-square document.
    In 6.0, when you do the same thing, the height and width are the same. So, no compensation is being done for the non-square pixels.
    In 5.5, if you place a circle by entering the dimensions in the ellipse option, say 400, by 400, with PAR turned on, the image is squeezed side to side.
    So, In 5.5 Shift Compansated for nonSquare pixels. In CS6, it does not.

  • Please help with Aspect Ratio Setting

    I shot video with my MiniDV camera switched to 16:9 (my normal is 4:3)
    Editing the footage in Final Cut, the Sequence Setting, Aspect Ratio says NTSC DV 3:2
    I sent a clip to Motion to make a lower 3rd. I had to change my Motion Project Properties> Pixel Aspect Ratio> to NTSC D1/DV Anamorphic so the footage would look wide.
    When I export the lower 3rd clip and bring it into Final Cut timeline it doesn't look right. It looks right in the Viewer but not the timeline? Any suggestions

    Well, I guess I thought the video in Motion needed to look more rectangle (16x9) than square (4:3). Since it did in FCP. And my FCP sequence setting>Aspect Ratio says NTSC DV 3:2
    I am used to working with plain MiniDV 4:3. I shoot with Sony PD150. I don't understand or never had to deal with Aspect Ratios. This project they wanted a widescreen look so I switch the camera to 16x9.
    I don't think it is the real 16x9 but like I said I don't know about this stuff or why my camera has 16x9 on in if it is not the real thing.
    Feel free to comment, I am trying to learn

  • Help with aspect ratio and resolution nightmare

    I am currently working on a documentary and all the footage I was given are in different formats an resolutions. Some are in 720 x 480 others in much larger aspect ratios. Some are standard SD some are HD
    is there any way to conform all of these together, or any tips? what about exporting? any help would be appreciated.
    thanks

    What's your final delivery format?
    What I do, and I usually have some HDV to mix with DV is to put everything on a ProRes 422 sequence with the setting to the highest resolution I have to start with (usually HDV 1440x1080) but I don't let FCP automatically change the time line or covert anything until I do a render. Then I finally do a render all and FCP up rezzes stuff when it renders. I use very little of the DV stuff (it's a backup when I need something that the HDV cams didn't video the way I need, such as both HDV cams moving to a point of view at the same time).
    If you don't need to intercut the various pieces (that is, if you can edit each one as an individual piece in its owns sequence, then just stitch them together end to end at the end), then I create each one in its own sequence, and let FCP change the sequence settings when I drop the video into it. Then I stitch it together when I get ready to make the DVD.
    My DVD's are all SD, so I use compressor to downrez and compress: then they are all in the same resolution, etc. and I stitch it together in DVD SP as stories, or just drop them into the same video line, end to end.
    Eddie O

  • Complete Confusion with Aspect Ratio...

    My movie is 4:3
    original DV File: 568 x 576
    importing to Event and Project gives: 720 x 576
    Then exporting with E - overview gives a to expected result: 768 x 576
    The Final result in Quicktime finally is - oh wonder: 787 x 576
    hmmm, my question is:
    For the website i need a width of 580 or 588. resizing in Compressor or Quicktime MP4 export also gives different results...
    Can someone tell me the best setting, and by the way: at which stage i get rid of these ugly interlacing lines?
    When all done i move on to 16 : 9 - wish me luck...
    My videos are on http://www.drummerworld.com
    Bernhard

    DV has this weird thing: pixels aren't square. That is why, although PAL DV actually has 720x576 pixels, like Tom said, the correct 4:3 aspect ratio corresponds to 768x576 (I'm sure 568 was a typo, Bernhard meant 768).
    If you do a "get info" on a DV movie in Quicktime Player you may get something like this:

  • Panasonic sdr-s150 / problem with aspect ratio

    Hi all,
    I'm about to purchase the sdr-s150 as it fits my needs regarding size vs. picture quality. Before doing so I wanted to make sure that footage from the camera can be edited with the all new imovie 08. And here's my problem with that.
    I downloaded some 16:9 sample footage out of the internet and imported this into imovie 08. The icons imovie creates in the import and project areas are all looking good regarding aspect ratio. In the project settings I choose aspect ratio 16:9 and 'fit to frame' (don't know the exact setting in the english version) for the clips being added to the projects.
    The preview of the clips and final export know shows black bars at top and bottom and the footage ist squeezed together.
    I already tried sdcopy and ran the clips through this before importing into imovie 08. No change.
    Any ideas ? Please also feel free to comment on the quality of the footage of this camera once processed through imovie from your point of view.
    Thanks,
    JasperJunker.

    hey there Derek100,
    i've experienced the same thing w/ FCP & iMovie (in NTSC). it's that the FCP easy set-up is "anamorphic", which is a 4:3 image made to appear as 16:9 & so that is how FCP works w/ the image. i really have no other explanation. i suppose if you create a custom set-up, you could eliminate the bars @ the top & bottom. there should be something in the Manuals, though i don't know where--i've never looked. sorry not to be of more help, but now i'm gonna investigate for myself.
    good luck.

  • Problems with aspect ratio metadata filtering, am I doing things wrong?

    Hi,
    I tried to filter out all my pictures in a collection that has a portrait aspect ratio but LR is doing it all wrong.
    As you can see, there is a mix of landscape and portraits even though portrait is filtered.
    I tried to look at some of my other collections and see if this was an isolated issue but found that I have the problem here and there.
    Found this example:
    Even though the dimensions in the EXIF-info on the right says 3456x2304, LR thinks that the picture is square.
    Could I be doing something wrong here or could I somewhere help LR on the way or is it a bug of some sort? I'm using LR 3.3 on a Mac with Mac OS 10.5.8
    Thanks in advance,
    -Jimmy

    Many thanks. Didn't think of that but I cropped all the wrong pictures to landscape and then did a reset to the crop and that did the trick. There were almost 4000 pictures wrong so I'm glad that I could use the auto-sync feature to do it faster.
    -Jimmy

  • Cam Optia problem with aspect ratio.

    Hello, i bought a subject camera today. And when i try to chat with my friend through some online services, which capture image from cam with 76x44 resolition my friend see video picture with incorrect aspect ratio (stretched up and down).
    Also i have similar problem with 352x258 resolution.
    How can i solve this problem?
    P.S. My friends, that have another camera, didn't face to this problem.
    Thank to all!

    Any capture shots to see?

  • Resizing Image and Not Keep Aspect Ratio

    Is there a free program to resize images and not keep the original aspect ratio?
    I need to resize loads of images to 100x100 pixels and have tried Image well and IResize yet they do not seem to have an option to not keep the original aspect ratio.
    Thank you
    20" Intel 2GHz Core Duo imac, 2GB Ram, 250 GB HD    

    Hi, Downsize does not seem all that great according to reviews. Why not see if you can buy PS E' 3 mac -- maybe ebay/amazon (if I remember I only paid about $70 for PS E3) As PS E4 just came out I'm sure someone has PS E3 for sale. You will then have no problems completing your image resizing.
    2 other questions for you..are you using the Mac side of your intel or Windows?
    if your using the Windows side I can let you have PS 6 (PC) ..freegratus.

  • TROUBLE WITH ASPECT RATIO

    USING PE7. CAM 1 AND 2 SHOT WITH 16/9 RATIO. THE CAPTURED IMAGES FROM BOTH
    CAMERAS DISPLAY EXAGGERATED WIDTHS, EVERYBODY LOOKS 50 LBS FATTER THAN THEY ARE. I'VE TRIED CAPTURING IN 3 OTHER PROGRAMS-SAME RESULT.
    CAM 1 IS A CANON GL2. IT COMPRESSED THE IMAGE DURING RECORDING TO FIT A 4:3.
    THE EDITING PROGRAMS "SEE" THE 4:3 AS A 16/9 COMPRESSED FORMAT AND AUTOMATICALLY DISPLAY 16:9.
    CAM 2 IS A 2007 HITACHI HD. IT DEFAULTS TO A 16:9. LOOKS GOOD ON THE ON-BOARD SCREEN WHEN SHOOTING BUT ON PLAYBACK LOOKS FAT ALSO.
    I DUMPED THE FILES ONTO A DVD TO TRY ON THE TV. SAME FATS. WHEN I CHANGE THE ASPECT RATIO ON THE TV MONITOR TO FORCE THE 16:9 BACK TO 4:3, THE LATTER SETTING LOOKS ABOUT RIGHT, NOT TOO SKINNY, NOT TOO FAT. THE PROBLEM IS THAT NOT EVERYBODY HAS A TV THAT CAN ADJUST THE AR AND THEY WOULD PROBABLY JUST THINK THAT THESE PEOPLE ARE ALL ON HIGH-CALORIE DIETS.
    WHAT DO I DO NOW? I NEED A PROGRAM THAT I CAN ADJUST THE ASPECT RATIO TO GET EVERYBODY'S WEIGHT REDUCED FAIRLY.
    IS THERE ANYBODY OUT THERE THAT CAN HELP?
    HOWIE
    [email protected]

    If you have recorded in widescreen you need to work in a widescreen project. Did you select a widescreen project preset at start up?
    If so and you still have the problem then the other thing to look at is to right click on the clip in the project Media Bin and select Interpret Footage. Then in Conform To select the appropriate widecscreen preset.

  • Resize flash movie while maintaining aspect ratio?

    Hey all,
    We have created an extremely content heavy .swf file (1900 x
    1400) for a presentation that runs full screen on a monitor at a
    screen resolution of 1900 x 1400. I think that was the
    resolution... I've been away from the project for a while and I
    can't remember. anyways....
    now we need to shrink the .swf down to a more reasonable size
    so that we can make a cd rom out of it. Probably needs to be shrunk
    to about 800 x 600. Is there an easy way to shrink the .swf in
    flash from 1900 x 1400 to 800 x 600 while maintaining aspect ratio
    and keeping all items on stage?
    I sure hope so! I'd hate to have to recreate the entire
    thing! It was a HUUUGE project with a ton of content.
    Thanks in advance for any help or suggestions!!!!

    Hey all.... I am just now working on this project.
    I've created my .fla file and I'm trying to load a .swf into
    an empty movie clip. It didn't scale down like I want it to and it
    was still appearing as the normal size file. So I added the
    container._height = 500; and container._width = 800; When I added
    the width and height the .swf inside the empty mc container
    disappeared!!!!! Any idea why???
    Here is my code:
    stop();
    this.createEmptyMovieClip("container",
    this.getNextHighestDepth());
    loadMovie("hlhuntyears.swf", container);
    container._width = 800;
    container._height = 500;
    container._x = 0;
    container._y = 0;
    I export it as an .exe since its going to be a cd rom and
    when I double click the .exe to run it I get a blank screen. But
    when I take out height and width it shows up but not to the correct
    scale. The original file (hlhuntyears.swf) is 1440 x 900 and when I
    run the .exe I can only see a tiny piece of it. Can anybody help??
    please??

  • Working with Aspect Ratio to DVD - 800x600 projector vs. 720x480 DVD player

    Hi there and thanks for reading. I don't post on this community often, so if there is better place for this question please point me there.
    First a little about my project: I'm a student of fine arts and my current work involves the use of a projector and 2d and 3d objects. Projection mapping, or video mapping has been a budding art form for quite some time, but I do not use any of the current software applications that would be best for the medium. My current process begins by setting up a physical 2d or 3d composition in my studio space and projecting my PC desktop onto the scene with a common classroom style projector. I begin "mapping" objects in my studio with Illustrator, and then import my project to After Effects in order to animate my composition. If I set my project resolution to something that doesn't match my projector resolution and go to full screen, my software composition will not match my physical composition. After my project is complete and I'm ready to show visitors, I'll export a video and set it to loop.
    For some time now I've been trying to work out a set of best practices so that my projects are clear and precise. Even the slightest bump and everything in the video mapping falls apart. Since my projector shoots a native 3:4 aspect ratio, and has a resolution of 800x600px, I set my Illustrator document size to the same. When I work in After Effects, I set my composition to the same res. and I make sure my settings are accurate when I go to export a video (typically h.264 format since I'm used to using my computer for playback).
    My current problem involves exporting my project for playback on a DVD player. As far as I know, the best format for DVD playback is mpeg2-DVD. This format demands that I convert to 720x480px - which is not in accordance with my projector. Can this problem be solved with After Effects composition or export settings?
    Any ideas, tips, or links that might be of help are greatly appreciated!

    It depends entirely on what the projector does with the signal it receives.  Most projectors will simply scale an incoming standard def signal to fill the entire frame.  In which case, I'd simply author your project in 4:3 standard def (720x480), make sure the resulting DVD is 4:3 formatted, and that should do it.

  • Working with aspect ratio from fcp to dvd sp

    I am trying to cut video for use in a dvdsp menu. I have converted video to m2v using compressor. Video looks fine when importing to dvdsp. I try to edit same file in fcp. Everything works except when I export. After I edit m2v in fcp I am unable to make a successful export to dvdsp. I am able to import and add it to menu but the video looses its aspect ratio and is stretched.

    Very true!
    But there are more cows on the loose here.
    For example, the QuickTime Player Pro ( with its MPEG-2 Playout Component) will always report a square- pixel size of a .m2v file. But this is just reflecting the window size that QT decided to scale the 720x480 (or 720x576) to, because the inability for a computer screen to display non-square pixels.
    So it can say that an MPEG-2 file is 640x480 when it is in fact 720x480. Even worse it can tell you 720x404 or 720x540, while none of them are even technically possible to use in MPEG-2.
    It is true also that BitVice (1.8x and 2.x) allows you to encode all MPEG-2 legal picture sizes up to and including 720x576, a.k.a MP@ML ( or just SD). However, only a very few of them are legal for DVD, for example, NTSC:
    720x480
    704x480
    352x480
    352x240
    and PAL
    720x576
    704x576
    352x576
    352x288
    Roger Andersson / Innobits AB, makers of BitVice MPEG-2 Encoder
    As per Apple Discussions Terms of Service:
    "I may receive some form of compensation, financial or otherwise, from my recommendation or link."

  • Having trouble with aspect ratio when compressing DVCPRO HD footage to QT

    I have a 35mm film (1.85-1 aspect ratio) converted to 16/9 DVCPRO HD. When I compress it to Mpeg2 for DVD, it looks great, holds the correct aspect ratio. But when I choose a setting for the web, a small Quicktime file, it stretches the image ever so slightly. Not sure what the problem is. Thanks for the help.

    Hey Lodgeboy,
    without knowing the settings you are using, it is difficult to help, but i will try to answer as best i can:
    if you are using web-presets, make sure you crop the matte, NOT resize the file.
    Basically, instead of letterboxing OR creating am anamorphic MPEG2 for DVD (still in the 720x480 space) you would first crop the mattes off and then resize.
    In the case of a web-file, it doesnt matter what order you process the file, EXCEPT if its for IPTV.
    Without knowing details about what your final deliverable is, the source and the settings, this is as much as i can help you.
    Mikey M.

  • Problems with aspect ratios on export

    Details:
    CS4 PPro with all current updates
    Win 7 64bit machine
    Editing using the DV NTSC widescreen 48kHz sequence settings. Pixel aspect ratio 16:9 (1.21)
    All of my graphics and video looks fine in the preview window as you can see in this screen capture. That logo is round.
    Here's where the problem arises, when I export it to Adobe Media encoder it also appears to look ok.
    But once the clip is exported and I playback the .mov file the video is squeezed and the logo is now oblong.
    Not sure what to do as I've edited this entire video and do not have time to start over from scratch.
    Here's the screen capture of the file in Quicktime. It does the same thing if I export it as an avi and play it in WMP.
    Any help would be appreciated.

    Here is the workflow to sort this out.  (Note : QTPro)
    Open your mov in QT Pro
    Show Movie Properties (Ctrl-J)
    Click on Video Track
    Click on Visual Settings Tab
    Un check the Preserve Aspect Ratio box
    (Here is where you now need to do some math to change the 4x3 to 16:9 ratio) 16 divided by 9 = 1.7777 (1.78 is close enough)
    Divide the Vertical Pixel Dimension by 1.78 and enter the result in the Vert Dimension box
    Ensure the Preserve Aspect Ratio box is UNCHECKED
    Hit Tab key and notice the image in the QT window change.
    In the QT Window Menu - File>Save
    Heres an example:
    QT movie Original is 320x240
    Divide 240 x1.78 ( ie. 240/1.78=134)
    Note- It is important to SAVE. This process is only changing the Header flag info in the QT file.
    Bingo!

Maybe you are looking for