javax.swing.text.View Java Examples

The following examples show how to use javax.swing.text.View. 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: AquaTabbedPaneUI.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
    final View v = getTextViewForTab(tabIndex);
    if (v != null) {
        v.paint(g2d, textRect);
        return;
    }

    if (title == null) return;

    final Color color = tabPane.getForegroundAt(tabIndex);
    if (color instanceof UIResource) {
        // sja fix getTheme().setThemeTextColor(g, isSelected, isPressed && tracking, tabPane.isEnabledAt(tabIndex));
        if (tabPane.isEnabledAt(tabIndex)) {
            g2d.setColor(Color.black);
        } else {
            g2d.setColor(Color.gray);
        }
    } else {
        g2d.setColor(color);
    }

    g2d.setFont(font);
    SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
}
 
Example #2
Source File: AquaTabbedPaneCopyFromBasicUI.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void layoutLabel(final int tabPlacement, final FontMetrics metrics, final int tabIndex, final String title, final Icon icon, final Rectangle tabRect, final Rectangle iconRect, final Rectangle textRect, final boolean isSelected) {
    textRect.x = textRect.y = iconRect.x = iconRect.y = 0;

    final View v = getTextViewForTab(tabIndex);
    if (v != null) {
        tabPane.putClientProperty("html", v);
    }

    SwingUtilities.layoutCompoundLabel(tabPane, metrics, title, icon, SwingConstants.CENTER, SwingConstants.CENTER, SwingConstants.CENTER, SwingConstants.TRAILING, tabRect, iconRect, textRect, textIconGap);

    tabPane.putClientProperty("html", null);

    final int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);
    final int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);
    iconRect.x += xNudge;
    iconRect.y += yNudge;
    textRect.x += xNudge;
    textRect.y += yNudge;
}
 
Example #3
Source File: AquaTabbedPaneUI.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
    final View v = getTextViewForTab(tabIndex);
    if (v != null) {
        v.paint(g2d, textRect);
        return;
    }

    if (title == null) return;

    final Color color = tabPane.getForegroundAt(tabIndex);
    if (color instanceof UIResource) {
        // sja fix getTheme().setThemeTextColor(g, isSelected, isPressed && tracking, tabPane.isEnabledAt(tabIndex));
        if (tabPane.isEnabledAt(tabIndex)) {
            g2d.setColor(Color.black);
        } else {
            g2d.setColor(Color.gray);
        }
    } else {
        g2d.setColor(color);
    }

    g2d.setFont(font);
    SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
}
 
Example #4
Source File: BasicTabbedPaneUI.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the tab width.
 * @param tabPlacement  the placement (left, right, bottom, top) of the tab
 * @param tabIndex      the index of the tab with respect to other tabs
 * @param metrics       the font metrics
 * @return the tab width
 */
protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) {
    Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
    int width = tabInsets.left + tabInsets.right + 3;
    Component tabComponent = tabPane.getTabComponentAt(tabIndex);
    if (tabComponent != null) {
        width += tabComponent.getPreferredSize().width;
    } else {
        Icon icon = getIconForTab(tabIndex);
        if (icon != null) {
            width += icon.getIconWidth() + textIconGap;
        }
        View v = getTextViewForTab(tabIndex);
        if (v != null) {
            // html
            width += (int) v.getPreferredSpan(View.X_AXIS);
        } else {
            // plain text
            String title = tabPane.getTitleAt(tabIndex);
            width += SwingUtilities2.stringWidth(tabPane, metrics, title);
        }
    }
    return width;
}
 
