Skip to content

Commit

Permalink
Make generic helper for action threads
Browse files Browse the repository at this point in the history
  • Loading branch information
fireduck64 committed Jan 21, 2020
1 parent 1950fc7 commit 029df4c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
1 change: 1 addition & 0 deletions iceleaf-ui/src/NodePanel.java
Expand Up @@ -150,6 +150,7 @@ private void startNode()
setMessageBox("");
}

@Override
public void setStatus(String msg)
{
this.setStatusBox(msg);
Expand Down
16 changes: 4 additions & 12 deletions iceleaf-ui/src/SendPanel.java
Expand Up @@ -91,20 +91,12 @@ public void setupPanel()

}

public class SendButtonListner implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
new SendButtonThread().start();

}
}


public class SendButtonThread extends Thread
public class SendButtonListner extends ThreadActionListener
{
public void run()
public void threadActionPerformed(ActionEvent e)
{

try
{
synchronized(state_obj)
Expand Down Expand Up @@ -151,7 +143,7 @@ public void run()
for(int i=0; i<SEND_DELAY; i+=SEND_DELAY_STEP)
{
setProgressBar(i, SEND_DELAY);
sleep(SEND_DELAY_STEP);
Thread.sleep(SEND_DELAY_STEP);
}
setStatusBox("Ready to broadcast");
setProgressBar(SEND_DELAY, SEND_DELAY);
Expand Down
41 changes: 41 additions & 0 deletions iceleaf-ui/src/ThreadActionListener.java
@@ -0,0 +1,41 @@

package snowblossom.iceleaf;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


/**
* Need an action listener to do a bunch of stuff, outside of the GUI thread
* use this. Just extend and implement threadActionPerformed.
*/
public abstract class ThreadActionListener implements ActionListener
{

/**
* This will be run in its own new thread on each action fired to this action listener
*/
public abstract void threadActionPerformed(ActionEvent e);

public void actionPerformed(ActionEvent e)
{
new ActionRunnerThread(e).start();
}

public class ActionRunnerThread extends Thread
{
private ActionEvent e;
public ActionRunnerThread(ActionEvent e)
{
this.e = e;
}

public void run()
{
threadActionPerformed(e);
}

}

}

0 comments on commit 029df4c

Please sign in to comment.