Example usage for java.awt Color orange

List of usage examples for java.awt Color orange

Introduction

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

Prototype

Color orange

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

Click Source Link

Document

The color orange.

Usage

From source file:ColorComboBox.java

public static void main(String args[]) {
    Color colors[] = { Color.black, Color.blue, Color.cyan, Color.darkGray, Color.gray, Color.green,
            Color.lightGray, Color.magenta, Color.orange, Color.pink, Color.red, Color.white, Color.yellow };
    JFrame frame = new JFrame("Color JComboBox");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();

    final JComboBox comboBox = new JComboBox(colors);
    comboBox.setMaximumRowCount(5);/*from   w  ww . j av  a2s.c om*/
    comboBox.setEditable(true);
    comboBox.setRenderer(new ColorCellRenderer());
    Color color = (Color) comboBox.getSelectedItem();
    ComboBoxEditor editor = new ColorComboBoxEditor(color);
    comboBox.setEditor(editor);
    contentPane.add(comboBox, BorderLayout.NORTH);

    final JLabel label = new JLabel();
    label.setOpaque(true);
    label.setBackground((Color) comboBox.getSelectedItem());
    contentPane.add(label, BorderLayout.CENTER);

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Color selectedColor = (Color) comboBox.getSelectedItem();
            label.setBackground(selectedColor);
        }
    };
    comboBox.addActionListener(actionListener);

    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:com.offbynull.peernetic.debug.visualizer.App.java

public static void main(String[] args) throws Throwable {
    Random random = new Random();
    Visualizer<Integer> visualizer = new JGraphXVisualizer<>();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Recorder<Integer> recorder = new XStreamRecorder(baos);

    visualizer.visualize(recorder, null);

    visualizer.step("Adding nodes 1 and 2", new AddNodeCommand<>(1),
            new ChangeNodeCommand(1, null, new Point(random.nextInt(400), random.nextInt(400)), Color.RED),
            new AddNodeCommand<>(2),
            new ChangeNodeCommand(2, null, new Point(random.nextInt(400), random.nextInt(400)), Color.BLUE));
    Thread.sleep(500);//from w  w  w . j ava2 s .  com

    visualizer.step("Adding nodes 3 and 4", new AddNodeCommand<>(3),
            new ChangeNodeCommand(3, null, new Point(random.nextInt(400), random.nextInt(400)), Color.ORANGE),
            new AddNodeCommand<>(4),
            new ChangeNodeCommand(4, null, new Point(random.nextInt(400), random.nextInt(400)), Color.PINK));
    Thread.sleep(500);

    visualizer.step("Connecting 1/2/3 to 4", new AddEdgeCommand<>(1, 4), new AddEdgeCommand<>(2, 4),
            new AddEdgeCommand<>(3, 4));
    Thread.sleep(500);

    visualizer.step("Adding trigger to 4 when no more edges",
            new TriggerOnLingeringNodeCommand(4, new RemoveNodeCommand<>(4)));
    Thread.sleep(500);

    visualizer.step("Removing connections from 1 and 2", new RemoveEdgeCommand<>(1, 4),
            new RemoveEdgeCommand<>(2, 4));
    Thread.sleep(500);

    visualizer.step("Removing connections from 3", new RemoveEdgeCommand<>(3, 4));
    Thread.sleep(500);

    recorder.close();

    Thread.sleep(2000);

    JGraphXVisualizer<Integer> visualizer2 = new JGraphXVisualizer<>();
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    Player<Integer> player = new XStreamPlayer<>(bais);

    visualizer2.visualize();

    player.play(visualizer2);

}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document(PageSize.A4.rotate());
    PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();// w  w  w  .  j a  v  a2s  .  co  m
    PdfPTable table = new PdfPTable(4);
    table.setWidthPercentage(100);
    PdfPCell cell;
    cell = new PdfPCell(new Paragraph("t"));
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph("d"));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setBackgroundColor(Color.red);
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph("r"));
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph("b"));
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph("G:"));
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph("0.25"));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setGrayFill(0.25f);
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph("0.5"));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setGrayFill(0.5f);
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph("0.75"));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setGrayFill(0.75f);
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph(":"));
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph("a"));
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph("b"));
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph("o"));
    cell.setBorderWidth(6f);
    cell.setBorderColor(Color.orange);
    table.addCell(cell);
    document.add(table);

    document.close();
}

