package io.github.jonestimd.swing;

import java.awt.Component;
import java.awt.event.ActionEvent;

import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;

public abstract class SwingTest {
    private static JFrame frame = new JFrame("test");

    @BeforeClass
    public static void showFrame() throws Exception {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                frame.setContentPane(new JPanel());
                frame.pack();
                frame.setVisible(true);
                frame.toFront();
            }
        });
    }

    @AfterClass
    public static void disposeFrame() {
        frame.dispose();
    }

    @After
    public void removeComopnents() throws Exception {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                frame.getContentPane().removeAll();
            }
        });
    }

    protected void showComponent(final Component component) throws Exception {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                frame.getContentPane().add(component);
                frame.pack();
                component.requestFocus();
            }
        });
    }

    protected void invokeAction(final JComponent source, String actionKey) throws Exception {
        invokeAction(source, source.getActionMap().get(actionKey));
    }

    protected void invokeAction(final Component source, final Action action) throws Exception {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                action.actionPerformed(new ActionEvent(source, -1, (String) action.getValue(Action.ACTION_COMMAND_KEY)));
            }
        });
    }
}
@@ -525,54 +525,13 @@
 ait(
-new Runnable() %7B%0A            public void run()
+() -%3E
  %7B%0A 
@@ -533,36 +533,32 @@
 %3E %7B%0A            
-    
 frame.setContent
@@ -581,36 +581,32 @@
 ));%0A            
-   
- 
 frame.pack();%0A  
@@ -595,36 +595,32 @@
   frame.pack();%0A
-    
             fram
@@ -647,28 +647,24 @@
             
-  
-  
 frame.toFron
@@ -664,38 +664,24 @@
 .toFront();%0A
-            %7D%0A
         %7D);%0A
@@ -815,10 +815,10 @@
 eCom
-o
 p
+o
 nent
@@ -881,72 +881,13 @@
 ait(
-new Runnable() %7B%0A            public void run() %7B%0A               
+() -%3E
  fra
@@ -921,33 +921,8 @@
 ll()
-;%0A            %7D%0A        %7D
 );%0A 
@@ -1047,61 +1047,16 @@
 ait(
-new Runnable() %7B%0A            public void run() %7B%0A    
+() -%3E %7B%0A
     
@@ -1106,36 +1106,32 @@
 t);%0A            
-    
 frame.pack();%0A  
@@ -1120,36 +1120,32 @@
   frame.pack();%0A
-    
             comp
@@ -1166,30 +1166,16 @@
 ocus();%0A
-            %7D%0A
         
@@ -1491,61 +1491,16 @@
 ait(
-new Runnable() %7B%0A            public void run() %7B%0A    
+() -%3E %7B%0A
     
@@ -1617,22 +1617,8 @@
 ));%0A
-            %7D%0A
     

Fix spelling