package fbench;
import java.awt.*;
import javax.swing.*;
import java.io.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import javax.swing.tree.TreeSelectionModel;
import java.awt.*;
import javax.swing.*;
import fbench.graph.GraphViewTransfer;
import fbench.tree.LibraryTreeNode;
class Project_Making
extends JFrame {
private JTextField tf01=new JTextField("",20);
private JTextField tf02=new JTextField("",20);
private JTextField tf03=new JTextField("",20);
private JTextField tf04=new JTextField("",20);
private String SystemConfig;
private String location;
private String Output_location;
private String[] memory = new String[100];
private String Projectname;
private int counter =0 ;
private final JTree libraryTree;
private File dir, dir2;
private GraphViewTransfer gvhandler;
private JSplitPane splitPaneH, splitPane2;
private JPanel p1, p2;
private JScrollPane libraryView;
private MenuBar menubar;
private Menu menu;
private MenuItem exitMenu;
private FBench test;
// action listener
private class PushButtonActionListener implements ActionListener{
JPanel p1 = null;
public PushButtonActionListener(JPanel af) {
this.p1 = af;
}
public void actionPerformed(ActionEvent ae){
if(ae.getActionCommand()=="Choose"){
JFileChooser fc=new JFileChooser(System.getProperty("user.dir"));
int fd=fc.showSaveDialog(p1);
try{
if(fd==JFileChooser.APPROVE_OPTION){
dir = fc.getSelectedFile().getParentFile();
location = fc.getSelectedFile().getParent();
location = location + "\\src";
System.out.println(dir);
tf03.setText(dir.toString());
}
}
catch (Exception ex){}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
else if(ae.getActionCommand()=="Open"){
tf01.setText("");
tf02.setText("");
JFileChooser fc=new JFileChooser(System.getProperty("user.dir")); // File chooser thingy
int fd=fc.showOpenDialog(p1);
int i = 0; // memory counter
try{
if(fd==JFileChooser.APPROVE_OPTION){
FileInputStream fi=new FileInputStream(fc.getSelectedFile());
BufferedReader br=new BufferedReader(new InputStreamReader(fi));
String s01=br.readLine();
tf01.setText(fc.getSelectedFile().getName());
while(s01!= null){
s01=br.readLine();
String temp = s01.trim();
if( temp.contains("<FB Name=") ){
//System.out.println(temp.split("Type"));
String temp1 = temp.split("Type=\"")[1];
String temp2 = temp1.split("\"")[0];
memory[i] = temp2;
System.out.println(memory[i]);
i++;
}
counter = i -1;
}
}
}
catch(Exception ex){}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
else if(ae.getActionCommand() == "Make"){
new File(Output_location).mkdir();
File srcPath = new File(dir.toString()+File.separator + "src"); //changing path to FBDK/SRC
String[] children = srcPath.list(); //list of all dirs in SRC
String to_config = "================";
for(int a = 0; a<children.length; a++){ //printing all files within subfolders of SRC
File childPath = new File(srcPath.toString()+ File.separator + children[a]);
System.out.println(counter);
String[] child = childPath.list(); //creates list of all files within folders of SRC
for(int b = 0; b<child.length; b++){
int temp = counter;
while(temp >=0){
if(child[b].contains(memory[temp])){
//reading content of file in order to copy it to the next bit
try{
FileInputStream fi=new FileInputStream(childPath.getAbsolutePath().toString() + File.separator + child[b]);
BufferedReader br=new BufferedReader(new InputStreamReader(fi));
//writing stream
FileOutputStream fo= new FileOutputStream(Output_location + File.separator + child[b]);
PrintStream ps=new PrintStream(fo);
String ttt=br.readLine();
ps.println(ttt);
//writing to new file
while(ttt!= null){
ttt=br.readLine();
ps.println(ttt);
}}
catch (Exception ex){}
to_config = to_config + "\n"
+ "++++" + "\n"
+ child[b] + "\n"
+ childPath.getAbsolutePath().toString() + "\n";
//writing config file
memory[temp] = null;
}
temp--;
}
}
//System.out.println(children[a]);
}
System.out.println("making project now");
System.out.println(Output_location);
try{
FileOutputStream fo1 = new FileOutputStream (Output_location + File.separator + "config.prj");
PrintStream ps1 = new PrintStream(fo1);
ps1.print(to_config);
}
catch (IOException e){}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
else if(ae.getActionCommand()=="Save"){
JFileChooser fc=new JFileChooser(System.getProperty("user.dir"));
int fd=fc.showSaveDialog(p1);
try{
if(fd==JFileChooser.APPROVE_OPTION){
System.out.println(fc.getSelectedFile());
dir2 = fc.getSelectedFile();
Output_location = fc.getSelectedFile().toString();
tf02.setText(Output_location);
/*FileOutputStream fo=new FileOutputStream(fc.getSelectedFile());
PrintStream ps=new PrintStream(fo);
ps.println(tf01.getText());
ps.println(tf02.getText());
ps.close();
fo.close();*/
}
}
catch(Exception ex){}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
else if(ae.getActionCommand() == "Make"){
new File(Output_location).mkdir();
File srcPath = new File(dir.toString()+File.separator + "src"); //changing path to FBDK/SRC
String[] children = srcPath.list(); //list of all dirs in SRC
String to_config = "================";
for(int a = 0; a<children.length; a++){ //printing all files within subfolders of SRC
File childPath = new File(srcPath.toString()+ File.separator + children[a]);
System.out.println(counter);
String[] child = childPath.list(); //creates list of all files within folders of SRC
for(int b = 0; b<child.length; b++){
int temp = counter;
while(temp >=0){
if(child[b].contains(memory[temp])){
//reading content of file in order to copy it to the next bit
try{
FileInputStream fi=new FileInputStream(childPath.getAbsolutePath().toString() + File.separator + child[b]);
BufferedReader br=new BufferedReader(new InputStreamReader(fi));
//writing stream
FileOutputStream fo= new FileOutputStream(Output_location + File.separator + child[b]);
PrintStream ps=new PrintStream(fo);
String ttt=br.readLine();
ps.println(ttt);
//writing to new file
while(ttt!= null){
ttt=br.readLine();
ps.println(ttt);
}}
catch (Exception ex){}
to_config = to_config + "\n"
+ "++++" + "\n"
+ child[b] + "\n"
+ childPath.getAbsolutePath().toString() + "\n";
//writing config file
memory[temp] = null;
}
temp--;
}
}
//System.out.println(children[a]);
}
System.out.println("making project now");
System.out.println(Output_location);
try{
FileOutputStream fo1 = new FileOutputStream (Output_location + File.separator + "config.prj");
PrintStream ps1 = new PrintStream(fo1);
ps1.print(to_config);
}
catch (IOException e){}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
else if(ae.getActionCommand() == "Import"){
String fbname;
String fblocation;
JFileChooser fc=new JFileChooser(System.getProperty("user.dir")); // File chooser thingy
int fd=fc.showOpenDialog(p1);
try{
if(fd==JFileChooser.APPROVE_OPTION){
FileInputStream fi=new FileInputStream(fc.getSelectedFile());
BufferedReader br=new BufferedReader(new InputStreamReader(fi));
tf04.setText(fc.getSelectedFile().toString());
String s01=br.readLine();
while (s01 != null){
if(s01.equals("++++")){
System.out.println("true");
fbname = br.readLine();
System.out.println(fbname);
fblocation = br.readLine();
System.out.println(fblocation);
// reading content of file in order to copy it to the next bit
try{
FileInputStream fi1=new FileInputStream(fc.getSelectedFile().getParent().toString()+ File.separator + fbname);
BufferedReader br1=new BufferedReader(new InputStreamReader(fi1));
//writing stream
FileOutputStream fo= new FileOutputStream(fblocation + File.separator + fbname);
PrintStream ps=new PrintStream(fo);
String ttt=br1.readLine();
//System.out.println(ttt);
ps.println(ttt);
//writing to new file
while(ttt!= null){
ttt=br1.readLine();
ps.println(ttt);
}}
catch (Exception ex){System.out.println("read error");}
}
s01 = br.readLine();
}
}
}
catch (Exception e){}
}
}
}
public Project_Making() {
setTitle("FBench Project Maker");
setIconImage(IconFactory.getIcon("oooneida24.png").getImage());
setBackground(Color.gray);
JPanel topPanel = new JPanel();
topPanel.setLayout(new BorderLayout());
getContentPane().add(topPanel);
menubar = new MenuBar();
menu = new Menu("File");
menubar.add(menu);
exitMenu = new MenuItem("Exit");
exitMenu.setShortcut(new MenuShortcut('x'));
menu.add(exitMenu);
setMenuBar(menubar);
// Create the panels
createPanel1();
createPanel2();
createTestPane();
//TreeView
LibraryTreeNode libraryRoot = new LibraryTreeNode(new File("src"), null);
libraryTree = new JTree(libraryRoot);
gvhandler = new GraphViewTransfer(libraryTree);
libraryTree.setCellRenderer(libraryRoot);
libraryTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
libraryTree.setDragEnabled(true);
// mouse listener for opening documents from the tree
libraryTree.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
Object obj = libraryTree.getLeadSelectionPath()
.getLastPathComponent();
if (obj instanceof LibraryTreeNode){
//open(((LibraryTreeNode) obj).getFile().toString());
if (test == null)
test = new FBench();
test.open(((LibraryTreeNode) obj).getFile());
//found source, now what is done with it??
//System.out.println("=============================================================");
//System.out.println(((LibraryTreeNode) obj).getFile());
//System.out.println("=============================================================");
}
}
}
});
libraryView = new JScrollPane(libraryTree);
splitPaneH = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, libraryView, p1);
splitPaneH.setBounds(100,100,800,600);
topPanel.add(splitPaneH, BorderLayout.CENTER);
topPanel.setBounds(100,100,800,600);
//splitPaneH.setLeftComponent(libraryView);
//splitPaneH.setRightComponent(p1);
}
//Test pane
public void createTestPane(){
JPanel test = new JPanel();
splitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, p1, test);
splitPane2.setPreferredSize(new Dimension(640, 200));
/* JLabel Update_Checker = new JLabel("FBench Project Environment Class Update Checker");
SpringLayout layout = new SpringLayout();
layout.putConstraint(SpringLayout.WEST, Update_Checker, 50, SpringLayout.WEST, p2);
layout.putConstraint(SpringLayout.NORTH, Update_Checker, 20, SpringLayout.NORTH, p2);
layout.putConstraint(SpringLayout.NORTH, test, 100, SpringLayout.NORTH, p2);
layout.putConstraint(SpringLayout.EAST, test, 100, SpringLayout.EAST, p2);
test.setLayout(layout);
test.add(Update_Checker);*/
}
// Create new Plane //
public void createPanel1() {
libraryView = new JScrollPane(libraryTree);
JLabel Update_Checker = new JLabel("FBench Project Environment Class Update Checker");
libraryView.setPreferredSize(new Dimension(640, 200));
}
// Status Window //
public void createPanel2() {
p1=new JPanel();
p1.setPreferredSize(new Dimension(640, 200));
JLabel sourceLabel = new JLabel("Choose System Configuration File: "); //text label1
JLabel saveLabel = new JLabel("Choose Output Location: ");
JLabel chooselabel = new JLabel("Choose Location of FBDK: ");
chooselabel.setAlignmentX(10);
chooselabel.setAlignmentY(100);
JButton bt_open=new JButton("Browse"); //creates a new button
bt_open.setActionCommand("Open");
bt_open.addActionListener(new PushButtonActionListener(p1));
JButton bt_save=new JButton("Browse");
bt_save.setActionCommand("Save");
bt_save.addActionListener(new PushButtonActionListener(p1));
JButton bt_choose = new JButton("Browse");
bt_choose.setActionCommand("Choose");
bt_choose.addActionListener(new PushButtonActionListener(p1));
JButton bt_make = new JButton("Make Project");
bt_make.setActionCommand("Make");
bt_make.addActionListener(new PushButtonActionListener(p1));
JLabel importLabel = new JLabel("Choose Project to import");
JButton bt_import = new JButton("import");
bt_import.setActionCommand("Import");
bt_import.addActionListener(new PushButtonActionListener(p1));
SpringLayout layout = new SpringLayout();
layout.putConstraint(SpringLayout.WEST, chooselabel, 20, SpringLayout.WEST, p1);
layout.putConstraint(SpringLayout.NORTH, chooselabel, 50, SpringLayout.NORTH, p1);
layout.putConstraint(SpringLayout.EAST, tf03, -5, SpringLayout.EAST, p1);
layout.putConstraint(SpringLayout.NORTH, tf03, 50, SpringLayout.NORTH, p1);
layout.putConstraint(SpringLayout.NORTH, bt_choose, 10, SpringLayout.SOUTH, tf03); //distance between button and text box is 10 pixels
layout.putConstraint(SpringLayout.EAST, bt_choose, -5, SpringLayout.EAST, p1);
layout.putConstraint(SpringLayout.SOUTH, sourceLabel, 102, SpringLayout.NORTH, chooselabel);
layout.putConstraint(SpringLayout.WEST, sourceLabel, 20, SpringLayout.WEST, p1);
layout.putConstraint(SpringLayout.NORTH, tf01, 30, SpringLayout.SOUTH, bt_choose); //distance between two different things is 30
layout.putConstraint(SpringLayout.EAST, tf01, -5, SpringLayout.EAST, p1);
layout.putConstraint(SpringLayout.NORTH, bt_open, 10, SpringLayout.SOUTH, tf01);
layout.putConstraint(SpringLayout.EAST, bt_open, -5, SpringLayout.EAST, p1);
layout.putConstraint(SpringLayout.NORTH, tf02, 30, SpringLayout.SOUTH, bt_open);
layout.putConstraint(SpringLayout.EAST, tf02, -5, SpringLayout.EAST, p1);
layout.putConstraint(SpringLayout.NORTH, bt_make, 10, SpringLayout.SOUTH, tf02);
layout.putConstraint(SpringLayout.EAST, bt_make, -5, SpringLayout.EAST, p1);
layout.putConstraint(SpringLayout.NORTH, bt_save, 10, SpringLayout.SOUTH, tf02);
layout.putConstraint(SpringLayout.EAST, bt_save, -5, SpringLayout.WEST, bt_make);
layout.putConstraint(SpringLayout.SOUTH, saveLabel, 102, SpringLayout.NORTH, sourceLabel);
layout.putConstraint(SpringLayout.WEST, saveLabel, 20, SpringLayout.WEST, p1);
layout.putConstraint(SpringLayout.NORTH, tf04, 30, SpringLayout.SOUTH, bt_make);
layout.putConstraint(SpringLayout.EAST, tf04, -5, SpringLayout.EAST, p1);
layout.putConstraint(SpringLayout.NORTH, bt_import, 10, SpringLayout.SOUTH, tf04);
layout.putConstraint(SpringLayout.EAST, bt_import, -5, SpringLayout.EAST, p1);
layout.putConstraint(SpringLayout.WEST, importLabel, 20, SpringLayout.WEST, p1);
layout.putConstraint(SpringLayout.SOUTH, importLabel, 102, SpringLayout.NORTH, saveLabel);
p1.setLayout(layout);
p1.add(chooselabel);
p1.add(tf03);
p1.add(bt_choose);
p1.add(sourceLabel);
p1.add(tf01);
p1.add(bt_open);
p1.add(saveLabel);
p1.add(tf02);
p1.add(bt_save);
p1.add(bt_make);
p1.add(importLabel);
p1.add(tf04);
p1.add(bt_import);
}
public static void main(String args[]) {
Project_Making mainFrame = new Project_Making();
mainFrame.pack();
mainFrame.setVisible(true);
}
}