当前位置: 首页>>代码示例>>Java>>正文


Java JEditorPane.getUI方法代码示例

本文整理汇总了Java中javax.swing.JEditorPane.getUI方法的典型用法代码示例。如果您正苦于以下问题:Java JEditorPane.getUI方法的具体用法?Java JEditorPane.getUI怎么用?Java JEditorPane.getUI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JEditorPane的用法示例。


在下文中一共展示了JEditorPane.getUI方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createEditor

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public Component createEditor(JEditorPane j) {
    EditorUI editorUI = Utilities.getEditorUI(j);
    if (editorUI == null) { // Editor kit not installed yet??
        javax.swing.plaf.TextUI ui = j.getUI();
        javax.swing.text.EditorKit kit = j.getEditorKit();
        throw new IllegalStateException("NbEditorDocument.createEditor(): ui=" + ui + // NOI18N
                ", kit=" + kit + ", pane=" + j); // NOI18N
    }
    return editorUI.getExtComponent();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:NbEditorDocument.java

示例2: checkViewToModelConsistency

import javax.swing.JEditorPane; //导入方法依赖的package包/类
private void checkViewToModelConsistency(JEditorPane jep) throws Exception {
        Document doc = jep.getDocument();
        
        assertTrue("Expecting BaseTextUI", jep.getUI() instanceof BaseTextUI);
        BaseTextUI btui = (BaseTextUI) jep.getUI();
        Insets margin = btui.getEditorUI().getTextMargin();
        int charWidth = btui.getEditorUI().defaultSpaceWidth;
        int charHeight = btui.getEditorUI().getLineHeight();

//        System.out.println("### charWidth = " + charWidth + ", charHeight = " + charHeight
//            + ", docLen = " + doc.getLength()
//            + ", jep.width = " + jep.getWidth()
//            + ", jep.height = " + jep.getHeight());
        
        Rectangle eodRectangle = null;
        Rectangle eolRectangle = null;
        for(int y = charHeight / 2 + margin.top; y < jep.getHeight(); y += charHeight) {
            if (eodRectangle == null) {
                eolRectangle = null;
            }
            for(int x = charWidth / 2 + margin.left; x < jep.getWidth(); x += charWidth) {
                Point p = new Point(x, y);

                // view-to-model translation
                int offset = jep.viewToModel(p);
                assertTrue("Invalid v2m translation: " + s(p) + " -> " + offset+ ", docLen = " + doc.getLength(),
                        offset >= 0 && offset <= doc.getLength());
                
                // model-to-view
                Rectangle r = jep.modelToView(offset);
                assertNotNull("No m2v translation: offset = " + offset + ", docLen = " + doc.getLength(), r);

                // check
                if (eodRectangle == null) {
                    boolean eod = offset == doc.getLength();
                    boolean eol = doc.getText(offset, 1).charAt(0) == '\n';
                    
                    if (eolRectangle == null) {
                        assertTrue("Inconsistent v2m-m2v translation, point = " + s(p) + " not within " + s(r)
                            + ", offset = " + offset + ", docLen = " + doc.getLength(), r.contains(p));
                        if (eol) {
                            eolRectangle = r;
                        }
                    } else {
                        assertEquals("Inconsistent v2m-m2v translation, for point = " + s(p) + " behing eol"
                            + ", offset = " + offset + ", docLen = " + doc.getLength(), eolRectangle, r);
                    }
                    
                    if (eod) {
                        eodRectangle = r;
                    }
                } else {
                    Point pointAtTheLastLine = new Point(Math.min(p.x, eolRectangle.x), eodRectangle.y);
                    assertTrue("Inconsistent v2m-m2v translation, for point = " + s(p)
                        + " behing eod, point at the last line " + s(pointAtTheLastLine) + " is outside of " + s(r)
                        + ", offset = " + offset + ", docLen = " + doc.getLength(), r.contains(pointAtTheLastLine));
                }
            }
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:61,代码来源:DrawEngineTest.java

示例3: checkModelToViewCorrectness

import javax.swing.JEditorPane; //导入方法依赖的package包/类
private void checkModelToViewCorrectness(JEditorPane jep) throws Exception {
        Document doc = jep.getDocument();
        
        assertTrue("Expecting BaseTextUI", jep.getUI() instanceof BaseTextUI);
        BaseTextUI btui = (BaseTextUI) jep.getUI();
        Insets margin = btui.getEditorUI().getTextMargin();
        int charWidth = btui.getEditorUI().defaultSpaceWidth;
        int charHeight = btui.getEditorUI().getLineHeight();

//        System.out.println("### charWidth = " + charWidth + ", charHeight = " + charHeight
//            + ", docLen = " + doc.getLength()
//            + ", jep.width = " + jep.getWidth()
//            + ", jep.height = " + jep.getHeight());
        
        for(int offset = 0; offset <= doc.getLength(); offset++) {
            // model-to-view translation
            Rectangle r = jep.modelToView(offset);
            assertNotNull("No m2v translation: offset = " + offset + ", docLen = " + doc.getLength(), r);

            View rootView = Utilities.getRootView(jep, DrawEngineDocView.class);
            int line = rootView.getViewIndex(offset, Position.Bias.Forward);
            int col = offset - rootView.getView(line).getStartOffset();

// XXX: this would be necessary for handling tabs, but it uses DrawEngineLineView
//      and therefore is not independent from the tested code, the inverse transformation
//      will be needed in checkViewToModel
//            int col = Utilities.getVisualColumn((BaseDocument)doc, offset);
//            int nextCol = offset >= rootView.getView(line).getEndOffset() - 1 ? col + 1 : Utilities.getVisualColumn((BaseDocument)doc, offset + 1);
//            System.out.println("### offset = " + offset + ", col = " + col + ", nextCol = " + nextCol + ", docLen = " + doc.getLength());

            Rectangle r2 = new Rectangle(
                margin.left + col * charWidth,
                margin.top + line * charHeight,
// XXX: see above comment about the tabs handling
//                (nextCol - col) * charWidth,
                charWidth,
                charHeight
            );

            assertEquals("Incorrect m2v translation: offset = " + offset + ", docLen = " + doc.getLength(), r2, r);
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:43,代码来源:DrawEngineTest.java


注:本文中的javax.swing.JEditorPane.getUI方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。