javax.swing.plaf.basic.BasicHTML Java Examples

The following examples show how to use javax.swing.plaf.basic.BasicHTML. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SynthGraphicsUtils.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the maximum size needed to properly render an icon and text.
 *
 * @param ss SynthContext
 * @param font Font to use
 * @param text Text to layout
 * @param icon Icon to layout
 * @param hAlign horizontal alignment
 * @param vAlign vertical alignment
 * @param hTextPosition horizontal text position
 * @param vTextPosition vertical text position
 * @param iconTextGap gap between icon and text
 * @param mnemonicIndex Index into text to render the mnemonic at, -1
 *        indicates no mnemonic.
 */
public Dimension getMaximumSize(SynthContext ss, Font font, String text,
                  Icon icon, int hAlign, int vAlign, int hTextPosition,
                  int vTextPosition, int iconTextGap, int mnemonicIndex) {
    JComponent c = ss.getComponent();
    Dimension size = getPreferredSize(ss, font, text, icon, hAlign,
                                      vAlign, hTextPosition, vTextPosition,
                                      iconTextGap, mnemonicIndex);
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);

    if (v != null) {
        size.width += v.getMaximumSpan(View.X_AXIS) -
                      v.getPreferredSpan(View.X_AXIS);
    }
    return size;
}
 
Example #2
Source File: SynthToolTipUI.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void propertyChange(PropertyChangeEvent e) {
    if (SynthLookAndFeel.shouldUpdateStyle(e)) {
        updateStyle((JToolTip)e.getSource());
    }
    String name = e.getPropertyName();
    if (name.equals("tiptext") || "font".equals(name) ||
            "foreground".equals(name)) {
        // remove the old html view client property if one
        // existed, and install a new one if the text installed
        // into the JLabel is html source.
        JToolTip tip = ((JToolTip) e.getSource());
        String text = tip.getTipText();
        BasicHTML.updateRenderer(tip, text);
    }
}
 
Example #3
Source File: SynthToolTipUI.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void propertyChange(PropertyChangeEvent e) {
    if (SynthLookAndFeel.shouldUpdateStyle(e)) {
        updateStyle((JToolTip)e.getSource());
    }
    String name = e.getPropertyName();
    if (name.equals("tiptext") || "font".equals(name) ||
            "foreground".equals(name)) {
        // remove the old html view client property if one
        // existed, and install a new one if the text installed
        // into the JLabel is html source.
        JToolTip tip = ((JToolTip) e.getSource());
        String text = tip.getTipText();
        BasicHTML.updateRenderer(tip, text);
    }
}
 
Example #4
Source File: SynthToolTipUI.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Paints the specified component.
 *
 * @param context context for the component being painted
 * @param g the {@code Graphics} object used for painting
 * @see #update(Graphics,JComponent)
 */
protected void paint(SynthContext context, Graphics g) {
    JToolTip tip = (JToolTip)context.getComponent();

    Insets insets = tip.getInsets();
    View v = (View)tip.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
        Rectangle paintTextR = new Rectangle(insets.left, insets.top,
              tip.getWidth() - (insets.left + insets.right),
              tip.getHeight() - (insets.top + insets.bottom));
        v.paint(g, paintTextR);
    } else {
        g.setColor(context.getStyle().getColor(context,
                                               ColorType.TEXT_FOREGROUND));
        g.setFont(style.getFont(context));
        context.getStyle().getGraphicsUtils(context).paintText(
            context, g, tip.getTipText(), insets.left, insets.top, -1);
    }
}
 
Example #5
Source File: TitledBorder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a TitledBorder instance with the specified border,
 * title, title-justification, title-position, title-font, and
 * title-color.
 *
 * @param border  the border
 * @param title  the title the border should display
 * @param titleJustification the justification for the title
 * @param titlePosition the position for the title
 * @param titleFont the font of the title
 * @param titleColor the color of the title
 */
