-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ajt06004
committed
Jul 5, 2018
1 parent
82808cf
commit 6340f8b
Showing
4 changed files
with
179 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package edu.uconn.tripoint.ui; | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.Font; | ||
|
||
import javax.swing.BoxLayout; | ||
import javax.swing.JLabel; | ||
import javax.swing.JPanel; | ||
import javax.swing.JScrollPane; | ||
import javax.swing.JTextArea; | ||
|
||
@SuppressWarnings("serial") | ||
public class CommandOutputPanel extends JPanel { | ||
|
||
private JTextArea _ota; | ||
|
||
public CommandOutputPanel(Font font){ | ||
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); | ||
|
||
JLabel sol = new JLabel("Command Line Output:"); | ||
sol.setHorizontalAlignment(JLabel.LEFT); | ||
sol.setFont(font); | ||
_ota = new JTextArea(15, 35); | ||
_ota.setEditable(false); | ||
JScrollPane osp = new JScrollPane(_ota); | ||
osp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); | ||
osp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); | ||
JPanel opanel = new JPanel(new BorderLayout()); | ||
opanel.add(sol, BorderLayout.NORTH); | ||
opanel.add(osp, BorderLayout.CENTER); | ||
|
||
add(opanel); | ||
} | ||
|
||
public void addLine(String s){ | ||
_ota.append(s+"\n"); | ||
revalidate(); | ||
repaint(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package edu.uconn.tripoint.ui; | ||
|
||
|
||
import java.awt.BorderLayout; | ||
import java.awt.Font; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.PipedInputStream; | ||
import java.io.PipedOutputStream; | ||
import java.io.PrintStream; | ||
|
||
import javax.swing.JButton; | ||
import javax.swing.JDialog; | ||
import javax.swing.JFrame; | ||
import javax.swing.JOptionPane; | ||
import javax.swing.JPanel; | ||
import javax.swing.JProgressBar; | ||
import javax.swing.SwingWorker; | ||
|
||
public class CommandRunner { | ||
|
||
private JFrame _frame; | ||
private Font _labelfont; | ||
private Process _p; | ||
private String _title; | ||
|
||
public CommandRunner(JFrame frame, String title){ | ||
_frame = frame; | ||
_title = title; | ||
} | ||
|
||
|
||
|
||
public void run() { | ||
final JOptionPane pane = new JOptionPane(); | ||
|
||
final CommandOutputPanel op = new CommandOutputPanel(_labelfont); | ||
|
||
final JProgressBar jpb = new JProgressBar(); | ||
jpb.setSize(500, 10); | ||
jpb.setIndeterminate(true); | ||
|
||
final JButton cancel = new JButton("Cancel"); | ||
final JButton finish = new JButton("Finish"); | ||
|
||
|
||
final JPanel cp = new JPanel(new BorderLayout()); | ||
cp.add(jpb, BorderLayout.CENTER); | ||
cp.add(cancel, BorderLayout.EAST); | ||
|
||
final JPanel combinedpanel = new JPanel(new BorderLayout()); | ||
combinedpanel.add(op, BorderLayout.NORTH); | ||
combinedpanel.add(cp, BorderLayout.SOUTH); | ||
|
||
|
||
pane.setMessage(combinedpanel); | ||
pane.setOptions(new Object[]{}); | ||
|
||
final JDialog dialog = pane.createDialog(_frame, _title); | ||
|
||
finish.addActionListener(new ActionListener(){ | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
dialog.dispose(); | ||
} | ||
|
||
}); | ||
|
||
cancel.addActionListener(new ActionListener(){ | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
if(_p != null){ | ||
_p.destroy(); | ||
} | ||
dialog.dispose(); | ||
} | ||
}); | ||
|
||
|
||
SwingWorker<Void, Void> sw = new SwingWorker<Void, Void>(){ | ||
|
||
@Override | ||
protected Void doInBackground() throws Exception { | ||
|
||
try { | ||
PipedOutputStream pout = new PipedOutputStream(); | ||
System.setOut(new PrintStream(pout)); | ||
PipedInputStream pin = new PipedInputStream(); | ||
|
||
BufferedReader stdin = new BufferedReader(new InputStreamReader(pin)); | ||
System.out.println("Test"); | ||
String s = null; | ||
while((s = stdin.readLine()) != null){ | ||
op.addLine(s); | ||
op.revalidate(); | ||
op.repaint(); | ||
} | ||
|
||
stdin.close(); | ||
|
||
} catch (IOException e1) { | ||
e1.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
protected void done(){ | ||
cp.remove(jpb); | ||
cp.remove(cancel); | ||
cp.add(finish, BorderLayout.EAST); | ||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); | ||
dialog.revalidate(); | ||
dialog.repaint(); | ||
} | ||
|
||
}; | ||
|
||
sw.execute(); | ||
|
||
|
||
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); | ||
dialog.setVisible(true); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters