Example usage for java.awt Color YELLOW

List of usage examples for java.awt Color YELLOW

Introduction

In this page you can find the example usage for java.awt Color YELLOW.

Prototype

Color YELLOW

To view the source code for java.awt Color YELLOW.

Click Source Link

Document

The color yellow.

Usage

From source file:umontreal.iro.lecuyer.charts.SSJCategorySeriesCollection.java

protected static Color getDefaultColor(int index) {
    if (index % 6 == 0)
        return Color.RED;
    else if (index % 6 == 1)
        return Color.BLUE;
    else if (index % 6 == 2)
        return Color.GREEN;
    else if (index % 6 == 3)
        return Color.YELLOW;
    else if (index % 6 == 4)
        return Color.MAGENTA;
    else//from  ww  w  .j a  v a 2 s  . c  o  m
        return Color.CYAN;
}

From source file:cytoscape.render.immed.GraphGraphicsTest.java

private long drawOldFull(Random rand) {
    final float nodeSizeFactor = 50f;
    float size = (float) canvasSize;

    long begin = System.nanoTime();
    for (int i = 0; i < numNodes; i++) {
        float x = rand.nextFloat() * (rand.nextBoolean() ? size : -size);
        float y = rand.nextFloat() * (rand.nextBoolean() ? size : -size);
        oldGraphGraphics.drawNodeFull((byte) (i % (int) OldGraphGraphics.s_last_shape), x, y,
                (x + (rand.nextFloat() * nodeSizeFactor)), (y + (rand.nextFloat() * nodeSizeFactor)),
                Color.blue, 1.0f + (i % 10), Color.yellow);
    }/* ww w. j a v a 2s .c om*/
    long end = System.nanoTime();
    long nodeDur = end - begin;

    BasicStroke edgeStroke = new BasicStroke(1f);

    begin = System.nanoTime();
    for (int i = 0; i < numEdges; i++) {
        oldGraphGraphics.drawEdgeFull((byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.red,
                (byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.orange,
                rand.nextFloat() * (rand.nextBoolean() ? size : -size),
                rand.nextFloat() * (rand.nextBoolean() ? size : -size), oldGraphGraphics.m_noAnchors,
                rand.nextFloat() * (rand.nextBoolean() ? size : -size),
                rand.nextFloat() * (rand.nextBoolean() ? size : -size), 1f, Color.green, 0f);
    }
    end = System.nanoTime();

    long duration = (end - begin) + nodeDur;

    //      try {
    //         ImageIO.write(image,"PNG",new File("/tmp/homer-old-" + rand.nextInt(100) + ".png"));
    //      } catch (IOException ioe) { ioe.printStackTrace(); }
    return duration;
}

From source file:org.ow2.clif.jenkins.chart.MovingStatChart.java

private XYLineAndShapeRenderer getGlobalRenderer() {
    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesPaint(0, Color.BLUE);
    renderer.setSeriesStroke(0, new BasicStroke(1));
    renderer.setSeriesShapesVisible(1, false);
    renderer.setSeriesPaint(1, Color.RED);
    renderer.setSeriesStroke(1, new BasicStroke(1));
    renderer.setSeriesShapesVisible(2, false);
    renderer.setSeriesPaint(2, Color.GREEN);
    renderer.setSeriesStroke(2, new BasicStroke(1));
    renderer.setSeriesShapesVisible(3, false);
    renderer.setSeriesPaint(3, Color.YELLOW);
    renderer.setSeriesStroke(3, new BasicStroke(1));
    renderer.setSeriesShapesVisible(4, false);
    renderer.setSeriesPaint(4, Color.ORANGE);
    renderer.setSeriesStroke(4, new BasicStroke(1));
    return renderer;
}

From source file:org.activiti.crystalball.generator.ProcessInstancesGeneratorTest.java

public void testGenerateHistoricInstances() throws IOException {

    HistoricInstancesGenerator monitor = new HistoricInstancesGenerator();
    monitor.setRepositoryService(repositoryService);
    monitor.setHistoryService(historyService);
    List<ColorInterval> highlightColorIntervalList = new ArrayList<ColorInterval>();
    highlightColorIntervalList.add(new ColorInterval(4, Color.green));
    highlightColorIntervalList.add(new ColorInterval(1, 3, Color.yellow));
    highlightColorIntervalList.add(new ColorInterval(0, 0, Color.red));

    monitor.setHighlightColorIntervalList(highlightColorIntervalList);

    String processDefinitionId = repositoryService.createProcessDefinitionQuery()
            .processDefinitionKey(PROCESS_KEY).singleResult().getId();

    monitor.generateReport(processDefinitionId, null, null, "target/HistoricInstanceMonitor-1.png");

    File expectedFile = new File(
            "src/test/resources/org/activiti/crystalball/generator/HistoricInstanceMonitor-1.png");
    File generatedFile = new File("target/HistoricInstanceMonitor-1.png");
    assertTrue(FileUtils.contentEquals(expectedFile, generatedFile));

    // move 3 tasks forward
    List<Task> taskList = taskService.createTaskQuery().taskCandidateUser("user1").list();
    for (int i = 0; i < 3; i++) {
        Task t = taskList.get(i);//from   w  w w. j a v a 2  s . c  o m
        taskService.claim(t.getId(), "user1");
        taskService.complete(t.getId());
    }

    monitor.generateReport(processDefinitionId, null, null, "target/HistoricInstanceMonitor-2.png");

    expectedFile = new File(
            "src/test/resources/org/activiti/crystalball/generator/HistoricInstanceMonitor-2.png");
    generatedFile = new File("target/HistoricInstanceMonitor-2.png");
    assertTrue(FileUtils.contentEquals(expectedFile, generatedFile));

    // move 3 tasks forward
    taskList = taskService.createTaskQuery().taskCandidateUser("user2").list();
    for (Task t : taskList) {
        taskService.claim(t.getId(), "user2");
        taskService.complete(t.getId());
    }

    monitor.generateReport(processDefinitionId, null, null, "target/HistoricInstanceMonitor-3.png");

    expectedFile = new File(
            "src/test/resources/org/activiti/crystalball/generator/HistoricInstanceMonitor-3.png");
    generatedFile = new File("target/HistoricInstanceMonitor-3.png");
    assertTrue(FileUtils.contentEquals(expectedFile, generatedFile));

    // move 3 tasks forward
    taskList = taskService.createTaskQuery().taskCandidateUser("user3").list();
    for (Task t : taskList) {
        taskService.claim(t.getId(), "user3");
        taskService.complete(t.getId());
    }

    monitor.generateReport(processDefinitionId, null, null, "target/HistoricInstanceMonitor-4.png");

    expectedFile = new File(
            "src/test/resources/org/activiti/crystalball/generator/HistoricInstanceMonitor-4.png");
    generatedFile = new File("target/HistoricInstanceMonitor-4.png");
    assertTrue(FileUtils.contentEquals(expectedFile, generatedFile));

}

From source file:patientview.HistoryJFrame.java

public void genGraph(int code) {
    //ArrayList<LiveData> data = thisPatient.getLiveDatahistory(timerCSeconds); //Displays live data up untill the current moment
    ArrayList<LiveData> data = thisPatient.getAllLiveData();

    //create and populate graph
    XYSeries rr = new XYSeries("Respiratory rate (breaths/min)");
    XYSeries os = new XYSeries("Oxygen saturation (%)");
    XYSeries t = new XYSeries("Temperature (C)");
    XYSeries sbp = new XYSeries("Systolic blood pressure (mmHg)");
    XYSeries hr = new XYSeries("Heart rate (beats/min)");

    for (int i = 0; i < data.size(); i++) {
        rr.add(i * 5, data.get(i).rr);//from  www  .  ja v a 2 s  . c  o  m
        os.add(i * 5, data.get(i).os);
        t.add(i * 5, data.get(i).t);
        sbp.add(i * 5, data.get(i).sbp);
        hr.add(i * 5, data.get(i).hr);
    }

    XYDataset xyDataset1 = new XYSeriesCollection(rr);
    XYDataset xyDataset2 = new XYSeriesCollection(os);
    XYDataset xyDataset3 = new XYSeriesCollection(t);
    XYDataset xyDataset4 = new XYSeriesCollection(sbp);
    XYDataset xyDataset5 = new XYSeriesCollection(hr);

    JFreeChart chart = ChartFactory.createXYLineChart(thisPatient.getFullName(), "Time (s)", "", null,
            PlotOrientation.VERTICAL, true, true, false);

    this.plot = chart.getXYPlot();

    this.plot.setRenderer(0, new StandardXYItemRenderer());
    this.plot.setRenderer(1, new StandardXYItemRenderer());
    this.plot.setRenderer(2, new StandardXYItemRenderer());
    this.plot.setRenderer(3, new StandardXYItemRenderer());
    this.plot.setRenderer(4, new StandardXYItemRenderer());

    boolean markers = false;
    if ((code & 32) == 32) {
        markers = true;
    }
    //respiratory rate
    if ((code & 1) == 1) {
        this.plot.setDataset(0, xyDataset1);
        if (markers) {
            IntervalMarker zone = new IntervalMarker(9, 20);
            zone.setPaint(new Color(255, 0, 0, 64));
            plot.addRangeMarker(zone);
        }
        this.plot.getRendererForDataset(plot.getDataset(0)).setSeriesPaint(0, Color.red);
    }
    //oxygen saturation
    if ((code & 2) == 2) {
        this.plot.setDataset(1, xyDataset2);
        if (markers) {
            IntervalMarker zone = new IntervalMarker(93, 100);
            zone.setPaint(new Color(0, 255, 0, 64));
            plot.addRangeMarker(zone);
        }
        this.plot.getRendererForDataset(plot.getDataset(1)).setSeriesPaint(0, Color.green);
    }
    //temperature
    if ((code & 4) == 4) {
        this.plot.setDataset(2, xyDataset3);
        if (markers) {
            IntervalMarker zone = new IntervalMarker(36, 37.9);
            zone.setPaint(new Color(0, 0, 255, 64));
            plot.addRangeMarker(zone);
        }
        this.plot.getRendererForDataset(plot.getDataset(2)).setSeriesPaint(0, Color.blue);
    }
    //systolic blood pressure
    if ((code & 8) == 8) {
        this.plot.setDataset(3, xyDataset4);
        if (markers) {
            IntervalMarker zone = new IntervalMarker(100, 199);
            zone.setPaint(new Color(255, 255, 0, 64));
            plot.addRangeMarker(zone);
        }
        this.plot.getRendererForDataset(plot.getDataset(3)).setSeriesPaint(0, Color.yellow);
    }
    //heart rate
    if ((code & 16) == 16) {
        this.plot.setDataset(4, xyDataset5);
        if (markers) {
            IntervalMarker zone = new IntervalMarker(50, 99);
            zone.setPaint(new Color(255, 0, 255, 64));
            plot.addRangeMarker(zone);
        }
        this.plot.getRendererForDataset(plot.getDataset(4)).setSeriesPaint(0, Color.magenta);
    }

    graphPanel.removeAll();
    cp = new ChartPanel(chart);
    cp.setMouseWheelEnabled(true);
    cp.setPreferredSize(new Dimension(640, 480));
    graphPanel.setLayout(new java.awt.BorderLayout());
    graphPanel.add(cp, java.awt.BorderLayout.CENTER);
    graphPanel.validate();

}

From source file:de.unidue.inf.is.ezdl.gframedl.tools.relations.DLObjectGraphView.java

private void setRenderers() {
    vv.getRenderContext().setVertexLabelTransformer(new Transformer<DLObject, String>() {

        @Override/*  w w  w .  j  av a  2s  .  c  o  m*/
        public String transform(DLObject v) {
            String result = "";
            if (v instanceof Person) {
                result = ((Person) v).getFirstName() + " " + ((Person) v).getLastName();
            }
            if (v instanceof TextDocument) {
                result = ((TextDocument) v).getTitle();
            }
            return result;
        }
    });
    vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.red));
    vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan));
    vv.getRenderContext().setVertexShapeTransformer(new VertexShapeFunction<DLObject>());

    vv.getRenderContext().setVertexIconTransformer(new Transformer<DLObject, Icon>() {

        @Override
        public Icon transform(final DLObject v) {
            final int size = getVertexSize(v);
            return new Icon() {

                @Override
                public int getIconHeight() {
                    return size;
                }

                @Override
                public int getIconWidth() {
                    return size;
                }

                @Override
                public void paintIcon(Component c, Graphics g, int x, int y) {
                    int halfSize = size / 2;
                    if (vv.getPickedVertexState().isPicked(v)) {
                        g.setColor(Color.yellow);
                    } else {
                        g.setColor(Color.lightGray);
                    }
                    g.fillOval(x, y, size, size);

                    if (vv.getPickedVertexState().isPicked(v)) {
                        g.setColor(Color.red);
                    } else {
                        g.setColor(Color.black);
                    }
                    g.drawOval(x, y, size, size);

                    int iconX = x + halfSize - 8;
                    int iconY = y + halfSize - 8;

                    if (v instanceof Person) {
                        Icons.MEDIA_AUTHOR.get16x16().paintIcon(c, g, iconX, iconY);
                    }
                    if (v instanceof TextDocument) {
                        Icons.MEDIA_TEXT.get16x16().paintIcon(c, g, iconX, iconY);
                    }
                    if (v instanceof Term) {
                        Icons.MEDIA_TERM.get16x16().paintIcon(c, g, iconX, iconY);
                    }
                }
            };
        }
    });

    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.black));
    vv.setBackground(Color.white);
}

