Java Code Examples for javax.swing.text.Document#getProperty()

The following examples show how to use javax.swing.text.Document#getProperty() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void performClickAction(final Document doc, final int offset, final HyperlinkType type) {
    final String issueId = getIssueId(doc, offset, type);
    if(issueId == null) {
        return;
    }

    class IssueDisplayer implements Runnable {
        @Override
        public void run() {
            DataObject dobj = (DataObject) doc.getProperty(Document.StreamDescriptionProperty);
            FileObject fileObject = null;
            if (dobj != null) {
                fileObject = dobj.getPrimaryFile();
            }
            if(fileObject == null) {
                Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "EditorHyperlinkProviderImpl - no file found for given document");
                return;
            }
            Util.openIssue(fileObject, issueId);
        }
    }
    RequestProcessor.getDefault().post(new IssueDisplayer());
}
 
Example 2
Source Project: netbeans   File: SyntaxHighlighting.java    License: Apache License 2.0 6 votes vote down vote up
/** Creates a new instance of SyntaxHighlighting */
public SyntaxHighlighting(Document document) {
    this.document = document;
    String mimeType = (String) document.getProperty("mimeType"); //NOI18N
    if (mimeType != null && mimeType.startsWith("test")) { //NOI18N
        this.mimeTypeForOptions = mimeType;
    } else {
        this.mimeTypeForOptions = null;
    }
    
    // Start listening on changes in global colorings since they may affect colorings for target language
    findFCSInfo("", null);

    hierarchy = TokenHierarchy.get(document);
    hierarchy.addTokenHierarchyListener(WeakListeners.create(TokenHierarchyListener.class, this, hierarchy));
}
 
Example 3
private Document createDocument(EditorKit kit, URL page)
{
    // we have pageProperties, because we can be in situation that
    // old page is being removed & new page is not yet created...
    // we need somewhere store important data.
    Document doc = kit.createDefaultDocument();
    if (pageProperties != null)
    {
        // transfer properties discovered in stream to the
        // document property collection.
        for (Enumeration<String> e = pageProperties.keys(); e
                .hasMoreElements();)
        {
            Object key = e.nextElement();
            doc.putProperty(key, pageProperties.get(key));
        }
    }
    if (doc.getProperty(Document.StreamDescriptionProperty) == null)
    {
        doc.putProperty(Document.StreamDescriptionProperty, page);
    }
    return doc;
}
 
Example 4
Source Project: netbeans   File: DataObjectEnvFactory.java    License: Apache License 2.0 5 votes vote down vote up
static FileObject getFileObject(Document doc) {
    Object sdp = doc.getProperty(Document.StreamDescriptionProperty);
    if (sdp instanceof FileObject) {
        return (FileObject)sdp;
    }
    if (sdp instanceof DataObject) {
        return ((DataObject)sdp).getPrimaryFile();
    }
    return null;
}
 
Example 5
Source Project: netbeans   File: SQLCompletionProvider.java    License: Apache License 2.0 5 votes vote down vote up
private static TokenSequence<SQLTokenId> getSQLTokenSequence(Document doc) {
    // Hack until the SQL editor is entirely ported to the Lexer API.
    if (doc.getProperty(Language.class) == null) {
        doc.putProperty(Language.class, SQLTokenId.language());
    }
    TokenHierarchy<?> hierarchy = TokenHierarchy.get(doc);
    return hierarchy.tokenSequence(SQLTokenId.language());
}
 
Example 6
Source Project: netbeans   File: FastImportAction.java    License: Apache License 2.0 5 votes vote down vote up
private FileObject getFile(Document doc) {
    DataObject od = (DataObject) doc.getProperty(Document.StreamDescriptionProperty);
    
    if (od == null)
        return null;
    
    return od.getPrimaryFile();
}
 
Example 7
Source Project: netbeans   File: JsfHtmlExtension.java    License: Apache License 2.0 5 votes vote down vote up
public void checkELEnabled(HtmlParserResult result) {
    Document doc = result.getSnapshot().getSource().getDocument(true);
    InputAttributes inputAttributes = (InputAttributes) doc.getProperty(InputAttributes.class);
    if (inputAttributes == null) {
        inputAttributes = new InputAttributes();
        doc.putProperty(InputAttributes.class, inputAttributes);
    }
    Language xhtmlLang = Language.find(JsfUtils.XHTML_MIMETYPE); //NOI18N
    if (inputAttributes.getValue(LanguagePath.get(xhtmlLang), EL_ENABLED_KEY) == null) {
        inputAttributes.setValue(LanguagePath.get(xhtmlLang), EL_ENABLED_KEY, new Object(), false);

        //refresh token hierarchy so the EL becomes lexed
        recolor(doc);
    }
}
 