@ConstructorProperties({"border", "title", "titleJustification", "titlePosition", "titleFont", "titleColor"})
public TitledBorder(Border border,
                    String title,
                    int titleJustification,
                    int titlePosition,
                    Font titleFont,
                    Color titleColor) {
    this.title = title;
    this.border = border;
    this.titleFont = titleFont;
    this.titleColor = titleColor;

    setTitleJustification(titleJustification);
    setTitlePosition(titlePosition);

    this.label = new JLabel();
    this.label.setOpaque(false);
    this.label.putClientProperty(BasicHTML.propertyKey, null);
}
 
Example #6
Source File: DesktopAlertImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public JTextPane configureMessagePaneUi(@Nonnull JTextPane messageComponent, @Nullable String message, @Nullable UIUtil.FontSize fontSize) {
  UIUtil.FontSize fixedFontSize = fontSize == null ? UIUtil.FontSize.NORMAL : fontSize;
  messageComponent.setFont(UIUtil.getLabelFont(fixedFontSize));
  if (BasicHTML.isHTMLString(message)) {
    HTMLEditorKit editorKit = new HTMLEditorKit();
    Font font = UIUtil.getLabelFont(fixedFontSize);
    editorKit.getStyleSheet().addRule(UIUtil.displayPropertiesToCSS(font, UIUtil.getLabelForeground()));
    messageComponent.setEditorKit(editorKit);
    messageComponent.setContentType(UIUtil.HTML_MIME);
  }
  messageComponent.setText(message);
  messageComponent.setEditable(false);
  if (messageComponent.getCaret() != null) {
    messageComponent.setCaretPosition(0);
  }

  messageComponent.setBackground(UIUtil.getOptionPaneBackground());
  messageComponent.setForeground(UIUtil.getLabelForeground());
  return messageComponent;
}
 
Example #7
Source File: TitledBorder.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a TitledBorder instance with the specified border,
 * title, title-justification, title-position, title-font, and
 * title-color.
 *
 * @param border  the border
 * @param title  the title the border should display
 * @param titleJustification the justification for the title
 * @param titlePosition the position for the title
 * @param titleFont the font of the title
 * @param titleColor the color of the title
 */
@ConstructorProperties({"border", "title", "titleJustification", "titlePosition", "titleFont", "titleColor"})
public TitledBorder(Border border,
                    String title,
                    int titleJustification,
                    int titlePosition,
                    Font titleFont,
                    Color titleColor) {
    this.title = title;
    this.border = border;
    this.titleFont = titleFont;
    this.titleColor = titleColor;

    setTitleJustification(titleJustification);
    setTitlePosition(titlePosition);

    this.label = new JLabel();
    this.label.setOpaque(false);
    this.label.putClientProperty(BasicHTML.propertyKey, null);
}
 
Example #8
Source File: TabbedPaneHandler.java    From darklaf with MIT License 6 votes vote down vote up
protected void updateHtmlViews(final int index, final boolean inserted) {
    String title = ui.tabPane.getTitleAt(index);
    boolean isHTML = BasicHTML.isHTMLString(title);
    if (isHTML) {
        if (ui.htmlViews == null) { // Initialize vector
            ui.htmlViews = ui.createHTMLVector();
        } else { // Vector already exists
            View v = BasicHTML.createHTMLView(ui.tabPane, title);
            setHtmlView(v, inserted, index);
        }
    } else { // Not HTML
        if (ui.htmlViews != null) { // Add placeholder
            setHtmlView(null, inserted, index);
        } // else nada!
    }
    ui.updateMnemonics();
}
 
Example #9
Source File: HelpTooltip.java    From consulo with Apache License 2.0 6 votes vote down vote up
void setSizeForWidth(float width) {
  if (width > MAX_WIDTH.get()) {
    View v = (View)getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
      width = 0.0f;
      for (View row : getRows(v)) {
        float rWidth = row.getPreferredSpan(View.X_AXIS);
        if (width < rWidth) {
          width = rWidth;
        }
      }

      v.setSize(width, v.getPreferredSpan(View.Y_AXIS));
    }
  }
}
 
