本文整理汇总了Java中javax.swing.text.JTextComponent.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java JTextComponent.getParent方法的具体用法?Java JTextComponent.getParent怎么用?Java JTextComponent.getParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.JTextComponent
的用法示例。
在下文中一共展示了JTextComponent.getParent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUsableWidth
import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private int getUsableWidth(JTextComponent component) {
Container parent = component.getParent();
if (parent instanceof JLayeredPane) {
parent = parent.getParent();
}
return (parent instanceof JViewport)
? ((JViewport)parent).getExtentSize().width
: component.getSize().width;
}
示例2: BraceMatchingSidebarComponent
import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@SuppressWarnings("LeakingThisInConstructor")
public BraceMatchingSidebarComponent(JTextComponent editor) {
this.editor = editor;
this.mimeType = DocumentUtilities.getMimeType(editor);
this.prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
final Lookup.Result r = MimeLookup.getLookup(org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(editor)).lookupResult(
FontColorSettings.class);
prefListenerGC = new PrefListener();
this.colorResult = r;
r.addLookupListener(WeakListeners.create(LookupListener.class, this , r));
prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, prefListenerGC, prefs));
loadPreferences();
editorPane = findEditorPane(editor);
Component parent = editor.getParent();
if (parent instanceof JLayeredPane) {
parent = parent.getParent();
}
if (parent instanceof JViewport) {
this.viewport = (JViewport)parent;
// see #219015; need to listen on viewport change to show/hide the tooltip
viewport.addChangeListener(WeakListeners.change(this, viewport));
}
TextUI ui = editor.getUI();
if (ui instanceof BaseTextUI) {
baseUI = (BaseTextUI)ui;
MasterMatcher.get(editor).addMatchListener(this);
} else {
baseUI = null;
}
setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
updatePreferredSize();
}
示例3: getUrl
import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
protected URL getUrl(JTextComponent comp) {
FileObject f = null;
if (comp instanceof Lookup.Provider) {
f = ((Lookup.Provider) comp).getLookup().lookup(FileObject.class);
}
if (f == null) {
Container container = comp.getParent();
while (container != null) {
if (container instanceof Lookup.Provider) {
f = ((Lookup.Provider) container).getLookup().lookup(FileObject.class);
if (f != null) {
break;
}
}
container = container.getParent();
}
}
if (f != null) {
try {
return f.getURL();
} catch (FileStateInvalidException e) {
LOG.log(Level.WARNING, "Can't get URL for " + f, e); //NOI18N
}
}
return null;
}
示例4: invokeDefaultAction
import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
boolean invokeDefaultAction(boolean onlyActive) {
JTextComponent comp = getComponent();
if (comp == null) {
Logger.getLogger(HintsUI.class.getName()).log(Level.WARNING, "HintsUI.invokeDefaultAction called, but comp == null");
return false;
}
Document doc = comp.getDocument();
cancel.set(false);
if (doc instanceof BaseDocument) {
try {
Rectangle carretRectangle = comp.modelToView(comp.getCaretPosition());
int line = Utilities.getLineOffset((BaseDocument) doc, comp.getCaretPosition());
FixData fixes;
String description;
if (!onlyActive) {
refresh(doc, comp.getCaretPosition());
AnnotationHolder holder = getAnnotationHolder(doc);
Pair<FixData, String> fixData = holder != null ? holder.buildUpFixDataForLine(line) : null;
if (fixData == null) return false;
fixes = fixData.first();
description = fixData.second();
} else {
AnnotationDesc activeAnnotation = ((BaseDocument) doc).getAnnotations().getActiveAnnotation(line);
if (activeAnnotation == null) {
return false;
}
String type = activeAnnotation.getAnnotationType();
if (!fixableAnnotations.contains(type) && onlyActive) {
return false;
}
if (onlyActive) {
refresh(doc, comp.getCaretPosition());
}
Annotations annotations = ((BaseDocument) doc).getAnnotations();
AnnotationDesc desc = annotations.getAnnotation(line, type);
ParseErrorAnnotation annotation = null;
if (desc != null) {
annotations.frontAnnotation(desc);
annotation = findAnnotation(doc, desc, line);
}
if (annotation == null) {
return false;
}
fixes = annotation.getFixes();
description = annotation.getDescription();
}
Point p = comp.modelToView(Utilities.getRowStartFromLineOffset((BaseDocument) doc, line)).getLocation();
p.y += carretRectangle.height;
if(comp.getParent() instanceof JViewport) {
p.x += ((JViewport)comp.getParent()).getViewPosition().x;
}
if(comp.getParent() instanceof JLayeredPane &&
comp.getParent().getParent() instanceof JViewport) {
p.x += ((JViewport)comp.getParent().getParent()).getViewPosition().x;
}
showPopup(fixes, description, comp, p);
return true;
} catch (BadLocationException ex) {
ErrorManager.getDefault().notify(ex);
}
}
return false;
}