Java Code Examples for java.awt.BasicStroke

The following examples show how to use java.awt.BasicStroke. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: ET_Redux   Source File: HeatMapLegendPanel.java    License: Apache License 2.0 7 votes vote down vote up
/**
 *
 * @param g2d
 */
public void paint(Graphics2D g2d) {

    g2d.setColor(Color.BLACK);
    g2d.setStroke(new BasicStroke(1.0f));

    g2d.setFont(new Font(
            getTitleFont(),
            Font.BOLD,
            Integer.parseInt(getTitleFontSize()) - 2));

    g2d.drawString(getSubtitle(), getX() + 10, getY() + 25 + 1.5f * Integer.valueOf(getTitleFontSize()));

    if (isTitleBoxShow()) {
        DrawBounds(g2d);
    }

    for (int i = 5; i < getBoxWidth() - 5; i++) {
        int selectedIndex = HeatMap.selectColorInRange(0, 0, ((double) i) / (getBoxWidth() - 5));
        int rgb = HeatMap.getRgb().get(selectedIndex);

        g2d.setColor(new Color(rgb));
        g2d.drawLine(i + getX(), 3 + getY(), i + getX(), 3 + getY() + 20);
    }

}
 
Example 2
Source Project: astor   Source File: MarkerTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getStroke() and setStroke() methods.
 */
public void testGetSetStroke() {
    // we use ValueMarker for the tests, because we need a concrete 
    // subclass...
    ValueMarker m = new ValueMarker(1.1);
    m.addChangeListener(this);
    this.lastEvent = null;
    assertEquals(new BasicStroke(0.5f), m.getStroke());
    m.setStroke(new BasicStroke(1.1f));
    assertEquals(new BasicStroke(1.1f), m.getStroke());
    assertEquals(m, this.lastEvent.getMarker());
    
    // check null argument...
    try {
        m.setStroke(null);
        fail("Expected an IllegalArgumentException for null.");
    }
    catch (IllegalArgumentException e) {
        assertTrue(true);
    }
}
 
Example 3
Source Project: tn5250j   Source File: ButtonTabComponent.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g.create();
   // shift the image for pressed buttons
   if (getModel().isPressed()) {
      g2.translate(1, 1);
   }
   g2.setStroke(new BasicStroke(2));
   g2.setColor(Color.BLACK);
   if (getModel().isRollover()) {
      g2.setColor(Color.MAGENTA);
   }
   int delta = 6;
   g2.drawLine(delta, delta, getWidth() - delta - 1, getHeight() - delta - 1);
   g2.drawLine(getWidth() - delta - 1, delta, delta, getHeight() - delta - 1);
   g2.dispose();
}
 
Example 4
Source Project: SmartIM   Source File: ClosableTabHost.java    License: Apache License 2.0 6 votes vote down vote up
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g.create();
    // shift the image for pressed buttons
    if (getModel().isPressed()) {
        g2.translate(1, 1);
    }
    g2.setStroke(new BasicStroke(2));
    g2.setColor(Color.GRAY);
    if (getModel().isRollover()) {
        g2.setColor(Color.LIGHT_GRAY);
    }
    int delta = 5;
    g2.drawLine(delta, delta, getWidth() - delta, getHeight() - delta);
    g2.drawLine(getWidth() - delta, delta, delta, getHeight() - delta);
    g2.dispose();
}
 
