當前位置: 首頁>>代碼示例>>Java>>正文


Java ViewFactory類代碼示例

本文整理匯總了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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:31,代碼來源:GapBoxView.java

示例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);
	}
}
 
開發者ID:Thecarisma,項目名稱:powertext,代碼行數:24,代碼來源:WrappedSyntaxView.java

示例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;
    }
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:24,代碼來源:SoftwareAgreementDialog.java

示例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);
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:21,代碼來源:BasicTextUI.java

示例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);
	}
}
 
開發者ID:andy-goryachev,項目名稱:PasswordSafe,代碼行數:18,代碼來源:LocalImageView.java

示例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);
}
 
開發者ID:nmldiegues,項目名稱:jvm-stm,代碼行數:21,代碼來源:BasicTextUI.java

示例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;
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:18,代碼來源:JXLabel.java

示例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);
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:20,代碼來源:JXLabel.java

示例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;
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:23,代碼來源:BasicHyperlinkUI.java

示例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;
}
 
開發者ID:metasfresh,項目名稱:metasfresh,代碼行數:28,代碼來源:HTMLRenderer.java

示例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);
    }
}
 
開發者ID:mantlik,項目名稱:swingbox-javahelp-viewer,代碼行數:23,代碼來源:DelegateView.java

示例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);
        }
    }
}
 
開發者ID:mantlik,項目名稱:swingbox-javahelp-viewer,代碼行數:22,代碼來源:ElementBoxView.java

示例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;
}
 
開發者ID:mantlik,項目名稱:swingbox-javahelp-viewer,代碼行數:26,代碼來源:BrowserPane.java

示例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;
        }
    };
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:25,代碼來源:ParagraphView_RequirementsTest.java

示例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);
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:23,代碼來源:ParagraphView_RequirementsTest.java


注:本文中的javax.swing.text.ViewFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。