Example 8
Source Project: netbeans   File: JavaElementFoldManager.java    License: Apache License 2.0 5 votes vote down vote up
public synchronized void initFolds(FoldHierarchyTransaction transaction) {
    Document doc = operation.getHierarchy().getComponent().getDocument();
    Object od = doc.getProperty(Document.StreamDescriptionProperty);
    
    if (od instanceof DataObject) {
        FileObject file = ((DataObject)od).getPrimaryFile();

        task = JavaElementFoldTask.getTask(file);
        task.setJavaElementFoldManager(JavaElementFoldManager.this, file);
    }
}
 
Example 9
private static OffsetsBag getBag(Document doc) {
    OffsetsBag bag = (OffsetsBag) doc.getProperty(RemoveSurroundingCodePanel.class);                
    if (bag == null) {
        doc.putProperty(RemoveSurroundingCodePanel.class, bag = new OffsetsBag(doc));
    }        
    return bag;
}
 
Example 10
Source Project: netbeans   File: DebuggerAnnotation.java    License: Apache License 2.0 5 votes vote down vote up
static synchronized OffsetsBag getHighlightsBag(Document doc) {
    OffsetsBag bag = (OffsetsBag) doc.getProperty(DebuggerAnnotation.class);
    if (bag == null) {
        doc.putProperty(DebuggerAnnotation.class, bag = new OffsetsBag(doc, true));
    }
    return bag;
}
 
Example 11
Source Project: netbeans   File: Editor.java    License: Apache License 2.0 5 votes vote down vote up
private boolean saveFile( Component comp ) {
    if( comp == null ) return false;
    JTextComponent edit = (JTextComponent)com2text.get( comp );
    Document doc = edit.getDocument();
    File file = (File)doc.getProperty( FILE );
    boolean created = ((Boolean)doc.getProperty( CREATED )).booleanValue();
    
    return saveFile( comp, file, created );
}
 
Example 12
Source Project: netbeans   File: Utilities.java    License: Apache License 2.0 5 votes vote down vote up
/** Display the identity of the document together with the title property
 * and stream-description property.
 */
public static String debugDocument(Document doc) {
    return "<" + System.identityHashCode(doc) // NOI18N
        + ", title='" + doc.getProperty(Document.TitleProperty)
        + "', stream='" + doc.getProperty(Document.StreamDescriptionProperty)
        + ", " + doc.toString() + ">"; // NOI18N
}
 
Example 13
@Override
public FileObject getFileObject(Document doc) {
    Object o = doc.getProperty(Document.StreamDescriptionProperty);
    if (o instanceof DataObject) {
        return ((DataObject) o).getPrimaryFile();
    } else if (o instanceof FileObject) {
        return (FileObject) o;
    } else if (o != null) {
        LOG.warning("Unable to return FileObject for Document " + doc + ". StreamDescriptionProperty points to non-DataLoader, non-FileObject instace: " + o); //NOI18N
    }
    return null;
}
 
Example 14
Source Project: netbeans   File: HintsControllerImpl.java    License: Apache License 2.0 5 votes vote down vote up
public static void setErrors(Document doc, String layer, Collection<? extends ErrorDescription> errors) {
    DataObject od = (DataObject) doc.getProperty(Document.StreamDescriptionProperty);

    if (od == null)
        return ;
    
    try {
        setErrorsImpl(od.getPrimaryFile(), layer, errors);
    } catch (IOException e) {
        Exceptions.printStackTrace(e);
    }
}
 
Example 15
Source Project: netbeans   File: IntroduceHint.java    License: Apache License 2.0 5 votes vote down vote up
static final OffsetsBag introduceBag(Document doc) {
    OffsetsBag bag = (OffsetsBag) doc.getProperty(IntroduceHint.class);

    if (bag == null) {
        doc.putProperty(IntroduceHint.class, bag = new OffsetsBag(doc));
    }

    return bag;
}
 
Example 16
Source Project: netbeans   File: GoToSupport.java    License: Apache License 2.0 4 votes vote down vote up
private static FileObject getFileObject(Document doc) {
    DataObject od = (DataObject) doc.getProperty(Document.StreamDescriptionProperty);
    
    return od != null ? od.getPrimaryFile() : null;
}
 