Example 5
Source Project: jdk8u_jdk   Source File: Test7019861.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] argv) throws Exception {
    BufferedImage im = getWhiteImage(30, 30);
    Graphics2D g2 = (Graphics2D)im.getGraphics();
    g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(KEY_STROKE_CONTROL, VALUE_STROKE_PURE);
    g2.setStroke(new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    g2.setBackground(Color.white);
    g2.setColor(Color.black);

    Path2D p = getPath(0, 0, 20);
    g2.draw(p);

    if (!(new Color(im.getRGB(20, 19))).equals(Color.black)) {
        throw new Exception("This pixel should be black");
    }
}
 
Example 6
public static ShapeSpanIterator getStrokeSpans(SunGraphics2D sg2d,
                                               Shape s)
{
    ShapeSpanIterator sr = new ShapeSpanIterator(false);

    try {
        sr.setOutputArea(sg2d.getCompClip());
        sr.setRule(PathIterator.WIND_NON_ZERO);

        BasicStroke bs = (BasicStroke) sg2d.stroke;
        boolean thin = (sg2d.strokeState <= SunGraphics2D.STROKE_THINDASHED);
        boolean normalize =
            (sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE);

        RenderEngine.strokeTo(s,
                              sg2d.transform, bs,
                              thin, normalize, false, sr);
    } catch (Throwable t) {
        sr.dispose();
        sr = null;
        throw new InternalError("Unable to Stroke shape ("+
                                t.getMessage()+")", t);
    }
    return sr;
}
 
Example 7
Source Project: ccu-historian   Source File: MarkerTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Some checks for the getOutlineStroke() and setOutlineStroke() methods.
 */
@Test
public void testGetSetOutlineStroke() {
    // we use ValueMarker for the tests, because we need a concrete
    // subclass...
    ValueMarker m = new ValueMarker(1.1);
    m.addChangeListener(this);
    this.lastEvent = null;
    assertEquals(new BasicStroke(0.5f), m.getOutlineStroke());
    m.setOutlineStroke(new BasicStroke(1.1f));
    assertEquals(new BasicStroke(1.1f), m.getOutlineStroke());
    assertEquals(m, this.lastEvent.getMarker());

    // check null argument...
    m.setOutlineStroke(null);
    assertEquals(null, m.getOutlineStroke());
}
 
Example 8
Source Project: MeteoInfo   Source File: Draw.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Draw ellipse
 *
 * @param points The points
 * @param aPGB The polygon break
 * @param g Grahpics2D
 */
public static void drawEllipse(PointF[] points, PolygonBreak aPGB, Graphics2D g) {
    float sx = Math.min(points[0].X, points[2].X);
    float sy = Math.min(points[0].Y, points[2].Y);
    float width = Math.abs(points[2].X - points[0].X);
    float height = Math.abs(points[2].Y - points[0].Y);

    if (aPGB.isDrawFill()) {
        g.setColor(aPGB.getColor());
        g.fill(new Ellipse2D.Float(sx, sy, width, height));
    }
    if (aPGB.isDrawOutline()) {
        g.setColor(aPGB.getOutlineColor());
        g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
        g.draw(new Ellipse2D.Float(sx, sy, width, height));
    }
}
 
Example 9
Source Project: pumpernickel   Source File: ColorPickerSliderUI.java    License: MIT License 6 votes vote down vote up
@Override
public void paintThumb(Graphics g) {
	int y = thumbRect.y + thumbRect.height / 2;
	Polygon polygon = new Polygon();
	polygon.addPoint(0, y - ARROW_HALF);
	polygon.addPoint(ARROW_HALF, y);
	polygon.addPoint(0, y + ARROW_HALF);

	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
			RenderingHints.VALUE_ANTIALIAS_ON);
	g2.setColor(Color.black);
	g2.fill(polygon);
	g2.setColor(Color.white);
	g2.setStroke(new BasicStroke(1));
	g2.draw(polygon);
}
 
Example 10
Source Project: Forsythia   Source File: R0.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void strokeVisiblePolygons(ViewportDef viewportdef,Graphics2D graphics,OrderedPolygons visiblepolygons,double visibledetailfloor,double alpha255detailfloor){
//stroke visible polygons
double detailsize,zz;
int alpha;
Path2D path;
BasicStroke stroke=createStroke(viewportdef,1.5);
graphics.setStroke(stroke);
for(List<FPolygon> a:visiblepolygons.getPolygonLists()){
  for(FPolygon polygon:a){
    //set alpha according to detail size relative to visibledetailfloor and alpha255detailfloor
    detailsize=polygon.getDetailSize();
    if(detailsize>alpha255detailfloor){
      alpha=255;
    }else if(detailsize<visibledetailfloor){
      alpha=0;
    }else{
      zz=(detailsize-visibledetailfloor)/(alpha255detailfloor-visibledetailfloor);
      alpha=(int)(zz*255);}
    path=polygon.getDPolygon().getPath2D();
    graphics.setPaint(new Color(0,0,0,alpha));//black
    graphics.draw(path);}}}
 
