Пример #1
0
  @Override
  protected void paintText(
      final Graphics g, final JComponent c, final Rectangle textRect, final String text) {
    final AbstractButton b = (AbstractButton) c;
    final ButtonModel model = b.getModel();
    final FontMetrics fm = SwingUtils.getFontMetrics(c, g);
    final int mnemonicIndex = b.getDisplayedMnemonicIndex();

    // Drawing text
    if (model.isEnabled()) {
      // Normal text
      g.setColor(b.getForeground());
      SwingUtils.drawStringUnderlineCharAt(
          g,
          text,
          mnemonicIndex,
          textRect.x + getTextShiftOffset(),
          textRect.y + fm.getAscent() + getTextShiftOffset());
    } else {
      // Disabled text
      g.setColor(b.getBackground().brighter());
      SwingUtils.drawStringUnderlineCharAt(
          g, text, mnemonicIndex, textRect.x, textRect.y + fm.getAscent());
      g.setColor(b.getBackground().darker());
      SwingUtils.drawStringUnderlineCharAt(
          g, text, mnemonicIndex, textRect.x - 1, textRect.y + fm.getAscent() - 1);
    }
  }
Пример #2
0
  /** {@inheritDoc} */
  @Override
  public void paint(final Graphics2D g2d, final Rectangle bounds, final E label) {
    // Applying graphics settings
    final Composite oc = LafUtils.setupAlphaComposite(g2d, transparency, transparency != null);
    final Map textHints =
        drawShade ? StyleConstants.defaultTextRenderingHints : StyleConstants.textRenderingHints;
    final Font oldFont = LafUtils.setupFont(g2d, label.getFont());
    final Map oldHints = SwingUtils.setupTextAntialias(g2d, textHints);

    // Retrieving icon & text
    final String text = label.getText();
    final Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();

    // Painting background
    if (backgroundPainter != null) {
      backgroundPainter.paint(g2d, bounds, label);
    }

    // We don't need to go futher if there is not icon/text
    if (icon == null && text == null) {
      return;
    }

    final FontMetrics fm = label.getFontMetrics(label.getFont());
    final String clippedText = layout(label, fm, label.getWidth(), label.getHeight());

    if (icon != null) {
      icon.paintIcon(label, g2d, paintIconR.x, paintIconR.y);
    }

    if (text != null) {
      final View v = (View) label.getClientProperty(BasicHTML.propertyKey);
      if (v != null) {
        // Painting HTML label view
        v.paint(g2d, paintTextR);
      } else {
        // Painting plain label view
        final int textX = paintTextR.x;
        final int textY = paintTextR.y + fm.getAscent();
        if (label.isEnabled()) {
          paintEnabledText(label, g2d, clippedText, textX, textY);
        } else {
          paintDisabledText(label, g2d, clippedText, textX, textY);
        }
      }
    }

    SwingUtils.restoreTextAntialias(g2d, oldHints);
    LafUtils.restoreFont(g2d, oldFont);
    LafUtils.restoreComposite(g2d, oc, transparency != null);
  }
Пример #3
0
 /**
  * Performs disabled text painting.
  *
  * @param label label to process
  * @param g2d graphics context
  * @param text label text
  * @param textX text X coordinate
  * @param textY text Y coordinate
  */
 protected void paintDisabledText(
     final E label, final Graphics2D g2d, final String text, final int textX, final int textY) {
   if (label.isEnabled() && drawShade) {
     g2d.setColor(label.getBackground().darker());
     paintShadowText(g2d, text, textX, textY);
   } else {
     final int accChar = label.getDisplayedMnemonicIndex();
     final Color background = label.getBackground();
     g2d.setColor(background.brighter());
     SwingUtils.drawStringUnderlineCharAt(g2d, text, accChar, textX + 1, textY + 1);
     g2d.setColor(background.darker());
     SwingUtils.drawStringUnderlineCharAt(g2d, text, accChar, textX, textY);
   }
 }
