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();
}
}
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);
}
}
});
}
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;
}
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();
}
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);
}
Aggregations