예제 #1
0
 /**
  * Erases a given shape's outline on the screen.
  *
  * @param shape the shape object to be erased
  */
 public void eraseOutline(Shape shape) {
   Color original = graphic.getColor();
   graphic.setColor(backgroundColour);
   graphic.draw(shape); // erase by drawing background colour
   graphic.setColor(original);
   canvas.repaint();
 }
예제 #2
0
 public BufferedImage makeTranslucent(BufferedImage source, float alpha) {
   Graphics2D g2d = source.createGraphics();
   g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha));
   g2d.drawImage(source, 0, 0, null);
   g2d.dispose();
   return source;
 }
예제 #3
0
 /** Draws the edge structure of the tree */
 public void drawEdges(Graphics2D gg) {
   gg.setPaint(Color.black);
   Enumeration nodeList = argument.getBreadthFirstTraversal().elements();
   // For each vertex...
   while (nodeList.hasMoreElements()) {
     // Get its edge list...
     TreeVertex vertex = (TreeVertex) nodeList.nextElement();
     Enumeration edges = vertex.getEdgeList().elements();
     // For each edge in the list...
     while (edges.hasMoreElements()) {
       TreeEdge edge = (TreeEdge) edges.nextElement();
       // If we have several vertices on layer 0, only draw
       // edges for layers below that
       if (!(argument.isMultiRoots() && vertex.getLayer() == 0)) {
         // If the edge has been selected with the mouse,
         // use a thick line
         if (edge.isSelected()) {
           gg.setStroke(selectStroke);
         }
         gg.draw(edge.getShape(this));
         // If we used a thick line, reset the stroke to normal
         // line for next edge.
         if (edge.isSelected()) {
           gg.setStroke(solidStroke);
         }
         TreeVertex edgeSource = edge.getDestVertex();
       }
     }
   }
 }
예제 #4
0
  private static Pair<Image, Point> createDragImage(
      final Tree tree, final Component c, Point dragOrigin, boolean adjustToPathUnderDragOrigin) {
    if (c instanceof JComponent) {
      ((JComponent) c).setOpaque(true);
    }

    c.setForeground(tree.getForeground());
    c.setBackground(tree.getBackground());
    c.setFont(tree.getFont());
    c.setSize(c.getPreferredSize());
    final BufferedImage image =
        new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D) image.getGraphics();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
    c.paint(g2);
    g2.dispose();

    Point point = new Point(-image.getWidth(null) / 2, -image.getHeight(null) / 2);

    if (adjustToPathUnderDragOrigin) {
      TreePath path = tree.getPathForLocation(dragOrigin.x, dragOrigin.y);
      if (path != null) {
        Rectangle bounds = tree.getPathBounds(path);
        point = new Point(bounds.x - dragOrigin.x, bounds.y - dragOrigin.y);
      }
    }

    return new Pair<Image, Point>(image, point);
  }
 public static void drawStringUnderlineCharAt(
     JComponent c, Graphics g, String text, int underlinedIndex, int x, int y) {
   Graphics2D g2D = (Graphics2D) g;
   Object savedRenderingHint = null;
   if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
     savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
     g2D.setRenderingHint(
         RenderingHints.KEY_TEXT_ANTIALIASING,
         AbstractLookAndFeel.getTheme().getTextAntiAliasingHint());
   }
   if (getJavaVersion() >= 1.6) {
     try {
       Class swingUtilities2Class = Class.forName("sun.swing.SwingUtilities2");
       Class classParams[] = {
         JComponent.class, Graphics.class, String.class, Integer.TYPE, Integer.TYPE, Integer.TYPE
       };
       Method m = swingUtilities2Class.getMethod("drawStringUnderlineCharAt", classParams);
       Object methodParams[] = {
         c, g, text, new Integer(underlinedIndex), new Integer(x), new Integer(y)
       };
       m.invoke(null, methodParams);
     } catch (Exception ex) {
       BasicGraphicsUtils.drawString(g, text, underlinedIndex, x, y);
     }
   } else if (getJavaVersion() >= 1.4) {
     BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, underlinedIndex, x, y);
   } else {
     BasicGraphicsUtils.drawString(g, text, underlinedIndex, x, y);
   }
   if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
     g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
   }
 }
  private boolean paintPlaceholderText(Graphics2D g) {
    CharSequence hintText = myEditor.getPlaceholder();
    EditorComponentImpl editorComponent = myEditor.getContentComponent();
    if (myDocument.getTextLength() > 0
        || hintText == null
        || hintText.length() == 0
        || KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == editorComponent
            && !myEditor.getShowPlaceholderWhenFocused()) {
      return false;
    }

    hintText =
        SwingUtilities.layoutCompoundLabel(
            g.getFontMetrics(),
            hintText.toString(),
            null,
            0,
            0,
            0,
            0,
            editorComponent.getBounds(),
            new Rectangle(),
            new Rectangle(),
            0);
    g.setColor(myEditor.getFoldingModel().getPlaceholderAttributes().getForegroundColor());
    g.setFont(myEditor.getColorsScheme().getFont(EditorFontType.PLAIN));
    g.drawString(hintText.toString(), 0, myView.getAscent());
    return true;
  }
  /*
   * (non-Javadoc)
   *
   * @seeorg.jvnet.flamingo.common.ui.BasicCommandButtonUI#
   * paintButtonVerticalSeparator(java.awt.Graphics, int)
   */
  @Override
  protected void paintButtonVerticalSeparator(Graphics graphics, Rectangle separatorArea) {
    Graphics2D g2d = (Graphics2D) graphics.create();
    g2d.translate(separatorArea.x, 0);

    SubstanceColorScheme colorScheme =
        SubstanceColorSchemeUtilities.getColorScheme(
            this.commandButton,
            ColorSchemeAssociationKind.SEPARATOR,
            ComponentState.getState(this.commandButton.getActionModel(), this.commandButton));

    float fadeAlpha = this.getSeparatorAlpha();
    g2d.setComposite(AlphaComposite.SrcOver.derive(fadeAlpha));

    SeparatorPainterUtils.paintSeparator(
        this.commandButton,
        g2d,
        colorScheme,
        1,
        this.commandButton.getHeight(),
        JSlider.VERTICAL,
        true,
        4,
        4,
        true);

    g2d.dispose();
  }
