下面列出了javax.swing.JFrame#dispose ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@RandomlyFails
public void testModelToViewCorrectness() throws Throwable {
for(String text : TEXTS) {
JEditorPane jep = createJep(text);
try {
checkModelToViewCorrectness(jep);
} catch (Throwable e) {
System.err.println("testModelToViewCorrectness processing {");
System.err.println(text);
System.err.println("} failed with:");
e.printStackTrace();
throw e;
} finally {
JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, jep);
if (frame != null) {
frame.dispose();
}
}
}
}
@RandomlyFails
public void testModelToViewConsistency() throws Throwable {
for(String text : TEXTS) {
JEditorPane jep = createJep(text);
try {
checkModelToViewConsistency(jep);
} catch (Throwable e) {
System.err.println("testModelToViewConsistency processing {");
System.err.println(text);
System.err.println("} failed with:");
e.printStackTrace();
throw e;
} finally {
JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, jep);
if (frame != null) {
frame.dispose();
}
}
}
}
private static BufferedImage renderImage(JPanel panel) {
JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.getContentPane().add(panel);
frame.pack();
BufferedImage bi = new BufferedImage(panel.getWidth(), panel.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = bi.createGraphics();
panel.print(graphics);
graphics.dispose();
frame.dispose();
return bi;
}
@Override
public void componentShown(ComponentEvent e) {
JFrame frame = (JFrame) e.getComponent();
runActualTest(device, latch, frame, result);
frame.setVisible(false);
frame.dispose();
latch.countDown();
}
/**
* Test if a dialog that has never been shown fire
* the WINDOW_CLOSED event on parent dispose().
* @throws Exception
*/
public static void testHidenChildDispose() throws Exception {
JFrame f = new JFrame();
JDialog dlg = new JDialog(f);
Listener l = new Listener();
dlg.addWindowListener(l);
f.dispose();
waitEvents();
assertEquals(0, l.getCount());
}
public File saveToFile(File captureFile) throws FileNotFoundException, IOException {
writePNG(captureFile);
ImageReader reader = getPNGImageReader();
ImageInputStream iis = ImageIO.createImageInputStream(new FileInputStream(captureFile));
reader.setInput(iis);
BufferedImage pngImage = reader.read(0);
IIOMetadata imageMetadata = reader.getImageMetadata(0);
Node root = imageMetadata.getAsTree(imageMetadata.getNativeMetadataFormatName());
IIOMetadataNode textNode = new IIOMetadataNode("tEXt");
ArrayList<Annotation> annotations = imagePanel.getAnnotations();
for (int i = 0; i < annotations.size(); i++) {
textNode.appendChild(getAnnotationNode((Annotation) annotations.get(i), i));
}
root.appendChild(textNode);
imageMetadata.mergeTree(imageMetadata.getNativeMetadataFormatName(), root);
IIOImage imageWrite = new IIOImage(pngImage, new ArrayList<BufferedImage>(), imageMetadata);
ImageWriter writer = getPNGImageWriter();
ImageOutputStream ios = ImageIO.createImageOutputStream(new FileOutputStream(captureFile));
writer.setOutput(ios);
writer.write(imageWrite);
writer.dispose();
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
ImagePanel finalImage = new ImagePanel(new FileInputStream(captureFile), false);
frame.add(finalImage, BorderLayout.CENTER);
frame.pack();
File savedFile = new File(captureFile.getParentFile(), "ext-" + captureFile.getName());
getScreenShot(frame.getContentPane(), savedFile);
frame.dispose();
return savedFile;
}
/**
* Test if a dialog fire the WINDOW_CLOSED event
* on parent dispose().
* @throws Exception
*/
public static void testVisibleChildParentDispose() throws Exception {
JFrame f = new JFrame();
JDialog dlg = new JDialog(f);
Listener l = new Listener();
dlg.addWindowListener(l);
dlg.setVisible(true);
f.dispose();
waitEvents();
assertEquals(1, l.getCount());
}
public void doStep() {
JFrame f = getFrame();
if (f != null) {
f.dispose();
}
System.out.println("Done");
testDone.countDown();
}
public void run() {
String title = getClass().getName();
JFrame frame = new JFrame(title);
frame.setVisible(true);
Color color = JColorChooser.showDialog(frame, title, Color.BLACK);
if (color != null) {
throw new Error("unexpected color: " + color);
}
frame.setVisible(false);
frame.dispose();
}
/**
* Test if a dialog fire the WINDOW_CLOSED event
* on parent dispose().
* @throws Exception
*/
public static void testVisibleChildParentDispose() throws Exception {
JFrame f = new JFrame();
JDialog dlg = new JDialog(f);
Listener l = new Listener();
dlg.addWindowListener(l);
dlg.setVisible(true);
f.dispose();
waitEvents();
assertEquals(1, l.getCount());
}
/**
* Test if a Window that has never been shown fire the
* WINDOW_CLOSED event on dispose()
*/
public static void testHidenWindowDispose() throws Exception {
JFrame f = new JFrame();
Listener l = new Listener();
f.addWindowListener(l);
f.dispose();
waitEvents();
assertEquals(0, l.getCount());
}
public void doStep() {
JFrame f = getFrame();
if (f != null) {
f.dispose();
}
System.out.println("Done");
testDone.countDown();
}
public void doStep() {
JFrame f = getFrame();
if (f != null) {
f.dispose();
}
System.out.println("Done");
testDone.countDown();
}
@Override
public void run() {
final JFrame mainFrame = new JFrame();
try {
testDefaultFont(mainFrame);
} finally {
mainFrame.dispose();
}
}
public static void main(final String[] args) throws Exception {
final JFrame frame = new DrawBitmaskToSurfaceTest();
frame.setBounds(10, 350, 200, 200);
frame.setVisible(true);
Thread.sleep(2000);
System.err.println("Change frame bounds...");
latch = new CountDownLatch(1);
frame.setBounds(10, 350, 90, 90);
frame.repaint();
try {
if (latch.getCount() > 0) {
latch.await();
}
} catch (InterruptedException e) {
}
frame.dispose();
if (theError != null) {
throw new RuntimeException("Test failed.", theError);
}
System.err.println("Test passed");
}
public void run() {
String title = getClass().getName();
JFrame frame = new JFrame(title);
frame.setVisible(true);
Color color = JColorChooser.showDialog(frame, title, Color.BLACK);
if (color != null) {
throw new Error("unexpected color: " + color);
}
frame.setVisible(false);
frame.dispose();
}
@Override
public void componentShown(ComponentEvent e) {
JFrame frame = (JFrame) e.getComponent();
runActualTest(device, latch, frame, result);
frame.setVisible(false);
frame.dispose();
latch.countDown();
}
/**
* Test if a Window that has never been shown fire the
* WINDOW_CLOSED event on dispose()
*/
public static void testHidenWindowDispose() throws Exception {
JFrame f = new JFrame();
Listener l = new Listener();
f.addWindowListener(l);
f.dispose();
waitEvents();
assertEquals(0, l.getCount());
}
/**
* Test if a dialog fire the WINDOW_CLOSED event
* on parent dispose().
* @throws Exception
*/
public static void testVisibleChildParentDispose() throws Exception {
JFrame f = new JFrame();
JDialog dlg = new JDialog(f);
Listener l = new Listener();
dlg.addWindowListener(l);
dlg.setVisible(true);
f.dispose();
waitEvents();
assertEquals(1, l.getCount());
}
/**
* Test if a dialog that has never been shown fire
* the WINDOW_CLOSED event on parent dispose().
* @throws Exception
*/
public static void testHidenChildDispose() throws Exception {
JFrame f = new JFrame();
JDialog dlg = new JDialog(f);
Listener l = new Listener();
dlg.addWindowListener(l);
f.dispose();
waitEvents();
assertEquals(0, l.getCount());
}