本文整理匯總了Java中javax.swing.text.ViewFactory類的典型用法代碼示例。如果您正苦於以下問題:Java ViewFactory類的具體用法?Java ViewFactory怎麽用?Java ViewFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ViewFactory類屬於javax.swing.text包,在下文中一共展示了ViewFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: elementReloadChildren
import javax.swing.text.ViewFactory; //導入依賴的package包/類
/**
* Loads child views by tracking child elements of the element
* this view was created for.
* @param index index at which the views should be added/replaced.
* @param removeLength number of removed children views. It is useful
* when rebuilding children for a portion of the view.
* @param elementIndex index of the first child element for which
* the view should be created
* @param elementCount number of elements for which the views should be created.
*/
protected void elementReloadChildren(int index, int removeLength,
int elementCount) {
Element e = getElement();
View[] added = null;
ViewFactory f = getViewFactory();
// Null view factory can mean that one of the grand parents is already disconnected
// from the view hierarchy. No added children for null factory.
if (f != null) {
added = new View[elementCount];
for (int i = 0; i < elementCount; i++) {
added[i] = f.create(e.getElement(index + i));
}
}
replace(index, removeLength, added);
}
示例2: handleDocumentEvent
import javax.swing.text.ViewFactory; //導入依賴的package包/類
private void handleDocumentEvent(DocumentEvent e, Shape a,
ViewFactory f) {
int n = calculateLineCount();
if (this.nlines != n) {
this.nlines = n;
WrappedSyntaxView.this.preferenceChanged(this, false, true);
// have to repaint any views after the receiver.
RSyntaxTextArea textArea = (RSyntaxTextArea)getContainer();
textArea.repaint();
// Must also revalidate container so gutter components, such
// as line numbers, get updated for this line's new height
Gutter gutter = RSyntaxUtilities.getGutter(textArea);
if (gutter!=null) {
gutter.revalidate();
gutter.repaint();
}
}
else if (a != null) {
Component c = getContainer();
Rectangle alloc = (Rectangle) a;
c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
}
}
示例3: createAgreementPanel
import javax.swing.text.ViewFactory; //導入依賴的package包/類
protected JComponent createAgreementPanel() {
String html = HTMLUtils.createStyledHTMLFromFragment( SoftwareAgreement.getInstance().getContent() );
HTMLEditorPane htmlEditorPane = new HTMLUtils.InteractiveHTMLPane( html );
final HTMLEditorKit.HTMLFactory htmlFactory = new HTMLFactoryWithImages();
htmlEditorPane.setEditorKit( new HTMLEditorKit() {
public ViewFactory getViewFactory() {
return htmlFactory;
}
} );
htmlEditorPane.setText( html );
htmlEditorPane.setBackground( Color.WHITE );
JScrollPane scrollPane = new JScrollPane( htmlEditorPane );
scrollPane.setPreferredSize( new Dimension( scrollPane.getPreferredSize().width + 30, 300 ) );
// this ensures that the first line of text is at the top of the scrollpane
htmlEditorPane.setCaretPosition( 0 );
return scrollPane;
}
示例4: modelChanged
import javax.swing.text.ViewFactory; //導入依賴的package包/類
/**
* Indicates that the model of a text component has changed. This
* triggers a rebuild of the view hierarchy.
*/
protected void modelChanged()
{
if (textComponent == null || rootView == null)
return;
ViewFactory factory = rootView.getViewFactory();
if (factory == null)
return;
Document doc = textComponent.getDocument();
if (doc == null)
return;
Element elem = doc.getDefaultRootElement();
if (elem == null)
return;
View view = factory.create(elem);
setView(view);
}
示例5: changedUpdate
import javax.swing.text.ViewFactory; //導入依賴的package包/類
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f)
{
super.changedUpdate(e, a, f);
float align = getVerticalAlignment();
int h = height;
int w = width;
initialize(getElement());
boolean hChanged = (height != h);
boolean wChanged = (width != w);
if(hChanged || wChanged || getVerticalAlignment() != align)
{
getParent().preferenceChanged(this, hChanged, wChanged);
}
}
示例6: modelChanged
import javax.swing.text.ViewFactory; //導入依賴的package包/類
/**
* Indicates that the model of a text component has changed. This
* triggers a rebuild of the view hierarchy.
*/
protected void modelChanged()
{
if (textComponent == null || rootView == null)
return;
ViewFactory factory = rootView.getViewFactory();
if (factory == null)
return;
Document doc = textComponent.getDocument();
if (doc == null)
return;
Element elem = doc.getDefaultRootElement();
if (elem == null)
return;
View view = factory.create(elem);
setView(view);
}
示例7: createView
import javax.swing.text.ViewFactory; //導入依賴的package包/類
public static View createView(JXLabel c) {
BasicEditorKit kit = getFactory();
float rightIndent = 0;
if (c.getIcon() != null && c.getHorizontalTextPosition() != SwingConstants.CENTER) {
rightIndent = c.getIcon().getIconWidth() + c.getIconTextGap();
}
Document doc = kit.createDefaultDocument(c.getFont(), c.getForeground(), c.getTextAlignment(), rightIndent);
Reader r = new StringReader(c.getText() == null ? "" : c.getText());
try {
kit.read(r, doc, 0);
} catch (Throwable e) {
}
ViewFactory f = kit.getViewFactory();
View hview = f.create(doc.getDefaultRootElement());
View v = new Renderer(c, f, hview, true);
return v;
}
示例8: Renderer
import javax.swing.text.ViewFactory; //導入依賴的package包/類
Renderer(JXLabel c, ViewFactory f, View v, boolean wordWrap) {
super(null, wordWrap);
factory = f;
view = v;
view.setParent(this);
host = c;
//log.fine("vir: " + host.getVisibleRect());
int w;
if (host.getVisibleRect().width == 0) {
invalidated = true;
return;
} else {
w = host.getVisibleRect().width;
}
//log.fine("w:" + w);
// initially layout to the preferred size
//setSize(c.getMaxLineSpan() > -1 ? c.getMaxLineSpan() : view.getPreferredSpan(X_AXIS), view.getPreferredSpan(Y_AXIS));
setSize(c.getMaxLineSpan() > -1 ? c.getMaxLineSpan() : w, host.getVisibleRect().height);
}
示例9: createHTMLView
import javax.swing.text.ViewFactory; //導入依賴的package包/類
/**
* Create an html renderer for the given component and
* string of html.
*/
public static View createHTMLView(JComponent c, String html) {
BasicEditorKit kit = getFactory();
Document doc = kit.createDefaultDocument(c.getFont(),
c.getForeground());
Object base = c.getClientProperty(documentBaseKey);
if (base instanceof URL) {
((HTMLDocument)doc).setBase((URL)base);
}
Reader r = new StringReader(html);
try {
kit.read(r, doc, 0);
} catch (Throwable e) {
}
ViewFactory f = kit.getViewFactory();
View hview = f.create(doc.getDefaultRootElement());
View v = new Renderer(c, f, hview);
return v;
}
示例10: get
import javax.swing.text.ViewFactory; //導入依賴的package包/類
/**
* Get View from HTML String
* @param html html string
* @return renderer view
*/
public static HTMLRenderer get (String html)
{
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
try
{
doc.remove(0, doc.getLength());
Reader r = new StringReader(html);
kit.read(r, doc, 0);
}
catch (Exception e)
{
log.error("", e);
}
// Create Renderer
Element element = doc.getDefaultRootElement();
ViewFactory factory = kit.getViewFactory();
View view = factory.create(element); // Y_AXIS is main
HTMLRenderer renderer = new HTMLRenderer (factory, view);
renderer.preferenceChanged (null, true, true);
return renderer;
}
示例11: setParent
import javax.swing.text.ViewFactory; //導入依賴的package包/類
/**
* Sets the view parent.
*
* @param parent
* the parent view
*/
@Override
public void setParent(View parent)
{
if (parent == null && view != null) view.setParent(null);
this.parent = parent;
// if set new parent and has some element, try to load children
// this element is a BranchElement ("collection"),
// so we should have some LeafElements ("children")
if ((parent != null) && (getElement() != null))
{
ViewFactory f = getViewFactory();
loadChildren(f);
}
}
示例12: forwardUpdate
import javax.swing.text.ViewFactory; //導入依賴的package包/類
@Override
protected void forwardUpdate(DocumentEvent.ElementChange ec,
DocumentEvent e, Shape a, ViewFactory f)
{
boolean wasValid = isLayoutValid(majorAxis);
super.forwardUpdate(ec, e, a, f);
// determine if a repaint is needed
if (wasValid && (!isLayoutValid(majorAxis)))
{
// Repaint is needed because one of the tiled children
// have changed their span along the major axis. If there
// is a hosting component and an allocated shape we repaint.
Component c = getContainer();
if ((a != null) && (c != null))
{
Rectangle alloc = getInsideAllocation(a);
c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
}
}
}
示例13: renderContent
import javax.swing.text.ViewFactory; //導入依賴的package包/類
/**
* Renders current content to given graphic context, which is updated and
* returned. Context must have set the clip, otherwise NullPointerException
* is throwen.
*
* @param g
* the context to be rendered to.
* @return the Graphics2D context
* @see Graphics2D
*/
public Graphics2D renderContent(Graphics2D g)
{
if (g.getClip() == null)
throw new NullPointerException(
"Clip is not set on graphics context");
ViewFactory factory = getEditorKit().getViewFactory();
if (factory instanceof SwingBoxViewFactory)
{
View view = ((SwingBoxViewFactory) factory).getViewport();
if (view != null) view.paint(g, g.getClip());
}
return g;
}
示例14: setUp
import javax.swing.text.ViewFactory; //導入依賴的package包/類
protected void setUp() throws Exception {
super.setUp();
setIgnoreNotImplemented(true);
kit = new HTMLEditorKit();
doc = (HTMLDocument)kit.createDefaultDocument();
StringReader reader = new StringReader("<html><head></head><body>" +
"<p><small>one long</small>Word" +
"<p>very LongWord" +
"</body></html>");
kit.read(reader, doc, 0);
metrics = getFontMetrics(null, CHAR_WIDTH);
factory = new ViewFactory() {
public View create(final Element element) {
InlineView result = new InlineView(element) {
protected FontMetrics getFontMetrics() {
return metrics;
}
};
result.setGlyphPainter(BlockViewTest.InlineViewFactory.painter);
return result;
}
};
}
示例15: testCalculateMinorAxisRequirements04
import javax.swing.text.ViewFactory; //導入依賴的package包/類
public void testCalculateMinorAxisRequirements04() throws Exception {
factory = new ViewFactory() {
public View create(Element element) {
PlainView result = new PlainView(element) {
public float getPreferredSpan(int axis) {
if (axis == X_AXIS) {
return CHAR_WIDTH
* (getEndOffset() - getStartOffset());
}
return super.getPreferredSpan(axis);
}
};
return result;
}
};
view = new ParagraphViewImpl(doc.getParagraphElement(10), factory);
SizeRequirements sr =
view.calculateMinorAxisRequirements(View.X_AXIS, null);
assertEquals(8 * CHAR_WIDTH, sr.minimum);
assertEquals(13 * CHAR_WIDTH, sr.preferred);
assertEquals(Integer.MAX_VALUE, sr.maximum);
}