예제 #8
0
 // buffered images are just better.
 protected static BufferedImage imageToBufferedImage(Image img) {
   BufferedImage bi =
       new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
   Graphics2D g2 = bi.createGraphics();
   g2.drawImage(img, null, null);
   return bi;
 }
    public synchronized void paint(Graphics g) {
      if (needToStartThread) {
        totalDrawTime = 0;
        counter = 0;
        needToStartThread = false;
        startThread(beginAngle, endAngle);
        if (firstImage == null) {
          firstImage = createImageFromComponent(component1);
        }
        if (secondImage == null) {
          secondImage = createImageFromComponent(component2);
        }
      }
      if (firstImage == null || secondImage == null) return;
      Graphics2D g2d = (Graphics2D) g;
      int ww = firstImage.getWidth();
      int hh = firstImage.getHeight();
      {
        BufferedImage currImage = null;
        int[] currPixels = null;
        int w = firstImage.getWidth();
        int offset = (int) (w * angle / 180);
        if (offset < 0) offset = 0;
        if (offset > w) offset = w;

        long beforeDraw = System.currentTimeMillis();
        g2d.drawImage(firstImage, null, 0, 0);
        g2d.drawImage(secondImage, null, w - offset, 0);
        totalDrawTime += (System.currentTimeMillis() - beforeDraw);
        counter++;
      }
    }
예제 #10
0
    public void paint(Graphics g) {
      Dimension size = getSize();
      Color colors[];
      if (isEnabled()) {
        if (getModel().isArmed() && getModel().isPressed()) {
          colors = BaseLookAndFeel.getTheme().getPressedColors();
        } else if (getModel().isRollover()) {
          colors = BaseLookAndFeel.getTheme().getRolloverColors();
        } else {
          colors = BaseLookAndFeel.getTheme().getButtonColors();
        }
      } else {
        colors = BaseLookAndFeel.getTheme().getDisabledColors();
      }
      Utilities.fillHorGradient(g, colors, 0, 0, size.width, size.height);

      boolean inverse = ColorHelper.getGrayValue(colors) < 128;

      Icon icon = inverse ? BaseIcons.getComboBoxInverseIcon() : BaseIcons.getComboBoxIcon();
      int x = (size.width - icon.getIconWidth()) / 2;
      int y = (size.height - icon.getIconHeight()) / 2;

      Graphics2D g2D = (Graphics2D) g;
      Composite savedComposite = g2D.getComposite();
      g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
      if (getModel().isPressed() && getModel().isArmed()) {
        icon.paintIcon(this, g, x + 2, y + 1);
      } else {
        icon.paintIcon(this, g, x + 1, y);
      }
      g2D.setComposite(savedComposite);
      paintBorder(g2D);
    }
