List of usage examples for java.awt Graphics2D setStroke
public abstract void setStroke(Stroke s);
From source file:TransformShear.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // Use antialiasing. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Move the origin to 75, 75. AffineTransform at = AffineTransform.getTranslateInstance(75, 75); g2.transform(at);//from w w w . j av a 2 s .c o m // Draw the shapes in their original locations. g2.setPaint(Color.black); g2.draw(axes); g2.draw(shape); // Transform the Graphics2D. AffineTransform sat = AffineTransform.getTranslateInstance(150, 0); sat.shear(-.5, 0); g2.transform(sat); // Draw the "new" shapes in dashed. g2.transform(AffineTransform.getTranslateInstance(75, 75)); Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 }, 0); g2.setStroke(stroke); g2.draw(axes); g2.draw(shape); }
From source file:at.tuwien.ifs.somtoolbox.visualization.thematicmap.SOMRegion.java
public void drawRegion(Graphics2D g) { if (segments.size() > 0) { g.setColor(borderColor);//from w ww . ja v a 2 s.c o m g.setStroke(new BasicStroke(0.0f)); g.drawPolygon(this); } }
From source file:tilt.image.page.Line.java
/** * Draw the line on the image for debugging * @param g the graphics environment to draw in * @param n the number of the line/*from w w w. j ava2 s . c o m*/ */ public void draw(Graphics g, int n) { Point p1, p2 = null; for (int i = 0; i < points.size(); i++) { p1 = p2; p2 = points.get(i); if (p1 != null) { int x1 = Math.round(p1.x); int y1 = Math.round(p1.y); int x2 = Math.round(p2.x); int y2 = Math.round(p2.y); if (!rogue) { g.drawLine(x1, y1, x2, y2); } else { Graphics2D g2 = (Graphics2D) g; g2.setStroke(new BasicStroke(3)); g2.draw(new Line2D.Float(x1, y1, x2, y2)); g2.setStroke(new BasicStroke(1)); } } } Rectangle bounds = getPointsBounds(); String num = Integer.toString(n); g.drawString(num, bounds.x - 30, (bounds.y * 2 + bounds.height) / 2); //System.out.println("width of line"+n+": "+bounds.width); }
From source file:org.tsho.dmc2.core.chart.AbstractDmcPlot.java
private void drawRangeGridLine(Graphics2D g2, Rectangle2D dataArea, double value) { Range range = rangeAxis.getRange();// w w w. j a v a2 s.c om if (!range.contains(value)) { return; } Line2D line = null; double v = rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); g2.setPaint(gridPaint); g2.setStroke(gridStroke); g2.draw(line); }
From source file:TransferableScribblePane.java
/** We override this method to draw ourselves. */ public void paintComponent(Graphics g) { // Let the superclass do its painting first super.paintComponent(g); // Make a copy of the Graphics context so we can modify it Graphics2D g2 = (Graphics2D) (g.create()); // Our superclass doesn't paint the background, so do this ourselves. g2.setColor(getBackground());//from w w w. j a v a2 s .co m g2.fillRect(0, 0, getWidth(), getHeight()); // Set the line width and color to use for the foreground g2.setStroke(stroke); g2.setColor(this.getForeground()); // Now loop through the PolyLine shapes and draw them all int numlines = lines.size(); for (int i = 0; i < numlines; i++) { PolyLine line = (PolyLine) lines.get(i); if (line == selectedLine) { // If it is the selected line g2.setStroke(selectedStroke); // Set dash pattern g2.draw(line); // Draw the line g2.setStroke(stroke); // Revert to solid lines } else g2.draw(line); // Otherwise just draw the line } }
From source file:org.squidy.designer.zoom.impl.DataTypeShape.java
@Override protected void paintShapeZoomedIn(PPaintContext paintContext) { Graphics2D g = paintContext.getGraphics(); paintContext.pushTransform(translation); PBounds bounds = getBoundsReference(); // Rectangle rectBounds = roundedRectangleShape.getBounds(); int x = (int) bounds.x - 3; int y = (int) bounds.y - 3; int width = (int) bounds.width + 6; int height = (int) bounds.height; g.setColor(Color.WHITE);/*from w w w.j ava2 s . com*/ g.fillRoundRect(x - 40, y, width + 80, height, 825, 825); g.setStroke(STROKE_SHAPE); g.setColor(Color.BLACK); g.drawRoundRect(x - 40, y, width + 80, height, 825, 825); paintContext.popTransform(translation); // 1st vertical g.drawLine(1000, 100, 1000, 220); // 1st horizontal g.drawLine(230, 220, 1780, 220); // 2nd (left) vertical g.drawLine(230, 220, 230, 700); // 2nd (left-middle) vertical g.drawLine(740, 220, 740, 960); // 2d (right-middle) vertical g.drawLine(1260, 220, 1260, 700); // 2nd (right) vertical g.drawLine(1780, 220, 1780, 700); }
From source file:org.tsho.dmc2.core.chart.AbstractDmcPlot.java
private void drawDomainGridLine(Graphics2D g2, Rectangle2D dataArea, double value) { Range range = domainAxis.getRange(); if (!range.contains(value)) { return;//from w w w. j av a2s.c om } Line2D line = null; double v = domainAxis.valueToJava2D(value, dataArea, RectangleEdge.BOTTOM); line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); g2.setPaint(gridPaint); g2.setStroke(gridStroke); g2.draw(line); }
From source file:de.fhbingen.wbs.wpOverview.tabs.APCalendarPanel.java
/** * Initialize the work package calendar panel inclusive the listeners. *//*w ww. j a va 2s. c om*/ private void init() { List<Workpackage> userWp = new ArrayList<Workpackage>(WpManager.getUserWp(WPOverview.getUser())); Collections.sort(userWp, new APLevelComparator()); dataset = createDataset(userWp); chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); final JPopupMenu popup = new JPopupMenu(); JMenuItem miSave = new JMenuItem(LocalizedStrings.getButton().save(LocalizedStrings.getWbs().timeLine())); miSave.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent arg0) { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new ExtensionAndFolderFilter("jpg", "jpeg")); //NON-NLS chooser.setSelectedFile(new File("chart-" //NON-NLS + System.currentTimeMillis() + ".jpg")); int returnVal = chooser.showSaveDialog(reference); if (returnVal == JFileChooser.APPROVE_OPTION) { try { File outfile = chooser.getSelectedFile(); ChartUtilities.saveChartAsJPEG(outfile, chart, chartPanel.getWidth(), chartPanel.getWidth()); Controller.showMessage( LocalizedStrings.getMessages().timeLineSaved(outfile.getCanonicalPath())); } catch (IOException e) { Controller.showError(LocalizedStrings.getErrorMessages().timeLineExportError()); } } } }); popup.add(miSave); chartPanel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { popup.show(e.getComponent(), e.getX(), e.getY()); } } }); chartPanel.setMinimumDrawHeight(50 + 15 * userWp.size()); chartPanel.setMaximumDrawHeight(50 + 15 * userWp.size()); chartPanel.setMaximumDrawWidth(9999); chartPanel.setPreferredSize( new Dimension((int) chartPanel.getPreferredSize().getWidth(), 50 + 15 * userWp.size())); chartPanel.setPopupMenu(null); this.setLayout(new BorderLayout()); this.removeAll(); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1; constraints.weighty = 1; constraints.anchor = GridBagConstraints.NORTHWEST; panel.add(chartPanel, constraints); panel.setBackground(Color.white); this.add(panel, BorderLayout.CENTER); GanttRenderer.setDefaultShadowsVisible(false); GanttRenderer.setDefaultBarPainter(new BarPainter() { @Override public void paintBar(final Graphics2D g, final BarRenderer arg1, final int row, final int col, final RectangularShape rect, final RectangleEdge arg5) { String wpName = (String) dataset.getColumnKey(col); int i = 0; int spaceCount = 0; while (wpName.charAt(i++) == ' ' && spaceCount < 17) { spaceCount++; } g.setColor(new Color(spaceCount * 15, spaceCount * 15, spaceCount * 15)); g.fill(rect); g.setColor(Color.black); g.setStroke(new BasicStroke()); g.draw(rect); } @Override public void paintBarShadow(final Graphics2D arg0, final BarRenderer arg1, final int arg2, final int arg3, final RectangularShape arg4, final RectangleEdge arg5, final boolean arg6) { } }); ((CategoryPlot) chart.getPlot()).setRenderer(new GanttRenderer() { private static final long serialVersionUID = -6078915091070733812L; public void drawItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis, final CategoryDataset dataset, final int row, final int column, final int pass) { super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass); } }); }
From source file:ScribbleDragAndDrop.java
/** * This method implements the DragGestureListener interface. It will be * invoked when the DragGestureRecognizer thinks that the user has initiated * a drag. If we're not in drawing mode, then this method will try to figure * out which Scribble object is being dragged, and will initiate a drag on * that object./* w w w . j ava 2 s .c om*/ */ public void dragGestureRecognized(DragGestureEvent e) { // Don't drag if we're not in drag mode if (!dragMode) return; // Figure out where the drag started MouseEvent inputEvent = (MouseEvent) e.getTriggerEvent(); int x = inputEvent.getX(); int y = inputEvent.getY(); // Figure out which scribble was clicked on, if any by creating a // small rectangle around the point and testing for intersection. Rectangle r = new Rectangle(x - LINEWIDTH, y - LINEWIDTH, LINEWIDTH * 2, LINEWIDTH * 2); int numScribbles = scribbles.size(); for (int i = 0; i < numScribbles; i++) { // Loop through the scribbles Scribble s = (Scribble) scribbles.get(i); if (s.intersects(r)) { // The user started the drag on top of this scribble, so // start to drag it. // First, remember which scribble is being dragged, so we can // delete it later (if this is a move rather than a copy) beingDragged = s; // Next, create a copy that will be the one dragged Scribble dragScribble = (Scribble) s.clone(); // Adjust the origin to the point the user clicked on. dragScribble.translate(-x, -y); // Choose a cursor based on the type of drag the user initiated Cursor cursor; switch (e.getDragAction()) { case DnDConstants.ACTION_COPY: cursor = DragSource.DefaultCopyDrop; break; case DnDConstants.ACTION_MOVE: cursor = DragSource.DefaultMoveDrop; break; default: return; // We only support move and copys } // Some systems allow us to drag an image along with the // cursor. If so, create an image of the scribble to drag if (dragSource.isDragImageSupported()) { Rectangle scribbleBox = dragScribble.getBounds(); Image dragImage = this.createImage(scribbleBox.width, scribbleBox.height); Graphics2D g = (Graphics2D) dragImage.getGraphics(); g.setColor(new Color(0, 0, 0, 0)); // transparent background g.fillRect(0, 0, scribbleBox.width, scribbleBox.height); g.setColor(Color.black); g.setStroke(linestyle); g.translate(-scribbleBox.x, -scribbleBox.y); g.draw(dragScribble); Point hotspot = new Point(-scribbleBox.x, -scribbleBox.y); // Now start dragging, using the image. e.startDrag(cursor, dragImage, hotspot, dragScribble, this); } else { // Or start the drag without an image e.startDrag(cursor, dragScribble, this); } // After we've started dragging one scribble, stop looking return; } } }
From source file:org.squidy.designer.shape.ZoomShape.java
@Override protected void paintShape(PPaintContext paintContext) { super.paintShape(paintContext); Graphics2D g = paintContext.getGraphics(); double scale = paintContext.getScale(); g.setColor(Color.BLACK);//from w w w . j a v a 2s.c o m if (scale > Constants.SEMANTIC_ZOOM_SCALE) { g.setStroke(STROKE_SEMANTIC_ZOOM); layoutSemantics(ZoomState.ZOOM_IN); paintShapeZoomedIn(paintContext); } else { g.setStroke(STROKE_ZOOM_OUT); layoutSemantics(ZoomState.ZOOM_OUT); paintShapeZoomedOut(paintContext); } }