Java 类javax.swing.text.EditorKit 实例源码

项目:incubator-netbeans    文件:CustomizeScriptPanel.java   
/** Create the wizard panel component and set up some basic properties. */
public CustomizeScriptPanel (CustomizeScriptWizardPanel wiz) {
    initComponents ();
    initAccessibility ();
    // Provide a name in the title bar.
    setName (NbBundle.getMessage (CustomizeScriptPanel.class, "CSP_LBL_cust_gend_ant_script"));
    scriptPane.setContentType ("text/xml"); // NOI18N
    // Hack; EditorKit does not permit "fallback" kits, so we have to
    // mimic what the IDE itself does:
    EditorKit kit = scriptPane.getEditorKit ();
    String clazz = kit.getClass ().getName ();
    if (clazz.equals ("javax.swing.text.DefaultEditorKit") || // NOI18N
           clazz.equals ("javax.swing.JEditorPane$PlainEditorKit")) { // NOI18N
        scriptPane.setEditorKit (JEditorPane.createEditorKitForContentType ("text/plain")); // NOI18N
    }
}
项目:incubator-netbeans    文件:AdvancedActionPanel.java   
public AdvancedActionPanel(AntProjectCookie project, Set<TargetLister.Target> allTargets) {
    this.project = project;
    this.allTargets = allTargets;
    initComponents();

    getAccessibleContext().setAccessibleDescription(
            NbBundle.getMessage(AdvancedActionPanel.class,"AdvancedActionsPanel.acsd.title"));

    Mnemonics.setLocalizedText(targetLabel, NbBundle.getMessage(AdvancedActionPanel.class, "AdvancedActionsPanel.targetLabel.text"));
    Mnemonics.setLocalizedText(targetDescriptionLabel, NbBundle.getMessage(AdvancedActionPanel.class, "AdvancedActionsPanel.targetDescriptionLabel.text"));
    Mnemonics.setLocalizedText(propertiesLabel, NbBundle.getMessage(AdvancedActionPanel.class, "AdvancedActionsPanel.propertiesLabel.text"));
    Mnemonics.setLocalizedText(verbosityLabel, NbBundle.getMessage(AdvancedActionPanel.class, "AdvancedActionsPanel.verbosityLabel.text"));
    // Hack; EditorKit does not permit "fallback" kits, so we have to
    // mimic what the IDE itself does:
    EditorKit kit = propertiesPane.getEditorKit();
    String clazz = kit.getClass().getName();
    if (clazz.equals("javax.swing.text.DefaultEditorKit") || // NOI18N
            clazz.equals("javax.swing.JEditorPane$PlainEditorKit")) { // NOI18N
        propertiesPane.setEditorKit(JEditorPane.createEditorKitForContentType("text/plain")); // NOI18N
    }
    // Make ENTER run OK, not change the combo box.
    targetComboBox.getInputMap().remove(KeyStroke.getKeyStroke("ENTER")); // NOI18N
    initializeFields();
}
项目:incubator-netbeans    文件:BaseDocument.java   
Syntax getFreeSyntax() {
        EditorKit kit = getEditorKit();
        if (kit instanceof BaseKit) {
            return ((BaseKit) kit).createSyntax(this);
        } else {
            return new BaseKit.DefaultSyntax();
        }
//        synchronized (syntaxList) {
//            int cnt = syntaxList.size();
//            if (cnt > 0) {
//                return syntaxList.remove(cnt - 1);
//            } else {
//                EditorKit kit = getEditorKit();
//                if (kit instanceof BaseKit) {
//                    return ((BaseKit) kit).createSyntax(this);
//                } else {
//                    return new BaseKit.DefaultSyntax();
//                }
//            }
//        }
    }
项目:incubator-netbeans    文件:BaseDocument.java   
/**
 * Print into given container.
 *
 * @param container printing container into which the printing will be done.
 * @param usePrintColoringMap use printing coloring settings instead
 *  of the regular ones.
 * @param lineNumberEnabled if set to false the line numbers will not be printed.
 *  If set to true the visibility of line numbers depends on the settings
 *  for the line number visibility.
 * @param startOffset start offset of text to print
 * @param endOffset end offset of text to print
 */
