Example #1
0
  private static Icon getThemeIcon(ColorScheme colorScheme, boolean square) {
    int iSize = SubstanceSizeUtils.getTitlePaneIconSize();
    BufferedImage result = SubstanceCoreUtilities.getBlankImage(iSize, iSize);
    Graphics2D graphics = (Graphics2D) result.getGraphics().create();
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    Color color1 = (colorScheme == null) ? Color.red : colorScheme.getUltraDarkColor();
    Color color2 = (colorScheme == null) ? Color.green : colorScheme.getMidColor();
    Color color3 = (colorScheme == null) ? Color.blue : colorScheme.getExtraLightColor();

    graphics.setColor(color1);
    if (square) graphics.fillRect(5, 2, 6, 6);
    else graphics.fillOval(5, 2, 6, 6);
    graphics.setColor(color1.darker());
    if (square) graphics.drawRect(5, 2, 6, 6);
    else graphics.drawOval(5, 2, 6, 6);

    graphics.setColor(color2);
    if (square) graphics.fillRect(1, 9, 6, 6);
    else graphics.fillOval(1, 9, 6, 6);
    graphics.setColor(color2.darker());
    if (square) graphics.drawRect(1, 9, 6, 6);
    else graphics.drawOval(1, 9, 6, 6);

    graphics.setColor(color3);
    if (square) graphics.fillRect(9, 9, 6, 6);
    else graphics.fillOval(9, 9, 6, 6);
    graphics.setColor(color3.darker());
    if (square) graphics.drawRect(9, 9, 6, 6);
    else graphics.drawOval(9, 9, 6, 6);

    graphics.dispose();
    return new ImageIcon(result);
  }
Example #2
0
  /** {@inheritDoc} */
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setBackground(Color.white);
    int xDim = (int) (getWidth() / 56);
    int yDim = (int) (getHeight() / 66);
    g2d.drawLine(0, (agent[0].length) * yDim, Slope.getWidth() * xDim, (agent[0].length) * yDim);
    g2d.drawRect((Slope.getWidth() - 3) * xDim, 0, 15, Slope.getHeight() * yDim);

    for (int k = 0; k < Slope.getHeight(); k++)
      for (int l = 0; l < Slope.getWidth(); l++) {

        g2d.setColor(new Color(0, 0, 0, 1));
        g2d.drawRect(k * getWidth() / 56, l * getHeight() / 66, 30, 30);
      }

    for (int i = 0; i < agent.length; i++) {
      for (int j = 0; j < agent[0].length; j++) {
        g2d.setColor(Color.blue);
        if (agent[i][j]) {
          //					 g2d.drawString("*", i*getWidth()/56, j*getHeight()/66);
          g2d.drawImage(image, i * getWidth() / 56, j * getHeight() / 66, null);
        }
      }
    }
  }
Example #3
0
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      AbstractButton button = (AbstractButton) c;
      Graphics2D g2D = (Graphics2D) g;
      Color frameColor = AbstractLookAndFeel.getTheme().getFrameColor();
      if (!JTattooUtilities.isFrameActive(button)) {
        frameColor = ColorHelper.brighter(frameColor, 40);
      }

      if (AbstractLookAndFeel.getTheme().doDrawSquareButtons()) {
        g2D.setColor(Color.white);
        g2D.drawRect(x, y, w - 1, h - 1);

        if (button.getRootPane() != null
            && button.equals(button.getRootPane().getDefaultButton())
            && !button.hasFocus()) {
          g2D.setColor(ColorHelper.darker(frameColor, 20));
          g2D.drawRect(x, y, w - 1, h - 2);
          if (!button.getModel().isRollover()) {
            g2D.setColor(defaultColorHi);
            g2D.drawRect(x + 1, y + 1, w - 3, h - 4);
            g2D.setColor(defaultColorLo);
            g2D.drawRect(x + 2, y + 2, w - 5, h - 6);
          }
        } else {
          g2D.setColor(frameColor);
          g2D.drawRect(x, y, w - 2, h - 2);
        }
      } else {
        Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
        g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        if (button.getRootPane() != null
            && button.equals(button.getRootPane().getDefaultButton())) {
          if (!button.getModel().isRollover()) {
            g2D.setColor(defaultColorHi);
            g2D.drawRoundRect(x + 1, y + 1, w - 4, h - 2, 6, 6);
            g2D.setColor(defaultColorLo);
            g2D.drawRoundRect(x + 2, y + 2, w - 6, h - 6, 6, 6);
          }
        }

        g2D.setColor(Color.white);
        g2D.drawRoundRect(x, y, w - 1, h - 1, 6, 6);

        g2D.setColor(frameColor);
        g2D.drawRoundRect(x, y, w - 2, h - 2, 6, 6);

        g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint);
      }
    }
Example #4
0
  public void paint(java.awt.Graphics g) {
    if (element != null) {
      Rectangle bounds = element.jGetBounds();
      Graphics2D g2 = (Graphics2D) g;

      g2.setFont(font);

      int mitteX = bounds.x + (bounds.width) / 2;
      int mitteY = bounds.y + (bounds.height) / 2;

      int distanceY = 10;

      g2.setColor(new Color(204, 204, 255));
      g2.fillRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY);
      g2.setColor(Color.BLACK);
      g2.drawRect(bounds.x, mitteY - distanceY, bounds.width, 2 * distanceY);

      String caption = "dec(" + variable.getValue() + ")";

      FontMetrics fm = g2.getFontMetrics();
      Rectangle2D r = fm.getStringBounds(caption, g2);

      g2.setColor(Color.BLACK);
      g.drawString(
          caption, mitteX - (int) (r.getWidth() / 2), (int) (mitteY + fm.getHeight() / 2) - 3);
    }
    super.paint(g);
  }
  /** Paints selection for the specified <code>component</code>. */
  public static void paintSelectionDecoration(
      @NotNull RadComponent component, Graphics g, boolean focused) {
    if (component.isSelected()) {
      if (focused) {
        g.setColor(PlatformColors.BLUE);
      } else {
        g.setColor(Color.GRAY);
      }
      final Point[] points = getPoints(component.getWidth(), component.getHeight());
      for (final Point point : points) {
        g.fillRect(point.x - R, point.y - R, 2 * R + 1, 2 * R + 1);
      }
    } else if (component.getWidth() < FormEditingUtil.EMPTY_COMPONENT_SIZE
        || component.getHeight() < FormEditingUtil.EMPTY_COMPONENT_SIZE) {
      Graphics2D g2d = (Graphics2D) g;
      Composite oldComposite = g2d.getComposite();
      Stroke oldStroke = g2d.getStroke();
      Color oldColor = g2d.getColor();

      g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f));
      g2d.setStroke(new BasicStroke(0.7f));
      g2d.setColor(Color.black);
      g2d.drawRect(
          0,
          0,
          Math.max(component.getWidth(), FormEditingUtil.EMPTY_COMPONENT_SIZE),
          Math.max(component.getHeight(), FormEditingUtil.EMPTY_COMPONENT_SIZE));

      g2d.setComposite(oldComposite);
      g2d.setStroke(oldStroke);
      g2d.setColor(oldColor);
    }
  }
  public void paintShadow(Component c, Graphics2D g, int x, int y, int width, int height) {
    final int leftSize = myLeft.getIconWidth();
    final int rightSize = myRight.getIconWidth();
    final int bottomSize = myBottom.getIconHeight();
    final int topSize = myTop.getIconHeight();

    myTopLeft.paintIcon(c, g, x, y);
    myTopRight.paintIcon(c, g, x + width - myTopRight.getIconWidth(), y);
    myBottomRight.paintIcon(
        c, g, x + width - myBottomRight.getIconWidth(), y + height - myBottomRight.getIconHeight());
    myBottomLeft.paintIcon(c, g, x, y + height - myBottomLeft.getIconHeight());

    for (int _x = myTopLeft.getIconWidth(); _x < width - myTopRight.getIconWidth(); _x++) {
      myTop.paintIcon(c, g, _x + x, y);
    }
    for (int _x = myBottomLeft.getIconWidth(); _x < width - myBottomLeft.getIconWidth(); _x++) {
      myBottom.paintIcon(c, g, _x + x, y + height - bottomSize);
    }
    for (int _y = myTopLeft.getIconHeight(); _y < height - myBottomLeft.getIconHeight(); _y++) {
      myLeft.paintIcon(c, g, x, _y + y);
    }
    for (int _y = myTopRight.getIconHeight(); _y < height - myBottomRight.getIconHeight(); _y++) {
      myRight.paintIcon(c, g, x + width - rightSize, _y + y);
    }

    if (myBorderColor != null) {
      g.setColor(myBorderColor);
      g.drawRect(
          x + leftSize - 1,
          y + topSize - 1,
          width - leftSize - rightSize + 1,
          height - topSize - bottomSize + 1);
    }
  }
