Annotation, Interaction and Transparent Color Scale : Interaction « Advanced Graphics « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Advanced Graphics » InteractionScreenshots 
Annotation, Interaction and Transparent Color Scale
Annotation, Interaction and Transparent Color Scale

import java.util.Collection;
import java.util.Iterator;
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>Annotation techniques
 * <li>Custom interaction
 * <li>Invisible lines with annotation
 * <li>Using transparent colors
 * <li>True scale resize
 * </ul>
 
 @author <a href="mailto:jacob.dreyer@geosoft.no">Jacob Dreyer</a>
 */   
public class Demo7 extends JFrame
  implements GInteraction
{
  private GScene      scene_;
  private GObject     interaction_;
  private GSegment    interactionSegment_;  
  private GObject     rubberBand_;
  private Collection  selection_;
  private int         x0_, y0_;
  
  
  /**
   * Class for creating the demo canvas and hande Swing events.
   */   
  public Demo7()
  {
    super ("G Graphics Library - Demo 7");
    setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    
    // Create the GUI
    JPanel topLevel = new JPanel();
    topLevel.setLayout (new BorderLayout());
    getContentPane().add (topLevel);        

    JPanel buttonPanel = new JPanel();
    buttonPanel.add (new JLabel ("Move mouse to highlight"));
    topLevel.add (buttonPanel,   BorderLayout.NORTH);

    // Create the graphic canvas
    GWindow window = new GWindow (new Color (100100100));
    topLevel.add (window.getCanvas(), BorderLayout.CENTER);    
    
    // Create scene with default viewport and world extent settings
    scene_ = new GScene (window, "Scene");

    double w0[] {-1.0, -1.00.0};
    double w1[] {10.0, -1.00.0};
    double w2[] {-1.010.00.0};
    scene_.setWorldExtent (w0, w1, w2);
    scene_.shouldWorldExtentFitViewport (false);
    scene_.shouldZoomOnResize (false);    
    
    // Create som graphic objects
    GObject testObject = new TestObject (scene_);
    scene_.add (testObject);

    rubberBand_ = new GObject ("Interaction");
    scene_.add (rubberBand_);
    
    pack();
    setSize (new Dimension (500500));
    setVisible (true);
    
    window.startInteraction (this);
  }


  
  public void event (GScene scene, int event, int x, int y)
  {
    switch (event) {
      case GWindow.MOTION :
        double[] w = scene_.getTransformer().deviceToWorld (x, y);

        if (w[0|| w[0|| w[1|| w[18)
          interaction_.removeSegment (interactionSegment_);
        else {
          interaction_.addSegment (interactionSegment_);
          interactionSegment_.setGeometry (Geometry.createCircle (x, y, 30));
        }

        scene_.refresh();          
    }
  }
  
  

  
  /**
   * Defines the geometry and presentation for the sample
   * graphic object.
   */   
  private class TestObject extends GObject
  {
    private GSegment[]  fields_;
    private GSegment[]  labels_;

    /**
     * As a rule of thumb we create as much of the object during
     * construction as possible. Trye to do geometry only in the
     * draw method.
     */
    TestObject (GScene scene)
    {
      GStyle black = new GStyle();
      black.setFillPattern (GStyle.FILL_SOLID);
      black.setForegroundColor (new Color (000));

      GStyle white = new GStyle();
      white.setFillPattern (GStyle.FILL_SOLID);
      white.setForegroundColor (new Color (255255255));

      GStyle label = new GStyle();
      label.setFont (new Font ("Dialog", Font.PLAIN, 24));
      label.setLineStyle (GStyle.LINESTYLE_INVISIBLE);
      label.setForegroundColor (new Color (210210210));

      GStyle interaction = new GStyle();
      interaction.setLineStyle (GStyle.LINESTYLE_INVISIBLE);
      interaction.setBackgroundColor (new Color (1.0f0.0f0.0f0.7f));

      fields_ = new GSegment[64];
      labels_ = new GSegment[16];
        
      for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
          GSegment field = new GSegment();
          addSegment (field);
          field.setStyle ((i + j!= ? black : white);
          fields_[i*+ j= field;
        }
      }

      for (int i = 0; i < 8; i++) {
        labels_[inew GSegment();
        labels_[i].setStyle (label);
        String text = "" (i+1);
        labels_[i].addText (new GText (text, GPosition.TOP));
        labels_[i].addText (new GText (text, GPosition.BOTTOM));
        addSegment (labels_[i]);

        labels_[i+8new GSegment();
        labels_[i+8].setStyle (label);
        labels_[i+8].addText (new GText ((new Character ((char)('h' - i))).toString(),
                              GPosition.LEFT));
        labels_[i+8].addText (new GText ((new Character ((char)('h' - i))).toString(),        
                              GPosition.RIGHT));
        addSegment (labels_[i+8]);
      }

      interaction_ = new GObject();
      interaction_.setStyle (interaction);
      interactionSegment_ = new GSegment();
      interaction_.addSegment (interactionSegment_);
      add (interaction_, front());
    }
    

    
    public void draw()
    {
      // Field geometry
      for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
          double[] x = new double[] {i, i+1, i+1, i};
          double[] y = new double[] {j, j,   j+1, j+1};          

          fields_[i*+ j].setGeometry (x, y);
        }
      }

      // Label line geometry
      for (int i = 0; i < 8; i++) {
        labels_[i].setGeometry (i+0.50.0, i+0.58.0);
        labels_[i+8].setGeometry (0.0, i+0.58.0, i+0.5);        
      }
    }
  }
  


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

           
       
G-AnnotationAndInteractionAndTransparentColorScale.zip( 194 k)
Related examples in the same category
1. Custom Move InteractionCustom Move Interaction
2. Custom InteractionCustom Interaction
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.