Example #5
Source File: SubstanceToolTipUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public Dimension getPreferredSize(JComponent c) {
	Font font = c.getFont();
	Insets insets = c.getInsets();

	Dimension prefSize = new Dimension(insets.left + insets.right,
			insets.top + insets.bottom);
	String text = ((JToolTip) c).getTipText();

	if ((text == null) || text.equals("")) {
		text = "";
	} else {
		View v = (c != null) ? (View) c.getClientProperty("html") : null;
		if (v != null) {
			// fix for 302 - add extra pixels for the HTML view as well
			prefSize.width += (int) (v.getPreferredSpan(View.X_AXIS) + 6);
			prefSize.height += (int) (v.getPreferredSpan(View.Y_AXIS) + 2);
		} else {
			FontMetrics fm = SubstanceMetricsUtilities.getFontMetrics(font);
			prefSize.width += fm.stringWidth(text) + 6;
			prefSize.height += fm.getHeight() + 2;
		}
	}
	return prefSize;
}
 
Example #6
Source File: BasicTabbedPaneUI.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void updateHtmlViews(int index) {
    String title = tabPane.getTitleAt(index);
    boolean isHTML = BasicHTML.isHTMLString(title);
    if (isHTML) {
        if (htmlViews==null) {    // Initialize vector
            htmlViews = createHTMLVector();
        } else {                  // Vector already exists
            View v = BasicHTML.createHTMLView(tabPane, title);
            htmlViews.insertElementAt(v, index);
        }
    } else {                             // Not HTML
        if (htmlViews!=null) {           // Add placeholder
            htmlViews.insertElementAt(null, index);
        }                                // else nada!
    }
    updateMnemonics();
}
 
Example #7
Source File: AquaTabbedPaneContrastUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
    final View v = getTextViewForTab(tabIndex);
    if (v != null) {
        v.paint(g2d, textRect);
        return;
    }

    if (title == null) return;

    final Color color = tabPane.getForegroundAt(tabIndex);
    if (color instanceof UIResource) {
        g2d.setColor(getNonSelectedTabTitleColor());
        if (tabPane.getSelectedIndex() == tabIndex) {
            boolean pressed = isPressedAt(tabIndex);
            boolean enabled = tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex);
            Color textColor = getSelectedTabTitleColor(enabled, pressed);
            Color shadowColor = getSelectedTabTitleShadowColor(enabled);
            AquaUtils.paintDropShadowText(g2d, tabPane, font, metrics, textRect.x, textRect.y, 0, 1, textColor, shadowColor, title);
            return;
        }
    } else {
        g2d.setColor(color);
    }
    g2d.setFont(font);
    SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
}
 
Example #8
Source File: BaseView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Helper for displaying hierarchy - called recursively.
* @param origView view for which the displayHierarchy method was originally
*  called. It is marked by asterisk.
* @param col column offset
* @param index index of this view in parent children[] array
*/
private void displayHierarchyHelper(View origView, int col, int index) {
    StringBuffer buf = new StringBuffer();
    buf.append(((this == origView) ? "*" : " ")); // NOI18N
    for (int i = 0; i < col; i++) {
        buf.append(' ');
    }
    buf.append('[');
    buf.append(Integer.toString(index));
    buf.append("] "); // NOI18N
    buf.append(this.toString());
    System.out.println(buf);
    int childrenCnt = getViewCount();
    if (childrenCnt > 0) {
        for (int i = 0; i < childrenCnt; i++) {
            ((BaseView)getView(i)).displayHierarchyHelper(origView, col + 1, i);
        }
    }

}
 
Example #9
Source File: SynthTabbedPaneUI.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void paintText(SynthContext ss,
                         Graphics g, int tabPlacement,
                         Font font, FontMetrics metrics, int tabIndex,
                         String title, Rectangle textRect,
                         boolean isSelected) {
    g.setFont(font);

    View v = getTextViewForTab(tabIndex);
    if (v != null) {
        // html
        v.paint(g, textRect);
    } else {
        // plain text
        int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);

        g.setColor(ss.getStyle().getColor(ss, ColorType.TEXT_FOREGROUND));
        ss.getStyle().getGraphicsUtils(ss).paintText(ss, g, title,
                              textRect, mnemIndex);
    }
}
 
