Text position hints and Annotation algorithm : Text « 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 » Text 




Text position hints and Annotation algorithm
Text position hints and Annotation algorithm

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

import javax.swing.*;

import no.geosoft.cc.graphics.*;



/**
 * G demo program. Demonstrates:
 *
 * <ul>
 * <li>Text position hints
 * <li>Annotation algorithm
 * </ul>
 
 @author <a href="mailto:[email protected]">Jacob Dreyer</a>
 */   
public class Demo4 extends JFrame
{
  /**
   * Class for creating the demo canvas and hande Swing events.
   */   
  public Demo4()
  {
    super ("G Graphics Library - Demo 4");
    //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 ("Resize window to redo geometry"));
    topLevel.add (buttonPanel,   BorderLayout.NORTH);

    // Create the graphic canvas
    GWindow 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");

    // Create som graphic objects
    GObject testObject = new TestObject();
    scene.add (testObject);

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


  
  /**
   * Defines the geometry and presentation for a sample
   * graphic object.
   */   
  private class TestObject extends GObject
  {
    private GSegment  line_;

    
    
    TestObject()
    {
      line_ = new GSegment();
      GStyle lineStyle = new GStyle();
      lineStyle.setForegroundColor (new Color (00255));
      line_.setStyle (lineStyle);
      addSegment (line_);

      GStyle textStyle = new GStyle();
      textStyle.setForegroundColor (new Color (2005050));
      textStyle.setFont (new Font ("Dialog", Font.BOLD, 18));

      GText text;
      text = new GText ("Top", GPosition.TOP | GPosition.NORTH);
      text.setStyle (textStyle);
      line_.addText (text);

      text = new GText ("Bottom", GPosition.BOTTOM | GPosition.SOUTH);
      text.setStyle (textStyle);
      line_.addText (text);
      
      text = new GText ("Left", GPosition.LEFT | GPosition.WEST);
      text.setStyle (textStyle);
      line_.addText (text);

      text = new GText ("Right", GPosition.RIGHT | GPosition.EAST);
      text.setStyle (textStyle);
      line_.addText (text);

      text = new GText ("First", GPosition.FIRST | GPosition.CENTER);
      text.setStyle (textStyle);
      line_.addText (text);

      text = new GText ("Last", GPosition.LAST | GPosition.CENTER);
      text.setStyle (textStyle);
      line_.addText (text);

      GStyle symbolStyle = new GStyle();
      symbolStyle.setForegroundColor (new Color (000));
      GImage square = new GImage (GImage.SYMBOL_SQUARE1);
      square.setStyle (symbolStyle);
      
      line_.setVertexImage (square);
    }
    

    
    public void draw()
    {
      // Center of viewport
      int x0     = (intMath.round (getScene().getViewport().getCenterX());
      int y0     = (intMath.round (getScene().getViewport().getCenterY());

      int width  = (intMath.round (getScene().getViewport().getWidth());
      int height = (intMath.round (getScene().getViewport().getHeight());

      int nPoints = 15;
      
      int[] x = new int[nPoints];
      int[] y = new int[nPoints];
      
      for (int i = 0; i < nPoints; i++) {
        x[i50 (intMath.round ((width  - 100* Math.random());
        y[i20 (intMath.round ((height -  40* Math.random());
      }

      line_.setGeometry (x, y);
    }
  }
  


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

           
       














G-DrawLines.zip( 201 k)
Related examples in the same category
1.Vertical TextVertical Text
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.