Example #10
Source File: SynthToolTipUI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void propertyChange(PropertyChangeEvent e) {
    if (SynthLookAndFeel.shouldUpdateStyle(e)) {
        updateStyle((JToolTip)e.getSource());
    }
    String name = e.getPropertyName();
    if (name.equals("tiptext") || "font".equals(name) ||
            "foreground".equals(name)) {
        // remove the old html view client property if one
        // existed, and install a new one if the text installed
        // into the JLabel is html source.
        JToolTip tip = ((JToolTip) e.getSource());
        String text = tip.getTipText();
        BasicHTML.updateRenderer(tip, text);
    }
}
 
Example #11
Source File: TitledBorder.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a TitledBorder instance with the specified border,
 * title, title-justification, title-position, title-font, and
 * title-color.
 *
 * @param border  the border
 * @param title  the title the border should display
 * @param titleJustification the justification for the title
 * @param titlePosition the position for the title
 * @param titleFont the font of the title
 * @param titleColor the color of the title
 */
@ConstructorProperties({"border", "title", "titleJustification", "titlePosition", "titleFont", "titleColor"})
public TitledBorder(Border border,
                    String title,
                    int titleJustification,
                    int titlePosition,
                    Font titleFont,
                    Color titleColor) {
    this.title = title;
    this.border = border;
    this.titleFont = titleFont;
    this.titleColor = titleColor;

    setTitleJustification(titleJustification);
    setTitlePosition(titlePosition);

    this.label = new JLabel();
    this.label.setOpaque(false);
    this.label.putClientProperty(BasicHTML.propertyKey, null);
}
 
Example #12
Source File: SynthToolTipUI.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void propertyChange(PropertyChangeEvent e) {
    if (SynthLookAndFeel.shouldUpdateStyle(e)) {
        updateStyle((JToolTip)e.getSource());
    }
    String name = e.getPropertyName();
    if (name.equals("tiptext") || "font".equals(name) ||
            "foreground".equals(name)) {
        // remove the old html view client property if one
        // existed, and install a new one if the text installed
        // into the JLabel is html source.
        JToolTip tip = ((JToolTip) e.getSource());
        String text = tip.getTipText();
        BasicHTML.updateRenderer(tip, text);
    }
}
 
Example #13
Source File: TitledBorder.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a TitledBorder instance with the specified border,
 * title, title-justification, title-position, title-font, and
 * title-color.
 *
 * @param border  the border
 * @param title  the title the border should display
 * @param titleJustification the justification for the title
 * @param titlePosition the position for the title
 * @param titleFont the font of the title
 * @param titleColor the color of the title
 */
@ConstructorProperties({"border", "title", "titleJustification", "titlePosition", "titleFont", "titleColor"})
public TitledBorder(Border border,
                    String title,
                    int titleJustification,
                    int titlePosition,
                    Font titleFont,
                    Color titleColor) {
    this.title = title;
    this.border = border;
    this.titleFont = titleFont;
    this.titleColor = titleColor;

    setTitleJustification(titleJustification);
    setTitlePosition(titlePosition);

    this.label = new JLabel();
    this.label.setOpaque(false);
    this.label.putClientProperty(BasicHTML.propertyKey, null);
}
 
Example #14
Source File: SynthGraphicsUtils.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the minimum size needed to properly render an icon and text.
 *
 * @param ss SynthContext
 * @param font Font to use
 * @param text Text to layout
 * @param icon Icon to layout
 * @param hAlign horizontal alignment
 * @param vAlign vertical alignment
 * @param hTextPosition horizontal text position
 * @param vTextPosition vertical text position
 * @param iconTextGap gap between icon and text
 * @param mnemonicIndex Index into text to render the mnemonic at, -1
 *        indicates no mnemonic.
 */