public void print(PrintContainer container, boolean usePrintColoringMap, boolean lineNumberEnabled, int startOffset,
                  int endOffset) {
    readLock();
    try {
        EditorUI editorUI;
        EditorKit kit = getEditorKit();
        if (kit instanceof BaseKit) {
            editorUI = ((BaseKit) kit).createPrintEditorUI(this, usePrintColoringMap, lineNumberEnabled);
        } else {
            editorUI = new EditorUI(this, usePrintColoringMap, lineNumberEnabled);
        }

        DrawGraphics.PrintDG printDG = new DrawGraphics.PrintDG(container);
        DrawEngine.getDrawEngine().draw(printDG, editorUI, startOffset, endOffset, 0, 0, Integer.MAX_VALUE);
    } catch (BadLocationException e) {
        LOG.log(Level.WARNING, null, e);
    } finally {
        readUnlock();
    }
}
项目:incubator-netbeans    文件:GuardedBlockTest.java   
@Override
protected void loadFromStreamToKit(StyledDocument doc, InputStream stream, EditorKit kit) throws IOException, BadLocationException {
    if (guardedEditor == null) {
        guardedEditor = new FormGEditor();
        GuardedSectionsFactory gFactory = GuardedSectionsFactory.find("text/x-java");
        if (gFactory != null) {
            guardedProvider = gFactory.create(guardedEditor);
        }
    }

    if (guardedProvider != null) {
        guardedEditor.doc = doc;
        Charset c = FileEncodingQuery.getEncoding(this.getDataObject().getPrimaryFile());
        Reader reader = guardedProvider.createGuardedReader(stream, c);
        try {
            kit.read(reader, doc, 0);
        } finally {
            reader.close();
        }
    } else {
        super.loadFromStreamToKit(doc, stream, kit);
    }
}
项目:incubator-netbeans    文件:EditorActionUtilities.java   
/**
 * Get searchable editor kit for the given kit.
 * @param kit non-null kit.
 * @return non-null searchable kit.
 */
