本文整理匯總了Java中org.openide.loaders.DataObject.getCookie方法的典型用法代碼示例。如果您正苦於以下問題:Java DataObject.getCookie方法的具體用法?Java DataObject.getCookie怎麽用?Java DataObject.getCookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openide.loaders.DataObject
的用法示例。
在下文中一共展示了DataObject.getCookie方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPosition
import org.openide.loaders.DataObject; //導入方法依賴的package包/類
public PositionBounds getPosition() {
try {
DataObject dobj = DataObject.find(getParentFile());
if (dobj != null) {
EditorCookie.Observable obs = (EditorCookie.Observable)dobj.getCookie(EditorCookie.Observable.class);
if (obs != null && obs instanceof CloneableEditorSupport) {
CloneableEditorSupport supp = (CloneableEditorSupport)obs;
if (loc == null) {
loc = location();
}
PositionBounds bounds = new PositionBounds(
supp.createPositionRef(loc[0], Position.Bias.Forward),
supp.createPositionRef(Math.max(loc[0], loc[1]), Position.Bias.Forward)
);
return bounds;
}
}
} catch (DataObjectNotFoundException ex) {
ex.printStackTrace();
}
return null;
}
示例2: linePart
import org.openide.loaders.DataObject; //導入方法依賴的package包/類
public static PositionBounds linePart(FileObject file, int start, int end) {
try {
DataObject od = DataObject.find(file);
if (od == null)
return null;
EditorCookie ec = od.getCookie(EditorCookie.class);
if (!(ec instanceof CloneableEditorSupport)) {
return null;
}
final CloneableEditorSupport ces = (CloneableEditorSupport) ec;
checkOffsetsAndLog(start, end);
return new PositionBounds(ces.createPositionRef(start, Position.Bias.Forward), ces.createPositionRef(end, Position.Bias.Backward));
} catch (IOException e) {
LOG.log(Level.INFO, null, e);
return null;
}
}
示例3: getOpenedPanes
import org.openide.loaders.DataObject; //導入方法依賴的package包/類
@Override
public JEditorPane[] getOpenedPanes(FileObject fo) {
DataObject dobj;
try {
dobj = DataObject.find(fo);
} catch (DataObjectNotFoundException ex) {
return new JEditorPane[0];
}
EditorCookie editorCookie = dobj.getCookie(EditorCookie.class);
if (editorCookie == null) {
return new JEditorPane[0];
}
return editorCookie.getOpenedPanes();
}
示例4: getChildren
import org.openide.loaders.DataObject; //導入方法依賴的package包/類
private static Children getChildren(DataObject dobj, boolean noBeanInfo) {
if (noBeanInfo) {
return Children.LEAF;
}
InstanceCookie inst = (InstanceCookie)dobj.getCookie(InstanceCookie.class);
if (inst == null) return Children.LEAF;
try {
Class clazz = inst.instanceClass();
if (BeanContext.class.isAssignableFrom(clazz) ||
BeanContextProxy.class.isAssignableFrom(clazz)) {
return new InstanceChildren ();
} else {
return Children.LEAF;
}
} catch (Exception ex) {
return Children.LEAF;
}
}
示例5: dumpFile
import org.openide.loaders.DataObject; //導入方法依賴的package包/類
/** @author David Kaspar */
public String dumpFile(DataObject dao) {
SourceCookie sc = (SourceCookie) dao.getCookie(SourceCookie.class);
SourceElement se = sc.getSource();
ClassElement[] cea = se.getClasses();
if (cea == null)
return "";
ClassElement[] newcea = new ClassElement[cea.length];
for (int a = 0; a < cea.length; a ++)
newcea[a] = (ClassElement) cea[a].clone();
newcea = sortClasses(newcea);
String str = "";
for (int a = 0; a < newcea.length; a ++)
str += newcea[a].toString();
return str;
}
示例6: getMappingResourceOccurPlaces
import org.openide.loaders.DataObject; //導入方法依賴的package包/類
private static List<OccurrenceItem> getMappingResourceOccurPlaces(FileObject configFile, String resourceName, boolean searchingPathOnly) {
List<OccurrenceItem> foundPlaces = new ArrayList<OccurrenceItem>();
try {
// Get the document for this file
DataObject dataObject = DataObject.find(configFile);
EditorCookie result = dataObject.getCookie(EditorCookie.class);
if (result == null) {
throw new IllegalStateException("File " + configFile + " does not have an EditorCookie.");
}
CloneableEditorSupport editor = (CloneableEditorSupport) result;
BaseDocument document = (BaseDocument) editor.openDocument();
XMLSyntaxSupport syntaxSupport = XMLSyntaxSupport.getSyntaxSupport(document);
if (syntaxSupport == null) {
return foundPlaces;
}
return syntaxSupport.runWithSequence(0,
(TokenSequence ts) -> {
int start = document.getStartPosition().getOffset();
return getMappingResourceOccurPlacesLocked(syntaxSupport, ts, start, editor, resourceName, searchingPathOnly);
});
} catch (IOException | BadLocationException ex) {
ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, ex);
}
return foundPlaces;
}
示例7: test135210
import org.openide.loaders.DataObject; //導入方法依賴的package包/類
/**
* SIOOBE when reformatting code with unclosed javadoc comment.
* Regression test.
*
* http://www.netbeans.org/issues/show_bug.cgi?id=135210
*/
public void test135210() throws Exception {
testFile = new File(getWorkDir(), "Test.java");
TestUtilities.copyStringToFile(testFile,
"package hierbas.del.litoral;\n"
+ "\n"
+ "public class Test {\n"
+ "}\n");
FileObject testSourceFO = FileUtil.toFileObject(testFile);
DataObject testSourceDO = DataObject.find(testSourceFO);
EditorCookie ec = (EditorCookie)testSourceDO.getCookie(EditorCookie.class);
final Document doc = ec.openDocument();
doc.putProperty(Language.class, JavaTokenId.language());
String content =
"package hierbas.del.litoral;\n"
+ "public class Test{\n"
+ "/**\n"
+ "*\n"
+ "*\n"
+ "}\n";
String golden =
"package hierbas.del.litoral;\n"
+ "\n"
+ "public class Test {\n"
+ "\n"
+ " /**\n"
+ " *\n"
+ " *\n"
+ " * }\n";
reformat(doc, content, golden);
}
示例8: isDocumentActive
import org.openide.loaders.DataObject; //導入方法依賴的package包/類
/**
* Verify whether the given document is still being actively used
* by the corresponding editor support.
*/
public static boolean isDocumentActive(Document doc) {
DataObject dob = getDataObject(doc);
if (dob != null) {
EditorCookie editorCookie = (EditorCookie)dob.getCookie(EditorCookie.class);
if (editorCookie != null) {
Document ecDoc = editorCookie.getDocument(); // returns null if closed
if (ecDoc == doc) { // actively used by ec
return true;
}
}
}
return false;
}
示例9: getInstance
import org.openide.loaders.DataObject; //導入方法依賴的package包/類
public static synchronized AnnotationHolder getInstance(FileObject file) {
if (file == null)
return null;
try {
DataObject od = DataObject.find(file);
AnnotationHolder result = file2Holder.get(od);
if (result == null) {
EditorCookie editorCookie = od.getCookie(EditorCookie.class);
if (editorCookie == null) {
LOG.log(Level.WARNING,
"No EditorCookie.Observable for file: {0}", FileUtil.getFileDisplayName(file)); //NOI18N
} else {
Document doc = editorCookie.getDocument();
if (doc instanceof BaseDocument) {
file2Holder.put(od, result = new AnnotationHolder(file, od, (BaseDocument) doc));
}
}
}
return result;
} catch (IOException e) {
LOG.log(Level.FINE, null, e);
return null;
}
}
示例10: cancel
import org.openide.loaders.DataObject; //導入方法依賴的package包/類
/** Cancels current internationalizing session and re-layout top component to original layout. */
public void cancel() {
if (replaceCount>0) {
//Need to save resource
DataObject resource = support.getResourceHolder().getResource();
if (resource != null) {
SaveCookie save = resource.getCookie(SaveCookie.class);
if (save!=null) {
try {
save.save();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
replaceCount = 0;
// No memory leaks.
support = null;
if(LOG.isLoggable(Level.FINEST)) {
LOG.logp(Level.FINEST, getClass().getName(), "cancel()",
"Sets the I18nSupport to null"); // NOI18N
}
closeDialog();
}
示例11: getTargetFile
import org.openide.loaders.DataObject; //導入方法依賴的package包/類
public static FileObject getTargetFile(JTextComponent targetComponent) {
if (targetComponent == null) {
return null;
}
DataObject d = NbEditorUtilities.getDataObject(targetComponent.getDocument());
if (d == null) {
return null;
}
EditorCookie ec = (EditorCookie) d.getCookie(EditorCookie.class);
if (ec == null || ec.getOpenedPanes() == null) {
return null;
}
return d.getPrimaryFile();
}
示例12: isModified
import org.openide.loaders.DataObject; //導入方法依賴的package包/類
@Override
public EditorCookie isModified(FileObject file) {
DataObject.Registry regs = DataObject.getRegistry();
Set<DataObject> modified = (Set<DataObject>) regs.getModifiedSet();
for (DataObject dobj : modified) {
if (file.equals(dobj.getPrimaryFile())) {
EditorCookie ec = (EditorCookie) dobj.getCookie(EditorCookie.class);
return ec;
}
}
return null;
}
示例13: openAndFocusElement
import org.openide.loaders.DataObject; //導入方法依賴的package包/類
private void openAndFocusElement(final TreeNodeAdapter selected, final boolean selectLineOnly) {
BaseDocument bdoc = (BaseDocument)selected.getDocumentElement().getDocument();
DataObject dobj = NbEditorUtilities.getDataObject(bdoc);
if(dobj == null) return ;
final EditorCookie.Observable ec = (EditorCookie.Observable)dobj.getCookie(EditorCookie.Observable.class);
if(ec == null) return ;
try {
final Document doc = ec.openDocument(); //wait to editor to open
}catch(IOException ioe) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe);
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JEditorPane[] panes = ec.getOpenedPanes();
if (panes != null && panes.length > 0) {
// editor already opened, so just select
selectElementInPane(panes[0], selected, !selectLineOnly);
} else if(!selectLineOnly) {
// editor not opened yet
ec.open();
panes = ec.getOpenedPanes();
if (panes != null && panes.length > 0) {
selectElementInPane(panes[0], selected, true);
}
}
}
});
}
示例14: performAction
import org.openide.loaders.DataObject; //導入方法依賴的package包/類
/**
* Actually performs the action. Implements superclass abstract method.
* @param activatedNodes Currently activated nodes.
*/
protected void performAction(final Node[] activatedNodes) {
if (activatedNodes.length != 1) {
return;
}
final Node node = activatedNodes[0];
DataObject dataObject = node.getCookie(DataObject.class);
if (dataObject == null) {
return;
}
if (FileOwnerQuery.getOwner(dataObject.getPrimaryFile()) == null) {
return;
}
EditorCookie editorCookie = node.getCookie(EditorCookie.class);
if (editorCookie == null) {
editorCookie = dataObject.getCookie(EditorCookie.class);
if (editorCookie == null) {
return;
}
}
editorCookie.open();
I18nManager.getDefault().internationalize(dataObject);
}
示例15: openSnapshot
import org.openide.loaders.DataObject; //導入方法依賴的package包/類
public void openSnapshot(FileObject snapshotFo) {
try {
DataObject snapshotDo = DataObject.find(snapshotFo);
OpenCookie open = snapshotDo.getCookie(OpenCookie.class);
if (open != null) {
open.open();
}
} catch (DataObjectNotFoundException ex) {
Exceptions.printStackTrace(ex);
}
}