import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.filechooser.FileFilter;
public class FileChooser
extends JPanel {
// GUI component
// structure file result of molecular dynamic
// project name (folder that contains all result file)
// absolute path of index file
// absolute path of topology file (.tpr)
// absolute path of trajectories (.xtc)
// selected group
String group1
= "", group2
= "";
public FileChooser(
this.nameprj = nameprj;
this.pathIndex = pathIndex;
this.pathTopology = pathTopology;
this.pathTra = pathTra;
createPanel();
}
public void createPanel() {
statusbarGro
= new JLabel(""); openGro.addActionListener(new OpenFileChooser());
statusbarNdx
= new JLabel(""); openNdx.addActionListener(new OpenFileChooser());
statusbarTpr
= new JLabel(""); openTpr.addActionListener(new OpenFileChooser());
statusbarXtc
= new JLabel(""); openXtc.addActionListener(new OpenFileChooser());
start.addActionListener(new OpenFileChooser());
save.addActionListener(new OpenFileChooser());
}
if (e.getSource() == cb1) {
group1
= String.
valueOf(jcb.
getSelectedIndex()); System.
out.
println("group1 " + group1
); }
if (e.getSource() == cb2) {
group2
= String.
valueOf(jcb.
getSelectedIndex()); System.
out.
println("group2 " + group2
); }
}
}
//private Object ServiceManager;
try {
if (e.getSource() == openGro) {
fileChooser.setFileFilter(new GroFileFilter());
int n = fileChooser.showOpenDialog(FileChooser.this);
File f
= fileChooser.
getSelectedFile(); statusbarGro.setText("You chose..." + f.getName());
pathDynamic = f.getAbsolutePath();
}
}
if (e.getSource() == openNdx) {
fileChooser.setFileFilter(new NdxFileFilter());
int n = fileChooser.showOpenDialog(FileChooser.this);
File f
= fileChooser.
getSelectedFile();
statusbarNdx.setText("You chose..." + f.getName());
pathIndex = f.getAbsolutePath();
String[] cmd
= {"/bin/sh",
"-c",
" grep '\\[' " + f.
getAbsolutePath(),
}; p.waitFor();
while ((line = in.readLine()) != null) {
l.add(line);
}
cb1.addActionListener(new cbListener());
b.add(cb1);
cb2.addActionListener(new cbListener());
b.add(cb2);
revalidate();
}
}
if (e.getSource() == openTpr) {
fileChooser.setFileFilter(new TprFileFilter());
int n = fileChooser.showOpenDialog(FileChooser.this);
File f
= fileChooser.
getSelectedFile(); statusbarTpr.setText("You chose..." + f.getName());
pathTopology = f.getAbsolutePath();
}
}
if (e.getSource() == openXtc) {
fileChooser.setFileFilter(new XtcFileFilter());
int n = fileChooser.showOpenDialog(FileChooser.this);
File f
= fileChooser.
getSelectedFile(); statusbarXtc.setText("You chose..." + f.getName());
pathTra = f.getAbsolutePath();
}
}
if (e.getSource() == save) {
fileChooser.setAcceptAllFileFilterUsed(false);
//fileChooser.setFileFilter(new PrjFileFilter());
int returnVal = fileChooser.showSaveDialog(FileChooser.this);
File file
= fileChooser.
getSelectedFile(); //This is where a real application would save the file.
//log.append("Saving: " + file.getName() + "." + newline);
nameprj = file.getAbsolutePath();
System.
out.
println("Saving: " + file.
getAbsolutePath()); } else {
//log.append("Save command cancelled by user." + newline);
}
}
if (e.getSource() == start) {
if (pathDynamic.length() != 0
&& nameprj.length() != 0
&& pathIndex.length() != 0
&& pathTopology.length() != 0
&& pathTra.length() != 0
&& group1.length() != 0
&& group2.length() != 0) {
MindistCall a = null;
a = new MindistCall(nameprj, pathTra, pathTopology, pathIndex, group1, group2);
d = Support.listTimeDist(a.getmindist(), 0.7000);
s = Support.joinInfo(d, a.getatom(), a.getmindist());
PieChart v = new PieChart(occP1, nameprj, "occP1");
PieChart v1 = new PieChart(occP2, nameprj, "occP2");
Support.print(P1, a.getNamePrj(), "P1", occP1);
Support.print(P2, a.getNamePrj(), "P2", occP2);
Support.print(a.getNamePrj(), "Couple", Couple);
}
} else {
statusbar.setText("fill all field");
}
}
}
}
public boolean accept
(File file
) { if (file.isDirectory()) {
return true;
}
String fname
= file.
getName().
toLowerCase(); return fname.endsWith("gro");
}
public String getDescription
() { return "*.gro";
}
}
public boolean accept
(File file
) { if (file.isDirectory()) {
return true;
}
String fname
= file.
getName().
toLowerCase(); return fname.endsWith("ndx");
}
public String getDescription
() { return "*.ndx";
}
}
public boolean accept
(File file
) { if (file.isDirectory()) {
return true;
}
String fname
= file.
getName().
toLowerCase(); return fname.endsWith("tpr");
}
public String getDescription
() { return "*.tpr";
}
}
public boolean accept
(File file
) { if (file.isDirectory()) {
return true;
}
String fname
= file.
getName().
toLowerCase(); return fname.endsWith("xtc");
}
public String getDescription
() { return "*.xtc";
}
}
public static void main
(String[] argv
) { FileChooser demo = new FileChooser();
frame.getContentPane().add(demo);
frame.
setDefaultCloseOperation(JFrame.
EXIT_ON_CLOSE); frame.setSize(330, 360);
frame.setVisible(true);
}
}