Example usage for java.awt.geom Ellipse2D.Float Ellipse2D.Float

List of usage examples for java.awt.geom Ellipse2D.Float Ellipse2D.Float

Introduction

In this page you can find the example usage for java.awt.geom Ellipse2D.Float Ellipse2D.Float.

Prototype

public Float(float x, float y, float w, float h) 

Source Link

Document

Constructs and initializes an Ellipse2D from the specified coordinates.

Usage

From source file:fungus.JungObserver.java

public JungObserver(String name) {
    this.name = name;
    this.hyphadataPid = Configuration.getPid(name + "." + PAR_HYPHADATA_PROTO);
    this.hyphalinkPid = Configuration.getPid(name + "." + PAR_HYPHALINK_PROTO);
    this.mycocastPid = Configuration.getPid(name + "." + PAR_MYCOCAST_PROTO);
    self = this;/*from  w  w  w. j  a va 2  s.co  m*/
    mainThread = Thread.currentThread();

    graph = new DirectedSparseGraph<MycoNode, String>();
    edu.uci.ics.jung.algorithms.layout.SpringLayout<MycoNode, String> layout = new edu.uci.ics.jung.algorithms.layout.SpringLayout<MycoNode, String>(
            graph);
    layout.setSize(new Dimension(650, 650));
    layout.setRepulsionRange(75);
    //layout.setForceMultiplier(0.75);
    layout.setStretch(0.85);

    Dimension preferredSize = new Dimension(650, 650);
    VisualizationModel<MycoNode, String> visualizationModel = new DefaultVisualizationModel<MycoNode, String>(
            layout, preferredSize);
    visualizer = new VisualizationViewer<MycoNode, String>(visualizationModel, preferredSize);
    visualizer.addGraphMouseListener(new InfoFrameVertexListener());

    //visualizer = new BasicVisualizationServer<Node,String>(layout);
    //visualizer.setPreferredSize(new Dimension(650, 650));

    Transformer<MycoNode, String> nodeLabeller = new Transformer<MycoNode, String>() {
        public String transform(MycoNode n) {
            return Long.toString(n.getID());
        }
    };

    final Shape biomassCircle = new Ellipse2D.Float(-2.5f, -2.5f, 5.0f, 5.0f);
    final Shape hyphaCircle = new Ellipse2D.Float(-5.0f, -5.0f, 10.0f, 10.0f);
    Transformer<MycoNode, Shape> shapeTransformer = new Transformer<MycoNode, Shape>() {
        public Shape transform(MycoNode n) {
            HyphaData data = n.getHyphaData();
            if (data.isBiomass()) {
                return biomassCircle;
            } else {
                return hyphaCircle;
            }
        }

    };

    Transformer<MycoNode, Paint> nodeFillRenderer = new Transformer<MycoNode, Paint>() {
        public Paint transform(MycoNode n) {
            HyphaData data = (HyphaData) n.getProtocol(hyphadataPid);
            if (!n.isUp()) {
                return Color.BLACK;
            }
            if (data.isBiomass()) {
                return Color.BLUE;
            } else if (data.isExtending()) {
                return Color.RED;
            } else if (data.isBranching()) {
                return Color.YELLOW;
            } else {
                return Color.GREEN;
            }
        }
    };
    Transformer<MycoNode, Paint> nodeShapeRenderer = new Transformer<MycoNode, Paint>() {
        public Paint transform(MycoNode n) {
            HyphaData data = (HyphaData) n.getProtocol(hyphadataPid);
            if (data.isBiomass()) {
                return Color.BLUE;
            } else if (data.isExtending()) {
                return Color.RED;
            } else if (data.isBranching()) {
                return Color.YELLOW;
            } else {
                return Color.GREEN;
            }
        }
    };

    final Stroke biomassStroke = new BasicStroke(0.25f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f);
    final Stroke hyphalStroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f);

    Transformer<String, Stroke> edgeStrokeTransformer = new Transformer<String, Stroke>() {
        public Stroke transform(String s) {
            Pair<MycoNode> vertices = graph.getEndpoints(s);
            HyphaData firstData = vertices.getFirst().getHyphaData();
            HyphaData secondData = vertices.getSecond().getHyphaData();
            if (firstData.isHypha() && secondData.isHypha()) {
                return hyphalStroke;
            } else {
                return biomassStroke;
            }
        }
    };

    visualizer.getRenderContext().setVertexFillPaintTransformer(nodeFillRenderer);
    visualizer.getRenderContext().setVertexShapeTransformer(shapeTransformer);
    visualizer.getRenderContext().setVertexLabelTransformer(nodeLabeller);
    visualizer.setVertexToolTipTransformer(new ToStringLabeller<MycoNode>());
    visualizer.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer);
    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container c = frame.getContentPane();
    c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS));

    //JScrollPane scrollPane = new JScrollPane(visualizer);
    //c.add(scrollPane);
    c.add(visualizer);

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));

    JButton pauseButton = new JButton("pause");
    ActionListener pauser = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //e.consume();
            synchronized (self) {
                stepBlocked = true;
                noBlock = false;
                //self.notifyAll();
            }
        }
    };
    pauseButton.addActionListener(pauser);

    JButton stepButton = new JButton("step");
    ActionListener stepper = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Clicked!\n");
            //e.consume();
            synchronized (self) {
                stepBlocked = false;
                self.notifyAll();
            }
        }
    };
    stepButton.addActionListener(stepper);

    JButton runButton = new JButton("run");
    ActionListener runner = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //e.consume();
            synchronized (self) {
                stepBlocked = false;
                noBlock = true;
                self.notifyAll();
            }
        }
    };
    runButton.addActionListener(runner);

    buttonPane.add(pauseButton);
    buttonPane.add(stepButton);
    buttonPane.add(runButton);
    c.add(buttonPane);

    frame.pack();
    frame.setVisible(true);
}