List of usage examples for java.awt Color WHITE
Color WHITE
To view the source code for java.awt Color WHITE.
Click Source Link
From source file:edu.packt.neuralnet.som.Kohonen2DTest.java
public static void main(String[] args) { RandomNumberGenerator.seed = System.currentTimeMillis(); int numberOfInputs = 2; int neuronsGridX = 12; int neuronsGridY = 12; int numberOfPoints = 1000; double[][] rndDataSet; rndDataSet = RandomNumberGenerator.GenerateMatrixGaussian(numberOfPoints, numberOfInputs, 100.0, 1.0); //rndDataSet = RandomNumberGenerator.GenerateMatrixBetween(numberOfPoints, numberOfInputs, 100.0, 110.0); for (int i = 0; i < numberOfPoints; i++) { rndDataSet[i][0] *= Math.sin(i); rndDataSet[i][0] += RandomNumberGenerator.GenerateNext() * 50; rndDataSet[i][1] *= Math.cos(i); rndDataSet[i][1] += RandomNumberGenerator.GenerateNext() * 50; }//www. j av a 2 s. c o m // for (int i=0;i<numberOfPoints;i++){ // rndDataSet[i][0]=i; // rndDataSet[i][0]+=RandomNumberGenerator.GenerateNext(); // rndDataSet[i][1]=Math.cos(i/100.0); // rndDataSet[i][1]+=RandomNumberGenerator.GenerateNext()*5; // } Kohonen kn2 = new Kohonen(numberOfInputs, neuronsGridX, neuronsGridY, new GaussianInitialization(500.0, 20.0)); NeuralDataSet neuralDataSet = new NeuralDataSet(rndDataSet, 2); CompetitiveLearning complrn = new CompetitiveLearning(kn2, neuralDataSet, LearningAlgorithm.LearningMode.ONLINE); complrn.show2DData = true; complrn.printTraining = true; complrn.setLearningRate(0.5); complrn.setMaxEpochs(1000); complrn.setReferenceEpoch(300); complrn.sleep = -1; try { String[] seriesNames = { "Training Data" }; Paint[] seriesColor = { Color.WHITE }; Chart chart = new Chart("Training", rndDataSet, seriesNames, 0, seriesColor, Chart.SeriesType.DOTS); ChartFrame frame = new ChartFrame("Training", chart.scatterPlot("X", "Y")); frame.pack(); frame.setVisible(true); // //System.in.read(); complrn.setPlot2DFrame(frame); complrn.showPlot2DData(); //System.in.read(); complrn.train(); } catch (Exception ne) { } }
From source file:ColorComboBoxEditor.java
public static void main(String args[]) { Color colors[] = { Color.RED, Color.BLUE, Color.BLACK, Color.WHITE }; JFrame frame = new JFrame("Editable JComboBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JComboBox comboBox = new JComboBox(colors); comboBox.setEditable(true);//from w w w.j ava 2 s. c o m comboBox.setEditor(new ColorComboBoxEditor(Color.RED)); frame.add(comboBox, BorderLayout.NORTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:com.github.fritaly.svngraph.SvnGraph.java
public static void main(String[] args) throws Exception { if (args.length != 2) { System.out.println(String.format("%s <input-file> <output-file>", SvnGraph.class.getSimpleName())); System.exit(1);//from w ww . jav a 2 s . com } final File input = new File(args[0]); if (!input.exists()) { throw new IllegalArgumentException( String.format("The given file '%s' doesn't exist", input.getAbsolutePath())); } final File output = new File(args[1]); final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(input); final History history = new History(document); final Set<String> rootPaths = history.getRootPaths(); System.out.println(rootPaths); for (String path : rootPaths) { System.out.println(path); System.out.println(history.getHistory(path).getRevisions()); System.out.println(); } int count = 0; FileWriter fileWriter = null; GraphMLWriter graphWriter = null; try { fileWriter = new FileWriter(output); graphWriter = new GraphMLWriter(fileWriter); final NodeStyle tagStyle = graphWriter.getNodeStyle(); tagStyle.setFillColor(Color.WHITE); graphWriter.graph(); // map associating node labels to their corresponding node id in the graph final Map<String, String> nodeIdsPerLabel = new TreeMap<>(); // the node style associated to each branch final Map<String, NodeStyle> nodeStyles = new TreeMap<>(); for (Revision revision : history.getSignificantRevisions()) { System.out.println(revision.getNumber() + " - " + revision.getMessage()); // TODO Render also the deletion of branches // there should be only 1 significant update per revision (the one with action ADD) for (Update update : revision.getSignificantUpdates()) { if (update.isCopy()) { // a merge is also considered a copy final RevisionPath source = update.getCopySource(); System.out.println(String.format(" > %s %s from %s@%d", update.getAction(), update.getPath(), source.getPath(), source.getRevision())); final String sourceRoot = Utils.getRootName(source.getPath()); if (sourceRoot == null) { // skip the revisions whose associated root is // null (happens whether a branch was created // outside the 'branches' directory for // instance) System.err.println(String.format("Skipped revision %d because of a null root", source.getRevision())); continue; } final String sourceLabel = computeNodeLabel(sourceRoot, source.getRevision()); // create a node for the source (path, revision) final String sourceId; if (nodeIdsPerLabel.containsKey(sourceLabel)) { // retrieve the id of the existing node sourceId = nodeIdsPerLabel.get(sourceLabel); } else { // create the new node if (Utils.isTagPath(source.getPath())) { graphWriter.setNodeStyle(tagStyle); } else { if (!nodeStyles.containsKey(sourceRoot)) { final NodeStyle style = new NodeStyle(); style.setFillColor(randomColor()); nodeStyles.put(sourceRoot, style); } graphWriter.setNodeStyle(nodeStyles.get(sourceRoot)); } sourceId = graphWriter.node(sourceLabel); nodeIdsPerLabel.put(sourceLabel, sourceId); } // and another for the newly created directory final String targetRoot = Utils.getRootName(update.getPath()); if (targetRoot == null) { System.err.println(String.format("Skipped revision %d because of a null root", revision.getNumber())); continue; } final String targetLabel = computeNodeLabel(targetRoot, revision.getNumber()); if (Utils.isTagPath(update.getPath())) { graphWriter.setNodeStyle(tagStyle); } else { if (!nodeStyles.containsKey(targetRoot)) { final NodeStyle style = new NodeStyle(); style.setFillColor(randomColor()); nodeStyles.put(targetRoot, style); } graphWriter.setNodeStyle(nodeStyles.get(targetRoot)); } final String targetId; if (nodeIdsPerLabel.containsKey(targetLabel)) { // retrieve the id of the existing node targetId = nodeIdsPerLabel.get(targetLabel); } else { // create the new node if (Utils.isTagPath(update.getPath())) { graphWriter.setNodeStyle(tagStyle); } else { if (!nodeStyles.containsKey(targetRoot)) { final NodeStyle style = new NodeStyle(); style.setFillColor(randomColor()); nodeStyles.put(targetRoot, style); } graphWriter.setNodeStyle(nodeStyles.get(targetRoot)); } targetId = graphWriter.node(targetLabel); nodeIdsPerLabel.put(targetLabel, targetId); } // create an edge between the 2 nodes graphWriter.edge(sourceId, targetId); } else { System.out.println(String.format(" > %s %s", update.getAction(), update.getPath())); } } System.out.println(); count++; } // Dispatch the revisions per corresponding branch final Map<String, Set<Long>> revisionsPerBranch = new TreeMap<>(); for (String nodeLabel : nodeIdsPerLabel.keySet()) { if (nodeLabel.contains("@")) { final String branchName = StringUtils.substringBefore(nodeLabel, "@"); final long revision = Long.parseLong(StringUtils.substringAfter(nodeLabel, "@")); if (!revisionsPerBranch.containsKey(branchName)) { revisionsPerBranch.put(branchName, new TreeSet<Long>()); } revisionsPerBranch.get(branchName).add(revision); } else { throw new IllegalStateException(nodeLabel); } } // Recreate the missing edges between revisions from a same branch for (String branchName : revisionsPerBranch.keySet()) { final List<Long> branchRevisions = new ArrayList<>(revisionsPerBranch.get(branchName)); for (int i = 0; i < branchRevisions.size() - 1; i++) { final String nodeLabel1 = String.format("%s@%d", branchName, branchRevisions.get(i)); final String nodeLabel2 = String.format("%s@%d", branchName, branchRevisions.get(i + 1)); graphWriter.edge(nodeIdsPerLabel.get(nodeLabel1), nodeIdsPerLabel.get(nodeLabel2)); } } graphWriter.closeGraph(); System.out.println(String.format("Found %d significant revisions", count)); } finally { if (graphWriter != null) { graphWriter.close(); } if (fileWriter != null) { fileWriter.close(); } } System.out.println("Done"); }
From source file:OverlaySample.java
public static void main(String args[]) { ActionListener generalActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JComponent comp = (JComponent) actionEvent.getSource(); System.out.println(actionEvent.getActionCommand() + ": " + comp.getBounds()); }/* w w w.j a va2s .com*/ }; ActionListener sizingActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { setupButtons(actionEvent.getActionCommand()); } }; JFrame frame = new JFrame("Overlay Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); LayoutManager overlay = new OverlayLayout(panel); panel.setLayout(overlay); Object settings[][] = { { "Small", new Dimension(25, 25), Color.white }, { "Medium", new Dimension(50, 50), Color.gray }, { "Large", new Dimension(100, 100), Color.black } }; JButton buttons[] = { smallButton, mediumButton, largeButton }; for (int i = 0, n = settings.length; i < n; i++) { JButton button = buttons[i]; button.addActionListener(generalActionListener); button.setActionCommand((String) settings[i][0]); button.setMaximumSize((Dimension) settings[i][1]); button.setBackground((Color) settings[i][2]); panel.add(button); } setupButtons(SET_CENTRAL); JPanel actionPanel = new JPanel(); actionPanel.setBorder(BorderFactory.createTitledBorder("Change Alignment")); String actionSettings[] = { SET_MINIMUM, SET_MAXIMUM, SET_CENTRAL, SET_MIXED }; for (int i = 0, n = actionSettings.length; i < n; i++) { JButton button = new JButton(actionSettings[i]); button.addActionListener(sizingActionListener); actionPanel.add(button); } Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); contentPane.add(actionPanel, BorderLayout.SOUTH); frame.setSize(400, 300); frame.setVisible(true); }
From source file:TextLayoutPanel.java
public static void main(String arg[]) { JFrame frame = new JFrame(); frame.setBackground(Color.white); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);/* w ww . j a v a2 s. c o m*/ } }); frame.getContentPane().add("Center", new TextLayoutPanel()); frame.pack(); frame.setSize(new Dimension(400, 300)); frame.setVisible(true); }
From source file:de.codesourcery.eve.skills.ui.ChartTest.java
public static void main(String[] args) { TimeSeries s1 = new TimeSeries("L&G European Index Trust"); s1.add(new Day(1, 2, 2001), 181.8); s1.add(new Month(3, 2001), 167.3); s1.add(new Month(4, 2001), 153.8); s1.add(new Month(5, 2001), 167.6); s1.add(new Month(6, 2001), 158.8); s1.add(new Month(7, 2001), 148.3); s1.add(new Month(8, 2001), 153.9); s1.add(new Month(9, 2001), 142.7); s1.add(new Month(10, 2001), 123.2); s1.add(new Month(11, 2001), 131.8); s1.add(new Month(12, 2001), 139.6); s1.add(new Month(1, 2002), 142.9); s1.add(new Month(2, 2002), 138.7); s1.add(new Month(3, 2002), 137.3); s1.add(new Month(4, 2002), 143.9); s1.add(new Month(5, 2002), 139.8); s1.add(new Month(6, 2002), 137.0); s1.add(new Month(7, 2002), 132.8); TimeSeries s2 = new TimeSeries("L&G UK Index Trust"); s2.add(new Month(2, 2001), 129.6); s2.add(new Month(3, 2001), 123.2); s2.add(new Month(4, 2001), 117.2); s2.add(new Month(5, 2001), 124.1); s2.add(new Month(6, 2001), 122.6); s2.add(new Month(7, 2001), 119.2); s2.add(new Month(8, 2001), 116.5); s2.add(new Month(9, 2001), 112.7); s2.add(new Month(10, 2001), 101.5); s2.add(new Month(11, 2001), 106.1); s2.add(new Month(12, 2001), 110.3); s2.add(new Month(1, 2002), 111.7); s2.add(new Month(2, 2002), 111.0); s2.add(new Month(3, 2002), 109.6); s2.add(new Month(4, 2002), 113.2); s2.add(new Month(5, 2002), 111.6); s2.add(new Month(6, 2002), 108.8); s2.add(new Month(7, 2002), 101.6); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1);/* w ww . j av a 2s.c o m*/ dataset.addSeries(s2); JFreeChart chart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", // title "Date", // x-axis label "Price Per Unit", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); // display chart ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); chartPanel.setMouseZoomable(true, false); JFrame frame = new JFrame("test"); frame.setContentPane(chartPanel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:it.iit.genomics.cru.igb.bundles.mi.view.TestJung.java
public static void main(String[] args) { Graph<MoleculeEntry, EdgeInteraction> graph = new SparseMultigraph<>(); MoleculeEntry v1 = new MoleculeEntry("A"); v1.addGeneName("A"); v1.setTaxid("9606"); MoleculeEntry v2 = new MoleculeEntry("B"); v2.addGeneName("b"); v2.setTaxid("9606"); MoleculeEntry v3 = new MoleculeEntry("DNA"); v3.addGeneName("DNA"); v3.setTaxid(MoleculeEntry.TAXID_DNA); EdgeInteraction edge = new EdgeInteraction(true, true, true, "e1"); graph.addEdge(edge, v1, v2, EdgeType.UNDIRECTED); EdgeInteraction edge2 = new EdgeInteraction(false, false, true, "e2"); graph.addEdge(edge2, v1, v3, EdgeType.UNDIRECTED); EdgeInteraction edge3 = new EdgeInteraction(false, false, false, "e3"); graph.addEdge(edge3, v2, v3, EdgeType.UNDIRECTED); // The Layout<V, E> is parameterized by the vertex and edge types Layout<MoleculeEntry, EdgeInteraction> layout = new ISOMLayout(graph); layout.setSize(new Dimension(500, 600)); // sets the initial size of the space // The BasicVisualizationServer<V,E> is parameterized by the edge types VisualizationViewer<MoleculeEntry, EdgeInteraction> vv = new VisualizationViewer<>(layout); vv.setPreferredSize(new Dimension(550, 650)); //Sets the viewing area size vv.setBackground(Color.WHITE); Transformer<MoleculeEntry, Paint> vertexPaint = new Transformer<MoleculeEntry, Paint>() { @Override/*ww w . j ava2s . c o m*/ public Paint transform(MoleculeEntry molecule) { switch (molecule.getTaxid()) { case MoleculeEntry.TAXID_DNA: ; case MoleculeEntry.TAXID_RNA: return Color.GREEN; case MoleculeEntry.TAXID_LIGAND: return Color.MAGENTA; default: return Color.GREEN; } } }; Transformer<EdgeInteraction, Paint> edgePaint = new Transformer<EdgeInteraction, Paint>() { @Override public Paint transform(EdgeInteraction interaction) { return interaction.hasStructure ? Color.BLACK : Color.GRAY; } }; final Stroke edgeStroke01 = new BasicStroke(); final float nodeSize = 20; final Stroke edgeStrokeBothContacts = new ShapeStroke(new Shape[] { new Ellipse2D.Float(0, 0, 10, 10) }, nodeSize, true, true); final Stroke edgeStrokeStartContacts = new ShapeStroke(new Shape[] { new Ellipse2D.Float(0, 0, 10, 10) }, nodeSize, true, false); final Stroke edgeStrokeEndContacts = new ShapeStroke(new Shape[] { new Ellipse2D.Float(0, 0, 10, 10) }, nodeSize, false, true); final Stroke edgeStrokeBothContact = new CompoundStroke(edgeStroke01, edgeStrokeBothContacts, CompoundStroke.ADD); final Stroke edgeStrokeStartContact = new CompoundStroke(edgeStroke01, edgeStrokeStartContacts, CompoundStroke.ADD); final Stroke edgeStrokeEndContact = new CompoundStroke(edgeStroke01, edgeStrokeEndContacts, CompoundStroke.ADD); Transformer<EdgeInteraction, Stroke> edgeStrokeTransformer = new Transformer<EdgeInteraction, Stroke>() { @Override public Stroke transform(EdgeInteraction s) { if (s.hasContactsA && s.hasContactsB) { return edgeStrokeBothContact; } if (s.hasContactsA) { return edgeStrokeStartContact; } if (s.hasContactsB) { return edgeStrokeEndContact; } return edgeStroke01; } }; Transformer<MoleculeEntry, String> moleculeLabeller = new Transformer<MoleculeEntry, String>() { @Override public String transform(MoleculeEntry s) { return s.getGeneName(); } }; vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); vv.getRenderContext().setEdgeDrawPaintTransformer(edgePaint); vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer); vv.getRenderContext().setVertexLabelTransformer(moleculeLabeller); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); vv.setGraphMouse(graphMouse); JFrame frame = new JFrame("Network " + "A"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(vv); frame.pack(); frame.setVisible(true); }
From source file:org.eclipse.swt.snippets.Snippet361.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 361"); shell.setText("Translate and Rotate an AWT Image in an SWT GUI"); shell.setLayout(new GridLayout(8, false)); Button fileButton = new Button(shell, SWT.PUSH); fileButton.setText("&Open Image File"); fileButton.addSelectionListener(widgetSelectedAdapter(e -> { String filename = new FileDialog(shell).open(); if (filename != null) { image = Toolkit.getDefaultToolkit().getImage(filename); canvas.repaint();/*from w ww . j a v a 2 s . c om*/ } })); new Label(shell, SWT.NONE).setText("Translate &X by:"); final Combo translateXCombo = new Combo(shell, SWT.NONE); translateXCombo.setItems("0", "image width", "image height", "100", "200"); translateXCombo.select(0); translateXCombo.addModifyListener(e -> { translateX = numericValue(translateXCombo); canvas.repaint(); }); new Label(shell, SWT.NONE).setText("Translate &Y by:"); final Combo translateYCombo = new Combo(shell, SWT.NONE); translateYCombo.setItems("0", "image width", "image height", "100", "200"); translateYCombo.select(0); translateYCombo.addModifyListener(e -> { translateY = numericValue(translateYCombo); canvas.repaint(); }); new Label(shell, SWT.NONE).setText("&Rotate by:"); final Combo rotateCombo = new Combo(shell, SWT.NONE); rotateCombo.setItems("0", "Pi", "Pi/2", "Pi/4", "Pi/8"); rotateCombo.select(0); rotateCombo.addModifyListener(e -> { rotate = numericValue(rotateCombo); canvas.repaint(); }); Button printButton = new Button(shell, SWT.PUSH); printButton.setText("&Print Image"); printButton.addSelectionListener(widgetSelectedAdapter(e -> { performPrintAction(display, shell); })); composite = new Composite(shell, SWT.EMBEDDED | SWT.BORDER); GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 8, 1); data.widthHint = 640; data.heightHint = 480; composite.setLayoutData(data); Frame frame = SWT_AWT.new_Frame(composite); canvas = new Canvas() { @Override public void paint(Graphics g) { if (image != null) { g.setColor(Color.WHITE); g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight()); /* Use Java2D here to modify the image as desired. */ Graphics2D g2d = (Graphics2D) g; AffineTransform t = new AffineTransform(); t.translate(translateX, translateY); t.rotate(rotate); g2d.setTransform(t); /*------------*/ g.drawImage(image, 0, 0, this); } } }; frame.add(canvas); composite.getAccessible().addAccessibleListener(new AccessibleAdapter() { @Override public void getName(AccessibleEvent e) { e.result = "Image drawn in AWT Canvas"; } }); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
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 w ww . jav a 2 s. c o 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.googlecode.sarasvati.visual.jung.JungVisualizer.java
@SuppressWarnings("serial") public static void main(String[] args) throws Exception { TestSetup.init();//from w w w . ja v a 2 s. c o m Session session = TestSetup.openSession(); HibEngine engine = new HibEngine(session); JFrame frame = new JFrame("Workflow Visualizer"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setMinimumSize(new Dimension(800, 600)); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); frame.getContentPane().add(splitPane); DefaultListModel listModel = new DefaultListModel(); for (Graph g : engine.getRepository().getGraphs()) { listModel.addElement(g); } ListCellRenderer cellRenderer = new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); Graph g = (Graph) value; setText(g.getName() + "." + g.getVersion() + " "); return this; } }; final JList graphList = new JList(listModel); graphList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); graphList.setCellRenderer(cellRenderer); JScrollPane listScrollPane = new JScrollPane(graphList); listScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); listScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); splitPane.add(listScrollPane); //TreeLayout<NodeRef, Arc> layout = new TreeLayout<NodeRef, Arc>(); DirectedSparseMultigraph<Node, Arc> graph = new DirectedSparseMultigraph<Node, Arc>(); //final SpringLayout2<HibNodeRef, HibArc> layout = new SpringLayout2<HibNodeRef, HibArc>(graph); //final KKLayout<HibNodeRef, HibArc> layout = new KKLayout<HibNodeRef, HibArc>(graph); final TreeLayout layout = new TreeLayout(graph); final BasicVisualizationServer<Node, Arc> vs = new BasicVisualizationServer<Node, Arc>(layout); //vs.getRenderContext().setVertexLabelTransformer( new NodeLabeller() ); //vs.getRenderContext().setEdgeLabelTransformer( new ArcLabeller() ); vs.getRenderContext().setVertexShapeTransformer(new NodeShapeTransformer()); vs.getRenderContext().setVertexFillPaintTransformer(new NodeColorTransformer()); vs.getRenderContext().setLabelOffset(5); vs.getRenderContext().setVertexIconTransformer(new Transformer<Node, Icon>() { @Override public Icon transform(Node node) { return "task".equals(node.getType()) ? new TaskIcon(node) : null; } }); Transformer<Arc, Paint> edgeColorTrans = new Transformer<Arc, Paint>() { private Color darkRed = new Color(128, 0, 0); @Override public Paint transform(Arc arc) { return "reject".equals(arc.getName()) ? darkRed : Color.black; } }; vs.getRenderContext().setEdgeDrawPaintTransformer(edgeColorTrans); vs.getRenderContext().setArrowDrawPaintTransformer(edgeColorTrans); final JScrollPane scrollPane = new JScrollPane(vs); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); splitPane.add(scrollPane); scrollPane.setBackground(Color.white); graphList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } final Graph g = (Graph) graphList.getSelectedValue(); if ((g == null && currentGraph == null) || (g != null && g.equals(currentGraph))) { return; } currentGraph = g; DirectedSparseMultigraph<Node, Arc> jungGraph = new DirectedSparseMultigraph<Node, Arc>(); for (Node ref : currentGraph.getNodes()) { jungGraph.addVertex(ref); } for (Arc arc : currentGraph.getArcs()) { jungGraph.addEdge(arc, arc.getStartNode(), arc.getEndNode()); } GraphTree graphTree = new GraphTree(g); layout.setGraph(jungGraph); layout.setInitializer(new NodeLocationTransformer(graphTree)); scrollPane.repaint(); } }); frame.setVisible(true); }