public static SearchableEditorKit getSearchableKit(EditorKit kit) {
    SearchableEditorKit searchableKit;
    if (kit instanceof SearchableEditorKit) {
        searchableKit = ((SearchableEditorKit)kit);
    } else {
        synchronized (kit2searchable) {
            searchableKit = kit2searchable.get(kit);
            if (searchableKit == null) {
                searchableKit = new DefaultSearchableKit(kit);
                registerSearchableKit(kit, searchableKit);
            }
        }
    }
    return searchableKit;
}
项目:incubator-netbeans    文件:PresenterEditorAction.java   
public void actionPerformed(ActionEvent evt) {
    // Find the right action for the corresponding editor kit
    JTextComponent component = getTextComponent(evt);
    if (component != null) {
        TextUI ui = component.getUI();
        if (ui != null) {
            EditorKit kit = ui.getEditorKit(component);
            if (kit != null) {
                Action action = EditorUtilities.getAction(kit, actionName);
                if (action != null) {
                    action.actionPerformed(evt);
                } else {
                    if (LOG.isLoggable(Level.FINE)) {
                        LOG.fine("Action '" + actionName + "' not found in editor kit " + kit + '\n'); // NOI18N
                    }
                }
            }
        }
    }
}
项目:incubator-netbeans    文件:ViewHierarchyRandomTesting.java   
public static RandomTestContainer createContainer(EditorKit kit) throws Exception {
    // Ensure the new view hierarchy is turned on
    System.setProperty("org.netbeans.editor.linewrap", "true");
    // Set the property for synchronous highlights firing since otherwise
    // the repeatability of problems with view hierarchy is none or limited.
    System.setProperty("org.netbeans.editor.sync.highlights", "true");
    System.setProperty("org.netbeans.editor.linewrap.edt", "true");

    RandomTestContainer container = new RandomTestContainer();
    EditorPaneTesting.initContainer(container, kit);
    DocumentTesting.initContainer(container);
    DocumentTesting.initUndoManager(container);
    container.addCheck(new ViewHierarchyCheck());
    JEditorPane pane = EditorPaneTesting.getEditorPane(container);
    pane.putClientProperty("text-line-wrap", "words"); // SimpleValueNames.TEXT_LINE_WRAP
    return container;
}
项目:incubator-netbeans    文件:CloneableEditorDoubleLoadingTest.java   
@Override
protected void loadFromStreamToKit(StyledDocument doc, InputStream stream, EditorKit kit)
throws IOException, BadLocationException {
    Exception e = new Exception();
    StringWriter sw = new StringWriter(500);
    PrintWriter pw = new PrintWriter(sw);
    pw.println("loadFromStreamToKit"
    + " this:[" + Integer.toHexString(System.identityHashCode(doc)) + "]"
    + " thread:" + Thread.currentThread().getName());
    e.printStackTrace(pw);
    pw.flush();

    inits.add(new Exception(sw.toString()));

    super.loadFromStreamToKit(doc, stream, kit);
}
项目:incubator-netbeans    文件:XMLSyntaxBridgeImpl.java   
@Override
public org.netbeans.editor.Syntax createSyntax(EditorKit host, Document doc, String mimeType) {
    if (DTDKit.MIME_TYPE.equals(mimeType)) {
        return new JJEditorSyntax( 
            new DTDSyntaxTokenManager(null).new Bridge(),
            new DTDSyntaxTokenMapper(),
            DTDTokenContext.contextPath
        );

    } else if (XMLKit.MIME_TYPE.equals(mimeType)) {
        return new XMLDefaultSyntax();
    } else if (ENTKit.MIME_TYPE.equals(mimeType)) {
        return new XMLDefaultSyntax();
    } else {
        return null;
    }
}
项目:incubator-netbeans    文件:DocumentationScrollPane.java   
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey, JTextComponent component) {
    // This method is implemented due to the issue
    // #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
    KeyStroke[] ret = new KeyStroke[] { defaultKey };
    if (component != null) {
        TextUI componentUI = component.getUI();
        Keymap km = component.getKeymap();
        if (componentUI != null && km != null) {
            EditorKit kit = componentUI.getEditorKit(component);
            if (kit instanceof BaseKit) {
                 Action a = ((BaseKit)kit).getActionByName(editorActionName);
                if (a != null) {
                    KeyStroke[] keys = km.getKeyStrokesForAction(a);
                    if (keys != null && keys.length > 0) {
                        ret = keys;
                    }
                }
            }
        }
    }
    return ret;
}
项目:incubator-netbeans    文件:DataEditorSupport.java   
/** Let's the super method create the document and also annotates it
* with Title and StreamDescription properties.
*
* @param kit kit to user to create the document
* @return the document annotated by the properties
*/
@Override
protected StyledDocument createStyledDocument (EditorKit kit) {
    StyledDocument doc = super.createStyledDocument (kit);

    // set document name property
    doc.putProperty(Document.TitleProperty,
        FileUtil.getFileDisplayName(obj.getPrimaryFile())
    );
    // set dataobject to stream desc property
    doc.putProperty(Document.StreamDescriptionProperty,
        obj
    );

    //Report the document into the Timers&Counters window:
    Logger.getLogger("TIMER").log(Level.FINE, "Document", new Object[] {obj.getPrimaryFile(), doc});

    return doc;
}
项目:incubator-netbeans    文件:DocumentationScrollPane.java   
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey, JTextComponent component) {
    // This method is implemented due to the issue
    // #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
    KeyStroke[] ret = new KeyStroke[] { defaultKey };
    if (component != null) {
        TextUI componentUI = component.getUI();
        Keymap km = component.getKeymap();
        if (componentUI != null && km != null) {
            EditorKit kit = componentUI.getEditorKit(component);
            if (kit instanceof BaseKit) {
                 Action a = ((BaseKit)kit).getActionByName(editorActionName);
                if (a != null) {
                    KeyStroke[] keys = km.getKeyStrokesForAction(a);
                    if (keys != null && keys.length > 0) {
                        ret = keys;
                    }
                }
            }
        }
    }
    return ret;
}
项目:incubator-netbeans    文件:AdvancedActionPanel.java   
public AdvancedActionPanel(AntProjectCookie project, Set/*<TargetLister.Target>*/ allTargets) {
    this.project = project;
    this.allTargets = allTargets;
    initComponents();
    Mnemonics.setLocalizedText(targetLabel, NbBundle.getMessage(AdvancedActionPanel.class, "AdvancedActionsPanel.targetLabel.text"));
    Mnemonics.setLocalizedText(targetDescriptionLabel, NbBundle.getMessage(AdvancedActionPanel.class, "AdvancedActionsPanel.targetDescriptionLabel.text"));
    Mnemonics.setLocalizedText(propertiesLabel, NbBundle.getMessage(AdvancedActionPanel.class, "AdvancedActionsPanel.propertiesLabel.text"));
    Mnemonics.setLocalizedText(verbosityLabel, NbBundle.getMessage(AdvancedActionPanel.class, "AdvancedActionsPanel.verbosityLabel.text"));
    // Hack; EditorKit does not permit "fallback" kits, so we have to
    // mimic what the IDE itself does:
    EditorKit kit = propertiesPane.getEditorKit();
    String clazz = kit.getClass().getName();
    if (clazz.equals("javax.swing.text.DefaultEditorKit") || // NOI18N
            clazz.equals("javax.swing.JEditorPane$PlainEditorKit")) { // NOI18N
        propertiesPane.setEditorKit(JEditorPane.createEditorKitForContentType("text/plain")); // NOI18N
    }
    // Make ENTER run OK, not change the combo box.
    targetComboBox.getInputMap().remove(KeyStroke.getKeyStroke("ENTER")); // NOI18N
    initializeFields();
}
项目:incubator-netbeans    文件:Typing.java   
public Typing(final EditorKit kit, final String textWithPipe) {
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                pane = new JEditorPane();
                pane.setEditorKit(kit);
                Document doc = pane.getDocument();
                // Required by Java's default key typed
                doc.putProperty(Language.class, HTMLTokenId.language());
                doc.putProperty("mimeType", "text/html");
                int caretOffset = textWithPipe.indexOf('|');
                String text;
                if (caretOffset != -1) {
                    text = textWithPipe.substring(0, caretOffset) + textWithPipe.substring(caretOffset + 1);
                } else {
                    text = textWithPipe;
                }
                pane.setText(text);
                pane.setCaretPosition((caretOffset != -1) ? caretOffset : doc.getLength());
            }
        });
    } catch (InterruptedException | InvocationTargetException e) {
        throw new RuntimeException(e.getCause());
    }
}
项目:incubator-netbeans    文件:TypingCompletionUnitTest.java   
public Context(final EditorKit kit, final String textWithPipe) {
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                pane = new JEditorPane();
                pane.setEditorKit(kit);
                Document doc = pane.getDocument();
                // Required by Java's default key typed
                doc.putProperty(Language.class, JavaTokenId.language());
                doc.putProperty("mimeType", "text/x-java");
                int caretOffset = textWithPipe.indexOf('|');
                String text;
                if (caretOffset != -1) {
                    text = textWithPipe.substring(0, caretOffset) + textWithPipe.substring(caretOffset + 1);
                } else {
                    text = textWithPipe;
                }
                pane.setText(text);
                pane.setCaretPosition((caretOffset != -1) ? caretOffset : doc.getLength());
            }
        });
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
项目:incubator-netbeans    文件:DiffContentPanel.java   
private Action getAction(String key) {
    if (key == null) {
        return null;
    }

    // Try to find the action from kit.
    EditorKit kit = editorPane.getEditorKit();

    if (kit == null) { // kit is cleared in closeDocument()

        return null;
    }

    Action[] actions = kit.getActions();

    for (int i = 0; i < actions.length; i++) {
        if (key.equals(actions[i].getValue(Action.NAME))) {
            return actions[i];
        }
    }

    return null;
}
项目:incubator-netbeans    文件:LegacyFormattersProvider.java   
private Formatter getFormatter() {
    if (legacyFormatter == null) {
        EditorKit kit = MimeLookup.getLookup(mimePath).lookup(EditorKit.class);
        if (kit != null) {
            try {
                Method createFormatterMethod = kit.getClass().getDeclaredMethod("createFormatter"); //NOI18N
                legacyFormatter = createFormatterMethod.invoke(kit);
            } catch (Exception e) {
                legacyFormatter = e;
            }
        } else {
            legacyFormatter = NO_FORMATTER;
        }
    }
    return legacyFormatter instanceof Formatter ? (Formatter) legacyFormatter : null;
}
项目:incubator-netbeans    文件:Formatter.java   
/**
 * Gets <code>Formatter</code> implementation for given mime type.
 * 
 * @param mimeType The mime type to get the <code>Formatter</code> for.
 * 
 * @return <code>Formatter</code> implementation created by the mime
 *   type's editor kit.
 * @deprecated Use Editor Indentation API.
 * @since 1.18
 */
