示例#1
0
 /*    */ public void paint(Graphics g) {
   /* 55 */ if (this.anim != null) {
     /* 56 */ this.anim.updateToTime(System.currentTimeMillis() - this.startTime);
     /* 57 */ setIcon(new ImageIcon(this.anim.getImage()));
     /*    */ }
   /* 59 */ super.paint(g);
   /*    */ }
示例#2
0
  /**
   * /** paint is subclassed to draw the background correctly. JLabel currently does not allow
   * backgrounds other than white, and it will also fill behind the icon. Something that isn't
   * desirable.
   */
  public void paint(Graphics g) {
    Color bColor;
    Icon currentI = getIcon();

    if (selected) {
      bColor = SelectedBackgroundColor;
    } else if (getParent() != null) {

      /* Pick background color up from parent (which will come from
      the JTree we're contained in). */
      bColor = getParent().getBackground();
    } else {
      bColor = getBackground();
    }
    g.setColor(bColor);
    if (currentI != null && getText() != null) {
      int offset = (currentI.getIconWidth() + getIconTextGap());

      if (getComponentOrientation().isLeftToRight()) {
        g.fillRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1);
      } else {
        g.fillRect(0, 0, getWidth() - 1 - offset, getHeight() - 1);
      }
    } else {
      g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
    }
    super.paint(g);
  }
示例#3
0
 /**
  * Draws this multi-line string inside a given rectangle.
  *
  * @param pGraphics2D the graphics context
  * @param pRectangle the rectangle into which to place this multi-line string
  */
 public void draw(Graphics2D pGraphics2D, Rectangle2D pRectangle) {
   JLabel label = getLabel();
   label.setFont(pGraphics2D.getFont());
   label.setBounds(0, 0, (int) pRectangle.getWidth(), (int) pRectangle.getHeight());
   pGraphics2D.translate(pRectangle.getX(), pRectangle.getY());
   label.paint(pGraphics2D);
   pGraphics2D.translate(-pRectangle.getX(), -pRectangle.getY());
 }
示例#4
0
 public void paint(Graphics g) {
   super.paint(g);
   if (_focus && g instanceof Graphics2D) {
     Stroke old = ((Graphics2D) g).getStroke();
     ((Graphics2D) g).setStroke(_dashed);
     g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
     ((Graphics2D) g).setStroke(old);
   }
 }
示例#5
0
 @Override
 public void paint(Graphics g) {
   if (active) {
     g.setColor(defaultGray);
     g.fillRect(getX(), getY(), getWidth(), getHeight());
     if (l != null) l.paint(g);
     paintBorder(g);
   } else super.paint(g);
 }
 @Override
 public void paint(Graphics g) {
   this.oldColor = g.getColor();
   if (this.selected) {
     g.setColor(UIManager.getColor("textHighlight"));
     g.fillRect(0, 0, (int) this.getPreferredSize().getWidth(), (int) this.getSize().getHeight());
     g.setColor(this.oldColor);
   }
   super.paint(g);
 }
示例#7
0
 public void paint(Graphics g) {
   super.paint(g);
   Font f = getFont();
   FontMetrics fm = getFontMetrics(f);
   int x1 = 0;
   int y1 = fm.getHeight() + 3;
   int x2 = fm.stringWidth(getText());
   if (getText().length() > 0) {
     g.drawLine(x1, y1, x2, y1);
   }
 }
 public void paint(Graphics g) {
   paintBackground(g);
   if (rolloverCol == col) {
     if (gv > 128) {
       setForeground(Color.black);
     } else {
       setForeground(Color.white);
     }
   }
   super.paint(g);
 }
示例#9
0
 /**
  * Draws this shape.
  *
  * @param g2 the graphics context
  */
 public void paintShape(Graphics2D g2) {
   Dimension dim = label.getPreferredSize();
   //        System.out.println(dim);
   if (dim.width > 0 && dim.height > 0) {
     label.setBounds(0, 0, dim.width, dim.height);
     g2.translate(getX(), getY());
     g2.scale(
         (image.getWidth() + 2 * xGrow) / dim.width, (image.getHeight() + 2 * yGrow) / dim.height);
     label.paint(g2);
   }
 }
