Search in sources :

Example 1 with GUIBackend

use of com.willwinder.universalgcodesender.model.GUIBackend in project Universal-G-Code-Sender by winder.

the class MainWindow method main.

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    // Fix look and feel to use CMD+C/X/V/A instead of CTRL
    if (SystemUtils.IS_OS_MAC) {
        Collection<InputMap> ims = new ArrayList<>();
        ims.add((InputMap) UIManager.get("TextField.focusInputMap"));
        ims.add((InputMap) UIManager.get("TextArea.focusInputMap"));
        ims.add((InputMap) UIManager.get("EditorPane.focusInputMap"));
        ims.add((InputMap) UIManager.get("FormattedTextField.focusInputMap"));
        ims.add((InputMap) UIManager.get("PasswordField.focusInputMap"));
        ims.add((InputMap) UIManager.get("TextPane.focusInputMap"));
        int c = KeyEvent.VK_C;
        int v = KeyEvent.VK_V;
        int x = KeyEvent.VK_X;
        int a = KeyEvent.VK_A;
        int meta = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
        for (InputMap im : ims) {
            im.put(KeyStroke.getKeyStroke(c, meta), DefaultEditorKit.copyAction);
            im.put(KeyStroke.getKeyStroke(v, meta), DefaultEditorKit.pasteAction);
            im.put(KeyStroke.getKeyStroke(x, meta), DefaultEditorKit.cutAction);
            im.put(KeyStroke.getKeyStroke(a, meta), DefaultEditorKit.selectAllAction);
        }
    }
    /* Create the form */
    GUIBackend backend = new GUIBackend();
    final MainWindow mw = new MainWindow(backend);
    /* Apply the settings to the MainWindow bofore showing it */
    boolean unitsAreMM = mw.settings.getDefaultUnits().equals(Units.MM.abbreviation);
    mw.fileChooser = new JFileChooser(mw.settings.getLastOpenedFilename());
    mw.commPortComboBox.setSelectedItem(mw.settings.getPort());
    mw.baudrateSelectionComboBox.setSelectedItem(mw.settings.getPortRate());
    mw.scrollWindowCheckBox.setSelected(mw.settings.isScrollWindowEnabled());
    mw.showVerboseOutputCheckBox.setSelected(mw.settings.isVerboseOutputEnabled());
    mw.showCommandTableCheckBox.setSelected(mw.settings.isCommandTableEnabled());
    mw.showCommandTableCheckBoxActionPerformed(null);
    mw.firmwareComboBox.setSelectedItem(mw.settings.getFirmwareVersion());
    mw.setSize(mw.settings.getMainWindowSettings().width, mw.settings.getMainWindowSettings().height);
    mw.setLocation(mw.settings.getMainWindowSettings().xLocation, mw.settings.getMainWindowSettings().yLocation);
    mw.addComponentListener(new ComponentListener() {

        @Override
        public void componentResized(ComponentEvent ce) {
            mw.settings.getMainWindowSettings().height = ce.getComponent().getSize().height;
            mw.settings.getMainWindowSettings().width = ce.getComponent().getSize().width;
        }

        @Override
        public void componentMoved(ComponentEvent ce) {
            mw.settings.getMainWindowSettings().xLocation = ce.getComponent().getLocation().x;
            mw.settings.getMainWindowSettings().yLocation = ce.getComponent().getLocation().y;
        }

        @Override
        public void componentShown(ComponentEvent ce) {
        }

        @Override
        public void componentHidden(ComponentEvent ce) {
        }
    });
    /* Display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            mw.setVisible(true);
        }
    });
    mw.initFileChooser();
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            if (mw.fileChooser.getSelectedFile() != null) {
                mw.settings.setLastOpenedFilename(mw.fileChooser.getSelectedFile().getAbsolutePath());
            }
            mw.settings.setPort(mw.commPortComboBox.getSelectedItem().toString());
            mw.settings.setPortRate(mw.baudrateSelectionComboBox.getSelectedItem().toString());
            mw.settings.setScrollWindowEnabled(mw.scrollWindowCheckBox.isSelected());
            mw.settings.setVerboseOutputEnabled(mw.showVerboseOutputCheckBox.isSelected());
            mw.settings.setCommandTableEnabled(mw.showCommandTableCheckBox.isSelected());
            mw.settings.setFirmwareVersion(mw.firmwareComboBox.getSelectedItem().toString());
            SettingsFactory.saveSettings(mw.settings);
            if (mw.pendantUI != null) {
                mw.pendantUI.stop();
            }
        }
    });
    // Check command line for a file to open.
    boolean open = false;
    for (String arg : args) {
        if (open) {
            try {
                backend.setGcodeFile(new File(arg));
                open = false;
            } catch (Exception ex) {
                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
                System.exit(1);
            }
        }
        if (arg.equals("--open") || arg.equals("-o")) {
            open = true;
        }
    }
}
Also used : ComponentListener(java.awt.event.ComponentListener) GUIBackend(com.willwinder.universalgcodesender.model.GUIBackend) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) javax.swing(javax.swing) ComponentEvent(java.awt.event.ComponentEvent) File(java.io.File)

Example 2 with GUIBackend

use of com.willwinder.universalgcodesender.model.GUIBackend in project Universal-G-Code-Sender by winder.

the class WidgetPreviewer method main.

public static void main(String[] args) throws Exception {
    BackendAPI backend = new GUIBackend();
    backend.applySettings(SettingsFactory.loadSettings());
    JPanel panel = new JPanel();
    // Create the main frame.
    JFrame frame = new JFrame("Widget Previewer");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(panel, BorderLayout.CENTER);
    // Button panel...
    panel.setLayout(new MigLayout("wrap 1"));
    panel.add(frameLauncherButton("ConnectionPanelGroup", new ConnectionPanelGroup(backend, new JogService(backend))));
    panel.add(frameLauncherButton("CommandTextArea", new CommandTextArea(backend)));
    // panel.add(frameLauncherButton("ConnectionSettingsDialog", new ConnectionSettingsDialog(backend.getSettings()), null, false));
    panel.add(dialogLauncherButton("ConnectionSettingsPanel", new UGSSettingsDialog("ConnectionSettingsPanel", backend.getSettings(), new ConnectionSettingsPanel(backend.getSettings()), frame, true)));
    panel.add(dialogLauncherButton("ControllerProcessorSettingsPanel", new UGSSettingsDialog("ControllerProcessorSettingsPanel", backend.getSettings(), new ControllerProcessorSettingsPanel(backend.getSettings(), FirmwareUtils.getConfigFiles()), frame, true)));
    panel.add(frameLauncherButton("MacroActionPanel", new MacroActionPanel(backend)));
    panel.add(frameLauncherButton("MacroPanel", new MacroPanel(backend)));
    panel.add(frameLauncherButton("OverridesPanel", new OverridesPanel(backend)));
    panel.add(frameLauncherButton("SendStatusLine", new SendStatusLine(backend)));
    panel.add(frameLauncherButton("SendStatusPanel", new SendStatusPanel(backend)));
    panel.add(frameLauncherButton("ActionButtonPanel", new ActionButtonPanel(backend)));
    panel.add(frameLauncherButton("ActionPanel", new ActionPanel(backend)));
    panel.add(frameLauncherButton("CommandPanel", new CommandPanel(backend)));
    panel.add(frameLauncherButton("JogPanel(true)", new JogPanel(backend, new JogService(backend), true)));
    panel.add(frameLauncherButton("JogPanel(false)", new JogPanel(backend, new JogService(backend), false)));
    panel.add(frameLauncherButton("MachineStatusPanel", new MachineStatusPanel(backend)));
    // Display the main frame.
    frame.pack();
    frame.setVisible(true);
}
Also used : JogPanel(com.willwinder.universalgcodesender.uielements.jog.JogPanel) ConnectionPanelGroup(com.willwinder.universalgcodesender.uielements.panels.ConnectionPanelGroup) BackendAPI(com.willwinder.universalgcodesender.model.BackendAPI) MacroPanel(com.willwinder.universalgcodesender.uielements.macros.MacroPanel) MigLayout(net.miginfocom.swing.MigLayout) GUIBackend(com.willwinder.universalgcodesender.model.GUIBackend) SendStatusPanel(com.willwinder.universalgcodesender.uielements.panels.SendStatusPanel) JogService(com.willwinder.universalgcodesender.services.JogService) CommandTextArea(com.willwinder.universalgcodesender.uielements.components.CommandTextArea) CommandPanel(com.willwinder.universalgcodesender.uielements.panels.CommandPanel) BorderLayout(java.awt.BorderLayout) MachineStatusPanel(com.willwinder.universalgcodesender.uielements.panels.MachineStatusPanel) ConnectionSettingsPanel(com.willwinder.universalgcodesender.uielements.panels.ConnectionSettingsPanel) MacroActionPanel(com.willwinder.universalgcodesender.uielements.macros.MacroActionPanel) OverridesPanel(com.willwinder.universalgcodesender.uielements.panels.OverridesPanel) ControllerProcessorSettingsPanel(com.willwinder.universalgcodesender.uielements.panels.ControllerProcessorSettingsPanel) ActionPanel(com.willwinder.universalgcodesender.uielements.panels.ActionPanel) MacroActionPanel(com.willwinder.universalgcodesender.uielements.macros.MacroActionPanel) ActionButtonPanel(com.willwinder.universalgcodesender.uielements.panels.ActionButtonPanel)

Aggregations

GUIBackend (com.willwinder.universalgcodesender.model.GUIBackend)2 BackendAPI (com.willwinder.universalgcodesender.model.BackendAPI)1 JogService (com.willwinder.universalgcodesender.services.JogService)1 CommandTextArea (com.willwinder.universalgcodesender.uielements.components.CommandTextArea)1 JogPanel (com.willwinder.universalgcodesender.uielements.jog.JogPanel)1 MacroActionPanel (com.willwinder.universalgcodesender.uielements.macros.MacroActionPanel)1 MacroPanel (com.willwinder.universalgcodesender.uielements.macros.MacroPanel)1 ActionButtonPanel (com.willwinder.universalgcodesender.uielements.panels.ActionButtonPanel)1 ActionPanel (com.willwinder.universalgcodesender.uielements.panels.ActionPanel)1 CommandPanel (com.willwinder.universalgcodesender.uielements.panels.CommandPanel)1 ConnectionPanelGroup (com.willwinder.universalgcodesender.uielements.panels.ConnectionPanelGroup)1 ConnectionSettingsPanel (com.willwinder.universalgcodesender.uielements.panels.ConnectionSettingsPanel)1 ControllerProcessorSettingsPanel (com.willwinder.universalgcodesender.uielements.panels.ControllerProcessorSettingsPanel)1 MachineStatusPanel (com.willwinder.universalgcodesender.uielements.panels.MachineStatusPanel)1 OverridesPanel (com.willwinder.universalgcodesender.uielements.panels.OverridesPanel)1 SendStatusPanel (com.willwinder.universalgcodesender.uielements.panels.SendStatusPanel)1 BorderLayout (java.awt.BorderLayout)1 ComponentEvent (java.awt.event.ComponentEvent)1 ComponentListener (java.awt.event.ComponentListener)1 File (java.io.File)1