Search in sources :

Example 1 with HierarchyListener

use of java.awt.event.HierarchyListener in project jdk8u_jdk by JetBrains.

the class TwentyThousandTest method doAttempt.

private static void doAttempt() throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            final JFileChooser chooser = new JFileChooser(tmpDir);
            chooser.updateUI();
            // Postpone JFileChooser closing until it becomes visible
            chooser.addHierarchyListener(new HierarchyListener() {

                @Override
                public void hierarchyChanged(HierarchyEvent e) {
                    if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                        if (chooser.isShowing()) {
                            Thread thread = new Thread(new Runnable() {

                                public void run() {
                                    try {
                                        Thread.sleep(INTERVAL);
                                        // Close JFileChooser
                                        SwingUtilities.invokeLater(new Runnable() {

                                            public void run() {
                                                chooser.cancelSelection();
                                            }
                                        });
                                    } catch (InterruptedException e) {
                                        throw new RuntimeException(e);
                                    }
                                }
                            });
                            thread.start();
                        }
                    }
                }
            });
            chooser.showOpenDialog(null);
        }
    });
    DisposerRecord disposerRecord = new DisposerRecord() {

        public void dispose() {
            disposerComplete = true;
        }
    };
    disposerComplete = false;
    Disposer.addRecord(new Object(), disposerRecord);
    while (!disposerComplete) {
        Util.generateOOME();
    }
}
Also used : DisposerRecord(sun.java2d.DisposerRecord) HierarchyEvent(java.awt.event.HierarchyEvent) HierarchyListener(java.awt.event.HierarchyListener)

Example 2 with HierarchyListener

use of java.awt.event.HierarchyListener in project android by JetBrains.

the class NlPreviewManager method processFileEditorChange.

private void processFileEditorChange(@Nullable final TextEditor newEditor) {
    if (myPendingShowComponent != null) {
        myPendingShowComponent.removeHierarchyListener(myHierarchyListener);
        myPendingShowComponent = null;
    }
    myToolWindowUpdateQueue.cancelAllUpdates();
    myToolWindowUpdateQueue.queue(new Update("update") {

        @Override
        public void run() {
            if (!myToolWindowReady || myToolWindowDisposed) {
                return;
            }
            boolean renderImmediately = myRenderImmediately;
            myRenderImmediately = false;
            final Editor activeEditor = newEditor != null ? newEditor.getEditor() : null;
            if (myToolWindow == null) {
                if (activeEditor == null) {
                    return;
                } else if (!activeEditor.getComponent().isShowing()) {
                    // per project frame.)
                    if (!mySeenEditor) {
                        myPendingShowComponent = activeEditor.getComponent();
                        if (myHierarchyListener == null) {
                            myHierarchyListener = new HierarchyListener() {

                                @Override
                                public void hierarchyChanged(HierarchyEvent hierarchyEvent) {
                                    if ((hierarchyEvent.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
                                        if (hierarchyEvent.getComponent() == myPendingShowComponent && myPendingShowComponent.isShowing()) {
                                            myPendingShowComponent.removeHierarchyListener(myHierarchyListener);
                                            mySeenEditor = true;
                                            myPendingShowComponent = null;
                                            processFileEditorChange(getActiveLayoutXmlEditor());
                                        }
                                    }
                                }
                            };
                        }
                        myPendingShowComponent.addHierarchyListener(myHierarchyListener);
                    }
                    return;
                }
                mySeenEditor = true;
                initToolWindow();
            }
            final AndroidEditorSettings settings = AndroidEditorSettings.getInstance();
            final boolean hideForNonLayoutFiles = settings.getGlobalState().isHideForNonLayoutFiles();
            if (activeEditor == null) {
                myToolWindowForm.setFile(null);
                myToolWindow.setAvailable(!hideForNonLayoutFiles, null);
                return;
            }
            final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(activeEditor.getDocument());
            myToolWindowForm.setFile(psiFile);
            if (psiFile == null) {
                myToolWindow.setAvailable(!hideForNonLayoutFiles, null);
                return;
            }
            myToolWindow.setAvailable(true, null);
            final boolean visible = AndroidEditorSettings.getInstance().getGlobalState().isVisible();
            if (visible) {
                // tool window is shown and the time the render has completed
                if (!myToolWindow.isVisible()) {
                    RenderResult renderResult = myToolWindowForm.getRenderResult();
                    if (renderResult != null && renderResult.getFile() != psiFile) {
                        myToolWindowForm.setRenderResult(RenderResult.createBlank(psiFile));
                    }
                }
                myToolWindow.show(null);
            }
        }
    });
}
Also used : HierarchyEvent(java.awt.event.HierarchyEvent) AndroidEditorSettings(org.jetbrains.android.uipreview.AndroidEditorSettings) RenderResult(com.android.tools.idea.rendering.RenderResult) PsiFile(com.intellij.psi.PsiFile) Update(com.intellij.util.ui.update.Update) com.intellij.openapi.fileEditor(com.intellij.openapi.fileEditor) Editor(com.intellij.openapi.editor.Editor) HierarchyListener(java.awt.event.HierarchyListener)

Example 3 with HierarchyListener

use of java.awt.event.HierarchyListener in project gradle by gradle.

the class SinglePaneUIInstance method createCenterPanel.

private Component createCenterPanel() {
    splitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitter.setTopComponent(createMainGradlePanel());
    splitter.setBottomComponent(outputPanelLord.getMainPanel());
    splitter.setContinuousLayout(true);
    //This little bit of tedium is so we can set our size based on window's size. This listens
    //for when the window is actually shown. It then adds a listen to store the location.
    splitter.addHierarchyListener(new HierarchyListener() {

        public void hierarchyChanged(HierarchyEvent e) {
            if (HierarchyEvent.SHOWING_CHANGED == (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED)) {
                //we only want the first one of these, so remove ourselves as a listener.
                splitter.removeHierarchyListener(this);
                Window window = SwingUtilities.getWindowAncestor(splitter);
                if (window != null) {
                    Dimension dimension = window.getSize();
                    //we'll just make ourselves half the height of the window
                    int halfHeight = dimension.height / 2;
                    splitter.setDividerLocation(halfHeight);
                }
                PreferencesAssistant.restoreSettings(settings, splitter, SPLITTER_PREFERENCES_ID, SinglePaneUIInstance.class);
                //Now that we're visible, this is so we save the location when the splitter is moved.
                splitter.addPropertyChangeListener(new PropertyChangeListener() {

                    public void propertyChange(PropertyChangeEvent evt) {
                        if (JSplitPane.DIVIDER_LOCATION_PROPERTY.equals(evt.getPropertyName())) {
                            PreferencesAssistant.saveSettings(settings, splitter, SPLITTER_PREFERENCES_ID, SinglePaneUIInstance.class);
                        }
                    }
                });
            }
        }
    });
    //this keeps the bottom the same size when resizing the window. Extra space is added/removed from the top.
    splitter.setResizeWeight(1);
    return splitter;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) HierarchyEvent(java.awt.event.HierarchyEvent) HierarchyListener(java.awt.event.HierarchyListener)

Example 4 with HierarchyListener

use of java.awt.event.HierarchyListener in project jdk8u_jdk by JetBrains.

the class WindowsMenuBarUI method installListeners.

@Override
protected void installListeners() {
    if (WindowsLookAndFeel.isOnVista()) {
        installWindowListener();
        hierarchyListener = new HierarchyListener() {

            public void hierarchyChanged(HierarchyEvent e) {
                if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0) {
                    if (menuBar.isDisplayable()) {
                        installWindowListener();
                    } else {
                        uninstallWindowListener();
                    }
                }
            }
        };
        menuBar.addHierarchyListener(hierarchyListener);
    }
    super.installListeners();
}
Also used : HierarchyEvent(java.awt.event.HierarchyEvent) HierarchyListener(java.awt.event.HierarchyListener)

