下面列出了java.awt.Window#getWindows ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void main(String[] args) throws AWTException {
robot = new Robot();
// test escape after selection
start();
click(KeyEvent.VK_ESCAPE);
toolkit.realSync();
// test double escape after editing
start();
click(KeyEvent.VK_1);
click(KeyEvent.VK_0);
click(KeyEvent.VK_ESCAPE);
click(KeyEvent.VK_ESCAPE);
toolkit.realSync();
// all windows should be closed
for (Window window : Window.getWindows()) {
if (window.isVisible()) {
throw new Error("found visible window: " + window.getName());
}
}
}
public static void main(String[] args) throws AWTException {
robot = new Robot();
// test escape after selection
start();
click(KeyEvent.VK_ESCAPE);
toolkit.realSync();
// test double escape after editing
start();
click(KeyEvent.VK_1);
click(KeyEvent.VK_0);
click(KeyEvent.VK_ESCAPE);
click(KeyEvent.VK_ESCAPE);
toolkit.realSync();
// all windows should be closed
for (Window window : Window.getWindows()) {
if (window.isVisible()) {
throw new Error("found visible window: " + window.getName());
}
}
}
public static void main(String[] args) throws AWTException {
robot = new Robot();
// test escape after selection
start();
click(KeyEvent.VK_ESCAPE);
toolkit.realSync();
// test double escape after editing
start();
click(KeyEvent.VK_1);
click(KeyEvent.VK_0);
click(KeyEvent.VK_ESCAPE);
click(KeyEvent.VK_ESCAPE);
toolkit.realSync();
// all windows should be closed
for (Window window : Window.getWindows()) {
if (window.isVisible()) {
throw new Error("found visible window: " + window.getName());
}
}
}
public static void main(String[] args) throws AWTException {
robot = new Robot();
// test escape after selection
start();
click(KeyEvent.VK_ESCAPE);
toolkit.realSync();
// test double escape after editing
start();
click(KeyEvent.VK_1);
click(KeyEvent.VK_0);
click(KeyEvent.VK_ESCAPE);
click(KeyEvent.VK_ESCAPE);
toolkit.realSync();
// all windows should be closed
for (Window window : Window.getWindows()) {
if (window.isVisible()) {
throw new Error("found visible window: " + window.getName());
}
}
}
public String getTitle() {
String title = getTitleFromNP(window);
Window[] windows = Window.getWindows();
String original = title;
int index = 1;
for (Window w : windows) {
if (w == window) {
return title;
}
if (!w.isVisible()) {
continue;
}
String wTitle = getTitleFromNP(w);
if (original.equals(wTitle)) {
title = original + "(" + index++ + ")";
}
}
return title;
}
public Component getComponent() {
if (component == null) {
Window activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
if (activeWindow != null) {
return activeWindow.getFocusOwner();
}
Window[] windows = Window.getWindows();
if (windows.length > 0) {
if (windows[0].getFocusOwner() != null) {
return windows[0].getFocusOwner();
}
return windows[0];
}
}
return component;
}
public static void main(String[] args) throws AWTException {
robot = new Robot();
// test escape after selection
start();
click(KeyEvent.VK_ESCAPE);
toolkit.realSync();
// test double escape after editing
start();
click(KeyEvent.VK_1);
click(KeyEvent.VK_0);
click(KeyEvent.VK_ESCAPE);
click(KeyEvent.VK_ESCAPE);
toolkit.realSync();
// all windows should be closed
for (Window window : Window.getWindows()) {
if (window.isVisible()) {
throw new Error("found visible window: " + window.getName());
}
}
}
public static void main(String[] args) throws AWTException {
robot = new Robot();
// test escape after selection
start();
click(KeyEvent.VK_ESCAPE);
robot.waitForIdle();
// test double escape after editing
start();
click(KeyEvent.VK_1);
click(KeyEvent.VK_0);
click(KeyEvent.VK_ESCAPE);
click(KeyEvent.VK_ESCAPE);
robot.waitForIdle();
// all windows should be closed
for (Window window : Window.getWindows()) {
if (window.isVisible()) {
throw new Error("found visible window: " + window.getName());
}
}
}
@Override
public void preferenceChange(PreferenceChangeEvent e) {
// Update to reflect new skin
if (e.getName().equals(GUIPreferences.SKIN_FILE)) {
showMainMenu();
frame.repaint();
} else if (e.getName().equals(GUIPreferences.UI_THEME)) {
try {
UIManager.setLookAndFeel((String)e.getNewValue());
// We went all Oprah and gave everybody frames...
// so now we have to let everybody who got a frame
// under their chair know that we updated our look
// and feel.
for (Frame f : Frame.getFrames()) {
SwingUtilities.updateComponentTreeUI(f);
}
// ...and also all of our windows and dialogs, etc.
for (Window w : Window.getWindows()) {
SwingUtilities.updateComponentTreeUI(w);
}
} catch (Exception ex) {
DefaultMmLogger.getInstance().error(getClass(), "preferenceChange(GUIPreferences.UI_THEME)", ex);
}
}
}
public static void main(String[] args) throws AWTException {
robot = new Robot();
// test escape after selection
start();
click(KeyEvent.VK_ESCAPE);
toolkit.realSync();
// test double escape after editing
start();
click(KeyEvent.VK_1);
click(KeyEvent.VK_0);
click(KeyEvent.VK_ESCAPE);
click(KeyEvent.VK_ESCAPE);
toolkit.realSync();
// all windows should be closed
for (Window window : Window.getWindows()) {
if (window.isVisible()) {
throw new Error("found visible window: " + window.getName());
}
}
}
public static void main(String[] args) throws AWTException {
robot = new Robot();
// test escape after selection
start();
click(KeyEvent.VK_ESCAPE);
toolkit.realSync();
// test double escape after editing
start();
click(KeyEvent.VK_1);
click(KeyEvent.VK_0);
click(KeyEvent.VK_ESCAPE);
click(KeyEvent.VK_ESCAPE);
toolkit.realSync();
// all windows should be closed
for (Window window : Window.getWindows()) {
if (window.isVisible()) {
throw new Error("found visible window: " + window.getName());
}
}
}
static Snapshot[] getGUISnapshots() {
List snapshots = new ArrayList(); //System.err.println("gGUI: thread = "+Thread.currentThread());
Window[] windows = Window.getWindows(); //System.err.println("gGUI: windows = "+windows.length);
for (int wi = 0; wi < windows.length; wi++) {
Window w = windows[wi]; //System.err.println("gGUI: w["+wi+"] = "+w+", is visible = "+w.isVisible());
if (!w.isVisible()) {
continue;
}
Dimension d = w.getSize(); //System.err.println("gGUI: size = "+d);
if (d.width == 0 || d.height == 0) {
continue;
}
BufferedImage bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bi.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
w.paint(g);
Raster raster = bi.getData();
Object data = raster.getDataElements(0, 0, d.width, d.height, null);
int[] dataArr; //System.err.println("gGUI: data = "+data);
if (data instanceof int[]) {
dataArr = (int[]) data;
} else {
continue;
}
String title = null;
if (w instanceof Frame) {
title = ((Frame) w).getTitle();
} else if (w instanceof Dialog) {
title = ((Dialog) w).getTitle();
} //System.err.println("gGUI: title = "+title);
snapshots.add(new Snapshot(w, title, d.width, d.height, dataArr));
}
Snapshot[] snapshotArr = (Snapshot[]) snapshots.toArray(new Snapshot[] {});
lastGUISnapshots = snapshotArr;
return snapshotArr;
}
/**
* Close all open MZmine windows, except the main (project) window
*/
public static void closeAllWindows() {
for (Window window : Window.getWindows()) {
if (window instanceof MainWindow)
continue;
window.dispose();
}
}
public static SettingsEditor find(GURPSCharacter character) {
for (Window window : Window.getWindows()) {
if (window.isShowing() && window instanceof SettingsEditor) {
SettingsEditor wnd = (SettingsEditor) window;
if (wnd.mCharacter == character) {
return wnd;
}
}
}
return null;
}
@Override
public void eventDispatched(AWTEvent event) {
KeyEvent e = (KeyEvent) event;
if (e.getKeyCode() == KeyEvent.VK_F6
&& e.getID() == KeyEvent.KEY_PRESSED) {
PumpernickelShowcaseApp frame = null;
for (Window w : Window.getWindows()) {
if (w instanceof PumpernickelShowcaseApp)
frame = (PumpernickelShowcaseApp) w;
}
VectorImage img = new VectorImage();
img.getOperations().addListListener(
new VectorImageInspector.StackTraceListener(), false);
frame.paint(img.createGraphics());
inspector.setVectorImage(img);
cardLayout.show(cardPanel, "inspector");
if (!VectorImageDemo.this.isShowing()) {
JComponent content = QDialog.createContentPanel(
"Would you like to switch to the VectorGraphics2D demo?",
"Pressing F6 took a snapshot of the current window as a VectorGraphics2D.",
null, // innerComponent,
true);
int option = QDialog.showDialog(frame,
"Show VectorGraphics Demo",
QDialog.QUESTION_MESSAGE, content, null, // leftControls,
DialogFooter.OK_CANCEL_OPTION,
DialogFooter.OK_OPTION, null, // dontShowKey,
null, // alwaysApplyKey,
DialogFooter.EscapeKeyBehavior.TRIGGERS_CANCEL);
if (option == DialogFooter.OK_OPTION) {
frame.showDemo(VectorImageDemo.this);
}
}
}
}
/**
* Update UI of all application windows immediately.
* Invoke after changing LaF.
*/
public static void updateUI() {
for( Window w : Window.getWindows() )
SwingUtilities.updateComponentTreeUI( w );
}
public void storeTo(ProfilerIDESettings settings) {
settings.setSourcesColoringEnabled(coloringChoice.isSelected());
PackageColorer.setRegisteredColors(colors);
for (Window w : Window.getWindows()) w.repaint();
}
public static void updateAllUI() {
Window[] windows = Window.getWindows();
for (Window window : windows) {
SwingUtilities.updateComponentTreeUI(window);
}
}
public void storeTo(ProfilerIDESettings settings) {
settings.setSourcesColoringEnabled(coloringChoice.isSelected());
PackageColorer.setRegisteredColors(colors);
for (Window w : Window.getWindows()) w.repaint();
}
public static JDialog create(String caption, String message, int messageType) {
// Bugfix #361, set the JDialog to appear in the Taskbar on Windows (ModalityType.APPLICATION_MODAL)
Window[] windows = Window.getWindows();
final JDialog d = windows == null || windows.length == 0 ?
new JDialog(null, caption, JDialog.ModalityType.APPLICATION_MODAL) :
new JDialog((Frame)null, caption, true);
if (message != null) initDialog(d, message, messageType);
// Bugfix #361, JDialog should use the VisualVM icon for better identification
List<Image> icons = new ArrayList();
icons.add(ImageUtilities.loadImage("org/netbeans/core/startup/frame.gif", true)); // NOI18N
icons.add(ImageUtilities.loadImage("org/netbeans/core/startup/frame24.gif", true)); // NOI18N
icons.add(ImageUtilities.loadImage("org/netbeans/core/startup/frame32.gif", true)); // NOI18N
icons.add(ImageUtilities.loadImage("org/netbeans/core/startup/frame48.gif", true)); // NOI18N
d.setIconImages(icons);
d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
d.setResizable(false);
d.setLocationRelativeTo(null);
// Bugfix #361, ensure that the dialog will be the topmost visible window after opening
d.addHierarchyListener(new HierarchyListener() {
public void hierarchyChanged(HierarchyEvent e) {
if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
if (d.isShowing()) {
// For some reason the dialog created with defined JDialog.ModalityType
// isn't displayed on Windows when opened by the NetBeans launcher. This
// code seems to workaround it while not breaking anything elsewhere.
// Disabled to fix jigsaw, the problem is not reproducible using [email protected]
// ComponentPeer peer = d.getPeer();
// if (peer != null) peer.setVisible(true);
d.removeHierarchyListener(this);
d.setAlwaysOnTop(true);
d.toFront();
d.setAlwaysOnTop(false);
}
}
}
});
return d;
}