예제 #11
0
파일: Main.java 프로젝트: omusico/bisag-gis
  //	public void savePDF(){
  //		 Rectangle suggestedPageSize = getITextPageSize(page1.getPageSize());
  //		  Rectangle pageSize = rotatePageIfNecessary(suggestedPageSize);
  //		  //rotate if we need landscape
  //		  Document document = new Document(pageSize);
  //
  //		  PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile));
  //		  document.open();
  //		  Graphics2D graphics = cb.createGraphics(pageSize.getWidth(), pageSize.getHeight());
  //
  //		  // call your GTRenderer here
  //		  GTRenderer draw = new StreamingRenderer();
  //		  draw.setMapContent(mapContent);
  //
  //		  draw.paint(graphics, outputArea, mapContent.getLayerBounds() );
  //
  //		  // cleanup
  //		  graphics.dispose();
  //
  //		  //cleanup
  //		  document.close();
  //		  writer.close();
  //	}
  public void saveImage(final MapContent map, final String file, final int imageWidth) {

    GTRenderer renderer = new StreamingRenderer();
    renderer.setMapContent(map);

    Rectangle imageBounds = null;
    ReferencedEnvelope mapBounds = null;
    try {
      mapBounds = map.getMaxBounds();
      double heightToWidth = mapBounds.getSpan(1) / mapBounds.getSpan(0);
      imageBounds = new Rectangle(0, 0, imageWidth, (int) Math.round(imageWidth * heightToWidth));

    } catch (Exception e) {
      // failed to access mapContent layers
      throw new RuntimeException(e);
    }

    BufferedImage image =
        new BufferedImage(imageBounds.width, imageBounds.height, BufferedImage.TYPE_INT_RGB);

    Graphics2D gr = image.createGraphics();
    gr.setPaint(Color.WHITE);
    gr.fill(imageBounds);

    try {
      renderer.paint(gr, imageBounds, mapBounds);
      File fileToSave = new File(file);
      ImageIO.write(image, "jpeg", fileToSave);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  /**
   * All purpose paint method that should do the right thing for all linear bouncing-box progress
   * bars. Override this if you are making another kind of progress bar.
   *
   * @see #paintDeterminate
   * @since 1.4
   */
  protected void paintIndeterminate(Graphics g, JComponent c) {
    if (!(g instanceof Graphics2D)) {
      return;
    }

    Insets b = progressBar.getInsets(); // area for border
    int barRectWidth = progressBar.getWidth() - (b.right + b.left);
    int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);

    if (barRectWidth <= 0 || barRectHeight <= 0) {
      return;
    }

    Graphics2D g2 = (Graphics2D) g;

    // Paint the bouncing box.
    boxRect = getBox(boxRect);
    if (boxRect != null) {
      g2.setColor(progressBar.getForeground());
      g2.fillRect(boxRect.x, boxRect.y, boxRect.width, boxRect.height);
    }

    // Deal with possible text painting
    if (progressBar.isStringPainted()) {
      if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
        paintString(g2, b.left, b.top, barRectWidth, barRectHeight, boxRect.x, boxRect.width, b);
      } else {
        paintString(g2, b.left, b.top, barRectWidth, barRectHeight, boxRect.y, boxRect.height, b);
      }
    }
  }
예제 #13
0
    private BufferedImage createThumbNailImage(Dimension imgSize, ProgressMonitor pm) {
      Assert.notNull(pm, "pm");

      String thumbNailBandName = getThumbnailBandName();
      Band thumbNailBand = product.getBand(thumbNailBandName);

      Debug.trace(
          "ProductSubsetDialog: Reading thumbnail data for band '" + thumbNailBandName + "'...");
      pm.beginTask("Creating thumbnail image", 5);
      BufferedImage image = null;
      try {
        MultiLevelSource multiLevelSource =
            BandImageMultiLevelSource.create(thumbNailBand, SubProgressMonitor.create(pm, 1));
        final ImageLayer imageLayer = new ImageLayer(multiLevelSource);
        final int imageWidth = imgSize.width;
        final int imageHeight = imgSize.height;
        final int imageType = BufferedImage.TYPE_3BYTE_BGR;
        image = new BufferedImage(imageWidth, imageHeight, imageType);
        Viewport snapshotVp = new DefaultViewport(isModelYAxisDown(imageLayer));
        final BufferedImageRendering imageRendering = new BufferedImageRendering(image, snapshotVp);

        final Graphics2D graphics = imageRendering.getGraphics();
        graphics.setColor(getBackground());
        graphics.fillRect(0, 0, imageWidth, imageHeight);

        snapshotVp.zoom(imageLayer.getModelBounds());
        snapshotVp.moveViewDelta(snapshotVp.getViewBounds().x, snapshotVp.getViewBounds().y);
        imageLayer.render(imageRendering);

        pm.worked(4);
      } finally {
        pm.done();
      }
      return image;
    }