public static synchronized Formatter getFormatter(String mimeType) {
    MimePath mimePath = MimePath.parse(mimeType);
    Formatter formatter = mimePath2Formatter.get(mimePath);

    if (formatter == null) {
        EditorKit editorKit = MimeLookup.getLookup(mimePath).lookup(EditorKit.class);
        if (editorKit instanceof BaseKit) {
            formatter = callCreateFormatterMethod((BaseKit) editorKit);
        } else {
            formatter = callCreateFormatterMethod(BaseKit.getKit(BaseKit.class));
        }
        mimePath2Formatter.put(mimePath, formatter);
    }

    return formatter;
}
项目:incubator-netbeans    文件:FormEditorSupport.java   
@Override
protected void loadFromStreamToKit(StyledDocument doc, InputStream stream, EditorKit kit) throws IOException, BadLocationException {
    if (guardedEditor == null) {
        guardedEditor = new FormGEditor();
        GuardedSectionsFactory gFactory = GuardedSectionsFactory.find(((DataEditorSupport.Env) env).getMimeType());
        if (gFactory != null) {
            guardedProvider = gFactory.create(guardedEditor);
        }
    }

    if (guardedProvider != null) {
        guardedEditor.doc = doc;
        Charset c = FileEncodingQuery.getEncoding(this.getDataObject().getPrimaryFile());
        Reader reader = guardedProvider.createGuardedReader(stream, c);
        try {
            kit.read(reader, doc, 0);
        } finally {
            reader.close();
        }
    } else {
        super.loadFromStreamToKit(doc, stream, kit);
    }
}
项目:incubator-netbeans    文件:SwingBrowserImpl.java   
@Override
public EditorKit getEditorKitForContentType( String type ) {
    if( "text/html".equals( type ) ) {
        return new HTMLEditorKit() {
            @Override
            public Document createDefaultDocument() {
                StyleSheet styles = getStyleSheet();
                //#200472 - hack to make JDK 1.7 javadoc readable
                StyleSheet ss = new FilteredStyleSheet();

                ss.addStyleSheet(styles);

                HTMLDocument doc = new HTMLDocument(ss);
                doc.setParser(getParser());
                doc.setAsynchronousLoadPriority(4);
                doc.setTokenThreshold(100);
                return doc;
            }
        };
    }
    return super.getEditorKitForContentType( type );
}
项目:incubator-netbeans    文件:FoldView.java   
@Override
public JComponent getToolTip(double x, double y, Shape allocation) {
    Container container = getContainer();
    if (container instanceof JEditorPane) {
        JEditorPane editorPane = (JEditorPane) getContainer();
        JEditorPane tooltipPane = new JEditorPane();
        EditorKit kit = editorPane.getEditorKit();
        Document doc = getDocument();
        if (kit != null && doc != null) {
            Element lineRootElement = doc.getDefaultRootElement();
            tooltipPane.putClientProperty(FoldViewFactory.DISPLAY_ALL_FOLDS_EXPANDED_PROPERTY, true);
            try {
                // Start-offset of the fold => line start => position
                int lineIndex = lineRootElement.getElementIndex(fold.getStartOffset());
                Position pos = doc.createPosition(
                        lineRootElement.getElement(lineIndex).getStartOffset());
                // DocumentView.START_POSITION_PROPERTY
                tooltipPane.putClientProperty("document-view-start-position", pos); // NOI18N
                // End-offset of the fold => line end => position
                lineIndex = lineRootElement.getElementIndex(fold.getEndOffset());
                pos = doc.createPosition(lineRootElement.getElement(lineIndex).getEndOffset());
                // DocumentView.END_POSITION_PROPERTY
                tooltipPane.putClientProperty("document-view-end-position", pos); // NOI18N
                tooltipPane.putClientProperty("document-view-accurate-span", true); // NOI18N
                // Set the same kit and document
                tooltipPane.setEditorKit(kit);
                tooltipPane.setDocument(doc);
                tooltipPane.setEditable(false);
                return new FoldToolTip(editorPane, tooltipPane, getBorderColor());
            } catch (BadLocationException e) {
                // => return null
            }
        }
    }
    return null;
}
项目:incubator-netbeans    文件:BaseDocument.java   
/**
 * Print into given container.
 *
 * @param container printing container into which the printing will be done.
 * @param usePrintColoringMap use printing coloring settings instead
 *  of the regular ones.
 * @param lineNumberEnabled if null, the visibility of line numbers is the same as it is given by settings
 *  for the line number visibility, otherwise the visibility equals the boolean value of the parameter
 * @param startOffset start offset of text to print
 * @param endOffset end offset of text to print
 */