Example #7
0
  public void StaticObjNew(StaticObj so) {
    Graphics2D g = radarArea.backImage.createGraphics();
    g.setColor(so_color);

    if (so instanceof Beacon) {
      g.drawOval(
          convPos(so.pos.x) - grid_size / 6,
          convPos(so.pos.y) - grid_size / 6,
          grid_size / 3,
          grid_size / 3);
      JLabel sol = new JLabel(Integer.toString(so.id));
      sol.setForeground(so_text_color);
      sol.setBounds(
          convPos(so.pos.x) + grid_size / 6, convPos(so.pos.y), grid_size / 3, grid_size / 2);
      radarArea.add(sol, new Integer(1));
    }

    if (so instanceof Airfield) {
      int xa[] = new int[3], ya[] = new int[3];
      int l1 = grid_size / 2, l2 = grid_size / 6;
      xa[0] = convPos(so.pos.x);
      ya[0] = convPos(so.pos.y);
      xa[1] = convPos(so.pos.x) - l1 * so.dir.x - l2 * so.dir.y;
      ya[1] = convPos(so.pos.y) - l1 * so.dir.y + l2 * so.dir.x;
      xa[2] = convPos(so.pos.x) - l1 * so.dir.x + l2 * so.dir.y;
      ya[2] = convPos(so.pos.y) - l1 * so.dir.y - l2 * so.dir.x;
      g.drawPolygon(xa, ya, 3);
      JLabel sol = new JLabel(Integer.toString(so.id));
      sol.setForeground(so_text_color);
      sol.setBounds(
          convPos(so.pos.x) + grid_size / 6, convPos(so.pos.y), grid_size / 3, grid_size / 2);
      radarArea.add(sol, new Integer(1));
    }

    if (so instanceof Exit) {
      g.drawRect(
          convPos(so.pos.x) - grid_size / 6,
          convPos(so.pos.y) - grid_size / 6,
          grid_size / 3,
          grid_size / 3);
      JLabel sol = new JLabel(Integer.toString(so.id));
      sol.setForeground(so_text_color);
      sol.setBounds(
          convPos(so.pos.x) + grid_size / 6, convPos(so.pos.y), grid_size / 3, grid_size / 2);
      radarArea.add(sol, new Integer(1));
    }

    if (so instanceof Line) {
      g.setColor(line_color);
      g.drawLine(
          convPos(((Line) so).pos.x),
          convPos(((Line) so).pos.y),
          convPos(((Line) so).second_end.x),
          convPos(((Line) so).second_end.y));
    }

    radarArea.backIcon = new ImageIcon(radarArea.backImage);
    radarArea.back.setIcon(radarArea.backIcon);
  }
 @Override
 public void draw(Graphics2D g2) {
   int w = toolInterface.getStrokeWidth() * 4;
   Color c = g2.getColor();
   g2.setColor(Color.GRAY);
   g2.drawRect(mouseX - w / 2, mouseY - w / 2, w, w);
   g2.setColor(c);
 }
Example #9
0
 // initialize default image
 private BufferedImage getDefaultImage(int w, int h) {
   BufferedImage defaultImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
   Graphics2D graphics2D = defaultImage.createGraphics();
   graphics2D.setColor(new Color(200, 200, 200));
   graphics2D.fillRect(0, 0, w, h);
   graphics2D.setColor(new Color(130, 130, 130));
   graphics2D.drawRect(0, 0, w - 1, h - 1);
   return defaultImage;
 }