public Dimension getMinimumSize(SynthContext ss, Font font, String text,
                  Icon icon, int hAlign, int vAlign, int hTextPosition,
                  int vTextPosition, int iconTextGap, int mnemonicIndex) {
    JComponent c = ss.getComponent();
    Dimension size = getPreferredSize(ss, font, text, icon, hAlign,
                                      vAlign, hTextPosition, vTextPosition,
                                      iconTextGap, mnemonicIndex);
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);

    if (v != null) {
        size.width -= v.getPreferredSpan(View.X_AXIS) -
                      v.getMinimumSpan(View.X_AXIS);
    }
    return size;
}
 
Example #15
Source File: SynthGraphicsUtils.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the maximum size needed to properly render an icon and text.
 *
 * @param ss SynthContext
 * @param font Font to use
 * @param text Text to layout
 * @param icon Icon to layout
 * @param hAlign horizontal alignment
 * @param vAlign vertical alignment
 * @param hTextPosition horizontal text position
 * @param vTextPosition vertical text position
 * @param iconTextGap gap between icon and text
 * @param mnemonicIndex Index into text to render the mnemonic at, -1
 *        indicates no mnemonic.
 */
public Dimension getMaximumSize(SynthContext ss, Font font, String text,
                  Icon icon, int hAlign, int vAlign, int hTextPosition,
                  int vTextPosition, int iconTextGap, int mnemonicIndex) {
    JComponent c = ss.getComponent();
    Dimension size = getPreferredSize(ss, font, text, icon, hAlign,
                                      vAlign, hTextPosition, vTextPosition,
                                      iconTextGap, mnemonicIndex);
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);

    if (v != null) {
        size.width += v.getMaximumSpan(View.X_AXIS) -
                      v.getPreferredSpan(View.X_AXIS);
    }
    return size;
}
 
Example #16
Source File: SynthToolTipUI.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void propertyChange(PropertyChangeEvent e) {
    if (SynthLookAndFeel.shouldUpdateStyle(e)) {
        updateStyle((JToolTip)e.getSource());
    }
    String name = e.getPropertyName();
    if (name.equals("tiptext") || "font".equals(name) ||
            "foreground".equals(name)) {
        // remove the old html view client property if one
        // existed, and install a new one if the text installed
        // into the JLabel is html source.
        JToolTip tip = ((JToolTip) e.getSource());
        String text = tip.getTipText();
        BasicHTML.updateRenderer(tip, text);
    }
}
 
Example #17
Source File: SynthGraphicsUtils.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the maximum size needed to properly render an icon and text.
 *
 * @param ss SynthContext
 * @param font Font to use
 * @param text Text to layout
 * @param icon Icon to layout
 * @param hAlign horizontal alignment
 * @param vAlign vertical alignment
 * @param hTextPosition horizontal text position
 * @param vTextPosition vertical text position
 * @param iconTextGap gap between icon and text
 * @param mnemonicIndex Index into text to render the mnemonic at, -1
 *        indicates no mnemonic.
 */
public Dimension getMaximumSize(SynthContext ss, Font font, String text,
                  Icon icon, int hAlign, int vAlign, int hTextPosition,
                  int vTextPosition, int iconTextGap, int mnemonicIndex) {
    JComponent c = ss.getComponent();
    Dimension size = getPreferredSize(ss, font, text, icon, hAlign,
                                      vAlign, hTextPosition, vTextPosition,
                                      iconTextGap, mnemonicIndex);
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);

    if (v != null) {
        size.width += v.getMaximumSpan(View.X_AXIS) -
                      v.getPreferredSpan(View.X_AXIS);
    }
    return size;
}
 
Example #18
Source File: SynthToolTipUI.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void propertyChange(PropertyChangeEvent e) {
    if (SynthLookAndFeel.shouldUpdateStyle(e)) {
        updateStyle((JToolTip)e.getSource());
    }
    String name = e.getPropertyName();
    if (name.equals("tiptext") || "font".equals(name) ||
            "foreground".equals(name)) {
        // remove the old html view client property if one
        // existed, and install a new one if the text installed
        // into the JLabel is html source.
        JToolTip tip = ((JToolTip) e.getSource());
        String text = tip.getTipText();
        BasicHTML.updateRenderer(tip, text);
    }
}
 
