예제 #1
0
  @Override
  protected BufferedImage renderOffscreen() {
    BufferedImage bimage = null;

    if (getOrientation() == SwingConstants.HORIZONTAL) {

      bimage = new BufferedImage(DEFAULT_WIDTH, 10, BufferedImage.TYPE_4BYTE_ABGR);
      Graphics2D g2d = bimage.createGraphics();
      int ncolors = colorMap.getMapSize();
      double distance = colorMap.getMaximumValue() - colorMap.getMinimumValue();

      double start = colorMap.getMinimumValue();

      for (int i = 0; i < ncolors; i++) {
        ColorInterval ci = colorMap.getInterval(i);
        double size = ((ci.getMaximum() - ci.getMinimum()) / distance);
        double xpos = (ci.getMinimum() - start) / distance;

        Rectangle2D rect =
            new Rectangle2D.Double(xpos * DEFAULT_WIDTH, 0, size * DEFAULT_WIDTH, 10);
        float trans = (float) ci.getAlpha();

        AlphaComposite comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, trans / 255f);

        g2d.setComposite(comp);
        g2d.setPaint(ci.getColor());
        g2d.fill(rect);
      }
    } else {
      bimage = new BufferedImage(10, DEFAULT_HEIGHT, BufferedImage.TYPE_4BYTE_ABGR);
      int ncolors = colorMap.getMapSize();
      double distance = colorMap.getMaximumValue() - colorMap.getMinimumValue();
      double start = colorMap.getMinimumValue();

      Graphics2D g2d = bimage.createGraphics();
      for (int i = 0; i < ncolors; i++) {
        ColorInterval ci = colorMap.getInterval(i);
        double size = ((ci.getMaximum() - ci.getMinimum()) / distance);
        double ypos = (ci.getMinimum() - start) / distance;

        Rectangle2D rect =
            new Rectangle2D.Double(0, ypos * DEFAULT_HEIGHT, 10, size * DEFAULT_HEIGHT);
        float trans = (float) ci.getAlpha();

        AlphaComposite comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, trans / 255f);

        g2d.setComposite(comp);
        g2d.setPaint(ci.getColor());
        g2d.fill(rect);
      }
    }

    cachedImage = bimage;
    return cachedImage;
  }
예제 #2
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);
  }
