コード例 #1
0
ファイル: LVAoberflaeche.java プロジェクト: bomm/thera-pi
  protected String layoutCL(
      JLabel label,
      FontMetrics fontMetrics,
      String text,
      Icon icon,
      Rectangle viewR,
      Rectangle iconR,
      Rectangle textR) {
    String s =
        layoutCompoundLabel(
            (JComponent) label,
            fontMetrics,
            splitStringByLines(text),
            icon,
            label.getVerticalAlignment(),
            label.getHorizontalAlignment(),
            label.getVerticalTextPosition(),
            label.getHorizontalTextPosition(),
            viewR,
            iconR,
            textR,
            label.getIconTextGap());

    if (s.equals("")) return text;
    return s;
  }
コード例 #2
0
 /**
  * {@inheritDoc}
  *
  * <p>Paints a diagonal cross over the text if the comp is of type JLabel, does nothing otherwise.
  */
 @Override
 protected void doPaint(Graphics2D g, JComponent comp, int width, int height) {
   if (!(comp instanceof JLabel)) return;
   JLabel label = (JLabel) comp;
   Insets insets = label.getInsets(insetss);
   paintViewR.x = insets.left;
   paintViewR.y = insets.top;
   paintViewR.width = width - (insets.left + insets.right);
   paintViewR.height = height - (insets.top + insets.bottom);
   paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
   paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;
   SwingUtilities.layoutCompoundLabel(
       label,
       label.getFontMetrics(label.getFont()),
       label.getText(),
       null,
       label.getVerticalAlignment(),
       label.getHorizontalAlignment(),
       label.getVerticalTextPosition(),
       label.getHorizontalTextPosition(),
       paintViewR,
       paintIconR,
       paintTextR,
       label.getIconTextGap());
   doPaint(g, paintTextR);
 }
コード例 #3
0
  @NotNull
  @Override
  public BalloonBuilder createHtmlTextBalloonBuilder(
      @NotNull final String htmlContent,
      @Nullable final Icon icon,
      final Color fillColor,
      @Nullable final HyperlinkListener listener) {

    JEditorPane text =
        IdeTooltipManager.initPane(htmlContent, new HintHint().setAwtTooltip(true), null);

    if (listener != null) {
      text.addHyperlinkListener(listener);
    }
    text.setEditable(false);
    NonOpaquePanel.setTransparent(text);
    text.setBorder(null);

    JLabel label = new JLabel();
    final JPanel content =
        new NonOpaquePanel(
            new BorderLayout(
                (int) (label.getIconTextGap() * 1.5), (int) (label.getIconTextGap() * 1.5)));

    final NonOpaquePanel textWrapper = new NonOpaquePanel(new GridBagLayout());
    JScrollPane scrolledText = new JScrollPane(text);
    scrolledText.setBackground(fillColor);
    scrolledText.getViewport().setBackground(fillColor);
    scrolledText.getViewport().setBorder(null);
    scrolledText.setBorder(null);
    textWrapper.add(scrolledText);
    content.add(textWrapper, BorderLayout.CENTER);

    final NonOpaquePanel north = new NonOpaquePanel(new BorderLayout());
    north.add(new JLabel(icon), BorderLayout.NORTH);
    content.add(north, BorderLayout.WEST);

    content.setBorder(new EmptyBorder(2, 4, 2, 4));

    final BalloonBuilder builder = createBalloonBuilder(content);

    builder.setFillColor(fillColor);

    return builder;
  }
コード例 #4
0
 /**
  * Instantiates and configures a WrappingIconPanel with the dropHack property set as indicated by
  * the boolean.
  *
  * @param dropHackEnabled a boolean indicating whether the drop hack should be enabled.
  * @see #isVisible()
  */
 public WrappingIconPanel(boolean dropHackEnabled) {
   setOpaque(false);
   iconLabel = new JRendererLabel();
   iconLabelGap = iconLabel.getIconTextGap();
   iconLabel.setOpaque(false);
   updateIconBorder();
   setBorder(null);
   setLayout(new BorderLayout());
   add(iconLabel, BorderLayout.LINE_START);
   setDropHackEnabled(dropHackEnabled);
 }