示例#10
0
 public void paintShape(Graphics2D g2) {
   if (color != null) {
     label.setForeground(
         new java.awt.Color((int) color.getRed(), (int) color.getGreen(), (int) color.getBlue()));
     Dimension dim = label.getPreferredSize();
     if (dim.width > 0 && dim.height > 0) {
       label.setBounds(0, 0, dim.width, dim.height);
       g2.translate(getX(), getY());
       g2.scale(getWidth() / dim.width, getHeight() / dim.height);
       label.paint(g2);
     }
   }
 }
示例#11
0
    public void paintComponent(Graphics g) {

      Color c = (this == selComp) ? vLightBlue : Color.WHITE;
      int i = driver.allFiles ? 1 : 0;
      String lt = driver.curDiag.filterOptions[i];

      JLabel l = new JLabel(lt);
      Rectangle bounds = super.getBounds();
      g.setColor(c);
      g.fillRect(0, 0, bounds.width, bounds.height);
      l.setBounds(bounds);
      // setOpaque(true);
      l.paint(g);
    }
    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;
    }
  /**
   * Override the base class to properly set the painting. Code mostly stolen from
   * DefaultTreeCellRenderer without all the extra crap.
   *
   * @param g The graphics context to paint with
   */
  public void paint(Graphics g) {
    int imageOffset = -1;
    int width = getWidth();
    int height = getHeight();

    if (focused) {
      if (iconFocusBorder) {
        imageOffset = 0;
      } else if (imageOffset == -1) {
        imageOffset = getLabelStart();
      }
    }

    if (selected) {
      g.setColor(bgSelectColor);
      if (getComponentOrientation().isLeftToRight()) {
        g.fillRect(imageOffset, 0, width - 1 - imageOffset, height);
      } else {
        g.fillRect(0, 0, width - 1 - imageOffset, height);
      }

      g.setColor(textSelectColor);
      setForeground(textSelectColor);
    } else {
      g.setColor(textSelectColor);
      setForeground(textSelectColor);
    }

    if (focused) {
      g.setColor(borderColor);
      if (getComponentOrientation().isLeftToRight()) {
        g.drawRect(imageOffset, 0, width - 1 - imageOffset, height - 1);
      } else {
        g.drawRect(0, 0, width - 1 - imageOffset, height - 1);
      }
    }
    super.paint(g);
  }
示例#14
0
  @Override
  public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    int labelX = x + outsideInsets.left;
    int labelY = y + outsideInsets.top;

    TitledSeparator titledSeparator = getTitledSeparator(c);
    JLabel label = titledSeparator.getLabel();
    Dimension labelSize = label.getPreferredSize();
    label.setSize(labelSize);
    g.translate(labelX, labelY);
    label.paint(g);

    int separatorX = labelX + labelSize.width + TitledSeparator.SEPARATOR_LEFT_INSET;
    int separatorY = labelY + (UIUtil.isUnderAquaLookAndFeel() ? 2 : labelSize.height / 2 - 1);
    int separatorW = Math.max(0, width - separatorX - TitledSeparator.SEPARATOR_RIGHT_INSET);
    int separatorH = 2;

    JSeparator separator = titledSeparator.getSeparator();
    separator.setSize(separatorW, separatorH);
    g.translate(separatorX - labelX, separatorY - labelY);
    separator.paint(g);

    g.translate(-separatorX, -separatorY);
  }
示例#15
0
  public void paintComponent(Graphics g) {
    Dimension d = getSize();

    Dimension a = ui.getPreferredSize();

    jcb.setBounds(0, (d.height - a.height) / 2, a.width, a.height);

    Graphics g2 = g.create(0, (d.height - a.height) / 2, a.width, a.height);

    ui.paint(g2, jcb, selected, implicit, false);

    int labelWidth = d.width - a.width - PAD, labelHeight = d.height;

    jl.setBounds(a.width + PAD, 0, labelWidth, labelHeight);

    g2 = g.create(a.width + PAD, 0, labelWidth, labelHeight);

    Color c = jl.getBackground();
    if (c != null) {
      g2.setColor(c);
      g2.fillRect(0, 0, labelWidth, labelHeight);
    }
    jl.paint(g2);
  }
    @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)));
    }
