protected void drawConnections(Graphics g, Collection<Connection> cons) {
    if (selectedDotA != null && overDotB != null) {
      Color c = g.getColor();
      g.setColor(Color.GRAY);
      Connection tmpCon = new Connection();
      tmpCon.src = selectedDotA;
      tmpCon.dst = overDotB;
      tmpCon.paint(g);
      g.setColor(c);
    }

    for (Connection con : cons) {
      if (selectedDotA != null
          && overDotB != null
          && con.src.distance(selectedDotA) == 0
          && con.dst.distance(overDotB) != 0) {
        // ignore
      } else if ((overDotA != null && con.src.distance(overDotA) == 0)
          || (overDotB != null && con.dst.distance(overDotB) == 0)) {
        Color c = g.getColor();
        g.setColor(Color.CYAN);
        con.paint(g);
        g.setColor(c);
      } else con.paint(g);
    }
  }
Exemple #2
0
  /**
   * Paints the specified line onto the graphics context. Note that this method munges the offset
   * and count values of the segment.
   *
   * @param line The line segment
   * @param tokens The token list for the line
   * @param styles The syntax style list
   * @param expander The tab expander used to determine tab stops. May be null
   * @param gfx The graphics context
   * @param x The x co-ordinate
   * @param y The y co-ordinate
   * @return The x co-ordinate, plus the width of the painted string
   */
  public static int paintSyntaxLine(
      Segment line,
      Token tokens,
      SyntaxStyle[] styles,
      TabExpander expander,
      Graphics gfx,
      int x,
      int y) {
    Font defaultFont = gfx.getFont();
    Color defaultColor = gfx.getColor();

    int offset = 0;
    for (; ; ) {
      byte id = tokens.id;
      if (id == Token.END) break;

      int length = tokens.length;
      if (id == Token.NULL) {
        if (!defaultColor.equals(gfx.getColor())) gfx.setColor(defaultColor);
        if (!defaultFont.equals(gfx.getFont())) gfx.setFont(defaultFont);
      } else styles[id].setGraphicsFlags(gfx, defaultFont);

      line.count = length;
      x = Utilities.drawTabbedText(line, x, y, gfx, expander, 0);
      line.offset += length;
      offset += length;

      tokens = tokens.next;
    }

    return x;
  }
  // draw rectangles and Strings in different colors
  public void paintComponent(Graphics g) {
    super.paintComponent(g); // call superclass's paintComponent

    this.setBackground(Color.WHITE);

    // set new drawing color using integers
    g.setColor(new Color(255, 0, 0));
    g.fillRect(15, 25, 100, 20);
    g.drawString("Current RGB: " + g.getColor(), 130, 40);

    // set new drawing color using floats
    g.setColor(new Color(0.50f, 0.75f, 0.0f));
    g.fillRect(15, 50, 100, 20);
    g.drawString("Current RGB: " + g.getColor(), 130, 65);

    // set new drawing color using static Color objects
    g.setColor(Color.BLUE);
    g.fillRect(15, 75, 100, 20);
    g.drawString("Current RGB: " + g.getColor(), 130, 90);

    // display individual RGB values
    Color color = Color.MAGENTA;
    g.setColor(color);
    g.fillRect(15, 100, 100, 20);
    g.drawString(
        "RGB values: " + color.getRed() + ", " + color.getGreen() + ", " + color.getBlue(),
        130,
        115);
  } // end method paintComponent
  /** Paints the track. */
  @Override
  public void paintTrack(Graphics g) {
    // Draw track.
    super.paintTrack(g);

    Rectangle trackBounds = trackRect;

    if (slider.getOrientation() == JSlider.HORIZONTAL) {
      // Determine position of selected range by moving from the middle
      // of one thumb to the other.
      int lowerX = thumbRect.x + (thumbRect.width / 2);
      int upperX = upperThumbRect.x + (upperThumbRect.width / 2);

      // Determine track position.
      int cy = (trackBounds.height / 2) - 2;

      // Save color and shift position.
      Color oldColor = g.getColor();
      g.translate(trackBounds.x, trackBounds.y + cy);

      // Draw selected range.
      g.setColor(rangeColor);
      for (int y = 0; y <= 3; y++) {
        g.drawLine(lowerX - trackBounds.x, y, upperX - trackBounds.x, y);
      }

      // Restore position and color.
      g.translate(-trackBounds.x, -(trackBounds.y + cy));
      g.setColor(oldColor);

    } else {
      // Determine position of selected range by moving from the middle
      // of one thumb to the other.
      int lowerY = thumbRect.x + (thumbRect.width / 2);
      int upperY = upperThumbRect.x + (upperThumbRect.width / 2);

      // Determine track position.
      int cx = (trackBounds.width / 2) - 2;

      // Save color and shift position.
      Color oldColor = g.getColor();
      g.translate(trackBounds.x + cx, trackBounds.y);

      // Draw selected range.
      g.setColor(rangeColor);
      for (int x = 0; x <= 3; x++) {
        g.drawLine(x, lowerY - trackBounds.y, x, upperY - trackBounds.y);
      }

      // Restore position and color.
      g.translate(-(trackBounds.x + cx), -trackBounds.y);
      g.setColor(oldColor);
    }
  }
    @Override
    protected void paintExpandedControls(
        JXTaskPane group, Graphics g, int x, int y, int width, int height) {
      ((Graphics2D) g)
          .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

      g.setColor(getPaintColor(group));
      paintRectAroundControls(group, g, x, y, width, height, g.getColor(), g.getColor());
      paintChevronControls(group, g, x, y, width, height);

      ((Graphics2D) g)
          .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    }
  /**
   * Draw a legend for this data set
   *
   * @param g Graphics context
   * @param w Data Window
   */
  protected void draw_legend(Graphics g, Rectangle w) {
    Color c = g.getColor();
    Markers m = null;

    if (legend_text == null) return;
    if (legend_text.isNull()) return;

    if (legend_ix == 0 && legend_iy == 0) {
      legend_ix = (int) (w.x + ((legend_dx - xmin) / xrange) * w.width);
      legend_iy = (int) (w.y + (1.0 - (legend_dy - ymin) / yrange) * w.height);
    }

    if (linestyle != DataSet.NOLINE) {
      if (linecolor != null) g.setColor(linecolor);
      g.drawLine(legend_ix, legend_iy, legend_ix + legend_length, legend_iy);
    }

    if (marker > 0) {
      m = g2d.getMarkers();
      if (m != null) {
        if (markercolor != null) g.setColor(markercolor);
        else g.setColor(c);

        m.draw(g, marker, 1.0, legend_ix + legend_length / 2, legend_iy);
      }
    }

    legend_text.draw(
        g,
        legend_ix + legend_length + legend_text.charWidth(g, ' '),
        legend_iy + legend_text.getAscent(g) / 3);

    g.setColor(c);
  }
 @Override
 public void paint(Graphics g) {
   final Color color = g.getColor();
   g.setColor(myColor);
   g.fillRect(0, 0, getWidth(), getHeight());
   g.setColor(color);
 }
