List of usage examples for java.awt Graphics2D fillOval
public abstract void fillOval(int x, int y, int width, int height);
From source file:Paints.java
/** Draw the example */ public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; // Paint the entire background using a GradientPaint. // The background color varies diagonally from deep red to pale blue g.setPaint(new GradientPaint(0, 0, new Color(150, 0, 0), WIDTH, HEIGHT, new Color(200, 200, 255))); g.fillRect(0, 0, WIDTH, HEIGHT); // fill the background // Use a different GradientPaint to draw a box. // This one alternates between deep opaque green and transparent green. // Note: the 4th arg to Color() constructor specifies color opacity g.setPaint(new GradientPaint(0, 0, new Color(0, 150, 0), 20, 20, new Color(0, 150, 0, 0), true)); g.setStroke(new BasicStroke(15)); // use wide lines g.drawRect(25, 25, WIDTH - 50, HEIGHT - 50); // draw the box // The glyphs of fonts can be used as Shape objects, which enables // us to use Java2D techniques with letters Just as we would with // any other shape. Here we get some letter shapes to draw. Font font = new Font("Serif", Font.BOLD, 10); // a basic font Font bigfont = // a scaled up version font.deriveFont(AffineTransform.getScaleInstance(30.0, 30.0)); GlyphVector gv = bigfont.createGlyphVector(g.getFontRenderContext(), "JAV"); Shape jshape = gv.getGlyphOutline(0); // Shape of letter J Shape ashape = gv.getGlyphOutline(1); // Shape of letter A Shape vshape = gv.getGlyphOutline(2); // Shape of letter V // We're going to outline the letters with a 5-pixel wide line g.setStroke(new BasicStroke(5.0f)); // We're going to fake shadows for the letters using the // following Paint and AffineTransform objects Paint shadowPaint = new Color(0, 0, 0, 100); // Translucent black AffineTransform shadowTransform = AffineTransform.getShearInstance(-1.0, 0.0); // Shear to the right shadowTransform.scale(1.0, 0.5); // Scale height by 1/2 // Move to the baseline of our first letter g.translate(65, 270);//from w w w . ja v a 2 s .c om // Draw the shadow of the J shape g.setPaint(shadowPaint); g.translate(15, 20); // Compensate for the descender of the J // transform the J into the shape of its shadow, and fill it g.fill(shadowTransform.createTransformedShape(jshape)); g.translate(-15, -20); // Undo the translation above // Now fill the J shape with a solid (and opaque) color g.setPaint(Color.blue); // Fill with solid, opaque blue g.fill(jshape); // Fill the shape g.setPaint(Color.black); // Switch to solid black g.draw(jshape); // And draw the outline of the J // Now draw the A shadow g.translate(75, 0); // Move to the right g.setPaint(shadowPaint); // Set shadow color g.fill(shadowTransform.createTransformedShape(ashape)); // draw shadow // Draw the A shape using a solid transparent color g.setPaint(new Color(0, 255, 0, 125)); // Transparent green as paint g.fill(ashape); // Fill the shape g.setPaint(Color.black); // Switch to solid back g.draw(ashape); // Draw the outline // Move to the right and draw the shadow of the letter V g.translate(175, 0); g.setPaint(shadowPaint); g.fill(shadowTransform.createTransformedShape(vshape)); // We're going to fill the next letter using a TexturePaint, which // repeatedly tiles an image. The first step is to obtain the image. // We could load it from an image file, but here we create it // ourselves by drawing a into an off-screen image. Note that we use // a GradientPaint to fill the off-screen image, so the fill pattern // combines features of both Paint classes. BufferedImage tile = // Create an image new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB); Graphics2D tg = tile.createGraphics(); // Get its Graphics for drawing tg.setColor(Color.pink); tg.fillRect(0, 0, 50, 50); // Fill tile background with pink tg.setPaint(new GradientPaint(40, 0, Color.green, // diagonal gradient 0, 40, Color.gray)); // green to gray tg.fillOval(5, 5, 40, 40); // Draw a circle with this gradient // Use this new tile to create a TexturePaint and fill the letter V g.setPaint(new TexturePaint(tile, new Rectangle(0, 0, 50, 50))); g.fill(vshape); // Fill letter shape g.setPaint(Color.black); // Switch to solid black g.draw(vshape); // Draw outline of letter // Move to the right and draw the shadow of the final A g.translate(160, 0); g.setPaint(shadowPaint); g.fill(shadowTransform.createTransformedShape(ashape)); g.fill(ashape); // Fill letter A g.setPaint(Color.black); // Revert to solid black g.draw(ashape); // Draw the outline of the A }
From source file:RadialGradientApp.java
@Override protected void paintComponent(Graphics g) { setFont(getFont().deriveFont(70.f).deriveFont(Font.BOLD)); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Retains the previous state Paint oldPaint = g2.getPaint(); // Fills the circle with solid blue color g2.setColor(new Color(0x0153CC)); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Adds shadows at the top Paint p;/* w w w .j a va2s .c o m*/ p = new GradientPaint(0, 0, new Color(0.0f, 0.0f, 0.0f, 0.4f), 0, getHeight(), new Color(0.0f, 0.0f, 0.0f, 0.0f)); g2.setPaint(p); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Adds highlights at the bottom p = new GradientPaint(0, 0, new Color(1.0f, 1.0f, 1.0f, 0.0f), 0, getHeight(), new Color(1.0f, 1.0f, 1.0f, 0.4f)); g2.setPaint(p); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Creates dark edges for 3D effect p = new RadialGradientPaint(new Point2D.Double(getWidth() / 2.0, getHeight() / 2.0), getWidth() / 2.0f, new float[] { 0.0f, 1.0f }, new Color[] { new Color(6, 76, 160, 127), new Color(0.0f, 0.0f, 0.0f, 0.8f) }); g2.setPaint(p); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Adds oval inner highlight at the bottom p = new RadialGradientPaint(new Point2D.Double(getWidth() / 2.0, getHeight() * 1.5), getWidth() / 2.3f, new Point2D.Double(getWidth() / 2.0, getHeight() * 1.75 + 6), new float[] { 0.0f, 0.8f }, new Color[] { new Color(64, 142, 203, 255), new Color(64, 142, 203, 0) }, RadialGradientPaint.CycleMethod.NO_CYCLE, RadialGradientPaint.ColorSpaceType.SRGB, AffineTransform.getScaleInstance(1.0, 0.5)); g2.setPaint(p); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Adds oval specular highlight at the top left p = new RadialGradientPaint(new Point2D.Double(getWidth() / 2.0, getHeight() / 2.0), getWidth() / 1.4f, new Point2D.Double(45.0, 25.0), new float[] { 0.0f, 0.5f }, new Color[] { new Color(1.0f, 1.0f, 1.0f, 0.4f), new Color(1.0f, 1.0f, 1.0f, 0.0f) }, RadialGradientPaint.CycleMethod.NO_CYCLE); g2.setPaint(p); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Restores the previous state g2.setPaint(oldPaint); // Draws the logo // FontRenderContext context = g2.getFontRenderContext(); // TextLayout layout = new TextLayout("R", getFont(), context); // Rectangle2D bounds = layout.getBounds(); // // float x = (getWidth() - (float) bounds.getWidth()) / 2.0f; // float y = (getHeight() + (float) bounds.getHeight()) / 2.0f; // // g2.setColor(Color.WHITE); // layout.draw(g2, x, y); // // Area shadow = new Area(layout.getOutline(null)); // shadow.subtract(new Area(layout.getOutline(AffineTransform.getTranslateInstance(1.0, 1.0)))); // g2.setColor(Color.BLACK); // g2.translate(x, y); // g2.fill(shadow); // g2.translate(-x, -y); }
From source file:adams.gui.visualization.stats.paintlet.Gamma.java
/** * The paint routine of the paintlet./*from w ww .ja va 2 s . c om*/ * * @param g the graphics context to use for painting * @param moment what {@link PaintMoment} is currently being painted */ @Override protected void doPerformPaint(Graphics g, PaintMoment moment) { if ((m_Data != null) && (m_Sorted != null) && m_Shape != -1.0) { GUIHelper.configureAntiAliasing(g, m_AntiAliasingEnabled); for (int i = 0; i < m_Sorted.length; i++) { Graphics2D g2d = (Graphics2D) g; //If data points are to be filled if (m_Fill) { g2d.setColor(m_FillColor); g2d.setStroke(new BasicStroke(0)); g2d.fillOval(m_AxisBottom.valueToPos(m_Sorted[i]) - m_Size / 2, m_AxisLeft.valueToPos(m_TransformedY[i]) - m_Size / 2, m_Size, m_Size); } //outline of data point g2d.setStroke(new BasicStroke(m_StrokeThickness)); g2d.setColor(m_Color); g2d.drawOval(m_AxisBottom.valueToPos(m_Sorted[i]) - m_Size / 2, m_AxisLeft.valueToPos(m_TransformedY[i]) - m_Size / 2, m_Size, m_Size); } //If drawing regression fit diagonal if (m_RegressionLine) { g.setColor(Color.BLACK); double[] newData = new double[m_Sorted.length]; for (int i = 0; i < m_Sorted.length; i++) { newData[i] = Math.log(m_Sorted[i]); } GammaDistributionImpl gd = new GammaDistributionImpl(m_Shape, m_Scale); //draw the expected diagonal line using the gamma distribution for (int i = 0; i < m_Sorted.length - 1; i++) { double p1; try { p1 = gd.cumulativeProbability(newData[i]); } catch (MathException e) { p1 = 0; } double p2; try { p2 = gd.cumulativeProbability(newData[i + 1]); } catch (MathException e) { p2 = 0; } g.drawLine(m_AxisBottom.valueToPos(m_Sorted[i]), m_AxisLeft.valueToPos(p1), m_AxisBottom.valueToPos(m_Sorted[i + 1]), m_AxisLeft.valueToPos(p2)); } } } }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int cx = getSize().width / 2; int cy = getSize().height / 2; g2.translate(cx, cy);//from w w w .j a v a2s .com g2.rotate(theta * Math.PI / 180); Shape oldClip = g2.getClip(); Shape e = new Ellipse2D.Float(-cx, -cy, cx * 2, cy * 2); g2.clip(e); Shape c = new Ellipse2D.Float(-cx, -cy, cx * 3 / 4, cy * 2); g2.setPaint(new GradientPaint(40, 40, Color.blue, 60, 50, Color.white, true)); g2.fill(c); g2.setPaint(Color.yellow); g2.fillOval(cx / 4, 0, cx, cy); g2.setClip(oldClip); g2.setFont(new Font("Times New Roman", Font.PLAIN, 64)); g2.setPaint(new GradientPaint(-cx, 0, Color.red, cx, 0, Color.black, false)); g2.drawString("Hello, 2D!", -cx * 3 / 4, cy / 4); AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) .75); g2.setComposite(ac); Shape r = new RoundRectangle2D.Float(0, -cy * 3 / 4, cx * 3 / 4, cy * 3 / 4, 20, 20); g2.setStroke(new BasicStroke(4)); g2.setPaint(Color.magenta); g2.fill(r); g2.setPaint(Color.green); g2.draw(r); g2.drawImage(image, -cx / 2, -cy / 2, this); }
From source file:HighlightedButton.java
/** * Creates a new instance of HighlightedButton *//* ww w .j a v a2s.co m*/ public HighlightedButton(String label) { super(label); // Get the Graphics for the image Graphics2D g2d = highlight.createGraphics(); // Erase the image with a transparent background g2d.setComposite(AlphaComposite.Clear); g2d.fillRect(0, 0, HIGHLIGHT_SIZE, HIGHLIGHT_SIZE); g2d.setComposite(AlphaComposite.SrcOver); // Draw the highlight Point2D center = new Point2D.Float((float) HIGHLIGHT_SIZE / 2.0f, (float) HIGHLIGHT_SIZE / 2.0f); float radius = (float) HIGHLIGHT_SIZE / 2.0f; float[] dist = { 0.0f, .85f }; Color[] colors = { Color.white, new Color(255, 255, 255, 0) }; RadialGradientPaint paint = new RadialGradientPaint(center, radius, dist, colors); g2d.setPaint(paint); g2d.fillOval(0, 0, HIGHLIGHT_SIZE, HIGHLIGHT_SIZE); g2d.dispose(); }
From source file:bigdataproject.CustomFastScatterPlot.java
@Override public void render(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, CrosshairState crosshairState) { if (clusters != null) { int colorIndex = 0, points = 0; String shape = ""; for (Integer index : clusters.keySet()) { float[][] clusterFloat = clusters.get(index); for (float[] clusterFloat1 : clusterFloat) { points++;/* w ww . jav a2 s.c o m*/ float x = clusterFloat1[0]; float y = clusterFloat1[1]; int size = 6; int transX = (int) this.getDomainAxis().valueToJava2D(x, dataArea, RectangleEdge.BOTTOM); int transY = (int) this.getRangeAxis().valueToJava2D(y, dataArea, RectangleEdge.LEFT); g2.setPaint(colors[colorIndex % 11]); if (colorIndex % 2 == 0) { g2.fillOval(transX, transY, size, size); shape = "Round"; } else { g2.fillRect(transX, transY, size, size); shape = "Square"; } } System.out.println("Cluster number: " + colorIndex + " Points: " + clusterFloat.length + " Shape: " + shape + " Color: " + colorArray[colorIndex % 11]); colorIndex++; } System.out.println( "\nClustering done! Total clusters: " + colorIndex + " Total points: " + points + "\n"); } }
From source file:com.simiacryptus.mindseye.applications.ArtistryUtil.java
/** * Paint circles./*from w ww . ja va2 s . c o m*/ * * @param canvas the canvas * @param scale the scale */ public static void paint_Circles(final Tensor canvas, final int scale) { BufferedImage originalImage = canvas.toImage(); BufferedImage newImage = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = (Graphics2D) newImage.getGraphics(); IntStream.range(0, 10000).forEach(i -> { Random random = new Random(); int positionX = random.nextInt(originalImage.getWidth()); int positionY = random.nextInt(originalImage.getHeight()); int width = 1 + random.nextInt(2 * scale); int height = 1 + random.nextInt(2 * scale); DoubleStatistics[] stats = { new DoubleStatistics(), new DoubleStatistics(), new DoubleStatistics() }; canvas.coordStream(false).filter(c -> { int[] coords = c.getCoords(); int x = coords[0]; int y = coords[1]; double relX = Math.pow(1 - 2 * ((double) (x - positionX) / width), 2); double relY = Math.pow(1 - 2 * ((double) (y - positionY) / height), 2); return relX + relY < 1.0; }).forEach(c -> stats[c.getCoords()[2]].accept(canvas.get(c))); graphics.setStroke(new Stroke() { @Override public Shape createStrokedShape(final Shape p) { return null; } }); graphics.setColor(new Color((int) stats[0].getAverage(), (int) stats[1].getAverage(), (int) stats[2].getAverage())); graphics.fillOval(positionX, positionY, width, height); }); canvas.set(Tensor.fromRGB(newImage)); }
From source file:gsn.vsensor.DemoVSensor.java
public void dataAvailable(String inputStreamName, StreamElement data) { if (inputStreamName.equalsIgnoreCase("SSTREAM")) { String action = (String) data.getData("STATUS"); /**/*from w w w . j a v a 2 s . c o m*/ * */ String moteId = (String) data.getData("ID"); if (moteId.toLowerCase().indexOf("mica") < 0) return; if (action.toLowerCase().indexOf("add") >= 0) counter++; if (action.toLowerCase().indexOf("remove") >= 0) counter--; } if (inputStreamName.equalsIgnoreCase("CSTREAM")) { BufferedImage bufferedImage = null; outputStream.reset(); byte[] rawData = (byte[]) data.getData("IMAGE"); input = new ByteArrayInputStream(rawData); try { bufferedImage = ImageIO.read(input); } catch (IOException e) { logger.error(e.getMessage(), e); } Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics(); int size = 30; int locX = 0; int locY = 0; if (counter < 0) counter = 0; switch (counter) { case 0: graphics.setColor(Color.RED); break; case 1: graphics.setColor(Color.ORANGE); break; case 2: graphics.setColor(Color.YELLOW); break; case 3: graphics.setColor(Color.GREEN); break; default: logger.warn( new StringBuilder().append("Shouldn't happen.>").append(counter).append("<").toString()); } graphics.fillOval(locX, locY, size, size); try { ImageIO.write(bufferedImage, "jpeg", outputStream); outputStream.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } StreamElement outputSE = new StreamElement(OUTPUT_FIELDS, OUTPUT_TYPES, new Serializable[] { outputStream.toByteArray() }, data.getTimeStamp()); dataProduced(outputSE); } logger.info( new StringBuilder().append("Data received under the name: ").append(inputStreamName).toString()); }
From source file:au.org.ala.biocache.web.MapController.java
@RequestMapping(value = "/occurrences/legend", method = RequestMethod.GET) public void pointLegendImage( @RequestParam(value = "colourby", required = false, defaultValue = "0") Integer colourby, @RequestParam(value = "width", required = false, defaultValue = "50") Integer widthObj, @RequestParam(value = "height", required = false, defaultValue = "50") Integer heightObj, HttpServletResponse response) {/*from www. j a v a2 s . c o m*/ try { int width = widthObj.intValue(); int height = heightObj.intValue(); BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) img.getGraphics(); if (colourby != null) { int colour = 0xFF000000 | colourby.intValue(); Color c = new Color(colour); g.setPaint(c); } else { g.setPaint(Color.blue); } g.fillOval(0, 0, width, width); g.dispose(); response.setContentType("image/png"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ImageIO.write(img, "png", outputStream); ServletOutputStream outStream = response.getOutputStream(); outStream.write(outputStream.toByteArray()); outStream.flush(); outStream.close(); } catch (Exception e) { logger.error("Unable to write image", e); } }
From source file:com.imag.nespros.gui.plugin.GraphEditor.java
/** * create an instance of a simple graph with popup controls to create a * graph.//from w w w . ja va 2 s. c o m * */ private GraphEditor(Simulation s) { simu = s; try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ex) { Logger.getLogger(GraphEditor.class.getName()).log(Level.SEVERE, null, ex); } // create a simple graph for the demo graph = Topology.getInstance().getGraph(); this.layout = new StaticLayout<Device, ComLink>(graph, new Transformer<Device, Point2D>() { @Override public Point2D transform(Device v) { Point2D p = new Point2D.Double(v.getX(), v.getY()); return p; } }, new Dimension(600, 600)); vv = new VisualizationViewer<Device, ComLink>(layout); vv.setBackground(Color.white); final Transformer<Device, String> vertexLabelTransformer = new Transformer<Device, String>() { @Override public String transform(Device d) { return d.getDeviceName(); } }; //vv.getRenderContext().setVertexLabelTransformer(MapTransformer.<Device, String>getInstance( // LazyMap.<Device, String>decorate(new HashMap<Device, String>(), new ToStringLabeller<Device>()))); vv.getRenderContext().setVertexLabelTransformer(vertexLabelTransformer); vv.getRenderContext().setEdgeLabelTransformer(new Transformer<ComLink, String>() { @Override public String transform(ComLink link) { return (link.getID() + ", " + link.getLatency()); } }); //float dash[] = {0.1f}; //final Stroke edgeStroke = new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 1.0f); final Stroke edgeStroke = new BasicStroke(3.0f); final Transformer<ComLink, Stroke> edgeStrokeTransformer = new Transformer<ComLink, Stroke>() { @Override public Stroke transform(ComLink l) { return edgeStroke; } }; Transformer<ComLink, Paint> edgePaint = new Transformer<ComLink, Paint>() { public Paint transform(ComLink l) { if (l.isDown()) { return Color.RED; } else { return Color.BLACK; } } }; vv.getRenderContext().setEdgeDrawPaintTransformer(edgePaint); vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer); vv.setVertexToolTipTransformer(vv.getRenderContext().getVertexLabelTransformer()); vv.getRenderContext().setVertexIconTransformer(new CustomVertexIconTransformer()); vv.getRenderContext().setVertexShapeTransformer(new CustomVertexShapeTransformer()); vv.addPreRenderPaintable(new VisualizationViewer.Paintable() { @Override public void paint(Graphics grphcs) { for (Device d : Topology.getInstance().getGraph().getVertices()) { int size = d.getOperators().size(); MyLayeredIcon icon = d.getIcon(); //if(icon == null) continue; icon.removeAll(); if (size > 0) { // the vertex icon // Let's create the annotation image to be added to icon.. BufferedImage image = new BufferedImage(20, 20, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.setColor(Color.ORANGE); g.fillOval(0, 0, 20, 20); g.setColor(Color.BLACK); g.drawString(size + "", 5, 13); g.dispose(); ImageIcon img = new ImageIcon(image); //Dimension id = new Dimension(icon.getIconWidth(), icon.getIconHeight()); //double x = vv.getModel().getGraphLayout().transform(d).getX(); //x -= (icon.getIconWidth() / 2); //double y = vv.getModel().getGraphLayout().transform(d).getY(); //y -= (icon.getIconHeight() / 2); //grphcs.drawImage(image, (int) Math.round(x), (int) Math.round(y), null); icon.add(img); } } } @Override public boolean useTransform() { return false; } }); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); Factory<Device> vertexFactory = DeviceFactory.getInstance(); Factory<ComLink> edgeFactory = ComLinkFactory.getInstance(); final EditingModalGraphMouse<Device, ComLink> graphMouse = new EditingModalGraphMouse<>( vv.getRenderContext(), vertexFactory, edgeFactory); // Trying out our new popup menu mouse plugin... PopupVertexEdgeMenuMousePlugin myPlugin = new PopupVertexEdgeMenuMousePlugin(); // Add some popup menus for the edges and vertices to our mouse plugin. JPopupMenu edgeMenu = new MyMouseMenus.EdgeMenu(frame); JPopupMenu vertexMenu = new MyMouseMenus.VertexMenu(frame); myPlugin.setEdgePopup(edgeMenu); myPlugin.setVertexPopup(vertexMenu); graphMouse.remove(graphMouse.getPopupEditingPlugin()); // Removes the existing popup editing plugin graphMouse.add(myPlugin); // Add our new plugin to the mouse // AnnotatingGraphMousePlugin<Device,ComLink> annotatingPlugin = // new AnnotatingGraphMousePlugin<>(vv.getRenderContext()); //graphMouse.add(annotatingPlugin); // the EditingGraphMouse will pass mouse event coordinates to the // vertexLocations function to set the locations of the vertices as // they are created // graphMouse.setVertexLocations(vertexLocations); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); //final ImageAtEdgePainter<String, String> imageAtEdgePainter = // new ImageAtEdgePainter<String, String>(vv, edge, image); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton help = new JButton("Help"); help.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(vv, instructions); } }); JButton deploy = new JButton("Deploy"); deploy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // OPMapping algo here if (simu == null) { return; } GraphUtil<Device, ComLink> util = new GraphUtil<>(); for (EventProducer p : simu.getProducers()) { if (!p.isMapped()) { JOptionPane.showMessageDialog(frame, "Cannot map operators. Please deploy the producer: " + p.getName()); return; } } for (EventConsumer c : simu.getConsumers()) { if (!c.isMapped()) { JOptionPane.showMessageDialog(frame, "Cannot map operators. Please deploy the consumer: " + c.getName()); return; } System.out.println("-- Operator placement algorithm Greedy: " + c.getName() + " --"); Solution init = util.initialMapping(c.getGraph()); System.out.println(c.getGraph() + "\nInitial Mapping: " + init); OperatorMapping mapper = new OperatorMapping(); long T1, T2; System.out.println("--- OpMapping Algo Greedy --- "); T1 = System.currentTimeMillis(); Solution solution = mapper.opMapping(c.getGraph(), Topology.getInstance().getGraph(), init); T2 = System.currentTimeMillis(); System.out.println(solution); System.out.println("Solution founded in: " + (T2 - T1) + " ms"); } // Solution init = util.initialMapping(EPGraph.getInstance().getGraph()); // System.out.println("Initial Mapping: " + init); // OperatorMapping mapper = new OperatorMapping(); // long T1, T2; // System.out.println("--- OpMapping Algo Greedy --- "); // T1 = System.currentTimeMillis(); // Solution solution = mapper.opMapping(EPGraph.getInstance().getGraph(), // Topology.getInstance().getGraph(), init); // T2 = System.currentTimeMillis(); // System.out.println(solution); // System.out.println("Solution founded in: " + (T2 - T1) + " ms"); vv.repaint(); } }); JButton run = new JButton("Run"); run.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // run the simulation here System.out.println("Setting the simulation..."); for (EventConsumer c : simu.getConsumers()) { for (EPUnit op : c.getGraph().getVertices()) { if (op.isMapped()) { op.openIOchannels(); } else { JOptionPane.showMessageDialog(frame, "Cannot run, undeployed operators founded."); return; } } } //ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); System.out.println("Running the simulation..."); //scheduledExecutorService.execute(runner); for (Device device : Topology.getInstance().getGraph().getVertices()) { if (!device.isAlive()) { device.start(); } } for (ComLink link : Topology.getInstance().getGraph().getEdges()) { if (!link.isAlive()) { link.start(); } } for (EventConsumer c : simu.getConsumers()) { for (EPUnit op : c.getGraph().getVertices()) { if (op.isMapped() && op.getDevice() != null && !op.isAlive()) { op.start(); } } } } }); AnnotationControls<Device, ComLink> annotationControls = new AnnotationControls<Device, ComLink>( graphMouse.getAnnotatingPlugin()); JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 30, 0); slider.setMinorTickSpacing(5); slider.setMajorTickSpacing(30); slider.setPaintTicks(true); slider.setPaintLabels(true); slider.setLabelTable(slider.createStandardLabels(15)); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider slider = (JSlider) e.getSource(); if (!slider.getValueIsAdjusting()) { speedSimulation(slider.getValue()); } } }); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); JComboBox modeBox = graphMouse.getModeComboBox(); controls.add(modeBox); controls.add(annotationControls.getAnnotationsToolBar()); controls.add(slider); controls.add(deploy); controls.add(run); controls.add(help); content.add(controls, BorderLayout.SOUTH); /* Custom JPanels can be added here */ // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //final GraphEditor demo = new GraphEditor(); }