本文整理匯總了Java中javax.swing.text.View類的典型用法代碼示例。如果您正苦於以下問題:Java View類的具體用法?Java View怎麽用?Java View使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
View類屬於javax.swing.text包,在下文中一共展示了View類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPreferredSpan
import javax.swing.text.View; //導入依賴的package包/類
@Override
public float getPreferredSpan(int axis) {
if (axis == View.X_AXIS) {
String desc = fold.getDescription(); // For empty desc a single-space text layout is returned
float advance = 0;
if (desc.length() > 0) {
TextLayout textLayout = getTextLayout();
if (textLayout == null) {
return 0f;
}
advance = textLayout.getAdvance();
}
return advance + (2 * EXTRA_MARGIN_WIDTH);
} else {
EditorView.Parent parent = (EditorView.Parent) getParent();
return (parent != null) ? parent.getViewRenderContext().getDefaultRowHeight() : 0f;
}
}
示例2: calculateTabHeight
import javax.swing.text.View; //導入依賴的package包/類
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;
}
示例3: setParent
import javax.swing.text.View; //導入依賴的package包/類
public @Override void setParent(View parent) {
if (parent != null) { // start listening
JTextComponent component = (JTextComponent)parent.getContainer();
TextUI tui = component.getUI();
if (tui instanceof BaseTextUI){
editorUI = ((BaseTextUI)tui).getEditorUI();
if (editorUI!=null){
editorUI.addPropertyChangeListener(this);
}
}
}
super.setParent(parent);
if (parent == null) {
if (editorUI!=null){
editorUI.removePropertyChangeListener(this);
editorUI = null;
}
}
}
示例4: paintText
import javax.swing.text.View; //導入依賴的package包/類
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);
}
}
示例5: paintTitle
import javax.swing.text.View; //導入依賴的package包/類
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());
}
示例6: updateHtmlViews
import javax.swing.text.View; //導入依賴的package包/類
private void updateHtmlViews(int index) {
final String title = tabPane.getTitleAt(index);
final boolean isHTML = BasicHTML.isHTMLString(title);
if (isHTML) {
if (htmlViews == null) { // Initialize vector
htmlViews = createHTMLVector();
} else { // Vector already exists
final 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();
}
示例7: paintLayeredHighlights
import javax.swing.text.View; //導入依賴的package包/類
@Override
public void paintLayeredHighlights(Graphics g, int lineStart, int lineEnd,
Shape viewBounds, JTextComponent editor, View view) {
paintListLayered(g, lineStart,lineEnd, viewBounds, editor, view, markedOccurrences);
super.paintLayeredHighlights(g, lineStart, lineEnd, viewBounds, editor, view);
paintListLayered(g, lineStart,lineEnd, viewBounds, editor, view, parserHighlights);
}
示例8: updateIndex
import javax.swing.text.View; //導入依賴的package包/類
public int updateIndex(int viewIndex, int offset, View view, FlyView.Parent flyParent) {
while (--viewIndex >= 0) {
int startOffset = (flyParent != null)
? flyParent.getStartOffset(viewIndex)
: view.getView(viewIndex).getStartOffset();
if (startOffset != offset) { // view starts below offset
if (lowerAdjacent) {
viewIndex--; // return the lower view that ends at offset
}
break;
}
}
return viewIndex + 1;
}
示例9: getSingleLineTextBaseline
import javax.swing.text.View; //導入依賴的package包/類
/**
* Returns the baseline for single line text components, like
* <code>JTextField</code>.
*/
private static int getSingleLineTextBaseline(JTextComponent textComponent,
int h) {
View rootView = textComponent.getUI().getRootView(textComponent);
if (rootView.getViewCount() > 0) {
Insets insets = textComponent.getInsets();
int height = h - insets.top - insets.bottom;
int y = insets.top;
View fieldView = rootView.getView(0);
int vspan = (int)fieldView.getPreferredSpan(View.Y_AXIS);
if (height != vspan) {
int slop = height - vspan;
y += slop / 2;
}
FontMetrics fm = textComponent.getFontMetrics(
textComponent.getFont());
y += fm.getAscent();
return y;
}
return -1;
}
示例10: paintText
import javax.swing.text.View; //導入依賴的package包/類
@Override
protected void paintText(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);
if( tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex) )
{
g.setColor(isSelected ? Color.white : Color.black);
BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x,
textRect.y + metrics.getAscent());
}
else
{ // tab disabled
g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x,
textRect.y + metrics.getAscent());
g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x,
textRect.y + metrics.getAscent());
}
}
}
示例11: testBackwardBias
import javax.swing.text.View; //導入依賴的package包/類
@RandomlyFails
public void testBackwardBias() throws Throwable {
JEditorPane jep = createJep(PYRAMID);
View rootView = Utilities.getRootView(jep, DrawEngineDocView.class);
for(int i = 1; i < rootView.getViewCount(); i++) {
int backwardBiasOffset = rootView.getView(i).getStartOffset();
int previousLineEOLOffset = rootView.getView(i - 1).getEndOffset() - 1;
Rectangle r1 = jep.getUI().modelToView(jep, backwardBiasOffset, Position.Bias.Backward);
Rectangle r2 = jep.getUI().modelToView(jep, previousLineEOLOffset, Position.Bias.Forward);
assertEquals("Wrong backward bias offset translation: offset = " + backwardBiasOffset
+ ", previousLineEOLOffset = " + previousLineEOLOffset
+ ", docLen = " + jep.getDocument().getLength(), r2, r1);
}
}
示例12: paintTitle
import javax.swing.text.View; //導入依賴的package包/類
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());
}
示例13: modelToView
import javax.swing.text.View; //導入依賴的package包/類
/**
* Provides a mapping from the document model coordinate space
* to the coordinate space of the view mapped to it.
*
* @param pos the position to convert >= 0
* @param a the allocated region to render into
* @param b the bias toward the previous character or the
* next character represented by the offset, in case the
* position is a boundary of two views.
* @return the bounding box of the given position is returned
* @exception BadLocationException if the given position does
* not represent a valid location in the associated document
* @exception IllegalArgumentException for an invalid bias argument
* @see View#viewToModel
*/
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
int index = getViewIndex(pos, b);
if (index >= 0) {
Shape ca = getChildAllocation(index, a);
// forward to the child view
ViewLayoutState child = getChild(index);
View cv = child.getView();
return cv.modelToView(pos, ca, b);
} else {
Document doc = getDocument();
int docLen = (doc != null) ? doc.getLength() : -1;
throw new BadLocationException("Offset " + pos + " with bias " + b + " is outside of the view" //NOI18N
+ ", children = " + getViewCount() //NOI18N
+ (getViewCount() > 0 ? " covering offsets <" + //NOI18N
getView(0).getStartOffset() + ", " + //NOI18N
getView(getViewCount() - 1).getEndOffset() + ">" : "") + //NOI18N
", docLen=" + docLen
, pos);
}
}
示例14: paint
import javax.swing.text.View; //導入依賴的package包/類
/**
* 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);
}
}
示例15: calculateTabWidth
import javax.swing.text.View; //導入依賴的package包/類
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;
}