示例#17
0
  public void paint(
      Graphics2D g2, TreePath treePath, CanvasRendererContext rendererContext, int graphY) {
    boolean selected = rendererContext.isSelected(treePath, this);

    int step = rendererContext.getStep();

    int x0 = rendererContext.getGraphX() + getX() * step;
    int y0 = graphY + getY() * step;
    int width = getWidth() * step;
    int height = getHeight() * step;

    double tx = x0 + 0.5;
    double ty = y0 + 0.5;

    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    g2.translate(tx, ty);

    RRectangle rrect = new RRectangle(0, 0, width, step * 2, step, step, 0.0, 0.0);

    g2.setPaint(Color.WHITE);

    int y = step * 2;
    int h = height - y;

    g2.fillRect(0, y, width, h);
    g2.setPaint(
        new TexturePaint(MapperStyle.GRADIENT_TEXTURE, new Rectangle(0, 0, width, step * 2)));
    g2.fill(rrect);

    Icon icon = getIcon();

    int textX = step;

    if (icon != null) {
      double tx2 = step - 0.5;
      double ty2 = step - 0.5 - icon.getIconHeight() / 2 + 1;
      g2.translate(tx2, ty2);
      g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
      icon.paintIcon(rendererContext.getCanvas(), g2, 0, 0);
      g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
      g2.translate(-tx2, -ty2);

      textX += icon.getIconWidth() + 4;
    }
    g2.translate(-tx, -ty);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

    String name = getName();
    if (name != null) {
      int labelWidth = width - textX - step - 1;
      if (labelWidth > 0) {
        int labelX = x0 + textX;
        int labelY = y0 + 1;
        int labelHeight = step * 2 - 1;

        JLabel label = rendererContext.getTextRenderer();
        label.setBounds(0, 0, labelWidth, labelHeight);
        label.setForeground(MapperStyle.ICON_COLOR);
        label.setText(name);
        label.setHorizontalAlignment(JLabel.LEFT);
        label.setFont(label.getFont().deriveFont(Font.PLAIN));

        g2.translate(labelX, labelY);
        label.paint(g2);
        g2.translate(-labelX, -labelY);
      }
    }

    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    g2.translate(tx, ty);

    Stroke oldStroke = g2.getStroke();
    g2.setPaint(MapperStyle.VERTEX_BORDER_COLOR);
    for (int i = 2; i < getHeight(); i += 2) {
      y = i * step;
      g2.drawLine(0, y, width - 1, y);
    }

    rrect.setBounds(0, 0, width, height);

    if (selected) {
      g2.setStroke(MapperStyle.SELECTION_STROKE);
      g2.setPaint(MapperStyle.SELECTION_COLOR);
      g2.draw(rrect);
    } else {
      g2.setPaint(MapperStyle.VERTEX_BORDER_COLOR);
      g2.draw(rrect);
    }

    g2.fill(new Triangle(width - step, height, width, height - step, width, height));

    g2.setStroke(oldStroke);
    g2.translate(-tx, -ty);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

    for (int i = getItemCount() - 1; i >= 0; i--) {
      VertexItem item = getItem(i);
      item.paintTargetPin(g2, treePath, rendererContext, graphY);
      if (!item.isHairline()) {
        item.paint(g2, treePath, rendererContext, graphY);
      }
    }

    paintSourcePin(g2, treePath, rendererContext, graphY);

    String resultText = getResultText();
    if (resultText != null) {
      JLabel label = rendererContext.getTextRenderer();

      int labelWidth = width - 5 - step;

      if (labelWidth > 0) {
        int labelHeight = 2 * step - 1;
        int labelX = x0 + 3;
        int labelY = y0 + height - labelHeight;

        label.setHorizontalAlignment(JLabel.RIGHT);
        label.setText(resultText);
        label.setFont(label.getFont().deriveFont(Font.PLAIN));
        label.setForeground(MapperStyle.FUNCTION_RESULT_TEXT_COLOR);
        label.setBounds(0, 0, labelWidth, labelHeight);

        g2.translate(labelX, labelY);
        label.paint(g2);
        g2.translate(-labelX, -labelY);
      }
    }
  }