public void print(PrintContainer container, boolean usePrintColoringMap, Boolean lineNumberEnabled, int startOffset,
                  int endOffset) {
    readLock();
    try {
        boolean lineNumberEnabledPar = true;
        boolean forceLineNumbers = false;
        if (lineNumberEnabled != null) {
            lineNumberEnabledPar = lineNumberEnabled.booleanValue();
            forceLineNumbers = lineNumberEnabled.booleanValue();
        }

        EditorUI editorUI;
        EditorKit kit = getEditorKit();
        if (kit instanceof BaseKit) {
            editorUI = ((BaseKit) kit).createPrintEditorUI(this, usePrintColoringMap, lineNumberEnabledPar);
        } else {
            editorUI = new EditorUI(this, usePrintColoringMap, lineNumberEnabledPar);
        }

        if (forceLineNumbers) {
            editorUI.setLineNumberVisibleSetting(true);
            editorUI.setLineNumberEnabled(true);
            editorUI.updateLineNumberWidth(0);
        }

        DrawGraphics.PrintDG printDG = new DrawGraphics.PrintDG(container);
        DrawEngine.getDrawEngine().draw(printDG, editorUI, startOffset, endOffset, 0, 0, Integer.MAX_VALUE);
    } catch (BadLocationException e) {
        LOG.log(Level.WARNING, null, e);
    } finally {
        readUnlock();
    }
}
项目:incubator-netbeans    文件:BaseDocument.java   
private EditorKit getEditorKit() {
    EditorKit editorKit = MimeLookup.getLookup(mimeType).lookup(EditorKit.class);
    if (editorKit == null) {
        // Try 'text/plain'
        LOG.log(Level.CONFIG, "No registered editor kit for ''{0}'', trying ''text/plain''.", mimeType);
        editorKit = MimeLookup.getLookup("text/plain").lookup(EditorKit.class); //NOI18N
        if (editorKit == null) {
            LOG.config("No registered editor kit for 'text/plain', using default.");
            editorKit = new PlainEditorKit();
        }
    }
    return editorKit;
}
项目:openjdk-jdk10    文件:JEditorPaneOperator.java   
/**
 * Maps {@code JEditorPane.setEditorKit(EditorKit)} through queue
 */