Exemple #8
0
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    // Before I simply set the ColorPanel's background colour. But I found
    // this
    // caused weird paint effects e.g. a second copy of the panel appearing
    // at the top left corner of the rendered image. [Jon Aquino].
    // <<TODO:DESIGN>> Use the GraphicsState class [Jon Aquino]
    Color originalColor = g.getColor();
    g.setColor(getBackground());
    ((Graphics2D) g).setStroke(fillStroke);
    g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
    g.setColor(fillColor);
    g.fillRect(margin, margin, getWidth() - 1 - margin - margin, getHeight() - 1 - margin - margin);

    if (lineColor != null) {
      g.setColor(lineColor);
      ((Graphics2D) g).setStroke(lineStroke);

      // -1 to ensure the rectangle doesn't extend past the panel [Jon
      // Aquino]
      g.drawRect(
          margin, margin, getWidth() - 1 - margin - margin, getHeight() - 1 - margin - margin);
    }

    // <<TODO:DESIGN>> Put the next line in a finally block [Jon Aquino]
    g.setColor(originalColor);
  }
  @Override
  public void paint(Graphics g) {
    Color origColor;
    boolean isPressed, isEnabled;
    int w, h, size;

    w = getSize().width;
    h = getSize().height;
    origColor = g.getColor();
    isPressed = getModel().isPressed();
    isEnabled = isEnabled();

    g.setColor(getBackground());
    g.fillRect(1, 1, w - 2, h - 2);

    /// Draw the proper Border
    if (getBorder() != null && !(getBorder() instanceof UIResource)) {
      paintBorder(g);
    } else if (isPressed) {
      g.setColor(shadow);
      g.drawRect(0, 0, w - 1, h - 1);
    } else {
      // Using the background color set above
      g.drawLine(0, 0, 0, h - 1);
      g.drawLine(1, 0, w - 2, 0);

      g.setColor(highlight); // inner 3D border
      g.drawLine(1, 1, 1, h - 3);
      g.drawLine(2, 1, w - 3, 1);

      g.setColor(shadow); // inner 3D border
      g.drawLine(1, h - 2, w - 2, h - 2);
      g.drawLine(w - 2, 1, w - 2, h - 3);

      //                g.setColor(darkShadow);     // black drop shadow  __|
      g.drawLine(0, h - 1, w - 1, h - 1);
      g.drawLine(w - 1, h - 1, w - 1, 0);
    }

    // If there's no room to draw arrow, bail
    if (h < 5 || w < 5) {
      g.setColor(origColor);
      return;
    }

    if (isPressed) {
      g.translate(1, 1);
    }

    // Draw the arrow
    size = Math.min((h - 4) / 3, (w - 4) / 3);
    size = Math.max(size, 4); // Customized
    paintTriangle(g, (w - size) / 2, (h - size) / 2, size, direction, isEnabled);

    // Reset the Graphics back to it's original settings
    if (isPressed) {
      g.translate(-1, -1);
    }
    g.setColor(origColor);
  }
