Java Code Examples for javax.swing.plaf.basic.BasicHTML

The following examples show how to use javax.swing.plaf.basic.BasicHTML. These examples are extracted from open source projects. 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 Project: jdk8u-jdk   Source File: SynthToolTipUI.java    License: 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 2
Source Project: darklaf   Source File: TabbedPaneHandler.java    License: 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 3
Source Project: jdk1.8-source-analysis   Source File: TitledBorder.java    License: 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 4
Source Project: consulo   Source File: DesktopAlertImpl.java    License: 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 5
/**
 * 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 6
Source Project: jdk1.8-source-analysis   Source File: SynthGraphicsUtils.java    License: Apache License 2.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 7
/**
 * {@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 8
Source Project: openjdk-jdk9   Source File: SynthToolTipUI.java    License: 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 9
Source Project: jdk1.8-source-analysis   Source File: SynthToolTipUI.java    License: 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 10
Source Project: jdk1.8-source-analysis   Source File: SynthToolTipUI.java    License: 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 11
Source Project: pgptool   Source File: JXLabel.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void reshape(int x, int y, int w, int h) {
	int oldH = getHeight();
	super.reshape(x, y, w, h);
	if (!isLineWrap()) {
		return;
	}
	if (oldH == 0) {
		return;
	}
	if (w > getVisibleRect().width) {
		w = getVisibleRect().width;
	}
	View view = (View) getClientProperty(BasicHTML.propertyKey);
	if (view != null && view instanceof Renderer) {
		view.setSize(w - occupiedWidth, h);
	}

}
 
Example 12
Source Project: dragonwell8_jdk   Source File: TitledBorder.java    License: 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 13
Source Project: jdk8u_jdk   Source File: SynthGraphicsUtils.java    License: 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 14
Source Project: consulo   Source File: HelpTooltip.java    License: 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 15
/**
 * {@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 16
Source Project: Java8CN   Source File: TitledBorder.java    License: 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 17
/**
 * 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 18
/**
 * 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 19
/**
 * 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 20
/**
 * 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 21
Source Project: TencentKona-8   Source File: SynthToolTipUI.java    License: 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 22
Source Project: jdk8u60   Source File: SynthGraphicsUtils.java    License: 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 23
Source Project: java-swing-tips   Source File: MainPanel.java    License: 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 24
Source Project: jdk8u60   Source File: SynthToolTipUI.java    License: 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 25
Source Project: jdk8u60   Source File: SynthToolTipUI.java    License: 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 Project: jdk8u-jdk   Source File: TitledBorder.java    License: 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 27
Source Project: JDKSourceCode1.8   Source File: TitledBorder.java    License: 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 28
Source Project: jdk8u-jdk   Source File: SynthToolTipUI.java    License: 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 29
Source Project: JDKSourceCode1.8   Source File: SynthGraphicsUtils.java    License: 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 30
Source Project: openjdk-jdk9   Source File: TitledBorder.java    License: 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();
}