コード例 #5
0
ファイル: Banner.java プロジェクト: Rokko11/idea-community
  public void setText(@Nullable final String... text) {
    myText.removeAll();
    if (text == null) return;

    for (int i = 0; i < text.length; i++) {
      final JLabel eachLabel = new JLabel(text[i], JLabel.CENTER);
      final int gap = eachLabel.getIconTextGap();
      eachLabel.setBorder(new EmptyBorder(0, 0, 0, gap));
      eachLabel.setVerticalTextPosition(JLabel.TOP);
      eachLabel.setFont(eachLabel.getFont().deriveFont(Font.BOLD, eachLabel.getFont().getSize()));
      myText.add(eachLabel);
      if (i < text.length - 1) {
        final JLabel eachIcon =
            new JLabel(IconLoader.getIcon("/general/comboArrowRight.png"), JLabel.CENTER);
        eachIcon.setBorder(new EmptyBorder(0, 0, 0, gap));
        myText.add(eachIcon);
      }
    }
  }
コード例 #6
0
ファイル: Baseline.java プロジェクト: benbac20/jrdesktop
  private static int getLabelBaseline(JLabel label, int height) {
    Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();
    FontMetrics fm = label.getFontMetrics(label.getFont());

    resetRects(label, height);

    SwingUtilities.layoutCompoundLabel(
        label,
        fm,
        "a",
        icon,
        label.getVerticalAlignment(),
        label.getHorizontalAlignment(),
        label.getVerticalTextPosition(),
        label.getHorizontalTextPosition(),
        viewRect,
        iconRect,
        textRect,
        label.getIconTextGap());

    return textRect.y + fm.getAscent();
  }
コード例 #7
0
ファイル: JDragTree.java プロジェクト: TheSeeker/Thaw
  // 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);
  }
コード例 #8
0
  /** Creates and sets the layout of components */
  private void initComponents() {
    Rectangle2D rect;
    String constraint;

    LayoutManager lm = new MigLayout("insets 0");
    this.setLayout(lm);

    Font font = Font.decode("Courier-12");

    busyIcon = new ImageIcon(StatusBar.class.getResource(BUSY_ICON_IMAGE));
    renderLabel = new JLabel();
    renderLabel.setHorizontalTextPosition(JLabel.LEADING);
    rect = getFontMetrics(font).getStringBounds("rendering", renderLabel.getGraphics());

    constraint =
        String.format(
            "gapx 5, width %d!, height %d!",
            (int) rect.getWidth() + busyIcon.getIconWidth() + renderLabel.getIconTextGap(),
            (int) Math.max(rect.getHeight(), busyIcon.getIconHeight()) + 6);

    add(renderLabel, constraint);

    coordsLabel = new JLabel();
    Graphics graphics = coordsLabel.getGraphics();
    coordsLabel.setFont(font);

    rect = getFontMetrics(font).getStringBounds("  00000000.000 00000000.000", graphics);

    constraint =
        String.format(
            "width %d!, height %d!", (int) rect.getWidth() + 10, (int) rect.getHeight() + 6);

    add(coordsLabel, constraint);

    boundsLabel = new JLabel();
    boundsLabel.setFont(font);

    rect =
        getFontMetrics(font)
            .getStringBounds(
                "Min: 00000000.000 00000000.000 Span: 00000000.000 00000000.000", graphics);

    constraint =
        String.format(
            "width %d!, height %d!", (int) rect.getWidth() + 10, (int) rect.getHeight() + 6);

    add(boundsLabel, constraint);

    crsBtn = new JButton(stringRes.getString("crs_undefined"));
    crsBtn.setFont(font);

    rect = getFontMetrics(font).getStringBounds("X", graphics);

    constraint = String.format("height %d!", (int) rect.getHeight() + 6);

    crsBtn.setToolTipText(stringRes.getString("tool_tip_statusbar_crs"));
    crsMenu = new CRSPopupMenu();
    crsBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            crsMenu.show(crsBtn, 0, 0);
          }
        });

    add(crsBtn, constraint);
  }