Exemple #10
0
 @Override
 public void draw(Graphics graphicsInstance) {
   Color oldColor = graphicsInstance.getColor();
   graphicsInstance.setColor(this.getShapeColor());
   graphicsInstance.drawLine(getStartX(), getStartY(), getEndX(), getEndY());
   graphicsInstance.setColor(oldColor);
 }
Exemple #11
0
 public Rectangle[] draw(
     Graphics g, int xOffSet, int yOffSet, double xScale, double yScale, boolean isSelected) {
   Color temp = g.getColor();
   int left = (int) (this.getLeft() * xScale);
   int top = (int) (this.getTop() * yScale);
   int width = (int) ((this.getRight() - this.getLeft()) * xScale);
   int height = (int) ((this.getBottom() - this.getTop()) * yScale);
   Rectangle[] crossHairs = null;
   if (isSelected) {
     g.setColor(Color.red);
     crossHairs = new Rectangle[4];
     g.drawRect(left - 2, top - 2, 4, 4);
     g.drawRect(left + width - 2, top - 2, 4, 4);
     g.drawRect(left - 2, top + height - 2, 4, 4);
     g.drawRect(left + width - 2, top + height - 2, 4, 4);
     crossHairs[0] = new Rectangle(left - 2, top - 2, 4, 4);
     crossHairs[1] = new Rectangle(left + width - 2, top - 2, 4, 4);
     crossHairs[2] = new Rectangle(left - 2, top + height - 2, 4, 4);
     crossHairs[3] = new Rectangle(left + width - 2, top + height - 2, 4, 4);
     g.drawRect(left, top, width, height);
   }
   g.drawRect(
       (int) (this.getLeft() * xScale),
       (int) (this.getTop() * yScale),
       (int) ((this.getRight() - this.getLeft()) * xScale),
       (int) ((this.getBottom() - this.getTop()) * yScale));
   for (Header header : headersToData.keySet()) {
     g.setColor(header.getType().getColor());
     header.draw(g, xOffSet, yOffSet, xScale, yScale);
     headersToData.get(header).draw(g, xOffSet, yOffSet, xScale, yScale);
   }
   g.setColor(temp);
   return crossHairs;
 }
 /** Draw the connector on the simulation's canvas */
 public void draw(Graphics g) {
   Color tColor;
   tColor = g.getColor(); // save exisiting color
   g.setColor(color);
   g.drawLine((int) pointA.getX(), (int) pointA.getY(), (int) pointB.getX(), (int) pointB.getY());
   g.setColor(tColor); // restore previous color
 }
  private void drawXAxis(Graphics g, Font font) {
    if (!xAxis.isDisplayed()) return;

    Color oldColor = g.getColor();
    g.setColor(Color.BLACK);

    float leftBorder = getLeftBorder();
    int yVal = getHeight() - getNumPixelsReservedOnBottom();

    g.drawLine((int) leftBorder, yVal, getWidth(), yVal);

    float xInterval = (getWidth() - leftBorder) / xAxis.getNumberTicks();
    FontMetrics fm = g.getFontMetrics(font);

    for (int x = 1; x < xAxis.getNumberTicks(); x++) {
      float xPos = leftBorder + (xInterval * x);
      g.setColor(Color.GRAY);

      g.drawLine((int) xPos, yVal, (int) (xPos), yVal + 5);

      float axisValue =
          xAxis.getLowVal()
              + (x / ((float) xAxis.getNumberTicks())) * (xAxis.getHighVal() - xAxis.getLowVal());
      String axisString = new String("" + (int) (axisValue + 0.5));
      float tickLabelPos = xPos - fm.stringWidth(axisString) / 2;
      g.setColor(Color.BLACK);
      g.drawString(axisString, (int) tickLabelPos, yVal + 18);
    }

    g.setColor(oldColor);
  }
  private void drawHits(Graphics g) {
    // always draw the jitter in the same way
    Random random = new Random(323452);

    Color oldColor = g.getColor();
    int leftBorder = getLeftBorder();

    int xSize = getWidth();
    int availableSpaceForY = getHeight() - getNumPixelsReservedOnBottom();

    for (QueryHitGroup qhg : hits) {
      if (qhg.displayThisData()) {
        g.setColor(qhg.getColor());

        for (HitScores hs : qhg.getHitList()) {
          int yValue = getYValue(hs, availableSpaceForY);

          if (jitterVal > 0) {
            yValue += random.nextInt(jitterVal) + jitterVal / 2;
            yValue = Math.max(0, yValue);
            yValue = Math.min(availableSpaceForY, yValue);
          }

          int x1 = getXValue(hs.getTargetStart(), xSize);
          int x2 = getXValue(hs.getTargetEnd(), xSize);

          if (lineIsInFrame(x1, x2, yValue, xSize, availableSpaceForY)) {
            drawSomeLines(g, x1, x2, yValue, leftBorder, xSize);
          }
        }
      }
    }

    g.setColor(oldColor);
  }
  private void paintScaledTriangle(
      Graphics g, double x, double y, double size, int direction, boolean isEnabled) {
    size = Math.max(size, 2);
    Path2D.Double path = new Path2D.Double();
    path.moveTo(-size, size / 2);
    path.lineTo(size, size / 2);
    path.lineTo(0, -size / 2);
    path.closePath();
    AffineTransform affineTransform = new AffineTransform();
    affineTransform.rotate(Math.PI * (direction - 1) / 4);
    path.transform(affineTransform);

    Graphics2D g2d = (Graphics2D) g;
    double tx = x + size / 2;
    double ty = y + size / 2;
    g2d.translate(tx, ty);
    Color oldColor = g.getColor();
    if (!isEnabled) {
      g2d.translate(1, 0);
      g2d.setColor(highlight);
      g2d.fill(path);
      g2d.translate(-1, 0);
    }
    g2d.setColor(isEnabled ? darkShadow : shadow);
    g2d.fill(path);
    g2d.translate(-tx, -ty);
    g2d.setColor(oldColor);
  }
 public void draw(Graphics g) {
   Color cc = g.getColor();
   g.setColor(cColor);
   if (isEditing()) drawTemp(g);
   else g.fillRect(xView(offX), yView(offY), x2, y2);
   g.setColor(cc);
 }