예제 #3
0
    @Override
    protected void paintComponent(Graphics g) {
      Graphics2D g2d = (Graphics2D) g;

      final Dimension size = getSize();
      int _size = Math.min(size.width, size.height);
      _size = Math.min(_size, 600);

      if (myImage != null && myShouldInvalidate) {
        if (myImage.getWidth(null) != _size) {
          myImage = null;
        }
      }

      myShouldInvalidate = false;

      if (myImage == null) {
        myImage =
            createImage(
                new ColorWheelImageProducer(
                    _size - BORDER_SIZE * 2, _size - BORDER_SIZE * 2, myBrightness));
        myWheel =
            new Rectangle(
                BORDER_SIZE, BORDER_SIZE, _size - BORDER_SIZE * 2, _size - BORDER_SIZE * 2);
      }

      g.setColor(UIManager.getColor("Panel.background"));
      g.fillRect(0, 0, getWidth(), getHeight());

      g2d.setComposite(
          AlphaComposite.getInstance(AlphaComposite.SRC_OVER, ((float) myOpacity) / 255f));
      g.drawImage(myImage, myWheel.x, myWheel.y, null);

      g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, 1.0f));

      int mx = myWheel.x + myWheel.width / 2;
      int my = myWheel.y + myWheel.height / 2;
      //noinspection UseJBColor
      g.setColor(Color.WHITE);
      int arcw = (int) (myWheel.width * mySaturation / 2);
      int arch = (int) (myWheel.height * mySaturation / 2);
      double th = myHue * 2 * Math.PI;
      final int x = (int) (mx + arcw * Math.cos(th));
      final int y = (int) (my - arch * Math.sin(th));
      g.fillRect(x - 2, y - 2, 4, 4);
      //noinspection UseJBColor
      g.setColor(Color.BLACK);
      g.drawRect(x - 2, y - 2, 4, 4);
    }
  /** 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);
    }
  }
예제 #5
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);
  }
예제 #6
0
 @Override
 public void paint(Graphics g) {
   if (!myLookup.isFocused() && myLookup.isCompletion()) {
     ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f));
   }
   super.paint(g);
 }
예제 #7
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());
   }
 }
예제 #8
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;
 }
    @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);
    }
예제 #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
 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);
   }
 }
예제 #12
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);
 }
예제 #13
0
 public void paint(Graphics g) {
   Graphics2D g2d = (Graphics2D) g;
   Composite oldComp = g2d.getComposite();
   Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
   g2d.setComposite(alphaComp);
   super.paint(g2d);
   g2d.setComposite(oldComp);
 }
예제 #14
0
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      AbstractButton button = (AbstractButton) c;
      ButtonModel model = button.getModel();
      if (model.isEnabled()) {
        if ((model.isPressed() && model.isArmed()) || model.isSelected()) {
          Color frameColor =
              ColorHelper.darker(AbstractLookAndFeel.getToolbarBackgroundColor(), 30);
          g.setColor(frameColor);
          g.drawRect(x, y, w - 1, h - 1);

          Graphics2D g2D = (Graphics2D) g;
          Composite composite = g2D.getComposite();
          AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f);
          g2D.setComposite(alpha);
          g.setColor(Color.black);
          g.fillRect(x + 1, y + 1, w - 2, h - 2);
          g2D.setComposite(composite);
        } else if (model.isRollover()) {
          Color frameColor = AbstractLookAndFeel.getToolbarBackgroundColor();
          Color frameHiColor = ColorHelper.darker(frameColor, 5);
          Color frameLoColor = ColorHelper.darker(frameColor, 20);
          JTattooUtilities.draw3DBorder(g, frameHiColor, frameLoColor, x, y, w, h);
          frameHiColor = Color.white;
          frameLoColor = ColorHelper.brighter(frameLoColor, 60);
          JTattooUtilities.draw3DBorder(g, frameHiColor, frameLoColor, x + 1, y + 1, w - 2, h - 2);

          Graphics2D g2D = (Graphics2D) g;
          Composite composite = g2D.getComposite();
          AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f);
          g2D.setComposite(alpha);
          g.setColor(Color.white);
          g.fillRect(x + 2, y + 2, w - 4, h - 4);
          g2D.setComposite(composite);

          g.setColor(AbstractLookAndFeel.getFocusColor());
          g.drawLine(x + 1, y + 1, x + w - 1, y + 1);
          g.drawLine(x + 1, y + 2, x + w - 2, y + 2);
        } else if (model.isSelected()) {
          Color frameColor = AbstractLookAndFeel.getToolbarBackgroundColor();
          Color frameHiColor = Color.white;
          Color frameLoColor = ColorHelper.darker(frameColor, 30);
          JTattooUtilities.draw3DBorder(g, frameLoColor, frameHiColor, x, y, w, h);
        }
      }
    }
예제 #15
0
 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
   Graphics2D g2D = (Graphics2D) g;
   Composite savedComposite = g2D.getComposite();
   AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f);
   g2D.setComposite(alpha);
   Color cHi = AbstractLookAndFeel.getTheme().getControlHighlightColor();
   Color cLo = AbstractLookAndFeel.getTheme().getControlShadowColor();
   JTattooUtilities.draw3DBorder(g, cHi, cLo, x, y, w, h);
   g2D.setComposite(savedComposite);
 }
    public static Image createImage(final JTable table, int column) {
      final int height =
          Math.max(20, Math.min(100, table.getSelectedRowCount() * table.getRowHeight()));
      final int width = table.getColumnModel().getColumn(column).getWidth();

      final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g2 = (Graphics2D) image.getGraphics();

      g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));

      drawSelection(table, column, g2, width);
      return image;
    }
예제 #17
0
  @Override
  protected void paintComponent(Graphics g1) {

    Graphics2D g = (Graphics2D) g1;

    // Always use black even for light themes
    g.setPaint(Color.BLACK);

    // Set the opacity
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));

    // Create the darkened border rectangle (will appear beneath the panel layer)
    g.fillRect(0, 0, getWidth(), getHeight());
  }
    public static Image createImage(final JTree tree) {
      final TreeSelectionModel model = tree.getSelectionModel();
      final TreePath[] paths = model.getSelectionPaths();

      int count = 0;
      final List<ChangesBrowserNode> nodes = new ArrayList<ChangesBrowserNode>();
      for (final TreePath path : paths) {
        final ChangesBrowserNode node = (ChangesBrowserNode) path.getLastPathComponent();
        if (!node.isLeaf()) {
          nodes.add(node);
          count += node.getCount();
        }
      }

      for (TreePath path : paths) {
        final ChangesBrowserNode element = (ChangesBrowserNode) path.getLastPathComponent();
        boolean child = false;
        for (final ChangesBrowserNode node : nodes) {
          if (node.isNodeChild(element)) {
            child = true;
            break;
          }
        }

        if (!child) {
          if (element.isLeaf()) count++;
        } else if (!element.isLeaf()) {
          count -= element.getCount();
        }
      }

      final JLabel label = new JLabel(VcsBundle.message("changes.view.dnd.label", count));
      label.setOpaque(true);
      label.setForeground(tree.getForeground());
      label.setBackground(tree.getBackground());
      label.setFont(tree.getFont());
      label.setSize(label.getPreferredSize());
      final BufferedImage image =
          new BufferedImage(label.getWidth(), label.getHeight(), BufferedImage.TYPE_INT_ARGB);

      Graphics2D g2 = (Graphics2D) image.getGraphics();
      g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
      label.paint(g2);
      g2.dispose();

      return image;
    }
예제 #19
0
 @Override
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Graphics2D g2 = (Graphics2D) g.create();
   g2.setPaint(Objects.nonNull(c) ? c.getBackground() : Color.WHITE);
   g2.fillRect(x, y, getIconWidth(), getIconHeight());
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   g2.setColor(ELLIPSE_COLOR);
   g2.translate(x, y);
   int size = list.size();
   for (int i = 0; i < size; i++) {
     float alpha = isRunning ? (i + 1) / (float) size : .5f;
     g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
     g2.fill(list.get(i));
   }
   // g2.translate(-x, -y);
   g2.dispose();
 }
예제 #20
0
 public void paint(Graphics g) {
   Graphics2D g2d = (Graphics2D) g;
   graphics.drawImage(
       screen,
       0,
       0,
       getWidth(),
       getHeight(),
       getX(),
       getY(),
       getX() + getWidth(),
       getY() + getHeight(),
       null);
   Composite c = g2d.getComposite();
   graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.75f));
   graphics.drawImage(image, 0, 0, null);
   graphics.setComposite(c);
   g2d.drawImage(buffer, 0, 0, null);
 }
예제 #21
0
  @Override
  public void draw(Graphics2D g) {
    double opacity = get(OPACITY);
    opacity = Math.min(Math.max(0d, opacity), 1d);
    if (opacity != 0d) {
      if (opacity != 1d) {
        Rectangle2D.Double drawingArea = getDrawingArea();

        Rectangle2D clipBounds = g.getClipBounds();
        if (clipBounds != null) {
          Rectangle2D.intersect(drawingArea, clipBounds, drawingArea);
        }

        if (!drawingArea.isEmpty()) {

          BufferedImage buf =
              new BufferedImage(
                  (int) ((2 + drawingArea.width) * g.getTransform().getScaleX()),
                  (int) ((2 + drawingArea.height) * g.getTransform().getScaleY()),
                  BufferedImage.TYPE_INT_ARGB);
          Graphics2D gr = buf.createGraphics();
          gr.scale(g.getTransform().getScaleX(), g.getTransform().getScaleY());
          gr.translate((int) -drawingArea.x, (int) -drawingArea.y);
          gr.setRenderingHints(g.getRenderingHints());
          drawFigure(gr);
          gr.dispose();
          Composite savedComposite = g.getComposite();
          g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) opacity));
          g.drawImage(
              buf,
              (int) drawingArea.x,
              (int) drawingArea.y,
              2 + (int) drawingArea.width,
              2 + (int) drawingArea.height,
              null);
          g.setComposite(savedComposite);
        }
      } else {
        drawFigure(g);
      }
    }
  }
예제 #22
0
  protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) {
    ButtonModel model = b.getModel();
    FontMetrics fm = JTattooUtilities.getFontMetrics(b, g, b.getFont());
    int mnemIndex;
    if (JTattooUtilities.getJavaVersion() >= 1.4) {
      mnemIndex = b.getDisplayedMnemonicIndex();
    } else {
      mnemIndex = JTattooUtilities.findDisplayedMnemonicIndex(b.getText(), model.getMnemonic());
    }
    int offs = 0;
    if (model.isArmed() && model.isPressed()) {
      offs = 1;
    }

    Graphics2D g2D = (Graphics2D) g;
    Composite composite = g2D.getComposite();
    AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
    g2D.setComposite(alpha);
    Color foreground = b.getForeground();
    Color background = b.getBackground();
    if (background instanceof ColorUIResource) {
      if (model.isPressed() && model.isArmed()) {
        foreground = AbstractLookAndFeel.getTheme().getSelectionForegroundColor();
      } else if (model.isRollover()) {
        foreground = AbstractLookAndFeel.getTheme().getRolloverForegroundColor();
      }
    }
    if (!model.isEnabled()) {
      foreground = AbstractLookAndFeel.getTheme().getDisabledForegroundColor();
    }
    if (ColorHelper.getGrayValue(foreground) > 64) {
      g2D.setColor(Color.black);
    } else {
      g2D.setColor(Color.white);
    }
    JTattooUtilities.drawStringUnderlineCharAt(
        b, g, text, mnemIndex, textRect.x + offs + 1, textRect.y + offs + fm.getAscent() + 1);
    g2D.setComposite(composite);
    g2D.setColor(foreground);
    JTattooUtilities.drawStringUnderlineCharAt(
        b, g, text, mnemIndex, textRect.x + offs, textRect.y + offs + fm.getAscent());
  }
  // Takes resource name and returns button
  public JButton createButton(String name, String toolTip) {

    // load the image
    String imagePath = "./resources/" + name + ".png";
    ImageIcon iconRollover = new ImageIcon(imagePath);
    int w = iconRollover.getIconWidth();
    int h = iconRollover.getIconHeight();

    // get the cursor for this button
    Cursor cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);

    // make translucent default image
    Image image = createCompatibleImage(w, h, Transparency.TRANSLUCENT);
    Graphics2D g = (Graphics2D) image.getGraphics();
    Composite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f);
    g.setComposite(alpha);
    g.drawImage(iconRollover.getImage(), 0, 0, null);
    g.dispose();
    ImageIcon iconDefault = new ImageIcon(image);

    // make a pressed image
    image = createCompatibleImage(w, h, Transparency.TRANSLUCENT);
    g = (Graphics2D) image.getGraphics();
    g.drawImage(iconRollover.getImage(), 2, 2, null);
    g.dispose();
    ImageIcon iconPressed = new ImageIcon(image);

    // create the button
    JButton button = new JButton();
    button.addActionListener(this);
    button.setIgnoreRepaint(true);
    button.setFocusable(false);
    button.setToolTipText(toolTip);
    button.setBorder(null);
    button.setContentAreaFilled(false);
    button.setCursor(cursor);
    button.setIcon(iconDefault);
    button.setRolloverIcon(iconRollover);
    button.setPressedIcon(iconPressed);

    return button;
  }
예제 #24
0
  private void paintSelection(Graphics2D g) {
    int selectionStartOffset = editor.getSelectionModel().getSelectionStart();
    int selectionEndOffset = editor.getSelectionModel().getSelectionEnd();
    int firstSelectedLine = coords.offsetToScreenSpace(selectionStartOffset);
    int firstSelectedCharacter = coords.offsetToCharacterInLine(selectionStartOffset);
    int lastSelectedLine = coords.offsetToScreenSpace(selectionEndOffset);
    int lastSelectedCharacter = coords.offsetToCharacterInLine(selectionEndOffset);

    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.90f));
    g.setColor(
        editor
            .getColorsScheme()
            .getColor(ColorKey.createColorKey("SELECTION_BACKGROUND", JBColor.BLUE)));

    if (firstSelectedLine == lastSelectedLine) {
      // Single line is easy
      g.fillRect(
          firstSelectedCharacter,
          firstSelectedLine,
          lastSelectedCharacter - firstSelectedCharacter,
          config.pixelsPerLine);
    } else {
      // Draw the line leading in
      g.fillRect(
          firstSelectedCharacter,
          firstSelectedLine,
          getWidth() - firstSelectedCharacter,
          config.pixelsPerLine);

      // Then the line at the end
      g.fillRect(0, lastSelectedLine, lastSelectedCharacter, config.pixelsPerLine);

      if (firstSelectedLine + 1 != lastSelectedLine) {
        // And if there is anything in between, fill it in
        g.fillRect(
            0,
            firstSelectedLine + config.pixelsPerLine,
            getWidth(),
            lastSelectedLine - firstSelectedLine - config.pixelsPerLine);
      }
    }
  }
예제 #25
0
    private void updatePipette() {
      Dialog pickerDialog = getPickerDialog();
      if (pickerDialog != null && pickerDialog.isShowing()) {
        Point mouseLoc = updateLocation();
        if (mouseLoc == null) return;
        final Color c = getPixelColor(mouseLoc);
        if (!c.equals(getColor()) || !mouseLoc.equals(myPreviousLocation)) {
          setColor(c);
          myPreviousLocation.setLocation(mouseLoc);
          myCaptureRect.setBounds(
              mouseLoc.x - HOT_SPOT.x + SIZE / 2 - 2, mouseLoc.y - HOT_SPOT.y + SIZE / 2 - 2, 5, 5);

          BufferedImage capture = myRobot.createScreenCapture(myCaptureRect);

          // Clear the cursor graphics
          myGraphics.setComposite(AlphaComposite.Src);
          myGraphics.setColor(UIUtil.TRANSPARENT_COLOR);
          myGraphics.fillRect(0, 0, myImage.getWidth(), myImage.getHeight());

          myGraphics.drawImage(
              capture, myZoomRect.x, myZoomRect.y, myZoomRect.width, myZoomRect.height, this);

          // cropping round image
          myGraphics.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OUT));
          myGraphics.drawImage(
              myMaskImage, myZoomRect.x, myZoomRect.y, myZoomRect.width, myZoomRect.height, this);

          // paint magnifier
          myGraphics.setComposite(AlphaComposite.SrcOver);

          UIUtil.drawImage(
              myGraphics, myPipetteImage, SIZE - AllIcons.Ide.Pipette.getIconWidth(), 0, this);

          pickerDialog.setCursor(
              myParent.getToolkit().createCustomCursor(myImage, HOT_SPOT, "ColorPicker"));
          notifyListener(c, 300);
        }
      }
    }
  /**
   * Draw the icon at the specified location. Paints this component as an icon.
   *
   * @param c the component which can be used as observer
   * @param g the <tt>Graphics</tt> object used for painting
   * @param x the position on the X coordinate
   * @param y the position on the Y coordinate
   */
  public void paintIcon(Component c, Graphics g, int x, int y) {
    g = g.create();
    try {
      Graphics2D g2 = (Graphics2D) g;
      AntialiasingManager.activateAntialiasing(g2);

      g2.setColor(Color.WHITE);
      g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
      g2.fillRoundRect(x, y, getIconWidth() - 1, getIconHeight() - 1, 10, 10);
      g2.setColor(Color.DARK_GRAY);
      g2.drawRoundRect(x, y, getIconWidth() - 1, getIconHeight() - 1, 10, 10);

      // Indent component content from the border.
      g2.translate(x + 5, y + 5);

      super.paint(g2);

      g2.translate(x, y);
    } finally {
      g.dispose();
    }
  }
    @Override
    public Pair<Image, Point> createDraggedImage(DnDAction action, Point dragOrigin) {
      final TreePath[] paths = getSelectionPaths();
      if (paths == null) return null;

      final int count = paths.length;

      final JLabel label = new JLabel(String.format("%s item%s", count, count == 1 ? "" : "s"));
      label.setOpaque(true);
      label.setForeground(myTree.getForeground());
      label.setBackground(myTree.getBackground());
      label.setFont(myTree.getFont());
      label.setSize(label.getPreferredSize());
      final BufferedImage image =
          UIUtil.createImage(label.getWidth(), label.getHeight(), BufferedImage.TYPE_INT_ARGB);

      Graphics2D g2 = (Graphics2D) image.getGraphics();
      g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
      label.paint(g2);
      g2.dispose();

      return new Pair<Image, Point>(
          image, new Point(-image.getWidth(null), -image.getHeight(null)));
    }
