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.
Example 1
Project: ET_Redux   File: HeatMapLegendPanel.java    License: Apache License 2.0 6 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
Project: astor   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
Project: tn5250j   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
Project: SmartIM   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
Project: jdk8u_jdk   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
Project: openjdk-jdk8u-backup   File: LoopPipe.java    License: GNU General Public License v2.0 6 votes vote down vote up
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
Project: ccu-historian   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
Project: MeteoInfo   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
Project: pumpernickel   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
Project: Forsythia   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
Project: chipster   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
Project: render   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
Project: astor   File: StackedXYAreaRendererTests.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
Project: netbeans   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
Project: MeteoInfo   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
Project: jdk8u-jdk   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
Project: gpx-animator   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
Project: jdk8u-jdk   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
Project: development   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
Project: astor   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
Project: hottub   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
Project: astor   File: XYPolygonAnnotationTests.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
Project: SikuliX1   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
Project: jdk8u-dev-jdk   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
Project: orson-charts   File: CategoryMarkerTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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
Project: ramus   File: LineStyleAttributePlugin.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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
Project: GIFKR   File: ColorInterpolator.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@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
Project: workcraft   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
Project: openjdk-jdk8u   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
Project: Pixie   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);
}
 
Example 31
Project: TencentKona-8   File: WPrinterJob.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected boolean selectStylePen(int cap, int join, float width,
                                 Color color) {

    long endCap;
    long lineJoin;

    float[] rgb = color.getRGBColorComponents(null);

    switch(cap) {
    case BasicStroke.CAP_BUTT: endCap = PS_ENDCAP_FLAT; break;
    case BasicStroke.CAP_ROUND: endCap = PS_ENDCAP_ROUND; break;
    default:
    case BasicStroke.CAP_SQUARE: endCap = PS_ENDCAP_SQUARE; break;
    }

    switch(join) {
    case BasicStroke.JOIN_BEVEL:lineJoin = PS_JOIN_BEVEL; break;
    default:
    case BasicStroke.JOIN_MITER:lineJoin = PS_JOIN_MITER; break;
    case BasicStroke.JOIN_ROUND:lineJoin = PS_JOIN_ROUND; break;
    }

    return (selectStylePen(getPrintDC(), endCap, lineJoin, width,
                           (int) (rgb[0] * MAX_WCOLOR),
                           (int) (rgb[1] * MAX_WCOLOR),
                           (int) (rgb[2] * MAX_WCOLOR)));
}
 
Example 32
Project: openstock   File: XYShapeAnnotationTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode.
 */
@Test
public void testHashCode() {
    XYShapeAnnotation a1 = new XYShapeAnnotation(
            new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0),
            new BasicStroke(1.2f), Color.red, Color.blue);
    XYShapeAnnotation a2 = new XYShapeAnnotation(
            new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0),
            new BasicStroke(1.2f), Color.red, Color.blue);
    assertTrue(a1.equals(a2));
    int h1 = a1.hashCode();
    int h2 = a2.hashCode();
    assertEquals(h1, h2);
}
 
Example 33
Project: mzmine2   File: HistogramChartFactory.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds annotations to the Gaussian fit parameters
 * 
 * @param plot
 * @param fit Gaussian fit {normalisation factor, mean, sigma}
 */
public static void addGaussianFitAnnotations(XYPlot plot, double[] fit) {
  Paint c = plot.getDomainCrosshairPaint();
  BasicStroke s = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1,
      new float[] {5f, 2.5f}, 0);

  plot.addDomainMarker(new ValueMarker(fit[1], c, s));
  plot.addDomainMarker(new ValueMarker(fit[1] - fit[2], c, s));
  plot.addDomainMarker(new ValueMarker(fit[1] + fit[2], c, s));
}
 
Example 34
Project: openstock   File: XYBoxAnnotationTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    XYBoxAnnotation a1 = new XYBoxAnnotation(1.0, 2.0, 3.0, 4.0,
            new BasicStroke(1.2f), Color.red, Color.blue);
    XYBoxAnnotation a2 = (XYBoxAnnotation) TestUtilities.serialised(a1);
    assertEquals(a1, a2);
}
 
Example 35
Project: ccu-historian   File: StandardDialRange.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws the range.
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame (in Java2D space).
 * @param view  the dial's view rectangle (in Java2D space).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
        Rectangle2D view) {

    Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame,
            this.innerRadius, this.innerRadius);
    Rectangle2D arcRectOuter = DialPlot.rectangleByRadius(frame,
            this.outerRadius, this.outerRadius);

    DialScale scale = plot.getScale(this.scaleIndex);
    if (scale == null) {
        throw new RuntimeException("No scale for scaleIndex = "
                + this.scaleIndex);
    }
    double angleMin = scale.valueToAngle(this.lowerBound);
    double angleMax = scale.valueToAngle(this.upperBound);

    Arc2D arcInner = new Arc2D.Double(arcRectInner, angleMin,
            angleMax - angleMin, Arc2D.OPEN);
    Arc2D arcOuter = new Arc2D.Double(arcRectOuter, angleMax,
            angleMin - angleMax, Arc2D.OPEN);

    g2.setPaint(this.paint);
    g2.setStroke(new BasicStroke(2.0f));
    g2.draw(arcInner);
    g2.draw(arcOuter);
}
 