Exemple #17
0
  /**
   * Draw the vectors at the data points. If this data has been attached to an Axis then scale the
   * data based on the axis maximum/minimum otherwise scale using the data's maximum/minimum
   *
   * @param g Graphics state
   * @param bounds The data window to draw into
   */
  public void draw_data(Graphics g, Rectangle bounds) {
    Color c;

    if (xaxis != null) {
      xmax = xaxis.maximum;
      xmin = xaxis.minimum;
    }

    if (yaxis != null) {
      ymax = yaxis.maximum;
      ymin = yaxis.minimum;
    }

    xrange = xmax - xmin;
    yrange = ymax - ymin;

    /*
     ** draw the legend before we clip the data window
     */
    draw_legend(g, bounds);
    /*
     ** Clip the data window
     */
    if (clipping) g.clipRect(bounds.x, bounds.y, bounds.width, bounds.height);

    c = g.getColor();

    if (linecolor != null) g.setColor(linecolor);
    else g.setColor(c);

    drawVectors(g, bounds);

    g.setColor(c);
  }
    /**
     * Much of this code is copied from GlyphPainter1's implementation.
     *
     * @see javax.swing.text.GlyphView.GlyphPainter#paint(javax.swing.text.GlyphView,
     *     java.awt.Graphics, java.awt.Shape, int, int)
     */
    @Override
    public void paint(GlyphView v, Graphics g, Shape a, int p0, int p1) {
      sync(v);
      Segment text;
      TabExpander expander = v.getTabExpander();
      Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();

      // determine the x coordinate to render the glyphs
      int x = alloc.x;
      int p = v.getStartOffset();
      if (p != p0) {
        text = v.getText(p, p0);
        int width = Utilities.getTabbedTextWidth(text, metrics, x, expander, p);
        x += width;
      } // endif

      // determine the y coordinate to render the glyphs
      int y = alloc.y + metrics.getHeight() - metrics.getDescent();

      // Calculate the background highlight, it gets painted first.
      Color bg = TwoToneTextPane.getTwoToneColor(v.getElement().getAttributes());
      Color fg = g.getColor();
      if (bg == null) { // No color set, guess black or white
        float[] hsb = Color.RGBtoHSB(fg.getRed(), fg.getGreen(), fg.getBlue(), null);
        bg = hsb[2] > 0.7 ? Color.BLACK : Color.WHITE;
      } // endif
      g.setColor(bg);

      // render the glyphs, first in bg highlight, then in fg
      text = v.getText(p0, p1);
      g.setFont(metrics.getFont());
      Utilities.drawTabbedText(text, x + HORIZONTAL_OFFSET, y + VERTICAL_OFFSET, g, expander, p0);
      g.setColor(fg);
      Utilities.drawTabbedText(text, x, y, g, expander, p0);
    }