Пример #4
0
  private Component createValueLabel(DetailsDecoration property, int maxLength) {

    String value = property.getFormatedValue();
    boolean abbreviate = (value.length() > maxLength);
    String abbreviatedValue;

    if (value.matches("[0-9\\.]+e-?[0-9]+")) {
      value =
          "<html><body>" + value.replaceAll("e(-?[0-9]+)", "·10<sup>$1</sup>") + "</body></html>";
    }

    if (abbreviate) {
      abbreviatedValue = StringUtils.abbreviate(value, maxLength);
    } else {
      abbreviatedValue = value;
    }

    WebLabel label;
    if (StringUtils.isEmpty(property.getValueLink())) {
      label = new WebLabel(abbreviatedValue);
    } else {
      DetailsWebLinkLabel webLabel = new DetailsWebLinkLabel(abbreviatedValue);
      webLabel.setLink(property.getValueLink(), false);
      label = webLabel;
    }

    SwingUtils.changeFontSize(label, -1);

    if (abbreviate) {
      TooltipManager.setTooltip(label, value, TooltipWay.down, 0);
    }

    label.setCursor(new Cursor(Cursor.HAND_CURSOR));
    label.addMouseListener(new PropertyMouseListener(property));

    if (property.isSelected()) {
      SwingUtils.setBoldFont(label);
    }

    if (property.getBgColor() != null) {
      WebPanel colorBox = new WebPanel();
      colorBox.setPreferredSize(new Dimension(15, 15));
      colorBox.setBackground(property.getBgColor());
      return new GroupPanel(4, colorBox, label);
    }

    label.setForeground(property.isVisible() ? Color.BLACK : Color.lightGray);
    return label;
  }
Пример #5
0
  private static Component createDescription(Example example, ExampleGroup group) {
    Color foreground = group.getPreferredForeground();

    WebLabel titleLabel = new WebLabel(example.getTitle(), JLabel.TRAILING);
    titleLabel.setDrawShade(true);
    titleLabel.setForeground(foreground);
    if (foreground.equals(Color.WHITE)) {
      titleLabel.setShadeColor(Color.BLACK);
    }

    if (example.getDescription() == null) {
      return titleLabel;
    } else {
      WebLabel descriptionLabel = new WebLabel(example.getDescription(), WebLabel.TRAILING);
      descriptionLabel.setForeground(Color.GRAY);
      SwingUtils.changeFontSize(descriptionLabel, -1);

      WebPanel vertical =
          new WebPanel(new VerticalFlowLayout(VerticalFlowLayout.MIDDLE, 0, 0, true, false));
      vertical.setOpaque(false);
      vertical.add(titleLabel);
      vertical.add(descriptionLabel);

      return vertical;
    }
  }
Пример #6
0
 /**
  * Returns whether one of focusable childs is focused or not.
  *
  * @return true if one of focusable childs is focused, false otherwise
  */
 public boolean isChildFocused() {
   for (final WeakReference<Component> focusableChild : focusableChilds) {
     final Component component = focusableChild.get();
     if (component != null) {
       if (SwingUtils.hasFocusOwner(component)) {
         return true;
       }
     }
   }
   return false;
 }
Пример #7
0
 /**
  * Performs enabled text painting.
  *
  * @param label label to process
  * @param g2d graphics context
  * @param text label text
  * @param textX text X coordinate
  * @param textY text Y coordinate
  */
 protected void paintEnabledText(
     final E label, final Graphics2D g2d, final String text, final int textX, final int textY) {
   if (drawShade) {
     g2d.setColor(label.getForeground());
     paintShadowText(g2d, text, textX, textY);
   } else {
     final int mnemIndex = label.getDisplayedMnemonicIndex();
     g2d.setColor(label.getForeground());
     SwingUtils.drawStringUnderlineCharAt(g2d, text, mnemIndex, textX, textY);
   }
 }