Example 17
Source Project: netbeans   File: ComponentPeer.java    License: Apache License 2.0 4 votes vote down vote up
public static synchronized Dictionary getDictionary(Document doc) {
    Dictionary result = (Dictionary) doc.getProperty(CompoundDictionary.class);
    
    if (result != null) {
        return result;
    }
    
    Locale locale;
    
    FileObject file = NbEditorUtilities.getFileObject(doc);

    if (file != null) {
        locale = LocaleQuery.findLocale(file);
    } else {
        locale = DefaultLocaleQueryImplementation.getDefaultLocale();
    }
    
    if (locale == null) {
        locale = Locale.getDefault();
    }
    
    Dictionary d = ACCESSOR.lookupDictionary(locale);
    
    if (d == null)
        return null; //XXX
    
    List<Dictionary> dictionaries = new LinkedList<Dictionary>();
    
    dictionaries.add(getUsersLocalDictionary(locale));
    
    if (file != null) {
        Project p = FileOwnerQuery.getOwner(file);

        if (p != null) {
            Dictionary projectDictionary = getProjectDictionary(p, locale);

            if (projectDictionary != null) {
                dictionaries.add(projectDictionary);
            }
        }
    }
    
    dictionaries.add(d);
    
    result = CompoundDictionary.create(dictionaries.toArray(new Dictionary[0]));

    doc.putProperty(CompoundDictionary.class, result);
    knownDocuments.add(doc);
    
    return result;
}
 
Example 18
Source Project: netbeans   File: DocumentUtilities.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * This method should be used by swing document implementations that
 * want to support document listeners prioritization.
 * <br>
 * It should be called from document's constructor in the following way:<pre>
 *
 * class MyDocument extends AbstractDocument {
 *
 *     MyDocument() {
 *         super.addDocumentListener(DocumentUtilities.initPriorityListening(this));
 *     }
 *
 *     public void addDocumentListener(DocumentListener listener) {
 *         if (!DocumentUtilities.addDocumentListener(this, listener, DocumentListenerPriority.DEFAULT))
 *             super.addDocumentListener(listener);
 *     }
 *
 *     public void removeDocumentListener(DocumentListener listener) {
 *         if (!DocumentUtilities.removeDocumentListener(this, listener, DocumentListenerPriority.DEFAULT))
 *             super.removeDocumentListener(listener);
 *     }
 *
 * }</pre>
 *
 *
 * @param doc document to be initialized.
 * @return the document listener instance that should be added as a document
 *   listener typically by using <code>super.addDocumentListener()</code>
 *   in document's constructor.
 * @throws IllegalStateException when the document already has
 *   the property initialized.
 */
public static DocumentListener initPriorityListening(Document doc) {
    if (doc.getProperty(PriorityDocumentListenerList.class) != null) {
        throw new IllegalStateException(
                "PriorityDocumentListenerList already initialized for doc=" + doc); // NOI18N
    }
    PriorityDocumentListenerList listener = new PriorityDocumentListenerList();
    doc.putProperty(PriorityDocumentListenerList.class, listener);
    return listener;
}
 
Example 19
Source Project: netbeans   File: DocumentUtilities.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Get total count of document listeners attached to a particular document
 * (useful e.g. for logging).
 * <br/>
 * If the document uses priority listening then get the count of listeners
 * at all levels. If the document is not {@link AbstractDocument} the method
 * returns zero.
 * 
 * @param doc non-null document.
 * @return total count of document listeners attached to the document.
 */
public static int getDocumentListenerCount(Document doc) {
    PriorityDocumentListenerList pdll;
    return (pdll = (PriorityDocumentListenerList)doc.getProperty(PriorityDocumentListenerList.class)) != null
            ? pdll.getListenerCount()
            : ((doc instanceof AbstractDocument)
                    ? ((AbstractDocument)doc).getListeners(DocumentListener.class).length
                    : 0);
}
 
Example 20
Source Project: netbeans   File: DocumentUtilities.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Suitable for document implementations - removes document listener
 * from document with given priority and does not do anything
 * if the given document is not listener priority aware.
 * <br/>
 * Using this method in the document impls and defaulting
 * to super.removeDocumentListener() in case it returns false
 * will ensure that there won't be an infinite loop in case the super constructors
 * would remove some listeners prior initing of the priority listening.
 * 
 * @param doc document from which the listener should be removed.
 * @param listener document listener to remove.
 * @param priority priority with which the listener should be removed.
 * @return true if the priority listener was removed or false if the document
 *  does not support priority listening.
 */
public static boolean removePriorityDocumentListener(Document doc, DocumentListener listener,
DocumentListenerPriority priority) {
    PriorityDocumentListenerList priorityDocumentListenerList
            = (PriorityDocumentListenerList)doc.getProperty(PriorityDocumentListenerList.class);
    if (priorityDocumentListenerList != null) {
        priorityDocumentListenerList.remove(listener, priority.getPriority());
        return true;
    } else
        return false;
}