Example #10
Source File: SynthTabbedPaneUI.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void paintText(SynthContext ss,
                         Graphics g, int tabPlacement,
                         Font font, FontMetrics metrics, int tabIndex,
                         String title, Rectangle textRect,
                         boolean isSelected) {
    g.setFont(font);

    View v = getTextViewForTab(tabIndex);
    if (v != null) {
        // html
        v.paint(g, textRect);
    } else {
        // plain text
        int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);

        g.setColor(ss.getStyle().getColor(ss, ColorType.TEXT_FOREGROUND));
        ss.getStyle().getGraphicsUtils(ss).paintText(ss, g, title,
                              textRect, mnemIndex);
    }
}
 
Example #11
Source File: SynthToolTipUI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Dimension getPreferredSize(JComponent c) {
    SynthContext context = getContext(c);
    Insets insets = c.getInsets();
    Dimension prefSize = new Dimension(insets.left+insets.right,
                                       insets.top+insets.bottom);
    String text = ((JToolTip)c).getTipText();

    if (text != null) {
        View v = (c != null) ? (View) c.getClientProperty("html") : null;
        if (v != null) {
            prefSize.width += (int) v.getPreferredSpan(View.X_AXIS);
            prefSize.height += (int) v.getPreferredSpan(View.Y_AXIS);
        } else {
            Font font = context.getStyle().getFont(context);
            FontMetrics fm = c.getFontMetrics(font);
            prefSize.width += context.getStyle().getGraphicsUtils(context).
                              computeStringWidth(context, font, fm, text);
            prefSize.height += fm.getHeight();
        }
    }
    context.dispose();
    return prefSize;
}
 
Example #12
Source File: BasicTabbedPaneUI.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private void updateHtmlViews(int index) {
    String title = tabPane.getTitleAt(index);
    boolean isHTML = BasicHTML.isHTMLString(title);
    if (isHTML) {
        if (htmlViews==null) {    // Initialize vector
            htmlViews = createHTMLVector();
        } else {                  // Vector already exists
            View v = BasicHTML.createHTMLView(tabPane, title);
            htmlViews.insertElementAt(v, index);
        }
    } else {                             // Not HTML
        if (htmlViews!=null) {           // Add placeholder
            htmlViews.insertElementAt(null, index);
        }                                // else nada!
    }
    updateMnemonics();
}
 
Example #13
Source File: InlineBoxView.java    From SwingBox with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void paint(Graphics graphics, Shape allocation)
{
    if (box.isDisplayed())
    {
        Graphics2D g = (Graphics2D) graphics;
        // super.paint(g, allocation);

        box.getVisualContext().updateGraphics(g);
        box.drawBackground(g);
        int n = getViewCount();
        // Rectangle alloc = allocation instanceof Rectangle ? (Rectangle)
        // allocation : allocation.getBounds();

        for (int i = 0; i < n; i++)
        {
            View v = getView(i);
            v.paint(g, allocation);
        }

    }
}
 
Example #14
Source File: BasicTabbedPaneUI.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) {
    int height = 0;
    Component c = tabPane.getTabComponentAt(tabIndex);
    if (c != null) {
        height = c.getPreferredSize().height;
    } else {
        View v = getTextViewForTab(tabIndex);
        if (v != null) {
            // html
            height += (int) v.getPreferredSpan(View.Y_AXIS);
        } else {
            // plain text
            height += fontHeight;
        }
        Icon icon = getIconForTab(tabIndex);

        if (icon != null) {
            height = Math.max(height, icon.getIconHeight());
        }
    }
    Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
    height += tabInsets.top + tabInsets.bottom + 2;
    return height;
}
 