示例#18
0
  // DragGestureListener interface method
  public void dragGestureRecognized(final DragGestureEvent e) {
    // we should make sure we aren't in edit mode
    final InputEvent ievent = e.getTriggerEvent();
    if (ievent instanceof MouseEvent) {
      // even though I tell dgRecognizer to ignore the the right mouse button,
      // it thinks the RMB starts a drag event...argh
      if ((((MouseEvent) ievent).getModifiers() & InputEvent.BUTTON3_MASK) != 0) return;
    }

    // begin dnd
    final Point ptDragOrigin = e.getDragOrigin();
    final TreePath path = getPathForLocation(ptDragOrigin.x, ptDragOrigin.y);
    if (path == null) return;
    if (isRootPath(path)) return; // Ignore user trying to drag the root node

    // Work out the offset of the drag point from the TreePath bounding rectangle origin
    final Rectangle raPath = getPathBounds(path);
    _ptOffset.setLocation(ptDragOrigin.x - raPath.x, ptDragOrigin.y - raPath.y);

    // Get the cell renderer (which is a JLabel) for the path being dragged
    final JLabel lbl =
        (JLabel)
            getCellRenderer()
                .getTreeCellRendererComponent(
                    this, // tree
                    path.getLastPathComponent(), // value
                    false, // isSelected   (dont want a colored background)
                    this.isExpanded(path), // isExpanded
                    getModel().isLeaf(path.getLastPathComponent()), // isLeaf
                    0, // row          (not important for rendering)
                    false // hasFocus     (dont want a focus rectangle)
                    );
    lbl.setSize(
        (int) raPath.getWidth(),
        (int) raPath.getHeight()); // <-- The layout manager would normally do this

    // Get a buffered image of the selection for dragging a ghost image
    _imgGhost =
        new BufferedImage(
            (int) raPath.getWidth(), (int) raPath.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE);
    final Graphics2D g2 = _imgGhost.createGraphics();

    // Ask the cell renderer to paint itself into the BufferedImage
    g2.setComposite(
        AlphaComposite.getInstance(AlphaComposite.SRC, 0.5f)); // Make the image ghostlike
    lbl.paint(g2);

    // Now paint a gradient UNDER the ghosted JLabel text (but not under the icon if any)
    // Note: this will need tweaking if your icon is not positioned to the left of the text
    final Icon icon = lbl.getIcon();
    final int nStartOfText = (icon == null) ? 0 : icon.getIconWidth() + lbl.getIconTextGap();
    g2.setComposite(
        AlphaComposite.getInstance(AlphaComposite.DST_OVER, 0.5f)); // Make the gradient ghostlike
    g2.setPaint(
        new GradientPaint(
            nStartOfText,
            0,
            SystemColor.controlShadow,
            getWidth(),
            0,
            new Color(255, 255, 255, 0)));
    g2.fillRect(nStartOfText, 0, getWidth(), _imgGhost.getHeight());
    g2.dispose();

    setSelectionPath(path); // Select this path in the tree

    // Wrap the path being transferred into a Transferable object
    final Transferable transferable = new CTransferableTreePath(path);

    // Remember the path being dragged (because if it is being moved, we will have to delete it
    // later)
    _pathSource = path;

    // We pass our drag image just in case it IS supported by the platform
    e.startDrag(null, _imgGhost, new Point(5, 5), transferable, this);
  }
示例#19
0
 /** Paint */
 public void paint(Graphics g) {
   super.paint(g);
   setForeground(linkColor_);
 }