From source file:org.esa.s2tbx.dataio.s2.l1b.L1bSceneDescription.java

public BufferedImage createTilePicture(int width) {

    Color[] colors = new Color[] { Color.GREEN, Color.RED, Color.BLUE, Color.YELLOW };

    double scale = width / sceneRectangle.getWidth();
    int height = (int) Math.round(sceneRectangle.getHeight() * scale);

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics = image.createGraphics();
    graphics.scale(scale, scale);//  w w w.ja  va  2 s. c  o  m
    graphics.translate(-sceneRectangle.getX(), -sceneRectangle.getY());
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    graphics.setPaint(Color.WHITE);
    graphics.fill(sceneRectangle);
    graphics.setStroke(new BasicStroke(100F));
    graphics.setFont(new Font("Arial", Font.PLAIN, 800));

    for (int i = 0; i < tileInfos.length; i++) {
        Rectangle rect = tileInfos[i].rectangle;
        graphics.setPaint(addAlpha(colors[i % colors.length].brighter(), 100));
        graphics.fill(rect);
    }
    for (int i = 0; i < tileInfos.length; i++) {
        Rectangle rect = tileInfos[i].rectangle;
        graphics.setPaint(addAlpha(colors[i % colors.length].darker(), 100));
        graphics.draw(rect);
        graphics.setPaint(colors[i % colors.length].darker().darker());
        graphics.drawString("Tile " + (i + 1) + ": " + tileInfos[i].id, rect.x + 1200F, rect.y + 2200F);
    }
    return image;
}