Example 11
Source Project: chipster   Source File: Line.java    License: MIT License 6 votes vote down vote up
/**
 * 
 * @param g 
 * @param width 
 * @param height 
 */
public void draw(Graphics g, int width, int height, PaintMode notUsed) {
	
	//Disable drawing lines very near camera, because it causes strange effects.
	//Value of 1.5 was found with visual experiment, so feel free to modify it.
    if (Math.abs(projectedCoords[0][0]) > 1.5 || 
            Math.abs(projectedCoords[0][1]) > 1.5 ||
            this.hidden) {
        return;
    }
    
    g.setColor(color);
    deviceCoords[0][0] = (int)((projectedCoords[0][0] + 0.5) * width);
    deviceCoords[0][1] = (int)((projectedCoords[0][1] + 0.5) * height);
    deviceCoords[1][0] = (int)((projectedCoords[1][0] + 0.5) * width);
    deviceCoords[1][1] = (int)((projectedCoords[1][1] + 0.5) * height);
    
    Graphics2D g2 = (Graphics2D)g;
    g2.setStroke(new BasicStroke(thickness));        
    g2.drawLine(deviceCoords[0][0], deviceCoords[0][1], 
            deviceCoords[1][0], deviceCoords[1][1]);    
}
 
Example 12
Source Project: render   Source File: BoundingBoxRenderer.java    License: GNU General Public License v2.0 6 votes vote down vote up
public BoundingBoxRenderer(final RenderParameters renderParameters,
                           final Color foregroundColor,
                           final float lineWidth) {

    this.renderParameters = renderParameters;
    this.xOffset = renderParameters.getX();
    this.yOffset = renderParameters.getY();
    this.scale = renderParameters.getScale();

    this.foregroundColor = foregroundColor;

    if (renderParameters.getBackgroundRGBColor() == null) {
        this.backgroundColor = null;
    } else {
        this.backgroundColor = new Color(renderParameters.getBackgroundRGBColor());
    }

    this.stroke = new BasicStroke(lineWidth);
}
 
Example 13
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    StackedXYAreaRenderer r1 = new StackedXYAreaRenderer();
    r1.setShapePaint(Color.red);
    r1.setShapeStroke(new BasicStroke(1.23f));
    StackedXYAreaRenderer r2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(r1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        r2 = (StackedXYAreaRenderer) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(r1, r2);
}
 
Example 14
Source Project: netbeans   Source File: SynchronousXYItemPainter.java    License: Apache License 2.0 6 votes vote down vote up
public SynchronousXYItemPainter(float lineWidth, Color lineColor, Color fillColor,
                      int type, int maxValueOffset) {

    if (lineColor == null && fillColor == null)
        throw new IllegalArgumentException("No parameters defined"); // NOI18N

    this.lineWidth = (int)Math.ceil(lineWidth);
    this.lineColor = Utils.checkedColor(lineColor);
    this.fillColor = Utils.checkedColor(fillColor);

    this.lineStroke = new BasicStroke(lineWidth, BasicStroke.CAP_ROUND,
                                      BasicStroke.JOIN_ROUND);

    this.type = type;
    this.maxValueOffset = maxValueOffset;
}
 
Example 15
Source Project: MeteoInfo   Source File: Draw.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Draw pie
 *
 * @param aPoint Start point
 * @param width Width
 * @param height Height
 * @param startAngle Start angle
 * @param sweepAngle Sweep angle
 * @param aPGB Polygon break
 * @param wedgeWidth Wedge width
 * @param g Graphics2D
 */