Example #10
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = ((Graphics2D) g);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    g2d.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    g2d.setRenderingHint(
        RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
    g2d.setRenderingHint(
        RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
    g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
    g2d.setColor(Color.BLACK);
    g2d.fillRect(0, 0, getWidth(), getHeight());

    if (bufferedImage != null) {
      synchronized (LOCKER) {
        g2d.drawImage(bufferedImage, transformCells, null);
      }
    }
    // draw struct preview
    if (structurePreview != null) {
      Composite composite = g2d.getComposite();
      g2d.setComposite(compositeStructPreview);
      g2d.drawImage(structurePreview, previewTransform, null);
      g2d.setComposite(composite);
    }
    // draw grid
    if (transformCells.getScaleX() > SHOW_GRID_MIN_SCALE) {
      Composite composite = g2d.getComposite();
      g2d.setComposite(compositeGrid);
      g2d.drawImage(bufferedImageGrid, transformGrid, null);
      g2d.setComposite(composite);
    }
    // draw border for preview
    if (structurePreview != null && Math.abs(transformCells.getScaleX()) >= 0.95) {
      Shape shape = new Rectangle(0, 0, structurePreview.getWidth(), structurePreview.getHeight());
      shape = previewTransform.createTransformedShape(shape);
      g2d.setColor(Color.RED);
      g2d.draw(shape);
    }

    // draw border
    double x = transformCells.getTranslateX();
    double y = transformCells.getTranslateY();

    g2d.setColor(BORDER_COLOR);
    g2d.setStroke(new BasicStroke(BORDER_WIDTH));
    g2d.drawRect(
        round(x - BORDER_WIDTH),
        round(y - BORDER_WIDTH),
        round(getAutomatonWidth() * transformCells.getScaleX() + 2 * BORDER_WIDTH),
        round(getAutomatonHeight() * transformCells.getScaleY() + 2 * BORDER_WIDTH));
  }
Example #11
0
 @Override
 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
   Graphics2D g2 = (Graphics2D) g.create();
   g2.translate(x, y);
   g2.setPaint(borderSelectionColor);
   g2.drawRect(0, 0, w - 1, h - 1);
   g2.setPaint(getLineColor());
   BasicGraphicsUtils.drawDashedRect(g2, 0, 0, w, h);
   g2.dispose();
 }
  public void paintComponent(Graphics g) {
    setSize(xSize, ySize);
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;

    if (PedigreeExplorer.thickLines) {
      // turn this off so they don't look blurry when exported
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    } else {
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    }
    g2.setColor(Color.black);

    if (PedigreeExplorer.thickLines) {
      g2.setStroke(new BasicStroke(2));
    } else {
      g2.setStroke(new BasicStroke(1));
    }

    if (sex == male) {
      if (PedigreeExplorer.thickLines) {
        g2.drawRect(1, 1, symbolSize - 2, symbolSize - 2);
      } else {
        g2.drawRect(0, 0, symbolSize, symbolSize);
      }

      if (affection == affected) {
        g2.fillRect(0, 0, symbolSize, symbolSize);
      }
    }

    if (sex == female) {
      if (PedigreeExplorer.thickLines) {
        g2.drawArc(1, 1, symbolSize - 2, symbolSize - 2, 0, 360);
      } else {
        g2.drawArc(0, 0, symbolSize, symbolSize, 0, 360);
      }

      if (affection == affected) {
        g2.fillArc(0, 0, symbolSize, symbolSize, 0, 360);
      }
    }
  }
    /**
     * @param points
     * @param color
     * @param g
     */
    private void paintSequence(
        Slot type, List<List<ValuePointColored>> points, Color color, Graphics2D g) {
      int i = 0;
      int size = points.size();

      if (size > 0) {
        double increment = 200 / size;

        for (List<ValuePointColored> valuePoints : points) {
          int alpha = (int) (i * increment) + 55;
          Color c = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
          for (ValuePointColored valuePoint : valuePoints) {
            double[] coordinates = valuePoint.getPoint().toArray();
            int x = xToPix(coordinates[0]);
            int y = yToPix(coordinates[1]);
            // if minimum then red, else black
            if (valuePoint.getBest() == true) {
              g.setColor(Color.red);
            } else {
              g.setColor(c);
            }
            g.setStroke(LINE);

            switch (type) {
              case CIRCLE:
                g.drawOval(x - RADIUS / 2 - 3, y - RADIUS / 2 - 3, RADIUS * 2, RADIUS * 2);
                break;
              case SQUARE:
                g.drawRect(x - RADIUS / 2 - 2, y - RADIUS / 2 - 2, RADIUS * 2 - 2, RADIUS * 2 - 2);
                break;
              case TRIANGLE:
                GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3);
                polyline.moveTo(x, y - RADIUS / 2 - 4);
                polyline.lineTo(x + RADIUS / 2 + 3, y + RADIUS / 2 + 1);
                polyline.lineTo(x - RADIUS / 2 - 3, y + RADIUS / 2 + 1);
                polyline.closePath();
                g.draw(polyline);
                break;
              case CROSS:
                int xLow = x - RADIUS / 2 - 1;
                int xHigh = x + RADIUS / 2 + 1;
                int yLow = y - RADIUS / 2 - 1;
                int yHigh = y + RADIUS / 2 + 1;
                g.drawLine(xLow, yLow, xHigh, yHigh);
                g.drawLine(xHigh, yLow, xLow, yHigh);
                break;
            }
          }
          i++;
        }
      }
    }
Example #14
0
  private void paintVisibleWindow(Graphics2D g) {
    Rectangle visibleArea = editor.getScrollingModel().getVisibleArea();
    int firstVisibleLine = getMapYFromEditorY((int) visibleArea.getMinY());
    int height =
        coords.linesToPixels(
            (int) ((visibleArea.getMaxY() - visibleArea.getMinY()) / editor.getLineHeight()));

    // Draw the current viewport
    g.setColor(viewportColor);
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.50f));
    g.drawRect(0, firstVisibleLine, getWidth(), height);
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.20f));
    g.fillRect(0, firstVisibleLine, getWidth(), height);
  }
  private void paintWhitespace(
      Graphics2D g,
      CharSequence text,
      float x,
      int y,
      int start,
      int end,
      EditorImpl.LineWhitespacePaintingStrategy whitespacePaintingStrategy,
      VisualLineFragmentsIterator.Fragment fragment) {
    g.setColor(myEditor.getColorsScheme().getColor(EditorColors.WHITESPACES_COLOR));
    boolean isRtl = fragment.isRtl();
    int baseStartOffset = fragment.getStartOffset();
    int startOffset = isRtl ? baseStartOffset - start : baseStartOffset + start;
    for (int i = start; i < end; i++) {
      int charOffset = isRtl ? baseStartOffset - i - 1 : baseStartOffset + i;
      char c = text.charAt(charOffset);
      if (" \t\u3000".indexOf(c) >= 0
          && whitespacePaintingStrategy.showWhitespaceAtOffset(charOffset)) {
        int startX =
            (int)
                fragment.offsetToX(
                    x, startOffset, isRtl ? baseStartOffset - i : baseStartOffset + i);
        int endX =
            (int)
                fragment.offsetToX(
                    x, startOffset, isRtl ? baseStartOffset - i - 1 : baseStartOffset + i + 1);

        if (c == ' ') {
          g.fillRect((startX + endX) / 2, y, 1, 1);
        } else if (c == '\t') {
          endX -= myView.getPlainSpaceWidth() / 4;
          int height = myView.getCharHeight();
          int halfHeight = height / 2;
          int mid = y - halfHeight;
          int top = y - height;
          UIUtil.drawLine(g, startX, mid, endX, mid);
          UIUtil.drawLine(g, endX, y, endX, top);
          g.fillPolygon(
              new int[] {endX - halfHeight, endX - halfHeight, endX},
              new int[] {y, y - height, y - halfHeight},
              3);
        } else if (c == '\u3000') { // ideographic space
          final int charHeight = myView.getCharHeight();
          g.drawRect(startX + 2, y - charHeight, endX - startX - 4, charHeight);
        }
      }
    }
  }
Example #16
0
  public void paint(Graphics g) {
    Graphics2D gr = (Graphics2D) g;
    super.paint(g);
    Rectangle bounds = scene.getBounds();
    Dimension size = getSize();

    double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0;
    double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0;
    double scale = Math.min(sx, sy);

    int vw = (int) (scale * bounds.width);
    int vh = (int) (scale * bounds.height);
    int vx = (size.width - vw) / 2;
    int vy = (size.height - vh) / 2;

    if (image == null || vw != imageWidth || vh != imageHeight) {

      imageWidth = vw;
      imageHeight = vh;
      image = this.createImage(imageWidth, imageHeight);
      Graphics2D ig = (Graphics2D) image.getGraphics();
      ig.scale(scale, scale);
      scene.setRealZoomFactor(scale);
      scene.paint(ig);
      scene.setRealZoomFactor(0.0);
    }

    gr.drawImage(image, vx, vy, this);

    JComponent component = scene.getView();
    double zoomFactor = scene.getZoomFactor();
    Rectangle viewRectangle = component != null ? component.getVisibleRect() : null;
    if (viewRectangle != null) {
      Rectangle window =
          new Rectangle(
              (int) ((double) viewRectangle.x * scale / zoomFactor),
              (int) ((double) viewRectangle.y * scale / zoomFactor),
              (int) ((double) viewRectangle.width * scale / zoomFactor),
              (int) ((double) viewRectangle.height * scale / zoomFactor));
      window.translate(vx, vy);
      gr.setColor(new Color(200, 200, 200, 128));
      gr.fill(window);
      gr.setColor(Color.BLACK);
      gr.drawRect(window.x, window.y, window.width - 1, window.height - 1);
    }
  }