public void setEditorKit(final EditorKit editorKit) {
    runMapping(new MapVoidAction("setEditorKit") {
        @Override
        public void map() {
            ((JEditorPane) getSource()).setEditorKit(editorKit);
        }
    });
}
项目:incubator-netbeans    文件:Utilities.java   
/**
 * Gets the mime type of a document in <code>JTextComponent</code>. If
 * the mime type can't be determined this method will return <code>null</code>.
 * It tries to determine the document's mime type first and if that does not
 * work it uses mime type from the <code>EditorKit</code> attached to the
 * component.
 * 
 * @param component The component to get the mime type for.
 * 
 * @return The mime type of a document opened in the component or <code>null</code>.
 */
/* package */ static String getMimeType(JTextComponent component) {
    Document doc = component.getDocument();
    String mimeType = getMimeType(doc);
    if (mimeType == null) {
        EditorKit kit = component.getUI().getEditorKit(component);
        if (kit != null) {
            mimeType = kit.getContentType();
        }
    }
    return mimeType;
}
项目:incubator-netbeans    文件:FoldHierarchyExecution.java   
private String getMimeType() {
    EditorKit ek = component.getUI().getEditorKit(component);
    String mimeType;

    if (ek != null) {
        mimeType = ek.getContentType();
    } else if (component.getDocument() != null) {
        mimeType = DocumentUtilities.getMimeType(component.getDocument());
    } else {
        mimeType = "";
    }
    return mimeType;
}
项目:incubator-netbeans    文件:HintDataObject.java   
@MimeRegistration(mimeType=DeclarativeHintTokenId.MIME_TYPE, service=EditorKit.class)
public static NbEditorKit createEditorKit() {
    return new NbEditorKit() {
        @Override public String getContentType() {
            return DeclarativeHintTokenId.MIME_TYPE;
        }
    };
}
项目:incubator-netbeans    文件:GuardedBlockTest.java   
@Override
protected void saveFromKitToStream(StyledDocument doc, EditorKit kit, OutputStream stream) throws IOException, BadLocationException {
    if (guardedProvider != null) {
        Charset c = FileEncodingQuery.getEncoding(this.getDataObject().getPrimaryFile());
        Writer writer = guardedProvider.createGuardedWriter(stream, c);
        try {
            kit.write(writer, doc, 0, doc.getLength());
        } finally {
            writer.close();
        }
    } else {
        super.saveFromKitToStream(doc, kit, stream);
    }
}
项目:jdk8u-jdk    文件:MultiTextUI.java   
/**
 * Invokes the <code>getEditorKit</code> method on each UI handled by this object.
 *
 * @return the value obtained from the first UI, which is
 * the UI obtained from the default <code>LookAndFeel</code>
 */