Пример #8
0
  public void setVisibleRowCount(final int visibleRowCount) {
    this.visibleRowCount = visibleRowCount;

    // Reset preferred viewport size
    setPreferredScrollableViewportSize(null);

    // Update viewport size
    final JScrollPane scrollPane = SwingUtils.getScrollPane(this);
    if (scrollPane != null) {
      scrollPane.getViewport().invalidate();
    }
  }
Пример #9
0
  private Component createNameLabel(DetailsDecoration detail) {

    if (detail instanceof JComponentDetailsDecoration) {
      Component c = createComponentNameLabel((JComponentDetailsDecoration) detail);
      if (c != null) {
        c.setForeground(detail.isVisible() ? Color.BLACK : Color.lightGray);
        return c;
      }
    }

    WebLabel label = new WebLabel(StringUtils.capitalize(detail.getName()), JLabel.TRAILING);

    label.setDrawShade(true);
    SwingUtils.changeFontSize(label, -1);

    if (detail.isSelected()) {
      SwingUtils.setBoldFont(label);
    }

    label.setCursor(new Cursor(Cursor.HAND_CURSOR));
    label.addMouseListener(new PropertyMouseListener(detail));

    if (StringUtils.isNotEmpty(detail.getDescription())) {
      String description =
          "<html><body width=\"300px\">" + detail.getDescription() + "</body></html>";
      TooltipManager.setTooltip(label, description, TooltipWay.down, 0);
    }

    if (!StringUtils.isEmpty(detail.getDescriptionLink())) {
      DetailsWebLinkLabel webLabel = new DetailsWebLinkLabel("", JLabel.TRAILING);
      webLabel.setIcon(IconNames.INFO_ICON);
      webLabel.setLink(detail.getDescriptionLink(), false);
      TooltipManager.setTooltip(webLabel, detail.getDescriptionLink(), TooltipWay.down, 0);
      return new GroupPanel(GroupingType.fillFirst, 5, webLabel, label);
    }

    label.setForeground(detail.isVisible() ? Color.BLACK : Color.lightGray);
    return label;
  }
Пример #10
0
  private void updateBorder() {
    // Preserve old borders
    if (SwingUtils.isPreserveBorders(radioButton)) {
      return;
    }

    // Actual margin
    final boolean ltr = radioButton.getComponentOrientation().isLeftToRight();
    final Insets m =
        new Insets(
            margin.top,
            ltr ? margin.left : margin.right,
            margin.bottom,
            ltr ? margin.right : margin.left);

    // Installing border
    radioButton.setBorder(LafUtils.createWebBorder(m));
  }
Пример #11
0
  /** {@inheritDoc} */
  @Override
  public void updateBorder() {
    if (splitPane != null) {
      // Preserve old borders
      if (SwingUtils.isPreserveBorders(splitPane)) {
        return;
      }

      // Actual margin
      final boolean ltr = splitPane.getComponentOrientation().isLeftToRight();
      final Insets m =
          new Insets(
              margin.top,
              ltr ? margin.left : margin.right,
              margin.bottom,
              ltr ? margin.right : margin.left);

      // Installing border
      splitPane.setBorder(LafUtils.createWebBorder(m));
    }
  }
Пример #12
0
  /** Additional initializtion of WebWindow settings. */
  protected void initialize() {
    setFocusable(true);
    SwingUtils.setOrientation(this);

    // Adding focus tracker for this window
    // It is stored into a separate field to avoid its disposal from memory
    focusTracker =
        new DefaultFocusTracker(true) {
          @Override
          public boolean isTrackingEnabled() {
            return closeOnFocusLoss;
          }

          @Override
          public void focusChanged(final boolean focused) {
            if (closeOnFocusLoss && WebWindow.this.isShowing() && !focused && !isChildFocused()) {
              setVisible(false);
            }
          }
        };
    FocusManager.addFocusTracker(this, focusTracker);
  }