Example #17
0
  private void paintMap(Graphics2D g2) {
    for (int y = 0; y < this.m_map.length; y++) {
      for (int x = 0; x < this.m_map[y].length; x++) {
        if (this.m_map[y][x] == GameBody.SNAKE || this.m_map[y][x] == GameBody.SNAKE_HEAD) {
          g2.drawRect(
              x * UserInterface.SCALE,
              y * UserInterface.SCALE,
              UserInterface.SCALE,
              UserInterface.SCALE);

        } else if (this.m_map[y][x] == GameBody.FRUIT) {
          g2.fillOval(
              x * UserInterface.SCALE,
              y * UserInterface.SCALE,
              UserInterface.SCALE,
              UserInterface.SCALE);
        }
      }
    }
  }
  /** Part of print code coped from Sun */
  public void printTablePart(Graphics2D g2, PageFormat pageFormat, int rowIndex, int columnIndex) {

    String pageNumber = "Page: " + (rowIndex + 1);
    if (subTableSplitSize > 1) {
      pageNumber += "-" + (columnIndex + 1);
    }

    int pageLeft = subTableSplit[columnIndex];
    int pageRight = subTableSplit[columnIndex + 1];

    int pageWidth = pageRight - pageLeft;

    // page number message (in smaller type)
    g2.setFont(new Font(g2.getFont().getName(), g2.getFont().getStyle(), 8));
    g2.drawString(pageNumber, pageWidth / 2 - 35, (int) (pageHeight - fontHeight));

    double clipHeight =
        Math.min(tableHeightOnFullPage, tableHeight - rowIndex * tableHeightOnFullPage);

    g2.translate(-subTableSplit[columnIndex], 0);
    g2.setClip(pageLeft, 0, pageWidth, (int) headerHeight);

    g2.scale(scale, scale);
    tableHeader.paint(g2); // draw the header on every page
    g2.scale(1 / scale, 1 / scale);
    g2.translate(0, headerHeight);
    g2.translate(0, -tableHeightOnFullPage * rowIndex);

    // cut table image and draw on the page

    g2.setClip(pageLeft, (int) tableHeightOnFullPage * rowIndex, pageWidth, (int) clipHeight);
    g2.scale(scale, scale);
    _table.paint(g2);
    g2.scale(1 / scale, 1 / scale);

    double pageTop = tableHeightOnFullPage * rowIndex - headerHeight;
    //		double pageBottom = pageTop +  clipHeight + headerHeight;
    g2.drawRect(pageLeft, (int) pageTop, pageWidth, (int) (clipHeight + headerHeight));
  }
  @Override
  public void paintBorder(Component component, Graphics g, int x, int y, int width, int height) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setPaint(getBoundsColor());
    int horMargin = myOuterMargin.left + myOuterMargin.right;
    int vertMargin = myOuterMargin.top + myOuterMargin.bottom;

    g2.drawRect(
        x + myOuterMargin.left,
        y + myOuterMargin.top,
        x + width - 3 - horMargin,
        y + height - 3 - vertMargin);
    g2.setPaint(myShade1);

    g2.drawLine(
        x + 1 + myOuterMargin.left,
        y + height - 2 - myOuterMargin.bottom,
        x + width - 2 - myOuterMargin.right,
        y + height - 2 - myOuterMargin.bottom);
    g2.drawLine(
        x + width - 2 - myOuterMargin.right,
        y + 1 + myOuterMargin.bottom,
        x + width - 2 - myOuterMargin.right,
        y + height - 2 - myOuterMargin.bottom);

    g2.setPaint(myShade2);
    g2.drawLine(
        x + 2 + myOuterMargin.left,
        y + height - 1 - myOuterMargin.bottom,
        x + width - 1 - myOuterMargin.right,
        y + height - 1 - myOuterMargin.bottom);
    g2.drawLine(
        x + width - 1 - myOuterMargin.right,
        y + 2 + myOuterMargin.top,
        x + width - 1 - myOuterMargin.right,
        y + height - 1 - myOuterMargin.bottom);
  }
Example #20
0
    public void drawCursor(char c, Graphics2D gfx, TextStyle style) {
      TerminalCursorState state = computeCursorState();

      // hidden: do nothing
      if (state == TerminalCursorState.HIDDEN) {
        return;
      } else {
        final int x = getCoordX();
        final int y = getCoordY();
        if (y >= 0 && y < myTermSize.height) {
          if (state == TerminalCursorState.SHOWING) {
            TextStyle styleToDraw = getInversedStyle(style);
            drawCharacters(x, y, styleToDraw, new CharBuffer(c, 1), gfx);
          } else if (state == TerminalCursorState.NO_FOCUS) {
            int xCoord = x * myCharSize.width;
            int yCoord = y * myCharSize.height;
            gfx.setColor(
                getPalette().getColor(myStyleState.getForeground(style.getForegroundForRun())));
            gfx.drawRect(xCoord, yCoord, myCharSize.width - 1, myCharSize.height - 1);
          }
        }
      }
    }
