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

Home
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.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Advanced Graphics » Interaction 




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:[email protected]">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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.