package de.martinet.apps.tcgui.minigui;
import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Event;
import java.awt.BorderLayout;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.KeyStroke;
import java.awt.Point;
import javax.swing.table.DefaultTableModel;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JFrame;
import javax.swing.JDialog;
import java.awt.GridLayout;
import javax.swing.JSplitPane;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.JTextField;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.BoxLayout;
import javax.swing.table.DefaultTableModel;
import de.martinet.apps.tcgui.bl.ITCInformationManager;
import de.martinet.apps.tcgui.bl.TCStandarrdConnector;
import de.martinet.apps.tcgui.domain.MappingInformation;
import de.martinet.apps.tcgui.domain.Status;
import java.awt.FlowLayout;
import java.util.Vector;
public class MiniGUIStart {
private JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="10,10"
private JPanel jPnMainContent = null;
private JMenuBar jJMenuBar = null;
private JMenu fileMenu = null;
private JMenu editMenu = null;
private JMenu helpMenu = null;
private JMenuItem exitMenuItem = null;
private JMenuItem aboutMenuItem = null;
private JMenuItem cutMenuItem = null;
private JMenuItem copyMenuItem = null;
private JMenuItem pasteMenuItem = null;
private JMenuItem saveMenuItem = null;
private JDialog aboutDialog = null;
private JPanel aboutContentPane = null;
private JLabel aboutVersionLabel = null;
private JSplitPane jSplitPane = null;
private JPanel jPnlUpperPanel = null;
private JLabel jLblMountFrom = null;
private JLabel jLblMountTo = null;
private JTextField jTfMountTo = null;
private JButton jBtMountFromSelect = null;
private JButton jBtMountFromToSelect = null;
private JScrollPane jSpDriveList = null;
private JTable jTblDriveList = null;
private JPanel jPanel1 = null;
private JPanel jBtMountActions = null; // @jve:decl-index=0:visual-constraint="51,-170"
private JButton jButton = null;
private JButton jButton1 = null;
private JButton jBtDismount = null;
private JTextField jTfMountFrom = null;
// Business logic
private ITCInformationManager infoMgr = new TCStandarrdConnector(); // @jve:decl-index=0:
/**
* This method initializes jSplitPane
*
* @return javax.swing.JSplitPane
*/
private JSplitPane getJSplitPane() {
if (jSplitPane == null) {
jSplitPane = new JSplitPane();
jSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
jSplitPane.setTopComponent(getJPanel1());
jSplitPane.setBottomComponent(getJSpDriveList());
jSplitPane.setDividerLocation(150);
}
return jSplitPane;
}
/**
* This method initializes jPnlUpperPanel
*
* @return javax.swing.JPanel
*/
private JPanel getJPnlUpperPanel() {
if (jPnlUpperPanel == null) {
GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
gridBagConstraints11.fill = GridBagConstraints.VERTICAL;
gridBagConstraints11.gridy = 0;
gridBagConstraints11.weightx = 1.0;
gridBagConstraints11.gridx = 1;
GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
gridBagConstraints4.gridx = 2;
gridBagConstraints4.gridy = 1;
GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
gridBagConstraints3.gridx = 2;
gridBagConstraints3.gridy = 0;
GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
gridBagConstraints2.fill = GridBagConstraints.VERTICAL;
gridBagConstraints2.gridy = 1;
gridBagConstraints2.weightx = 1.0;
gridBagConstraints2.gridx = 1;
gridBagConstraints11.fill = GridBagConstraints.VERTICAL;
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.gridx = 0;
gridBagConstraints1.gridy = 1;
jLblMountTo = new JLabel();
jLblMountTo.setText("Mount to:");
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
jLblMountFrom = new JLabel();
jLblMountFrom.setText("Mount from:");
jPnlUpperPanel = new JPanel();
jPnlUpperPanel.setLayout(new GridBagLayout());
jPnlUpperPanel.add(jLblMountFrom, gridBagConstraints);
jPnlUpperPanel.add(jLblMountTo, gridBagConstraints1);
jPnlUpperPanel.add(getJTfMountTo(), gridBagConstraints2);
jPnlUpperPanel.add(getJBtMountFromSelect(), gridBagConstraints3);
jPnlUpperPanel.add(getJBtMountFromToSelect(), gridBagConstraints4);
jPnlUpperPanel.add(getJTfMountFrom(), gridBagConstraints11);
}
return jPnlUpperPanel;
}
/**
* This method initializes jTfMountTo
*
* @return javax.swing.JTextField
*/
private JTextField getJTfMountTo() {
if (jTfMountTo == null) {
jTfMountTo = new JTextField();
jTfMountTo.setColumns(30);
}
return jTfMountTo;
}
/**
* This method initializes jBtMountFromSelect
*
* @return javax.swing.JButton
*/
private JButton getJBtMountFromSelect() {
if (jBtMountFromSelect == null) {
jBtMountFromSelect = new JButton();
jBtMountFromSelect.setText("select source");
jBtMountFromSelect.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(MiniGUIStart.this.jBtMountFromSelect);
if (returnVal == JFileChooser.APPROVE_OPTION) {
MiniGUIStart.this.jTfMountFrom.setText(fc.getSelectedFile().getPath());
}
}
});
}
return jBtMountFromSelect;
}
/**
* This method initializes jBtMountFromToSelect
*
* @return javax.swing.JButton
*/
private JButton getJBtMountFromToSelect() {
if (jBtMountFromToSelect == null) {
jBtMountFromToSelect = new JButton();
jBtMountFromToSelect.setText("select destination");
jBtMountFromToSelect.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
final JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = fc.showOpenDialog(MiniGUIStart.this.jBtMountFromSelect);
if (returnVal == JFileChooser.APPROVE_OPTION) {
MiniGUIStart.this.jTfMountTo.setText(fc.getSelectedFile().getPath());
}
}
});
}
return jBtMountFromToSelect;
}
/**
* This method initializes jSpDriveList
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJSpDriveList() {
if (jSpDriveList == null) {
jSpDriveList = new JScrollPane();
jSpDriveList.setViewportView(getJTblDriveList());
}
fillStatus();
return jSpDriveList;
}
/**
* This method initializes jTblDriveList
*
* @return javax.swing.JTable
*/
private JTable getJTblDriveList() {
if (jTblDriveList == null) {
jTblDriveList = new JTable();
jTblDriveList = new JTable(new DefaultTableModel(
new String[] {"Device", "Mapped to", "Destination", "Encryption"}, 0));
jTblDriveList.addMouseListener(new java.awt.event.MouseAdapter() {
// Simmuliert einen rowlistener
public void mouseClicked(java.awt.event.MouseEvent e) {
// TODO Allow deselect
int row = jTblDriveList.rowAtPoint(new Point(e.getX(),e.getY()));
// if a row is selected, enable remove button
if(row >= 0)
{
jBtDismount.setEnabled(true);
}
else // otherwise disable it again
{
jBtDismount.setEnabled(false);
}
}
});
}
return jTblDriveList;
}
/**
* This method initializes jPanel1
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel1() {
if (jPanel1 == null) {
GridLayout gridLayout2 = new GridLayout();
gridLayout2.setRows(2);
jPanel1 = new JPanel();
jPanel1.setLayout(gridLayout2);
jPanel1.add(getJPnlUpperPanel(), null);
jPanel1.add(getJBtMountActions(), null);
}
return jPanel1;
}
/**
* This method initializes jBtMountActions
*
* @return javax.swing.JPanel
*/
private JPanel getJBtMountActions() {
if (jBtMountActions == null) {
jBtMountActions = new JPanel();
jBtMountActions.setLayout(new FlowLayout());
jBtMountActions.setBorder(null);
jBtMountActions.add(getJButton1(), null);
jBtMountActions.add(getJBtDismount(), null);
jBtMountActions.add(getJButton(), null);
}
return jBtMountActions;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("dismount all");
}
return jButton;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("Mount");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
MountOptions mo = new MountOptions(MiniGUIStart.this.jFrame);
mo.setModal(true);
mo.setVisible(true);
}
});
}
return jButton1;
}
/**
* This method initializes jBtDismount
*
* @return javax.swing.JButton
*/
private JButton getJBtDismount() {
if (jBtDismount == null) {
jBtDismount = new JButton();
jBtDismount.setText("Dismount");
jBtDismount.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
//infoMgr.detachdevice();
DefaultTableModel tmpMdl = (DefaultTableModel) jTblDriveList
.getModel();
String device = (String) (tmpMdl.getValueAt(jTblDriveList.getSelectedRow(), 0));
infoMgr.detachdevice(device);
fillStatus();
}
});
}
return jBtDismount;
}
/**
* This method initializes jTfMountFrom
*
* @return javax.swing.JTextField
*/
private JTextField getJTfMountFrom() {
if (jTfMountFrom == null) {
jTfMountFrom = new JTextField();
jTfMountFrom.setColumns(30);
}
return jTfMountFrom;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
MiniGUIStart application = new MiniGUIStart();
application.getJFrame().setVisible(true);
}
});
}
/**
* This method initializes jFrame
*
* @return javax.swing.JFrame
*/
private JFrame getJFrame() {
if (jFrame == null) {
jFrame = new JFrame();
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setJMenuBar(getJJMenuBar());
jFrame.setSize(567, 428);
jFrame.setContentPane(getJPnMainContent());
jFrame.setTitle("Application");
}
return jFrame;
}
/**
* This method initializes jPnMainContent
*
* @return javax.swing.JPanel
*/
private JPanel getJPnMainContent() {
if (jPnMainContent == null) {
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(1);
jPnMainContent = new JPanel();
jPnMainContent.setLayout(gridLayout);
jPnMainContent.add(getJSplitPane(), null);
}
return jPnMainContent;
}
/**
* This method initializes jJMenuBar
*
* @return javax.swing.JMenuBar
*/
private JMenuBar getJJMenuBar() {
if (jJMenuBar == null) {
jJMenuBar = new JMenuBar();
jJMenuBar.add(getFileMenu());
jJMenuBar.add(getEditMenu());
jJMenuBar.add(getHelpMenu());
}
return jJMenuBar;
}
/**
* This method initializes jMenu
*
* @return javax.swing.JMenu
*/
private JMenu getFileMenu() {
if (fileMenu == null) {
fileMenu = new JMenu();
fileMenu.setText("File");
fileMenu.add(getSaveMenuItem());
fileMenu.add(getExitMenuItem());
}
return fileMenu;
}
/**
* This method initializes jMenu
*
* @return javax.swing.JMenu
*/
private JMenu getEditMenu() {
if (editMenu == null) {
editMenu = new JMenu();
editMenu.setText("Edit");
editMenu.add(getCutMenuItem());
editMenu.add(getCopyMenuItem());
editMenu.add(getPasteMenuItem());
}
return editMenu;
}
/**
* This method initializes jMenu
*
* @return javax.swing.JMenu
*/
private JMenu getHelpMenu() {
if (helpMenu == null) {
helpMenu = new JMenu();
helpMenu.setText("Help");
helpMenu.add(getAboutMenuItem());
}
return helpMenu;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getExitMenuItem() {
if (exitMenuItem == null) {
exitMenuItem = new JMenuItem();
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
}
return exitMenuItem;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getAboutMenuItem() {
if (aboutMenuItem == null) {
aboutMenuItem = new JMenuItem();
aboutMenuItem.setText("About");
aboutMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JDialog aboutDialog = getAboutDialog();
aboutDialog.pack();
Point loc = getJFrame().getLocation();
loc.translate(20, 20);
aboutDialog.setLocation(loc);
aboutDialog.setVisible(true);
}
});
}
return aboutMenuItem;
}
/**
* This method initializes aboutDialog
*
* @return javax.swing.JDialog
*/
private JDialog getAboutDialog() {
if (aboutDialog == null) {
aboutDialog = new JDialog(getJFrame(), true);
aboutDialog.setTitle("About");
aboutDialog.setContentPane(getAboutContentPane());
}
return aboutDialog;
}
/**
* This method initializes aboutContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getAboutContentPane() {
if (aboutContentPane == null) {
aboutContentPane = new JPanel();
aboutContentPane.setLayout(new BorderLayout());
aboutContentPane.add(getAboutVersionLabel(), BorderLayout.CENTER);
}
return aboutContentPane;
}
/**
* This method initializes aboutVersionLabel
*
* @return javax.swing.JLabel
*/
private JLabel getAboutVersionLabel() {
if (aboutVersionLabel == null) {
aboutVersionLabel = new JLabel();
aboutVersionLabel.setText("Version 1.0");
aboutVersionLabel.setHorizontalAlignment(SwingConstants.CENTER);
}
return aboutVersionLabel;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getCutMenuItem() {
if (cutMenuItem == null) {
cutMenuItem = new JMenuItem();
cutMenuItem.setText("Cut");
cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
Event.CTRL_MASK, true));
}
return cutMenuItem;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getCopyMenuItem() {
if (copyMenuItem == null) {
copyMenuItem = new JMenuItem();
copyMenuItem.setText("Copy");
copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
Event.CTRL_MASK, true));
}
return copyMenuItem;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getPasteMenuItem() {
if (pasteMenuItem == null) {
pasteMenuItem = new JMenuItem();
pasteMenuItem.setText("Paste");
pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,
Event.CTRL_MASK, true));
}
return pasteMenuItem;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getSaveMenuItem() {
if (saveMenuItem == null) {
saveMenuItem = new JMenuItem();
saveMenuItem.setText("Save");
saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
Event.CTRL_MASK, true));
}
return saveMenuItem;
}
private void fillStatus()
{
Status tmpStatus = infoMgr.getStatus();
// first remove old rows
for(int i = 0; i < ((DefaultTableModel) jTblDriveList.getModel()).getRowCount(); i++)
{
((DefaultTableModel) jTblDriveList.getModel()).removeRow(i);
}
//jTblDriveList = getJTblDriveList();
for(MappingInformation mapInf : tmpStatus.getStati())
{
// create a new vector to add a row
Vector<String> vec = new Vector<String>();
// Device
vec.add(mapInf.getSourceVolume());
// Mapped to
vec.add(mapInf.getMappedTo());
// Destination
vec.add(mapInf.getMappedTo());
// Encryption
vec.add(mapInf.getEncription());
// eine neue Row hinzufügen
((DefaultTableModel) jTblDriveList
.getModel()).addRow(vec);
}
}
}