Exemple #19
0
  private static void paintRoundedRectangle2D(Graphics g, RemoteRectangle rectangle, boolean fill) {
    Graphics2D g2d = (Graphics2D) g;
    try {
      // Rectangle bounds = rectangle.getBounds();
      RoundRectangle2D.Double rectangle2D =
          new RoundRectangle2D.Double(
              rectangle.getX(),
              rectangle.getY(),
              rectangle.getWidth(),
              rectangle.getHeight(),
              ARC_WIDTH,
              ARC_HEIGHT);

      if (fill) {
        g2d.fill(rectangle2D);
        Color origColor = g.getColor();
        g.setColor(Color.BLACK);
        g2d.draw(rectangle2D);
        g.setColor(origColor);
        // g2d.draw(rectangle2D);
      } else g2d.draw(rectangle2D);
    } catch (Exception e) {
      e.printStackTrace();
      // System.out.println(e);
    }
  }
  public void draw(Graphics graphics) {
    Color _oldColor = graphics.getColor();

    graphics.setColor(hasExceptionHandlers(getActivity(), getData()) ? CI.RED : CI.LIGHTGREY);
    super.draw(graphics);
    graphics.setColor(_oldColor);
  }
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Color oldColor = g.getColor();
   Line line = new Line(x, y + 7, x + 20, y + 7);
   line.setColor(this.color);
   line.drawDotLine(g, 1, 1);
   g.setColor(oldColor);
 }
  /* (non-Javadoc)
   * @see rendering.Drawable#paint(java.awt.Graphics)
   */
  @Override
  public void paint(Graphics g) {

    Color oldColor = g.getColor();
    Rectangle field = g.getClipBounds();
    g.setColor(color);

    if (autoscale) {
      double[] start = this.plotSheet.toCoordinatePoint(0, 0, field);
      double[] end =
          this.plotSheet.toCoordinatePoint(0, 0 + this.plotSheet.getFrameThickness(), field);

      this.scaleFactor = Math.abs(end[1] - start[1]);
    } else {
      this.scaleFactor = 1.0;
    }

    if (this.isOnFrame) yOffset = plotSheet.getyRange()[0];

    for (int i = 0; i < this.points[0].length; i++) {
      if (points.length == 3) {
        drawBar(
            points[0][i], points[1][i] * scaleFactor * extraScaleFactor, g, field, points[2][i]);
      } else {
        drawBar(points[0][i], points[1][i] * scaleFactor * extraScaleFactor, g, field);
      }
    }

    g.setColor(oldColor);
  }