From source file:com.google.code.facebook.graph.sna.applet.MultiViewDemo.java

/**
 * create an instance of a simple graph in two views with controls to
 * demo the zoom features.//from  w ww . j a va 2s .  co  m
 * 
 */
public MultiViewDemo() {

    // create a simple graph for the demo
    graph = TestGraphs.getOneComponentGraph();

    // create one layout for the graph
    FRLayout<String, Number> layout = new FRLayout<String, Number>(graph);
    layout.setMaxIterations(1000);

    // create one model that all 3 views will share
    VisualizationModel<String, Number> visualizationModel = new DefaultVisualizationModel<String, Number>(
            layout, preferredSize);

    // create 3 views that share the same model
    vv1 = new VisualizationViewer<String, Number>(visualizationModel, preferredSize);
    vv2 = new VisualizationViewer<String, Number>(visualizationModel, preferredSize);
    vv3 = new VisualizationViewer<String, Number>(visualizationModel, preferredSize);

    vv1.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<String, Number>());
    vv2.getRenderContext()
            .setVertexShapeTransformer(new ConstantTransformer(new Rectangle2D.Float(-6, -6, 12, 12)));

    vv2.getRenderContext().setEdgeShapeTransformer(new EdgeShape.QuadCurve<String, Number>());

    vv3.getRenderContext().setEdgeShapeTransformer(new EdgeShape.CubicCurve<String, Number>());

    //        transformer = vv1.getLayoutTransformer();
    //        vv2.setLayoutTransformer(transformer);
    //        vv3.setLayoutTransformer(transformer);
    //        
    //        vv2.setViewTransformer(vv1.getViewTransformer());
    //        vv3.setViewTransformer(vv1.getViewTransformer());

    vv2.getRenderContext().setMultiLayerTransformer(vv1.getRenderContext().getMultiLayerTransformer());
    vv3.getRenderContext().setMultiLayerTransformer(vv1.getRenderContext().getMultiLayerTransformer());

    vv1.getRenderContext().getMultiLayerTransformer().addChangeListener(vv1);
    vv2.getRenderContext().getMultiLayerTransformer().addChangeListener(vv2);
    vv3.getRenderContext().getMultiLayerTransformer().addChangeListener(vv3);

    vv1.setBackground(Color.white);
    vv2.setBackground(Color.white);
    vv3.setBackground(Color.white);

    // create one pick support for all 3 views to share
    GraphElementAccessor<String, Number> pickSupport = new ShapePickSupport<String, Number>(vv1);
    vv1.setPickSupport(pickSupport);
    vv2.setPickSupport(pickSupport);
    vv3.setPickSupport(pickSupport);

    // create one picked state for all 3 views to share
    PickedState<Number> pes = new MultiPickedState<Number>();
    PickedState<String> pvs = new MultiPickedState<String>();
    vv1.setPickedVertexState(pvs);
    vv2.setPickedVertexState(pvs);
    vv3.setPickedVertexState(pvs);
    vv1.setPickedEdgeState(pes);
    vv2.setPickedEdgeState(pes);
    vv3.setPickedEdgeState(pes);

    // set an edge paint function that shows picked edges
    vv1.getRenderContext()
            .setEdgeDrawPaintTransformer(new PickableEdgePaintTransformer<Number>(pes, Color.black, Color.red));
    vv2.getRenderContext()
            .setEdgeDrawPaintTransformer(new PickableEdgePaintTransformer<Number>(pes, Color.black, Color.red));
    vv3.getRenderContext()
            .setEdgeDrawPaintTransformer(new PickableEdgePaintTransformer<Number>(pes, Color.black, Color.red));
    vv1.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<String>(pvs, Color.red, Color.yellow));
    vv2.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<String>(pvs, Color.blue, Color.cyan));
    vv3.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<String>(pvs, Color.red, Color.yellow));

    // add default listener for ToolTips
    vv1.setVertexToolTipTransformer(new ToStringLabeller());
    vv2.setVertexToolTipTransformer(new ToStringLabeller());
    vv3.setVertexToolTipTransformer(new ToStringLabeller());

    Container content = getContentPane();
    JPanel panel = new JPanel(new GridLayout(1, 0));

    final JPanel p1 = new JPanel(new BorderLayout());
    final JPanel p2 = new JPanel(new BorderLayout());
    final JPanel p3 = new JPanel(new BorderLayout());

    p1.add(new GraphZoomScrollPane(vv1));
    p2.add(new GraphZoomScrollPane(vv2));
    p3.add(new GraphZoomScrollPane(vv3));

    JButton h1 = new JButton("?");
    h1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            textArea.setText(messageOne);
            JOptionPane.showMessageDialog(p1, scrollPane, "View 1", JOptionPane.PLAIN_MESSAGE);
        }
    });
    JButton h2 = new JButton("?");
    h2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            textArea.setText(messageTwo);
            JOptionPane.showMessageDialog(p2, scrollPane, "View 2", JOptionPane.PLAIN_MESSAGE);
        }
    });
    JButton h3 = new JButton("?");
    h3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            textArea.setText(messageThree);
            textArea.setCaretPosition(0);
            JOptionPane.showMessageDialog(p3, scrollPane, "View 3", JOptionPane.PLAIN_MESSAGE);
        }
    });

    // create a GraphMouse for each view
    // each one has a different scaling plugin
    DefaultModalGraphMouse gm1 = new DefaultModalGraphMouse() {
        protected void loadPlugins() {
            pickingPlugin = new PickingGraphMousePlugin();
            animatedPickingPlugin = new AnimatedPickingGraphMousePlugin();
            translatingPlugin = new TranslatingGraphMousePlugin(InputEvent.BUTTON1_MASK);
            scalingPlugin = new ScalingGraphMousePlugin(new LayoutScalingControl(), 0);
            rotatingPlugin = new RotatingGraphMousePlugin();
            shearingPlugin = new ShearingGraphMousePlugin();

            add(scalingPlugin);
            setMode(Mode.TRANSFORMING);
        }
    };

    DefaultModalGraphMouse gm2 = new DefaultModalGraphMouse() {
        protected void loadPlugins() {
            pickingPlugin = new PickingGraphMousePlugin();
            animatedPickingPlugin = new AnimatedPickingGraphMousePlugin();
            translatingPlugin = new TranslatingGraphMousePlugin(InputEvent.BUTTON1_MASK);
            scalingPlugin = new ScalingGraphMousePlugin(new ViewScalingControl(), 0);
            rotatingPlugin = new RotatingGraphMousePlugin();
            shearingPlugin = new ShearingGraphMousePlugin();

            add(scalingPlugin);
            setMode(Mode.TRANSFORMING);
        }

    };

    DefaultModalGraphMouse gm3 = new DefaultModalGraphMouse() {
    };

    vv1.setGraphMouse(gm1);
    vv2.setGraphMouse(gm2);
    vv3.setGraphMouse(gm3);

    vv1.setToolTipText("<html><center>MouseWheel Scales Layout</center></html>");
    vv2.setToolTipText("<html><center>MouseWheel Scales View</center></html>");
    vv3.setToolTipText(
            "<html><center>MouseWheel Scales Layout and<p>crosses over to view<p>ctrl+MouseWheel scales view</center></html>");

    vv1.addPostRenderPaintable(new BannerLabel(vv1, "View 1"));
    vv2.addPostRenderPaintable(new BannerLabel(vv2, "View 2"));
    vv3.addPostRenderPaintable(new BannerLabel(vv3, "View 3"));

    textArea = new JTextArea(6, 30);
    scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.setEditable(false);

    JPanel flow = new JPanel();
    flow.add(h1);
    flow.add(gm1.getModeComboBox());
    p1.add(flow, BorderLayout.SOUTH);
    flow = new JPanel();
    flow.add(h2);
    flow.add(gm2.getModeComboBox());
    p2.add(flow, BorderLayout.SOUTH);
    flow = new JPanel();
    flow.add(h3);
    flow.add(gm3.getModeComboBox());
    p3.add(flow, BorderLayout.SOUTH);

    panel.add(p1);
    panel.add(p2);
    panel.add(p3);
    content.add(panel);

}