From source file:ComboTableCellRenderer.java

public static void main(String args[]) {
    Color choices[] = { Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.BLUE, Color.MAGENTA };
    ComboTableCellRenderer renderer = new ComboTableCellRenderer();
    JComboBox comboBox = new JComboBox(choices);
    comboBox.setRenderer(renderer);/* w  w w . ja v a 2 s.  com*/

    TableCellEditor editor = new DefaultCellEditor(comboBox);

    JFrame frame = new JFrame("Editable Color Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    TableModel model = new ColorTableModel();
    JTable table = new JTable(model);
    TableColumn column = table.getColumnModel().getColumn(1);
    column.setCellRenderer(renderer);
    column.setCellEditor(editor);

    JScrollPane scrollPane = new JScrollPane(table);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:nz.ac.waikato.cms.supernova.SupernovaCSV.java

public static void main(String[] args) throws Exception {
    ArgumentParser parser;/* w w  w .  ja  v a2  s .  co  m*/

    parser = ArgumentParsers.newArgumentParser("I am supernova");
    parser.description("Generates output according to 'I am supernova' by Keith Soo.\n"
            + "Loads scores/percentiles from a CSV file to generate multiple outputs at once.\n"
            + "Expected four columns (name of column is irrelevant):\n"
            + "- ID: the filename (excluding path and extension)\n" + "- Measure: the measure (" + MEASURE_LIST
            + ")\n" + "- Score: the score of the measure\n" + "- Percentile: the percentile of the measure\n"
            + "\n" + "Project homepage:\n" + "https://github.com/fracpete/i-am-supernova");

    // colors
    parser.addArgument("--" + AbstractOutputGenerator.OPENNESS + COLOR_SUFFIX)
            .metavar(AbstractOutputGenerator.OPENNESS + COLOR_SUFFIX).type(String.class)
            .setDefault(ColorHelper.toHex(Color.ORANGE))
            .help("The color for '" + AbstractOutputGenerator.OPENNESS + "' in hex format (e.g., "
                    + ColorHelper.toHex(Color.ORANGE) + ").");
    parser.addArgument("--" + AbstractOutputGenerator.EXTRAVERSION + COLOR_SUFFIX)
            .metavar(AbstractOutputGenerator.EXTRAVERSION + COLOR_SUFFIX).type(String.class)
            .setDefault(ColorHelper.toHex(Color.YELLOW))
            .help("The color for '" + AbstractOutputGenerator.EXTRAVERSION + "' in hex format (e.g., "
                    + ColorHelper.toHex(Color.YELLOW) + ").");
    parser.addArgument("--" + AbstractOutputGenerator.AGREEABLENESS + COLOR_SUFFIX)
            .metavar(AbstractOutputGenerator.AGREEABLENESS + COLOR_SUFFIX).type(String.class)
            .setDefault(ColorHelper.toHex(Color.GREEN))
            .help("The color for '" + AbstractOutputGenerator.AGREEABLENESS + "' in hex format (e.g., "
                    + ColorHelper.toHex(Color.GREEN) + ").");
    parser.addArgument("--" + AbstractOutputGenerator.CONSCIENTIOUSNESS + COLOR_SUFFIX)
            .metavar(AbstractOutputGenerator.CONSCIENTIOUSNESS + COLOR_SUFFIX).type(String.class)
            .setDefault(ColorHelper.toHex(Color.BLUE))
            .help("The color for '" + AbstractOutputGenerator.CONSCIENTIOUSNESS + "' in hex format (e.g., "
                    + ColorHelper.toHex(Color.BLUE) + ").");
    parser.addArgument("--" + AbstractOutputGenerator.NEUROTICISM + COLOR_SUFFIX)
            .metavar(AbstractOutputGenerator.NEUROTICISM + COLOR_SUFFIX).type(String.class)
            .setDefault(ColorHelper.toHex(Color.RED))
            .help("The color for '" + AbstractOutputGenerator.NEUROTICISM + "' in hex format (e.g., "
                    + ColorHelper.toHex(Color.RED) + ").");

    // other parameters
    parser.addArgument("--" + CSV).metavar(CSV).type(String.class).required(true)
            .help("The CSV file containing the scores/percentiles (header must be present).");

    parser.addArgument("--" + ID).metavar(ID).type(Integer.class).setDefault(1)
            .help("The 1-based index of the column in the CSV file containing the ID for the output file.");

    parser.addArgument("--" + MEASURE).metavar(MEASURE).type(Integer.class).setDefault(2)
            .help("The 1-based index of the column in the CSV file containing the measure name.\n"
                    + "Allowed values: " + MEASURE_LIST);

    parser.addArgument("--" + SCORE).metavar(SCORE).type(Integer.class).setDefault(3)
            .help("The 1-based index of the column in the CSV file containing the scores.");

    parser.addArgument("--" + PERCENTILE).metavar(PERCENTILE).type(Integer.class).setDefault(4)
            .help("The 1-based index of the column in the CSV file containing the percentiles.");

    parser.addArgument("--" + BACKGROUND).metavar(BACKGROUND).type(String.class)
            .setDefault(ColorHelper.toHex(Color.BLACK)).help("The background color.");

    parser.addArgument("--" + OPACITY).metavar(OPACITY).type(Double.class).setDefault(0.1)
            .help("The opacity (0-1).");

    parser.addArgument("--" + MARGIN).metavar(MARGIN).type(Double.class).setDefault(0.2)
            .help("The margin in the output (0-1).");

    parser.addArgument("--" + WIDTH).metavar(WIDTH).type(Integer.class).setDefault(2000)
            .help("The width of the output.");

    parser.addArgument("--" + HEIGHT).metavar(HEIGHT).type(Integer.class).setDefault(2000)
            .help("The height of the output.");

    parser.addArgument("--" + CENTER).metavar(CENTER).type(String.class).setDefault(Incenter.class.getName())
            .help("The name of the algorithm for calculating the center of a triangle.\n" + "Available: "
                    + Registry.toString(Registry.getCenters(), true));

    parser.addArgument("--" + GENERATOR).metavar(GENERATOR).type(String.class).setDefault(PNG.class.getName())
            .help("The name of the generator class to use.\n" + "Available: "
                    + Registry.toString(Registry.getGenerators(), true));

    parser.addArgument("--" + OUTPUT).metavar(OUTPUT).type(String.class)
            .help("The directory to store the output in.");

    parser.addArgument("--" + VERBOSE).metavar(VERBOSE).type(Boolean.class).action(Arguments.storeTrue())
            .help("Whether to output logging information.");

    Namespace namespace;
    try {
        namespace = parser.parseArgs(args);
    } catch (Exception e) {
        if (!(e instanceof HelpScreenException))
            parser.printHelp();
        return;
    }

    // colors
    Map<String, Color> colors = new HashMap<>();
    colors.put(AbstractOutputGenerator.OPENNESS, ColorHelper
            .valueOf(namespace.getString(AbstractOutputGenerator.OPENNESS + COLOR_SUFFIX), Color.ORANGE));
    colors.put(AbstractOutputGenerator.EXTRAVERSION, ColorHelper
            .valueOf(namespace.getString(AbstractOutputGenerator.EXTRAVERSION + COLOR_SUFFIX), Color.YELLOW));
    colors.put(AbstractOutputGenerator.AGREEABLENESS, ColorHelper
            .valueOf(namespace.getString(AbstractOutputGenerator.AGREEABLENESS + COLOR_SUFFIX), Color.GREEN));
    colors.put(AbstractOutputGenerator.CONSCIENTIOUSNESS, ColorHelper.valueOf(
            namespace.getString(AbstractOutputGenerator.CONSCIENTIOUSNESS + COLOR_SUFFIX), Color.BLUE));
    colors.put(AbstractOutputGenerator.NEUROTICISM, ColorHelper
            .valueOf(namespace.getString(AbstractOutputGenerator.NEUROTICISM + COLOR_SUFFIX), Color.RED));

    File outdir = new File(namespace.getString(OUTPUT));

    String centerCls = namespace.getString(CENTER);
    if (!centerCls.contains("."))
        centerCls = AbstractTriangleCenterCalculation.class.getPackage().getName() + "." + centerCls;
    String generatorCls = namespace.getString(GENERATOR);
    if (!generatorCls.contains("."))
        generatorCls = AbstractOutputGenerator.class.getPackage().getName() + "." + generatorCls;
    AbstractOutputGenerator generator = (AbstractOutputGenerator) Class.forName(generatorCls).newInstance();
    generator.setVerbose(namespace.getBoolean(VERBOSE));
    generator.setColors(colors);
    generator.setBackground(ColorHelper.valueOf(namespace.getString(BACKGROUND), Color.BLACK));
    generator.setOpacity(namespace.getDouble(OPACITY));
    generator.setMargin(namespace.getDouble(MARGIN));
    generator.setCenter((AbstractTriangleCenterCalculation) Class.forName(centerCls).newInstance());
    if (generator instanceof AbstractOutputGeneratorWithDimensions) {
        AbstractOutputGeneratorWithDimensions pixel = (AbstractOutputGeneratorWithDimensions) generator;
        pixel.setWidth(namespace.getInt(WIDTH));
        pixel.setHeight(namespace.getInt(HEIGHT));
    }

    int colID = namespace.getInt(ID) - 1;
    int colMeasure = namespace.getInt(MEASURE) - 1;
    int colScore = namespace.getInt(SCORE) - 1;
    int colPercentile = namespace.getInt(PERCENTILE) - 1;
    Reader reader = new FileReader(namespace.getString(CSV));
    CSVParser csvparser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
    String oldID = "";
    Map<String, List<Double>> test = new HashMap<>();
    for (CSVRecord rec : csvparser) {
        if (rec.size() < 4)
            continue;
        String id = rec.get(colID);
        if (!id.equals(oldID)) {
            if (!test.isEmpty()) {
                File outfile = new File(outdir + File.separator + oldID + "." + generator.getExtension());
                String msg = generator.generate(test, outfile);
                if (msg != null)
                    System.err.println("Failed to generate output for ID: " + oldID);
            }
            test.clear();
            oldID = id;
        }
        String measure = rec.get(colMeasure);
        double score = Double.parseDouble(rec.get(colScore));
        double percentile = Double.parseDouble(rec.get(colPercentile));
        test.put(measure, new ArrayList<>(Arrays.asList(new Double[] { score, percentile })));
    }
    if (!test.isEmpty()) {
        File outfile = new File(outdir + File.separator + oldID + "." + generator.getExtension());
        String msg = generator.generate(test, outfile);
        if (msg != null)
            System.err.println("Failed to generate output for ID: " + oldID);
    }
}

From source file:PowerMethod.power_method.java

public static void main(String[] args) {
    //////////////////////////////////////////////////////
    // Edit vals to contain values for matrix A         //
    // Edit vals2 to contain values for initial vector  //
    //////////////////////////////////////////////////////
    double[][] vals = { { 3, 4 }, { 3, 1 } };
    RealMatrix A = new Array2DRowRealMatrix(vals);
    double[][] vals2 = { { 1 }, { 1 } };
    RealMatrix u = new Array2DRowRealMatrix(vals2);
    power_object a = power_method(A, u, .1, 7);

    List<RealMatrix> matrices = genMatrices();
    List<trace_det> trace_dets = new ArrayList<>();
    double trace;
    double det;/*www. java  2  s.c  o  m*/
    int iterA;
    int iterInverseA;
    for (RealMatrix r : matrices) {
        MatrixMethods m = new MatrixMethods(r);
        RealMatrix inverseR = m.inverseMatrix();
        power_object largestVal = power_method(r, u, .00005, 100);
        power_object smallestVal = power_method(inverseR, u, .00005, 100);
        if (largestVal == null || smallestVal == null) {
            continue;
        }
        trace = m.trace();
        det = m.determinant();
        iterA = largestVal.getNumN();
        iterInverseA = smallestVal.getNumN();
        trace_det td = new trace_det(trace, det, iterA, iterInverseA);
        trace_dets.add(td);
    }
    JFreeChart chart = ChartFactory.createXYLineChart("Trace vs. Determinant for Power Method", "Determinant",
            "Trace", createDataSetA(trace_dets), PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    final XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.BLUE);
    renderer.setSeriesPaint(2, Color.GREEN);
    renderer.setSeriesPaint(3, Color.BLACK);
    renderer.setSeriesPaint(4, Color.YELLOW);
    renderer.setSeriesPaint(5, Color.PINK);
    renderer.setSeriesPaint(6, Color.ORANGE);
    renderer.setSeriesPaint(7, Color.GRAY);
    renderer.setSeriesPaint(8, Color.MAGENTA);
    renderer.setSeriesPaint(9, Color.LIGHT_GRAY);
    renderer.setSeriesPaint(10, Color.DARK_GRAY);
    //renderer.setSeriesStroke( 0 , new BasicStroke( 3.0f ) );
    //renderer.setSeriesStroke( 1 , new BasicStroke( 2.0f ) );
    plot.setRenderer(renderer);
    ChartFrame frame = new ChartFrame("Power Method", chart);
    frame.pack();
    frame.setVisible(true);

    JFreeChart inverseChart = ChartFactory.createXYLineChart("Trace vs. Determinant for Inverse Power Method",
            "Determinant", "Trace", createDataSetAInverse(trace_dets), PlotOrientation.VERTICAL, true, true,
            false);
    ChartPanel inverseChartPanel = new ChartPanel(inverseChart);
    inverseChartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    final XYPlot inversePlot = inverseChart.getXYPlot();
    XYLineAndShapeRenderer inverseRenderer = new XYLineAndShapeRenderer();
    inverseRenderer.setSeriesPaint(0, Color.RED);
    inverseRenderer.setSeriesPaint(1, Color.BLUE);
    inverseRenderer.setSeriesPaint(2, Color.GREEN);
    inverseRenderer.setSeriesPaint(3, Color.BLACK);
    inverseRenderer.setSeriesPaint(4, Color.YELLOW);
    inverseRenderer.setSeriesPaint(5, Color.PINK);
    inverseRenderer.setSeriesPaint(6, Color.ORANGE);
    inverseRenderer.setSeriesPaint(7, Color.GRAY);
    inverseRenderer.setSeriesPaint(8, Color.MAGENTA);
    inverseRenderer.setSeriesPaint(9, Color.LIGHT_GRAY);
    inverseRenderer.setSeriesPaint(10, Color.DARK_GRAY);
    inversePlot.setRenderer(renderer);
    ChartFrame inverseFrame = new ChartFrame("Power Method", inverseChart);
    inverseFrame.pack();
    inverseFrame.setVisible(true);
}

From source file:Graph_with_jframe_and_arduino.java

public static void main(String[] args) {

    // create and configure the window
    JFrame window = new JFrame();
    window.setTitle("Sensor Graph GUI");
    window.setSize(600, 400);//from  ww w.  j  a va 2s  .co m
    window.setLayout(new BorderLayout());
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // create a drop-down box and connect button, then place them at the top of the window
    JComboBox<String> portList_combobox = new JComboBox<String>();
    Dimension d = new Dimension(300, 100);
    portList_combobox.setSize(d);
    JButton connectButton = new JButton("Connect");
    JPanel topPanel = new JPanel();
    topPanel.add(portList_combobox);
    topPanel.add(connectButton);
    window.add(topPanel, BorderLayout.NORTH);
    //pause button
    JButton Pause_btn = new JButton("Start");

    // populate the drop-down box
    SerialPort[] portNames;
    portNames = SerialPort.getCommPorts();
    //check for new port available
    Thread thread_port = new Thread() {
        @Override
        public void run() {
            while (true) {
                SerialPort[] sp = SerialPort.getCommPorts();
                if (sp.length > 0) {
                    for (SerialPort sp_name : sp) {
                        int l = portList_combobox.getItemCount(), i;
                        for (i = 0; i < l; i++) {
                            //check port name already exist or not
                            if (sp_name.getSystemPortName().equalsIgnoreCase(portList_combobox.getItemAt(i))) {
                                break;
                            }
                        }
                        if (i == l) {
                            portList_combobox.addItem(sp_name.getSystemPortName());
                        }

                    }

                } else {
                    portList_combobox.removeAllItems();

                }
                portList_combobox.repaint();

            }

        }

    };
    thread_port.start();
    for (SerialPort sp_name : portNames)
        portList_combobox.addItem(sp_name.getSystemPortName());

    //for(int i = 0; i < portNames.length; i++)
    //   portList.addItem(portNames[i].getSystemPortName());

    // create the line graph
    XYSeries series = new XYSeries("line 1");
    XYSeries series2 = new XYSeries("line 2");
    XYSeries series3 = new XYSeries("line 3");
    XYSeries series4 = new XYSeries("line 4");
    for (int i = 0; i < 100; i++) {
        series.add(x, 0);
        series2.add(x, 0);
        series3.add(x, 0);
        series4.add(x, 10);
        x++;
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);
    dataset.addSeries(series2);
    XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(series3);
    dataset2.addSeries(series4);

    //create jfree chart
    JFreeChart chart = ChartFactory.createXYLineChart("Sensor Readings", "Time (seconds)", "Arduino Reading",
            dataset);
    JFreeChart chart2 = ChartFactory.createXYLineChart("Sensor Readings", "Time (seconds)", "Arduino Reading 2",
            dataset2);

    //color render for chart 1
    XYLineAndShapeRenderer r1 = new XYLineAndShapeRenderer();
    r1.setSeriesPaint(0, Color.RED);
    r1.setSeriesPaint(1, Color.GREEN);
    r1.setSeriesShapesVisible(0, false);
    r1.setSeriesShapesVisible(1, false);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(0, r1);
    plot.setRenderer(1, r1);

    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.blue);

    //color render for chart 2
    XYLineAndShapeRenderer r2 = new XYLineAndShapeRenderer();
    r2.setSeriesPaint(0, Color.BLUE);
    r2.setSeriesPaint(1, Color.ORANGE);
    r2.setSeriesShapesVisible(0, false);
    r2.setSeriesShapesVisible(1, false);

    XYPlot plot2 = chart2.getXYPlot();
    plot2.setRenderer(0, r2);
    plot2.setRenderer(1, r2);

    ChartPanel cp = new ChartPanel(chart);
    ChartPanel cp2 = new ChartPanel(chart2);

    //multiple graph container
    JPanel graph_container = new JPanel();
    graph_container.setLayout(new BoxLayout(graph_container, BoxLayout.X_AXIS));
    graph_container.add(cp);
    graph_container.add(cp2);

    //add chart panel in main window
    window.add(graph_container, BorderLayout.CENTER);
    //window.add(cp2, BorderLayout.WEST);

    window.add(Pause_btn, BorderLayout.AFTER_LAST_LINE);
    Pause_btn.setEnabled(false);
    //pause btn action
    Pause_btn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (Pause_btn.getText().equalsIgnoreCase("Pause")) {

                if (chosenPort.isOpen()) {
                    try {
                        Output.write(0);
                    } catch (IOException ex) {
                        Logger.getLogger(Graph_with_jframe_and_arduino.class.getName()).log(Level.SEVERE, null,
                                ex);
                    }
                }

                Pause_btn.setText("Start");
            } else {
                if (chosenPort.isOpen()) {
                    try {
                        Output.write(1);
                    } catch (IOException ex) {
                        Logger.getLogger(Graph_with_jframe_and_arduino.class.getName()).log(Level.SEVERE, null,
                                ex);
                    }
                }

                Pause_btn.setText("Pause");
            }
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });

    // configure the connect button and use another thread to listen for data
    connectButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            if (connectButton.getText().equals("Connect")) {
                // attempt to connect to the serial port
                chosenPort = SerialPort.getCommPort(portList_combobox.getSelectedItem().toString());
                chosenPort.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 0, 0);
                if (chosenPort.openPort()) {
                    Output = chosenPort.getOutputStream();
                    connectButton.setText("Disconnect");
                    Pause_btn.setEnabled(true);
                    portList_combobox.setEnabled(false);
                }

                // create a new thread that listens for incoming text and populates the graph
                Thread thread = new Thread() {
                    @Override
                    public void run() {
                        Scanner scanner = new Scanner(chosenPort.getInputStream());
                        while (scanner.hasNextLine()) {
                            try {
                                String line = scanner.nextLine();
                                int number = Integer.parseInt(line);
                                series.add(x, number);
                                series2.add(x, number / 2);
                                series3.add(x, number / 1.5);
                                series4.add(x, number / 5);

                                if (x > 100) {
                                    series.remove(0);
                                    series2.remove(0);
                                    series3.remove(0);
                                    series4.remove(0);
                                }

                                x++;
                                window.repaint();
                            } catch (Exception e) {
                            }
                        }
                        scanner.close();
                    }
                };
                thread.start();
            } else {
                // disconnect from the serial port
                chosenPort.closePort();
                portList_combobox.setEnabled(true);
                Pause_btn.setEnabled(false);
                connectButton.setText("Connect");

            }
        }
    });

    // show the window
    window.setVisible(true);
}

