下面列出了java.awt.Container#getParent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
void updateTabName(String name) {
if (DEBUG) {
System.out.println(">>>>>" + name + " " + MainPanel.getTabbIndex(this));
StackTraceElement[] s = new Throwable().getStackTrace();
System.out.println(" .(" + s[1].getFileName() + ":" + s[1].getLineNumber() + ") ");
System.out.println(" .(" + s[2].getFileName() + ":" + s[2].getLineNumber() + ") ");
}
Container tabb = getParent();
while (!(tabb instanceof JTabbedPane)) {
tabb = tabb.getParent();
}
JTabbedPane tabbedPane = (JTabbedPane) tabb;
int index = MainPanel.getTabbIndex(this);
tabbedPane.setTitleAt(index, name);
// tabUI = new TabUI(name);
// tabbedPane.setTabComponentAt(index, tabUI);
}
@Override
protected void unconfigureEnclosingScrollPane()
{
super.unconfigureEnclosingScrollPane();
Container p = getParent();
if (p instanceof JViewport)
{
Container gp = p.getParent();
if (gp instanceof JScrollPane)
{
JScrollPane scrollPane = (JScrollPane) gp;
// Make certain we are the viewPort's view and not, for
// example, the rowHeaderView of the scrollPane -
// an implementor of fixed columns might do this.
JViewport viewport = scrollPane.getViewport();
if (viewport == null || viewport.getView() != this)
{
return;
}
scrollPane.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, null);
}
}
}
public boolean isObscured() {
Container container = (target instanceof Container) ?
(Container)target : target.getParent();
if (container == null) {
return true;
}
Container parent;
while ((parent = container.getParent()) != null) {
container = parent;
}
if (container instanceof Window) {
XWindowPeer wpeer = (XWindowPeer)(container.getPeer());
if (wpeer != null) {
return (wpeer.winAttr.visibilityState !=
wpeer.winAttr.AWT_UNOBSCURED);
}
}
return true;
}
/**
* Tries to determine the parent this panel is part of.
*
* @param cont the container to get the parent for
* @param parentClass the class of the parent to obtain
* @return the parent if one exists or null if not
*/
public static Object getParent(Container cont, Class parentClass) {
Container result;
Container parent;
result = null;
parent = cont;
while (parent != null) {
if (parentClass.isInstance(parent)) {
result = parent;
break;
}
else {
parent = parent.getParent();
}
}
return result;
}
public boolean isObscured() {
Container container = (target instanceof Container) ?
(Container)target : target.getParent();
if (container == null) {
return true;
}
Container parent;
while ((parent = container.getParent()) != null) {
container = parent;
}
if (container instanceof Window) {
XWindowPeer wpeer = (XWindowPeer)(container.getPeer());
if (wpeer != null) {
return (wpeer.winAttr.visibilityState !=
wpeer.winAttr.AWT_UNOBSCURED);
}
}
return true;
}
/**
* Layout the components in the Container using the layout logic of the parent
* FlowLayout class.
*
* @param target the Container using this WrapLayout
*/
@Override
public final void layoutContainer(final Container target) {
Dimension size = preferredLayoutSize(target);
// When a frame is minimized or maximized the preferred size of the
// Container is assumed not to change. Therefore we need to force a
// validate() to make sure that space, if available, is allocated to
// the panel using a WrapLayout.
if (size.equals(preferredLayoutSize)) {
super.layoutContainer(target);
} else {
preferredLayoutSize = size;
Container top = target;
while (!(top instanceof Window) && top.getParent() != null) {
top = top.getParent();
}
top.validate();
}
}
public void showGoToDialog() {
if (goToDialog==null) {
goToDialog = new GoToDialog(this);
// center dialog on videoPanel view
Container c = VideoPlayer.this.getParent();
while (c!=null) {
if (c instanceof JSplitPane) {
Dimension dim = c.getSize();
Point p = c.getLocationOnScreen();
int x = (dim.width - goToDialog.getBounds().width) / 2;
int y = (dim.height - goToDialog.getBounds().height) / 2;
goToDialog.setLocation(p.x+x, p.y+y);
break;
}
c = c.getParent();
}
}
else {
goToDialog.setPlayer(this);
}
goToDialog.setVisible(true);
}
/**
* {@inheritDoc}
*
* <p>Overridden to take into account for possible parent {@code JLayer}s.
*
* @see javax.swing.JLayer
*/
// Note: Same implementation as in JXTable#getEnclosingScrollPane() but changed to get the
// parent and viewport view using
// the methods SwingUtilities#getUnwrappedParent(Component) and
// SwingUtilities#getUnwrappedView(JViewport) respectively.
@Override
protected JScrollPane getEnclosingScrollPane() {
Container p = SwingUtilities.getUnwrappedParent(this);
if (p instanceof JViewport) {
Container gp = p.getParent();
if (gp instanceof JScrollPane) {
JScrollPane scrollPane = (JScrollPane) gp;
// Make certain we are the viewPort's view and not, for
// example, the rowHeaderView of the scrollPane -
// an implementor of fixed columns might do this.
JViewport viewport = scrollPane.getViewport();
if (viewport == null || SwingUtilities.getUnwrappedView(viewport) != this) {
return null;
}
return scrollPane;
}
}
return null;
}
private static void revalidateParents(Container container) {
while (container != null) {
container.invalidate();
container.validate();
container.repaint();
container = container.getParent();
}
}
private static void revalidateParents(Container container) {
while (container != null) {
container.invalidate();
container.validate();
container.repaint();
container = container.getParent();
}
}
Container getTopmostProvider(Container focusCycleRoot, Component aComponent) {
Container aCont = aComponent.getParent();
Container ftp = null;
while (aCont != focusCycleRoot && aCont != null) {
if (aCont.isFocusTraversalPolicyProvider()) {
ftp = aCont;
}
aCont = aCont.getParent();
}
if (aCont == null) {
return null;
}
return ftp;
}
@Override
protected void onWizardStarting(@NotNull ModelWizard.Facade wizard) {
FlutterProjectModel model = getModel();
myKotlinCheckBox.setText(FlutterBundle.message("module.wizard.language.name_kotlin"));
mySwiftCheckBox.setText(FlutterBundle.message("module.wizard.language.name_swift"));
myBindings.bindTwoWay(new SelectedProperty(myUseAndroidxCheckBox), getModel().useAndroidX());
TextProperty packageNameText = new TextProperty(myPackageName);
Expression<String> computedPackageName = new DomainToPackageExpression(model.companyDomain(), model.projectName()) {
@Override
public String get() {
return super.get().replaceAll("_", "");
}
};
BoolProperty isPackageSynced = new BoolValueProperty(true);
myBindings.bind(packageNameText, computedPackageName, isPackageSynced);
myBindings.bind(model.packageName(), packageNameText);
myListeners.listen(packageNameText, value -> isPackageSynced.set(value.equals(computedPackageName.get())));
// The wizard changed substantially in 3.5. Something causes this page to not get properly validated
// after it is added to the Swing tree. Here we check that we have to validate the tree, then do so.
// It only needs to be done once, so we remove the listener to prevent possible flicker.
focusListener = new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
super.focusGained(e);
Container parent = myRoot;
while (parent != null && !(parent instanceof JBLayeredPane)) {
parent = parent.getParent();
}
if (parent != null) {
parent.validate();
}
myPackageName.removeFocusListener(focusListener);
}
};
myPackageName.addFocusListener(focusListener);
}
protected QueryEditorComponent getEditor(){
Container parent=getParent();
while(parent!=null && !(parent instanceof QueryEditorComponent)){
parent=parent.getParent();
}
if(parent!=null) return (QueryEditorComponent)parent;
else return null;
}
private JTabbedPane getTabbedPaneParent(Container c) {
while (c != null) {
if (c instanceof JTabbedPane)
return (JTabbedPane) c;
c = c.getParent();
}
return null;
}
Container getTopmostProvider(Container focusCycleRoot, Component aComponent) {
Container aCont = aComponent.getParent();
Container ftp = null;
while (aCont != focusCycleRoot && aCont != null) {
if (aCont.isFocusTraversalPolicyProvider()) {
ftp = aCont;
}
aCont = aCont.getParent();
}
if (aCont == null) {
return null;
}
return ftp;
}
@Override
public Dimension preferredLayoutSize(Container target) {
Insets insets = target.getInsets();
Component[] children = target.getComponents();
int across = 1;
int width = 0;
int height = 0;
int margin = mSheet.getScale().scale(MARGIN);
if (children.length > 0) {
Dimension size = children[0].getPreferredSize();
Container parent = target.getParent();
if (parent != null) {
Insets parentInsets = parent.getInsets();
int avail = parent.getWidth() - (parentInsets.left + parentInsets.right);
int pageWidth = size.width;
avail -= insets.left + insets.right + pageWidth;
pageWidth += margin;
while (true) {
avail -= pageWidth;
if (avail >= 0) {
across++;
} else {
break;
}
}
}
width = (size.width + margin) * across - margin;
int pagesDown = children.length / across;
if (children.length % across != 0) {
pagesDown++;
}
height = (size.height + margin) * pagesDown - margin;
}
return new Dimension(insets.left + insets.right + width, insets.top + insets.bottom + height);
}
Container getTopmostProvider(Container focusCycleRoot, Component aComponent) {
Container aCont = aComponent.getParent();
Container ftp = null;
while (aCont != focusCycleRoot && aCont != null) {
if (aCont.isFocusTraversalPolicyProvider()) {
ftp = aCont;
}
aCont = aCont.getParent();
}
if (aCont == null) {
return null;
}
return ftp;
}
/**
* Forwards the {@code scrollRectToVisible()} message to the
* {@code JComponent}'s parent. Components that can service
* the request, such as {@code JViewport},
* override this method and perform the scrolling.
*
* @param aRect the visible {@code Rectangle}
* @see javax.swing.JViewport
*/
@Override
public void scrollRectToVisible(Rectangle aRect)
{
Container parent;
int dx = getX();
int dy = getY();
for (parent = getParent(); (parent != null) && !(parent instanceof JComponent)
&& !(parent instanceof CellRendererPane); parent = parent.getParent())
{
final Rectangle bounds = parent.getBounds();
dx += bounds.x;
dy += bounds.y;
}
if ((parent != null) && !(parent instanceof CellRendererPane))
{
aRect.x += dx;
aRect.y += dy;
((JComponent) parent).scrollRectToVisible(aRect);
aRect.x -= dx;
aRect.y -= dy;
}
}
private void selectElementInPane(final JEditorPane pane, final TreeNodeAdapter tna, final boolean focus) {
RP.post(new Runnable() {
public void run() {
pane.setCaretPosition(tna.getDocumentElement().getStartOffset());
}
});
if(focus) {
// try to activate outer TopComponent
Container temp = pane;
while (!(temp instanceof TopComponent)) {
temp = temp.getParent();
}
((TopComponent) temp).requestActive();
}
}
Container getTopmostProvider(Container focusCycleRoot, Component aComponent) {
Container aCont = aComponent.getParent();
Container ftp = null;
while (aCont != focusCycleRoot && aCont != null) {
if (aCont.isFocusTraversalPolicyProvider()) {
ftp = aCont;
}
aCont = aCont.getParent();
}
if (aCont == null) {
return null;
}
return ftp;
}