From source file:edu.uci.ics.jung.samples.MultiViewDemo.java

/**
 * create an instance of a simple graph in two views with controls to
 * demo the zoom features.//  ww  w .jav  a  2s.  c  o m
 * 
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public MultiViewDemo() {

    // create a simple graph for the demo
    graph = TestGraphs.getOneComponentGraph();

    // create one layout for the graph
    FRLayout<String, Number> layout = new FRLayout<String, Number>(graph);
    layout.setMaxIterations(1000);

    // create one model that all 3 views will share
    VisualizationModel<String, Number> visualizationModel = new DefaultVisualizationModel<String, Number>(
            layout, preferredSize);

    // create 3 views that share the same model
    vv1 = new VisualizationViewer<String, Number>(visualizationModel, preferredSize);
    vv2 = new VisualizationViewer<String, Number>(visualizationModel, preferredSize);
    vv3 = new VisualizationViewer<String, Number>(visualizationModel, preferredSize);

    vv1.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<String, Number>());
    vv2.getRenderContext()
            .setVertexShapeTransformer(new ConstantTransformer(new Rectangle2D.Float(-6, -6, 12, 12)));

    vv2.getRenderContext().setEdgeShapeTransformer(new EdgeShape.QuadCurve<String, Number>());

    vv3.getRenderContext().setEdgeShapeTransformer(new EdgeShape.CubicCurve<String, Number>());

    //        transformer = vv1.getLayoutTransformer();
    //        vv2.setLayoutTransformer(transformer);
    //        vv3.setLayoutTransformer(transformer);
    //        
    //        vv2.setViewTransformer(vv1.getViewTransformer());
    //        vv3.setViewTransformer(vv1.getViewTransformer());

    vv2.getRenderContext().setMultiLayerTransformer(vv1.getRenderContext().getMultiLayerTransformer());
    vv3.getRenderContext().setMultiLayerTransformer(vv1.getRenderContext().getMultiLayerTransformer());

    vv1.getRenderContext().getMultiLayerTransformer().addChangeListener(vv1);
    vv2.getRenderContext().getMultiLayerTransformer().addChangeListener(vv2);
    vv3.getRenderContext().getMultiLayerTransformer().addChangeListener(vv3);

    vv1.setBackground(Color.white);
    vv2.setBackground(Color.white);
    vv3.setBackground(Color.white);

    // create one pick support for all 3 views to share
    GraphElementAccessor<String, Number> pickSupport = new ShapePickSupport<String, Number>(vv1);
    vv1.setPickSupport(pickSupport);
    vv2.setPickSupport(pickSupport);
    vv3.setPickSupport(pickSupport);

    // create one picked state for all 3 views to share
    PickedState<Number> pes = new MultiPickedState<Number>();
    PickedState<String> pvs = new MultiPickedState<String>();
    vv1.setPickedVertexState(pvs);
    vv2.setPickedVertexState(pvs);
    vv3.setPickedVertexState(pvs);
    vv1.setPickedEdgeState(pes);
    vv2.setPickedEdgeState(pes);
    vv3.setPickedEdgeState(pes);

    // set an edge paint function that shows picked edges
    vv1.getRenderContext()
            .setEdgeDrawPaintTransformer(new PickableEdgePaintTransformer<Number>(pes, Color.black, Color.red));
    vv2.getRenderContext()
            .setEdgeDrawPaintTransformer(new PickableEdgePaintTransformer<Number>(pes, Color.black, Color.red));
    vv3.getRenderContext()
            .setEdgeDrawPaintTransformer(new PickableEdgePaintTransformer<Number>(pes, Color.black, Color.red));
    vv1.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<String>(pvs, Color.red, Color.yellow));
    vv2.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<String>(pvs, Color.blue, Color.cyan));
    vv3.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<String>(pvs, Color.red, Color.yellow));

    // add default listener for ToolTips
    vv1.setVertexToolTipTransformer(new ToStringLabeller());
    vv2.setVertexToolTipTransformer(new ToStringLabeller());
    vv3.setVertexToolTipTransformer(new ToStringLabeller());

    Container content = getContentPane();
    JPanel panel = new JPanel(new GridLayout(1, 0));

    final JPanel p1 = new JPanel(new BorderLayout());
    final JPanel p2 = new JPanel(new BorderLayout());
    final JPanel p3 = new JPanel(new BorderLayout());

    p1.add(new GraphZoomScrollPane(vv1));
    p2.add(new GraphZoomScrollPane(vv2));
    p3.add(new GraphZoomScrollPane(vv3));

    JButton h1 = new JButton("?");
    h1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            textArea.setText(messageOne);
            JOptionPane.showMessageDialog(p1, scrollPane, "View 1", JOptionPane.PLAIN_MESSAGE);
        }
    });
    JButton h2 = new JButton("?");
    h2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            textArea.setText(messageTwo);
            JOptionPane.showMessageDialog(p2, scrollPane, "View 2", JOptionPane.PLAIN_MESSAGE);
        }
    });
    JButton h3 = new JButton("?");
    h3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            textArea.setText(messageThree);
            textArea.setCaretPosition(0);
            JOptionPane.showMessageDialog(p3, scrollPane, "View 3", JOptionPane.PLAIN_MESSAGE);
        }
    });

    // create a GraphMouse for each view
    // each one has a different scaling plugin
    DefaultModalGraphMouse gm1 = new DefaultModalGraphMouse() {
        protected void loadPlugins() {
            pickingPlugin = new PickingGraphMousePlugin();
            animatedPickingPlugin = new AnimatedPickingGraphMousePlugin();
            translatingPlugin = new TranslatingGraphMousePlugin(InputEvent.BUTTON1_MASK);
            scalingPlugin = new ScalingGraphMousePlugin(new LayoutScalingControl(), 0);
            rotatingPlugin = new RotatingGraphMousePlugin();
            shearingPlugin = new ShearingGraphMousePlugin();

            add(scalingPlugin);
            setMode(Mode.TRANSFORMING);
        }
    };

    DefaultModalGraphMouse gm2 = new DefaultModalGraphMouse() {
        protected void loadPlugins() {
            pickingPlugin = new PickingGraphMousePlugin();
            animatedPickingPlugin = new AnimatedPickingGraphMousePlugin();
            translatingPlugin = new TranslatingGraphMousePlugin(InputEvent.BUTTON1_MASK);
            scalingPlugin = new ScalingGraphMousePlugin(new ViewScalingControl(), 0);
            rotatingPlugin = new RotatingGraphMousePlugin();
            shearingPlugin = new ShearingGraphMousePlugin();

            add(scalingPlugin);
            setMode(Mode.TRANSFORMING);
        }

    };

    DefaultModalGraphMouse gm3 = new DefaultModalGraphMouse() {
    };

    vv1.setGraphMouse(gm1);
    vv2.setGraphMouse(gm2);
    vv3.setGraphMouse(gm3);

    vv1.setToolTipText("<html><center>MouseWheel Scales Layout</center></html>");
    vv2.setToolTipText("<html><center>MouseWheel Scales View</center></html>");
    vv3.setToolTipText(
            "<html><center>MouseWheel Scales Layout and<p>crosses over to view<p>ctrl+MouseWheel scales view</center></html>");

    vv1.addPostRenderPaintable(new BannerLabel(vv1, "View 1"));
    vv2.addPostRenderPaintable(new BannerLabel(vv2, "View 2"));
    vv3.addPostRenderPaintable(new BannerLabel(vv3, "View 3"));

    textArea = new JTextArea(6, 30);
    scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.setEditable(false);

    JPanel flow = new JPanel();
    flow.add(h1);
    flow.add(gm1.getModeComboBox());
    p1.add(flow, BorderLayout.SOUTH);
    flow = new JPanel();
    flow.add(h2);
    flow.add(gm2.getModeComboBox());
    p2.add(flow, BorderLayout.SOUTH);
    flow = new JPanel();
    flow.add(h3);
    flow.add(gm3.getModeComboBox());
    p3.add(flow, BorderLayout.SOUTH);

    panel.add(p1);
    panel.add(p2);
    panel.add(p3);
    content.add(panel);

}

From source file:org.trade.ui.chart.renderer.HeikinAshiRenderer.java

/**
 * Method drawItem./*w w w. ja  v  a 2 s . c om*/
 * 
 * @param g2
 *            Graphics2D
 * @param state
 *            XYItemRendererState
 * @param dataArea
 *            Rectangle2D
 * @param info
 *            PlotRenderingInfo
 * @param plot
 *            XYPlot
 * @param domainAxis
 *            ValueAxis
 * @param rangeAxis
 *            ValueAxis
 * @param dataset
 *            XYDataset
 * @param series
 *            int
 * @param item
 *            int
 * @param crosshairState
 *            CrosshairState
 * @param pass
 *            int
 * @see org.jfree.chart.renderer.xy.XYItemRenderer#drawItem(Graphics2D,
 *      XYItemRendererState, Rectangle2D, PlotRenderingInfo, XYPlot,
 *      ValueAxis, ValueAxis, XYDataset, int, int, CrosshairState, int)
 */
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    if (dataset instanceof HeikinAshiDataset) {

        // setup for collecting optional entity info...
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
        }

        HeikinAshiDataset highLowData = (HeikinAshiDataset) dataset;

        double x = highLowData.getXValue(series, item);
        double yHigh = highLowData.getHighValue(series, item);
        double yLow = highLowData.getLowValue(series, item);
        double yOpen = highLowData.getOpenValue(series, item);
        double yClose = highLowData.getCloseValue(series, item);

        RectangleEdge domainEdge = plot.getDomainAxisEdge();
        double xx = domainAxis.valueToJava2D(x, dataArea, domainEdge);

        RectangleEdge edge = plot.getRangeAxisEdge();
        double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, edge);
        double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, edge);
        double yyOpen = rangeAxis.valueToJava2D(yOpen, dataArea, edge);
        double yyClose = rangeAxis.valueToJava2D(yClose, dataArea, edge);

        int itemCount = highLowData.getItemCount(series);
        double xxWidth = dataArea.getWidth() / itemCount;

        xxWidth -= 2 * this.getAutoWidthGap();
        xxWidth *= this.getAutoWidthFactor();
        xxWidth = Math.min(xxWidth, this.maxCandleWidth);
        double stickWidth = Math.max(Math.min(3, this.maxCandleWidth), xxWidth);

        Paint outlinePaint = null;
        outlinePaint = getItemOutlinePaint(series, item);
        g2.setStroke(getItemStroke(series, item));
        g2.setPaint(outlinePaint);

        double yyMaxOpenClose = Math.max(yyOpen, yyClose);
        double yyMinOpenClose = Math.min(yyOpen, yyClose);
        double maxOpenClose = Math.max(yOpen, yClose);
        double minOpenClose = Math.min(yOpen, yClose);

        Shape body = null;
        boolean highlight = highlight(series, item);
        /**********************************
         * draw the upper shadow START
         **********************************/

        if (yHigh > maxOpenClose) {
            if (highlight) {
                body = new Rectangle2D.Double(xx - (stickWidth / 2), yyHigh - 10, stickWidth,
                        (yyMaxOpenClose - yyHigh) + 10);
                g2.setPaint(Color.YELLOW);
                g2.fill(body);
                g2.draw(body);
            }
        }

        if (yHigh > maxOpenClose) {
            if (nightMode) {
                if (yClose > yOpen) {
                    g2.setPaint(upPaint);
                } else {
                    g2.setPaint(downPaint);
                }
            } else {
                g2.setPaint(Color.black);
            }

            g2.draw(new Line2D.Double(xx, yyHigh, xx, yyMaxOpenClose));
        }

        /**********************************
         * draw the lower shadow START
         **********************************/
        if (yLow < minOpenClose) {
            if (highlight) {
                body = new Rectangle2D.Double(xx - (stickWidth / 2), yyMinOpenClose, stickWidth,
                        (yyLow - yyMinOpenClose) + 10);
                g2.setPaint(Color.YELLOW);
                g2.fill(body);
                g2.draw(body);
            }
            if (yLow < minOpenClose) {
                if (nightMode) {
                    if (yClose > yOpen) {
                        g2.setPaint(upPaint);
                    } else {
                        g2.setPaint(downPaint);
                    }
                } else {
                    g2.setPaint(Color.BLACK);
                }
                g2.draw(new Line2D.Double(xx, yyLow, xx, yyMinOpenClose));
            }
        }

        /**********************************
         * draw the body
         **********************************/

        body = new Rectangle2D.Double(xx - (stickWidth / 2), yyMinOpenClose, stickWidth,
                yyMaxOpenClose - yyMinOpenClose);

        if (nightMode) {
            g2.setPaint(Color.white);
        } else {
            if (yClose > yOpen) {
                g2.setPaint(upPaint);
            } else {
                g2.setPaint(downPaint);
            }
        }

        g2.fill(body);
        g2.draw(body);

        if (nightMode) {
            if (yClose > yOpen) {
                g2.setPaint(upPaint);
            } else {
                g2.setPaint(downPaint);
            }
        } else {
            g2.setPaint(outlinePaint);
        }
        g2.draw(body);
        // add an entity for the item...
        if (entities != null) {
            String tip = null;
            XYToolTipGenerator generator = getToolTipGenerator(series, item);
            if (generator != null) {
                tip = generator.generateToolTip(dataset, series, item);
            }

            XYItemEntity entity = new XYItemEntity(body, dataset, series, item, tip, null);

            entities.add(entity);
        }
    }
}