Scroll Handling : Animation « Advanced Graphics « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Advanced Graphics » AnimationScreenshots 
Scroll Handling
Scroll Handling

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import no.geosoft.cc.geometry.Geometry;
import no.geosoft.cc.graphics.*;



/**
 * G demo program. Demonstrates:
 *
 * <ul>
 * <li>Custom move interaction
 * <li>Switching interactions
 * <li>Update world extent geometry
 * <li>Scroll handling
 * </ul>
 
 @author <a href="mailto:[email protected]">Jacob Dreyer</a>
 */   
public class Demo11 extends JFrame
  implements ActionListener, GInteraction
{
  private JButton   zoomButton_;
  private JButton   moveButton_;
  private GWindow   window_;
  private GSegment  interactionSegment_;
  private int       x0_, y0_;

  
  public Demo11()
  {
    super ("G Graphics Library - Demo 11");    
    setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    
    getContentPane().setLayout (new BorderLayout());
    
    // Create the GUI
    JScrollBar hScrollBar = new JScrollBar (JScrollBar.HORIZONTAL);
    getContentPane().add (hScrollBar, BorderLayout.SOUTH);

    JScrollBar vScrollBar = new JScrollBar (JScrollBar.VERTICAL);
    getContentPane().add (vScrollBar, BorderLayout.EAST);

    JPanel buttonPanel = new JPanel();
    zoomButton_ = new JButton ("Zoom");
    zoomButton_.addActionListener (this);
    buttonPanel.add (zoomButton_);
    
    moveButton_ = new JButton ("Move");
    moveButton_.addActionListener (this);
    buttonPanel.add (moveButton_);    
    getContentPane().add (buttonPanel, BorderLayout.NORTH);
    
    // Create the graphic canvas
    window_ = new GWindow();
    getContentPane().add (window_.getCanvas(), BorderLayout.CENTER);
    
    // Create scane with default viewport and world extent settings
    GScene scene = new GScene (window_);

    // Use a normalized world extent
    double w0[] {0.00.00.0};
    double w1[] {1.00.00.0};
    double w2[] {0.01.00.0};
    scene.setWorldExtent (w0, w1, w2);
    
    // Create a graphic object
    GObject object = new TestObject();
    scene.add (object);

    pack();
    setSize (new Dimension (500500));
    setVisible (true);

    window_.startInteraction (new ZoomInteraction (scene));

    scene.shouldWorldExtentFitViewport (false);
    scene.shouldZoomOnResize (false);    
    scene.installScrollHandler (hScrollBar, vScrollBar);
  }


  public void actionPerformed (ActionEvent event)
  {
    if (event.getSource() == zoomButton_)
      window_.startInteraction (new ZoomInteraction (window_.getScene()));
    else
      window_.startInteraction (this);
  }


  
  // Move interaction
  public void event (GScene scene, int event, int x, int y)
  {
    switch (event) {
      case GWindow.BUTTON1_DOWN :
        interactionSegment_ = scene.findSegment (x, y);
        x0_ = x;
        y0_ = y;
        break;
        
      case GWindow.BUTTON1_DRAG :
        int dx = x - x0_;
        int dy = y - y0_;
        if (interactionSegment_ != null) {
          TestObject testObject = (TestObjectinteractionSegment_.getOwner();
          testObject.translate (interactionSegment_, dx, dy);
          scene.refresh();
        }
        x0_ = x;
        y0_ = y;
        break;

      case GWindow.BUTTON1_UP :
        interactionSegment_ = null;
        break;
    }
  }
  
  
  
  /**
   * Defines the geometry and presentation for a sample graphic object.
   */   
  private class TestObject extends GObject
  {
    private GSegment[] stars_;
    private double[][] geometry_;
    
    
    TestObject()
    {
      int nStars = 20;

      stars_    = new GSegment[nStars];
      geometry_ = new double[nStars][];
      
      for (int i = 0; i < nStars; i++) {
        stars_[inew GSegment();
        stars_[i].setUserData (new Integer(i));
        addSegment (stars_[i]);
        
        double[] xy = Geometry.createStar (Math.random(), Math.random(),
                                           0.050.120);
        geometry_[i= xy;

        GStyle style = new GStyle();
        style.setForegroundColor (new Color ((floatMath.random(),
                                             (floatMath.random(),
                                             (floatMath.random()));
        
        style.setBackgroundColor (new Color ((floatMath.random(),
                                             (floatMath.random(),
                                             (floatMath.random()));
        style.setLineWidth (2);
        stars_[i].setStyle (style);
      }
    }


    // Convert the world extent geometry of the specified
    // segment according to specified device translation
    public void translate (GSegment segment, int dx, int dy)
    {
      GTransformer transformer = getTransformer();
      double[] dw0 = transformer.deviceToWorld (0,  0);
      double[] dw1 = transformer.deviceToWorld (dx, dy);      

      int index = ((Integersegment.getUserData()).intValue();
      double[] geometry = geometry_[index];
      for (int i = 0; i < geometry.length; i += 2) {
        geometry[i + 0+= dw1[0- dw0[0];
        geometry[i + 1+= dw1[1- dw0[1];        
      }

      segment.setGeometryXy (geometry);              
    }

  
    public void draw()
    {
      for (int i = 0; i < stars_.length; i++)
        stars_[i].setGeometryXy (geometry_[i]);        
    }
  }
  


  public static void main (String[] args)
  {
    new Demo11();
  }
}

           
       
G-Scroll-Handling.zip( 192 k)
Related examples in the same category
1. Simple animation techniqueSimple animation technique
2. Custom move interaction, Switching interactions, Update world extent geometry and Scroll handlingCustom move interaction, Switching interactions, Update world extent geometry and Scroll handling
3. Curve AnimationCurve Animation
4. ClockClock
ww___w___.__j___a_v_a__2__s.___c__o__m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.