Example #19
Source File: SynthGraphicsUtils.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the minimum size needed to properly render an icon and text.
 *
 * @param ss SynthContext
 * @param font Font to use
 * @param text Text to layout
 * @param icon Icon to layout
 * @param hAlign horizontal alignment
 * @param vAlign vertical alignment
 * @param hTextPosition horizontal text position
 * @param vTextPosition vertical text position
 * @param iconTextGap gap between icon and text
 * @param mnemonicIndex Index into text to render the mnemonic at, -1
 *        indicates no mnemonic.
 */
public Dimension getMinimumSize(SynthContext ss, Font font, String text,
                  Icon icon, int hAlign, int vAlign, int hTextPosition,
                  int vTextPosition, int iconTextGap, int mnemonicIndex) {
    JComponent c = ss.getComponent();
    Dimension size = getPreferredSize(ss, font, text, icon, hAlign,
                                      vAlign, hTextPosition, vTextPosition,
                                      iconTextGap, mnemonicIndex);
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);

    if (v != null) {
        size.width -= v.getPreferredSpan(View.X_AXIS) -
                      v.getMinimumSpan(View.X_AXIS);
    }
    return size;
}
 
Example #20
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
public static int getFirstLineCenterY(String text, AbstractButton c, Rectangle iconRect) {
  int y = 0;
  if (Objects.nonNull(text) && c.getVerticalTextPosition() == SwingConstants.TOP) {
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);
    if (Objects.nonNull(v)) {
      try {
        Element e = v.getElement().getElement(0);
        Shape s = new Rectangle();
        Position.Bias b = Position.Bias.Forward;
        s = v.modelToView(e.getStartOffset(), b, e.getEndOffset(), b, s);
        // System.out.println("v.h: " + s.getBounds());
        y = Math.round(Math.abs(s.getBounds().height - iconRect.height) / 2f);
      } catch (BadLocationException ex) {
        // should never happen
        RuntimeException wrap = new StringIndexOutOfBoundsException(ex.offsetRequested());
        wrap.initCause(ex);
        throw wrap;
      }
    }
  }
  return y;
}
 
Example #21
Source File: SynthToolTipUI.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Paints the specified component.
 *
 * @param context context for the component being painted
 * @param g the {@code Graphics} object used for painting
 * @see #update(Graphics,JComponent)
 */
protected void paint(SynthContext context, Graphics g) {
    JToolTip tip = (JToolTip)context.getComponent();

    Insets insets = tip.getInsets();
    View v = (View)tip.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
        Rectangle paintTextR = new Rectangle(insets.left, insets.top,
              tip.getWidth() - (insets.left + insets.right),
              tip.getHeight() - (insets.top + insets.bottom));
        v.paint(g, paintTextR);
    } else {
        g.setColor(context.getStyle().getColor(context,
                                               ColorType.TEXT_FOREGROUND));
        g.setFont(style.getFont(context));
        context.getStyle().getGraphicsUtils(context).paintText(
            context, g, tip.getTipText(), insets.left, insets.top, -1);
    }
}
 
Example #22
Source File: SynthToolTipUI.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void propertyChange(PropertyChangeEvent e) {
    if (SynthLookAndFeel.shouldUpdateStyle(e)) {
        updateStyle((JToolTip)e.getSource());
    }
    String name = e.getPropertyName();
    if (name.equals("tiptext") || "font".equals(name) ||
            "foreground".equals(name)) {
        // remove the old html view client property if one
        // existed, and install a new one if the text installed
        // into the JLabel is html source.
        JToolTip tip = ((JToolTip) e.getSource());
        String text = tip.getTipText();
        BasicHTML.updateRenderer(tip, text);
    }
}
 