Example #15
Source File: bug6670274.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static void check(TestTabbedPaneUI ui, int... indices) {
    for(int i = 0; i < ui.getTabbedPane().getTabCount(); i++) {
        System.out.print("Checking tab #" + i);
        View view = ui.getTextViewForTab(i);
        boolean found = false;
        for (int j = 0; j < indices.length; j++) {
            if (indices[j]== i) {
                found = true;
                break;
            }
        }
        System.out.print("; view = " + view);
        if (found) {
            if (view == null) {
                throw new RuntimeException("View is unexpectedly null");
            }
        } else if (view != null) {
            throw new RuntimeException("View is unexpectedly not null");
        }
        System.out.println(" ok");
    }
    System.out.println("");
}
 
Example #16
Source File: CloseTabPaneUI.java    From iBioSim with Apache License 2.0 6 votes vote down vote up
@Override
public void componentAdded(ContainerEvent e) {
	JTabbedPane tp = (JTabbedPane) e.getContainer();
	Component child = e.getChild();
	if (child instanceof UIResource) {
		return;
	}
	int index = tp.indexOfComponent(child);
	String title = tp.getTitleAt(index);
	boolean isHTML = BasicHTML.isHTMLString(title);
	if (isHTML) {
		if (htmlViews == null) { // Initialize vector
			htmlViews = createHTMLVector();
		}
		else { // Vector already exists
			View v = BasicHTML.createHTMLView(tp, title);
			htmlViews.insertElementAt(v, index);
		}
	}
	else { // Not HTML
		if (htmlViews != null) { // Add placeholder
			htmlViews.insertElementAt(null, index);
		} // else nada!
	}
}
 
Example #17
Source File: AquaTabbedPaneCopyFromBasicUI.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
protected int calculateTabWidth(final int tabPlacement, final int tabIndex, final FontMetrics metrics) {
    final Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
    int width = tabInsets.left + tabInsets.right + 3;
    final Component tabComponent = tabPane.getTabComponentAt(tabIndex);
    if (tabComponent != null) {
        width += tabComponent.getPreferredSize().width;
    } else {
        final Icon icon = getIconForTab(tabIndex);
        if (icon != null) {
            width += icon.getIconWidth() + textIconGap;
        }
        final View v = getTextViewForTab(tabIndex);
        if (v != null) {
            // html
            width += (int)v.getPreferredSpan(View.X_AXIS);
        } else {
            // plain text
            final String title = tabPane.getTitleAt(tabIndex);
            width += SwingUtilities2.stringWidth(tabPane, metrics, title);
        }
    }
    return width;
}
 
Example #18
Source File: BasicToolTipUI.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public Dimension getPreferredSize(JComponent c) {
    Font font = c.getFont();
    FontMetrics fm = c.getFontMetrics(font);
    Insets insets = c.getInsets();

    Dimension prefSize = new Dimension(insets.left+insets.right,
                                       insets.top+insets.bottom);
    String text = ((JToolTip)c).getTipText();

    if ((text == null) || text.equals("")) {
        text = "";
    }
    else {
        View v = (c != null) ? (View) c.getClientProperty("html") : null;
        if (v != null) {
            prefSize.width += (int) v.getPreferredSpan(View.X_AXIS) + 6;
            prefSize.height += (int) v.getPreferredSpan(View.Y_AXIS);
        } else {
            prefSize.width += SwingUtilities2.stringWidth(c,fm,text) + 6;
            prefSize.height += fm.getHeight();
        }
    }
    return prefSize;
}
 
Example #19
Source File: AquaTabbedPaneContrastUI.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
protected void paintTitle(final Graphics2D g2d, final Font font, final FontMetrics metrics, final Rectangle textRect, final int tabIndex, final String title) {
    final View v = getTextViewForTab(tabIndex);
    if (v != null) {
        v.paint(g2d, textRect);
        return;
    }

    if (title == null) return;

    final Color color = tabPane.getForegroundAt(tabIndex);
    if (color instanceof UIResource) {
        g2d.setColor(getNonSelectedTabTitleColor());
        if (tabPane.getSelectedIndex() == tabIndex) {
            boolean pressed = isPressedAt(tabIndex);
            boolean enabled = tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex);
            Color textColor = getSelectedTabTitleColor(enabled, pressed);
            Color shadowColor = getSelectedTabTitleShadowColor(enabled);
            AquaUtils.paintDropShadowText(g2d, tabPane, font, metrics, textRect.x, textRect.y, 0, 1, textColor, shadowColor, title);
            return;
        }
    } else {
        g2d.setColor(color);
    }
    g2d.setFont(font);
    SwingUtilities2.drawString(tabPane, g2d, title, textRect.x, textRect.y + metrics.getAscent());
}
 
