package synchronize;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.tree.TreePath;
import org.apache.tools.ant.types.Path;
public class Gui extends JFrame implements AdjustmentListener
{
/**
*
*/
private static final long serialVersionUID = -4290702090831530326L;
public void adjustmentValueChanged(AdjustmentEvent e) {
// TODO Auto-generated method stub
}
private final String HTMLBUTTONS = "<html><font size=\"3\">";
private final String VERSION = "alpha 0.1";
private String labels[] = {HTMLBUTTONS+"Verzeichnisse Synchronisieren", HTMLBUTTONS+"Verzeichnis Archivieren", HTMLBUTTONS+"Verzeichnisse Vergleichen"};
private String acs[] = {"sync", "zip", "compare"};
private JPanel centerPnl, eastPnl, westPnl, southPnl, eastrow, westrow, northPnl;
private JLabel quelle, ziel;
private JButton buttons[] = new JButton[labels.length];
private JMenuBar menu;
private JTree src_tree, dst_tree;
private ActionListener al;
private WindowListener wl;
private MouseListener ml;
private KeyListener kl;
/*--------------------------------------------------------------------------------------------------------
inner (sub)class of WindowAdapter, not all abstract methods of windowlistener need to be overwritten
inner class knows all methods and attributes of its external class
---------------------------------------------------------------------------------------------------------*/
class InWindowListener extends WindowAdapter
{
public void windowClosing(WindowEvent we) //overwriting abstract method windowClosing
{
shutdown(); //calling method
}
};
/*--------------------------------------------------------------------------------------------------------
inner class implements Interface ActionListener, actionPerformed need to be overwritten
inner class knows all methods and attributes of its external class
---------------------------------------------------------------------------------------------------------*/
class InActionListener implements ActionListener
{
public void actionPerformed(ActionEvent ae) //method actionPerformed gets an actionevent delivered
{
if(ae.getActionCommand().equals("load2") || ae.getActionCommand().equals("filmlist"))
{
// loading("menu");
}
}
};
/*--------------------------------------------------------------------------------------------------------
inner (sub)class of MouseAdapter, not all abstract methods of mouselistener need to be overwritten
inner class knows all methods and attributes of its external class
---------------------------------------------------------------------------------------------------------*/
class InMouseListener extends MouseAdapter
{
public void mouseClicked(MouseEvent me) //method mouseclicked gets an mouseevent delivered
{
if (me.getClickCount() == 2) //if mousebutton is clicked twice...
{
//edit();
}
}
};
/*--------------------------------------------------------------------------------------------------------
inner (sub)class of KeyAdapter, not all abstract methods of keylistener need to be overwritten
inner class knows all methods and attributes of its external class
---------------------------------------------------------------------------------------------------------*/
class InKeyListener extends KeyAdapter
{
public void keyPressed(KeyEvent ke) //overwriting keyPressed method, delivereing a key event
{
if(ke.getKeyCode()==KeyEvent.VK_ESCAPE) //if the specific code of a (pressed)key matches to VS_ESCAPEs, do...
{
dispose();
}
}
};
public Gui(String title)
{
super(title); //calling constructor of superiorclass...cause frame elements are needed
initLayout(); //calling methods
}
protected void createButtons()
{
for (int i=0 ; i < labels.length; i++)
{
buttons[i] = new JButton(labels[i]);
buttons[i].setFont(new Font("Courier New", Font.BOLD, 12));
buttons[i].addKeyListener(kl);
buttons[i].addActionListener(al);
buttons[i].setActionCommand(acs[i]);
centerPnl.add(buttons[i]);
}
}
protected int confirming(String message, String title)
{
int option = JOptionPane.showConfirmDialog(null,"<html><center>[b]"+message+"<center></html>",title,JOptionPane.YES_NO_OPTION);
return option; //returning int value
}
protected void setStatus(String message, String title, String type)
{
if (type.equalsIgnoreCase("error"))
{
JOptionPane.showMessageDialog(null,"<html><center>[b]"+message+"<center></html>",title,JOptionPane.ERROR_MESSAGE);
}
else if (type.equalsIgnoreCase("info"))
{
JOptionPane.showMessageDialog(null,"<html><center>[b]"+message+"<center></html>",title,JOptionPane.INFORMATION_MESSAGE);
}
else if (type.equalsIgnoreCase("ask"))
{
JOptionPane.showMessageDialog(null,"<html><center>[b]"+message+"<center></html>",title,JOptionPane.QUESTION_MESSAGE);
}
}
protected JFrame getJFrame()
{
return this;
}
protected void positioning()
{
Dimension dims = Toolkit.getDefaultToolkit().getScreenSize(); //save systems screensize to Dimension-toolkit object
setSize((dims.width*10/13),(dims.height*10/15)); //set size of frame by using dims value
setLocation((dims.width/9),(dims.height/9)); //set location where frame will be opened using dims value
}
protected void shutdown()
{
int chose = confirming("Programm wirklich beenden?","Ende"); //chose gets int value of JOptionpane dialog
if(chose==1)
{
getJFrame().setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); //window shut not be closed, continue running program
}
else
{
dispose(); //vanishing frame
System.exit(0); //exiting programm
}
}
protected void initLayout()
{
Container environment = getContentPane(); //getting contentPane into 'environment' of type container
environment.setLayout(new BorderLayout()); //setting up layout, here borderlayout
setTitle("SyncTool "+VERSION); //setting title and version
positioning(); //calling method for positioning frame
setResizable(false); //user should not be able to change dialogs size
//setForeground(Color.black); //setting Foreground
//setBackground(Color.lightGray); //setting background
//creating some Listeners objects of our inner class
ml = new InMouseListener();
al = new InActionListener();
wl = new InWindowListener();
kl = new InKeyListener();
addWindowListener(wl);
// menu = new HiltownMenu(al); //new menubar for contextmenu is needed
//setJMenuBar(menu);
westPnl = new JPanel();
eastPnl = new JPanel();
eastrow = new JPanel();
westrow = new JPanel();
southPnl = new JPanel();
centerPnl = new JPanel();
northPnl = new JPanel();
centerPnl.setLayout(new BorderLayout());
westPnl.setLayout(new BorderLayout());
eastPnl.setLayout(new BorderLayout());
northPnl.setLayout(new BorderLayout());
quelle = new JLabel("<html> [b]<font size=\"3\"<u> Quellverzeichnis auswählen</u>[/b] ");
ziel = new JLabel("<html> [b]<font size=\"3\"<u> Zielverzeichnis auswählen</u>[/b] ");
src_tree = new JTree();
dst_tree = new JTree();
createButtons(); //now create buttons
eastrow.add(quelle);
westrow.add(ziel);
eastPnl.add("North", eastrow);
eastPnl.add("Center", src_tree);
northPnl.add("West", buttons[0]);
northPnl.add("Center", buttons[1]);
northPnl.add("East", buttons[2]);
westPnl.add("North", westrow);
westPnl.add("Center", dst_tree);
//adding panel into Container
environment.add("West", westPnl);
environment.add("East", eastPnl);
environment.add("North", northPnl);
environment.add("Center", centerPnl);
environment.add("South", southPnl);
setVisible(true); //of course the window should be visible
}
}