Exemple #23
0
  /**
   * Draw the LineSelection at its current location. It is the responsibility of the
   * applet/application to draw the LineSelection at the appropriate times, e.g., inside the
   * component's update() and/or paint() method. This gives maximum flexibility for double
   * buffering, etc.
   *
   * @param g The Graphics context to use for drawing.
   */
  public void draw(Graphics g) {

    if (!isVisible()) {
      return;
    }

    Color saveColor = g.getColor();
    g.setColor(color);
    if (thickness > 1) {
      double ratio = ((double) thickness) / ((double) length());
      double txdb = ratio * ((double) height) / 2.0;
      int tx = txdb > 0 ? ((int) Math.ceil(txdb)) : ((int) Math.floor(txdb));
      double tydb = -ratio * ((double) width) / 2.0;
      int ty = tydb > 0 ? ((int) Math.ceil(tydb)) : ((int) Math.floor(tydb));
      Point[] poly = new Point[4];
      for (int i = 0; i < 4; i++) poly[i] = new Point(x, y);
      poly[0].translate(tx, ty);
      poly[1].translate(-tx, -ty);
      poly[2].translate(width, height);
      poly[2].translate(-tx, -ty);
      poly[3].translate(width, height);
      poly[3].translate(tx, ty);
      Polygon polygon = new Polygon();
      for (int i = 0; i < 4; i++) polygon.addPoint(poly[i].x, poly[i].y);
      g.fillPolygon(polygon);
    } else g.drawLine(x, y, x + width, y + height);
    g.setColor(saveColor);
  } // end draw
    public void paintIcon(Component c, Graphics g, int x, int y) {
      boolean enabled = c.isEnabled();

      // paint the icon
      Icon paintedIcon = enabled ? icon : disabledIcon;
      if (paintedIcon != null) paintedIcon.paintIcon(c, g, x, y);

      // backup current color
      Color oldColor = g.getColor();
      int insetx = 4;
      if (c instanceof JComponent) {
        Insets borderinset = ((JComponent) c).getBorder().getBorderInsets(c);
        insetx = borderinset.left;
      }
      if (paintedIcon != null) {
        g.translate(paintedIcon.getIconWidth() + X_GAP + insetx, 0);
      }

      arrow.paintIcon(c, g, x, y);
      if (paintedIcon != null) {
        g.translate(-paintedIcon.getIconWidth() - X_GAP - insetx, 0);
      }

      // restore previous color
      g.setColor(oldColor);
    }
  public void draw(Graphics g) {
    // 19-2-2008 Removed showing the horizontal and vertical segment constraints
    if (true) return;
    if ((m_seg.getM_parentStk().getM_type() == Stroke.TYPE_NORMAL) && (m_seg.isEnabled())) {
      Graphics2D g2d = (Graphics2D) g;
      // set the color of the graphics to the color of the segment
      Color prevColor = g.getColor();
      g2d.setColor(getColor());

      // create a dashed line for radii lines
      BasicStroke prevStroke = (BasicStroke) g2d.getStroke();
      g2d.setColor(GVariables.DRAWING_ASSIST_COLOR);
      g2d.setStroke(
          new BasicStroke(
              prevStroke.getLineWidth(),
              prevStroke.getEndCap(),
              prevStroke.getLineJoin(),
              prevStroke.getMiterLimit(),
              new float[] {4, 4, 8, 4},
              prevStroke.getDashPhase()));
      g2d.draw(marker_line);
      g2d.setStroke(prevStroke);
      g2d.draw(marker_rect);

      // reset the graphics color back
      g2d.setColor(prevColor);
    }
  }
 public void draw(Graphics g) {
   Color oldColor = g.getColor();
   g.setColor(color);
   if (filled) g.fillRect(cornerX, cornerY, width, height);
   else g.drawRect(cornerX, cornerY, width, height);
   g.setColor(oldColor);
 }
