My favorites | Sign in
Project Logo
                
Search
for
Updated Jan 05, 2009 by aalmiray
SceneExampleAsterisk  

package org.kordamp.jsilhouette.scenegraph;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.sun.scenario.scenegraph.*;
import org.kordamp.jsilhouette.geom.*;

public class SGAsteriskExample {
   public static JSGPanel canvas() {
      JSGPanel canvas = new JSGPanel();
      canvas.setScene(shape(asterisk(),Color.RED));
      return canvas;
   }

   private static SGAsterisk asterisk() {
      SGAsterisk asterisk = new SGAsterisk();
      asterisk.setCx( 50);
      asterisk.setCy( 50 );
      asterisk.setRadius( 40 );
      asterisk.setWidth( 8 );
      asterisk.setBeams( 5 );
      asterisk.setAngle( 18 );
      asterisk.setRoundness( 0.75f );
      return asterisk;
   }

   private static SGGroup shape( SGShape shape, Color color ) {
      SGGroup group = new SGGroup();
      group.add( configureShapeForFill(shape,color) );
      group.add( configureShapeForStroke(shape) );
      return group;
   }

   private static SGShape configureShapeForFill( SGShape shape, Color color ) {
      SGShape s = new SGShape();
      s.setShape(shape.getShape());
      s.setFillPaint(color);
      s.setMode(SGShape.Mode.FILL);
      s.setAntialiasingHint(RenderingHints.VALUE_ANTIALIAS_ON);
      return s;
   }

   private static SGShape configureShapeForStroke( SGShape shape ) {
      SGShape s = new SGShape();
      s.setShape(shape.getShape());
      s.setDrawStroke(new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
      s.setDrawPaint(Color.black);
      s.setMode(SGShape.Mode.STROKE);
      s.setAntialiasingHint(RenderingHints.VALUE_ANTIALIAS_ON);
      return s;
   }

   public static JFrame buildUI() {
      JFrame frame = new JFrame("SGAsterisk");
      frame.getContentPane().add(canvas());
      frame.setSize(new Dimension(110,130));
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      return frame;
   }

   public static void main( String[] args ) {
      SwingUtilities.invokeLater( new Runnable() {
         public void run() {
            buildUI().setVisible(true);
         }
      });
   }
}

Sign in to add a comment
Hosted by Google Code