예제 #14
0
 /**
  * Erases a String on the Canvas.
  *
  * @param text the String to be displayed
  * @param x x co-ordinate for text placement
  * @param y y co-ordinate for text placement
  */
 public void eraseString(String text, int x, int y) {
   Color original = graphic.getColor();
   graphic.setColor(backgroundColour);
   graphic.drawString(text, x, y);
   graphic.setColor(original);
   canvas.repaint();
 }
예제 #15
0
 void drawLine(Graphics g, DrawObject L) {
   if (L == null) {
     return;
   }
   if ((sequencingOn) && (L.sequenceNum != currentSequenceNumDisplay)) {
     return;
   }
   Graphics2D g2 = (Graphics2D) g;
   g2.setStroke(L.drawStroke);
   int x1 = (int) ((L.x - minX) / (maxX - minX) * (D.width - 2 * inset));
   int y1 = (int) ((L.y - minY) / (maxY - minY) * (D.height - 2.0 * inset));
   int x2 = (int) ((L.x2 - minX) / (maxX - minX) * (D.width - 2 * inset));
   int y2 = (int) ((L.y2 - minY) / (maxY - minY) * (D.height - 2.0 * inset));
   if (L.isArrow) {
     drawArrow(
         (Graphics2D) g,
         inset + x1,
         D.height - y1 - inset,
         inset + x2,
         D.height - y2 - inset,
         1.0f,
         L.drawStroke);
   } else {
     g.drawLine(inset + x1, D.height - y1 - inset, inset + x2, D.height - y2 - inset);
   }
 }
예제 #16
0
  protected void paintComponent(Graphics g2) {
    super.paintComponent(g2);

    Graphics2D g = (Graphics2D) g2;
    test.draw(g2, 0, 0);
    // Shape triangle = new Polygon(new int[] {15, 20, 10}, new int[] {0, 10, 10}, 3);

    Shape square = new Rectangle2D.Double(0, 0, 30, 30);

    g.setColor(Color.white);

    g.translate(20, 20);
    // g.rotate(theta, 10, 10);
    // g.fill(star);

    // g.setColor(new Color(0, 86, 141));
    // g.fill(square);
    if (star2 != null) g.fill(star2);

    // Graphics2D g3 = (Graphics2D) g;
    // 3.fill(star);

    // g.setStroke(new BasicStroke(1));
    // g.translate(x, y);
    // g.draw(line);
    // g.draw(line2);

  }