public static void drawPie(PointF aPoint, float width, float height, float startAngle,
        float sweepAngle, PolygonBreak aPGB, float wedgeWidth, Graphics2D g) {
    Color aColor = aPGB.getColor();
    Arc2D.Float arc2D = new Arc2D.Float(aPoint.X, aPoint.Y, width, height, startAngle, sweepAngle, Arc2D.PIE);
    Area area1 = new Area(arc2D);
    Ellipse2D e2 = new Ellipse2D.Float(aPoint.X + wedgeWidth, aPoint.Y + wedgeWidth, width - wedgeWidth * 2,
            height - wedgeWidth * 2);
    Area area2 = new Area(e2);
    area1.subtract(area2);
    if (aPGB.isDrawFill()) {
        g.setColor(aColor);
        g.fill(area1);
    }
    if (aPGB.isDrawOutline()) {
        g.setColor(aPGB.getOutlineColor());
        g.setStroke(new BasicStroke(aPGB.getOutlineSize()));
        g.draw(area1);
    }
}
 
Example 16
Source Project: jdk8u-jdk   Source File: BorderFactory.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a dashed border of the specified {@code paint}, {@code thickness},
 * line shape, relative {@code length}, and relative {@code spacing}.
 * If the specified {@code paint} is {@code null},
 * the component's foreground color will be used to render the border.
 *
 * @param paint      the {@link Paint} object used to generate a color
 * @param thickness  the width of a dash line
 * @param length     the relative length of a dash line
 * @param spacing    the relative spacing between dash lines
 * @param rounded    whether or not line ends should be round
 * @return the {@code Border} object
 *
 * @throws IllegalArgumentException if the specified {@code thickness} is less than {@code 1}, or
 *                                  if the specified {@code length} is less than {@code 1}, or
 *                                  if the specified {@code spacing} is less than {@code 0}
 * @since 1.7
 */
public static Border createDashedBorder(Paint paint, float thickness, float length, float spacing, boolean rounded) {
    boolean shared = !rounded && (paint == null) && (thickness == 1.0f) && (length == 1.0f) && (spacing == 1.0f);
    if (shared && (sharedDashedBorder != null)) {
        return sharedDashedBorder;
    }
    if (thickness < 1.0f) {
        throw new IllegalArgumentException("thickness is less than 1");
    }
    if (length < 1.0f) {
        throw new IllegalArgumentException("length is less than 1");
    }
    if (spacing < 0.0f) {
        throw new IllegalArgumentException("spacing is less than 0");
    }
    int cap = rounded ? BasicStroke.CAP_ROUND : BasicStroke.CAP_SQUARE;
    int join = rounded ? BasicStroke.JOIN_ROUND : BasicStroke.JOIN_MITER;
    float[] array = { thickness * (length - 1.0f), thickness * (spacing + 1.0f) };
    Border border = createStrokeBorder(new BasicStroke(thickness, cap, join, thickness * 2.0f, array, 0.0f), paint);
    if (shared) {
        sharedDashedBorder = border;
    }
    return border;
}
 
