本文整理匯總了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));
}