1 6 7 package com.thoughtriver.open.vectorvisuals.example.fundamental; 8 9 import java.awt.*; 10 import java.awt.event.*; 11 import java.awt.geom.*; 12 import java.util.*; 13 14 import javax.swing.*; 15 16 import com.thoughtriver.open.vectorvisuals.*; 17 import com.thoughtriver.open.vectorvisuals.task.*; 18 19 27 public class SwingEmbedding implements Runnable { 28 29 30 private VVDisplay vvDisplay = null; 31 32 35 public SwingEmbedding() { 36 VVPanel panel = new VVPanel(); 37 38 panel.setLayout(new FlowLayout()); 40 JButton button1 = new JButton(new ButtonAction()); 41 panel.add(button1); 42 43 vvDisplay = new VVDisplay(panel); 44 } 45 46 49 public void run() { 50 JFrame frame = new JFrame("Vector Visuals Swing Embedding Example"); 51 frame.setSize(640, 480); 52 frame.getContentPane().setLayout(new BorderLayout()); 53 frame.getContentPane().add(vvDisplay.getViewPane(), BorderLayout.CENTER); 54 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 55 56 frame.setVisible(true); 57 58 vvDisplay.getViewPane().setBackground(Color.DARK_GRAY); 60 vvDisplay.setWorldViewScale(1); 61 62 Brush brush = new Brush(Color.YELLOW, null, null); 64 VisualTextObject textObj = new VisualTextObject("Try resizing the frame.", null, null, brush); 65 66 AffineTransform transform = textObj.getTransform(); 68 transform.scale(3.0, 3.0); 69 transform.translate(40, 40); 70 textObj.setTransform(transform); 71 textObj.setLayer(2); 73 vvDisplay.addObject(textObj); 75 } 76 77 82 public static void main(final String [] args) { 83 Runnable example = new SwingEmbedding(); 84 example.run(); 85 } 86 87 93 private class ButtonAction extends AbstractAction { 94 95 private static final long serialVersionUID = 2162173921388239990L; 96 97 98 private final Random random = new Random(); 99 100 104 public ButtonAction() { 105 super("Press Me if You Dare!"); 106 } 107 108 115 public void actionPerformed(@SuppressWarnings ("unused") 116 final ActionEvent event) { 117 118 Brush lineBrush = new Brush(new Color(random.nextInt()), null, null); 120 Brush fillBrush = new Brush(new Color(random.nextInt()), null, null); 121 VisualObject rectangle = new VisualObject(new Rectangle2D.Double(0, 0, random.nextInt(200), random.nextInt(200)), lineBrush, fillBrush); 122 rectangle.setTransform(AffineTransform.getTranslateInstance(random.nextInt(500), random.nextInt(300))); 123 124 vvDisplay.addObject(rectangle); 126 127 IndefiniteOscillationTask task = new IndefiniteOscillationTask(rectangle, random.nextGaussian()); 129 vvDisplay.getTaskManager().addTask(task); 130 task.setRate(random.nextGaussian()); 131 } 132 133 } 134 } 135 | Popular Tags |