예제 #17
0
  // From: http://forum.java.sun.com/thread.jspa?threadID=378460&tstart=135
  void drawArrow(
      Graphics2D g2d,
      int xCenter,
      int yCenter,
      int x,
      int y,
      float stroke,
      BasicStroke drawStroke) {
    double aDir = Math.atan2(xCenter - x, yCenter - y);
    // Line can be dashed.
    g2d.setStroke(drawStroke);
    g2d.drawLine(x, y, xCenter, yCenter);
    // make the arrow head solid even if dash pattern has been specified
    g2d.setStroke(lineStroke);
    Polygon tmpPoly = new Polygon();
    int i1 = 12 + (int) (stroke * 2);
    // make the arrow head the same size regardless of the length length
    int i2 = 6 + (int) stroke;
    tmpPoly.addPoint(x, y);
    tmpPoly.addPoint(x + xCor(i1, aDir + .5), y + yCor(i1, aDir + .5));
    tmpPoly.addPoint(x + xCor(i2, aDir), y + yCor(i2, aDir));
    tmpPoly.addPoint(x + xCor(i1, aDir - .5), y + yCor(i1, aDir - .5));
    tmpPoly.addPoint(x, y); // arrow tip
    g2d.drawPolygon(tmpPoly);

    // Remove this line to leave arrow head unpainted:
    g2d.fillPolygon(tmpPoly);
  }
 public void paint(Graphics g) {
   Graphics2D g_2d = (Graphics2D) g;
   Ellipse2D ellipse = new Ellipse2D.Double(0, 2, 80, 80);
   Rectangle2D rect = new Rectangle2D.Double(40, 2, 80, 80);
   Area a1 = new Area(ellipse);
   Area a2 = new Area(rect);
   a1.intersect(a2); // "Óë"
   g_2d.fill(a1);
   ellipse.setFrame(130, 2, 80, 80);
   rect.setFrame(170, 2, 80, 80);
   a1 = new Area(ellipse);
   a2 = new Area(rect);
   a1.add(a2); // "»ò"
   g_2d.draw(a1);
   ellipse.setFrame(0, 90, 80, 80);
   rect.setFrame(40, 90, 80, 80);
   a1 = new Area(ellipse);
   a2 = new Area(rect);
   a1.subtract(a2); // "²î"
   g_2d.draw(a1);
   ellipse.setFrame(130, 90, 80, 80);
   rect.setFrame(170, 90, 80, 80);
   a1 = new Area(ellipse);
   a2 = new Area(rect);
   a1.exclusiveOr(a2); // "Òì»ò"
   g_2d.fill(a1);
 }
예제 #19
0
 /** Erase the whole canvas. (Does not repaint.) */
 private void erase() {
   Color original = graphic.getColor();
   graphic.setColor(backgroundColor);
   Dimension size = canvas.getSize();
   graphic.fill(new Rectangle(0, 0, size.width, size.height));
   graphic.setColor(original);
 }
예제 #20
0
 public void paintThumb(Graphics g) {
   Icon icon = null;
   if (slider.getOrientation() == JSlider.HORIZONTAL) {
     if (isRollover && slider.isEnabled()) {
       icon = getThumbHorIconRollover();
     } else {
       icon = getThumbHorIcon();
     }
   } else {
     if (isRollover && slider.isEnabled()) {
       icon = getThumbVerIconRollover();
     } else {
       icon = getThumbVerIcon();
     }
   }
   Graphics2D g2D = (Graphics2D) g;
   Composite savedComposite = g2D.getComposite();
   if (!slider.isEnabled()) {
     g.setColor(AbstractLookAndFeel.getBackgroundColor());
     g.fillRect(thumbRect.x + 1, thumbRect.y + 1, thumbRect.width - 2, thumbRect.height - 2);
     AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
     g2D.setComposite(alpha);
   }
   icon.paintIcon(null, g, thumbRect.x, thumbRect.y);
   g2D.setComposite(savedComposite);
 }
예제 #21
0
 @Override
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   if (moveThread != null) {
     if (moveThread.isRunning()) {
       Point2D p = moveThread.getCurrentPosition();
       currentDirection = moveThread.getDirection();
       this.setBounds((int) p.getX() - 32, (int) p.getY() - 32, 96, 64);
     } else {
       if (currentDirection == HeroDirection.MOVING_BACK) {
         currentDirection = HeroDirection.IDLE_BACK;
       } else if (currentDirection == HeroDirection.MOVING_FRONT) {
         currentDirection = HeroDirection.IDLE_FRONT;
       } else if (currentDirection == HeroDirection.MOVING_LEFT) {
         currentDirection = HeroDirection.IDLE_LEFT;
       } else if (currentDirection == HeroDirection.MOVING_RIGHT) {
         currentDirection = HeroDirection.IDLE_RIGHT;
       }
       moveThread = null;
       isMoveFinished = true;
     }
   }
   g2.drawImage(animation.getCurrentFrame(currentDirection), 0, 0, null);
 }