From source file:com.oculusinfo.ml.spark.unsupervised.TestDPMeans.java

/**
 * @param args// w ww  .j ava  2 s.c  o m
 */
public static void main(String[] args) {
    int k = 5;

    try {
        FileUtils.deleteDirectory(new File("output/clusters"));
        FileUtils.deleteDirectory(new File("output/centroids"));
    } catch (IOException e1) {
        /* ignore (*/ }

    genTestData(k);

    JavaSparkContext sc = new JavaSparkContext("local", "OculusML");
    SparkDataSet ds = new SparkDataSet(sc);
    ds.load("test.txt", new InstanceParser());

    DPMeansClusterer clusterer = new DPMeansClusterer(80, 10, 0.001);
    clusterer.setOutputPaths("output/centroids", "output/clusters");

    clusterer.registerFeatureType("point", MeanNumericVectorCentroid.class, new EuclideanDistance(1.0));

    clusterer.doCluster(ds);

    try {
        final List<double[]> instances = readInstances();

        final Color[] colors = { Color.red, Color.blue, Color.green, Color.magenta, Color.yellow, Color.black,
                Color.orange, Color.cyan, Color.darkGray, Color.white };

        TestDPMeans t = new TestDPMeans();
        t.add(new JComponent() {
            private static final long serialVersionUID = 7920802321066846416L;

            public void paintComponent(Graphics g) {
                Graphics2D g2 = (Graphics2D) g;
                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

                for (double[] inst : instances) {
                    int color = (int) inst[0];
                    g.setColor(colors[color]);

                    Ellipse2D l = new Ellipse2D.Double(inst[1], inst[2], 5, 5);
                    g2.draw(l);
                }
            }
        });

        t.setDefaultCloseOperation(EXIT_ON_CLOSE);
        t.setSize(400, 400);
        t.setVisible(true);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.oculusinfo.ml.spark.unsupervised.TestThresholdClusterer.java

/**
 * @param args/* w w w.j  a v a2s.c  om*/
 */
public static void main(String[] args) {
    int k = 5;

    try {
        FileUtils.deleteDirectory(new File("output/clusters"));
        FileUtils.deleteDirectory(new File("output/centroids"));
    } catch (IOException e1) {
        /* ignore (*/ }

    genTestData(k);

    JavaSparkContext sc = new JavaSparkContext("local", "OculusML");
    SparkDataSet ds = new SparkDataSet(sc);
    ds.load("test.txt", new InstanceParser());

    ThresholdClusterer clusterer = new ThresholdClusterer(80);
    clusterer.setOutputPaths("output/centroids", "output/clusters");

    clusterer.registerFeatureType("point", MeanNumericVectorCentroid.class, new EuclideanDistance(1.0));

    clusterer.doCluster(ds);

    try {
        final List<double[]> instances = readInstances();

        final Color[] colors = { Color.red, Color.blue, Color.green, Color.magenta, Color.yellow, Color.black,
                Color.orange, Color.cyan, Color.darkGray, Color.white };

        TestThresholdClusterer t = new TestThresholdClusterer();
        t.add(new JComponent() {
            private static final long serialVersionUID = -5597119848880912541L;

            public void paintComponent(Graphics g) {
                Graphics2D g2 = (Graphics2D) g;
                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

                for (double[] inst : instances) {
                    int color = (int) inst[0];
                    g.setColor(colors[color]);

                    Ellipse2D l = new Ellipse2D.Double(inst[1], inst[2], 5, 5);
                    g2.draw(l);
                }
            }
        });

        t.setDefaultCloseOperation(EXIT_ON_CLOSE);
        t.setSize(400, 400);
        t.setVisible(true);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.oculusinfo.ml.spark.unsupervised.TestKMeans.java

/**
 * @param args//from  w ww .  j  a v  a  2 s  . c  o  m
 */
public static void main(String[] args) {
    int k = 5;

    try {
        FileUtils.deleteDirectory(new File("output/clusters"));
        FileUtils.deleteDirectory(new File("output/centroids"));
    } catch (IOException e1) {
        /* ignore (*/ }

    genTestData(k);

    JavaSparkContext sc = new JavaSparkContext("local", "OculusML");
    SparkDataSet ds = new SparkDataSet(sc);
    ds.load("test.txt", new SparkInstanceParser() {
        private static final long serialVersionUID = 1L;

        @Override
        public Tuple2<String, Instance> call(String line) throws Exception {
            Instance inst = new Instance();

            String tokens[] = line.split(",");

            NumericVectorFeature v = new NumericVectorFeature("point");

            double x = Double.parseDouble(tokens[0]);
            double y = Double.parseDouble(tokens[1]);
            v.setValue(new double[] { x, y });

            inst.addFeature(v);

            return new Tuple2<String, Instance>(inst.getId(), inst);
        }
    });

    KMeansClusterer clusterer = new KMeansClusterer(k, 10, 0.001, "output/centroids", "output/clusters");

    clusterer.registerFeatureType("point", MeanNumericVectorCentroid.class, new EuclideanDistance(1.0));

    clusterer.doCluster(ds);

    try {
        final List<double[]> instances = readInstances();

        final Color[] colors = { Color.red, Color.blue, Color.green, Color.magenta, Color.yellow, Color.black,
                Color.orange, Color.cyan, Color.darkGray, Color.white };

        TestKMeans t = new TestKMeans();
        t.add(new JComponent() {
            private static final long serialVersionUID = 2059497051387104848L;

            public void paintComponent(Graphics g) {
                Graphics2D g2 = (Graphics2D) g;
                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

                for (double[] inst : instances) {
                    int color = (int) inst[0];
                    g.setColor(colors[color]);

                    Ellipse2D l = new Ellipse2D.Double(inst[1], inst[2], 5, 5);
                    g2.draw(l);
                }
            }
        });

        t.setDefaultCloseOperation(EXIT_ON_CLOSE);
        t.setSize(400, 400);
        t.setVisible(true);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}