Geometry onjects,zoom in or out,how to design?

I have plotted a composite geometry onject that has many polygons.
I want add one button event. Once I click it, the object will be zoom in or out,
What is the idea of it?
Thanks

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.Hashtable;
import javax.swing.*;
import javax.swing.event.*;
public class CompositeZoom extends JPanel implements ChangeListener {
    GeneralPath path;
    double scale = 1.0;
    public void stateChanged(ChangeEvent e) {
        int value = ((JSlider)e.getSource()).getValue();
        scale = (value+4)/10.0;
        repaint();
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        if(path == null) initPath();
        Rectangle r = path.getBounds();
        double x = r.getCenterX()*(1.0 - scale);
        double y = r.getCenterY()*(1.0 - scale);
        AffineTransform at = AffineTransform.getTranslateInstance(x, y);
        at.scale(scale, scale);
        g2.draw(at.createTransformedShape(path));
    private void initPath() {
        int cx = getWidth()/2;
        int cy = getHeight()/2;
        int d = 40;
        int R = Math.min(cx,cy)/3;
        int[][] xy = generateShapeArrays(cx-d, cy-d, R, 3);
        Polygon p = new Polygon(xy[0], xy[1], 3);
        path = new GeneralPath(p);
        xy = generateShapeArrays(cx+d, cy-d, R, 5);
        p = new Polygon(xy[0], xy[1], 5);
        path.append(p, false);
        xy = generateShapeArrays(cx-d, cy+d, R, 7);
        p = new Polygon(xy[0], xy[1], 7);
        path.append(p, false);
        xy = generateShapeArrays(cx+d, cy+d, R, 6);
        p = new Polygon(xy[0], xy[1], 6);
        path.append(p, false);
    private int[][] generateShapeArrays(int cx, int cy, int R, int sides) {
        int radInc = 0;
        if(sides % 2 == 0)
            radInc = 1;
        int[] x = new int[sides];
        int[] y = new int[sides];
        for(int i = 0; i < sides; i++) {
            x[i] = cx + (int)(R * Math.sin(radInc*Math.PI/sides));
            y[i] = cy - (int)(R * Math.cos(radInc*Math.PI/sides));
            radInc += 2;
        // keep base of triangle level
        if(sides == 3)
            y[2] = y[1];
        return new int[][] { x, y };
    private JSlider getControl() {
        int min = 1, max = 16, inc = 5;
        JSlider slider = new JSlider(min, max, 6);
        slider.setMajorTickSpacing(5);
        slider.setMinorTickSpacing(1);
        slider.setSnapToTicks(true);
        slider.setPaintTicks(true);
        slider.setLabelTable(getLabelTable(min, max, inc));
        slider.setPaintLabels(true);
        slider.addChangeListener(this);
        return slider;
    private Hashtable getLabelTable(int min, int max, int inc) {
        Hashtable<Integer, JLabel> table = new Hashtable<Integer, JLabel>();
        for(int j = min; j <= max; j+=inc) {
            String s = String.format("%.1f", (j+4)/10.0);
            table.put(Integer.valueOf(j), new JLabel(s));
        return table;
    public static void main(String[] args) {
        CompositeZoom test = new CompositeZoom();
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(test);
        f.getContentPane().add(test.getControl(), "Last");
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
}

Similar Messages

  • How to design and have universal color correctness?

    I designed a label using Illustrator and Photoshop, but when I got it printed, the color came out different than the onscreen visual. How can I avoid having to adjust everything? I want to be able to take it anywhere and print it and it come out how I designed it.

    Hi Saravanan,
    In your view, you have to add the UI element TabStrip. You will have an empty tab strip then. Right click on the tab strip, and add a 'Tab'. Continue in this manner to add as many tabs as you want. Each tab will have a header, specify the tab title in that.
    Now go to each tab, right click and insert element. You could insert any element like a table, Input fields etc. Event handling has to be done separately for these elements. At the tabstrip level, you need to handle only the onTabSelect event. This is the event triggered when you change tab selection in the tabstirp. In the properties of the tab strip, there will be a field selectedTab. Specify the ID of the tab which you want as selected. This will be your initial selection.
    You can also enable and disable tabs, say grey out tabs that have no data etc. All this can be done by context attribute binding.
    You can also refer to the view  by name TABSTRIP in the component WDR_TEST_EVENTS.
    Regards,
    Uday

  • How do I zoom in and out on a clip using final cut pro 6?

    I have searched around and I haven't found anything about how to zoom in and out on non-still video. I am sure there is some simple explanation as of how to do this but I can't seem to find it. If you guys could help me out that would be great. Thanks.

    Double click the clip in the Timeline, to place it in the viewer.
    In the Viewer window click the Motion tab. Adjust the "Scale" control and set keyframes as needed.

  • How do I zoom in and out on my iPad videos

    How do I zoom in and out using my ipad video?

    Double click the clip in the Timeline, to place it in the viewer.
    In the Viewer window click the Motion tab. Adjust the "Scale" control and set keyframes as needed.

  • How do i turn off new zoom in and out function on IOS 7?

    Hi Apple support people
    How do i turn off the IOS 7 new zoom in and out function when opening and closing applications. The movement makes me sick and gives me a head ack when i use it.
    I can not find the option anywhere
    Thank you very much for your help

    I don't believe it can be totally disabled. Send feedback to Apple here:
    http://www.apple.com/feedback/

  • I just upgraded to the New OS on my Mac Book Pro and now my trackpad does not zoom in or out.  I looked at system settings on trackpad and it is set, but does not work How do I get it started?

    I just upgraded to the New OS on my Mac Book Pro and now my trackpad does not zoom in or out.  I looked at system settings on trackpad and it is set, but does not work How do I get it started?

    This is really unfortunate. I'm sorry that nothing works. I was going to mention holding down the power button and doing a force shutdown but you already did that. You might need to take it into the Apple store. I don't know if booting into safe mode would help. You would have to turn off the machine again, hit the start button and hold down the shift key after you hear the tone, but normally you would let go of the shift key when you see the apple logo and spining wheel. Maybe by holding down the shift key after you here the tone will cause the screen to come back on? The other option is to start up from the 'install disk' if your machine came with one. You would insert the disk, then shut down the computer, and hold down the C key right after hitting the start button.
    Here's the link for the safeboot
    http://support.apple.com/kb/HT1564?viewlocale=nl_nl

  • How to Zoom in and Out on PDF files in Safari?

    Safari help is not helpful since it gives inaccurate information on how to Zoom in and Out on a PDF file that has opened in Safari. The help says to control click the page and choose the zooming level you desire. However control clicking the PDF file in Safari brings up a save page box. I tried some of the other keys with clicking and they did not work. Thanks in advance to those who helped me save a PDF file to the desktop so I can view in Preview.- But often I just need to be able to zoom in to read the tiny text that is displayed.

    Thanks for getting back to me-
    the website I am trying to zoom into a PDF on is:
    http://www.beedocuments.com/software/Timeline/screenshots.html
    I click on one of the screenshots- it loads into a safari window.
    When I control key click on the image- a pop up menu comes up asking me to save the image to deskotp- add it my image library and 2 other save options. No zoom in or Zoom out. I only have an apple pro mouse and my track pad- so right clicking isn't an option.

  • Just bought Photoshop Elements 13...I'm trying to make a slideshow but can't figure out how to alter duration time that the slide is on the screen.  They presently move from one to another way too quickly...also need a different pan and zoom option.  Wher

    Just bought Photoshop Elements 13...I'm trying to make a slideshow but can't figure out how to alter duration time that the slide is on the screen.  They presently move from one to another way too quickly...also need a different pan and zoom option.  Where are all the options I had in PS10?  Also...Can I burn this to a DVD?

    The changes have brought improvements but also drawbacks compared with the old slideshow editor.
    The templates are now fairly fixed but I find the “Classic Dark” gives reasonable results with some panning and you can click the audio button and browse you PC for any track. Unfortunately there are only three speed choices linked to the music track. The improvement for most people is that you can now export to your hard drive at 720p or 1080p and upload to sites like YouTube and Vimeo.

  • I like the mail feature with one exception; I cannot figure out how to change the font size of incoming mail permanently.  And, when answering an email I have to highlight the first few words and zoom it so I can see what I am writing.  what am I missing?

    I like the mail feature with one exception; I cannot figure out how to change the font size of incoming mail permanently.  And, when answering an email I have to highlight the first few words and zoom it so I can see what I am writing.  what am I missing?

    You can type the email using what you set in preferences and then highlight the text and use command - minus sign (or command - + for larger) to reduce the size of the text.
    You can also type command - T and a window will appear allowing you to select fonts/sizes/color/ background highlight.
    The above works in Notes also. I haven't tried to do this in any other Apple application.
    For incoming emails, you can use the above to reduce font size, but I don't know of a way to permanently set the incoming font size to a default.

  • How do I get Photoshop to stop changing the page when I zoom in or out?

    I was wondering how to stop my screen in photoshop to not change the page when I zoom in or out. When I zoom in the page adjust and make the panel smaller. I would like to leave the screen ful size and just the image zoom in and out

    Argh! Don't you just hate that! I don't know why Adobe set that as default behavior. To stop it go to Photoshop Preferences > General and uncheck "Zoom Resizes Window"
    You can also hit the F key once to enter Full Screen Mode.

  • How do i zoom in or out to take a picture?

    How do I zoom in or out before taking a picture?

    You can not take pictures with iPhoto - is this by chance an iPhone question? on the iPhone you use two fingers to squeeze the photo and then use the zoom slider that appears at the bottom of the screen
    LN

  • How do i zoom in and out while videoing

    how do i zoom in and out while i am videoing

    There is no built-in zoom function for video.
    So, you can either quickly run closer to the subject to zoom in, and quickly run back to zoom out, or use an alternative video capture app, such as:
    http://itunes.apple.com/us/app/video-zoom-2/id406643501?mt=8#

  • How to zoom in and out on Ipad?

    how to zoom in and out on Ipad?

    You might want to read about the Accessibility features of the ipad.
    Apple - Accessibility - iOS
    iPad: Configuring accessibility features (including VoiceOver and Zoom)

  • Hello, i was wondering if you can help me figure out how to edit a video to zoom in and out with the beat of the music?

    Hello, i was wondering if you can help me figure out how to edit a video to zoom in and out with the beat of the music?

    Use markers on every beat.
    The edit the zoom/scale to the markers.
    Adobe Premiere Pro Help | Working with markers

  • My Mac has lost the keyboard command to zoom in and out (Apple/shift/ /-)  How can I restore this?

    My Mac has lost the keyboard command to zoom in and out (Apple/shift/ /-)  How can I restore this?

    try doing an SMC reset, the following article tells how to do this:
    http://support.apple.com/kb/HT3964
    also go into your keyboard options and make sure the settings are correct there.

Maybe you are looking for

  • How do I set the direction of the sync?

    How do I set the direction of the sync? I recall from days past that there was a window that let you choose whether to "upload" the info from your computer or "download" the info from the .MAC account. In this case I am trying to import my address bo

  • Offline backup using BRTools 7---- Backup_ device_ type disk

    Hi Markus & Gurus.when im trying to take offline abck up this is the error in facing . Can u help me in resolving htis. BR0051I BRBACKUP 7.00 (28) BR0055I Start of database backup: bdwmgkqt.afd 2007-10-30 14.16.03 BR0484I BRBACKUP log file: F:\oracle

  • Setting ranges as default values for a selection screen value

    i have a selection screen parameter s_yywrpc. For this s_yywrpc i have to set some range of values as default values. Can u tell me how can i do that . select-options:s_yywrpc for vbak-yywrpc. for this parameter i have to set MSPG, MSP, FMP, FMPG, CF

  • Currency Conversion in Update Rule greyed out

    Hi All, I searched this forum for what I thought something would have been reported on, but in the update rule for a key figure there is the option to input currency translation. The problem is it's greyed out and I cannot input the translation.  The

  • Hi, can we use 15 inch mac book pro dvd to macbook pro13

    hi, can we use 15 inch mac book pro dvd to macbook pro13