Example 17
Source Project: gpx-animator   Source File: Renderer.java    License: Apache License 2.0 6 votes vote down vote up
private void printText(final Graphics2D g2, final String text, final float x, final float y) {
    final FontRenderContext frc = g2.getFontRenderContext();
    g2.setStroke(new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    final int height = g2.getFontMetrics(font).getHeight();

    final String[] lines = text == null ? new String[0] : text.split("\n");
    float yy = y - (lines.length - 1) * height;
    for (final String line : lines) {
        if (!line.isEmpty()) {
            final TextLayout tl = new TextLayout(line, font, frc);
            final Shape sha = tl.getOutline(AffineTransform.getTranslateInstance(x, yy));
            g2.setColor(Color.white);
            g2.fill(sha);
            g2.draw(sha);

            g2.setFont(font);
            g2.setColor(Color.black);
            g2.drawString(line, x, yy);
        }

        yy += height;
    }
}
 
Example 18
Source Project: jdk8u-jdk   Source File: Decoration.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void drawTextAndEmbellishments(Label label,
                                       Graphics2D g2d,
                                       float x,
                                       float y) {

    label.handleDraw(g2d, x, y);

    if (!strikethrough && stdUnderline == null && imUnderline == null) {
        return;
    }

    float x1 = x;
    float x2 = x1 + (float)label.getLogicalBounds().getWidth();

    CoreMetrics cm = label.getCoreMetrics();
    if (strikethrough) {
        Stroke savedStroke = g2d.getStroke();
        g2d.setStroke(new BasicStroke(cm.strikethroughThickness,
                                      BasicStroke.CAP_BUTT,
                                      BasicStroke.JOIN_MITER));
        float strikeY = y + cm.strikethroughOffset;
        g2d.draw(new Line2D.Float(x1, strikeY, x2, strikeY));
        g2d.setStroke(savedStroke);
    }

    float ulOffset = cm.underlineOffset;
    float ulThickness = cm.underlineThickness;

    if (stdUnderline != null) {
        stdUnderline.drawUnderline(g2d, ulThickness, x1, x2, y + ulOffset);
    }

    if (imUnderline != null) {
        imUnderline.drawUnderline(g2d, ulThickness, x1, x2, y + ulOffset);
    }
}
 
Example 19
Source Project: development   Source File: ImageProducer.java    License: Apache License 2.0 5 votes vote down vote up
protected BufferedImage createImage(Color bgColor) {
    BufferedImage bufferedImage = new BufferedImage(END_X, END_Y,
            BufferedImage.TYPE_INT_RGB);
    // create graphics and graphics2d
    final Graphics graphics = bufferedImage.getGraphics();
    final Graphics2D g2d = (Graphics2D) graphics;

    // set the background color
    g2d.setBackground(bgColor == null ? Color.gray : bgColor);
    g2d.clearRect(START_X, START_Y, END_X, END_Y);
    // create a pattern for the background
    createPattern(g2d);
    // set the fonts and font rendering hints
    Font font = new Font("Helvetica", Font.ITALIC, 30);
    g2d.setFont(font);
    FontRenderContext frc = g2d.getFontRenderContext();
    g2d.translate(10, 24);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setStroke(new BasicStroke(3));

    // sets the foreground color
    g2d.setPaint(Color.DARK_GRAY);
    GlyphVector gv = font.createGlyphVector(frc, message);
    int numGlyphs = gv.getNumGlyphs();
    for (int ii = 0; ii < numGlyphs; ii++) {
        AffineTransform at;
        Point2D p = gv.getGlyphPosition(ii);
        at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        at.rotate(Math.PI / 8);
        Shape shape = gv.getGlyphOutline(ii);
        Shape sss = at.createTransformedShape(shape);
        g2d.fill(sss);
    }
    return blurImage(bufferedImage);
}
 
Example 20
Source Project: astor   Source File: DialCapTests.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    DialCap c1 = new DialCap();
    DialCap c2 = new DialCap();
    assertTrue(c1.equals(c2));
    
    // radius
    c1.setRadius(0.5);
    assertFalse(c1.equals(c2));
    c2.setRadius(0.5);
    assertTrue(c1.equals(c2));
    
    // fill paint
    c1.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.blue, 
            3.0f, 4.0f, Color.green));
    assertFalse(c1.equals(c2));
    c2.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.blue, 
            3.0f, 4.0f, Color.green));
    
    // outline paint
    c1.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.white, 
            3.0f, 4.0f, Color.gray));
    assertFalse(c1.equals(c2));
    c2.setOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.white, 
            3.0f, 4.0f, Color.gray));
    
    assertTrue(c1.equals(c2));

    // outline stroke
    c1.setOutlineStroke(new BasicStroke(1.1f));
    assertFalse(c1.equals(c2));
    c2.setOutlineStroke(new BasicStroke(1.1f));
    assertTrue(c1.equals(c2));
    
    // check an inherited attribute
    c1.setVisible(false);
    assertFalse(c1.equals(c2));
    c2.setVisible(false);
    assertTrue(c1.equals(c2));
}
 
Example 21
Source Project: hottub   Source File: Underline.java    License: GNU General Public License v2.0 5 votes vote down vote up
private Stroke getStroke(float thickness) {

            float lineThickness = getLineThickness(thickness);
            BasicStroke stroke = cachedStroke;
            if (stroke == null ||
                    stroke.getLineWidth() != lineThickness) {

                stroke = createStroke(lineThickness);
                cachedStroke = stroke;
            }

            return stroke;
        }
 