Example #21
0
 // compare the two images in this object.
 public void compare() {
   // setup change display image
   imgc = imageToBufferedImage(img1);
   Graphics2D gc = imgc.createGraphics();
   gc.setColor(Color.RED);
   // convert to gray images.
   img1 = imageToBufferedImage(GrayFilter.createDisabledImage(img1));
   img2 = imageToBufferedImage(GrayFilter.createDisabledImage(img2));
   // how big are each section
   int blocksx = (int) (img1.getWidth() / comparex);
   int blocksy = (int) (img1.getHeight() / comparey);
   // set to a match by default, if a change is found then flag non-match
   this.match = true;
   // loop through whole image and compare individual blocks of images
   for (int y = 0; y < comparey; y++) {
     if (debugMode > 0) System.out.print("|");
     for (int x = 0; x < comparex; x++) {
       int b1 =
           getAverageBrightness(
               img1.getSubimage(x * blocksx, y * blocksy, blocksx - 1, blocksy - 1));
       int b2 =
           getAverageBrightness(
               img2.getSubimage(x * blocksx, y * blocksy, blocksx - 1, blocksy - 1));
       int diff = Math.abs(b1 - b2);
       if (diff
           > factorA) { // the difference in a certain region has passed the threshold value of
                        // factorA
         // draw an indicator on the change image to show where change was detected.
         gc.drawRect(x * blocksx, y * blocksy, blocksx - 1, blocksy - 1);
         this.match = false;
       }
       if (debugMode == 1) System.out.print((diff > factorA ? "X" : " "));
       if (debugMode == 2) System.out.print(diff + (x < comparex - 1 ? "," : ""));
     }
     if (debugMode > 0) System.out.println("|");
   }
 }
  public void paint(final Graphics g, final JComponent c) {
    final AnchoredButton button = (AnchoredButton) c;

    final String text = button.getText();
    final Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return;
    }

    final FontMetrics fm = button.getFontMetrics(button.getFont());
    ourViewInsets = c.getInsets(ourViewInsets);

    ourViewRect.x = ourViewInsets.left;
    ourViewRect.y = ourViewInsets.top;

    final ToolWindowAnchor anchor = button.getAnchor();

    // Use inverted height & width
    if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) {
      ourViewRect.height = c.getWidth() - (ourViewInsets.left + ourViewInsets.right);
      ourViewRect.width = c.getHeight() - (ourViewInsets.top + ourViewInsets.bottom);
    } else {
      ourViewRect.height = c.getHeight() - (ourViewInsets.left + ourViewInsets.right);
      ourViewRect.width = c.getWidth() - (ourViewInsets.top + ourViewInsets.bottom);
    }

    ourIconRect.x = ourIconRect.y = ourIconRect.width = ourIconRect.height = 0;
    ourTextRect.x = ourTextRect.y = ourTextRect.width = ourTextRect.height = 0;

    final String clippedText =
        SwingUtilities.layoutCompoundLabel(
            c,
            fm,
            text,
            icon,
            button.getVerticalAlignment(),
            button.getHorizontalAlignment(),
            button.getVerticalTextPosition(),
            button.getHorizontalTextPosition(),
            ourViewRect,
            ourIconRect,
            ourTextRect,
            button.getText() == null ? 0 : button.getIconTextGap());

    // Paint button's background

    final Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    final ButtonModel model = button.getModel();

    final Color background = button.getBackground();

    Color toBorder = model.isRollover() ? new Color(0, 0, 0, 50) : null;
    final boolean vertical = anchor == ToolWindowAnchor.LEFT || anchor == ToolWindowAnchor.RIGHT;

    if (model.isArmed() && model.isPressed() || model.isSelected()) {
      g2.setColor(new Color(0, 0, 0, 30));
      g2.fillRect(3, 3, button.getWidth() - (vertical ? 6 : 5), button.getHeight() - 6);

      g2.setColor(new Color(0, 0, 0, 120));
      g2.drawLine(2, 2, 3 + button.getWidth() - (vertical ? 7 : 6), 2);
      g2.drawLine(2, 3, 2, 3 + button.getHeight() - 7);

      g2.setColor(new Color(0, 0, 0, 40));
      g2.drawRect(3, 3, button.getWidth() - (vertical ? 7 : 6), button.getHeight() - 7);

      g2.setColor(new Color(255, 255, 255, 110));
      g2.drawLine(
          3,
          button.getHeight() - 3,
          3 + button.getWidth() - (vertical ? 6 : 5),
          button.getHeight() - 3);
      g2.drawLine(
          3 + button.getWidth() - (vertical ? 6 : 5),
          2,
          3 + button.getWidth() - (vertical ? 6 : 5),
          3 + button.getHeight() - 7);

      toBorder = null;
    }

    if (toBorder != null) {
      g.setColor(toBorder);
      g.drawRect(2, 2, button.getWidth() - (vertical ? 6 : 5), button.getHeight() - 6);
    }

    AffineTransform tr = null;
    if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) {
      tr = g2.getTransform();
      if (ToolWindowAnchor.RIGHT == anchor) {
        if (icon != null) { // do not rotate icon
          icon.paintIcon(c, g2, ourIconRect.y, ourIconRect.x);
        }
        g2.rotate(Math.PI / 2);
        g2.translate(0, -c.getWidth());
      } else {
        if (icon != null) { // do not rotate icon
          icon.paintIcon(
              c, g2, ourIconRect.y, c.getHeight() - ourIconRect.x - icon.getIconHeight());
        }
        g2.rotate(-Math.PI / 2);
        g2.translate(-c.getHeight(), 0);
      }
    } else {
      if (icon != null) {
        icon.paintIcon(c, g2, ourIconRect.x, ourIconRect.y);
      }
    }

    // paint text

    if (text != null) {
      if (model.isEnabled()) {
        if (model.isArmed() && model.isPressed() || model.isSelected()) {
          g.setColor(background);
        } else {
          g.setColor(button.getForeground());
        }
      } else {
        g.setColor(background.darker());
      }
      /* Draw the Text */
      if (model.isEnabled()) {
        /** * paint the text normally */
        g.setColor(button.getForeground());
        BasicGraphicsUtils.drawString(
            g, clippedText, button.getMnemonic2(), ourTextRect.x, ourTextRect.y + fm.getAscent());
      } else {
        /** * paint the text disabled ** */
        if (model.isSelected()) {
          g.setColor(c.getBackground());
        } else {
          g.setColor(getDisabledTextColor());
        }
        BasicGraphicsUtils.drawString(
            g, clippedText, button.getMnemonic2(), ourTextRect.x, ourTextRect.y + fm.getAscent());
      }
    }
    if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) {
      g2.setTransform(tr);
    }
  }
  private void drawInventory(Graphics g)
        //  PRE:  g must be initialized.
        //  POST: Draws the inventory of the store if mode == 0, else draws the players inventory.
        //        If an item is selected, its border is highlighted white.
      {
    Graphics2D g2; // Graphics 2D object to allow for different brush stroke widths.
    Color start; // The start color for the inventory window gradient.
    Color end; // The end color for the inventory window gradient.
    int x1; // Upper-left x coordinate.
    int y1; // Upper-left y coordinate.
    int x2; // Bottom-right x coordinate.
    int y2; // Bottom-right y coordinate.
    int width; // Width of the inventory box.
    int height; // Height of the inventory box.
    int itemHeight; // The height of an item box.
    int itemY; // The y coordinate of the item.
    Item currentItem; // Item to store the current item

    g2 = (Graphics2D) g;
    start = new Color(120, 120, 220);
    end = new Color(50, 50, 150);

    x1 = inventoryPos[0].getScaledX();
    y1 = inventoryPos[0].getScaledY();
    x2 = inventoryPos[1].getScaledX();
    y2 = inventoryPos[1].getScaledY();
    width = x2 - x1;
    height = y2 - y1;

    while (height % ITEMSPERPAGE != 0) // ensure that the item boxes do not fall short of the window
    {
      height = ++y2 - y1;
    }

    itemHeight = height / ITEMSPERPAGE;

    Drawing.drawGradient(g2, start, end, x1, y1, width, height / 2);
    Drawing.drawGradient(g2, end, start, x1, y1 + height / 2, width, height / 2);

    g2.setColor(Color.BLACK);
    g2.setStroke(new BasicStroke(3));
    g2.drawRect(--x1, --y1, ++width, height);
    g2.setColor(Color.WHITE);

    switch (store) // Chooses the current store
    {
      case 0:
        connectItems(getUserItems("Weapon", orderToSort));
        break;
      case 1:
        connectItems(getUserItems("ArmorSmith", orderToSort));
        break;
      case 2:
        connectItems(getUserItems("Accessory", orderToSort));
        break;
      case 3:
        connectItems(getUserItems("General", orderToSort));
        break;
    }

    if (mode) // Sets mode to true for user inventory and displays
    {
      connectItems(getUserItems("Player", orderToSort));
    }

    int count = 0;
    // count = currentPage * ITEMSPERPAGE ;

    try // Try loading 10 items per page
    {

      currentItem = null;
      count = currentPage * ITEMSPERPAGE;
      for (int i = 0; i < ITEMSPERPAGE; i++) // draw each item into the window
      {
        if (i > itemsArray.length - 1) // Check if i excceds the array size
        {
          return;
        }
        itemY = y1 + (itemHeight) * i;

        currentItem = itemsArray[count];

        if (itemSelected == i) // if the item was selected, highlight it
        {
          g2.drawRect(x1, itemY, width, itemHeight);
        }

        drawItem(g2, i, currentItem);

        count++;
      }

    } catch (Exception e) // Catch generic exception and print it out
    {
      System.err.println(e.toString());
      System.err.println("Oh no, not like this...");
    }
  }
    private void doPaint(Graphics g) {
      GraphicsUtil.setupAntialiasing(g);

      final boolean isEmpty = getIcon() == null && StringUtil.isEmpty(getText());
      final Dimension size = getSize();
      if (isSmallVariant()) {
        final Graphics2D g2 = (Graphics2D) g;
        g2.setColor(UIUtil.getControlColor());
        final int w = getWidth();
        final int h = getHeight();
        if (getModel().isArmed() && getModel().isPressed()) {
          g2.setPaint(
              new GradientPaint(
                  0,
                  0,
                  UIUtil.getControlColor(),
                  0,
                  h,
                  ColorUtil.shift(UIUtil.getControlColor(), 0.8)));
        } else {
          g2.setPaint(
              new GradientPaint(
                  0,
                  0,
                  ColorUtil.shift(UIUtil.getControlColor(), 1.1),
                  0,
                  h,
                  ColorUtil.shift(UIUtil.getControlColor(), 0.9)));
        }
        g2.fillRect(2, 0, w - 2, h);
        GraphicsUtil.setupAntialiasing(g2);
        if (!myMouseInside) {
          g2.setPaint(
              new GradientPaint(
                  0, 0, UIUtil.getBorderColor(), 0, h, UIUtil.getBorderColor().darker()));
          // g2.setColor(UIUtil.getBorderColor());
        } else {
          g2.setPaint(
              new GradientPaint(
                  0,
                  0,
                  UIUtil.getBorderColor().darker(),
                  0,
                  h,
                  UIUtil.getBorderColor().darker().darker()));
        }
        g2.drawRect(2, 0, w - 3, h - 1);
        final Icon icon = getIcon();
        int x = 7;
        if (icon != null) {
          icon.paintIcon(null, g, x, (size.height - icon.getIconHeight()) / 2);
          x += icon.getIconWidth() + 3;
        }
        if (!StringUtil.isEmpty(getText())) {
          final Font font = getFont();
          g2.setFont(font);
          g2.setColor(UIManager.getColor("Panel.foreground"));
          g2.drawString(getText(), x, (size.height + font.getSize()) / 2 - 1);
        }
      } else {
        super.paintComponent(g);
      }
      final Insets insets = super.getInsets();
      final Icon icon = isEnabled() ? ARROW_ICON : DISABLED_ARROW_ICON;
      final int x;
      if (isEmpty) {
        x = (size.width - icon.getIconWidth()) / 2;
      } else {
        if (isSmallVariant()) {
          x = size.width - icon.getIconWidth() - insets.right + 1;
        } else {
          x =
              size.width
                  - icon.getIconWidth()
                  - insets.right
                  + (UIUtil.isUnderNimbusLookAndFeel() ? -3 : 2);
        }
      }
      if (UIUtil.isUnderDarcula()) {
        g.setXORMode(new Color(208, 188, 159));
      }
      icon.paintIcon(null, g, x, (size.height - icon.getIconHeight()) / 2);
      g.setPaintMode();
    }
    public void paintComponent(Graphics g) {
      super.paintComponent(g);

      Graphics2D g2 = (Graphics2D) g;

      AlphaComposite ac, ac2 = null;
      ac2 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f);
      for (int i = 0; i < imagenum_now.length; i++) {
        for (int j = 0; j < imagenum_now[i].length; j++) {
          // System.out.println("x: " + i + ", y: " + j);

          g2.setComposite(ac2);

          if (imagenum_now[i][j] != -1) {
            g2.drawImage(
                // images.get(imagenum_now[i][j])
                // getImage(images.get(imagenum_now[i][j])),
                imagenum_now2[i][j], i * size_x, j * size_y, size_x, size_y, this);
          } else {
            // No picture found, ignoring
            // System.out.println("imagenum_now["+i+"]["+j+"] = -1");
          }

          try {
            ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, fade[i][j]);
          } catch (IllegalArgumentException e) {
            ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f);
          }
          g2.setComposite(ac);
          if (imagenum_next[i][j] != -1) {
            g2.drawImage(
                // images.get(imagenum_next[i][j]),
                // getImage(images.get(imagenum_next[i][j])),
                imagenum_next2[i][j], i * size_x, j * size_y, size_x, size_y, this);
          } else {
            // No picture found, ignoring
            // System.out.println("imagenum_now["+i+"]["+j+"] = -1");
          }

          /*
          if(i == 0 && j == 0)
          	System.out.println("" + imagenum_now[i][j] +
          			" => " +
          			imagenum_next[i][j] + ", fade: "+fade[i][j]);;
          */

          // Red border if the image is new
          if (number_of_frames_redborder != -1
              && (images_nevershown.contains((Integer) imagenum_next[i][j])
                  || images_nevershown.contains((Integer) imagenum_now[i][j]))) {
            g2.setComposite(ac2);
            g2.setColor(color_redborder);
            int bordertime = redborder[i][j];
            if (bordertime > 0) {
              // Draw border
              g2.drawRect(i * size_x, j * size_y, size_x - 1, size_y - 1);

              if (bordertime > number_of_frames_redborder) {
                // No more border
                redborder[i][j] = -number_of_frames_redborder;
              }
            }
            redborder[i][j]++;
          }
        }
      }
    }
  private void paintBorderEffect(
      Graphics2D g,
      ClipDetector clipDetector,
      int startOffset,
      int endOffset,
      TextAttributes attributes) {
    if (!clipDetector.rangeCanBeVisible(startOffset, endOffset)) return;
    int startLine = myDocument.getLineNumber(startOffset);
    int endLine = myDocument.getLineNumber(endOffset);
    if (startLine + 1 == endLine
        && startOffset == myDocument.getLineStartOffset(startLine)
        && endOffset == myDocument.getLineStartOffset(endLine)) {
      // special case of line highlighters
      endLine--;
      endOffset = myDocument.getLineEndOffset(endLine);
    }

    boolean rounded = attributes.getEffectType() == EffectType.ROUNDED_BOX;
    int lineHeight = myView.getLineHeight() - 1;
    g.setColor(attributes.getEffectColor());
    VisualPosition startPosition = myView.offsetToVisualPosition(startOffset, true, false);
    VisualPosition endPosition = myView.offsetToVisualPosition(endOffset, false, true);
    if (startPosition.line == endPosition.line) {
      int y = myView.visualLineToY(startPosition.line);
      TFloatArrayList ranges = adjustedLogicalRangeToVisualRanges(startOffset, endOffset);
      for (int i = 0; i < ranges.size() - 1; i += 2) {
        int startX = (int) ranges.get(i);
        int endX = (int) ranges.get(i + 1);
        if (rounded) {
          UIUtil.drawRectPickedOut(g, startX, y, endX - startX, lineHeight);
        } else {
          g.drawRect(startX, y, endX - startX, lineHeight);
        }
      }
    } else {
      int maxWidth = myView.getMaxWidthInLineRange(startPosition.line, endPosition.line) - 1;
      TFloatArrayList leadingRanges =
          adjustedLogicalRangeToVisualRanges(
              startOffset,
              myView.visualPositionToOffset(
                  new VisualPosition(startPosition.line, Integer.MAX_VALUE, true)));
      TFloatArrayList trailingRanges =
          adjustedLogicalRangeToVisualRanges(
              myView.visualPositionToOffset(new VisualPosition(endPosition.line, 0)), endOffset);
      if (!leadingRanges.isEmpty() && !trailingRanges.isEmpty()) {
        boolean containsInnerLines = endPosition.line > startPosition.line + 1;
        int leadingTopY = myView.visualLineToY(startPosition.line);
        int leadingBottomY = leadingTopY + lineHeight;
        int trailingTopY = myView.visualLineToY(endPosition.line);
        int trailingBottomY = trailingTopY + lineHeight;
        float start = 0;
        float end = 0;
        float leftGap = leadingRanges.get(0) - (containsInnerLines ? 0 : trailingRanges.get(0));
        int adjustY =
            leftGap == 0 ? 2 : leftGap > 0 ? 1 : 0; // avoiding 1-pixel gap between aligned lines
        for (int i = 0; i < leadingRanges.size() - 1; i += 2) {
          start = leadingRanges.get(i);
          end = leadingRanges.get(i + 1);
          if (i > 0) {
            drawLine(g, leadingRanges.get(i - 1), leadingBottomY, start, leadingBottomY, rounded);
          }
          drawLine(g, start, leadingBottomY + (i == 0 ? adjustY : 0), start, leadingTopY, rounded);
          if ((i + 2) < leadingRanges.size()) {
            drawLine(g, start, leadingTopY, end, leadingTopY, rounded);
            drawLine(g, end, leadingTopY, end, leadingBottomY, rounded);
          }
        }
        end = Math.max(end, maxWidth);
        drawLine(g, start, leadingTopY, end, leadingTopY, rounded);
        drawLine(g, end, leadingTopY, end, trailingTopY - 1, rounded);
        float targetX = trailingRanges.get(trailingRanges.size() - 1);
        drawLine(g, end, trailingTopY - 1, targetX, trailingTopY - 1, rounded);
        adjustY =
            end == targetX
                ? -2
                : -1; // for lastX == targetX we need to avoid a gap when rounding is used
        for (int i = trailingRanges.size() - 2; i >= 0; i -= 2) {
          start = trailingRanges.get(i);
          end = trailingRanges.get(i + 1);

          drawLine(g, end, trailingTopY + (i == 0 ? adjustY : 0), end, trailingBottomY, rounded);
          drawLine(g, end, trailingBottomY, start, trailingBottomY, rounded);
          drawLine(g, start, trailingBottomY, start, trailingTopY, rounded);
          if (i > 0) {
            drawLine(g, start, trailingTopY, trailingRanges.get(i - 1), trailingTopY, rounded);
          }
        }
        float lastX = start;
        if (containsInnerLines) {
          if (start > 0) {
            drawLine(g, start, trailingTopY, start, trailingTopY - 1, rounded);
            drawLine(g, start, trailingTopY - 1, 0, trailingTopY - 1, rounded);
            drawLine(g, 0, trailingTopY - 1, 0, leadingBottomY + 1, rounded);
          } else {
            drawLine(g, start, trailingTopY, 0, leadingBottomY + 1, rounded);
          }
          lastX = 0;
        }
        targetX = leadingRanges.get(0);
        if (lastX < targetX) {
          drawLine(g, lastX, leadingBottomY + 1, targetX, leadingBottomY + 1, rounded);
        } else {
          drawLine(g, lastX, leadingBottomY + 1, lastX, leadingBottomY, rounded);
          drawLine(g, lastX, leadingBottomY, targetX, leadingBottomY, rounded);
        }
      }
    }
  }
    @Override
    public void paintComponent(final Graphics g) {

      Graphics2D g2d = (Graphics2D) g.create();

      int width = getWidth() - 100;
      int height = getHeight() - 40;

      if (size.equals(BoxSize.MEDIUM)) {
        height -= 196;
        g2d.translate(0, 98);
      } else if (size.equals(BoxSize.LARGE)) {
        height -= 588;
        g2d.translate(0, 294);
      } else if (size.equals(BoxSize.LARGE_SINGLE)) {
        height -= 665;
        g2d.translate(0, 333);
      }

      g2d.setColor(clr1.getColor());
      g2d.setStroke(new BasicStroke(4));

      if (lineSide.equals(LineSide.LEFT) || lineSide.equals(LineSide.BOTH)) {
        g2d.drawLine(0, height / 2 + 20, 47, height / 2 + 20);
      }

      g2d.translate(50, 20);

      if (lineSide.equals(LineSide.RIGHT) || lineSide.equals(LineSide.BOTH)) {
        g2d.drawLine(width, height / 2, width + 65, height / 2);
        if (lineDir.equals(LineDirection.DOWN)) {
          g2d.drawLine(width + 48, height / 2, width + 48, height + 400);
        } else if (lineDir.equals(LineDirection.UP)) {
          g2d.drawLine(width + 48, height / 2, width + 48, -400);
        } else if (lineDir.equals(LineDirection.STRAIGHT)) {
          g2d.drawLine(width, height / 2, width + 45, height / 2);
        }
      }

      FSkin.setGraphicsGradientPaint(g2d, 0, 0, clr3, 0, height / 2 + 15, clr2);
      g2d.fillRect(0, 0, width, height / 2);

      FSkin.setGraphicsGradientPaint(g2d, 0, height / 2 - 15, clr2, 0, height, clr3);
      g2d.fillRect(0, height / 2, width, height / 2);

      g2d.setColor(clr1.getColor());
      g2d.setStroke(new BasicStroke(4));
      g2d.drawRect(1, 1, width - 2, height - 2);

      if (!singleBox) {
        FSkin.setGraphicsGradientPaint(
            g2d, 70, height / 2 - 1, clr1.alphaColor(0), width, height / 2 - 1, clr1);
        g2d.setStroke(new BasicStroke(2));
        g2d.drawRect(70, height / 2 - 1, width - 70, 2);
      }

      g2d.setColor(FSkin.getColor(Colors.CLR_TEXT).getColor());
      g2d.setStroke(new BasicStroke(1));

      if (!singleBox) {
        Rectangle2D textSize = g2d.getFontMetrics().getStringBounds("VS", g2d);
        g2d.drawString(
            "VS",
            (width + (int) textSize.getWidth()) / 2,
            (height + (int) textSize.getHeight()) / 2 - 2);
      }

      // Padding here
      g2d.translate(12, 12);

      g2d.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

      Dimension srcSize = img1.getSizeForPaint(g2d);
      int wSrc = srcSize.width;
      int hSrc = srcSize.height;

      FSkin.drawImage(
          g2d, img1, 0, 0, wImg, hImg, // Destination
          0, 0, wSrc, hSrc); // Source

      g2d.translate(0, 77);

      if (!singleBox) {
        FSkin.drawImage(
            g2d, img2, 0, 0, wImg, hImg, // Destination
            0, 0, wSrc, hSrc); // Source
      }

      g2d.dispose();
    }