public EditorKit getEditorKit(JTextComponent a) {
    EditorKit returnValue =
        ((TextUI) (uis.elementAt(0))).getEditorKit(a);
    for (int i = 1; i < uis.size(); i++) {
        ((TextUI) (uis.elementAt(i))).getEditorKit(a);
    }
    return returnValue;
}
项目:incubator-netbeans    文件:EditorActionUtilities.java   
DefaultSearchableKit(EditorKit kit) {
    for (Action action : kit.getActions()) {
        if (action != null) {
            name2actionRef.put((String)action.getValue(Action.NAME), new WeakReference<Action>(action));
        }
    }
}
项目:incubator-netbeans    文件:EditorRegistryWatcher.java   
public void registerPresenterUpdater(PresenterUpdater updater) {
    presenterUpdaters.add(updater);
    JTextComponent activeTextComponent = activeTextComponentRef.get();
    if (activeTextComponent != null) {
        EditorKit kit = activeTextComponent.getUI().getEditorKit(activeTextComponent);
        if (kit != null) {
            updater.setActiveAction(EditorActionUtilities.getAction(kit, updater.getActionName()));
        }
    }
}
项目:incubator-netbeans    文件:EditorRegistryWatcher.java   
private void updateActiveActionInPresenters(JTextComponent c) {
    if (c == activeTextComponentRef.get()) {
        return;
    }
    activeTextComponentRef = new WeakReference<JTextComponent>(c);
    EditorKit kit = (c != null) ? c.getUI().getEditorKit(c) : null;
    SearchableEditorKit searchableKit = (kit != null) ? EditorActionUtilities.getSearchableKit(kit) : null;
    for (PresenterUpdater updater : presenterUpdaters.getList()) {
        Action a = (searchableKit != null) ? searchableKit.getAction(updater.getActionName()) : null;
        updater.setActiveAction(a);
    }
}
项目:incubator-netbeans    文件:KeyBindingsUpdater.java   
public void addKit(EditorKit kit) {
    Map<String,List<List<KeyStroke>>> actionName2BindingLocal;
    synchronized (this) {
        actionName2BindingLocal = actionName2Binding; // actionName2binding not mutated
        kitRefs.add(new KitReference(kit));
    }
    updateKits(actionName2BindingLocal, Collections.singletonList(new KitReference(kit)));
}
项目:incubator-netbeans    文件:KeyBindingsUpdater.java   
public synchronized void removeKit(EditorKit kit) {
    for (Iterator<KitReference> it = kitRefs.iterator(); it.hasNext();) {
        KitReference ref = it.next();
        if (ref.get() == kit) {
            it.remove();
        }
    }
    checkEmpty();
}
项目:incubator-netbeans    文件:KeyBindingsUpdater.java   
private static void updateKits(Map<String,List<List<KeyStroke>>> actionName2binding, List<KitReference> kitRefs) {
    // Update kits without locks (a.putValue() is done)
    for (KitReference kitRef : kitRefs) {
        EditorKit kit = kitRef.get();
        if (kit == null) { // Might be null since this is a copy of orig. list
            continue;
        }
        Action[] actions = kit.getActions();
        for (int i = 0; i < actions.length; i++) {
            Action a = actions[i];
            String actionName = (String) a.getValue(Action.NAME);
            @SuppressWarnings("unchecked")
            List<List<KeyStroke>> origAccels = (List<List<KeyStroke>>) 
                    a.getValue(AbstractEditorAction.MULTI_ACCELERATOR_LIST_KEY);
            List<List<KeyStroke>> accels = actionName2binding.get(actionName);
            if (accels == null) {
                accels = Collections.emptyList();
            }
            if (origAccels == null || !origAccels.equals(accels)) {
                a.putValue(AbstractEditorAction.MULTI_ACCELERATOR_LIST_KEY, accels);
                if (accels.size() > 0) {
                    // First keystroke of first multi-key accelerator in the list
                    a.putValue(Action.ACCELERATOR_KEY, accels.get(0).get(0));
                }
            }
        }
    }
}
项目:openjdk-jdk10    文件:JEditorPaneOperator.java   
/**
 * Maps {@code JEditorPane.getEditorKitForContentType(String)} through queue
 */
public EditorKit getEditorKitForContentType(final String string) {
    return (runMapping(new MapAction<EditorKit>("getEditorKitForContentType") {
        @Override
        public EditorKit map() {
            return ((JEditorPane) getSource()).getEditorKitForContentType(string);
        }
    }));
}
项目:incubator-netbeans    文件:EditorUtilitiesTest.java   
@Test
public void testGetAction() throws Exception {
    EditorKit editorKit = new DefaultEditorKit();
    String actionName = DefaultEditorKit.backwardAction;
    Action result = EditorUtilities.getAction(editorKit, actionName);
    for (Action expected : editorKit.getActions()) {
        if (actionName.equals(expected.getValue(Action.NAME))) {
            assertEquals(expected, result);
            return;
        }
    }
    fail("Action " + actionName + " not found.");
}
项目:incubator-netbeans    文件:CloneableEditorRecentPaneTest.java   
@Override
protected EditorKit createEditorKit () {
    return new NbLikeEditorKit () {
        @Override
        public Void call() throws Exception {
            super.call();
            return null;
        }

    };
}