/**
  * This method check DefaultExpandedSideMenuPanel.
  *
  * @param collapseIcon the collapse icon
  * @param pinIcon the pin icon
  */
 private void checkDefaultExpandedSideMenuPanel(Icon collapseIcon, Icon pinIcon) {
   assertEquals("sideMenuModel", sideMenuModel, target.getSideMenuModel());
   ActionListener buttonListener =
       (ActionListener)
           TestHelper.getPrivateField(
               DefaultExpandedSideMenuPanel.class, target, "buttonListener");
   // check buttonListener
   assertNotNull("buttonListener", buttonListener);
   // ((JToggleButton) target.getPinButton()).setSelected(true);
   // buttonListener.actionPerformed(new ActionEvent(target.getPinButton(), 1, "xxx"));
   // assertEquals("should be floating", true, sideMenuModel.isFloating());
   ((JToggleButton) target.getPinButton()).setSelected(false);
   buttonListener.actionPerformed(new ActionEvent(target.getPinButton(), 1, "xxx"));
   assertEquals("should not be floating", false, sideMenuModel.isFloating());
   buttonListener.actionPerformed(new ActionEvent(target.getCollapseButton(), 1, "xxx"));
   assertEquals("should not be expanded", false, sideMenuModel.isExpanded());
   // check other fields
   assertEquals("content", TestHelper.CONTENT, target.getContent());
   TestHelper.checkButton(target.getCollapseButton(), buttonListener, collapseIcon);
   TestHelper.checkButton(target.getPinButton(), buttonListener, pinIcon);
   assertEquals("Selected status", sideMenuModel.isFloating(), target.getPinButton().isSelected());
   JLabel textLabel =
       (JLabel)
           TestHelper.getPrivateField(DefaultExpandedSideMenuPanel.class, target, "textLabel");
   assertEquals("text of textLabel", sideMenuModel.getTitle(), textLabel.getText());
   assertEquals(
       "HorizontalAlignment of textLabel",
       SwingConstants.CENTER,
       textLabel.getHorizontalAlignment());
 }
示例#2
0
  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;
  }
 /**
  * {@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);
 }
示例#4
0
  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();
  }