Example 22
/**
 * Two objects that are equal are required to return the same hashCode.
 */
public void testHashCode() {
    Stroke stroke = new BasicStroke(2.0f);
    XYPolygonAnnotation a1 = new XYPolygonAnnotation(new double[] {1.0,
            2.0, 3.0, 4.0, 5.0, 6.0}, stroke, Color.red, Color.blue);
    XYPolygonAnnotation a2 = new XYPolygonAnnotation(new double[] {1.0,
            2.0, 3.0, 4.0, 5.0, 6.0}, stroke, Color.red, Color.blue);
    assertTrue(a1.equals(a2));
    int h1 = a1.hashCode();
    int h2 = a2.hashCode();
    assertEquals(h1, h2);
}
 
Example 23
Source Project: SikuliX1   Source File: SxCircle.java    License: MIT License 5 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
  super.paintComponent(g);
  Graphics2D g2d = (Graphics2D) g;
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
          RenderingHints.VALUE_ANTIALIAS_ON);
  Stroke pen = new BasicStroke((float) stroke);
  g2d.setStroke(pen);
  Rectangle r = new Rectangle(getActualBounds());
  r.grow(-(stroke-1), -(stroke-1));
  g2d.translate(stroke-1, stroke-1);
  Ellipse2D.Double ellipse = new Ellipse2D.Double(0, 0, r.width - 1, r.height - 1);
  g2d.draw(ellipse);
}
 
Example 24
Source Project: jdk8u-dev-jdk   Source File: MyCursor.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override public void paint(Graphics gr) {
   gr.setColor(Color.GREEN);
   ((Graphics2D)gr).setStroke(new BasicStroke(3));
   //arrow
   gr.drawLine(0, 0, width/2, height/2);
   gr.drawLine(0, 0, width/2, 0);
   gr.drawLine(0, 0, 0, height/2);
   //plus
   gr.drawRect(width/2 - 1, height/2 -1, width/2 - 1, height/2 - 1);
   gr.drawLine(width*3/4 - 1, height/2 - 1, width*3/4 - 1, height);
   gr.drawLine(width/2 - 1, height*3/4 - 1, width, height*3/4 - 1);
}
 
Example 25
/**
 * Checks for serialization support.
 */
@Test
public void testSerialization() {
    CategoryMarker cm1 = new CategoryMarker("A");
    cm1.setLabel("ABC");
    cm1.setLabelAnchor(Anchor2D.BOTTOM_RIGHT);
    cm1.setLabelColor(Color.GREEN);
    cm1.setFillColor(Color.DARK_GRAY);
    cm1.setLineStroke(new BasicStroke(0.6f));
    cm1.setLineColor(Color.RED);
    CategoryMarker cm2 = (CategoryMarker) TestUtils.serialized(cm1);
    assertTrue(cm1.equals(cm2));
}
 
Example 26
@Override
public TableCellEditor getTableCellEditor(final Engine engine,
                                          final AccessRules rules, final Attribute attribute) {
    final JComboBox box = new JComboBox();
    box.setRenderer(comboBoxRenderer);

    for (Stroke stroke : LineStyleChooser.getStrokes()) {
        box.addItem(stroke);
    }

    return new DefaultCellEditor(box) {
        private Pin pin;

        @Override
        public boolean stopCellEditing() {
            if (box.getSelectedItem() instanceof Stroke) {
                ((Journaled) engine).startUserTransaction();
                apply((BasicStroke) box.getSelectedItem(), pin);
                return super.stopCellEditing();
            }
            return false;
        }

        @Override
        public Component getTableCellEditorComponent(JTable table,
                                                     Object value, boolean isSelected, int row, int column) {
            pin = (Pin) ((MetadataGetter) table).getMetadata();
            return super.getTableCellEditorComponent(table, value,
                    isSelected, row, column);
        }
    };
}
 
