System.exit(0);
}
});
// add a menu bar
JMenuBar mb = new JMenuBar();
JMenu file = new JMenu("File");
file.setMnemonic(KeyEvent.VK_F);
JMenuItem tmp;
file.add(tmp = new JMenuItem("Connect"));
tmp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.SHIFT_MASK | KeyEvent.CTRL_MASK));
tmp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
String destination =
JOptionPane.showInputDialog(frame,
new JLabel("Enter your destination host (host[:port])"),
"Connect", JOptionPane.QUESTION_MESSAGE
);
if (destination != null) {
int sep = 0;
if ((sep = destination.indexOf(' ')) > 0 || (sep = destination.indexOf(':')) > 0) {
host = destination.substring(0, sep);
port = destination.substring(sep + 1);
} else {
host = destination;
}
setup.broadcast(new SocketRequest());
setup.broadcast(new SocketRequest(host, Integer.parseInt(port)));
}
}
});
file.add(tmp = new JMenuItem("Disconnect"));
tmp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
setup.broadcast(new SocketRequest());
}
});
file.addSeparator();
if (setup.getComponents().get("Terminal") != null) {
file.add(tmp = new JMenuItem("Print"));
tmp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, KeyEvent.CTRL_MASK));
tmp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
PrintJob printJob =
frame.getToolkit().getPrintJob(frame, "JTA Terminal", null);
// return if the user clicked cancel
if (printJob == null) return;
((JComponent) setup.getComponents().get("Terminal"))
.print(printJob.getGraphics());
printJob.end();
}
});
file.addSeparator();
}
file.add(tmp = new JMenuItem("Exit"));
tmp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
frame.dispose();
System.exit(0);
}
});
mb.add(file);
JMenu edit = new JMenu("Edit");
edit.add(tmp = new JMenuItem("Copy"));
tmp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK));
tmp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (focussedPlugin instanceof VisualTransferPlugin)
((VisualTransferPlugin) focussedPlugin).copy(clipboard);
}
});
edit.add(tmp = new JMenuItem("Paste"));
tmp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_MASK));
tmp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (focussedPlugin instanceof VisualTransferPlugin)
((VisualTransferPlugin) focussedPlugin).paste(clipboard);
}
});
mb.add(edit);
Map menuList = setup.getMenus();
names = menuList.keySet().iterator();
while (names.hasNext()) {
String name = (String) names.next();
mb.add((JMenu) menuList.get(name));
}
JMenu help = new JMenu("Help");
help.setMnemonic(KeyEvent.VK_HELP);
help.add(tmp = new JMenuItem("General"));
tmp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Help.show(frame, options.getProperty("Help.url"));
}
});
mb.add(help);
frame.setJMenuBar(mb);
} // !personalJava