예제 #22
0
  /**
   * Returns the specified image as icon.
   *
   * @param name name of icon
   * @return icon
   */
  public static ImageIcon icon(final String name) {
    ImageIcon ii = ICONS.get(name);
    if (ii != null) return ii;

    Image img;
    if (GUIConstants.scale > 1) {
      // choose large image or none
      final URL url =
          GUIConstants.large() ? BaseXImages.class.getResource("/img/" + name + "_32.png") : null;

      if (url == null) {
        // resize low-res image if no hi-res image exists
        img = get(url(name));
        final int w = (int) (img.getWidth(null) * GUIConstants.scale);
        final int h = (int) (img.getHeight(null) * GUIConstants.scale);
        final BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        final Graphics2D g2 = tmp.createGraphics();
        g2.setRenderingHint(
            RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2.drawImage(img, 0, 0, w, h, null);
        g2.dispose();
        img = tmp;
      } else {
        img = get(url);
      }
    } else {
      img = get(name);
    }
    ii = new ImageIcon(img);
    ICONS.put(name, ii);
    return ii;
  }
예제 #23
0
 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
   if (((JToolBar) c).isFloatable()) {
     Graphics2D g2D = (Graphics2D) g;
     Composite savedComposite = g2D.getComposite();
     AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
     g2D.setComposite(alpha);
     if (((JToolBar) c).getOrientation() == HORIZONTAL) {
       if (!JTattooUtilities.isLeftToRight(c)) {
         x += w - 15;
       }
       g.setColor(Color.white);
       g.drawLine(x + 3, y + 4, x + 3, h - 5);
       g.drawLine(x + 6, y + 3, x + 6, h - 4);
       g.drawLine(x + 9, y + 4, x + 9, h - 5);
       g.setColor(shadow);
       g.drawLine(x + 4, y + 4, x + 4, h - 5);
       g.drawLine(x + 7, y + 3, x + 7, h - 4);
       g.drawLine(x + 10, y + 4, x + 10, h - 5);
     } else {
       // vertical
       g.setColor(Color.white);
       g.drawLine(x + 3, y + 3, w - 4, y + 3);
       g.drawLine(x + 3, y + 6, w - 4, y + 6);
       g.drawLine(x + 3, y + 9, w - 4, y + 9);
       g.setColor(shadow);
       g.drawLine(x + 3, y + 4, w - 4, y + 4);
       g.drawLine(x + 3, y + 7, w - 4, y + 7);
       g.drawLine(x + 3, y + 10, w - 4, y + 10);
     }
     g2D.setComposite(savedComposite);
   }
 }
    @Override
    public void paint(Graphics2D g2, State s, float cWidth, float cHeight) {

      float domainXScale = this.dwidth;
      float domainYScale = this.dheight;

      // determine then normalized width
      float width = (1.0f / domainXScale) * cWidth;
      float height = (1.0f / domainYScale) * cHeight;

      // pass through each cell of the map and if it is a wall, draw it
      for (int i = 0; i < this.dwidth; i++) {
        for (int j = 0; j < this.dheight; j++) {

          if (this.map[i][j] > 0) {

            float rx = i * width;
            float ry = cHeight - height - j * height;

            // draw the walls; make them black
            g2.setColor(this.cols[this.map[i][j] - 1]);

            g2.fill(new Rectangle2D.Float(rx, ry, width, height));
          }
        }
      }
    }
    @Override
    public void paintIcon(final Component component, final Graphics g, final int i, final int j) {
      final int iconWidth = getIconWidth();
      final int iconHeight = getIconHeight();
      if (myColor != null) {
        g.setColor(myColor);
        g.fillRect(i, j, iconWidth, iconHeight);
      } else if (myColours != null) {
        final Color top = myColours[0];
        g.setColor(top);
        g.fillRect(i, j, iconWidth, 2);

        final Color right = myColours[1];
        g.setColor(right);
        g.fillRect(i + iconWidth / 2, j + 2, iconWidth / 2, iconHeight / 2);

        final Color bottom = myColours[2];
        g.setColor(bottom);
        g.fillRect(i, j + iconHeight - 2, iconWidth, 2);

        final Color left = myColours[3];
        g.setColor(left);
        g.fillRect(i, j + 2, iconWidth / 2, iconHeight / 2);
      }

      final Composite old = ((Graphics2D) g).getComposite();
      ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
      g.setColor(Color.BLACK);
      g.drawRect(i, j, iconWidth - 1, iconHeight - 1);
      ((Graphics2D) g).setComposite(old);
    }
예제 #26
0
 /**
  * Write the given text string in the current font, centered on (x, y) and rotated by the
  * specified number of degrees
  *
  * @param x the center x-coordinate of the text
  * @param y the center y-coordinate of the text
  * @param s the text
  * @param degrees is the number of degrees to rotate counterclockwise
  */
 public static void text(double x, double y, String s, double degrees) {
   double xs = scaleX(x);
   double ys = scaleY(y);
   offscreen.rotate(Math.toRadians(-degrees), xs, ys);
   text(x, y, s);
   offscreen.rotate(Math.toRadians(+degrees), xs, ys);
 }
