本文整理汇总了Java中javax.swing.text.View.getPreferredSpan方法的典型用法代码示例。如果您正苦于以下问题:Java View.getPreferredSpan方法的具体用法?Java View.getPreferredSpan怎么用?Java View.getPreferredSpan使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.View
的用法示例。
在下文中一共展示了View.getPreferredSpan方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculateTabHeight
import javax.swing.text.View; //导入方法依赖的package包/类
protected int calculateTabHeight(final int tabPlacement, final int tabIndex, final int fontHeight) {
int height = 0;
final Component c = tabPane.getTabComponentAt(tabIndex);
if (c != null) {
height = c.getPreferredSize().height;
} else {
final View v = getTextViewForTab(tabIndex);
if (v != null) {
// html
height += (int)v.getPreferredSpan(View.Y_AXIS);
} else {
// plain text
height += fontHeight;
}
final Icon icon = getIconForTab(tabIndex);
if (icon != null) {
height = Math.max(height, icon.getIconHeight());
}
}
final Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
height += tabInsets.top + tabInsets.bottom + 2;
return height;
}
示例2: getPreferredSize
import javax.swing.text.View; //导入方法依赖的package包/类
/**
* {@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;
}
示例3: getMaximumSize
import javax.swing.text.View; //导入方法依赖的package包/类
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;
}
示例4: getMaximumSize
import javax.swing.text.View; //导入方法依赖的package包/类
/**
* @return getPreferredSize(c)
*/
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;
}
示例5: getMinimumSize
import javax.swing.text.View; //导入方法依赖的package包/类
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;
}
示例6: getMinimumSize
import javax.swing.text.View; //导入方法依赖的package包/类
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;
}
示例7: calculateTabWidth
import javax.swing.text.View; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected int calculateTabWidth(int tabPlacement, int tabIndex,
FontMetrics metrics) {
Icon icon = getIconForTab(tabIndex);
Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
int width = tabInsets.left + tabInsets.right;
Component tabComponent = tabPane.getTabComponentAt(tabIndex);
if (tabComponent != null) {
width += tabComponent.getPreferredSize().width;
} else {
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 += tabContext.getStyle().getGraphicsUtils(tabContext).
computeStringWidth(tabContext, metrics.getFont(),
metrics, title);
}
}
return width;
}
示例8: getMaximumSize
import javax.swing.text.View; //导入方法依赖的package包/类
public Dimension getMaximumSize(final JComponent c) {
final Dimension d = getPreferredSize(c);
final View v = (View)c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
d.width += v.getMaximumSpan(View.X_AXIS) - v.getPreferredSpan(View.X_AXIS);
}
return d;
}
示例9: getBaseline
import javax.swing.text.View; //导入方法依赖的package包/类
/**
* 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 < 0 || index >= tab count)
* @return baseline or a value < 0 indicating there is no reasonable
* baseline
* @since 1.6
*/
protected int getBaseline(final int tab) {
if (tabPane.getTabComponentAt(tab) != null) {
final 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;
}
final Component c = tabPane.getTabComponentAt(tab);
final Dimension pref = c.getPreferredSize();
final Insets tabInsets = getTabInsets(tabPane.getTabPlacement(), tab);
final int cellHeight = maxTabHeight - tabInsets.top - tabInsets.bottom;
return c.getBaseline(pref.width, pref.height) + (cellHeight - pref.height) / 2 + tabInsets.top;
} else {
final View view = getTextViewForTab(tab);
if (view != null) {
final int viewHeight = (int)view.getPreferredSpan(View.Y_AXIS);
final int baseline = BasicHTML.getHTMLBaseline(view, (int)view.getPreferredSpan(View.X_AXIS), viewHeight);
if (baseline >= 0) {
return maxTabHeight / 2 - viewHeight / 2 + baseline + getBaselineOffset();
}
return -1;
}
}
final FontMetrics metrics = getFontMetrics();
final int fontHeight = metrics.getHeight();
final int fontBaseline = metrics.getAscent();
return maxTabHeight / 2 - fontHeight / 2 + fontBaseline + getBaselineOffset();
}
示例10: getBaseline
import javax.swing.text.View; //导入方法依赖的package包/类
/**
* 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 < 0 || index >= tab count)
* @return baseline or a value < 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();
}
示例11: getMaximumSize
import javax.swing.text.View; //导入方法依赖的package包/类
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;
}
示例12: getPreferredSize
import javax.swing.text.View; //导入方法依赖的package包/类
public static java.awt.Dimension getPreferredSize(String text,
boolean width, int prefSize) {
JLabel resizer = new JLabel(text);
View view = (View) resizer
.getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey);
view.setSize(width ? prefSize : 0, width ? 0 : prefSize);
float w = view.getPreferredSpan(View.X_AXIS);
float h = view.getPreferredSpan(View.Y_AXIS) + 2;
return new java.awt.Dimension((int) Math.ceil(w), (int) Math.ceil(h));
}