Point Annotations : Math Notation « 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.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 » Advanced Graphics » Math NotationScreenshots 
Point Annotations
Point Annotations

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

import javax.swing.*;

import no.geosoft.cc.graphics.*;



/**
 * G demo program. Demonstrates:
 *
 * <ul>
 * <li>Point annotations
 * <li>Annotation algorithm
 * <li>Annotation background color
 * <li>Point images
 * <li>Printing feature
 * </ul>
 
 @author <a href="mailto:[email protected]">Jacob Dreyer</a>
 */   
public class Demo12 extends JFrame
  implements ActionListener
{
  private GWindow  window_;
  
  /**
   * Class for creating the demo canvas and hande Swing events.
   */   
  public Demo12()
  {
    super ("G Graphics Library - Demo 12");
    setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    
    // Create the GUI
    JPanel topLevel = new JPanel();
    topLevel.setLayout (new BorderLayout());
    getContentPane().add (topLevel);        

    JPanel buttonPanel = new JPanel();
    JButton printButton = new JButton ("Print");
    printButton.addActionListener (this);
    buttonPanel.add (printButton);
    topLevel.add (buttonPanel, BorderLayout.NORTH);
    
    // Create the graphic canvas
    window_ = new GWindow (new Color (255255255));
    topLevel.add (window_.getCanvas(), BorderLayout.CENTER);    

    // Create scene with default viewport and world extent settings
    GScene scene = new GScene (window_, "Scene");

    double w0[] {0.00.00.0};
    double w1[] {1.00.00.0};
    double w2[] {0.01.00.0};
    scene.setWorldExtent (w0, w1, w2);
    
    TestObject testObject = new TestObject();
    scene.add (testObject);

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

    window_.startInteraction (new ZoomInteraction (scene));
  }


  
  public void actionPerformed (ActionEvent event)
  {
    try {
      window_.print();
    }
    catch (Exception exception) {
      System.out.println ("Print failed!");
    }
  }
  

  
  /**
   * Defines the geometry and presentation for a sample graphic object.
   */   
  private class TestObject extends GObject
  {
    private GSegment  line_;
    private double[]  x_, y_;
    

    /**
     * As a rule of thumb we create as much of the object during
     * construction as possible. Try to do geometry only in the
     * draw method.
     */
    TestObject()
    {
      GStyle lineStyle = new GStyle();
      lineStyle.setLineWidth (2);      
      lineStyle.setForegroundColor (new Color (100100100));
      lineStyle.setAntialiased (true);

      GStyle symbolStyle = new GStyle();
      symbolStyle.setForegroundColor (new Color (00255));

      GStyle textStyle = new GStyle();
      textStyle.setFont (new Font ("Dialog", Font.BOLD, 14));
      textStyle.setForegroundColor (new Color (2552550));
      textStyle.setBackgroundColor (new Color (100100100));      
      
      line_ = new GSegment();
      line_.setStyle (lineStyle);
      addSegment (line_);

      GImage symbol = new GImage (GImage.SYMBOL_SQUARE2);
      symbol.setStyle (symbolStyle);
      line_.setVertexImage (symbol);

      int nPoints = 10;
      
      for (int i = 0; i < nPoints; i++) {
        GText text = new GText ("Point " + i,
                                GPosition.NORTH |
                                GPosition.STATIC);
        text.setStyle (textStyle);
        line_.addText (text);
      }

      // Geometry
      x_ = new double[nPoints];
      y_ = new double[nPoints];

      for (int i = 0; i < nPoints; i++) {
        x_[i0.2 0.8 * i * (1.0 / nPoints);
        y_[i0.1 0.8 * Math.random();
      }
    }
    

    
    public void draw()
    {
      line_.setGeometry (x_, y_);
    }
  }
  


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

           
       
G-Point-Annotations.zip( 192 k)
Related examples in the same category
1.Math Notation Demo
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.