Example 36
Project: MyBox   File: ImageScope.java    License: Apache License 2.0 5 votes vote down vote up
public static BufferedImage indicateRectangle(BufferedImage source,
        Color color, int lineWidth, DoubleRectangle rect) {
    try {

        int width = source.getWidth();
        int height = source.getHeight();
        if (!rect.isValid(width, height)) {
            return source;
        }
        int imageType = source.getType();
        if (imageType == BufferedImage.TYPE_CUSTOM) {
            imageType = BufferedImage.TYPE_INT_ARGB;
        }
        BufferedImage target = new BufferedImage(width, height, imageType);
        Graphics2D g = target.createGraphics();
        g.drawImage(source, 0, 0, width, height, null);
        AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f);
        g.setComposite(ac);
        g.setColor(color);
        BasicStroke stroke = new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                1f, new float[]{lineWidth, lineWidth}, 0f);
        g.setStroke(stroke);
        g.drawRect((int) rect.getSmallX(), (int) rect.getSmallY(), (int) rect.getWidth(), (int) rect.getHeight());
        g.dispose();
        return target;
    } catch (Exception e) {
        logger.error(e.toString());
        return source;
    }
}
 
Example 37
Project: ET_Redux   File: LAICPMSProjectParametersManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param g2d
 */
protected void paintInit(Graphics2D g2d) {
    RenderingHints rh = g2d.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHints(rh);

    g2d.setPaint(Color.BLACK);
    g2d.setStroke(new BasicStroke(1.0f));
    g2d.setFont(ReduxConstants.sansSerif_12_Bold);
}
 
Example 38
Project: openjdk-jdk8u   File: WPrinterJob.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected boolean selectStylePen(int cap, int join, float width,
                                 Color color) {

    long endCap;
    long lineJoin;

    float[] rgb = color.getRGBColorComponents(null);

    switch(cap) {
    case BasicStroke.CAP_BUTT: endCap = PS_ENDCAP_FLAT; break;
    case BasicStroke.CAP_ROUND: endCap = PS_ENDCAP_ROUND; break;
    default:
    case BasicStroke.CAP_SQUARE: endCap = PS_ENDCAP_SQUARE; break;
    }

    switch(join) {
    case BasicStroke.JOIN_BEVEL:lineJoin = PS_JOIN_BEVEL; break;
    default:
    case BasicStroke.JOIN_MITER:lineJoin = PS_JOIN_MITER; break;
    case BasicStroke.JOIN_ROUND:lineJoin = PS_JOIN_ROUND; break;
    }

    return (selectStylePen(getPrintDC(), endCap, lineJoin, width,
                           (int) (rgb[0] * MAX_WCOLOR),
                           (int) (rgb[1] * MAX_WCOLOR),
                           (int) (rgb[2] * MAX_WCOLOR)));
}
 
Example 39
Project: SIMVA-SoS   File: LineBorderTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Confirm that the equals() method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    LineBorder b1 = new LineBorder(Color.red, new BasicStroke(1.0f),
            new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    LineBorder b2 = new LineBorder(Color.red, new BasicStroke(1.0f),
            new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    assertTrue(b1.equals(b2));
    assertTrue(b2.equals(b2));

    b1 = new LineBorder(Color.blue, new BasicStroke(1.0f),
            new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    assertFalse(b1.equals(b2));
    b2 = new LineBorder(Color.blue, new BasicStroke(1.0f),
            new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    assertTrue(b1.equals(b2));

    b1 = new LineBorder(Color.blue, new BasicStroke(1.1f),
            new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    assertFalse(b1.equals(b2));
    b2 = new LineBorder(Color.blue, new BasicStroke(1.1f),
            new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    assertTrue(b1.equals(b2));

    b1 = new LineBorder(Color.blue, new BasicStroke(1.1f),
            new RectangleInsets(1.0, 2.0, 3.0, 4.0));
    assertFalse(b1.equals(b2));
    b2 = new LineBorder(Color.blue, new BasicStroke(1.1f),
            new RectangleInsets(1.0, 2.0, 3.0, 4.0));
    assertTrue(b1.equals(b2));

}
 
Example 40
Project: Bytecoder   File: Underline.java    License: Apache License 2.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;
        }