Пример #13
0
  /**
   * Installs UI in the specified component.
   *
   * @param c component for this UI
   */
  @Override
  public void installUI(final JComponent c) {
    super.installUI(c);

    // Default settings
    SwingUtils.setOrientation(splitPane);
    splitPane.setOpaque(false);
    splitPane.setBorder(null);
    splitPane.setDividerSize(6);

    // Updating border
    updateBorder();

    // Orientation change listener
    propertyChangeListener =
        new PropertyChangeListener() {
          @Override
          public void propertyChange(final PropertyChangeEvent evt) {
            updateBorder();
          }
        };
    splitPane.addPropertyChangeListener(
        WebLookAndFeel.ORIENTATION_PROPERTY, propertyChangeListener);
  }
Пример #14
0
 /** {@inheritDoc} */
 @Override
 public WebTable setFontSizeAndStyle(final int fontSize, final int style) {
   return SwingUtils.setFontSizeAndStyle(this, fontSize, style);
 }
Пример #15
0
 /** {@inheritDoc} */
 @Override
 public WebTable setFontSizeAndStyle(
     final int fontSize, final boolean bold, final boolean italic) {
   return SwingUtils.setFontSizeAndStyle(this, fontSize, bold, italic);
 }
Пример #16
0
 /** {@inheritDoc} */
 @Override
 public int getFontSize() {
   return SwingUtils.getFontSize(this);
 }
Пример #17
0
 /** {@inheritDoc} */
 @Override
 public WebTable changeFontSize(final int change) {
   return SwingUtils.changeFontSize(this, change);
 }
Пример #18
0
 /** {@inheritDoc} */
 @Override
 public WebTable setFontSize(final int fontSize) {
   return SwingUtils.setFontSize(this, fontSize);
 }
Пример #19
0
 /** {@inheritDoc} */
 @Override
 public WebTable setFontStyle(final int style) {
   return SwingUtils.setFontStyle(this, style);
 }
Пример #20
0
 /** {@inheritDoc} */
 @Override
 public boolean isItalicFont() {
   return SwingUtils.isItalicFont(this);
 }
Пример #21
0
 /** {@inheritDoc} */
 @Override
 public WebTable setItalicFont(final boolean apply) {
   return SwingUtils.setItalicFont(this, apply);
 }
Пример #22
0
 /** {@inheritDoc} */
 @Override
 public WebTable setItalicFont() {
   return SwingUtils.setItalicFont(this);
 }
Пример #23
0
 /** {@inheritDoc} */
 @Override
 public boolean isPlainFont() {
   return SwingUtils.isPlainFont(this);
 }
Пример #24
0
 /** {@inheritDoc} */
 @Override
 public WebTable setFontName(final String fontName) {
   return SwingUtils.setFontName(this, fontName);
 }
Пример #25
0
 /** {@inheritDoc} */
 @Override
 public WebComboBox setItalicFont() {
   return SwingUtils.setItalicFont(this);
 }
