Text position hints and Annotation algorithm : Text « 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 » TextScreenshots 
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
ww___w_._jav___a__2s.com_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.