Exemple #27
0
 public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
   Color oldColor = g.getColor();
   g.setColor(Color.BLACK);
   g.drawLine(x - width, y + height, x + width, y + height - 1);
   g.drawLine(x + width, y - height, x + width - 1, y + height - 1);
   g.setColor(oldColor);
 }
  public static void drawString(
      Graphics g,
      String str,
      int x,
      int y,
      HorizontalAlignment horizontalAlignment,
      VerticalAlignment verticalAlignment) {
    int textWidth = g.getFontMetrics().stringWidth(str);
    final int textHeight = g.getFontMetrics().getAscent();
    int resultX = x;
    int resultY = y;

    if (horizontalAlignment == HorizontalAlignment.left) resultX = x;
    else if (horizontalAlignment == HorizontalAlignment.center) resultX = x - textWidth / 2;
    else if (horizontalAlignment == HorizontalAlignment.right) resultX = x - textWidth;

    if (verticalAlignment == VerticalAlignment.top) resultY = y + textHeight;
    else if (verticalAlignment == VerticalAlignment.center) resultY = y + textHeight / 2 - 1;
    else if (verticalAlignment == VerticalAlignment.bottom) resultY = y;

    Color previousColor = g.getColor();
    g.setColor(new Color(1f, 1f, 1f, 0.7f));
    // g.setColor(new Color(0.7f, 0.7f, 1f, 0.7f)); //debug with this
    g.fillRect(resultX, resultY - textHeight + 1, textWidth, g.getFontMetrics().getHeight() - 1);
    g.setColor(previousColor);
    g.drawString(str, resultX, resultY);
  }
  @Override
  public void draw(Graphics g) {
    if (!isInitialised()) return;
    int x = (int) (parent.getDrawStart().getX() + absoluteLocation.getX());
    int y = (int) (parent.getDrawStart().getY() + absoluteLocation.getY());

    int horizontal = Configuration.getTileDiagonal();
    int vertical = Configuration.getTileDiagonal() / 2;
    int drawStartHeight = Configuration.getTileHeight() * startHeight;
    int drawEndHeight = Configuration.getTileHeight() * endHeight;

    top =
        new Polygon(
            new int[] {x, x + horizontal / 2, x, x - horizontal / 2},
            new int[] {
              y - drawEndHeight,
              y - drawStartHeight + vertical / 2,
              y - drawStartHeight + vertical,
              y - drawStartHeight + vertical / 2
            },
            4);
    Polygon leftSide =
        new Polygon(
            new int[] {x - horizontal / 2, x - horizontal / 2, x, x},
            new int[] {
              y + vertical / 2,
              y - drawStartHeight + vertical / 2,
              y - drawStartHeight + vertical,
              y + vertical
            },
            4);
    Polygon rightSide =
        new Polygon(
            new int[] {x, x, x + horizontal / 2, x + horizontal / 2},
            new int[] {
              y + vertical,
              y - drawStartHeight + vertical,
              y - drawStartHeight + vertical / 2,
              y + vertical / 2
            },
            4);

    Color oldColor = g.getColor();
    g.setColor(myColor);
    // Draw the top of the tile
    if (texture != null) {
      if (endHeight - startHeight == -1)
        texture.draw(x - horizontal / 2, y - drawStartHeight + vertical / 2, g);
      else texture.draw(x - horizontal / 2, y - drawEndHeight, g);
    }
    g.fillPolygon(top);
    g.setColor(Color.BLACK);
    // Draw the left side
    g.fillPolygon(leftSide);
    // Draw the right side
    g.fillPolygon(rightSide);

    g.setColor(oldColor);
  }
Exemple #30
0
 /**
  * Paints the thumb icon for the slider.
  *
  * @param g the graphics device.
  */
 public void paintThumb(Graphics g) {
   Color save = g.getColor();
   g.setColor(thumbColor);
   if (slider.getOrientation() == JSlider.HORIZONTAL)
     horizThumbIcon.paintIcon(slider, g, thumbRect.x, thumbRect.y);
   else vertThumbIcon.paintIcon(slider, g, thumbRect.x, thumbRect.y);
   g.setColor(save);
 }