Example #20
Source File: BasicLabelUI.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return getPreferredSize(c)
 */
public Dimension getMinimumSize(JComponent c) {
    Dimension d = getPreferredSize(c);
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
        d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS);
    }
    return d;
}
 
Example #21
Source File: AquaTabbedPaneCopyFromBasicUI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected void paintText(final Graphics g, final int tabPlacement, final Font font, final FontMetrics metrics, final int tabIndex, final String title, final Rectangle textRect, final boolean isSelected) {

        g.setFont(font);

        final View v = getTextViewForTab(tabIndex);
        if (v != null) {
            // html
            v.paint(g, textRect);
        } else {
            // plain text
            final int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);

            if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
                Color fg = tabPane.getForegroundAt(tabIndex);
                if (isSelected && (fg instanceof UIResource)) {
                    final Color selectedFG = UIManager.getColor("TabbedPane.selectedForeground");
                    if (selectedFG != null) {
                        fg = selectedFG;
                    }
                }
                g.setColor(fg);
                SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());

            } else { // tab disabled
                g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
                SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
                g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
                SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1);

            }
        }
    }
 
Example #22
Source File: BasicButtonUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Dimension getMaximumSize(JComponent c) {
    Dimension d = getPreferredSize(c);
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
        d.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS);
    }
    return d;
}
 
Example #23
Source File: BasicMenuItemUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Dimension getMaximumSize(JComponent c) {
    Dimension d = null;
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
        d = getPreferredSize(c);
        d.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS);
    }
    return d;
}
 
Example #24
Source File: NumberedParagraphView.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public int getPreviousLineCount0() {
    int lineCount = 0;
    View parent = this.getParent();
    int count = parent.getViewCount();
    for (int i = 0; i < count; i++) {
        if (parent.getView(i) == this) {
            break;
        } else {
            lineCount += parent.getView(i).getViewCount();
        }
    }
    return lineCount;
}
 
Example #25
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void paint(Graphics g, JComponent c) {
  if (!(c instanceof AbstractButton)) {
    return;
  }
  AbstractButton b = (AbstractButton) c;
  Font f = b.getFont();
  g.setFont(f);
  // Insets i = c.getInsets();
  // b.getSize(size);
  // viewRect.setBounds(i.left, i.top, size.width - i.left - i.right, size.height - i.top - i.bottom);
  SwingUtilities.calculateInnerArea(c, viewRect);
  iconRect.setBounds(0, 0, 0, 0);
  textRect.setBounds(0, 0, 0, 0);

  String text = SwingUtilities.layoutCompoundLabel(
      c, c.getFontMetrics(f), b.getText(), null, // altIcon != null ? altIcon : getDefaultIcon(),
      b.getVerticalAlignment(), b.getHorizontalAlignment(),
      b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
      viewRect, iconRect, textRect,
      0); // b.getText() == null ? 0 : b.getIconTextGap());

  if (c.isOpaque()) {
    g.setColor(b.getBackground());
    g.fillRect(0, 0, c.getWidth(), c.getHeight());
  }

  ButtonModel model = b.getModel();
  if (!model.isSelected() && !model.isPressed() && !model.isArmed() && b.isRolloverEnabled() && model.isRollover()) {
    g.setColor(Color.BLUE);
    g.drawLine(viewRect.x, viewRect.y + viewRect.height, viewRect.x + viewRect.width, viewRect.y + viewRect.height);
  }
  View v = (View) c.getClientProperty(BasicHTML.propertyKey);
  if (Objects.nonNull(v)) {
    v.paint(g, textRect);
  } else {
    paintText(g, b, textRect, text);
  }
}
 
