use of com.fo0.robot.client.gui.sub.UpdateWindow in project Robot by fo0.
the class MainGUI method initialize.
/**
* Initialize the contents of the frame.
*/
private static void initialize() {
// create main frame
frame = new JFrame();
frame.setTitle("Robot v" + CONSTANTS.VERSION);
frame.getContentPane().setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// center frame on screen
frame.setSize(655, 528);
frame.setLocationRelativeTo(null);
frame.getContentPane().setBackground(Color.LIGHT_GRAY);
frame.setBackground(Color.LIGHT_GRAY);
frame.setResizable(false);
toggleConsole(currentMode);
JPanel panelTop = new JPanel();
panelTop.setBounds(0, 0, 653, 25);
frame.getContentPane().add(panelTop);
panelTop.setLayout(null);
JButton btnAdd = new JButton("ADD");
btnAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new AddChainItemWindow();
}
});
btnAdd.setBounds(97, 0, 73, 24);
panelTop.add(btnAdd);
JButton btnDel = new JButton("DEL");
btnDel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int col = actionTable.getSelectedRow();
deleteItem(tableModel.getRow(col));
}
});
btnDel.setBounds(169, 0, 73, 24);
panelTop.add(btnDel);
JButton btnStart = new JButton("START");
btnStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a) {
new Thread(() -> {
SwingUtilities.invokeLater(() -> {
areaConsole.setText("");
areaChain.setText("");
});
SwingUtilities.invokeLater(() -> {
toggleConsole(EMode.ConsoleMaximized);
});
Utils.sleep(TimeUnit.MILLISECONDS, 200);
// adding listener to receive events from backend
ControllerChain.getChain().addCmdListener((ctx, e) -> {
appendToChain(String.valueOf(e.getKey().getId()), e.getKey().getName(), e.getKey().getDescription(), e.getValue().getData().getState().getCmd().name());
});
// add listener for: Console output log
ControllerChain.getChain().getContext().addOutputListener(cli -> {
appendToConsole(cli);
});
Utils.sleep(TimeUnit.SECONDS, 1);
ControllerChain.start();
}).start();
}
});
btnStart.setBounds(0, 0, 98, 24);
panelTop.add(btnStart);
JButton buttonToggleConsole = new JButton(">_");
buttonToggleConsole.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (currentMode == EMode.ConsoleMaximized) {
toggleConsole(EMode.Normal);
} else {
toggleConsole(EMode.ConsoleMaximized);
}
}
});
buttonToggleConsole.setBounds(580, 0, 73, 24);
panelTop.add(buttonToggleConsole);
ErrorMode errMode = ErrorMode.FailOnErr;
if (Controller.getConfig().ignoreErrors)
errMode = ErrorMode.NotFailOnErr;
JButton btnTgleErrors = new JButton(errMode.name());
btnTgleErrors.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (btnTgleErrors.getText().equals(ErrorMode.FailOnErr.name())) {
Controller.getConfig().ignoreErrors = true;
btnTgleErrors.setText(ErrorMode.NotFailOnErr.name());
} else {
Controller.getConfig().ignoreErrors = false;
btnTgleErrors.setText(ErrorMode.FailOnErr.name());
}
}
});
btnTgleErrors.setBounds(468, 0, 105, 24);
panelTop.add(btnTgleErrors);
createStopButton(panelTop);
createProcessLabel(panelTop);
JPanel panelTable = new JPanel();
panelTable.setBounds(0, 26, 653, 265);
frame.getContentPane().add(panelTable);
panelTable.setLayout(new CardLayout(0, 0));
actionTable = new JTable();
actionTable.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 2) {
JTable table = (JTable) e.getSource();
Point point = e.getPoint();
int row = table.rowAtPoint(point);
ActionItem item = tableModel.getRow(row);
new AddChainItemWindow(item);
}
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
});
tableModel = new BeanTableModelAction();
actionTable.setModel(tableModel);
JScrollPane scrollPaneTable = new JScrollPane(actionTable);
panelTable.add(scrollPaneTable, "name_7985051461163");
JPanel panelChain = new JPanel();
panelChain.setBounds(0, 292, 248, 188);
frame.getContentPane().add(panelChain);
panelChain.setLayout(new CardLayout(0, 0));
areaChain = new JTextArea();
areaChain.setEditable(false);
JScrollPane scrollPaneChain = new JScrollPane(areaChain);
// scrollPaneChain.getVerticalScrollBar().addAdjustmentListener(e -> {
// e.getAdjustable().setValue(e.getAdjustable().getMaximum());
// });
panelChain.add(scrollPaneChain, "name_1466312782685");
JPanel panelConsole = new JPanel();
panelConsole.setBounds(248, 292, 405, 188);
frame.getContentPane().add(panelConsole);
panelConsole.setLayout(new CardLayout(0, 0));
JScrollPane scrollPaneConsole = new JScrollPane((Component) null);
// scrollPaneConsole.getVerticalScrollBar().addAdjustmentListener(e -> {
// e.getAdjustable().setValue(e.getAdjustable().getMaximum());
// });
panelConsole.add(scrollPaneConsole, "name_2349855873542");
areaConsole = new JTextArea();
areaConsole.setEditable(false);
scrollPaneConsole.setViewportView(areaConsole);
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
JMenu mnConfig = new JMenu("Config");
menuBar.add(mnConfig);
JMenuItem mntmConfigLoad = new JMenuItem("Load");
mntmConfigLoad.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));
FileNameExtensionFilter filter = new FileNameExtensionFilter("Robot", "robot");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
// load config from disk -> file
ControllerChain.getChain().getContext().loadFromFile(file.getAbsolutePath());
MainGUI.getTableModel().loadActionContextFromController();
}
}
});
mnConfig.add(mntmConfigLoad);
JMenuItem mntmConfigSave = new JMenuItem("Save");
mntmConfigSave.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
String lastPathDetection = ".";
if (!Controller.getConfig().configFile.isEmpty()) {
lastPathDetection = Controller.getConfig().configFile;
}
chooser.setCurrentDirectory(new File(lastPathDetection));
FileNameExtensionFilter filter = new FileNameExtensionFilter("Robot", "robot");
chooser.setFileFilter(filter);
int returnVal = chooser.showSaveDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
if (!file.getName().endsWith(".robot")) {
Logger.info("detected missing file extension, appending .robot to file");
File tmpFile = new File(file.getAbsolutePath() + ".robot");
file.renameTo(tmpFile);
file = tmpFile;
}
// save config to disk -> file
ControllerChain.getChain().getContext().save(file.getAbsolutePath());
}
}
});
mnConfig.add(mntmConfigSave);
JMenu mnHelp = new JMenu("Help");
menuBar.add(mnHelp);
JMenuItem mntmHelpAbout = new JMenuItem("About");
mntmHelpAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
mnHelp.add(mntmHelpAbout);
JMenuItem mntmHelpUpdate = new JMenuItem("Update");
mntmHelpUpdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new UpdateWindow();
}
});
mnHelp.add(mntmHelpUpdate);
refreshTable();
addChainObservers();
}
Aggregations