Example #23
Source File: TitledBorder.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a TitledBorder instance with the specified border,
 * title, title-justification, title-position, title-font, and
 * title-color.
 *
 * @param border  the border
 * @param title  the title the border should display
 * @param titleJustification the justification for the title
 * @param titlePosition the position for the title
 * @param titleFont the font of the title
 * @param titleColor the color of the title
 */
@ConstructorProperties({"border", "title", "titleJustification", "titlePosition", "titleFont", "titleColor"})
public TitledBorder(Border border,
                    String title,
                    int titleJustification,
                    int titlePosition,
                    Font titleFont,
                    Color titleColor) {
    this.title = title;
    this.border = border;
    this.titleFont = titleFont;
    this.titleColor = titleColor;

    setTitleJustification(titleJustification);
    setTitlePosition(titlePosition);

    this.label = new JLabel();
    this.label.setOpaque(false);
    this.label.putClientProperty(BasicHTML.propertyKey, null);
}
 
Example #24
Source File: TitledBorder.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Creates a TitledBorder instance with the specified border,
 * title, title-justification, title-position, title-font, and
 * title-color.
 *
 * @param border  the border
 * @param title  the title the border should display
 * @param titleJustification the justification for the title
 * @param titlePosition the position for the title
 * @param titleFont the font of the title
 * @param titleColor the color of the title
 */
@ConstructorProperties({"border", "title", "titleJustification", "titlePosition", "titleFont", "titleColor"})
public TitledBorder(Border border,
                    String title,
                    int titleJustification,
                    int titlePosition,
                    Font titleFont,
                    Color titleColor) {
    this.title = title;
    this.border = border;
    this.titleFont = titleFont;
    this.titleColor = titleColor;

    setTitleJustification(titleJustification);
    setTitlePosition(titlePosition);

    this.label = new JLabel();
    this.label.setOpaque(false);
    this.label.putClientProperty(BasicHTML.propertyKey, null);
}
 
Example #25
Source File: SynthToolTipUI.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void propertyChange(PropertyChangeEvent e) {
    if (SynthLookAndFeel.shouldUpdateStyle(e)) {
        updateStyle((JToolTip)e.getSource());
    }
    String name = e.getPropertyName();
    if (name.equals("tiptext") || "font".equals(name) ||
            "foreground".equals(name)) {
        // remove the old html view client property if one
        // existed, and install a new one if the text installed
        // into the JLabel is html source.
        JToolTip tip = ((JToolTip) e.getSource());
        String text = tip.getTipText();
        BasicHTML.updateRenderer(tip, text);
    }
}
 
Example #26
Source File: SynthGraphicsUtils.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Returns the maximum size needed to properly render an icon and text.
 *
 * @param ss SynthContext
 * @param font Font to use
 * @param text Text to layout
 * @param icon Icon to layout
 * @param hAlign horizontal alignment
 * @param vAlign vertical alignment
 * @param hTextPosition horizontal text position
 * @param vTextPosition vertical text position
 * @param iconTextGap gap between icon and text
 * @param mnemonicIndex Index into text to render the mnemonic at, -1
 *        indicates no mnemonic.
 */
public Dimension getMaximumSize(SynthContext ss, Font font, String text,
                  Icon icon, int hAlign, int vAlign, int hTextPosition,
                  int vTextPosition, int iconTextGap, int mnemonicIndex) {
    JComponent c = ss.getComponent();
    Dimension size = getPreferredSize(ss, font, text, icon, hAlign,
                                      vAlign, hTextPosition, vTextPosition,
                                      iconTextGap, mnemonicIndex);
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);

    if (v != null) {
        size.width += v.getMaximumSpan(View.X_AXIS) -
                      v.getPreferredSpan(View.X_AXIS);
    }
    return size;
}
 
Example #27
Source File: TitledBorder.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a TitledBorder instance with the specified border,
 * title, title-justification, title-position, title-font, and
 * title-color.
 *
 * @param border  the border
 * @param title  the title the border should display
 * @param titleJustification the justification for the title
 * @param titlePosition the position for the title
 * @param titleFont the font of the title
 * @param titleColor the color of the title
 */