예제 #27
0
 protected void paintBackground(Graphics g, JComponent c, int x, int y, int w, int h) {
   JMenuItem b = (JMenuItem) c;
   ButtonModel model = b.getModel();
   if (c.getParent() instanceof JMenuBar) {
     if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
       g.setColor(AbstractLookAndFeel.getMenuSelectionBackgroundColor());
       g.fillRect(x, y, w, h);
     }
   } else {
     if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
       g.setColor(AbstractLookAndFeel.getMenuSelectionBackgroundColor());
       g.fillRect(x, y, w, h);
     } else if (!AbstractLookAndFeel.getTheme().isMenuOpaque()) {
       Graphics2D g2D = (Graphics2D) g;
       Composite composite = g2D.getComposite();
       AlphaComposite alpha =
           AlphaComposite.getInstance(
               AlphaComposite.SRC_OVER, AbstractLookAndFeel.getTheme().getMenuAlpha());
       g2D.setComposite(alpha);
       g.setColor(AbstractLookAndFeel.getMenuBackgroundColor());
       g.fillRect(x, y, w, h);
       g2D.setComposite(composite);
     } else {
       g.setColor(AbstractLookAndFeel.getMenuBackgroundColor());
       g.fillRect(x, y, w, h);
     }
   }
   if (menuItem.isSelected() && menuItem.isArmed()) {
     g.setColor(AbstractLookAndFeel.getMenuSelectionForegroundColor());
   } else {
     g.setColor(AbstractLookAndFeel.getMenuForegroundColor());
   }
 }
예제 #28
0
  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);
    }
  }
예제 #29
0
 public void drawTo(Graphics g, Line line) {
   if (!calc.tileOnMap(t1) || !calc.tileOnMap(t2)) return;
   if (calc.tileOnMap(line.getTile1()) && calc.tileOnMap(line.getTile2())) {
     Point p1 = calc.tileToMinimap(t1);
     Point p2 = calc.tileToMinimap(t2);
     Point p3 = calc.tileToMinimap(line.getTile2());
     Point p4 = calc.tileToMinimap(line.getTile1());
     GeneralPath path = new GeneralPath();
     path.moveTo(p1.x, p1.y);
     path.lineTo(p2.x, p2.y);
     path.lineTo(p3.x, p3.y);
     path.lineTo(p4.x, p4.y);
     path.closePath();
     g.setColor(POLY_FILL);
     ((Graphics2D) g).fill(path);
     ((Graphics2D) g).draw(path);
   }
   Point last = null, p;
   g.setColor(Color.ORANGE);
   for (RSTile t : pathList) {
     if (calc.tileOnMap(t)) {
       p = calc.tileToMinimap(t);
       g.fillOval(p.x - 2, p.y - 2, 5, 5);
       if (last != null) g.drawLine(p.x, p.y, last.x, last.y);
       last = p;
     } else last = null;
   }
 }
예제 #30
-2
 private void paintTextEffect(
     Graphics2D g, float xFrom, float xTo, int y, Color effectColor, EffectType effectType) {
   int xStart = (int) xFrom;
   int xEnd = (int) xTo;
   g.setColor(effectColor);
   if (effectType == EffectType.LINE_UNDERSCORE) {
     UIUtil.drawLine(g, xStart, y + 1, xEnd, y + 1);
   } else if (effectType == EffectType.BOLD_LINE_UNDERSCORE) {
     int height = JBUI.scale(Registry.intValue("editor.bold.underline.height", 2));
     g.fillRect(xStart, y, xEnd - xStart, height);
   } else if (effectType == EffectType.STRIKEOUT) {
     int y1 = y - myView.getCharHeight() / 2;
     UIUtil.drawLine(g, xStart, y1, xEnd, y1);
   } else if (effectType == EffectType.WAVE_UNDERSCORE) {
     UIUtil.drawWave(g, new Rectangle(xStart, y + 1, xEnd - xStart, myView.getDescent() - 1));
   } else if (effectType == EffectType.BOLD_DOTTED_LINE) {
     UIUtil.drawBoldDottedLine(
         g,
         xStart,
         xEnd,
         SystemInfo.isMac ? y : y + 1,
         myEditor.getBackgroundColor(),
         g.getColor(),
         false);
   }
 }