Example 27
@Override
public void paintGraph(Graphics2D g, int width, int height) {
	g.setColor(keyframes.get(0).getValue());
	g.fillRect(0, gradPadding, (int) (keyframes.get(0).getTime()*width), height-2*gradPadding);
	g.setColor(keyframes.get(keyframes.size()-1).getValue());
	g.fillRect((int) ((keyframes.get(keyframes.size()-1).getTime())*width), gradPadding, width - (int) ((keyframes.get(keyframes.size()-1).getTime())*width), height-2*gradPadding);

	Paint origP = g.getPaint();

	for(int i = 0; i < keyframes.size()-1; i++) {

		Keyframe<Color> k0 = keyframes.get(i), k1 = keyframes.get(i+1);

		g.setPaint(new GradientPaint(k0.getTime()*width, 0, k0.getValue(), k1.getTime()*width, 0, k1.getValue()));
		g.fillRect((int) (k0.getTime()*width), gradPadding-3, (int) (k1.getTime()*width-k0.getTime()*width), height-2*(gradPadding-3));
	}
	g.setPaint(origP);

	g.setStroke(new BasicStroke(3)); //Draw red bar at each keyframe
	g.setColor(Color.BLACK);//new Color(255, 0, 0, 32));
	for(int i = 0; i < keyframes.size(); i++)
		g.drawLine((int) (keyframes.get(i).getTime() * width), 0, (int) (keyframes.get(i).getTime() * width), height);
	g.setStroke(new BasicStroke(1)); //Draw red bar at each keyframe
	g.setColor(Color.WHITE);//new Color(255, 0, 0, 32));
	for(int i = 0; i < keyframes.size(); i++)
		g.drawLine((int) (keyframes.get(i).getTime() * width), 0, (int) (keyframes.get(i).getTime() * width), height);
}
 
Example 28
Source Project: workcraft   Source File: RouterVisualiser.java    License: MIT License 5 votes vote down vote up
private static void drawCellBusy(Graphics2D g, Coordinate dy, Coordinate dx) {
    Path2D shape = new Path2D.Double();
    shape.moveTo(dx.getValue() - 0.1, dy.getValue() - 0.1);
    shape.lineTo(dx.getValue() + 0.1, dy.getValue() + 0.1);
    shape.moveTo(dx.getValue() + 0.1, dy.getValue() - 0.1);
    shape.lineTo(dx.getValue() - 0.1, dy.getValue() + 0.1);
    g.setColor(Color.RED);
    g.setStroke(new BasicStroke(1.0f * (float) CircuitSettings.getWireWidth()));
    g.draw(shape);
}
 
Example 29
Source Project: openjdk-jdk8u   Source File: DashZeroWidth.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void draw(final Image img) {
    float[] dashes = {10.0f, 10.0f};
    BasicStroke bs = new BasicStroke(0.0f, BasicStroke.CAP_BUTT,
                                     BasicStroke.JOIN_BEVEL, 10.0f, dashes,
                                     0.0f);
    Graphics2D g = (Graphics2D) img.getGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, 200, 40);
    Line2D line = new Line2D.Double(20, 20, 180, 20);
    g.setColor(Color.BLACK);
    g.setStroke(bs);
    g.draw(line);
    g.dispose();
}
 
Example 30
Source Project: Pixie   Source File: DrawOptions.java    License: MIT License 5 votes vote down vote up
/**
 * Draw a bounding box / rectangle starting at the specified position,
 * having the specified line (dashed or plain), and being filled as
 * specified.
 *
 * @param g2d          the graphics object
 * @param box          the rectangle specification
 * @param color        the color of the rectangle
 * @param filledBox    true if the box should be filled with color
 * @param fillingColor the color used for the filling of the rectangle
 * @param dashedLine   true if the line used for the drawing of the rectangle should be dashed; false if the line should be solid/plain
 */
public static void drawBBox(Graphics2D g2d, Rectangle box, Color color,
        boolean filledBox, Color fillingColor, boolean dashedLine) {
    g2d.setStroke(dashedLine ? getDashedStroke() : new BasicStroke(0));

    if (filledBox) {
        // draw the fill of the rectangle    
        g2d.setColor(fillingColor);
        g2d.fillRect(box.x, box.y, box.width, box.height);
    }

    drawBBox(g2d, box, color, dashedLine);
}