Example 5 with HierarchyListener

use of java.awt.event.HierarchyListener in project android by JetBrains.

the class Choreographer method animate.

/**
   * @deprecated Legacy method to animate components. Each component animates on its own and has a
   * choreographer that is bound to that component's visibility. This can be safely removed once
   * all the legacy AnimatedComponents in Studio has been replaced by the new UI.
   */
@Deprecated
public static void animate(final AnimatedComponent component) {
    final Choreographer choreographer = new Choreographer(30, component);
    choreographer.register(component);
    HierarchyListener listener = event -> {
        if (choreographer.mTimer.isRunning() && !component.isShowing()) {
            choreographer.mTimer.stop();
        } else if (!choreographer.mTimer.isRunning() && component.isShowing()) {
            choreographer.mTimer.start();
        }
    };
    listener.hierarchyChanged(null);
    component.addHierarchyListener(listener);
}
Also used : List(java.util.List) ActionListener(java.awt.event.ActionListener) HierarchyListener(java.awt.event.HierarchyListener) NotNull(org.jetbrains.annotations.NotNull) LinkedList(java.util.LinkedList) ActionEvent(java.awt.event.ActionEvent) javax.swing(javax.swing) HierarchyListener(java.awt.event.HierarchyListener)

Aggregations

HierarchyListener (java.awt.event.HierarchyListener)20 HierarchyEvent (java.awt.event.HierarchyEvent)19 Window (java.awt.Window)5 WindowEvent (java.awt.event.WindowEvent)5 Component (java.awt.Component)4 WindowAdapter (java.awt.event.WindowAdapter)4 DetachedFrame (com.haulmont.cuba.desktop.DetachedFrame)2 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 JDialog (javax.swing.JDialog)2 JComboBoxWithBorder (org.freeplane.core.ui.components.JComboBoxWithBorder)2 RenderResult (com.android.tools.idea.rendering.RenderResult)1 ButtonTabComponent (com.haulmont.cuba.desktop.sys.ButtonTabComponent)1 DisabledGlassPane (com.haulmont.cuba.desktop.sys.DisabledGlassPane)1 Editor (com.intellij.openapi.editor.Editor)1 com.intellij.openapi.fileEditor (com.intellij.openapi.fileEditor)1 PsiFile (com.intellij.psi.PsiFile)1 Update (com.intellij.util.ui.update.Update)1 java.awt (java.awt)1 Dialog (java.awt.Dialog)1