Example #28
0
 private void drawRectangle(int x, int y, int width, int height) {
   gRef.drawRect(x, y, width, height);
 }
Example #29
0
  public VolatileImage render() {

    Graphics2D g2d = renderImage.createGraphics();

    try {

      // Draw background layer:
      for (int i = 0; i < backgroundLayer.length; i++) {
        g2d.drawImage(
            backgroundLayer[i],
            -(int) (camera.position.x * Math.pow(0.5, backgroundLayer.length - i)),
            -(int) (camera.position.y * Math.pow(0.5, backgroundLayer.length - i))
                + backgroundLayer[i].getHeight(this)
                - backgroundLayer[i].getHeight(this) / (i + 1),
            this);
      }

    } catch (Exception e) {
    }

    // Draw Tiles: (new)
    try {
      g2d.drawImage(
          tileLayer,
          camera.center.x - camera.position.x,
          camera.center.y - camera.position.y,
          this);
    } catch (Exception e) {
    }

    // Draw all kinds of Sprites:

    try {
      int a = 0;

      while (sprite[a] != null) {
        // Play Animation for sprite:
        if (sprite[a].animation.plays == true) {
          sprite[a].getAnimation().nextFrame();
        }

        // -- Draw sprite:
        g2d.drawImage(
            sprite[a].img,
            /*X1*/ sprite[a].posx
                + ((sprite[a].flipH - 1) / (-2)) * sprite[a].size.width /*camera*/
                - camera.position.x
                + camera.center.x, /*Y1*/
            sprite[a].posy
                + ((sprite[a].flipV - 1) / (-2)) * sprite[a].size.height /*camera*/
                - camera.position.y
                + camera.center.y,
            /*X2*/ sprite[a].posx
                + sprite[a].size.width * sprite[a].flipH
                + ((sprite[a].flipH - 1) / (-2)) * sprite[a].size.width /*camera*/
                - camera.position.x
                + camera.center.x, /*Y2*/
            sprite[a].posy
                + sprite[a].size.height * sprite[a].flipV
                + ((sprite[a].flipV - 1) / (-2)) * sprite[a].size.height /*camera*/
                - camera.position.y
                + camera.center.y, // destination
            sprite[a].getAnimation().col * sprite[a].size.width,
            sprite[a].getAnimation().row * sprite[a].size.height, // source
            (sprite[a].getAnimation().col + 1) * sprite[a].size.width,
            (sprite[a].getAnimation().row + 1) * sprite[a].size.height,
            this);

        a++;
      }
    } catch (Exception e) {
      g2d.drawString("Error drawing a Sprite", 20, 20);
    }

    // Draw "GUI":
    g2d.drawImage(coinSpriteSheet, 16, 16, 32, 32, 0, 0, 16, 16, this);
    g2d.setColor(Color.BLACK);
    g2d.drawString("x " + collectedCoins, 32, 30);
    g2d.setColor(Color.WHITE);
    g2d.drawString("x " + collectedCoins, 32, 29);

    if (showSpritePos == true) {
      for (int i = 0; i < numberOfSprites; i++) {
        g2d.setColor(Color.red);
        g2d.drawRect(
            /*X1*/ sprite[i].posx /*camera*/ - camera.position.x + camera.center.x, /*Y1*/
            sprite[i].posy /*camera*/ - camera.position.y + camera.center.y,
            1,
            1);
        g2d.setColor(Color.black);
      }
    }

    if (showSpriteNum == true) {
      for (int i = 0; i < numberOfSprites; i++) {
        g2d.setColor(Color.black);
        g2d.drawString(
            "" + i, /*X1*/
            sprite[i].posx /*camera*/ - camera.position.x + camera.center.x, /*Y1*/
            sprite[i].posy /*camera*/ - camera.position.y + camera.center.y);
        g2d.setColor(Color.white);
        g2d.drawString(
            "" + i, /*X1*/
            sprite[i].posx /*camera*/ - camera.position.x + camera.center.x, /*Y1*/
            sprite[i].posy /*camera*/ - camera.position.y + camera.center.y - 1);
      }
    }

    if (showSpritePos == true) {
      for (int i = 0; i < numberOfTiles; i++) {
        g2d.setColor(Color.red);
        g2d.drawRect(
            /*X1*/ tile[i].posx
                + ((tile[i].flipH - 1) / (-2)) * tile[i].size.width /*camera*/
                - camera.position.x
                + camera.center.x, /*Y1*/
            tile[i].posy
                + ((tile[i].flipV - 1) / (-2)) * tile[i].size.height /*camera*/
                - camera.position.y
                + camera.center.y,
            1,
            1);
        g2d.setColor(Color.black);
      }
    }

    if (showCamera == true) {
      g2d.setColor(Color.red);
      g2d.drawLine(
          0,
          camera.prefHeight - camera.position.y + camera.center.y,
          loadedLevel.getWidth() * 16,
          camera.prefHeight - camera.position.y + camera.center.y);
      g2d.setColor(new Color(1, 0, 0, 0.33f));
      g2d.fillRect(
          0,
          camera.prefHeight - camera.position.y + camera.tolerance,
          loadedLevel.getWidth() * 16,
          camera.tolerance);
      g2d.setColor(new Color(0, 1, 0, 0.33f));
      g2d.fillRect(
          camera.center.x - camera.position.x + camera.center.x,
          camera.center.y - camera.position.y + camera.center.y,
          camera.bounds.width - 2 * camera.center.x,
          camera.bounds.height);
      g2d.setColor(Color.green);
      g2d.drawLine(
          camera.center.x - camera.position.x + camera.center.x,
          0,
          camera.center.x - camera.position.x + camera.center.x,
          999);
      g2d.drawLine(
          camera.bounds.width - camera.center.x - camera.position.x + camera.center.x,
          0,
          camera.bounds.width - camera.center.x - camera.position.x + camera.center.x,
          999);
    }

    return renderImage;
  }
 public CustomCursor() {
   JFrame frame = new JFrame();
   int[][] cursorImageArray =
       new int[][] {
         {1, 0, 0, 0, 0, 0, 0, 0, 0},
         {1, 1, 0, 0, 0, 0, 0, 0, 0},
         {1, 1, 1, 0, 0, 0, 0, 0, 0},
         {1, 1, 1, 1, 0, 0, 0, 0, 0},
         {1, 1, 1, 1, 1, 0, 0, 0, 0},
         {1, 1, 1, 1, 1, 1, 0, 0, 0},
         {1, 1, 1, 1, 1, 1, 1, 0, 0},
         {1, 1, 1, 1, 1, 1, 1, 1, 0},
         {1, 1, 1, 1, 1, 1, 1, 1, 1},
         {1, 1, 1, 0, 1, 1, 0, 0, 0},
         {1, 1, 0, 0, 1, 1, 0, 0, 0},
         {1, 0, 0, 0, 0, 1, 1, 0, 0},
         {0, 0, 0, 0, 0, 1, 1, 0, 0},
         {0, 0, 0, 0, 0, 0, 1, 1, 0},
         {0, 0, 0, 0, 0, 0, 1, 1, 0},
         {0, 0, 0, 0, 0, 0, 0, 1, 1},
         {0, 0, 0, 0, 0, 0, 0, 1, 1}
       };
   // BufferedImage cursorImageSmall = new BufferedImage(cursorImageArray[0].length,
   // cursorImageArray.length, BufferedImage.TYPE_INT_ARGB);
   System.out.println("" + cursorImageArray[0].length + ", " + cursorImageArray.length);
   System.out.println(
       ""
           + Toolkit.getDefaultToolkit()
               .getBestCursorSize(cursorImageArray[0].length, cursorImageArray.length));
   Dimension bestCursorSize =
       Toolkit.getDefaultToolkit()
           .getBestCursorSize(cursorImageArray[0].length, cursorImageArray.length);
   BufferedImage cursorImage =
       new BufferedImage(bestCursorSize.width, bestCursorSize.height, BufferedImage.TYPE_INT_ARGB);
   Graphics2D graphics2D = (Graphics2D) cursorImage.getGraphics();
   Color transparentColor = new Color(198, 198, 198, 0);
   Color opaqueColor = new Color(255, 0, 0, 255);
   for (int y = 0; y < cursorImageArray.length; y++) {
     for (int x = 0; x < cursorImageArray[0].length; x++) {
       if (cursorImageArray[y][x] == 0) {
         System.out.println("found transparent pixel!");
         // Do nothing, because the background is already transparent
         // You could do this, if you wanted to make a pixel transparent:
         // graphics2D.setComposite(AlphaComposite.Src);
         // graphics2D.setColor(transparentColor);
         // graphics2D.drawRect(x, y, 1, 1);
       } else {
         System.out.println("found opaque pixel!");
         graphics2D.setColor(opaqueColor);
         graphics2D.drawRect(x, y, 1, 1);
       }
     }
   }
   frame.setCursor(
       Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, new Point(0, 0), "MyCursor"));
   JPanel panel = new MyPanel();
   frame.setContentPane(panel);
   frame.setSize(400, 300);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setVisible(true);
 }