Пример #26
0
  public static Component createGroupView(WebLookAndFeelDemo owner, ExampleGroup group) {
    // Creating group view
    Component exampleView;
    List<Example> examples = group.getGroupExamples();
    if (group.isSingleExample() && examples.size() == 1) {
      Example example = examples.get(0);
      exampleView = example.getPreview(owner);
    } else {
      final List<Component> preview = new ArrayList<Component>();

      final WebPanel groupPanel =
          new WebPanel() {
            @Override
            public void setEnabled(boolean enabled) {
              for (Component previewComponent : preview) {
                SwingUtils.setEnabledRecursively(previewComponent, enabled);
              }
              super.setEnabled(enabled);
            }
          };
      groupPanel.putClientProperty(SwingUtils.HANDLES_ENABLE_STATE, true);
      groupPanel.setOpaque(false);
      exampleView = groupPanel;

      int rowsAmount = examples.size() > 1 ? examples.size() * 2 - 1 : 1;
      double[] rows = new double[6 + rowsAmount];
      rows[0] = TableLayout.FILL;
      rows[1] = 20;
      rows[2] = TableLayout.PREFERRED;
      for (int i = 3; i < rows.length - 3; i++) {
        rows[i] = TableLayout.PREFERRED;
      }
      rows[rows.length - 3] = TableLayout.PREFERRED;
      rows[rows.length - 2] = 20;
      rows[rows.length - 1] = TableLayout.FILL;

      double[] columns = {
        20,
        1f - group.getContentPartSize(),
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        group.getContentPartSize(),
        20
      };

      TableLayout groupLayout = new TableLayout(new double[][] {columns, rows});
      groupLayout.setHGap(4);
      groupLayout.setVGap(4);
      groupPanel.setLayout(groupLayout);

      groupPanel.add(
          group.modifySeparator(createVerticalSeparator()), "2,0,2," + (rows.length - 1));
      groupPanel.add(
          group.modifySeparator(createVerticalSeparator()), "4,0,4," + (rows.length - 1));
      groupPanel.add(
          group.modifySeparator(createVerticalSeparator()), "6,0,6," + (rows.length - 1));
      groupPanel.add(
          group.modifySeparator(createVerticalSeparator()), "8,0,8," + (rows.length - 1));

      groupPanel.add(
          group.modifySeparator(createHorizontalSeparator()), "0,2," + (columns.length - 1) + ",2");
      groupPanel.add(
          group.modifySeparator(createHorizontalSeparator()),
          "0," + (rows.length - 3) + "," + (columns.length - 1) + "," + (rows.length - 3));

      int row = 3;
      for (Example example : examples) {
        // Title & description
        groupPanel.add(createDescription(example, group), "1," + row);

        // Marks
        Component mark = createMark(owner, example);
        groupPanel.add(mark, "3," + row);

        // Source code
        Component source = createSourceButton(owner, example);
        groupPanel.add(source, "5," + row);

        // More usage examples
        Component usage = createPresentationButton(example);
        groupPanel.add(usage, "7," + row);

        SwingUtils.equalizeComponentsSize(mark, source, usage);

        // Preview
        Component previewComponent = createPreview(owner, example);
        groupPanel.add(previewComponent, "9," + row);
        preview.add(previewComponent);

        // Rows separator
        if (row > 3) {
          groupPanel.add(
              group.modifySeparator(createHorizontalSeparator()),
              "0," + (row - 1) + "," + (columns.length - 1) + "," + (row - 1),
              0);
        }

        row += 2;
      }
    }

    if (group.isShowWatermark()) {
      WebImage linkImage = new WebImage(logoIcon);
      linkImage.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

      TooltipManager.setTooltip(linkImage, linkIcon, "Library site", TooltipWay.trailing);

      linkImage.addMouseListener(
          new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
              WebUtils.browseSiteSafely(WebLookAndFeelDemo.WEBLAF_SITE);
            }
          });

      WebOverlay linkOverlay =
          new WebOverlay(exampleView, linkImage, WebOverlay.LEADING, WebOverlay.BOTTOM);
      linkOverlay.setOverlayMargin(15, 15, 15, 15);
      linkOverlay.setOpaque(false);

      exampleView = linkOverlay;
    }

    return exampleView;
  }
Пример #27
0
 /** {@inheritDoc} */
 @Override
 public WebComboBox setFontSize(final int fontSize) {
   return SwingUtils.setFontSize(this, fontSize);
 }
Пример #28
0
 /** {@inheritDoc} */
 @Override
 public WebComboBox setFontStyle(final boolean bold, final boolean italic) {
   return SwingUtils.setFontStyle(this, bold, italic);
 }
Пример #29
0
 /** {@inheritDoc} */
 @Override
 public String getFontName() {
   return SwingUtils.getFontName(this);
 }
Пример #30
0
 /** {@inheritDoc} */
 @Override
 public WebTable setPlainFont() {
   return SwingUtils.setPlainFont(this);
 }