@ConstructorProperties({"border", "title", "titleJustification", "titlePosition", "titleFont", "titleColor"})
public TitledBorder(Border border,
                    String title,
                    int titleJustification,
                    int titlePosition,
                    Font titleFont,
                    Color titleColor) {
    this.title = title;
    this.border = border;
    this.titleFont = titleFont;
    this.titleColor = titleColor;

    setTitleJustification(titleJustification);
    setTitlePosition(titlePosition);

    this.label = new JLabel();
    this.label.setOpaque(false);
    this.label.putClientProperty(BasicHTML.propertyKey, null);
    installPropertyChangeListeners();
}
 
Example #28
Source File: SynthGraphicsUtils.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the maximum size needed to properly render an icon and text.
 *
 * @param ss SynthContext
 * @param font Font to use
 * @param text Text to layout
 * @param icon Icon to layout
 * @param hAlign horizontal alignment
 * @param vAlign vertical alignment
 * @param hTextPosition horizontal text position
 * @param vTextPosition vertical text position
 * @param iconTextGap gap between icon and text
 * @param mnemonicIndex Index into text to render the mnemonic at, -1
 *        indicates no mnemonic.
 */
public Dimension getMaximumSize(SynthContext ss, Font font, String text,
                  Icon icon, int hAlign, int vAlign, int hTextPosition,
                  int vTextPosition, int iconTextGap, int mnemonicIndex) {
    JComponent c = ss.getComponent();
    Dimension size = getPreferredSize(ss, font, text, icon, hAlign,
                                      vAlign, hTextPosition, vTextPosition,
                                      iconTextGap, mnemonicIndex);
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);

    if (v != null) {
        size.width += v.getMaximumSpan(View.X_AXIS) -
                      v.getPreferredSpan(View.X_AXIS);
    }
    return size;
}
 
Example #29
Source File: SynthGraphicsUtils.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the maximum size needed to properly render an icon and text.
 *
 * @param ss SynthContext
 * @param font Font to use
 * @param text Text to layout
 * @param icon Icon to layout
 * @param hAlign horizontal alignment
 * @param vAlign vertical alignment
 * @param hTextPosition horizontal text position
 * @param vTextPosition vertical text position
 * @param iconTextGap gap between icon and text
 * @param mnemonicIndex Index into text to render the mnemonic at, -1
 *        indicates no mnemonic.
 */
public Dimension getMaximumSize(SynthContext ss, Font font, String text,
                  Icon icon, int hAlign, int vAlign, int hTextPosition,
                  int vTextPosition, int iconTextGap, int mnemonicIndex) {
    JComponent c = ss.getComponent();
    Dimension size = getPreferredSize(ss, font, text, icon, hAlign,
                                      vAlign, hTextPosition, vTextPosition,
                                      iconTextGap, mnemonicIndex);
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);

    if (v != null) {
        size.width += v.getMaximumSpan(View.X_AXIS) -
                      v.getPreferredSpan(View.X_AXIS);
    }
    return size;
}
 
Example #30
Source File: SeaGlassToolTipUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * Paints the specified component.
 *
 * @param context
 *            context for the component being painted
 * @param g
 *            the {@code Graphics} object used for painting
 * @see #update(Graphics,JComponent)
 */
protected void paint(SynthContext context, Graphics g) {
    JToolTip tip = (JToolTip) context.getComponent();

    Insets insets = tip.getInsets();
    View v = (View) tip.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
        Rectangle paintTextR = new Rectangle(insets.left, insets.top, tip.getWidth() - (insets.left + insets.right), tip.getHeight()
                - (insets.top + insets.bottom));
        v.paint(g, paintTextR);
    } else {
        g.setColor(context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND));
        g.setFont(style.getFont(context));
        context.getStyle().getGraphicsUtils(context).paintText(context, g, tip.getTipText(), insets.left, insets.top, -1);
    }
}