예제 #28
0
  public void drawTag(Graphics g) {
    try {
      String b =
          tag.substring(
              tag.indexOf("B"), tag.indexOf("B") + 2); // gets the file name of the background file
      URL url = getClass().getResource(b + ".png");
      bg = ImageIO.read(url); // reads in the background file

      if (oldbg == null) {
        oldbg = bg;
        g.drawImage(bg, screenShakeX, screenShakeY, null);
      } else if (oldbg != bg) {
        if (fadeCounter == FADETIMELIMIT) {
          oldbg = bg;
          g.drawImage(bg, screenShakeX, screenShakeY, null); // draws the background image
        } else {
          g.drawImage(oldbg, screenShakeX, screenShakeY, null); // draws the background image

          float opacity = fadeCounter / FADETIMELIMIT;
          if (opacity > 1.0f) opacity = 1.0f;
          ((Graphics2D) g)
              .setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
          ((Graphics2D) g)
              .drawImage(bg, screenShakeX, screenShakeY, null); // draws the background image
          ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
        }
      } else g.drawImage(bg, screenShakeX, screenShakeY, null); // draws the background image

      if (tag.contains("H")) screenShakeUpdate = true;

      if (tag.contains("T")) // Two chars?
      {
        // CHANGE THIS LINE
        int ch1x = 200,
            ch1y = 200,
            ch2x = 600,
            ch2y = 200; // Where they are idk how big they are and where they should go
        String tagCopy =
            tag; // Need to make a copy because we still need to access the background component
        // later
        tagCopy =
            tagCopy.substring(
                tag.indexOf("T")); // gets the rest of the string after the tag of where they are
        String ch1 = tagCopy.substring(1, 4); // gets the name of the first character file
        url = getClass().getResource(ch1 + ".png");
        c1 = ImageIO.read(url); // reads in the first character image
        String ch2 = tagCopy.substring(4); // second char file
        c2 = ImageIO.read(url); // reads in
        g.drawImage(c1, ch1x, ch1y, null); // draws c1
        g.drawImage(c2, ch2x, ch2y, null); // draws c2
        url = getClass().getResource(ch2 + ".png");
      } else // only one char
      {
        // CHANGE THIS LINE
        int cx = 400, cy = 200; // location of the char
        String ch = tag.substring(tag.indexOf('C')); // gets name of char
        url = getClass().getResource(ch + ".png");
        c = ImageIO.read(url); // reads in
        g.drawImage(c, cx, cy, null); // draws c
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
예제 #29
0
  public void paint(Graphics g) // function that puts everything on the screen
      {
    Graphics2D scene = (Graphics2D) g; // Not really sure what this is. Blame Victor
    // use scene to draw the background

    scene.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.clearRect(0, 0, SCREENWIDTH, SCREENHEIGHT); // Clears the screen

    Font q =
        new Font(
            "Source Sans Pro", Font.PLAIN, 40); // Makes the font we use for options and story text
    g.setFont(q); // Sets the default font

    g.setColor(Color.white);

    if (state == 1) // Story text
    {
      drawTag(g);
      g.drawImage(textBox, 0, 0, null); // draw the story boxes
      Font n = new Font("Source Sans Pro", Font.BOLD, 48); // Makes the font for the names
      g.setFont(n); // Sets the name font
      scene.drawString(nameC, 53, 435); // Draws the current name
      g.setFont(q); // sets the quote font

      fm = g.getFontMetrics();

      ArrayList<String> lines = new ArrayList<String>();
      String line = "";

      for (int i = 0; i < quoteC.length(); i++) {
        line += quoteC.charAt(i);
        if (fm.stringWidth(line) > 1180) {
          String lineCopy = line;
          line = line.substring(0, lineCopy.lastIndexOf(' '));
          i -= lineCopy.length() - lineCopy.lastIndexOf(' ') - 1;
          lines.add(line);
          line = "";
        }
      }
      lines.add(line);

      for (int i = 0; i < lines.size(); i++) {
        scene.drawString(lines.get(i), 40, 535 + 65 * i);
      }
    } else if (state == 2) // Draws the options
    {
      scene.drawImage(bg, screenShakeX, screenShakeY, null);
      scene.drawImage(obox, screenShakeX, screenShakeY, null); // options thing
      scene.drawString(options.get(0), 220, 255);
      scene.drawString(options.get(1), 220, 375);
      scene.drawString(options.get(2), 220, 495);
    } else if (state == 3) // Game is over
    {
      scene.drawImage(oldbg, screenShakeX, screenShakeY, null);

      float opacity = fadeCounter / FADETIMELIMIT;
      if (opacity > 1.0f) opacity = 1.0f;
      scene.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
      scene.drawImage(bg, screenShakeX, screenShakeY, null); // draws the background image
      scene.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
      scene.drawString("The end", 40, 520); // End screen
    }
  }
예제 #30
0
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      Graphics2D g2D = (Graphics2D) g;
      Composite savedComposite = g2D.getComposite();
      AlphaComposite alpha =
          AlphaComposite.getInstance(
              AlphaComposite.SRC_OVER, AbstractLookAndFeel.getTheme().getMenuAlpha());
      g2D.setComposite(alpha);
      Color logoColor = AbstractLookAndFeel.getTheme().getMenuSelectionBackgroundColor();
      Color borderColorLo = AbstractLookAndFeel.getFrameColor();
      Color borderColorHi =
          ColorHelper.brighter(AbstractLookAndFeel.getMenuSelectionBackgroundColor(), 40);
      g.setColor(logoColor);
      if (JTattooUtilities.isLeftToRight(c)) {
        int dx = getBorderInsets(c).left;
        g.fillRect(x, y, dx - 1, h - 1 - shadowSize);
        paintLogo(c, g, x, y, w, h);
        // - highlight
        g.setColor(ColorHelper.brighter(AbstractLookAndFeel.getMenuBackgroundColor(), 40));
        g.drawLine(x + dx, y + 1, x + w - shadowSize - 2, y + 1);
        g.setColor(borderColorHi);
        g.drawLine(x + 1, y, x + 1, y + h - shadowSize - 2);
        // - outer frame
        g.setColor(borderColorLo);
        if (isMenuBarPopup(c)) {
          // top
          g.drawLine(x + dx - 1, y, x + w - shadowSize - 1, y);
          // left
          g.drawLine(x, y, x, y + h - shadowSize - 1);
          // bottom
          g.drawLine(x, y + h - shadowSize - 1, x + w - shadowSize - 1, y + h - shadowSize - 1);
          // right
          g.drawLine(x + w - shadowSize - 1, y + 1, x + w - shadowSize - 1, y + h - shadowSize - 1);
        } else {
          g.drawRect(x, y, w - shadowSize - 1, h - shadowSize - 1);
        }
        // - logo separator
        g.drawLine(x + dx - 1, y + 1, x + dx - 1, y + h - shadowSize - 1);
      } else {
        int dx = getBorderInsets(c).right - shadowSize;
        g.fillRect(x + w - dx - shadowSize, y, dx - 1, h - 1 - shadowSize);
        paintLogo(c, g, x, y, w, h);
        // - highlight
        g.setColor(ColorHelper.brighter(AbstractLookAndFeel.getMenuBackgroundColor(), 40));
        g.drawLine(x + 1, y + 1, x + w - dx - shadowSize - 1, y + 1);
        g.drawLine(x + 1, y + 1, x + 1, y + h - shadowSize - 2);
        // - outer frame
        g.setColor(borderColorLo);
        if (isMenuBarPopup(c)) {
          // top
          g.drawLine(x, y, x + w - dx - shadowSize, y);
          // left
          g.drawLine(x, y, x, y + h - shadowSize - 1);
          // bottom
          g.drawLine(x, y + h - shadowSize - 1, x + w - shadowSize - 1, y + h - shadowSize - 1);
          // right
          g.drawLine(x + w - shadowSize - 1, y, x + w - shadowSize - 1, y + h - shadowSize - 1);
        } else {
          g.drawRect(x, y, w - shadowSize - 1, h - shadowSize - 1);
        }
        // - logo separator
        g.drawLine(x + w - dx - shadowSize, y + 1, x + w - dx - shadowSize, y + h - shadowSize - 1);
      }

      // paint the shadow
      g2D.setColor(AbstractLookAndFeel.getTheme().getShadowColor());
      float alphaValue = 0.4f;
      for (int i = 0; i < shadowSize; i++) {
        alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alphaValue);
        g2D.setComposite(alpha);
        g.drawLine(
            x + w - shadowSize + i,
            y + shadowSize,
            x + w - shadowSize + i,
            y + h - shadowSize - 1 + i);
        g.drawLine(
            x + shadowSize, y + h - shadowSize + i, x + w - shadowSize + i, y + h - shadowSize + i);
        alphaValue -= (alphaValue / 2);
      }

      g2D.setComposite(savedComposite);
    }