use of java.awt.event.HierarchyEvent 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.HierarchyEvent 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.HierarchyEvent 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.HierarchyEvent in project omegat by omegat-org.
the class TableColumnSizer method init.
/**
* Add various listeners to keep the columns in sync with the table's
* current width.
*/
private void init() {
table.getColumnModel().addColumnModelListener(colListener);
table.getModel().addTableModelListener(modelListener);
table.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
Object oldVal = evt.getOldValue();
Object newVal = evt.getNewValue();
if (newVal != null && newVal.equals(evt.getOldValue())) {
return;
}
boolean shouldAdjust = false;
if (evt.getPropertyName().equals("columnModel")) {
if (newVal != null && newVal instanceof TableColumnModel) {
((TableColumnModel) newVal).addColumnModelListener(colListener);
shouldAdjust = true;
}
if (oldVal != null && oldVal instanceof TableColumnModel) {
((TableColumnModel) oldVal).removeColumnModelListener(colListener);
}
} else if (evt.getPropertyName().equals("model")) {
if (newVal != null && newVal instanceof TableModel) {
((TableModel) newVal).addTableModelListener(modelListener);
shouldAdjust = true;
}
if (oldVal != null && oldVal instanceof TableModel) {
((TableModel) oldVal).removeTableModelListener(modelListener);
}
} else if (evt.getPropertyName().equals("font")) {
if ((newVal != null && !newVal.equals(oldVal)) || (oldVal != null && !oldVal.equals(newVal))) {
shouldAdjust = true;
}
}
if (shouldAdjust) {
reset();
// Queue up the adjustment because when the table has a
// RowSorter things can be out of sync at this point.
SwingUtilities.invokeLater(TableColumnSizer.this::adjustTableColumns);
}
}
});
table.addHierarchyBoundsListener(new HierarchyBoundsAdapter() {
@Override
public void ancestorResized(HierarchyEvent e) {
adjustTableColumns();
}
});
}
use of java.awt.event.HierarchyEvent 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();
}
Aggregations