Example #26
Source File: BasicMenuItemUI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Dimension getMinimumSize(JComponent c) {
    Dimension d = null;
    View v = (View) c.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
        d = getPreferredSize(c);
        d.width -= v.getPreferredSpan(View.X_AXIS) - v.getMinimumSpan(View.X_AXIS);
    }
    return d;
}
 
Example #27
Source File: ImageView.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the preferred span of the View used to display the alt text,
 * or 0 if the view does not exist.
 */
private float getPreferredSpanFromAltView(int axis) {
    if (getImage() == null) {
        View view = getAltView();

        if (view != null) {
            return view.getPreferredSpan(axis);
        }
    }
    return 0f;
}
 
Example #28
Source File: Utilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Get first view in the hierarchy that is an instance of the given class.
 * It allows to skip various wrapper-views around the doc-view that holds
 * the child views for the lines.
 *
 * @param component component from which the root view is fetched.
 * @param rootViewClass class of the view to return.
 * @return view being instance of the requested class or null if there
 *  is not one.
 */
public static View getRootView(JTextComponent component, Class rootViewClass) {
    View view = null;
    TextUI textUI = component.getUI();
    if (textUI != null) {
        view = textUI.getRootView(component);
        while (view != null && !rootViewClass.isInstance(view)
            && view.getViewCount() == 1 // must be wrapper view
        ) {
            view = view.getView(0); // get the only child
        }
    }
    
    return view;
}
 
Example #29
Source File: BasicTabbedPaneUI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the baseline for the specified tab.
 *
 * @param tab index of tab to get baseline for
 * @exception IndexOutOfBoundsException if index is out of range
 *            (index &lt; 0 || index &gt;= tab count)
 * @return baseline or a value &lt; 0 indicating there is no reasonable
 *                  baseline
 * @since 1.6
 */
protected int getBaseline(int tab) {
    if (tabPane.getTabComponentAt(tab) != null) {
        int offset = getBaselineOffset();
        if (offset != 0) {
            // The offset is not applied to the tab component, and so
            // in general we can't get good alignment like with components
            // in the tab.
            return -1;
        }
        Component c = tabPane.getTabComponentAt(tab);
        Dimension pref = c.getPreferredSize();
        Insets tabInsets = getTabInsets(tabPane.getTabPlacement(), tab);
        int cellHeight = maxTabHeight - tabInsets.top - tabInsets.bottom;
        return c.getBaseline(pref.width, pref.height) +
                (cellHeight - pref.height) / 2 + tabInsets.top;
    }
    else {
        View view = getTextViewForTab(tab);
        if (view != null) {
            int viewHeight = (int)view.getPreferredSpan(View.Y_AXIS);
            int baseline = BasicHTML.getHTMLBaseline(
                view, (int)view.getPreferredSpan(View.X_AXIS), viewHeight);
            if (baseline >= 0) {
                return maxTabHeight / 2 - viewHeight / 2 + baseline +
                    getBaselineOffset();
            }
            return -1;
        }
    }
    FontMetrics metrics = getFontMetrics();
    int fontHeight = metrics.getHeight();
    int fontBaseline = metrics.getAscent();
    return maxTabHeight / 2 - fontHeight / 2 + fontBaseline +
            getBaselineOffset();
}
 
Example #30
Source File: CSSBorder.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void paint(Polygon shape, Graphics g, Color color, int side) {
    Rectangle r = shape.getBounds();
    int length = r.height * factor;
    int[] lengthPattern = { length, length };
    Color[] colorPattern = { color, null };
    paintStrokes(r, g, View.X_AXIS, lengthPattern, colorPattern);
}