Example usage for javax.swing JMenuItem setAccelerator

List of usage examples for javax.swing JMenuItem setAccelerator

Introduction

In this page you can find the example usage for javax.swing JMenuItem setAccelerator.

Prototype

@BeanProperty(preferred = true, description = "The keystroke combination which will invoke the JMenuItem's actionlisteners without navigating the menu hierarchy")
public void setAccelerator(KeyStroke keyStroke) 

Source Link

Document

Sets the key combination which invokes the menu item's action listeners without navigating the menu hierarchy.

Usage

From source file:com.maxl.java.amikodesk.AMiKoDesk.java

private static void createAndShowFullGUI() {
    // Create and setup window
    final JFrame jframe = new JFrame(Constants.APP_NAME);
    jframe.setName(Constants.APP_NAME + ".main");

    int min_width = CML_OPT_WIDTH;
    int min_height = CML_OPT_HEIGHT;
    jframe.setPreferredSize(new Dimension(min_width, min_height));
    jframe.setMinimumSize(new Dimension(min_width, min_height));
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screen.width - min_width) / 2;
    int y = (screen.height - min_height) / 2;
    jframe.setBounds(x, y, min_width, min_height);

    // Set application icon
    if (Utilities.appCustomization().equals("ywesee")) {
        ImageIcon img = new ImageIcon(Constants.AMIKO_ICON);
        jframe.setIconImage(img.getImage());
    } else if (Utilities.appCustomization().equals("desitin")) {
        ImageIcon img = new ImageIcon(Constants.DESITIN_ICON);
        jframe.setIconImage(img.getImage());
    } else if (Utilities.appCustomization().equals("meddrugs")) {
        ImageIcon img = new ImageIcon(Constants.MEDDRUGS_ICON);
        jframe.setIconImage(img.getImage());
    } else if (Utilities.appCustomization().equals("zurrose")) {
        ImageIcon img = new ImageIcon(Constants.AMIKO_ICON);
        jframe.setIconImage(img.getImage());
    }/*from ww w.j  a  va  2  s .  c  o m*/

    // ------ Setup menubar ------
    JMenuBar menu_bar = new JMenuBar();
    // menu_bar.add(Box.createHorizontalGlue()); // --> aligns menu items to the right!
    // -- Menu "Datei" --
    JMenu datei_menu = new JMenu("Datei");
    if (Utilities.appLanguage().equals("fr"))
        datei_menu.setText("Fichier");
    menu_bar.add(datei_menu);
    JMenuItem print_item = new JMenuItem("Drucken...");
    JMenuItem settings_item = new JMenuItem(m_rb.getString("settings") + "...");
    JMenuItem quit_item = new JMenuItem("Beenden");
    if (Utilities.appLanguage().equals("fr")) {
        print_item.setText("Imprimer");
        quit_item.setText("Terminer");
    }
    datei_menu.add(print_item);
    datei_menu.addSeparator();
    datei_menu.add(settings_item);
    datei_menu.addSeparator();
    datei_menu.add(quit_item);

    // -- Menu "Aktualisieren" --
    JMenu update_menu = new JMenu("Aktualisieren");
    if (Utilities.appLanguage().equals("fr"))
        update_menu.setText("Mise  jour");
    menu_bar.add(update_menu);
    final JMenuItem updatedb_item = new JMenuItem("Aktualisieren via Internet...");
    updatedb_item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
    JMenuItem choosedb_item = new JMenuItem("Aktualisieren via Datei...");
    update_menu.add(updatedb_item);
    update_menu.add(choosedb_item);
    if (Utilities.appLanguage().equals("fr")) {
        updatedb_item.setText("Tlcharger la banque de donnes...");
        updatedb_item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK));
        choosedb_item.setText("Ajourner la banque de donnes...");
    }

    // -- Menu "Hilfe" --
    JMenu hilfe_menu = new JMenu("Hilfe");
    if (Utilities.appLanguage().equals("fr"))
        hilfe_menu.setText("Aide");
    menu_bar.add(hilfe_menu);

    JMenuItem about_item = new JMenuItem("ber " + Constants.APP_NAME + "...");
    JMenuItem ywesee_item = new JMenuItem(Constants.APP_NAME + " im Internet");
    if (Utilities.appCustomization().equals("meddrugs"))
        ywesee_item.setText("med-drugs im Internet");
    JMenuItem report_item = new JMenuItem("Error Report...");
    JMenuItem contact_item = new JMenuItem("Kontakt...");

    if (Utilities.appLanguage().equals("fr")) {
        // Extrawunsch med-drugs
        if (Utilities.appCustomization().equals("meddrugs"))
            about_item.setText(Constants.APP_NAME);
        else
            about_item.setText("A propos de " + Constants.APP_NAME + "...");
        contact_item.setText("Contact...");
        if (Utilities.appCustomization().equals("meddrugs"))
            ywesee_item.setText("med-drugs sur Internet");
        else
            ywesee_item.setText(Constants.APP_NAME + " sur Internet");
        report_item.setText("Rapport d'erreur...");
    }
    hilfe_menu.add(about_item);
    hilfe_menu.add(ywesee_item);
    hilfe_menu.addSeparator();
    hilfe_menu.add(report_item);
    hilfe_menu.addSeparator();
    hilfe_menu.add(contact_item);

    // Menu "Abonnieren" (only for ywesee)
    JMenu subscribe_menu = new JMenu("Abonnieren");
    if (Utilities.appLanguage().equals("fr"))
        subscribe_menu.setText("Abonnement");
    if (Utilities.appCustomization().equals("ywesee")) {
        menu_bar.add(subscribe_menu);
    }

    jframe.setJMenuBar(menu_bar);

    // ------ Setup toolbar ------
    JToolBar toolBar = new JToolBar("Database");
    toolBar.setPreferredSize(new Dimension(jframe.getWidth(), 64));
    final JToggleButton selectAipsButton = new JToggleButton(
            new ImageIcon(Constants.IMG_FOLDER + "aips32x32_bright.png"));
    final JToggleButton selectFavoritesButton = new JToggleButton(
            new ImageIcon(Constants.IMG_FOLDER + "favorites32x32_bright.png"));
    final JToggleButton selectInteractionsButton = new JToggleButton(
            new ImageIcon(Constants.IMG_FOLDER + "interactions32x32_bright.png"));
    final JToggleButton selectShoppingCartButton = new JToggleButton(
            new ImageIcon(Constants.IMG_FOLDER + "shoppingcart32x32_bright.png"));
    final JToggleButton selectComparisonCartButton = new JToggleButton(
            new ImageIcon(Constants.IMG_FOLDER + "comparisoncart32x32_bright.png"));

    final JToggleButton list_of_buttons[] = { selectAipsButton, selectFavoritesButton, selectInteractionsButton,
            selectShoppingCartButton, selectComparisonCartButton };

    if (Utilities.appLanguage().equals("de")) {
        setupButton(selectAipsButton, "Kompendium", "aips32x32_gray.png", "aips32x32_dark.png");
        setupButton(selectFavoritesButton, "Favoriten", "favorites32x32_gray.png", "favorites32x32_dark.png");
        setupButton(selectInteractionsButton, "Interaktionen", "interactions32x32_gray.png",
                "interactions32x32_dark.png");
        setupButton(selectShoppingCartButton, "Warenkorb", "shoppingcart32x32_gray.png",
                "shoppingcart32x32_dark.png");
        setupButton(selectComparisonCartButton, "Preisvergleich", "comparisoncart32x32_gray.png",
                "comparisoncart32x32_dark.png");
    } else if (Utilities.appLanguage().equals("fr")) {
        setupButton(selectAipsButton, "Compendium", "aips32x32_gray.png", "aips32x32_dark.png");
        setupButton(selectFavoritesButton, "Favorites", "favorites32x32_gray.png", "favorites32x32_dark.png");
        setupButton(selectInteractionsButton, "Interactions", "interactions32x32_gray.png",
                "interactions32x32_dark.png");
        setupButton(selectShoppingCartButton, "Panier", "shoppingcart32x32_gray.png",
                "shoppingcart32x32_dark.png");
        setupButton(selectComparisonCartButton, "Preisvergleich", "comparisoncart32x32_gray.png",
                "comparisoncart32x32_dark.png");
    }

    // Add to toolbar and set up
    toolBar.setBackground(m_toolbar_bg);
    toolBar.add(selectAipsButton);
    toolBar.addSeparator();
    toolBar.add(selectFavoritesButton);
    toolBar.addSeparator();
    toolBar.add(selectInteractionsButton);
    if (!Utilities.appCustomization().equals("zurrose")) {
        toolBar.addSeparator();
        toolBar.add(selectShoppingCartButton);
    }
    if (Utilities.appCustomization().equals("zurrorse")) {
        toolBar.addSeparator();
        toolBar.add(selectComparisonCartButton);
    }
    toolBar.setRollover(true);
    toolBar.setFloatable(false);
    // Progress indicator (not working...)
    toolBar.addSeparator(new Dimension(32, 32));
    toolBar.add(m_progress_indicator);

    // ------ Setup settingspage ------
    final SettingsPage settingsPage = new SettingsPage(jframe, m_rb);
    // Attach observer to it
    settingsPage.addObserver(new Observer() {
        public void update(Observable o, Object arg) {
            System.out.println(arg);
            if (m_shopping_cart != null) {
                // Refresh some stuff
                m_shopping_basket.clear();
                int index = m_shopping_cart.getCartIndex();
                if (index > 0)
                    m_web_panel.saveShoppingCartWithIndex(index);
                m_web_panel.updateShoppingHtml();
            }
        }
    });

    jframe.addWindowListener(new WindowListener() {
        // Use WindowAdapter!
        @Override
        public void windowOpened(WindowEvent e) {
        }

        @Override
        public void windowClosed(WindowEvent e) {
            m_web_panel.dispose();
            Runtime.getRuntime().exit(0);
        }

        @Override
        public void windowClosing(WindowEvent e) {
            // Save shopping cart
            int index = m_shopping_cart.getCartIndex();
            if (index > 0 && m_web_panel != null)
                m_web_panel.saveShoppingCartWithIndex(index);
        }

        @Override
        public void windowIconified(WindowEvent e) {
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
        }

        @Override
        public void windowActivated(WindowEvent e) {
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
        }
    });
    print_item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            m_web_panel.print();
        }
    });
    settings_item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            settingsPage.display();
        }
    });
    quit_item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            try {
                // Save shopping cart
                int index = m_shopping_cart.getCartIndex();
                if (index > 0 && m_web_panel != null)
                    m_web_panel.saveShoppingCartWithIndex(index);
                // Save settings
                WindowSaver.saveSettings();
                m_web_panel.dispose();
                Runtime.getRuntime().exit(0);
            } catch (Exception e) {
                System.out.println(e);
            }
        }
    });
    subscribe_menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent event) {
            if (Utilities.appCustomization().equals("ywesee")) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(new URI(
                                "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3UM84Z6WLFKZE"));
                    } catch (IOException e) {
                        // TODO:
                    } catch (URISyntaxException r) {
                        // TODO:
                    }
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent event) {
            // do nothing
        }

        @Override
        public void menuCanceled(MenuEvent event) {
            // do nothing
        }
    });
    contact_item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (Utilities.appCustomization().equals("ywesee")) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        URI mail_to_uri = URI
                                .create("mailto:zdavatz@ywesee.com?subject=AmiKo%20Desktop%20Feedback");
                        Desktop.getDesktop().mail(mail_to_uri);
                    } catch (IOException e) {
                        // TODO:
                    }
                } else {
                    AmiKoDialogs cd = new AmiKoDialogs(Utilities.appLanguage(), Utilities.appCustomization());
                    cd.ContactDialog();
                }
            } else if (Utilities.appCustomization().equals("desitin")) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        URI mail_to_uri = URI
                                .create("mailto:info@desitin.ch?subject=AmiKo%20Desktop%20Desitin%20Feedback");
                        Desktop.getDesktop().mail(mail_to_uri);
                    } catch (IOException e) {
                        // TODO:
                    }
                } else {
                    AmiKoDialogs cd = new AmiKoDialogs(Utilities.appLanguage(), Utilities.appCustomization());
                    cd.ContactDialog();
                }
            } else if (Utilities.appCustomization().equals("meddrugs")) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        URI mail_to_uri = URI.create(
                                "mailto:med-drugs@just-medical.com?subject=med-drugs%20desktop%20Feedback");
                        Desktop.getDesktop().mail(mail_to_uri);
                    } catch (IOException e) {
                        // TODO:
                    }
                } else {
                    AmiKoDialogs cd = new AmiKoDialogs(Utilities.appLanguage(), Utilities.appCustomization());
                    cd.ContactDialog();
                }
            } else if (Utilities.appCustomization().equals("zurrose")) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(new URI("www.zurrose.ch/amiko"));
                    } catch (IOException e) {
                        // TODO:
                    } catch (URISyntaxException r) {
                        // TODO:
                    }
                }
            }
        }
    });
    report_item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            // Check first m_application_folder otherwise resort to
            // pre-installed report
            String report_file = m_application_data_folder + "\\" + Constants.DEFAULT_AMIKO_REPORT_BASE
                    + Utilities.appLanguage() + ".html";
            if (!(new File(report_file)).exists())
                report_file = System.getProperty("user.dir") + "/dbs/" + Constants.DEFAULT_AMIKO_REPORT_BASE
                        + Utilities.appLanguage() + ".html";
            // Open report file in browser
            if (Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(new File(report_file).toURI());
                } catch (IOException e) {
                    // TODO:
                }
            }
        }
    });
    ywesee_item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (Utilities.appCustomization().equals("ywesee")) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(new URI("http://www.ywesee.com/AmiKo/Desktop"));
                    } catch (IOException e) {
                        // TODO:
                    } catch (URISyntaxException r) {
                        // TODO:
                    }
                }
            } else if (Utilities.appCustomization().equals("desitin")) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(
                                new URI("http://www.desitin.ch/produkte/arzneimittel-kompendium-apps/"));
                    } catch (IOException e) {
                        // TODO:
                    } catch (URISyntaxException r) {
                        // TODO:
                    }
                }
            } else if (Utilities.appCustomization().equals("meddrugs")) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        if (Utilities.appLanguage().equals("de"))
                            Desktop.getDesktop().browse(new URI("http://www.med-drugs.ch"));
                        else if (Utilities.appLanguage().equals("fr"))
                            Desktop.getDesktop()
                                    .browse(new URI("http://www.med-drugs.ch/index.cfm?&newlang=fr"));
                    } catch (IOException e) {
                        // TODO:
                    } catch (URISyntaxException r) {
                        // TODO:
                    }
                }
            } else if (Utilities.appCustomization().equals("zurrose")) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(new URI("www.zurrose.ch/amiko"));
                    } catch (IOException e) {
                        // TODO:
                    } catch (URISyntaxException r) {
                        // TODO:
                    }
                }
            }
        }
    });
    about_item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            AmiKoDialogs ad = new AmiKoDialogs(Utilities.appLanguage(), Utilities.appCustomization());
            ad.AboutDialog();
        }
    });

    // Container
    final Container container = jframe.getContentPane();
    container.setBackground(Color.WHITE);
    container.setLayout(new BorderLayout());

    // ==== Toolbar =====
    container.add(toolBar, BorderLayout.NORTH);

    // ==== Left panel ====
    JPanel left_panel = new JPanel();
    left_panel.setBackground(Color.WHITE);
    left_panel.setLayout(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.insets = new Insets(2, 2, 2, 2);

    // ---- Search field ----
    final SearchField searchField = new SearchField("Suche Prparat");
    if (Utilities.appLanguage().equals("fr"))
        searchField.setText("Recherche Specialit");
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = gbc.gridheight = 1;
    gbc.weightx = gbc.weighty = 0.0;
    // --> container.add(searchField, gbc);
    left_panel.add(searchField, gbc);

    // ---- Buttons ----
    // Names
    String l_title = "Prparat";
    String l_author = "Inhaberin";
    String l_atccode = "Wirkstoff / ATC Code";
    String l_regnr = "Zulassungsnummer";
    String l_ingredient = "Wirkstoff";
    String l_therapy = "Therapie";
    String l_search = "Suche";

    if (Utilities.appLanguage().equals("fr")) {
        l_title = "Spcialit";
        l_author = "Titulaire";
        l_atccode = "Principe Active / Code ATC";
        l_regnr = "Nombre Enregistration";
        l_ingredient = "Principe Active";
        l_therapy = "Thrapie";
        l_search = "Recherche";
    }

    ButtonGroup bg = new ButtonGroup();

    JToggleButton but_title = new JToggleButton(l_title);
    setupToggleButton(but_title);
    bg.add(but_title);
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.gridwidth = gbc.gridheight = 1;
    gbc.weightx = gbc.weighty = 0.0;
    // --> container.add(but_title, gbc);
    left_panel.add(but_title, gbc);

    JToggleButton but_auth = new JToggleButton(l_author);
    setupToggleButton(but_auth);
    bg.add(but_auth);
    gbc.gridx = 0;
    gbc.gridy += 1;
    gbc.gridwidth = gbc.gridheight = 1;
    gbc.weightx = gbc.weighty = 0.0;
    // --> container.add(but_auth, gbc);
    left_panel.add(but_auth, gbc);

    JToggleButton but_atccode = new JToggleButton(l_atccode);
    setupToggleButton(but_atccode);
    bg.add(but_atccode);
    gbc.gridx = 0;
    gbc.gridy += 1;
    gbc.gridwidth = gbc.gridheight = 1;
    gbc.weightx = gbc.weighty = 0.0;
    // --> container.add(but_atccode, gbc);
    left_panel.add(but_atccode, gbc);

    JToggleButton but_regnr = new JToggleButton(l_regnr);
    setupToggleButton(but_regnr);
    bg.add(but_regnr);
    gbc.gridx = 0;
    gbc.gridy += 1;
    gbc.gridwidth = gbc.gridheight = 1;
    gbc.weightx = gbc.weighty = 0.0;
    // --> container.add(but_regnr, gbc);
    left_panel.add(but_regnr, gbc);

    JToggleButton but_therapy = new JToggleButton(l_therapy);
    setupToggleButton(but_therapy);
    bg.add(but_therapy);
    gbc.gridx = 0;
    gbc.gridy += 1;
    gbc.gridwidth = gbc.gridheight = 1;
    gbc.weightx = gbc.weighty = 0.0;
    // --> container.add(but_therapy, gbc);
    left_panel.add(but_therapy, gbc);

    // ---- Card layout ----
    final CardLayout cardl = new CardLayout();
    cardl.setHgap(-4); // HACK to make things look better!!
    final JPanel p_results = new JPanel(cardl);
    m_list_titles = new ListPanel();
    m_list_auths = new ListPanel();
    m_list_regnrs = new ListPanel();
    m_list_atccodes = new ListPanel();
    m_list_ingredients = new ListPanel();
    m_list_therapies = new ListPanel();
    // Contraints
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 0;
    gbc.gridy += 1;
    gbc.gridwidth = 1;
    gbc.gridheight = 10;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    //
    p_results.add(m_list_titles, l_title);
    p_results.add(m_list_auths, l_author);
    p_results.add(m_list_regnrs, l_regnr);
    p_results.add(m_list_atccodes, l_atccode);
    p_results.add(m_list_ingredients, l_ingredient);
    p_results.add(m_list_therapies, l_therapy);

    // --> container.add(p_results, gbc);
    left_panel.add(p_results, gbc);
    left_panel.setBorder(null);
    // First card to show
    cardl.show(p_results, l_title);

    // ==== Right panel ====
    JPanel right_panel = new JPanel();
    right_panel.setBackground(Color.WHITE);
    right_panel.setLayout(new GridBagLayout());

    // ---- Section titles ----
    m_section_titles = null;
    if (Utilities.appLanguage().equals("de")) {
        m_section_titles = new IndexPanel(SectionTitle_DE);
    } else if (Utilities.appLanguage().equals("fr")) {
        m_section_titles = new IndexPanel(SectionTitle_FR);
    }
    m_section_titles.setMinimumSize(new Dimension(150, 150));
    m_section_titles.setMaximumSize(new Dimension(320, 1000));

    // ---- Fachinformation ----
    m_web_panel = new WebPanel2();
    m_web_panel.setMinimumSize(new Dimension(320, 150));

    // Add JSplitPane on the RIGHT
    final int Divider_location = 150;
    final int Divider_size = 10;
    final JSplitPane split_pane_right = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, m_section_titles,
            m_web_panel);
    split_pane_right.setOneTouchExpandable(true);
    split_pane_right.setDividerLocation(Divider_location);
    split_pane_right.setDividerSize(Divider_size);

    // Add JSplitPane on the LEFT
    JSplitPane split_pane_left = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left_panel,
            split_pane_right /* right_panel */);
    split_pane_left.setOneTouchExpandable(true);
    split_pane_left.setDividerLocation(320); // Sets the pane divider location
    split_pane_left.setDividerSize(Divider_size);
    container.add(split_pane_left, BorderLayout.CENTER);

    // Add status bar on the bottom
    JPanel statusPanel = new JPanel();
    statusPanel.setPreferredSize(new Dimension(jframe.getWidth(), 16));
    statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS));
    container.add(statusPanel, BorderLayout.SOUTH);

    final JLabel m_status_label = new JLabel("");
    m_status_label.setHorizontalAlignment(SwingConstants.LEFT);
    statusPanel.add(m_status_label);

    // Add mouse listener
    searchField.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            searchField.setText("");
        }
    });

    final String final_title = l_title;
    final String final_author = l_author;
    final String final_atccode = l_atccode;
    final String final_regnr = l_regnr;
    final String final_therapy = l_therapy;
    final String final_search = l_search;

    // Internal class that implements switching between buttons
    final class Toggle {
        public void toggleButton(JToggleButton jbn) {
            for (int i = 0; i < list_of_buttons.length; ++i) {
                if (jbn == list_of_buttons[i])
                    list_of_buttons[i].setSelected(true);
                else
                    list_of_buttons[i].setSelected(false);
            }
        }
    }
    ;

    // ------ Add toolbar action listeners ------
    selectAipsButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            new Toggle().toggleButton(selectAipsButton);
            // Set state 'aips'
            if (!m_curr_uistate.getUseMode().equals("aips")) {
                m_curr_uistate.setUseMode("aips");
                // Show middle pane
                split_pane_right.setDividerSize(Divider_size);
                split_pane_right.setDividerLocation(Divider_location);
                m_section_titles.setVisible(true);
                //
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        m_start_time = System.currentTimeMillis();
                        m_query_str = searchField.getText();
                        int num_hits = retrieveAipsSearchResults(false);
                        m_status_label.setText(med_search.size() + " Suchresultate in "
                                + (System.currentTimeMillis() - m_start_time) / 1000.0f + " Sek.");
                        //
                        if (med_index < 0 && prev_med_index >= 0)
                            med_index = prev_med_index;
                        m_web_panel.updateText();
                        if (num_hits == 0) {
                            m_web_panel.emptyPage();
                        }
                    }
                });
            }
        }
    });
    selectFavoritesButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            new Toggle().toggleButton(selectFavoritesButton);
            // Set state 'favorites'
            if (!m_curr_uistate.getUseMode().equals("favorites")) {
                m_curr_uistate.setUseMode("favorites");
                // Show middle pane
                split_pane_right.setDividerSize(Divider_size);
                split_pane_right.setDividerLocation(Divider_location);
                m_section_titles.setVisible(true);
                //
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        m_start_time = System.currentTimeMillis();
                        // m_query_str = searchField.getText();
                        // Clear the search container
                        med_search.clear();
                        for (String regnr : favorite_meds_set) {
                            List<Medication> meds = m_sqldb.searchRegNr(regnr);
                            if (!meds.isEmpty()) { // Add med database ID
                                med_search.add(meds.get(0));
                            }
                        }
                        // Sort list of meds
                        Collections.sort(med_search, new Comparator<Medication>() {
                            @Override
                            public int compare(final Medication m1, final Medication m2) {
                                return m1.getTitle().compareTo(m2.getTitle());
                            }
                        });

                        sTitle();
                        cardl.show(p_results, final_title);

                        m_status_label.setText(med_search.size() + " Suchresultate in "
                                + (System.currentTimeMillis() - m_start_time) / 1000.0f + " Sek.");
                    }
                });
            }
        }
    });
    selectInteractionsButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            new Toggle().toggleButton(selectInteractionsButton);
            // Set state 'interactions'
            if (!m_curr_uistate.getUseMode().equals("interactions")) {
                m_curr_uistate.setUseMode("interactions");
                // Show middle pane
                split_pane_right.setDividerSize(Divider_size);
                split_pane_right.setDividerLocation(Divider_location);
                m_section_titles.setVisible(true);
                //
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        m_query_str = searchField.getText();
                        retrieveAipsSearchResults(false);
                        // Switch to interaction mode
                        m_web_panel.updateInteractionsCart();
                        m_web_panel.repaint();
                        m_web_panel.validate();
                    }
                });
            }
        }
    });
    selectShoppingCartButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            String email_adr = m_prefs.get("emailadresse", "");
            if (email_adr != null && email_adr.length() > 2) // Two chars is the minimum lenght for an email address
                m_preferences_ok = true;
            if (m_preferences_ok) {
                m_preferences_ok = false; // Check always
                new Toggle().toggleButton(selectShoppingCartButton);
                // Set state 'shopping'
                if (!m_curr_uistate.getUseMode().equals("shopping")) {
                    m_curr_uistate.setUseMode("shopping");
                    // Show middle pane
                    split_pane_right.setDividerSize(Divider_size);
                    split_pane_right.setDividerLocation(Divider_location);
                    m_section_titles.setVisible(true);
                    // Set right panel title
                    m_web_panel.setTitle(m_rb.getString("shoppingCart"));
                    // Switch to shopping cart
                    int index = 1;
                    if (m_shopping_cart != null) {
                        index = m_shopping_cart.getCartIndex();
                        m_web_panel.loadShoppingCartWithIndex(index);
                        // m_shopping_cart.printShoppingBasket();
                    }
                    // m_web_panel.updateShoppingHtml();
                    m_web_panel.updateListOfPackages();
                    if (m_first_pass == true) {
                        m_first_pass = false;
                        if (Utilities.appCustomization().equals("ywesee"))
                            med_search = m_sqldb.searchAuth("ibsa");
                        else if (Utilities.appCustomization().equals("desitin"))
                            med_search = m_sqldb.searchAuth("desitin");
                        sAuth();
                        cardl.show(p_results, final_author);
                    }
                }
            } else {
                selectShoppingCartButton.setSelected(false);
                settingsPage.display();
            }
        }
    });
    selectComparisonCartButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            new Toggle().toggleButton(selectComparisonCartButton);
            // Set state 'comparison'
            if (!m_curr_uistate.getUseMode().equals("comparison")) {
                m_curr_uistate.setUseMode("comparison");
                // Hide middle pane
                m_section_titles.setVisible(false);
                split_pane_right.setDividerLocation(0);
                split_pane_right.setDividerSize(0);
                //
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        m_start_time = System.currentTimeMillis();
                        // Set right panel title
                        m_web_panel.setTitle(getTitle("priceComp"));
                        if (med_index >= 0) {
                            if (med_id != null && med_index < med_id.size()) {
                                Medication m = m_sqldb.getMediWithId(med_id.get(med_index));
                                String atc_code = m.getAtcCode();
                                if (atc_code != null) {
                                    String atc = atc_code.split(";")[0];
                                    m_web_panel.fillComparisonBasket(atc);
                                    m_web_panel.updateComparisonCartHtml();
                                    // Update pane on the left
                                    retrieveAipsSearchResults(false);
                                }
                            }
                        }

                        m_status_label.setText(rose_search.size() + " Suchresultate in "
                                + (System.currentTimeMillis() - m_start_time) / 1000.0f + " Sek.");
                    }
                });
            }
        }
    });

    // ------ Add keylistener to text field (type as you go feature) ------
    searchField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent e) { // keyReleased(KeyEvent e)
            // invokeLater potentially in the wrong place... more testing
            // required
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    if (m_curr_uistate.isLoadCart())
                        m_curr_uistate.restoreUseMode();
                    m_start_time = System.currentTimeMillis();
                    m_query_str = searchField.getText();
                    // Queries for SQLite DB
                    if (!m_query_str.isEmpty()) {
                        if (m_query_type == 0) {
                            if (m_curr_uistate.isComparisonMode()) {
                                rose_search = m_rosedb.searchTitle(m_query_str);
                            } else {
                                med_search = m_sqldb.searchTitle(m_query_str);
                                if (m_curr_uistate.databaseUsed().equals("favorites"))
                                    retrieveFavorites();
                            }
                            sTitle();
                            cardl.show(p_results, final_title);
                        } else if (m_query_type == 1) {
                            if (m_curr_uistate.isComparisonMode()) {
                                rose_search = m_rosedb.searchSupplier(m_query_str);
                            } else {
                                med_search = m_sqldb.searchAuth(m_query_str);
                                if (m_curr_uistate.databaseUsed().equals("favorites"))
                                    retrieveFavorites();
                            }
                            sAuth();
                            cardl.show(p_results, final_author);
                        } else if (m_query_type == 2) {
                            if (m_curr_uistate.isComparisonMode()) {
                                rose_search = m_rosedb.searchATC(m_query_str);
                            } else {
                                med_search = m_sqldb.searchATC(m_query_str);
                                if (m_curr_uistate.databaseUsed().equals("favorites"))
                                    retrieveFavorites();
                            }
                            sATC();
                            cardl.show(p_results, final_atccode);
                        } else if (m_query_type == 3) {
                            if (m_curr_uistate.isComparisonMode()) {
                                rose_search = m_rosedb.searchEan(m_query_str);
                            } else {
                                med_search = m_sqldb.searchRegNr(m_query_str);
                                if (m_curr_uistate.databaseUsed().equals("favorites"))
                                    retrieveFavorites();
                            }
                            sRegNr();
                            cardl.show(p_results, final_regnr);
                        } else if (m_query_type == 4) {
                            if (m_curr_uistate.isComparisonMode()) {
                                rose_search = m_rosedb.searchTherapy(m_query_str);
                            } else {
                                med_search = m_sqldb.searchApplication(m_query_str);
                                if (m_curr_uistate.databaseUsed().equals("favorites"))
                                    retrieveFavorites();
                            }
                            sTherapy();
                            cardl.show(p_results, final_therapy);
                        } else {
                            // do nothing
                        }
                        int num_hits = 0;
                        if (m_curr_uistate.isComparisonMode())
                            num_hits = rose_search.size();
                        else
                            num_hits = med_search.size();
                        m_status_label.setText(num_hits + " Suchresultate in "
                                + (System.currentTimeMillis() - m_start_time) / 1000.0f + " Sek.");

                    }
                }
            });
        }
    });

    // Add actionlisteners
    but_title.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            if (m_curr_uistate.isLoadCart())
                m_curr_uistate.restoreUseMode();
            searchField.setText(final_search + " " + final_title);
            m_curr_uistate.setQueryType(m_query_type = 0);
            sTitle();
            cardl.show(p_results, final_title);
        }
    });
    but_auth.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            if (m_curr_uistate.isLoadCart())
                m_curr_uistate.restoreUseMode();
            searchField.setText(final_search + " " + final_author);
            m_curr_uistate.setQueryType(m_query_type = 1);
            sAuth();
            cardl.show(p_results, final_author);
        }
    });
    but_atccode.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            if (m_curr_uistate.isLoadCart())
                m_curr_uistate.restoreUseMode();
            searchField.setText(final_search + " " + final_atccode);
            m_curr_uistate.setQueryType(m_query_type = 2);
            sATC();
            cardl.show(p_results, final_atccode);
        }
    });
    but_regnr.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            if (m_curr_uistate.isLoadCart())
                m_curr_uistate.restoreUseMode();
            searchField.setText(final_search + " " + final_regnr);
            m_curr_uistate.setQueryType(m_query_type = 3);
            sRegNr();
            cardl.show(p_results, final_regnr);
        }
    });
    but_therapy.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            if (m_curr_uistate.isLoadCart())
                m_curr_uistate.restoreUseMode();
            searchField.setText(final_search + " " + final_therapy);
            m_curr_uistate.setQueryType(m_query_type = 4);
            sTherapy();
            cardl.show(p_results, final_therapy);
        }
    });

    // Display window
    jframe.pack();
    // jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    // jframe.setAlwaysOnTop(true);
    jframe.setVisible(true);

    // Check if user has selected an alternative database
    /*
     * NOTE: 21/11/2013: This solution is put on ice. Favored is a solution
     * where the database selected by the user is saved in a default folder
     * (see variable "m_application_data_folder")
     */
    /*
     * try { WindowSaver.loadSettings(jframe); String database_path =
     * WindowSaver.getDbPath(); if (database_path!=null)
     * m_sqldb.loadDBFromPath(database_path); } catch(IOException e) {
     * e.printStackTrace(); }
     */
    // Load AIPS database
    selectAipsButton.setSelected(true);
    selectFavoritesButton.setSelected(false);
    m_curr_uistate.setUseMode("aips");
    med_search = m_sqldb.searchTitle("");
    sTitle(); // Used instead of sTitle (which is slow)
    cardl.show(p_results, final_title);

    // Add menu item listeners
    updatedb_item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (m_mutex_update == false) {
                m_mutex_update = true;
                String db_file = m_maindb_update.doIt(jframe, Utilities.appLanguage(),
                        Utilities.appCustomization(), m_application_data_folder, m_full_db_update);
                // ... and update time
                if (m_full_db_update == true) {
                    DateTime dT = new DateTime();
                    m_prefs.put("updateTime", dT.now().toString());
                }
                //
                if (!db_file.isEmpty()) {
                    // Save db path (can't hurt)
                    WindowSaver.setDbPath(db_file);
                }
            }
        }
    });

    choosedb_item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            String db_file = m_maindb_update.chooseFromFile(jframe, Utilities.appLanguage(),
                    Utilities.appCustomization(), m_application_data_folder);
            // ... and update time
            DateTime dT = new DateTime();
            m_prefs.put("updateTime", dT.now().toString());
            //
            if (!db_file.isEmpty()) {
                // Save db path (can't hurt)
                WindowSaver.setDbPath(db_file);
            }
        }
    });

    /**
     * Observers
     */
    // Attach observer to 'm_update'
    m_maindb_update.addObserver(new Observer() {
        @Override
        public void update(Observable o, Object arg) {
            System.out.println(arg);
            // Reset flag
            m_full_db_update = true;
            m_mutex_update = false;
            // Refresh some stuff after update
            loadAuthors();
            m_emailer.loadMap();
            settingsPage.load_gln_codes();
            if (m_shopping_cart != null) {
                m_shopping_cart.load_conditions();
                m_shopping_cart.load_glns();
            }
            // Empty shopping basket
            if (m_curr_uistate.isShoppingMode()) {
                m_shopping_basket.clear();
                int index = m_shopping_cart.getCartIndex();
                if (index > 0)
                    m_web_panel.saveShoppingCartWithIndex(index);
                m_web_panel.updateShoppingHtml();
            }
            if (m_curr_uistate.isComparisonMode())
                m_web_panel.setTitle(getTitle("priceComp"));
        }
    });

    // Attach observer to 'm_emailer'
    m_emailer.addObserver(new Observer() {
        @Override
        public void update(Observable o, Object arg) {
            System.out.println(arg);
            // Empty shopping basket
            m_shopping_basket.clear();
            int index = m_shopping_cart.getCartIndex();
            if (index > 0)
                m_web_panel.saveShoppingCartWithIndex(index);
            m_web_panel.updateShoppingHtml();
        }
    });

    // Attach observer to "m_comparison_cart"
    m_comparison_cart.addObserver(new Observer() {
        @Override
        public void update(Observable o, Object arg) {
            System.out.println(arg);
            m_web_panel.setTitle(getTitle("priceComp"));
            m_comparison_cart.clearUploadList();
            m_web_panel.updateComparisonCartHtml();
            new AmiKoDialogs(Utilities.appLanguage(), Utilities.appCustomization()).UploadDialog((String) arg);
        }
    });

    // If command line options are provided start app with a particular title or eancode
    if (commandLineOptionsProvided()) {
        if (!CML_OPT_TITLE.isEmpty())
            startAppWithTitle(but_title);
        else if (!CML_OPT_EANCODE.isEmpty())
            startAppWithEancode(but_regnr);
        else if (!CML_OPT_REGNR.isEmpty())
            startAppWithRegnr(but_regnr);
    }

    // Start timer
    Timer global_timer = new Timer();
    // Time checks all 2 minutes (120'000 milliseconds)
    global_timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            checkIfUpdateRequired(updatedb_item);
        }
    }, 2 * 60 * 1000, 2 * 60 * 1000);
}

From source file:com.emental.mindraider.ui.frames.MindRaiderMainWindow.java

/**
 * Build main menu.//from  w w w .j  av  a2s.co m
 * 
 * @param spiders
 */
private void buildMenu(final SpidersGraph spiders) {
    JMenuBar menuBar;
    JMenu menu, submenu;
    JMenuItem menuItem, subMenuItem;
    JRadioButtonMenuItem rbMenuItem;

    // create the menu bar
    menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    // - main menu -------------------------------------------------------
    menu = new JMenu(MindRaiderConstants.MR_TITLE);
    menu.setMnemonic(KeyEvent.VK_M);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.setActiveNotebookAsHome"));
    menuItem.setMnemonic(KeyEvent.VK_H);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            MindRaider.profile.setHomeNotebook();
        }
    });
    menu.add(menuItem);
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.preferences"));
    menuItem.setMnemonic(KeyEvent.VK_P);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            new PreferencesJDialog();
        }
    });
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.exit"), KeyEvent.VK_X);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            exitMindRaider();
        }
    });
    menu.add(menuItem);

    menuBar.add(menu);

    // - Find ----------------------------------------------------------

    menu = new JMenu(Messages.getString("MindRaiderJFrame.search"));
    menu.setMnemonic(KeyEvent.VK_F);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.searchNotebooks"));
    menuItem.setMnemonic(KeyEvent.VK_N);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            new OpenOutlineJDialog();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.searchFulltext"));
    menuItem.setMnemonic(KeyEvent.VK_F);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menuItem.setEnabled(true);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            new FtsJDialog();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.searchConceptsInNotebook"));
    menuItem.setMnemonic(KeyEvent.VK_C);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (MindRaider.profile.getActiveOutlineUri() != null) {
                new OpenNoteJDialog();
            }
        }
    });
    menu.add(menuItem);

    // search by tag
    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.searchConceptsByTag"));
    menuItem.setEnabled(true);
    menuItem.setMnemonic(KeyEvent.VK_T);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            new OpenConceptByTagJDialog();
        }
    });
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.previousNote"));
    menuItem.setEnabled(true);
    menuItem.setMnemonic(KeyEvent.VK_P);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, ActionEvent.ALT_MASK));
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            MindRaider.recentConcepts.moveOneNoteBack();
        }
    });
    menu.add(menuItem);

    // global RDF search
    //        menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.searchRdql"));
    //        menuItem.setEnabled(false);
    //        menuItem.setMnemonic(KeyEvent.VK_R);
    //        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,
    //                ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    //        menuItem.addActionListener(new ActionListener() {
    //
    //            public void actionPerformed(ActionEvent e) {
    //                // TODO rdql to be implemented
    //            }
    //        });
    //        menu.add(menuItem);

    menuBar.add(menu);

    // - view ------------------------------------------------------------
    menu = new JMenu(Messages.getString("MindRaiderJFrame.view"));
    menu.setMnemonic(KeyEvent.VK_V);

    // TODO localize L&F menu
    ButtonGroup lfGroup = new ButtonGroup();
    submenu = new JMenu(Messages.getString("MindRaiderJFrame.lookAndFeel"));
    logger.debug("Look and feel is: " + MindRaider.profile.getLookAndFeel()); // {{debug}}
    submenu.setMnemonic(KeyEvent.VK_L);
    subMenuItem = new JRadioButtonMenuItem(Messages.getString("MindRaiderJFrame.lookAndFeelNative"));
    if (MindRaider.LF_NATIVE.equals(MindRaider.profile.getLookAndFeel())) {
        subMenuItem.setSelected(true);
    }
    subMenuItem.setEnabled(true);
    subMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            setLookAndFeel(MindRaider.LF_NATIVE);
        }
    });
    submenu.add(subMenuItem);
    lfGroup.add(subMenuItem);
    subMenuItem = new JRadioButtonMenuItem(Messages.getString("MindRaiderJFrame.lookAndFeelJava"));
    if (MindRaider.LF_JAVA_DEFAULT.equals(MindRaider.profile.getLookAndFeel())) {
        subMenuItem.setSelected(true);
    }
    subMenuItem.setEnabled(true);
    subMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            setLookAndFeel(MindRaider.LF_JAVA_DEFAULT);
        }
    });
    submenu.add(subMenuItem);
    lfGroup.add(subMenuItem);
    menu.add(submenu);

    menu.addSeparator();
    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.leftSideBar"));
    menuItem.setMnemonic(KeyEvent.VK_L);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (leftSidebarSplitPane.getDividerLocation() == 1) {
                leftSidebarSplitPane.resetToPreferredSizes();
            } else {
                closeLeftSidebar();
            }
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.rightSideBar"));
    menuItem.setMnemonic(KeyEvent.VK_R);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            OutlineJPanel.getInstance().toggleRightSidebar();
        }
    });
    menu.add(menuItem);

    // TODO tips to be implemented
    // JCheckBoxMenuItem helpCheckbox=new JCheckBoxMenuItem("Tips",true);
    // menu.add(helpCheckbox);

    // TODO localize
    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.toolbar"));
    menuItem.setMnemonic(KeyEvent.VK_T);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            MindRaider.masterToolBar.toggleVisibility();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.rdfNavigatorDashboard"));
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            MindRaider.spidersGraph.getGlPanel().toggleControlPanel();
        }
    });
    menu.add(menuItem);

    JCheckBoxMenuItem checkboxMenuItem;
    ButtonGroup colorSchemeGroup;

    //        if (!MindRaider.OUTLINER_PERSPECTIVE.equals(MindRaider.profile
    //                .getUiPerspective())) {

    menu.addSeparator();

    // Facets
    submenu = new JMenu(Messages.getString("MindRaiderJFrame.facet"));
    submenu.setMnemonic(KeyEvent.VK_F);
    colorSchemeGroup = new ButtonGroup();

    String[] facetLabels = FacetCustodian.getInstance().getFacetLabels();
    if (!ArrayUtils.isEmpty(facetLabels)) {
        for (String facetLabel : facetLabels) {
            rbMenuItem = new JRadioButtonMenuItem(facetLabel);
            rbMenuItem.addActionListener(new FacetActionListener(facetLabel));
            colorSchemeGroup.add(rbMenuItem);
            submenu.add(rbMenuItem);
            if (BriefFacet.LABEL.equals(facetLabel)) {
                rbMenuItem.setSelected(true);
            }
        }

    }
    menu.add(submenu);

    checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.graphLabelAsUri"));
    checkboxMenuItem.setMnemonic(KeyEvent.VK_G);
    checkboxMenuItem.setState(MindRaider.spidersGraph.isUriLabels());
    checkboxMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof JCheckBoxMenuItem) {
                JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource();
                MindRaider.spidersGraph.setUriLabels(j.getState());
                MindRaider.spidersGraph.renderModel();
                MindRaider.profile.setGraphShowLabelsAsUris(j.getState());
                MindRaider.profile.save();
            }
        }
    });

    menu.add(checkboxMenuItem);

    checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.predicateNodes"));
    checkboxMenuItem.setMnemonic(KeyEvent.VK_P);
    checkboxMenuItem.setState(!MindRaider.spidersGraph.getHidePredicates());
    checkboxMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof JCheckBoxMenuItem) {
                JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource();
                MindRaider.spidersGraph.hidePredicates(!j.getState());
                MindRaider.spidersGraph.renderModel();
                MindRaider.profile.setGraphHidePredicates(!j.getState());
                MindRaider.profile.save();
            }
        }
    });
    menu.add(checkboxMenuItem);

    checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.multilineLabels"));
    checkboxMenuItem.setMnemonic(KeyEvent.VK_M);
    checkboxMenuItem.setState(MindRaider.spidersGraph.isMultilineNodes());
    checkboxMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof JCheckBoxMenuItem) {
                JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource();
                MindRaider.spidersGraph.setMultilineNodes(j.getState());
                MindRaider.spidersGraph.renderModel();
                MindRaider.profile.setGraphMultilineLabels(j.getState());
                MindRaider.profile.save();
            }
        }
    });
    menu.add(checkboxMenuItem);
    //        }

    menu.addSeparator();

    // Antialias
    checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.antiAliased"), true);
    checkboxMenuItem.setMnemonic(KeyEvent.VK_A);
    checkboxMenuItem.setState(SpidersGraph.antialiased);
    checkboxMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof JCheckBoxMenuItem) {
                JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource();
                SpidersGraph.antialiased = j.getState();
                MindRaider.spidersGraph.renderModel();
            }
        }
    });
    menu.add(checkboxMenuItem);

    // Enable hyperbolic
    checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.hyperbolic"), true);
    checkboxMenuItem.setMnemonic(KeyEvent.VK_H);
    checkboxMenuItem.setState(SpidersGraph.hyperbolic);
    checkboxMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof JCheckBoxMenuItem) {
                JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource();
                SpidersGraph.hyperbolic = j.getState();
                MindRaider.spidersGraph.renderModel();
            }
        }
    });
    menu.add(checkboxMenuItem);

    // Show FPS
    checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.fps"), true);
    checkboxMenuItem.setMnemonic(KeyEvent.VK_F);
    checkboxMenuItem.setState(SpidersGraph.fps);
    checkboxMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof JCheckBoxMenuItem) {
                JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource();
                SpidersGraph.fps = j.getState();
                MindRaider.spidersGraph.renderModel();
            }
        }
    });
    menu.add(checkboxMenuItem);

    // Graph color scheme
    submenu = new JMenu(Messages.getString("MindRaiderJFrame.colorScheme"));
    submenu.setMnemonic(KeyEvent.VK_C);
    String[] allProfilesUris = MindRaider.spidersColorProfileRegistry.getAllProfilesUris();
    colorSchemeGroup = new ButtonGroup();
    for (int i = 0; i < allProfilesUris.length; i++) {
        rbMenuItem = new UriJRadioButtonMenuItem(
                MindRaider.spidersColorProfileRegistry.getColorProfileByUri(allProfilesUris[i]).getLabel(),
                allProfilesUris[i]);
        rbMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() instanceof UriJRadioButtonMenuItem) {
                    MindRaider.spidersColorProfileRegistry
                            .setCurrentProfile(((UriJRadioButtonMenuItem) e.getSource()).uri);
                    MindRaider.spidersGraph
                            .setRenderingProfile(MindRaider.spidersColorProfileRegistry.getCurrentProfile());
                    MindRaider.spidersGraph.renderModel();
                }
            }
        });
        colorSchemeGroup.add(rbMenuItem);
        submenu.add(rbMenuItem);
    }
    menu.add(submenu);

    // Annotation color scheme
    submenu = new JMenu(Messages.getString("MindRaiderJFrame.colorSchemeAnnotation"));
    submenu.setMnemonic(KeyEvent.VK_A);
    allProfilesUris = MindRaider.annotationColorProfileRegistry.getAllProfilesUris();
    colorSchemeGroup = new ButtonGroup();
    for (int i = 0; i < allProfilesUris.length; i++) {
        rbMenuItem = new UriJRadioButtonMenuItem(
                MindRaider.annotationColorProfileRegistry.getColorProfileByUri(allProfilesUris[i]).getLabel(),
                allProfilesUris[i]);
        rbMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() instanceof UriJRadioButtonMenuItem) {
                    MindRaider.annotationColorProfileRegistry
                            .setCurrentProfile(((UriJRadioButtonMenuItem) e.getSource()).uri);
                    OutlineJPanel.getInstance().conceptJPanel.refresh();
                }
            }
        });
        colorSchemeGroup.add(rbMenuItem);
        submenu.add(rbMenuItem);
    }
    menu.add(submenu);

    menu.addSeparator();

    checkboxMenuItem = new JCheckBoxMenuItem(Messages.getString("MindRaiderJFrame.fullScreen"));
    checkboxMenuItem.setMnemonic(KeyEvent.VK_U);
    checkboxMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0));
    checkboxMenuItem.setState(false);
    checkboxMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof JCheckBoxMenuItem) {
                JCheckBoxMenuItem j = (JCheckBoxMenuItem) e.getSource();
                if (j.getState()) {
                    Gfx.toggleFullScreen(MindRaiderMainWindow.this);
                } else {
                    Gfx.toggleFullScreen(null);
                }
            }
        }
    });
    menu.add(checkboxMenuItem);

    menuBar.add(menu);

    // - outline
    // ----------------------------------------------------------------------
    menu = new JMenu(Messages.getString("MindRaiderJFrame.notebook"));
    menu.setMnemonic(KeyEvent.VK_N);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.newNotebook"));
    menuItem.setMnemonic(KeyEvent.VK_N);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            // TODO clear should be optional - only if creation finished
            // MindRider.spidersGraph.clear();
            new NewOutlineJDialog();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.open"));
    menuItem.setMnemonic(KeyEvent.VK_O);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            new OpenOutlineJDialog();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.close"));
    menuItem.setMnemonic(KeyEvent.VK_C);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            MindRaider.outlineCustodian.close();
            OutlineJPanel.getInstance().refresh();
            MindRaider.spidersGraph.renderModel();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.discard"));
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.setEnabled(false); // TODO discard method must be implemented
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int result = JOptionPane.showConfirmDialog(MindRaiderMainWindow.this, Messages.getString(
                    "MindRaiderJFrame.confirmDiscardNotebook", MindRaider.profile.getActiveOutline()));
            if (result == JOptionPane.YES_OPTION) {
                if (MindRaider.profile.getActiveOutlineUri() != null) {
                    try {
                        MindRaider.labelCustodian
                                .discardOutline(MindRaider.profile.getActiveOutlineUri().toString());
                        MindRaider.outlineCustodian.close();
                    } catch (Exception e1) {
                        logger.error(Messages.getString("MindRaiderJFrame.unableToDiscardNotebook"), e1);
                    }
                }
            }
        }
    });
    menu.add(menuItem);

    menu.addSeparator();

    // export
    submenu = new JMenu(Messages.getString("MindRaiderJFrame.export"));
    submenu.setMnemonic(KeyEvent.VK_E);
    // Atom
    subMenuItem = new JMenuItem("Atom");
    subMenuItem.setEnabled(true);
    subMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            exportActiveOutlineToAtom();
        }
    });
    submenu.add(subMenuItem);

    // OPML
    subMenuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.opml"));
    subMenuItem.setEnabled(true);
    subMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (MindRaider.profile.getActiveOutline() == null) {
                JOptionPane.showMessageDialog(MindRaiderMainWindow.this,
                        Messages.getString("MindRaiderJFrame.exportNotebookWarning"),
                        Messages.getString("MindRaiderJFrame.exportError"),

                        JOptionPane.ERROR_MESSAGE);
                return;
            }

            JFileChooser fc = new JFileChooser();
            fc.setApproveButtonText(Messages.getString("MindRaiderJFrame.export"));
            fc.setControlButtonsAreShown(true);
            fc.setDialogTitle(Messages.getString("MindRaiderJFrame.chooseExportDirectory"));
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            // prepare directory
            String exportDirectory = MindRaider.profile.getHomeDirectory() + File.separator + "export"
                    + File.separator + "opml";
            Utils.createDirectory(exportDirectory);
            fc.setCurrentDirectory(new File(exportDirectory));
            int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                String dstFileName = fc.getSelectedFile().getAbsolutePath() + File.separator + "OPML-EXPORT-"
                        + MindRaider.outlineCustodian.getActiveNotebookNcName() + ".xml";
                logger.debug(Messages.getString("MindRaiderJFrame.exportingToFile", dstFileName));
                MindRaider.outlineCustodian.exportOutline(OutlineCustodian.FORMAT_OPML, dstFileName);
                Launcher.launchViaStart(dstFileName);
            } else {
                logger.debug(Messages.getString("MindRaiderJFrame.exportCommandCancelledByUser"));
            }
        }
    });
    submenu.add(subMenuItem);
    // TWiki
    subMenuItem = new JMenuItem("TWiki");
    subMenuItem.setEnabled(true);
    subMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (MindRaider.profile.getActiveOutline() == null) {
                JOptionPane.showMessageDialog(MindRaiderMainWindow.this,
                        Messages.getString("MindRaiderJFrame.exportNotebookWarning"),
                        Messages.getString("MindRaiderJFrame.exportError"), JOptionPane.ERROR_MESSAGE);
                return;
            }

            JFileChooser fc = new JFileChooser();
            fc.setApproveButtonText(Messages.getString("MindRaiderJFrame.export"));
            fc.setControlButtonsAreShown(true);
            fc.setDialogTitle(Messages.getString("MindRaiderJFrame.chooseExportDirectory"));
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            // prepare directory
            String exportDirectory = MindRaider.profile.getHomeDirectory() + File.separator + "export"
                    + File.separator + "twiki";
            Utils.createDirectory(exportDirectory);
            fc.setCurrentDirectory(new File(exportDirectory));
            int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                final String dstFileName = fc.getSelectedFile().getAbsolutePath() + File.separator
                        + "TWIKI-EXPORT-" + MindRaider.outlineCustodian.getActiveNotebookNcName() + ".txt";
                logger.debug(Messages.getString("MindRaiderJFrame.exportingToFile", dstFileName));

                MindRaider.outlineCustodian.exportOutline(OutlineCustodian.FORMAT_TWIKI, dstFileName);
            } else {
                logger.debug(Messages.getString("MindRaiderJFrame.exportCommandCancelledByUser"));
            }
        }
    });
    submenu.add(subMenuItem);

    menu.add(submenu);

    // import
    submenu = new JMenu(Messages.getString("MindRaiderJFrame.import"));
    submenu.setMnemonic(KeyEvent.VK_I);

    subMenuItem = new JMenuItem("Atom");
    subMenuItem.setEnabled(true);
    subMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            importFromAtom();
        }
    });
    submenu.add(subMenuItem);

    // TWiki
    subMenuItem = new JMenuItem("TWiki");
    subMenuItem.setEnabled(true);
    subMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            // choose file to be transformed
            OutlineJPanel.getInstance().clear();
            MindRaider.profile.setActiveOutlineUri(null);
            JFileChooser fc = new JFileChooser();
            int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                final File file = fc.getSelectedFile();
                MindRaider.profile.deleteActiveModel();
                logger.debug(
                        Messages.getString("MindRaiderJFrame.importingTWikiTopic", file.getAbsolutePath()));

                // perform it async
                final SwingWorker worker = new SwingWorker() {

                    public Object construct() {
                        ProgressDialogJFrame progressDialogJFrame = new ProgressDialogJFrame(
                                Messages.getString("MindRaiderJFrame.twikiImport"),
                                Messages.getString("MindRaiderJFrame.processingTopicTWiki"));
                        try {
                            MindRaider.outlineCustodian.importNotebook(OutlineCustodian.FORMAT_TWIKI,
                                    (file != null ? file.getAbsolutePath() : null), progressDialogJFrame);
                        } finally {
                            if (progressDialogJFrame != null) {
                                progressDialogJFrame.dispose();
                            }
                        }
                        return null;
                    }
                };
                worker.start();
            } else {
                logger.debug(Messages.getString("MindRaiderJFrame.openCommandCancelledByUser"));
            }
        }
    });
    submenu.add(subMenuItem);

    menu.add(submenu);

    menuBar.add(menu);

    // - note
    // ----------------------------------------------------------------------
    menu = new JMenu(Messages.getString("MindRaiderJFrame.concept"));
    menu.setMnemonic(KeyEvent.VK_C);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.new"));
    menuItem.setMnemonic(KeyEvent.VK_N);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            OutlineJPanel.getInstance().newConcept();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.open"));
    menuItem.setMnemonic(KeyEvent.VK_O);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (MindRaider.profile.getActiveOutlineUri() != null) {
                new OpenNoteJDialog();
            }
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.discard"));
    // do not accelerate this command with DEL - it's already handled
    // elsewhere
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            OutlineJPanel.getInstance().conceptDiscard();
        }
    });
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.up"));
    menuItem.setMnemonic(KeyEvent.VK_U);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, ActionEvent.CTRL_MASK));
    menuItem.setEnabled(true);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            OutlineJPanel.getInstance().conceptUp();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.promote"));
    menuItem.setMnemonic(KeyEvent.VK_P);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, ActionEvent.CTRL_MASK));
    menuItem.setEnabled(true);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            OutlineJPanel.getInstance().conceptPromote();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.demote"));
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, ActionEvent.CTRL_MASK));
    menuItem.setEnabled(true);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            OutlineJPanel.getInstance().conceptDemote();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.down"));
    menuItem.setMnemonic(KeyEvent.VK_O);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, ActionEvent.CTRL_MASK));
    menuItem.setEnabled(true);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            OutlineJPanel.getInstance().conceptDown();
        }
    });
    menu.add(menuItem);

    menuBar.add(menu);

    // - Tools -----------------------------------------------------------

    menu = new JMenu(Messages.getString("MindRaiderJFrame.tools"));
    menu.setMnemonic(KeyEvent.VK_T);

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.checkAndFix"));
    menuItem.setMnemonic(KeyEvent.VK_F);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Checker.checkAndFixRepositoryAsync();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.backupRepository"));
    menuItem.setMnemonic(KeyEvent.VK_B);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Installer.backupRepositoryAsync();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.rebuildSearchIndex"));
    menuItem.setMnemonic(KeyEvent.VK_R);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            SearchCommander.rebuildSearchAndTagIndices();
        }
    });
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.captureScreen"));
    menuItem.setMnemonic(KeyEvent.VK_S);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = new JFileChooser();
            fc.setApproveButtonText(Messages.getString("MindRaiderJFrame.screenshot"));
            fc.setControlButtonsAreShown(true);
            fc.setDialogTitle(Messages.getString("MindRaiderJFrame.chooseScreenshotDirectory"));
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            // prepare directory
            String exportDirectory = MindRaider.profile.getHomeDirectory() + File.separator + "Screenshots";
            Utils.createDirectory(exportDirectory);
            fc.setCurrentDirectory(new File(exportDirectory));
            int returnVal = fc.showOpenDialog(MindRaiderMainWindow.this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                final String filename = fc.getSelectedFile().getAbsolutePath() + File.separator
                        + "screenshot.jpg";

                // do it in async (redraw screen)
                Thread thread = new Thread() {
                    public void run() {
                        OutputStream file = null;
                        try {
                            file = new FileOutputStream(filename);

                            Robot robot = new Robot();
                            robot.delay(1000);

                            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(file);
                            encoder.encode(robot.createScreenCapture(
                                    new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())));
                        } catch (Exception e1) {
                            logger.error("Unable to capture screen!", e1);
                        } finally {
                            if (file != null) {
                                try {
                                    file.close();
                                } catch (IOException e1) {
                                    logger.error("Unable to close stream", e1);
                                }
                            }
                        }
                    }
                };
                thread.setDaemon(true);
                thread.start();

            }
        }
    });
    menu.add(menuItem);

    menuBar.add(menu);

    // - MindForger -----------------------------------------------------------

    menu = new JMenu(Messages.getString("MindRaiderMainWindow.menuMindForger"));
    menu.setMnemonic(KeyEvent.VK_O);
    //menu.setIcon(IconsRegistry.getImageIcon("tasks-internet.png"));

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.menuMindForgerVideoTutorial"));
    menuItem.setMnemonic(KeyEvent.VK_G);
    menuItem.setToolTipText("http://mindraider.sourceforge.net/mindforger.html");
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Launcher.launchInBrowser("http://mindraider.sourceforge.net/mindforger.html");
        }
    });
    menuItem.setEnabled(true);
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.signUp"));
    menuItem.setMnemonic(KeyEvent.VK_S);
    menuItem.setToolTipText("http://www.mindforger.com");
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Launcher.launchInBrowser("http://www.mindforger.com");
        }
    });
    menuItem.setEnabled(true);
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.menuMindForgerUpload"));
    menuItem.setMnemonic(KeyEvent.VK_U);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // fork in order to enable status updates in the main window
            new MindForgerUploadOutlineJDialog();
        }
    });
    menuItem.setEnabled(true);
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.menuMindForgerDownload"));
    menuItem.setMnemonic(KeyEvent.VK_U);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            downloadAnOutlineFromMindForger();
        }
    });
    menuItem.setEnabled(true);
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.menuMindForgerMyOutlines"));
    menuItem.setMnemonic(KeyEvent.VK_O);
    menuItem.setEnabled(true);
    menuItem.setToolTipText("http://web.mindforger.com");
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Launcher.launchInBrowser("http://web.mindforger.com");
        }
    });
    menu.add(menuItem);

    menuBar.add(menu);

    // - align Help on right -------------------------------------------------------------

    menuBar.add(Box.createHorizontalGlue());

    // - help -------------------------------------------------------------
    menu = new JMenu(Messages.getString("MindRaiderJFrame.help"));
    menu.setMnemonic(KeyEvent.VK_H);

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.documentation"));
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                MindRaider.outlineCustodian.loadOutline(new URI(MindRaiderVocabulary
                        .getNotebookUri(OutlineCustodian.MR_DOC_NOTEBOOK_DOCUMENTATION_LOCAL_NAME)));
                OutlineJPanel.getInstance().refresh();
            } catch (Exception e1) {
                logger.error(Messages.getString("MindRaiderJFrame.unableToLoadHelp", e1.getMessage()));
            }
        }
    });
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.webHomepage"));
    menuItem.setMnemonic(KeyEvent.VK_H);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Launcher.launchInBrowser("http://mindraider.sourceforge.net");
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.reportBug"));
    menuItem.setMnemonic(KeyEvent.VK_R);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Launcher.launchInBrowser("http://sourceforge.net/forum/?group_id=128454");
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem(Messages.getString("MindRaiderMainWindow.updateCheck"));
    menuItem.setMnemonic(KeyEvent.VK_F);
    menuItem.setEnabled(true);
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // just open html page at:
            //   http://mindraider.sourceforge.net/update-7.2.html
            // this page will either contain "you have the last version" or will ask user to
            // download the latest version from main page
            Launcher.launchInBrowser("http://mindraider.sourceforge.net/" + "update-"
                    + MindRaiderConstants.majorVersion + "." + MindRaiderConstants.minorVersion + ".html");
        }
    });
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem(Messages.getString("MindRaiderJFrame.about", MindRaiderConstants.MR_TITLE));
    menuItem.setMnemonic(KeyEvent.VK_A);
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            new AboutJDialog();
        }
    });
    menu.add(menuItem);

    menuBar.add(menu);
}

From source file:com.hexidec.ekit.EkitCore.java

/**
 * Master Constructor// w w  w. java  2s . com
 * 
 * @param sDocument
 *            [String] A text or HTML document to load in the editor upon
 *            startup.
 * @param sStyleSheet
 *            [String] A CSS stylesheet to load in the editor upon startup.
 * @param sRawDocument
 *            [String] A document encoded as a String to load in the editor
 *            upon startup.
 * @param sdocSource
 *            [StyledDocument] Optional document specification, using
 *            javax.swing.text.StyledDocument.
 * @param urlStyleSheet
 *            [URL] A URL reference to the CSS style sheet.
 * @param includeToolBar
 *            [boolean] Specifies whether the app should include the
 *            toolbar(s).
 * @param showViewSource
 *            [boolean] Specifies whether or not to show the View Source
 *            window on startup.
 * @param showMenuIcons
 *            [boolean] Specifies whether or not to show icon pictures in
 *            menus.
 * @param sLanguage
 *            [String] The language portion of the Internationalization
 *            Locale to run Ekit in.
 * @param sCountry
 *            [String] The country portion of the Internationalization
 *            Locale to run Ekit in.
 * @param base64
 *            [boolean] Specifies whether the raw document is Base64 encoded
 *            or not.
 * @param debugMode
 *            [boolean] Specifies whether to show the Debug menu or not.
 * @param hasSpellChecker
 *            [boolean] Specifies whether or not this uses the SpellChecker
 *            module
 * @param multiBar
 *            [boolean] Specifies whether to use multiple toolbars or one
 *            big toolbar.
 * @param toolbarSeq
 *            [String] Code string specifying the toolbar buttons to show.
 * @param keepUnknownTags
 *            [boolean] Specifies whether or not the parser should retain
 *            unknown tags.
 * @param enterBreak
 *            [boolean] Specifies whether the ENTER key should insert breaks
 *            instead of paragraph tags.
 * @param inlineEdit
 *            [boolean] Should edit inline content only (no line breaks)
 */
public EkitCore(boolean isParentApplet, String sDocument, String sStyleSheet, String sRawDocument,
        StyledDocument sdocSource, URL urlStyleSheet, boolean includeToolBar, boolean showViewSource,
        boolean showMenuIcons, String sLanguage, String sCountry, boolean base64, boolean debugMode,
        boolean hasSpellChecker, boolean multiBar, String toolbarSeq, boolean keepUnknownTags,
        boolean enterBreak, boolean inlineEdit, List<HTMLDocumentBehavior> behaviors) {
    super();

    if (behaviors != null) {
        this.behaviors.addAll(behaviors);
    }

    preserveUnknownTags = keepUnknownTags;
    enterIsBreak = enterBreak;
    this.inlineEdit = inlineEdit;

    frameHandler = new Frame();

    // Determine if system clipboard is available (SecurityManager version)
    /*
     * SecurityManager secManager = System.getSecurityManager();
     * if(secManager != null) { try {
     * secManager.checkSystemClipboardAccess(); sysClipboard =
     * Toolkit.getDefaultToolkit().getSystemClipboard(); }
     * catch(SecurityException se) { sysClipboard = null; } }
     */

    // Obtain system clipboard if available
    try {
        sysClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    } catch (Exception ex) {
        sysClipboard = null;
    }

    // Plain text DataFlavor for unformatted paste
    try {
        dfPlainText = new DataFlavor("text/plain; class=java.lang.String; charset=Unicode"); // Charsets
        // usually
        // available
        // include
        // Unicode,
        // UTF-16,
        // UTF-8,
        // &
        // US-ASCII
    } catch (ClassNotFoundException cnfe) {
        // it would be nice to use DataFlavor.plainTextFlavor, but that is
        // deprecated
        // this will not work as desired, but it will prevent errors from
        // being thrown later
        // alternately, we could flag up here that Unformatted Paste is not
        // available and adjust the UI accordingly
        // however, the odds of java.lang.String not being found are pretty
        // slim one imagines
        dfPlainText = DataFlavor.stringFlavor;
    }

    /* Localize for language */
    Locale baseLocale = Locale.getDefault();
    if (sLanguage != null && sCountry != null) {
        baseLocale = new Locale(sLanguage, sCountry);
    }
    Translatrix.init("EkitLanguageResources", baseLocale);

    /* Initialise system-specific control key value */
    if (!(GraphicsEnvironment.isHeadless())) {
        CTRLKEY = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    }

    /* Create the editor kit, document, and stylesheet */
    jtpMain = new EkitTextPane();
    htmlKit = new ExtendedHTMLEditorKit();
    htmlDoc = (ExtendedHTMLDocument) (htmlKit.createDefaultDocument());
    htmlDoc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
    htmlDoc.setPreservesUnknownTags(preserveUnknownTags);
    styleSheet = htmlDoc.getStyleSheet();
    htmlKit.setDefaultCursor(new Cursor(Cursor.TEXT_CURSOR));
    jtpMain.setCursor(new Cursor(Cursor.TEXT_CURSOR));

    /* Set up the text pane */
    jtpMain.setEditorKit(htmlKit);
    jtpMain.setDocument(htmlDoc);
    //      jtpMain.addMouseMotionListener(new EkitMouseMotionListener());
    jtpMain.addFocusListener(this);
    jtpMain.setMargin(new Insets(4, 4, 4, 4));
    jtpMain.addKeyListener(this);
    // jtpMain.setDragEnabled(true); // this causes an error in older Java
    // versions

    /* Create the source text area */
    if (sdocSource == null) {
        jtpSource = new JTextArea();
        jtpSource.setText(jtpMain.getText());
    } else {
        jtpSource = new JTextArea(sdocSource);
        jtpMain.setText(jtpSource.getText());
    }
    jtpSource.setBackground(new Color(212, 212, 212));
    jtpSource.setSelectionColor(new Color(255, 192, 192));
    jtpSource.setMargin(new Insets(4, 4, 4, 4));
    jtpSource.getDocument().addDocumentListener(this);
    jtpSource.addFocusListener(this);
    jtpSource.setCursor(new Cursor(Cursor.TEXT_CURSOR));
    jtpSource.setColumns(1024);
    jtpSource.setEditable(false);

    /* Add CaretListener for tracking caret location events */
    jtpMain.addCaretListener(new CaretListener() {
        public void caretUpdate(CaretEvent ce) {
            handleCaretPositionChange(ce);
        }
    });

    // Default text
    if (!inlineEdit) {
        setDocumentText("<p></p>");
    }

    /* Set up the undo features */
    undoMngr = new UndoManager();
    undoAction = new UndoAction();
    redoAction = new RedoAction();
    jtpMain.getDocument().addUndoableEditListener(new CustomUndoableEditListener());

    /* Insert raw document, if exists */
    if (sRawDocument != null && sRawDocument.length() > 0) {
        if (base64) {
            jtpMain.setText(Base64Codec.decode(sRawDocument));
        } else {
            jtpMain.setText(sRawDocument);
        }
    }
    jtpMain.setCaretPosition(0);
    jtpMain.getDocument().addDocumentListener(this);

    /* Import CSS from reference, if exists */
    if (urlStyleSheet != null) {
        try {
            String currDocText = jtpMain.getText();
            htmlDoc = (ExtendedHTMLDocument) (htmlKit.createDefaultDocument());
            htmlDoc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
            htmlDoc.setPreservesUnknownTags(preserveUnknownTags);
            styleSheet = htmlDoc.getStyleSheet();
            BufferedReader br = new BufferedReader(new InputStreamReader(urlStyleSheet.openStream()));
            styleSheet.loadRules(br, urlStyleSheet);
            br.close();
            htmlDoc = new ExtendedHTMLDocument(styleSheet);
            registerDocument(htmlDoc);
            jtpMain.setText(currDocText);
            jtpSource.setText(jtpMain.getText());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

    /* Preload the specified HTML document, if exists */
    if (sDocument != null) {
        File defHTML = new File(sDocument);
        if (defHTML.exists()) {
            try {
                openDocument(defHTML);
            } catch (Exception e) {
                logException("Exception in preloading HTML document", e);
            }
        }
    }

    /* Preload the specified CSS document, if exists */
    if (sStyleSheet != null) {
        File defCSS = new File(sStyleSheet);
        if (defCSS.exists()) {
            try {
                openStyleSheet(defCSS);
            } catch (Exception e) {
                logException("Exception in preloading CSS stylesheet", e);
            }
        }
    }

    /* Collect the actions that the JTextPane is naturally aware of */
    Hashtable<Object, Action> actions = new Hashtable<Object, Action>();
    Action[] actionsArray = jtpMain.getActions();
    for (Action a : actionsArray) {
        actions.put(a.getValue(Action.NAME), a);
    }

    /* Create shared actions */
    actionFontBold = new StyledEditorKit.BoldAction();
    actionFontItalic = new StyledEditorKit.ItalicAction();
    actionFontUnderline = new StyledEditorKit.UnderlineAction();
    actionFontStrike = new FormatAction(this, Translatrix.getTranslationString("FontStrike"), HTML.Tag.STRIKE);
    actionFontSuperscript = new FormatAction(this, Translatrix.getTranslationString("FontSuperscript"),
            HTML.Tag.SUP);
    actionFontSubscript = new FormatAction(this, Translatrix.getTranslationString("FontSubscript"),
            HTML.Tag.SUB);
    actionListUnordered = new ListAutomationAction(this, Translatrix.getTranslationString("ListUnordered"),
            HTML.Tag.UL);
    actionListOrdered = new ListAutomationAction(this, Translatrix.getTranslationString("ListOrdered"),
            HTML.Tag.OL);
    actionSelectFont = new SetFontFamilyAction(this, "[MENUFONTSELECTOR]");
    actionAlignLeft = new AlignmentAction(Translatrix.getTranslationString("AlignLeft"),
            StyleConstants.ALIGN_LEFT);
    actionAlignCenter = new AlignmentAction(Translatrix.getTranslationString("AlignCenter"),
            StyleConstants.ALIGN_CENTER);
    actionAlignRight = new AlignmentAction(Translatrix.getTranslationString("AlignRight"),
            StyleConstants.ALIGN_RIGHT);
    actionAlignJustified = new AlignmentAction(Translatrix.getTranslationString("AlignJustified"),
            StyleConstants.ALIGN_JUSTIFIED);
    actionInsertAnchor = new CustomAction(this, Translatrix.getTranslationString("InsertAnchor") + menuDialog,
            HTML.Tag.A);
    actionClearFormat = new ClearFormatAction(this);
    actionSpecialChar = new SpecialCharAction(this);

    // actionTableButtonMenu
    Action actionTableInsert = new CommandAction(Translatrix.getTranslationString("InsertTable") + menuDialog,
            getEkitIcon("TableCreate"), CMD_TABLE_INSERT, this);
    Action actionTableDelete = new CommandAction(Translatrix.getTranslationString("DeleteTable"),
            getEkitIcon("TableDelete"), CMD_TABLE_DELETE, this);
    Action actionTableRow = new CommandAction(Translatrix.getTranslationString("InsertTableRow"),
            getEkitIcon("InsertRow"), CMD_TABLE_ROW_INSERT, this);
    Action actionTableRowAfter = new CommandAction(Translatrix.getTranslationString("InsertTableRowAfter"),
            getEkitIcon("InsertRowAfter"), CMD_TABLE_ROW_INSERT_AFTER, this);
    Action actionTableCol = new CommandAction(Translatrix.getTranslationString("InsertTableColumn"),
            getEkitIcon("InsertColumn"), CMD_TABLE_COLUMN_INSERT, this);
    Action actionTableColAfter = new CommandAction(Translatrix.getTranslationString("InsertTableColumnAfter"),
            getEkitIcon("InsertColumnAfter"), CMD_TABLE_COLUMN_INSERT_AFTER, this);
    Action actionTableRowDel = new CommandAction(Translatrix.getTranslationString("DeleteTableRow"),
            getEkitIcon("DeleteRow"), CMD_TABLE_ROW_DELETE, this);
    Action actionTableColDel = new CommandAction(Translatrix.getTranslationString("DeleteTableColumn"),
            getEkitIcon("DeleteColumn"), CMD_TABLE_COLUMN_DELETE, this);
    Action actionTableColFmt = new CommandAction(Translatrix.getTranslationString("FormatTableColumn"),
            getEkitIcon("FormatColumn"), CMD_TABLE_COLUMN_FORMAT, this);
    actionTableButtonMenu = new ButtonMenuAction(Translatrix.getTranslationString("TableMenu"),
            getEkitIcon("TableMenu"), actionTableInsert, actionTableDelete, null, actionTableRow,
            actionTableRowAfter, actionTableCol, actionTableColAfter, null, actionTableRowDel,
            actionTableColDel, null, actionTableColFmt);

    /* Build the menus */
    /* FILE Menu */
    jMenuFile = new JMenu(Translatrix.getTranslationString("File"));
    htMenus.put(KEY_MENU_FILE, jMenuFile);
    JMenuItem jmiNew = new JMenuItem(Translatrix.getTranslationString("NewDocument"));
    jmiNew.setActionCommand(CMD_DOC_NEW);
    jmiNew.addActionListener(this);
    jmiNew.setAccelerator(KeyStroke.getKeyStroke('N', CTRLKEY, false));
    if (showMenuIcons) {
        jmiNew.setIcon(getEkitIcon("New"));
    }
    ;
    jMenuFile.add(jmiNew);
    JMenuItem jmiNewStyled = new JMenuItem(Translatrix.getTranslationString("NewStyledDocument"));
    jmiNewStyled.setActionCommand(CMD_DOC_NEW_STYLED);
    jmiNewStyled.addActionListener(this);
    if (showMenuIcons) {
        jmiNewStyled.setIcon(getEkitIcon("NewStyled"));
    }
    ;
    jMenuFile.add(jmiNewStyled);
    JMenuItem jmiOpenHTML = new JMenuItem(Translatrix.getTranslationString("OpenDocument") + menuDialog);
    jmiOpenHTML.setActionCommand(CMD_DOC_OPEN_HTML);
    jmiOpenHTML.addActionListener(this);
    jmiOpenHTML.setAccelerator(KeyStroke.getKeyStroke('O', CTRLKEY, false));
    if (showMenuIcons) {
        jmiOpenHTML.setIcon(getEkitIcon("Open"));
    }
    ;
    jMenuFile.add(jmiOpenHTML);
    JMenuItem jmiOpenCSS = new JMenuItem(Translatrix.getTranslationString("OpenStyle") + menuDialog);
    jmiOpenCSS.setActionCommand(CMD_DOC_OPEN_CSS);
    jmiOpenCSS.addActionListener(this);
    jMenuFile.add(jmiOpenCSS);
    jMenuFile.addSeparator();
    JMenuItem jmiSave = new JMenuItem(Translatrix.getTranslationString("Save"));
    jmiSave.setActionCommand(CMD_DOC_SAVE);
    jmiSave.addActionListener(this);
    jmiSave.setAccelerator(KeyStroke.getKeyStroke('S', CTRLKEY, false));
    if (showMenuIcons) {
        jmiSave.setIcon(getEkitIcon("Save"));
    }
    ;
    jMenuFile.add(jmiSave);
    JMenuItem jmiSaveAs = new JMenuItem(Translatrix.getTranslationString("SaveAs") + menuDialog);
    jmiSaveAs.setActionCommand(CMD_DOC_SAVE_AS);
    jmiSaveAs.addActionListener(this);
    jMenuFile.add(jmiSaveAs);
    JMenuItem jmiSaveBody = new JMenuItem(Translatrix.getTranslationString("SaveBody") + menuDialog);
    jmiSaveBody.setActionCommand(CMD_DOC_SAVE_BODY);
    jmiSaveBody.addActionListener(this);
    jMenuFile.add(jmiSaveBody);
    JMenuItem jmiSaveRTF = new JMenuItem(Translatrix.getTranslationString("SaveRTF") + menuDialog);
    jmiSaveRTF.setActionCommand(CMD_DOC_SAVE_RTF);
    jmiSaveRTF.addActionListener(this);
    jMenuFile.add(jmiSaveRTF);
    jMenuFile.addSeparator();
    JMenuItem jmiPrint = new JMenuItem(Translatrix.getTranslationString("Print"));
    jmiPrint.setActionCommand(CMD_DOC_PRINT);
    jmiPrint.addActionListener(this);
    jMenuFile.add(jmiPrint);
    jMenuFile.addSeparator();
    JMenuItem jmiSerialOut = new JMenuItem(Translatrix.getTranslationString("Serialize") + menuDialog);
    jmiSerialOut.setActionCommand(CMD_DOC_SERIALIZE_OUT);
    jmiSerialOut.addActionListener(this);
    jMenuFile.add(jmiSerialOut);
    JMenuItem jmiSerialIn = new JMenuItem(Translatrix.getTranslationString("ReadFromSer") + menuDialog);
    jmiSerialIn.setActionCommand(CMD_DOC_SERIALIZE_IN);
    jmiSerialIn.addActionListener(this);
    jMenuFile.add(jmiSerialIn);
    jMenuFile.addSeparator();
    JMenuItem jmiExit = new JMenuItem(Translatrix.getTranslationString("Exit"));
    jmiExit.setActionCommand(CMD_EXIT);
    jmiExit.addActionListener(this);
    jMenuFile.add(jmiExit);

    /* EDIT Menu */
    jMenuEdit = new JMenu(Translatrix.getTranslationString("Edit"));
    htMenus.put(KEY_MENU_EDIT, jMenuEdit);
    if (sysClipboard != null) {
        // System Clipboard versions of menu commands
        JMenuItem jmiCut = new JMenuItem(Translatrix.getTranslationString("Cut"));
        jmiCut.setActionCommand(CMD_CLIP_CUT);
        jmiCut.addActionListener(this);
        jmiCut.setAccelerator(KeyStroke.getKeyStroke('X', CTRLKEY, false));
        if (showMenuIcons) {
            jmiCut.setIcon(getEkitIcon("Cut"));
        }
        jMenuEdit.add(jmiCut);
        JMenuItem jmiCopy = new JMenuItem(Translatrix.getTranslationString("Copy"));
        jmiCopy.setActionCommand(CMD_CLIP_COPY);
        jmiCopy.addActionListener(this);
        jmiCopy.setAccelerator(KeyStroke.getKeyStroke('C', CTRLKEY, false));
        if (showMenuIcons) {
            jmiCopy.setIcon(getEkitIcon("Copy"));
        }
        jMenuEdit.add(jmiCopy);
        JMenuItem jmiPaste = new JMenuItem(Translatrix.getTranslationString("Paste"));
        jmiPaste.setActionCommand(CMD_CLIP_PASTE);
        jmiPaste.addActionListener(this);
        jmiPaste.setAccelerator(KeyStroke.getKeyStroke('V', CTRLKEY, false));
        if (showMenuIcons) {
            jmiPaste.setIcon(getEkitIcon("Paste"));
        }
        jMenuEdit.add(jmiPaste);
        JMenuItem jmiPasteX = new JMenuItem(Translatrix.getTranslationString("PasteUnformatted"));
        jmiPasteX.setActionCommand(CMD_CLIP_PASTE_PLAIN);
        jmiPasteX.addActionListener(this);
        jmiPasteX.setAccelerator(KeyStroke.getKeyStroke('V', CTRLKEY + KeyEvent.SHIFT_MASK, false));
        if (showMenuIcons) {
            jmiPasteX.setIcon(getEkitIcon("PasteUnformatted"));
        }
        jMenuEdit.add(jmiPasteX);
    } else {
        // DefaultEditorKit versions of menu commands
        JMenuItem jmiCut = new JMenuItem(new DefaultEditorKit.CutAction());
        jmiCut.setText(Translatrix.getTranslationString("Cut"));
        jmiCut.setAccelerator(KeyStroke.getKeyStroke('X', CTRLKEY, false));
        if (showMenuIcons) {
            jmiCut.setIcon(getEkitIcon("Cut"));
        }
        jMenuEdit.add(jmiCut);
        JMenuItem jmiCopy = new JMenuItem(new DefaultEditorKit.CopyAction());
        jmiCopy.setText(Translatrix.getTranslationString("Copy"));
        jmiCopy.setAccelerator(KeyStroke.getKeyStroke('C', CTRLKEY, false));
        if (showMenuIcons) {
            jmiCopy.setIcon(getEkitIcon("Copy"));
        }
        jMenuEdit.add(jmiCopy);
        JMenuItem jmiPaste = new JMenuItem(new DefaultEditorKit.PasteAction());
        jmiPaste.setText(Translatrix.getTranslationString("Paste"));
        jmiPaste.setAccelerator(KeyStroke.getKeyStroke('V', CTRLKEY, false));
        if (showMenuIcons) {
            jmiPaste.setIcon(getEkitIcon("Paste"));
        }
        jMenuEdit.add(jmiPaste);
        JMenuItem jmiPasteX = new JMenuItem(Translatrix.getTranslationString("PasteUnformatted"));
        jmiPasteX.setActionCommand(CMD_CLIP_PASTE_PLAIN);
        jmiPasteX.addActionListener(this);
        jmiPasteX.setAccelerator(KeyStroke.getKeyStroke('V', CTRLKEY + KeyEvent.SHIFT_MASK, false));
        if (showMenuIcons) {
            jmiPasteX.setIcon(getEkitIcon("PasteUnformatted"));
        }
        jMenuEdit.add(jmiPasteX);
    }
    jMenuEdit.addSeparator();
    JMenuItem jmiUndo = new JMenuItem(undoAction);
    jmiUndo.setAccelerator(KeyStroke.getKeyStroke('Z', CTRLKEY, false));
    if (showMenuIcons) {
        jmiUndo.setIcon(getEkitIcon("Undo"));
    }
    jMenuEdit.add(jmiUndo);
    JMenuItem jmiRedo = new JMenuItem(redoAction);
    jmiRedo.setAccelerator(KeyStroke.getKeyStroke('Y', CTRLKEY, false));
    if (showMenuIcons) {
        jmiRedo.setIcon(getEkitIcon("Redo"));
    }
    jMenuEdit.add(jmiRedo);
    jMenuEdit.addSeparator();
    JMenuItem jmiSelAll = new JMenuItem((Action) actions.get(DefaultEditorKit.selectAllAction));
    jmiSelAll.setText(Translatrix.getTranslationString("SelectAll"));
    jmiSelAll.setAccelerator(KeyStroke.getKeyStroke('A', CTRLKEY, false));
    jMenuEdit.add(jmiSelAll);
    JMenuItem jmiSelPara = new JMenuItem((Action) actions.get(DefaultEditorKit.selectParagraphAction));
    jmiSelPara.setText(Translatrix.getTranslationString("SelectParagraph"));
    jMenuEdit.add(jmiSelPara);
    JMenuItem jmiSelLine = new JMenuItem((Action) actions.get(DefaultEditorKit.selectLineAction));
    jmiSelLine.setText(Translatrix.getTranslationString("SelectLine"));
    jMenuEdit.add(jmiSelLine);
    JMenuItem jmiSelWord = new JMenuItem((Action) actions.get(DefaultEditorKit.selectWordAction));
    jmiSelWord.setText(Translatrix.getTranslationString("SelectWord"));
    jMenuEdit.add(jmiSelWord);
    jMenuEdit.addSeparator();
    JMenu jMenuEnterKey = new JMenu(Translatrix.getTranslationString("EnterKeyMenu"));
    jcbmiEnterKeyParag = new JCheckBoxMenuItem(Translatrix.getTranslationString("EnterKeyParag"),
            !enterIsBreak);
    jcbmiEnterKeyParag.setActionCommand(CMD_ENTER_PARAGRAPH);
    jcbmiEnterKeyParag.addActionListener(this);
    jMenuEnterKey.add(jcbmiEnterKeyParag);
    jcbmiEnterKeyBreak = new JCheckBoxMenuItem(Translatrix.getTranslationString("EnterKeyBreak"), enterIsBreak);
    jcbmiEnterKeyBreak.setActionCommand(CMD_ENTER_BREAK);
    jcbmiEnterKeyBreak.addActionListener(this);
    jMenuEnterKey.add(jcbmiEnterKeyBreak);
    jMenuEdit.add(jMenuEnterKey);

    /* VIEW Menu */
    jMenuView = new JMenu(Translatrix.getTranslationString("View"));
    htMenus.put(KEY_MENU_VIEW, jMenuView);
    if (includeToolBar) {
        if (multiBar) {
            jMenuToolbars = new JMenu(Translatrix.getTranslationString("ViewToolbars"));

            jcbmiViewToolbarMain = new JCheckBoxMenuItem(Translatrix.getTranslationString("ViewToolbarMain"),
                    false);
            jcbmiViewToolbarMain.setActionCommand(CMD_TOGGLE_TOOLBAR_MAIN);
            jcbmiViewToolbarMain.addActionListener(this);
            jMenuToolbars.add(jcbmiViewToolbarMain);

            jcbmiViewToolbarFormat = new JCheckBoxMenuItem(
                    Translatrix.getTranslationString("ViewToolbarFormat"), false);
            jcbmiViewToolbarFormat.setActionCommand(CMD_TOGGLE_TOOLBAR_FORMAT);
            jcbmiViewToolbarFormat.addActionListener(this);
            jMenuToolbars.add(jcbmiViewToolbarFormat);

            jcbmiViewToolbarStyles = new JCheckBoxMenuItem(
                    Translatrix.getTranslationString("ViewToolbarStyles"), false);
            jcbmiViewToolbarStyles.setActionCommand(CMD_TOGGLE_TOOLBAR_STYLES);
            jcbmiViewToolbarStyles.addActionListener(this);
            jMenuToolbars.add(jcbmiViewToolbarStyles);

            jMenuView.add(jMenuToolbars);
        } else {
            jcbmiViewToolbar = new JCheckBoxMenuItem(Translatrix.getTranslationString("ViewToolbar"), false);
            jcbmiViewToolbar.setActionCommand(CMD_TOGGLE_TOOLBAR_SINGLE);
            jcbmiViewToolbar.addActionListener(this);

            jMenuView.add(jcbmiViewToolbar);
        }
    }
    jcbmiViewSource = new JCheckBoxMenuItem(Translatrix.getTranslationString("ViewSource"), false);
    jcbmiViewSource.setActionCommand(CMD_TOGGLE_SOURCE_VIEW);
    jcbmiViewSource.addActionListener(this);
    jMenuView.add(jcbmiViewSource);

    /* FONT Menu */
    jMenuFont = new JMenu(Translatrix.getTranslationString("Font"));
    htMenus.put(KEY_MENU_FONT, jMenuFont);
    JMenuItem jmiBold = new JMenuItem(actionFontBold);
    jmiBold.setText(Translatrix.getTranslationString("FontBold"));
    jmiBold.setAccelerator(KeyStroke.getKeyStroke('B', CTRLKEY, false));
    if (showMenuIcons) {
        jmiBold.setIcon(getEkitIcon("Bold"));
    }
    jMenuFont.add(jmiBold);
    JMenuItem jmiItalic = new JMenuItem(actionFontItalic);
    jmiItalic.setText(Translatrix.getTranslationString("FontItalic"));
    jmiItalic.setAccelerator(KeyStroke.getKeyStroke('I', CTRLKEY, false));
    if (showMenuIcons) {
        jmiItalic.setIcon(getEkitIcon("Italic"));
    }
    jMenuFont.add(jmiItalic);
    JMenuItem jmiUnderline = new JMenuItem(actionFontUnderline);
    jmiUnderline.setText(Translatrix.getTranslationString("FontUnderline"));
    jmiUnderline.setAccelerator(KeyStroke.getKeyStroke('U', CTRLKEY, false));
    if (showMenuIcons) {
        jmiUnderline.setIcon(getEkitIcon("Underline"));
    }
    jMenuFont.add(jmiUnderline);
    JMenuItem jmiStrike = new JMenuItem(actionFontStrike);
    jmiStrike.setText(Translatrix.getTranslationString("FontStrike"));
    if (showMenuIcons) {
        jmiStrike.setIcon(getEkitIcon("Strike"));
    }
    jMenuFont.add(jmiStrike);
    JMenuItem jmiSupscript = new JMenuItem(actionFontSuperscript);
    if (showMenuIcons) {
        jmiSupscript.setIcon(getEkitIcon("Super"));
    }
    jMenuFont.add(jmiSupscript);
    JMenuItem jmiSubscript = new JMenuItem(actionFontSubscript);
    if (showMenuIcons) {
        jmiSubscript.setIcon(getEkitIcon("Sub"));
    }
    jMenuFont.add(jmiSubscript);
    jMenuFont.addSeparator();
    jMenuFont.add(
            new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("FormatBig"), HTML.Tag.BIG)));
    jMenuFont.add(new JMenuItem(
            new FormatAction(this, Translatrix.getTranslationString("FormatSmall"), HTML.Tag.SMALL)));
    JMenu jMenuFontSize = new JMenu(Translatrix.getTranslationString("FontSize"));
    jMenuFontSize.add(new JMenuItem(
            new StyledEditorKit.FontSizeAction(Translatrix.getTranslationString("FontSize1"), 8)));
    jMenuFontSize.add(new JMenuItem(
            new StyledEditorKit.FontSizeAction(Translatrix.getTranslationString("FontSize2"), 10)));
    jMenuFontSize.add(new JMenuItem(
            new StyledEditorKit.FontSizeAction(Translatrix.getTranslationString("FontSize3"), 12)));
    jMenuFontSize.add(new JMenuItem(
            new StyledEditorKit.FontSizeAction(Translatrix.getTranslationString("FontSize4"), 14)));
    jMenuFontSize.add(new JMenuItem(
            new StyledEditorKit.FontSizeAction(Translatrix.getTranslationString("FontSize5"), 18)));
    jMenuFontSize.add(new JMenuItem(
            new StyledEditorKit.FontSizeAction(Translatrix.getTranslationString("FontSize6"), 24)));
    jMenuFontSize.add(new JMenuItem(
            new StyledEditorKit.FontSizeAction(Translatrix.getTranslationString("FontSize7"), 32)));
    jMenuFont.add(jMenuFontSize);
    jMenuFont.addSeparator();
    JMenu jMenuFontSub = new JMenu(Translatrix.getTranslationString("Font"));
    JMenuItem jmiSelectFont = new JMenuItem(actionSelectFont);
    jmiSelectFont.setText(Translatrix.getTranslationString("FontSelect") + menuDialog);
    if (showMenuIcons) {
        jmiSelectFont.setIcon(getEkitIcon("FontFaces"));
    }
    jMenuFontSub.add(jmiSelectFont);
    JMenuItem jmiSerif = new JMenuItem((Action) actions.get("font-family-Serif"));
    jmiSerif.setText(Translatrix.getTranslationString("FontSerif"));
    jMenuFontSub.add(jmiSerif);
    JMenuItem jmiSansSerif = new JMenuItem((Action) actions.get("font-family-SansSerif"));
    jmiSansSerif.setText(Translatrix.getTranslationString("FontSansserif"));
    jMenuFontSub.add(jmiSansSerif);
    JMenuItem jmiMonospaced = new JMenuItem((Action) actions.get("font-family-Monospaced"));
    jmiMonospaced.setText(Translatrix.getTranslationString("FontMonospaced"));
    jMenuFontSub.add(jmiMonospaced);
    jMenuFont.add(jMenuFontSub);
    jMenuFont.addSeparator();
    JMenu jMenuFontColor = new JMenu(Translatrix.getTranslationString("Color"));
    Hashtable<String, String> customAttr = new Hashtable<String, String>();
    customAttr.put("color", "black");
    jMenuFontColor.add(new JMenuItem(new CustomAction(this,
            Translatrix.getTranslationString("CustomColor") + menuDialog, HTML.Tag.FONT, customAttr)));
    jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(
            Translatrix.getTranslationString("ColorAqua"), new Color(0, 255, 255))));
    jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(
            Translatrix.getTranslationString("ColorBlack"), new Color(0, 0, 0))));
    jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(
            Translatrix.getTranslationString("ColorBlue"), new Color(0, 0, 255))));
    jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(
            Translatrix.getTranslationString("ColorFuschia"), new Color(255, 0, 255))));
    jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(
            Translatrix.getTranslationString("ColorGray"), new Color(128, 128, 128))));
    jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(
            Translatrix.getTranslationString("ColorGreen"), new Color(0, 128, 0))));
    jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(
            Translatrix.getTranslationString("ColorLime"), new Color(0, 255, 0))));
    jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(
            Translatrix.getTranslationString("ColorMaroon"), new Color(128, 0, 0))));
    jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(
            Translatrix.getTranslationString("ColorNavy"), new Color(0, 0, 128))));
    jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(
            Translatrix.getTranslationString("ColorOlive"), new Color(128, 128, 0))));
    jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(
            Translatrix.getTranslationString("ColorPurple"), new Color(128, 0, 128))));
    jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(
            Translatrix.getTranslationString("ColorRed"), new Color(255, 0, 0))));
    jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(
            Translatrix.getTranslationString("ColorSilver"), new Color(192, 192, 192))));
    jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(
            Translatrix.getTranslationString("ColorTeal"), new Color(0, 128, 128))));
    jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(
            Translatrix.getTranslationString("ColorWhite"), new Color(255, 255, 255))));
    jMenuFontColor.add(new JMenuItem(new StyledEditorKit.ForegroundAction(
            Translatrix.getTranslationString("ColorYellow"), new Color(255, 255, 0))));
    jMenuFont.add(jMenuFontColor);

    /* FORMAT Menu */
    jMenuFormat = new JMenu(Translatrix.getTranslationString("Format"));
    htMenus.put(KEY_MENU_FORMAT, jMenuFormat);
    JMenuItem jmiClearFormat = new JMenuItem(actionClearFormat);
    jMenuFormat.add(jmiClearFormat);
    jMenuFormat.addSeparator();
    JMenu jMenuFormatAlign = new JMenu(Translatrix.getTranslationString("Align"));
    JMenuItem jmiAlignLeft = new JMenuItem(actionAlignLeft);
    if (showMenuIcons) {
        jmiAlignLeft.setIcon(getEkitIcon("AlignLeft"));
    }
    ;
    jMenuFormatAlign.add(jmiAlignLeft);
    JMenuItem jmiAlignCenter = new JMenuItem(actionAlignCenter);
    if (showMenuIcons) {
        jmiAlignCenter.setIcon(getEkitIcon("AlignCenter"));
    }
    ;
    jMenuFormatAlign.add(jmiAlignCenter);
    JMenuItem jmiAlignRight = new JMenuItem(actionAlignRight);
    if (showMenuIcons) {
        jmiAlignRight.setIcon(getEkitIcon("AlignRight"));
    }
    ;
    jMenuFormatAlign.add(jmiAlignRight);
    JMenuItem jmiAlignJustified = new JMenuItem(actionAlignJustified);
    if (showMenuIcons) {
        jmiAlignJustified.setIcon(getEkitIcon("AlignJustified"));
    }
    ;
    jMenuFormatAlign.add(jmiAlignJustified);
    jMenuFormat.add(jMenuFormatAlign);
    jMenuFormat.addSeparator();
    JMenu jMenuFormatHeading = new JMenu(Translatrix.getTranslationString("Heading"));
    jMenuFormatHeading.add(
            new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("Heading1"), HTML.Tag.H1)));
    jMenuFormatHeading.add(
            new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("Heading2"), HTML.Tag.H2)));
    jMenuFormatHeading.add(
            new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("Heading3"), HTML.Tag.H3)));
    jMenuFormatHeading.add(
            new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("Heading4"), HTML.Tag.H4)));
    jMenuFormatHeading.add(
            new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("Heading5"), HTML.Tag.H5)));
    jMenuFormatHeading.add(
            new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("Heading6"), HTML.Tag.H6)));
    jMenuFormat.add(jMenuFormatHeading);
    jMenuFormat.addSeparator();
    JMenuItem jmiUList = new JMenuItem(actionListUnordered);
    if (showMenuIcons) {
        jmiUList.setIcon(getEkitIcon("UList"));
    }
    jMenuFormat.add(jmiUList);
    JMenuItem jmiOList = new JMenuItem(actionListOrdered);
    if (showMenuIcons) {
        jmiOList.setIcon(getEkitIcon("OList"));
    }
    jMenuFormat.add(jmiOList);
    jMenuFormat.add(
            new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("ListItem"), HTML.Tag.LI)));
    jMenuFormat.addSeparator();
    jMenuFormat.add(new JMenuItem(
            new FormatAction(this, Translatrix.getTranslationString("FormatBlockquote"), HTML.Tag.BLOCKQUOTE)));
    jMenuFormat.add(
            new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("FormatPre"), HTML.Tag.PRE)));
    jMenuFormat.add(new JMenuItem(
            new FormatAction(this, Translatrix.getTranslationString("FormatStrong"), HTML.Tag.STRONG)));
    jMenuFormat.add(new JMenuItem(
            new FormatAction(this, Translatrix.getTranslationString("FormatEmphasis"), HTML.Tag.EM)));
    jMenuFormat.add(
            new JMenuItem(new FormatAction(this, Translatrix.getTranslationString("FormatTT"), HTML.Tag.TT)));
    jMenuFormat.add(new JMenuItem(
            new FormatAction(this, Translatrix.getTranslationString("FormatSpan"), HTML.Tag.SPAN)));

    /* INSERT Menu */
    jMenuInsert = new JMenu(Translatrix.getTranslationString("Insert"));
    htMenus.put(KEY_MENU_INSERT, jMenuInsert);
    JMenuItem jmiInsertAnchor = new JMenuItem(actionInsertAnchor);
    if (showMenuIcons) {
        jmiInsertAnchor.setIcon(getEkitIcon("Anchor"));
    }
    ;
    jMenuInsert.add(jmiInsertAnchor);
    JMenuItem jmiBreak = new JMenuItem(Translatrix.getTranslationString("InsertBreak"));
    jmiBreak.setActionCommand(CMD_INSERT_BREAK);
    jmiBreak.addActionListener(this);
    jmiBreak.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_MASK, false));
    jMenuInsert.add(jmiBreak);
    JMenuItem jmiNBSP = new JMenuItem(Translatrix.getTranslationString("InsertNBSP"));
    jmiNBSP.setActionCommand(CMD_INSERT_NBSP);
    jmiNBSP.addActionListener(this);
    jmiNBSP.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, KeyEvent.SHIFT_MASK, false));
    jMenuInsert.add(jmiNBSP);
    JMenu jMenuUnicode = new JMenu(Translatrix.getTranslationString("InsertUnicodeCharacter"));
    if (showMenuIcons) {
        jMenuUnicode.setIcon(getEkitIcon("Unicode"));
    }
    ;
    JMenuItem jmiUnicodeAll = new JMenuItem(
            Translatrix.getTranslationString("InsertUnicodeCharacterAll") + menuDialog);
    if (showMenuIcons) {
        jmiUnicodeAll.setIcon(getEkitIcon("Unicode"));
    }
    ;
    jmiUnicodeAll.setActionCommand(CMD_INSERT_UNICODE_CHAR);
    jmiUnicodeAll.addActionListener(this);
    jMenuUnicode.add(jmiUnicodeAll);
    JMenuItem jmiUnicodeMath = new JMenuItem(
            Translatrix.getTranslationString("InsertUnicodeCharacterMath") + menuDialog);
    if (showMenuIcons) {
        jmiUnicodeMath.setIcon(getEkitIcon("Math"));
    }
    ;
    jmiUnicodeMath.setActionCommand(CMD_INSERT_UNICODE_MATH);
    jmiUnicodeMath.addActionListener(this);
    jMenuUnicode.add(jmiUnicodeMath);
    JMenuItem jmiUnicodeDraw = new JMenuItem(
            Translatrix.getTranslationString("InsertUnicodeCharacterDraw") + menuDialog);
    if (showMenuIcons) {
        jmiUnicodeDraw.setIcon(getEkitIcon("Draw"));
    }
    ;
    jmiUnicodeDraw.setActionCommand(CMD_INSERT_UNICODE_DRAW);
    jmiUnicodeDraw.addActionListener(this);
    jMenuUnicode.add(jmiUnicodeDraw);
    JMenuItem jmiUnicodeDing = new JMenuItem(
            Translatrix.getTranslationString("InsertUnicodeCharacterDing") + menuDialog);
    jmiUnicodeDing.setActionCommand(CMD_INSERT_UNICODE_DING);
    jmiUnicodeDing.addActionListener(this);
    jMenuUnicode.add(jmiUnicodeDing);
    JMenuItem jmiUnicodeSigs = new JMenuItem(
            Translatrix.getTranslationString("InsertUnicodeCharacterSigs") + menuDialog);
    jmiUnicodeSigs.setActionCommand(CMD_INSERT_UNICODE_SIGS);
    jmiUnicodeSigs.addActionListener(this);
    jMenuUnicode.add(jmiUnicodeSigs);
    JMenuItem jmiUnicodeSpec = new JMenuItem(
            Translatrix.getTranslationString("InsertUnicodeCharacterSpec") + menuDialog);
    jmiUnicodeSpec.setActionCommand(CMD_INSERT_UNICODE_SPEC);
    jmiUnicodeSpec.addActionListener(this);
    jMenuUnicode.add(jmiUnicodeSpec);
    jMenuInsert.add(jMenuUnicode);
    JMenuItem jmiHRule = new JMenuItem(Translatrix.getTranslationString("InsertHorizontalRule"));
    jmiHRule.setActionCommand(CMD_INSERT_HR);
    jmiHRule.addActionListener(this);
    jMenuInsert.add(jmiHRule);
    jMenuInsert.addSeparator();
    if (!isParentApplet) {
        JMenuItem jmiImageLocal = new JMenuItem(
                Translatrix.getTranslationString("InsertLocalImage") + menuDialog);
        jmiImageLocal.setActionCommand(CMD_INSERT_IMAGE_LOCAL);
        jmiImageLocal.addActionListener(this);
        jMenuInsert.add(jmiImageLocal);
    }
    JMenuItem jmiImageURL = new JMenuItem(Translatrix.getTranslationString("InsertURLImage") + menuDialog);
    jmiImageURL.setActionCommand(CMD_INSERT_IMAGE_URL);
    jmiImageURL.addActionListener(this);
    jMenuInsert.add(jmiImageURL);

    /* TABLE Menu */
    jMenuTable = new JMenu(Translatrix.getTranslationString("Table"));
    htMenus.put(KEY_MENU_TABLE, jMenuTable);
    JMenuItem jmiTable = new JMenuItem(actionTableInsert);
    if (!showMenuIcons) {
        jmiTable.setIcon(null);
    }
    jMenuTable.add(jmiTable);
    jMenuTable.addSeparator();
    Action actionTableEdit = new CommandAction(Translatrix.getTranslationString("TableEdit") + menuDialog,
            getEkitIcon("TableEdit"), CMD_TABLE_EDIT, this);
    JMenuItem jmiEditTable = new JMenuItem(actionTableEdit);
    if (!showMenuIcons) {
        jmiEditTable.setIcon(null);
    }
    jMenuTable.add(jmiEditTable);
    Action actionCellEdit = new CommandAction(Translatrix.getTranslationString("TableCellEdit") + menuDialog,
            getEkitIcon("CellEdit"), CMD_TABLE_CELL_EDIT, this);
    JMenuItem jmiEditCell = new JMenuItem(actionCellEdit);
    if (!showMenuIcons) {
        jmiEditCell.setIcon(null);
    }
    jmiEditCell.setActionCommand(CMD_TABLE_CELL_EDIT);
    jmiEditCell.addActionListener(this);
    jMenuTable.add(jmiEditCell);
    jMenuTable.addSeparator();
    JMenuItem jmiTableRow = new JMenuItem(actionTableRow);
    if (!showMenuIcons) {
        jmiTableRow.setIcon(null);
    }
    jMenuTable.add(jmiTableRow);
    JMenuItem jmiTableCol = new JMenuItem(actionTableCol);
    if (!showMenuIcons) {
        jmiTableCol.setIcon(null);
    }
    jMenuTable.add(jmiTableCol);
    jMenuTable.addSeparator();
    JMenuItem jmiTableRowDel = new JMenuItem(actionTableRowDel);
    if (!showMenuIcons) {
        jmiTableRowDel.setIcon(null);
    }
    jMenuTable.add(jmiTableRowDel);
    JMenuItem jmiTableColDel = new JMenuItem(actionTableColDel);
    if (!showMenuIcons) {
        jmiTableColDel.setIcon(null);
    }
    jMenuTable.add(jmiTableColDel);

    /* FORMS Menu */
    jMenuForms = new JMenu(Translatrix.getTranslationString("Forms"));
    htMenus.put(KEY_MENU_FORMS, jMenuForms);
    JMenuItem jmiFormInsertForm = new JMenuItem(Translatrix.getTranslationString("FormInsertForm"));
    jmiFormInsertForm.setActionCommand(CMD_FORM_INSERT);
    jmiFormInsertForm.addActionListener(this);
    jMenuForms.add(jmiFormInsertForm);
    jMenuForms.addSeparator();
    JMenuItem jmiFormTextfield = new JMenuItem(Translatrix.getTranslationString("FormTextfield"));
    jmiFormTextfield.setActionCommand(CMD_FORM_TEXTFIELD);
    jmiFormTextfield.addActionListener(this);
    jMenuForms.add(jmiFormTextfield);
    JMenuItem jmiFormTextarea = new JMenuItem(Translatrix.getTranslationString("FormTextarea"));
    jmiFormTextarea.setActionCommand(CMD_FORM_TEXTAREA);
    jmiFormTextarea.addActionListener(this);
    jMenuForms.add(jmiFormTextarea);
    JMenuItem jmiFormCheckbox = new JMenuItem(Translatrix.getTranslationString("FormCheckbox"));
    jmiFormCheckbox.setActionCommand(CMD_FORM_CHECKBOX);
    jmiFormCheckbox.addActionListener(this);
    jMenuForms.add(jmiFormCheckbox);
    JMenuItem jmiFormRadio = new JMenuItem(Translatrix.getTranslationString("FormRadio"));
    jmiFormRadio.setActionCommand(CMD_FORM_RADIO);
    jmiFormRadio.addActionListener(this);
    jMenuForms.add(jmiFormRadio);
    JMenuItem jmiFormPassword = new JMenuItem(Translatrix.getTranslationString("FormPassword"));
    jmiFormPassword.setActionCommand(CMD_FORM_PASSWORD);
    jmiFormPassword.addActionListener(this);
    jMenuForms.add(jmiFormPassword);
    jMenuForms.addSeparator();
    JMenuItem jmiFormButton = new JMenuItem(Translatrix.getTranslationString("FormButton"));
    jmiFormButton.setActionCommand(CMD_FORM_BUTTON);
    jmiFormButton.addActionListener(this);
    jMenuForms.add(jmiFormButton);
    JMenuItem jmiFormButtonSubmit = new JMenuItem(Translatrix.getTranslationString("FormButtonSubmit"));
    jmiFormButtonSubmit.setActionCommand(CMD_FORM_SUBMIT);
    jmiFormButtonSubmit.addActionListener(this);
    jMenuForms.add(jmiFormButtonSubmit);
    JMenuItem jmiFormButtonReset = new JMenuItem(Translatrix.getTranslationString("FormButtonReset"));
    jmiFormButtonReset.setActionCommand(CMD_FORM_RESET);
    jmiFormButtonReset.addActionListener(this);
    jMenuForms.add(jmiFormButtonReset);

    /* TOOLS Menu */
    if (hasSpellChecker) {
        jMenuTools = new JMenu(Translatrix.getTranslationString("Tools"));
        htMenus.put(KEY_MENU_TOOLS, jMenuTools);
        JMenuItem jmiSpellcheck = new JMenuItem(Translatrix.getTranslationString("ToolSpellcheck"));
        jmiSpellcheck.setActionCommand(CMD_SPELLCHECK);
        jmiSpellcheck.addActionListener(this);
        jMenuTools.add(jmiSpellcheck);
    }

    /* SEARCH Menu */
    jMenuSearch = new JMenu(Translatrix.getTranslationString("Search"));
    htMenus.put(KEY_MENU_SEARCH, jMenuSearch);
    JMenuItem jmiFind = new JMenuItem(Translatrix.getTranslationString("SearchFind"));
    if (showMenuIcons) {
        jmiFind.setIcon(getEkitIcon("Find"));
    }
    ;
    jmiFind.setActionCommand(CMD_SEARCH_FIND);
    jmiFind.addActionListener(this);
    jmiFind.setAccelerator(KeyStroke.getKeyStroke('F', CTRLKEY, false));
    jMenuSearch.add(jmiFind);
    JMenuItem jmiFindAgain = new JMenuItem(Translatrix.getTranslationString("SearchFindAgain"));
    if (showMenuIcons) {
        jmiFindAgain.setIcon(getEkitIcon("FindAgain"));
    }
    ;
    jmiFindAgain.setActionCommand(CMD_SEARCH_FIND_AGAIN);
    jmiFindAgain.addActionListener(this);
    jmiFindAgain.setAccelerator(KeyStroke.getKeyStroke('G', CTRLKEY, false));
    jMenuSearch.add(jmiFindAgain);
    JMenuItem jmiReplace = new JMenuItem(Translatrix.getTranslationString("SearchReplace"));
    if (showMenuIcons) {
        jmiReplace.setIcon(getEkitIcon("Replace"));
    }
    ;
    jmiReplace.setActionCommand(CMD_SEARCH_REPLACE);
    jmiReplace.addActionListener(this);
    jmiReplace.setAccelerator(KeyStroke.getKeyStroke('R', CTRLKEY, false));
    jMenuSearch.add(jmiReplace);

    /* HELP Menu */
    jMenuHelp = new JMenu(Translatrix.getTranslationString("Help"));
    htMenus.put(KEY_MENU_HELP, jMenuHelp);
    JMenuItem jmiAbout = new JMenuItem(Translatrix.getTranslationString("About"));
    jmiAbout.setActionCommand(CMD_HELP_ABOUT);
    jmiAbout.addActionListener(this);
    jMenuHelp.add(jmiAbout);

    /* DEBUG Menu */
    jMenuDebug = new JMenu(Translatrix.getTranslationString("Debug"));
    htMenus.put(KEY_MENU_DEBUG, jMenuDebug);
    JMenuItem jmiDesc = new JMenuItem(Translatrix.getTranslationString("DescribeDoc"));
    jmiDesc.setActionCommand(CMD_DEBUG_DESCRIBE_DOC);
    jmiDesc.addActionListener(this);
    jMenuDebug.add(jmiDesc);
    JMenuItem jmiDescCSS = new JMenuItem(Translatrix.getTranslationString("DescribeCSS"));
    jmiDescCSS.setActionCommand(CMD_DEBUG_DESCRIBE_CSS);
    jmiDescCSS.addActionListener(this);
    jMenuDebug.add(jmiDescCSS);
    JMenuItem jmiTag = new JMenuItem(Translatrix.getTranslationString("WhatTags"));
    jmiTag.setActionCommand(CMD_DEBUG_CURRENT_TAGS);
    jmiTag.addActionListener(this);
    jMenuDebug.add(jmiTag);

    /* Create menubar and add menus */
    jMenuBar = new JMenuBar();
    jMenuBar.add(jMenuFile);
    jMenuBar.add(jMenuEdit);
    jMenuBar.add(jMenuView);
    jMenuBar.add(jMenuFont);
    jMenuBar.add(jMenuFormat);
    jMenuBar.add(jMenuSearch);
    jMenuBar.add(jMenuInsert);
    jMenuBar.add(jMenuTable);
    jMenuBar.add(jMenuForms);
    if (jMenuTools != null) {
        jMenuBar.add(jMenuTools);
    }
    jMenuBar.add(jMenuHelp);
    if (debugMode) {
        jMenuBar.add(jMenuDebug);
    }

    /* Create toolbar tool objects */
    jbtnNewHTML = new JButtonNoFocus(getEkitIcon("New"));
    jbtnNewHTML.setToolTipText(Translatrix.getTranslationString("NewDocument"));
    jbtnNewHTML.setActionCommand(CMD_DOC_NEW);
    jbtnNewHTML.addActionListener(this);
    htTools.put(KEY_TOOL_NEW, jbtnNewHTML);
    jbtnNewStyledHTML = new JButtonNoFocus(getEkitIcon("NewStyled"));
    jbtnNewStyledHTML.setToolTipText(Translatrix.getTranslationString("NewStyledDocument"));
    jbtnNewStyledHTML.setActionCommand(CMD_DOC_NEW_STYLED);
    jbtnNewStyledHTML.addActionListener(this);
    htTools.put(KEY_TOOL_NEWSTYLED, jbtnNewStyledHTML);
    jbtnOpenHTML = new JButtonNoFocus(getEkitIcon("Open"));
    jbtnOpenHTML.setToolTipText(Translatrix.getTranslationString("OpenDocument"));
    jbtnOpenHTML.setActionCommand(CMD_DOC_OPEN_HTML);
    jbtnOpenHTML.addActionListener(this);
    htTools.put(KEY_TOOL_OPEN, jbtnOpenHTML);
    jbtnSaveHTML = new JButtonNoFocus(getEkitIcon("Save"));
    jbtnSaveHTML.setToolTipText(Translatrix.getTranslationString("SaveDocument"));
    jbtnSaveHTML.setActionCommand(CMD_DOC_SAVE_AS);
    jbtnSaveHTML.addActionListener(this);
    htTools.put(KEY_TOOL_SAVE, jbtnSaveHTML);
    jbtnPrint = new JButtonNoFocus(getEkitIcon("Print"));
    jbtnPrint.setToolTipText(Translatrix.getTranslationString("PrintDocument"));
    jbtnPrint.setActionCommand(CMD_DOC_PRINT);
    jbtnPrint.addActionListener(this);
    htTools.put(KEY_TOOL_PRINT, jbtnPrint);
    // jbtnCut = new JButtonNoFocus(new DefaultEditorKit.CutAction());
    jbtnCut = new JButtonNoFocus();
    jbtnCut.setActionCommand(CMD_CLIP_CUT);
    jbtnCut.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            EkitCore.this.actionPerformed(evt);
        }
    });
    jbtnCut.setIcon(getEkitIcon("Cut"));
    jbtnCut.setText(null);
    jbtnCut.setToolTipText(Translatrix.getTranslationString("Cut"));
    htTools.put(KEY_TOOL_CUT, jbtnCut);
    // jbtnCopy = new JButtonNoFocus(new DefaultEditorKit.CopyAction());
    jbtnCopy = new JButtonNoFocus();
    jbtnCopy.setActionCommand(CMD_CLIP_COPY);
    jbtnCopy.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            EkitCore.this.actionPerformed(evt);
        }
    });
    jbtnCopy.setIcon(getEkitIcon("Copy"));
    jbtnCopy.setText(null);
    jbtnCopy.setToolTipText(Translatrix.getTranslationString("Copy"));
    htTools.put(KEY_TOOL_COPY, jbtnCopy);
    // jbtnPaste = new JButtonNoFocus(new DefaultEditorKit.PasteAction());
    jbtnPaste = new JButtonNoFocus();
    jbtnPaste.setActionCommand(CMD_CLIP_PASTE);
    jbtnPaste.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            EkitCore.this.actionPerformed(evt);
        }
    });
    jbtnPaste.setIcon(getEkitIcon("Paste"));
    jbtnPaste.setText(null);
    jbtnPaste.setToolTipText(Translatrix.getTranslationString("Paste"));
    htTools.put(KEY_TOOL_PASTE, jbtnPaste);
    jbtnPasteX = new JButtonNoFocus();
    jbtnPasteX.setActionCommand(CMD_CLIP_PASTE_PLAIN);
    jbtnPasteX.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            EkitCore.this.actionPerformed(evt);
        }
    });
    jbtnPasteX.setIcon(getEkitIcon("PasteUnformatted"));
    jbtnPasteX.setText(null);
    jbtnPasteX.setToolTipText(Translatrix.getTranslationString("PasteUnformatted"));
    htTools.put(KEY_TOOL_PASTEX, jbtnPasteX);
    jbtnUndo = new JButtonNoFocus(undoAction);
    jbtnUndo.setIcon(getEkitIcon("Undo"));
    jbtnUndo.setText(null);
    jbtnUndo.setToolTipText(Translatrix.getTranslationString("Undo"));
    htTools.put(KEY_TOOL_UNDO, jbtnUndo);
    jbtnRedo = new JButtonNoFocus(redoAction);
    jbtnRedo.setIcon(getEkitIcon("Redo"));
    jbtnRedo.setText(null);
    jbtnRedo.setToolTipText(Translatrix.getTranslationString("Redo"));
    htTools.put(KEY_TOOL_REDO, jbtnRedo);
    jbtnBold = new JButtonNoFocus(actionFontBold);
    jbtnBold.setIcon(getEkitIcon("Bold"));
    jbtnBold.setText(null);
    jbtnBold.setToolTipText(Translatrix.getTranslationString("FontBold"));
    htTools.put(KEY_TOOL_BOLD, jbtnBold);
    jbtnItalic = new JButtonNoFocus(actionFontItalic);
    jbtnItalic.setIcon(getEkitIcon("Italic"));
    jbtnItalic.setText(null);
    jbtnItalic.setToolTipText(Translatrix.getTranslationString("FontItalic"));
    htTools.put(KEY_TOOL_ITALIC, jbtnItalic);
    jbtnUnderline = new JButtonNoFocus(actionFontUnderline);
    jbtnUnderline.setIcon(getEkitIcon("Underline"));
    jbtnUnderline.setText(null);
    jbtnUnderline.setToolTipText(Translatrix.getTranslationString("FontUnderline"));
    htTools.put(KEY_TOOL_UNDERLINE, jbtnUnderline);
    jbtnStrike = new JButtonNoFocus(actionFontStrike);
    jbtnStrike.setIcon(getEkitIcon("Strike"));
    jbtnStrike.setText(null);
    jbtnStrike.setToolTipText(Translatrix.getTranslationString("FontStrike"));
    htTools.put(KEY_TOOL_STRIKE, jbtnStrike);
    jbtnSuperscript = new JButtonNoFocus(actionFontSuperscript);
    jbtnSuperscript.setIcon(getEkitIcon("Super"));
    jbtnSuperscript.setText(null);
    jbtnSuperscript.setToolTipText(Translatrix.getTranslationString("FontSuperscript"));
    htTools.put(KEY_TOOL_SUPER, jbtnSuperscript);
    jbtnSubscript = new JButtonNoFocus(actionFontSubscript);
    jbtnSubscript.setIcon(getEkitIcon("Sub"));
    jbtnSubscript.setText(null);
    jbtnSubscript.setToolTipText(Translatrix.getTranslationString("FontSubscript"));
    htTools.put(KEY_TOOL_SUB, jbtnSubscript);
    jbtnUList = new JButtonNoFocus(actionListUnordered);
    jbtnUList.setIcon(getEkitIcon("UList"));
    jbtnUList.setText(null);
    jbtnUList.setToolTipText(Translatrix.getTranslationString("ListUnordered"));
    htTools.put(KEY_TOOL_ULIST, jbtnUList);
    jbtnOList = new JButtonNoFocus(actionListOrdered);
    jbtnOList.setIcon(getEkitIcon("OList"));
    jbtnOList.setText(null);
    jbtnOList.setToolTipText(Translatrix.getTranslationString("ListOrdered"));
    htTools.put(KEY_TOOL_OLIST, jbtnOList);
    jbtnAlignLeft = new JButtonNoFocus(actionAlignLeft);
    jbtnAlignLeft.setIcon(getEkitIcon("AlignLeft"));
    jbtnAlignLeft.setText(null);
    jbtnAlignLeft.setToolTipText(Translatrix.getTranslationString("AlignLeft"));
    htTools.put(KEY_TOOL_ALIGNL, jbtnAlignLeft);
    jbtnAlignCenter = new JButtonNoFocus(actionAlignCenter);
    jbtnAlignCenter.setIcon(getEkitIcon("AlignCenter"));
    jbtnAlignCenter.setText(null);
    jbtnAlignCenter.setToolTipText(Translatrix.getTranslationString("AlignCenter"));
    htTools.put(KEY_TOOL_ALIGNC, jbtnAlignCenter);
    jbtnAlignRight = new JButtonNoFocus(actionAlignRight);
    jbtnAlignRight.setIcon(getEkitIcon("AlignRight"));
    jbtnAlignRight.setText(null);
    jbtnAlignRight.setToolTipText(Translatrix.getTranslationString("AlignRight"));
    htTools.put(KEY_TOOL_ALIGNR, jbtnAlignRight);
    jbtnAlignJustified = new JButtonNoFocus(actionAlignJustified);
    jbtnAlignJustified.setIcon(getEkitIcon("AlignJustified"));
    jbtnAlignJustified.setText(null);
    jbtnAlignJustified.setToolTipText(Translatrix.getTranslationString("AlignJustified"));
    htTools.put(KEY_TOOL_ALIGNJ, jbtnAlignJustified);
    jbtnUnicode = new JButtonNoFocus();
    jbtnUnicode.setActionCommand(CMD_INSERT_UNICODE_CHAR);
    jbtnUnicode.addActionListener(this);
    jbtnUnicode.setIcon(getEkitIcon("Unicode"));
    jbtnUnicode.setText(null);
    jbtnUnicode.setToolTipText(Translatrix.getTranslationString("ToolUnicode"));
    htTools.put(KEY_TOOL_UNICODE, jbtnUnicode);
    jbtnUnicodeMath = new JButtonNoFocus();
    jbtnUnicodeMath.setActionCommand(CMD_INSERT_UNICODE_MATH);
    jbtnUnicodeMath.addActionListener(this);
    jbtnUnicodeMath.setIcon(getEkitIcon("Math"));
    jbtnUnicodeMath.setText(null);
    jbtnUnicodeMath.setToolTipText(Translatrix.getTranslationString("ToolUnicodeMath"));
    htTools.put(KEY_TOOL_UNIMATH, jbtnUnicodeMath);
    jbtnFind = new JButtonNoFocus();
    jbtnFind.setActionCommand(CMD_SEARCH_FIND);
    jbtnFind.addActionListener(this);
    jbtnFind.setIcon(getEkitIcon("Find"));
    jbtnFind.setText(null);
    jbtnFind.setToolTipText(Translatrix.getTranslationString("SearchFind"));
    htTools.put(KEY_TOOL_FIND, jbtnFind);
    jbtnAnchor = new JButtonNoFocus(actionInsertAnchor);
    jbtnAnchor.setIcon(getEkitIcon("Anchor"));
    jbtnAnchor.setText(null);
    jbtnAnchor.setToolTipText(Translatrix.getTranslationString("ToolAnchor"));
    htTools.put(KEY_TOOL_ANCHOR, jbtnAnchor);
    jtbtnViewSource = new JToggleButtonNoFocus(getEkitIcon("Source"));
    jtbtnViewSource.setText(null);
    jtbtnViewSource.setToolTipText(Translatrix.getTranslationString("ViewSource"));
    jtbtnViewSource.setActionCommand(CMD_TOGGLE_SOURCE_VIEW);
    jtbtnViewSource.addActionListener(this);
    jtbtnViewSource.setPreferredSize(jbtnAnchor.getPreferredSize());
    jtbtnViewSource.setMinimumSize(jbtnAnchor.getMinimumSize());
    jtbtnViewSource.setMaximumSize(jbtnAnchor.getMaximumSize());
    htTools.put(KEY_TOOL_SOURCE, jtbtnViewSource);
    jcmbStyleSelector = new JComboBoxNoFocus();
    jcmbStyleSelector.setToolTipText(Translatrix.getTranslationString("PickCSSStyle"));
    jcmbStyleSelector.setAction(new StylesAction(jcmbStyleSelector));
    htTools.put(KEY_TOOL_STYLES, jcmbStyleSelector);
    String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    Vector<String> vcFontnames = new Vector<String>(fonts.length + 1);
    vcFontnames.add(Translatrix.getTranslationString("SelectorToolFontsDefaultFont"));
    for (String fontname : fonts) {
        vcFontnames.add(fontname);
    }
    Collections.sort(vcFontnames);
    jcmbFontSelector = new JComboBoxNoFocus(vcFontnames);
    jcmbFontSelector.setAction(new SetFontFamilyAction(this, "[EKITFONTSELECTOR]"));
    htTools.put(KEY_TOOL_FONTS, jcmbFontSelector);
    jbtnInsertTable = new JButtonNoFocus();
    jbtnInsertTable.setActionCommand(CMD_TABLE_INSERT);
    jbtnInsertTable.addActionListener(this);
    jbtnInsertTable.setIcon(getEkitIcon("TableCreate"));
    jbtnInsertTable.setText(null);
    jbtnInsertTable.setToolTipText(Translatrix.getTranslationString("InsertTable"));
    htTools.put(KEY_TOOL_INSTABLE, jbtnInsertTable);
    jbtnEditTable = new JButtonNoFocus();
    jbtnEditTable.setActionCommand(CMD_TABLE_EDIT);
    jbtnEditTable.addActionListener(this);
    jbtnEditTable.setIcon(getEkitIcon("TableEdit"));
    jbtnEditTable.setText(null);
    jbtnEditTable.setToolTipText(Translatrix.getTranslationString("TableEdit"));
    htTools.put(KEY_TOOL_EDITTABLE, jbtnEditTable);
    jbtnEditCell = new JButtonNoFocus();
    jbtnEditCell.setActionCommand(CMD_TABLE_CELL_EDIT);
    jbtnEditCell.addActionListener(this);
    jbtnEditCell.setIcon(getEkitIcon("CellEdit"));
    jbtnEditCell.setText(null);
    jbtnEditCell.setToolTipText(Translatrix.getTranslationString("TableCellEdit"));
    htTools.put(KEY_TOOL_EDITCELL, jbtnEditCell);
    jbtnInsertRow = new JButtonNoFocus();
    jbtnInsertRow.setActionCommand(CMD_TABLE_ROW_INSERT);
    jbtnInsertRow.addActionListener(this);
    jbtnInsertRow.setIcon(getEkitIcon("InsertRow"));
    jbtnInsertRow.setText(null);
    jbtnInsertRow.setToolTipText(Translatrix.getTranslationString("InsertTableRow"));
    htTools.put(KEY_TOOL_INSERTROW, jbtnInsertRow);
    jbtnInsertColumn = new JButtonNoFocus();
    jbtnInsertColumn.setActionCommand(CMD_TABLE_COLUMN_INSERT);
    jbtnInsertColumn.addActionListener(this);
    jbtnInsertColumn.setIcon(getEkitIcon("InsertColumn"));
    jbtnInsertColumn.setText(null);
    jbtnInsertColumn.setToolTipText(Translatrix.getTranslationString("InsertTableColumn"));
    htTools.put(KEY_TOOL_INSERTCOL, jbtnInsertColumn);
    jbtnDeleteRow = new JButtonNoFocus();
    jbtnDeleteRow.setActionCommand(CMD_TABLE_ROW_DELETE);
    jbtnDeleteRow.addActionListener(this);
    jbtnDeleteRow.setIcon(getEkitIcon("DeleteRow"));
    jbtnDeleteRow.setText(null);
    jbtnDeleteRow.setToolTipText(Translatrix.getTranslationString("DeleteTableRow"));
    htTools.put(KEY_TOOL_DELETEROW, jbtnDeleteRow);
    jbtnDeleteColumn = new JButtonNoFocus();
    jbtnDeleteColumn.setActionCommand(CMD_TABLE_COLUMN_DELETE);
    jbtnDeleteColumn.addActionListener(this);
    jbtnDeleteColumn.setIcon(getEkitIcon("DeleteColumn"));
    jbtnDeleteColumn.setText(null);
    jbtnDeleteColumn.setToolTipText(Translatrix.getTranslationString("DeleteTableColumn"));
    htTools.put(KEY_TOOL_DELETECOL, jbtnDeleteColumn);
    jbtnMaximize = new JButtonNoFocus();
    jbtnMaximize.setActionCommand(CMD_MAXIMIZE);
    jbtnMaximize.addActionListener(this);
    jbtnMaximize.setIcon(getEkitIcon("Maximize"));
    jbtnMaximize.setText(null);
    jbtnMaximize.setToolTipText(Translatrix.getTranslationString("Maximize"));
    htTools.put(KEY_TOOL_MAXIMIZE, jbtnMaximize);
    jbtnClearFormat = new JButtonNoFocus(actionClearFormat);
    jbtnClearFormat.setIcon(getEkitIcon("ClearFormat"));
    jbtnClearFormat.setText(null);
    jbtnClearFormat.setToolTipText(Translatrix.getTranslationString("ClearFormat"));
    htTools.put(KEY_TOOL_CLEAR_FORMAT, jbtnClearFormat);
    jbtnSpecialChar = new JButtonNoFocus(actionSpecialChar);
    jbtnSpecialChar.setIcon(getEkitIcon("SpecialChar"));
    jbtnSpecialChar.setText(null);
    jbtnSpecialChar.setToolTipText(Translatrix.getTranslationString("SpecialChar"));
    htTools.put(KEY_TOOL_SPECIAL_CHAR, jbtnSpecialChar);
    jbtnTableButtonMenu = new JButtonNoFocus(actionTableButtonMenu);
    jbtnTableButtonMenu.setText(null);
    htTools.put(KEY_TOOL_TABLE_MENU, jbtnTableButtonMenu);

    /* Create the toolbar */
    if (multiBar) {
        jToolBarMain = new JToolBar(JToolBar.HORIZONTAL);
        jToolBarMain.setFloatable(false);
        jToolBarFormat = new JToolBar(JToolBar.HORIZONTAL);
        jToolBarFormat.setFloatable(false);
        jToolBarStyles = new JToolBar(JToolBar.HORIZONTAL);
        jToolBarStyles.setFloatable(false);

        initializeMultiToolbars(toolbarSeq);

        // fix the weird size preference of toggle buttons
        jtbtnViewSource.setPreferredSize(jbtnAnchor.getPreferredSize());
        jtbtnViewSource.setMinimumSize(jbtnAnchor.getMinimumSize());
        jtbtnViewSource.setMaximumSize(jbtnAnchor.getMaximumSize());
    } else if (includeToolBar) {
        jToolBar = new JToolBar(JToolBar.HORIZONTAL);
        jToolBar.setFloatable(false);

        initializeSingleToolbar(toolbarSeq);

        // fix the weird size preference of toggle buttons
        jtbtnViewSource.setPreferredSize(jbtnAnchor.getPreferredSize());
        jtbtnViewSource.setMinimumSize(jbtnAnchor.getMinimumSize());
        jtbtnViewSource.setMaximumSize(jbtnAnchor.getMaximumSize());
    }

    /* Create the scroll area for the text pane */
    jspViewport = new JScrollPane(jtpMain);
    jspViewport.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    jspViewport.setPreferredSize(new Dimension(400, 400));
    jspViewport.setMinimumSize(new Dimension(32, 32));

    /* Create the scroll area for the source viewer */
    jspSource = new JScrollPane(jtpSource);
    jspSource.setPreferredSize(new Dimension(400, 100));
    jspSource.setMinimumSize(new Dimension(32, 32));

    displayPanel = new JPanel();
    displayPanel.setLayout(new CardLayout());
    displayPanel.add(jspViewport, PANEL_NAME_MAIN);
    displayPanel.add(jspSource, PANEL_NAME_SOURCE);
    if (showViewSource) {
        toggleSourceWindow();
    }

    registerDocumentStyles();

    tableCtl = new TableController(this);

    htmlDoc.setInlineEdit(inlineEdit);

    htmlDoc.addFilter(new HTMLTableDocumentFilter());

    // Inicializa documento pelos behaviors
    for (HTMLDocumentBehavior b : this.behaviors) {
        b.initializeDocument(jtpMain);
    }
    htmlDoc.getBehaviors().addAll(this.behaviors);

    /* Add the components to the app */
    this.setLayout(new BorderLayout());
    this.add(displayPanel, BorderLayout.CENTER);
}

From source file:com.nikonhacker.gui.EmulatorUI.java

@SuppressWarnings("MagicConstant")
protected JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    JMenuItem tmpMenuItem;

    //Set up the file menu.
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);/*w  w  w . j a v a 2s  .co m*/

    //load image
    for (int chip = 0; chip < 2; chip++) {
        loadMenuItem[chip] = new JMenuItem("Load " + Constants.CHIP_LABEL[chip] + " firmware image");
        if (chip == Constants.CHIP_FR)
            loadMenuItem[chip].setMnemonic(KEY_EVENT_LOAD);
        loadMenuItem[chip].setAccelerator(KeyStroke.getKeyStroke(KEY_EVENT_LOAD, KEY_CHIP_MODIFIER[chip]));
        loadMenuItem[chip].setActionCommand(COMMAND_IMAGE_LOAD[chip]);
        loadMenuItem[chip].addActionListener(this);
        fileMenu.add(loadMenuItem[chip]);
    }

    fileMenu.add(new JSeparator());

    //decoder
    tmpMenuItem = new JMenuItem("Decode firmware");
    tmpMenuItem.setMnemonic(KeyEvent.VK_D);
    tmpMenuItem.setActionCommand(COMMAND_DECODE);
    tmpMenuItem.addActionListener(this);
    fileMenu.add(tmpMenuItem);

    //encoder
    tmpMenuItem = new JMenuItem("Encode firmware (alpha)");
    tmpMenuItem.setMnemonic(KeyEvent.VK_E);
    tmpMenuItem.setActionCommand(COMMAND_ENCODE);
    tmpMenuItem.addActionListener(this);
    //        fileMenu.add(tmpMenuItem);

    fileMenu.add(new JSeparator());

    //decoder
    tmpMenuItem = new JMenuItem("Decode lens correction data");
    //tmpMenuItem.setMnemonic(KeyEvent.VK_D);
    tmpMenuItem.setActionCommand(COMMAND_DECODE_NKLD);
    tmpMenuItem.addActionListener(this);
    fileMenu.add(tmpMenuItem);

    fileMenu.add(new JSeparator());

    //Save state
    tmpMenuItem = new JMenuItem("Save state");
    tmpMenuItem.setActionCommand(COMMAND_SAVE_STATE);
    tmpMenuItem.addActionListener(this);
    fileMenu.add(tmpMenuItem);

    //Load state
    tmpMenuItem = new JMenuItem("Load state");
    tmpMenuItem.setActionCommand(COMMAND_LOAD_STATE);
    tmpMenuItem.addActionListener(this);
    fileMenu.add(tmpMenuItem);

    fileMenu.add(new JSeparator());

    //quit
    tmpMenuItem = new JMenuItem("Quit");
    tmpMenuItem.setMnemonic(KEY_EVENT_QUIT);
    tmpMenuItem.setAccelerator(KeyStroke.getKeyStroke(KEY_EVENT_QUIT, ActionEvent.ALT_MASK));
    tmpMenuItem.setActionCommand(COMMAND_QUIT);
    tmpMenuItem.addActionListener(this);
    fileMenu.add(tmpMenuItem);

    //Set up the run menu.
    JMenu runMenu = new JMenu("Run");
    runMenu.setMnemonic(KeyEvent.VK_R);
    menuBar.add(runMenu);

    for (int chip = 0; chip < 2; chip++) {
        //emulator play
        playMenuItem[chip] = new JMenuItem("Start (or resume) " + Constants.CHIP_LABEL[chip] + " emulator");
        playMenuItem[chip].setAccelerator(KeyStroke.getKeyStroke(KEY_EVENT_RUN[chip], ActionEvent.ALT_MASK));
        playMenuItem[chip].setActionCommand(COMMAND_EMULATOR_PLAY[chip]);
        playMenuItem[chip].addActionListener(this);
        runMenu.add(playMenuItem[chip]);

        //emulator debug
        debugMenuItem[chip] = new JMenuItem("Debug " + Constants.CHIP_LABEL[chip] + " emulator");
        debugMenuItem[chip].setAccelerator(KeyStroke.getKeyStroke(KEY_EVENT_DEBUG[chip], ActionEvent.ALT_MASK));
        debugMenuItem[chip].setActionCommand(COMMAND_EMULATOR_DEBUG[chip]);
        debugMenuItem[chip].addActionListener(this);
        runMenu.add(debugMenuItem[chip]);

        //emulator pause
        pauseMenuItem[chip] = new JMenuItem("Pause " + Constants.CHIP_LABEL[chip] + " emulator");
        pauseMenuItem[chip].setAccelerator(KeyStroke.getKeyStroke(KEY_EVENT_PAUSE[chip], ActionEvent.ALT_MASK));
        pauseMenuItem[chip].setActionCommand(COMMAND_EMULATOR_PAUSE[chip]);
        pauseMenuItem[chip].addActionListener(this);
        runMenu.add(pauseMenuItem[chip]);

        //emulator step
        stepMenuItem[chip] = new JMenuItem("Step " + Constants.CHIP_LABEL[chip] + " emulator");
        stepMenuItem[chip].setAccelerator(KeyStroke.getKeyStroke(KEY_EVENT_STEP[chip], ActionEvent.ALT_MASK));
        stepMenuItem[chip].setActionCommand(COMMAND_EMULATOR_STEP[chip]);
        stepMenuItem[chip].addActionListener(this);
        runMenu.add(stepMenuItem[chip]);

        //emulator stop
        stopMenuItem[chip] = new JMenuItem("Stop and reset " + Constants.CHIP_LABEL[chip] + " emulator");
        stopMenuItem[chip].setActionCommand(COMMAND_EMULATOR_STOP[chip]);
        stopMenuItem[chip].addActionListener(this);
        runMenu.add(stopMenuItem[chip]);

        runMenu.add(new JSeparator());

        //setup breakpoints
        breakpointMenuItem[chip] = new JMenuItem("Setup " + Constants.CHIP_LABEL[chip] + " breakpoints");
        breakpointMenuItem[chip].setActionCommand(COMMAND_SETUP_BREAKPOINTS[chip]);
        breakpointMenuItem[chip].addActionListener(this);
        runMenu.add(breakpointMenuItem[chip]);

        if (chip == Constants.CHIP_FR) {
            runMenu.add(new JSeparator());
        }
    }

    //Set up the components menu.
    JMenu componentsMenu = new JMenu("Components");
    componentsMenu.setMnemonic(KeyEvent.VK_O);
    menuBar.add(componentsMenu);

    for (int chip = 0; chip < 2; chip++) {
        //CPU state
        cpuStateMenuItem[chip] = new JCheckBoxMenuItem(Constants.CHIP_LABEL[chip] + " CPU State window");
        if (chip == Constants.CHIP_FR)
            cpuStateMenuItem[chip].setMnemonic(KEY_EVENT_CPUSTATE);
        cpuStateMenuItem[chip]
                .setAccelerator(KeyStroke.getKeyStroke(KEY_EVENT_CPUSTATE, KEY_CHIP_MODIFIER[chip]));
        cpuStateMenuItem[chip].setActionCommand(COMMAND_TOGGLE_CPUSTATE_WINDOW[chip]);
        cpuStateMenuItem[chip].addActionListener(this);
        componentsMenu.add(cpuStateMenuItem[chip]);

        //memory hex editor
        memoryHexEditorMenuItem[chip] = new JCheckBoxMenuItem(
                Constants.CHIP_LABEL[chip] + " Memory hex editor");
        if (chip == Constants.CHIP_FR)
            memoryHexEditorMenuItem[chip].setMnemonic(KEY_EVENT_MEMORY);
        memoryHexEditorMenuItem[chip]
                .setAccelerator(KeyStroke.getKeyStroke(KEY_EVENT_MEMORY, KEY_CHIP_MODIFIER[chip]));
        memoryHexEditorMenuItem[chip].setActionCommand(COMMAND_TOGGLE_MEMORY_HEX_EDITOR[chip]);
        memoryHexEditorMenuItem[chip].addActionListener(this);
        componentsMenu.add(memoryHexEditorMenuItem[chip]);

        //Interrupt controller
        interruptControllerMenuItem[chip] = new JCheckBoxMenuItem(
                Constants.CHIP_LABEL[chip] + " interrupt controller");
        interruptControllerMenuItem[chip].setActionCommand(COMMAND_TOGGLE_INTERRUPT_CONTROLLER_WINDOW[chip]);
        interruptControllerMenuItem[chip].addActionListener(this);
        componentsMenu.add(interruptControllerMenuItem[chip]);

        //Programmble timers
        programmableTimersMenuItem[chip] = new JCheckBoxMenuItem(
                Constants.CHIP_LABEL[chip] + " programmable timers");
        programmableTimersMenuItem[chip].setActionCommand(COMMAND_TOGGLE_PROGRAMMABLE_TIMERS_WINDOW[chip]);
        programmableTimersMenuItem[chip].addActionListener(this);
        componentsMenu.add(programmableTimersMenuItem[chip]);

        //Serial interface
        serialInterfacesMenuItem[chip] = new JCheckBoxMenuItem(
                Constants.CHIP_LABEL[chip] + " serial interfaces");
        serialInterfacesMenuItem[chip].setActionCommand(COMMAND_TOGGLE_SERIAL_INTERFACES[chip]);
        serialInterfacesMenuItem[chip].addActionListener(this);
        componentsMenu.add(serialInterfacesMenuItem[chip]);

        // I/O
        ioPortsMenuItem[chip] = new JCheckBoxMenuItem(Constants.CHIP_LABEL[chip] + " I/O ports");
        ioPortsMenuItem[chip].setActionCommand(COMMAND_TOGGLE_IO_PORTS_WINDOW[chip]);
        ioPortsMenuItem[chip].addActionListener(this);
        componentsMenu.add(ioPortsMenuItem[chip]);

        //Serial devices
        serialDevicesMenuItem[chip] = new JCheckBoxMenuItem(Constants.CHIP_LABEL[chip] + " serial devices");
        serialDevicesMenuItem[chip].setActionCommand(COMMAND_TOGGLE_SERIAL_DEVICES[chip]);
        serialDevicesMenuItem[chip].addActionListener(this);
        componentsMenu.add(serialDevicesMenuItem[chip]);

        componentsMenu.add(new JSeparator());
    }

    //screen emulator: FR80 only
    screenEmulatorMenuItem = new JCheckBoxMenuItem("Screen emulator (FR only)");
    screenEmulatorMenuItem.setMnemonic(KEY_EVENT_SCREEN);
    screenEmulatorMenuItem.setAccelerator(KeyStroke.getKeyStroke(KEY_EVENT_SCREEN, ActionEvent.ALT_MASK));
    screenEmulatorMenuItem.setActionCommand(COMMAND_TOGGLE_SCREEN_EMULATOR);
    screenEmulatorMenuItem.addActionListener(this);
    componentsMenu.add(screenEmulatorMenuItem);

    //Component 4006: FR80 only
    component4006MenuItem = new JCheckBoxMenuItem("Component 4006 window (FR only)");
    component4006MenuItem.setMnemonic(KeyEvent.VK_4);
    component4006MenuItem.setActionCommand(COMMAND_TOGGLE_COMPONENT_4006_WINDOW);
    component4006MenuItem.addActionListener(this);
    componentsMenu.add(component4006MenuItem);

    componentsMenu.add(new JSeparator());

    //A/D converter: TX19 only for now
    adConverterMenuItem[Constants.CHIP_TX] = new JCheckBoxMenuItem(
            Constants.CHIP_LABEL[Constants.CHIP_TX] + " A/D converter (TX only)");
    adConverterMenuItem[Constants.CHIP_TX].setActionCommand(COMMAND_TOGGLE_AD_CONVERTER[Constants.CHIP_TX]);
    adConverterMenuItem[Constants.CHIP_TX].addActionListener(this);
    componentsMenu.add(adConverterMenuItem[Constants.CHIP_TX]);

    //Front panel: TX19 only
    frontPanelMenuItem = new JCheckBoxMenuItem("Front panel (TX only)");
    frontPanelMenuItem.setActionCommand(COMMAND_TOGGLE_FRONT_PANEL);
    frontPanelMenuItem.addActionListener(this);
    componentsMenu.add(frontPanelMenuItem);

    //Set up the trace menu.
    JMenu traceMenu = new JMenu("Trace");
    traceMenu.setMnemonic(KeyEvent.VK_C);
    menuBar.add(traceMenu);

    for (int chip = 0; chip < 2; chip++) {
        //memory activity viewer
        memoryActivityViewerMenuItem[chip] = new JCheckBoxMenuItem(
                Constants.CHIP_LABEL[chip] + " Memory activity viewer");
        memoryActivityViewerMenuItem[chip].setActionCommand(COMMAND_TOGGLE_MEMORY_ACTIVITY_VIEWER[chip]);
        memoryActivityViewerMenuItem[chip].addActionListener(this);
        traceMenu.add(memoryActivityViewerMenuItem[chip]);

        //disassembly
        disassemblyMenuItem[chip] = new JCheckBoxMenuItem(
                "Real-time " + Constants.CHIP_LABEL[chip] + " disassembly log");
        if (chip == Constants.CHIP_FR)
            disassemblyMenuItem[chip].setMnemonic(KEY_EVENT_REALTIME_DISASSEMBLY);
        disassemblyMenuItem[chip].setAccelerator(
                KeyStroke.getKeyStroke(KEY_EVENT_REALTIME_DISASSEMBLY, KEY_CHIP_MODIFIER[chip]));
        disassemblyMenuItem[chip].setActionCommand(COMMAND_TOGGLE_DISASSEMBLY_WINDOW[chip]);
        disassemblyMenuItem[chip].addActionListener(this);
        traceMenu.add(disassemblyMenuItem[chip]);

        //Custom logger
        customMemoryRangeLoggerMenuItem[chip] = new JCheckBoxMenuItem(
                "Custom " + Constants.CHIP_LABEL[chip] + " logger window");
        customMemoryRangeLoggerMenuItem[chip].setActionCommand(COMMAND_TOGGLE_CUSTOM_LOGGER_WINDOW[chip]);
        customMemoryRangeLoggerMenuItem[chip].addActionListener(this);
        traceMenu.add(customMemoryRangeLoggerMenuItem[chip]);

        //Call Stack logger
        callStackMenuItem[chip] = new JCheckBoxMenuItem(Constants.CHIP_LABEL[chip] + " Call stack logger");
        callStackMenuItem[chip].setActionCommand(COMMAND_TOGGLE_CALL_STACK_WINDOW[chip]);
        callStackMenuItem[chip].addActionListener(this);
        traceMenu.add(callStackMenuItem[chip]);

        //ITRON Object
        iTronObjectMenuItem[chip] = new JCheckBoxMenuItem("ITRON " + Constants.CHIP_LABEL[chip] + " Objects");
        iTronObjectMenuItem[chip].setActionCommand(COMMAND_TOGGLE_ITRON_OBJECT_WINDOW[chip]);
        iTronObjectMenuItem[chip].addActionListener(this);
        traceMenu.add(iTronObjectMenuItem[chip]);

        //ITRON Return Stack
        iTronReturnStackMenuItem[chip] = new JCheckBoxMenuItem(
                "ITRON " + Constants.CHIP_LABEL[chip] + " Return stack");
        iTronReturnStackMenuItem[chip].setActionCommand(COMMAND_TOGGLE_ITRON_RETURN_STACK_WINDOW[chip]);
        iTronReturnStackMenuItem[chip].addActionListener(this);
        traceMenu.add(iTronReturnStackMenuItem[chip]);

        traceMenu.add(new JSeparator());
    }

    //Set up the source menu.
    JMenu sourceMenu = new JMenu("Source");
    sourceMenu.setMnemonic(KEY_EVENT_SCREEN);
    menuBar.add(sourceMenu);

    // FR syscall symbols
    generateSysSymbolsMenuItem = new JMenuItem(
            "Generate " + Constants.CHIP_LABEL[Constants.CHIP_FR] + " system call symbols");
    generateSysSymbolsMenuItem.setActionCommand(COMMAND_GENERATE_SYS_SYMBOLS);
    generateSysSymbolsMenuItem.addActionListener(this);
    sourceMenu.add(generateSysSymbolsMenuItem);

    for (int chip = 0; chip < 2; chip++) {

        sourceMenu.add(new JSeparator());

        //analyse / disassemble
        analyseMenuItem[chip] = new JMenuItem("Analyse / Disassemble " + Constants.CHIP_LABEL[chip] + " code");
        analyseMenuItem[chip].setActionCommand(COMMAND_ANALYSE_DISASSEMBLE[chip]);
        analyseMenuItem[chip].addActionListener(this);
        sourceMenu.add(analyseMenuItem[chip]);

        sourceMenu.add(new JSeparator());

        //code structure
        codeStructureMenuItem[chip] = new JCheckBoxMenuItem(Constants.CHIP_LABEL[chip] + " code structure");
        codeStructureMenuItem[chip].setActionCommand(COMMAND_TOGGLE_CODE_STRUCTURE_WINDOW[chip]);
        codeStructureMenuItem[chip].addActionListener(this);
        sourceMenu.add(codeStructureMenuItem[chip]);

        //source code
        sourceCodeMenuItem[chip] = new JCheckBoxMenuItem(Constants.CHIP_LABEL[chip] + " source code");
        if (chip == Constants.CHIP_FR)
            sourceCodeMenuItem[chip].setMnemonic(KEY_EVENT_SOURCE);
        sourceCodeMenuItem[chip]
                .setAccelerator(KeyStroke.getKeyStroke(KEY_EVENT_SOURCE, KEY_CHIP_MODIFIER[chip]));
        sourceCodeMenuItem[chip].setActionCommand(COMMAND_TOGGLE_SOURCE_CODE_WINDOW[chip]);
        sourceCodeMenuItem[chip].addActionListener(this);
        sourceMenu.add(sourceCodeMenuItem[chip]);

        if (chip == Constants.CHIP_FR) {
            sourceMenu.add(new JSeparator());
        }
    }

    //Set up the tools menu.
    JMenu toolsMenu = new JMenu("Tools");
    toolsMenu.setMnemonic(KeyEvent.VK_T);
    menuBar.add(toolsMenu);

    for (int chip = 0; chip < 2; chip++) {
        // save/load memory area
        saveLoadMemoryMenuItem[chip] = new JMenuItem(
                "Save/Load " + Constants.CHIP_LABEL[chip] + " memory area");
        saveLoadMemoryMenuItem[chip].setActionCommand(COMMAND_SAVE_LOAD_MEMORY[chip]);
        saveLoadMemoryMenuItem[chip].addActionListener(this);
        toolsMenu.add(saveLoadMemoryMenuItem[chip]);

        //chip options
        chipOptionsMenuItem[chip] = new JMenuItem(Constants.CHIP_LABEL[chip] + " options");
        chipOptionsMenuItem[chip].setActionCommand(COMMAND_CHIP_OPTIONS[chip]);
        chipOptionsMenuItem[chip].addActionListener(this);
        toolsMenu.add(chipOptionsMenuItem[chip]);

        toolsMenu.add(new JSeparator());

    }

    //disassembly options
    uiOptionsMenuItem = new JMenuItem("Preferences");
    uiOptionsMenuItem.setActionCommand(COMMAND_UI_OPTIONS);
    uiOptionsMenuItem.addActionListener(this);
    toolsMenu.add(uiOptionsMenuItem);

    //Set up the help menu.
    JMenu helpMenu = new JMenu("?");
    menuBar.add(helpMenu);

    //about
    JMenuItem aboutMenuItem = new JMenuItem("About");
    aboutMenuItem.setActionCommand(COMMAND_ABOUT);
    aboutMenuItem.addActionListener(this);
    helpMenu.add(aboutMenuItem);

    //        JMenuItem testMenuItem = new JMenuItem("Test");
    //        testMenuItem.setActionCommand(COMMAND_TEST);
    //        testMenuItem.addActionListener(this);
    //        helpMenu.add(testMenuItem);

    // Global "Keep in sync" setting
    menuBar.add(Box.createHorizontalGlue());
    final JCheckBox syncEmulators = new JCheckBox("Keep emulators in sync");
    syncEmulators.setSelected(prefs.isSyncPlay());
    framework.getMasterClock().setSyncPlay(prefs.isSyncPlay());
    syncEmulators.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            prefs.setSyncPlay(syncEmulators.isSelected());
            framework.getMasterClock().setSyncPlay(syncEmulators.isSelected());
        }
    });
    menuBar.add(syncEmulators);
    return menuBar;
}

From source file:edu.ku.brc.specify.Specify.java

/**
 * Create menus//  ww  w  . j a v  a 2  s .  c  o  m
 */
public JMenuBar createMenus() {
    JMenuBar mb = new JMenuBar();
    JMenuItem mi;

    //--------------------------------------------------------------------
    //-- File Menu
    //--------------------------------------------------------------------

    JMenu menu = null;

    if (!UIHelper.isMacOS() || !isWorkbenchOnly) {
        menu = UIHelper.createLocalizedMenu(mb, "Specify.FILE_MENU", "Specify.FILE_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$
    }

    if (!isWorkbenchOnly) {
        // Add Menu for switching Collection
        String title = "Specify.CHANGE_COLLECTION"; //$NON-NLS-1$
        String mnu = "Specify.CHANGE_COLL_MNEU"; //$NON-NLS-1$
        changeCollectionMenuItem = UIHelper.createLocalizedMenuItem(menu, title, mnu, title, false, null);
        changeCollectionMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                if (SubPaneMgr.getInstance().aboutToShutdown()) {

                    // Actually we really need to start over
                    // "true" means that it should NOT use any cached values it can find to automatically initialize itself
                    // instead it should ask the user any questions as if it were starting over
                    restartApp(null, databaseName, userName, true, false);
                }
            }
        });

        menu.addMenuListener(new MenuListener() {
            @Override
            public void menuCanceled(MenuEvent e) {
            }

            @Override
            public void menuDeselected(MenuEvent e) {
            }

            @Override
            public void menuSelected(MenuEvent e) {
                boolean enable = Uploader.getCurrentUpload() == null
                        && ((SpecifyAppContextMgr) AppContextMgr.getInstance()).getNumOfCollectionsForUser() > 1
                        && !TaskMgr.areTasksDisabled();

                changeCollectionMenuItem.setEnabled(enable);
            }

        });
    }

    if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) {
        if (!UIRegistry.isMobile()) {
            menu.addSeparator();
        }
        String title = "Specify.EXIT"; //$NON-NLS-1$
        String mnu = "Specify.Exit_MNEU"; //$NON-NLS-1$
        mi = UIHelper.createLocalizedMenuItem(menu, title, mnu, title, true, null);
        if (!UIHelper.isMacOS()) {
            mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_DOWN_MASK));
        }
        mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                doExit(true);
            }
        });
    }

    menu = UIRegistry.getInstance().createEditMenu();
    mb.add(menu);

    //menu = UIHelper.createMenu(mb, "EditMenu", "EditMneu");
    if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) {
        menu.addSeparator();
        String title = "Specify.PREFERENCES"; //$NON-NLS-1$
        String mnu = "Specify.PREFERENCES_MNEU";//$NON-NLS-1$
        mi = UIHelper.createLocalizedMenuItem(menu, title, mnu, title, false, null);
        mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                doPreferences();
            }
        });
        mi.setEnabled(true);
    }

    //--------------------------------------------------------------------
    //-- Data Menu
    //--------------------------------------------------------------------
    JMenu dataMenu = UIHelper.createLocalizedMenu(mb, "Specify.DATA_MENU", "Specify.DATA_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$
    ResultSetController.addMenuItems(dataMenu);
    dataMenu.addSeparator();

    // Save And New Menu Item
    Action saveAndNewAction = new AbstractAction(getResourceString("Specify.SAVE_AND_NEW")) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            FormViewObj fvo = getCurrentFVO();
            if (fvo != null) {
                fvo.setSaveAndNew(((JCheckBoxMenuItem) e.getSource()).isSelected());
            }
        }
    };
    saveAndNewAction.setEnabled(false);
    JCheckBoxMenuItem saveAndNewCBMI = new JCheckBoxMenuItem(saveAndNewAction);
    dataMenu.add(saveAndNewCBMI);
    UIRegistry.register("SaveAndNew", saveAndNewCBMI); //$NON-NLS-1$
    UIRegistry.registerAction("SaveAndNew", saveAndNewAction); //$NON-NLS-1$
    mb.add(dataMenu);

    // Configure Carry Forward
    Action configCarryForwardAction = new AbstractAction(
            getResourceString("Specify.CONFIG_CARRY_FORWARD_MENU")) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            FormViewObj fvo = getCurrentFVO();
            if (fvo != null) {
                fvo.configureCarryForward();
            }
        }
    };
    configCarryForwardAction.setEnabled(false);
    JMenuItem configCFWMI = new JMenuItem(configCarryForwardAction);
    dataMenu.add(configCFWMI);
    UIRegistry.register("ConfigCarryForward", configCFWMI); //$NON-NLS-1$
    UIRegistry.registerAction("ConfigCarryForward", configCarryForwardAction); //$NON-NLS-1$
    mb.add(dataMenu);

    //---------------------------------------
    // Carry Forward Menu Item (On / Off)
    Action carryForwardAction = new AbstractAction(getResourceString("Specify.CARRY_FORWARD_CHECKED_MENU")) { //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            FormViewObj fvo = getCurrentFVO();
            if (fvo != null) {
                fvo.toggleCarryForward();
                ((JCheckBoxMenuItem) e.getSource()).setSelected(fvo.isDoCarryForward());
            }
        }
    };
    carryForwardAction.setEnabled(false);
    JCheckBoxMenuItem carryForwardCBMI = new JCheckBoxMenuItem(carryForwardAction);
    dataMenu.add(carryForwardCBMI);
    UIRegistry.register("CarryForward", carryForwardCBMI); //$NON-NLS-1$
    UIRegistry.registerAction("CarryForward", carryForwardAction); //$NON-NLS-1$
    mb.add(dataMenu);

    if (!isWorkbenchOnly) {
        final String AUTO_NUM = "AutoNumbering";
        //---------------------------------------
        // AutoNumber Menu Item (On / Off)
        Action autoNumberOnOffAction = new AbstractAction(
                getResourceString("FormViewObj.SET_AUTONUMBER_ONOFF")) { //$NON-NLS-1$
            public void actionPerformed(ActionEvent e) {
                FormViewObj fvo = getCurrentFVO();
                if (fvo != null) {
                    fvo.toggleAutoNumberOnOffState();
                    ((JCheckBoxMenuItem) e.getSource()).setSelected(fvo.isAutoNumberOn());
                }
            }
        };
        autoNumberOnOffAction.setEnabled(false);
        JCheckBoxMenuItem autoNumCBMI = new JCheckBoxMenuItem(autoNumberOnOffAction);
        dataMenu.add(autoNumCBMI);
        UIRegistry.register(AUTO_NUM, autoNumCBMI); //$NON-NLS-1$
        UIRegistry.registerAction(AUTO_NUM, autoNumberOnOffAction); //$NON-NLS-1$
    }

    if (System.getProperty("user.name").equals("rods")) {
        dataMenu.addSeparator();

        AbstractAction gpxAction = new AbstractAction("GPS Data") {
            @Override
            public void actionPerformed(ActionEvent e) {
                GPXPanel.getDlgInstance().setVisible(true);
            }
        };
        JMenuItem gpxMI = new JMenuItem(gpxAction);
        dataMenu.add(gpxMI);
        UIRegistry.register("GPXDlg", gpxMI); //$NON-NLS-1$
        UIRegistry.registerAction("GPXDlg", gpxAction); //$NON-NLS-1$
    }

    mb.add(dataMenu);

    SubPaneMgr.getInstance(); // force creating of the Mgr so the menu Actions are created.

    //--------------------------------------------------------------------
    //-- System Menu
    //--------------------------------------------------------------------

    if (!isWorkbenchOnly) {
        // TODO This needs to be moved into the SystemTask, but right now there is no way
        // to ask a task for a menu.
        menu = UIHelper.createLocalizedMenu(mb, "Specify.SYSTEM_MENU", "Specify.SYSTEM_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$

        /*if (true)
        {
        menu = UIHelper.createMenu(mb, "Forms", "o");
        Action genForms = new AbstractAction()
        {
            public void actionPerformed(ActionEvent ae)
            {
                FormGenerator fg = new FormGenerator();
                fg.generateForms();
            }
        };
        mi = UIHelper.createMenuItemWithAction(menu, "Generate All Forms", "G", "", true, genForms);
        }*/
    }

    //--------------------------------------------------------------------
    //-- Tab Menu
    //--------------------------------------------------------------------
    menu = UIHelper.createLocalizedMenu(mb, "Specify.TABS_MENU", "Specify.TABS_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$

    String ttl = UIRegistry.getResourceString("Specify.SBP_CLOSE_CUR_MENU");
    String mnu = UIRegistry.getResourceString("Specify.SBP_CLOSE_CUR_MNEU");
    mi = UIHelper.createMenuItemWithAction(menu, ttl, mnu, ttl, true, getAction("CloseCurrent"));
    if (!UIHelper.isMacOS()) {
        mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK));
    }

    ttl = UIRegistry.getResourceString("Specify.SBP_CLOSE_ALL_MENU");
    mnu = UIRegistry.getResourceString("Specify.SBP_CLOSE_ALL_MNEU");
    mi = UIHelper.createMenuItemWithAction(menu, ttl, mnu, ttl, true, getAction("CloseAll"));
    if (!UIHelper.isMacOS()) {
        mi.setAccelerator(
                KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK));
    }

    ttl = UIRegistry.getResourceString("Specify.SBP_CLOSE_ALLBUT_MENU");
    mnu = UIRegistry.getResourceString("Specify.SBP_CLOSE_ALLBUT_MNEU");
    mi = UIHelper.createMenuItemWithAction(menu, ttl, mnu, ttl, true, getAction("CloseAllBut"));

    menu.addSeparator();

    // Configure Task
    JMenuItem configTaskMI = new JMenuItem(getAction("ConfigureTask"));
    menu.add(configTaskMI);
    //UIRegistry.register("ConfigureTask", configTaskMI); //$NON-NLS-1$

    //--------------------------------------------------------------------
    //-- Debug Menu
    //--------------------------------------------------------------------

    boolean doDebug = AppPreferences.getLocalPrefs().getBoolean("debug.menu", false);
    if (!UIRegistry.isRelease() || doDebug) {
        menu = UIHelper.createLocalizedMenu(mb, "Specify.DEBUG_MENU", "Specify.DEBUG_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$
        String ttle = "Specify.SHOW_LOC_PREFS";//$NON-NLS-1$ 
        String mneu = "Specify.SHOW_LOC_PREF_MNEU";//$NON-NLS-1$ 
        String desc = "Specify.SHOW_LOC_PREFS";//$NON-NLS-1$ 
        mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null);
        mi.addActionListener(new ActionListener() {
            @SuppressWarnings("synthetic-access") //$NON-NLS-1$ 
            public void actionPerformed(ActionEvent ae) {
                openLocalPrefs();
            }
        });

        ttle = "Specify.SHOW_REM_PREFS";//$NON-NLS-1$ 
        mneu = "Specify.SHOW_REM_PREFS_MNEU";//$NON-NLS-1$ 
        desc = "Specify.SHOW_REM_PREFS";//$NON-NLS-1$ 
        mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null);
        mi.addActionListener(new ActionListener() {
            @SuppressWarnings("synthetic-access") //$NON-NLS-1$
            public void actionPerformed(ActionEvent ae) {
                openRemotePrefs();
            }
        });

        menu.addSeparator();

        ttle = "Specify.CONFIG_LOGGERS";//$NON-NLS-1$ 
        mneu = "Specify.CONFIG_LOGGERS_MNEU";//$NON-NLS-1$ 
        desc = "Specify.CONFIG_LOGGER";//$NON-NLS-1$ 
        mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null);
        mi.addActionListener(new ActionListener() {
            @SuppressWarnings("synthetic-access") //$NON-NLS-1$
            public void actionPerformed(ActionEvent ae) {
                final LoggerDialog dialog = new LoggerDialog(topFrame);
                UIHelper.centerAndShow(dialog);
            }
        });

        ttle = "Specify.CONFIG_DEBUG_LOGGERS";//$NON-NLS-1$ 
        mneu = "Specify.CONFIG_DEBUG_LOGGERS_MNEU";//$NON-NLS-1$ 
        desc = "Specify.CONFIG_DEBUG_LOGGER";//$NON-NLS-1$ 
        mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null);
        mi.addActionListener(new ActionListener() {
            @SuppressWarnings("synthetic-access") //$NON-NLS-1$
            public void actionPerformed(ActionEvent ae) {
                DebugLoggerDialog dialog = new DebugLoggerDialog(topFrame);
                UIHelper.centerAndShow(dialog);
            }
        });

        menu.addSeparator();

        ttle = "Specify.SHOW_MEM_STATS";//$NON-NLS-1$ 
        mneu = "Specify.SHOW_MEM_STATS_MNEU";//$NON-NLS-1$ 
        desc = "Specify.SHOW_MEM_STATS";//$NON-NLS-1$ 
        mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null);
        mi.addActionListener(new ActionListener() {
            @SuppressWarnings("synthetic-access") //$NON-NLS-1$
            public void actionPerformed(ActionEvent ae) {
                System.gc();
                System.runFinalization();

                // Get current size of heap in bytes
                double meg = 1024.0 * 1024.0;
                double heapSize = Runtime.getRuntime().totalMemory() / meg;

                // Get maximum size of heap in bytes. The heap cannot grow beyond this size.
                // Any attempt will result in an OutOfMemoryException.
                double heapMaxSize = Runtime.getRuntime().maxMemory() / meg;

                // Get amount of free memory within the heap in bytes. This size will increase
                // after garbage collection and decrease as new objects are created.
                double heapFreeSize = Runtime.getRuntime().freeMemory() / meg;

                UIRegistry.getStatusBar()
                        .setText(String.format("Heap Size: %7.2f    Max: %7.2f    Free: %7.2f   Used: %7.2f", //$NON-NLS-1$
                                heapSize, heapMaxSize, heapFreeSize, (heapSize - heapFreeSize)));
            }
        });

        JMenu prefsMenu = new JMenu(UIRegistry.getResourceString("Specify.PREFS_IMPORT_EXPORT")); //$NON-NLS-1$
        menu.add(prefsMenu);
        ttle = "Specify.IMPORT_MENU";//$NON-NLS-1$ 
        mneu = "Specify.IMPORT_MNEU";//$NON-NLS-1$ 
        desc = "Specify.IMPORT_PREFS";//$NON-NLS-1$ 
        mi = UIHelper.createLocalizedMenuItem(prefsMenu, ttle, mneu, desc, true, null);
        mi.addActionListener(new ActionListener() {
            @SuppressWarnings("synthetic-access") //$NON-NLS-1$
            public void actionPerformed(ActionEvent ae) {
                importPrefs();
            }
        });
        ttle = "Specify.EXPORT_MENU";//$NON-NLS-1$ 
        mneu = "Specify.EXPORT_MNEU";//$NON-NLS-1$ 
        desc = "Specify.EXPORT_PREFS";//$NON-NLS-1$ 
        mi = UIHelper.createLocalizedMenuItem(prefsMenu, ttle, mneu, desc, true, null);
        mi.addActionListener(new ActionListener() {
            @SuppressWarnings("synthetic-access") //$NON-NLS-1$
            public void actionPerformed(ActionEvent ae) {
                exportPrefs();
            }
        });

        ttle = "Associate Storage Items";//$NON-NLS-1$ 
        mneu = "A";//$NON-NLS-1$ 
        desc = "";//$NON-NLS-1$ 
        mi = UIHelper.createMenuItemWithAction(menu, ttle, mneu, desc, true, null);
        mi.addActionListener(new ActionListener() {
            @SuppressWarnings("synthetic-access") //$NON-NLS-1$
            public void actionPerformed(ActionEvent ae) {
                associateStorageItems();
            }
        });

        ttle = "Load GPX Points";//$NON-NLS-1$ 
        mneu = "a";//$NON-NLS-1$ 
        desc = "";//$NON-NLS-1$ 
        mi = UIHelper.createMenuItemWithAction(menu, ttle, mneu, desc, true, null);
        mi.addActionListener(new ActionListener() {
            @SuppressWarnings("synthetic-access") //$NON-NLS-1$
            public void actionPerformed(ActionEvent ae) {
                CustomDialog dlg = GPXPanel.getDlgInstance();
                if (dlg != null) {
                    dlg.setVisible(true);
                }
            }
        });

        JCheckBoxMenuItem cbMenuItem = new JCheckBoxMenuItem("Security Activated"); //$NON-NLS-1$
        menu.add(cbMenuItem);
        cbMenuItem.setSelected(AppContextMgr.isSecurityOn());
        cbMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                boolean isSecurityOn = !SpecifyAppContextMgr.isSecurityOn();
                AppContextMgr.getInstance().setSecurity(isSecurityOn);
                ((JMenuItem) ae.getSource()).setSelected(isSecurityOn);

                JLabel secLbl = statusField.getSectionLabel(3);
                if (secLbl != null) {
                    secLbl.setIcon(IconManager.getImage(isSecurityOn ? "SecurityOn" : "SecurityOff",
                            IconManager.IconSize.Std16));
                    secLbl.setHorizontalAlignment(SwingConstants.CENTER);
                    secLbl.setToolTipText(getResourceString("Specify.SEC_" + (isSecurityOn ? "ON" : "OFF")));
                }
            }
        });

        JMenuItem sizeMenuItem = new JMenuItem("Set to " + PREFERRED_WIDTH + "x" + PREFERRED_HEIGHT); //$NON-NLS-1$
        menu.add(sizeMenuItem);
        sizeMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                topFrame.setSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
            }
        });
    }

    //----------------------------------------------------
    //-- Helper Menu
    //----------------------------------------------------

    JMenu helpMenu = UIHelper.createLocalizedMenu(mb, "Specify.HELP_MENU", "Specify.HELP_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$
    HelpMgr.createHelpMenuItem(helpMenu, getResourceString("SPECIFY_HELP")); //$NON-NLS-1$
    helpMenu.addSeparator();

    String ttle = "Specify.LOG_SHOW_FILES";//$NON-NLS-1$ 
    String mneu = "Specify.LOG_SHOW_FILES_MNEU";//$NON-NLS-1$ 
    String desc = "Specify.LOG_SHOW_FILES";//$NON-NLS-1$      
    mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null);
    helpMenu.addSeparator();
    mi.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            AppBase.displaySpecifyLogFiles();
        }
    });

    ttle = "SecurityAdminTask.CHANGE_PWD_MENU"; //$NON-NLS-1$
    mneu = "SecurityAdminTask.CHANGE_PWD_MNEU"; //$NON-NLS-1$
    desc = "SecurityAdminTask.CHANGE_PWD_DESC"; //$NON-NLS-1$
    mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null);
    mi.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            SecurityAdminTask.changePassword(true);
        }
    });

    ttle = "Specify.CHECK_UPDATE";//$NON-NLS-1$ 
    mneu = "Specify.CHECK_UPDATE_MNEU";//$NON-NLS-1$ 
    desc = "Specify.CHECK_UPDATE_DESC";//$NON-NLS-1$      
    mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null);
    mi.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            checkForUpdates();
        }
    });

    ttle = "Specify.AUTO_REG";//$NON-NLS-1$ 
    mneu = "Specify.AUTO_REG_MNEU";//$NON-NLS-1$ 
    desc = "Specify.AUTO_REG_DESC";//$NON-NLS-1$      
    mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null);
    mi.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            RegisterSpecify.register(true, 0);
        }
    });

    ttle = "Specify.SA_REG";//$NON-NLS-1$ 
    mneu = "Specify.SA_REG_MNEU";//$NON-NLS-1$ 
    desc = "Specify.SA_REG_DESC";//$NON-NLS-1$      
    mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null);
    mi.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            RegisterSpecify.registerISA();
        }
    });

    ttle = "Specify.FEEDBACK";//$NON-NLS-1$ 
    mneu = "Specify.FB_MNEU";//$NON-NLS-1$ 
    desc = "Specify.FB_DESC";//$NON-NLS-1$      
    mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null);
    mi.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            FeedBackDlg feedBackDlg = new FeedBackDlg();
            feedBackDlg.sendFeedback();
        }
    });

    if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) {
        helpMenu.addSeparator();

        ttle = "Specify.ABOUT";//$NON-NLS-1$ 
        mneu = "Specify.ABOUTMNEU";//$NON-NLS-1$ 
        desc = "Specify.ABOUT";//$NON-NLS-1$ 
        mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null);
        mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                doAbout();
            }
        });
    }
    return mb;
}

From source file:com.jmstoolkit.queuebrowser.QueueBrowserView.java

/**
 * This method is called from within the constructor to
 * initialize the form./*from   w  w  w.  j  ava2  s.  com*/
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    mainPanel = new javax.swing.JPanel();
    destinationLabel = new javax.swing.JLabel();
    destinationComboBox = new javax.swing.JComboBox();
    browseButton = new javax.swing.JButton();
    cancelButton = new javax.swing.JButton();
    connectionFactoryLabel = new javax.swing.JLabel();
    connectionFactoryComboBox = new javax.swing.JComboBox();
    messageSplitPane = new javax.swing.JSplitPane();
    messagePropertiesSplitPane = new javax.swing.JSplitPane();
    messageScrollPane = new javax.swing.JScrollPane();
    messageTextArea = new javax.swing.JTextArea();
    messagePropertiesScrollPane = new javax.swing.JScrollPane();
    messagePropertiesTable = new javax.swing.JTable();
    messageRecordTableScrollPane = new javax.swing.JScrollPane();
    messageRecordTable = new javax.swing.JTable();
    menuBar = new javax.swing.JMenuBar();
    javax.swing.JMenu fileMenu = new javax.swing.JMenu();
    drainQueueMenuItem = new javax.swing.JMenuItem();
    javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
    javax.swing.JMenu helpMenu = new javax.swing.JMenu();
    javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
    statusPanel = new javax.swing.JPanel();
    javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
    statusMessageLabel = new javax.swing.JLabel();
    statusAnimationLabel = new javax.swing.JLabel();
    progressBar = new javax.swing.JProgressBar();
    messageTableModel = new com.jmstoolkit.beans.MessageTableModel();
    messagePropertyTableModel = new com.jmstoolkit.beans.PropertyTableModel();
    queueDrainedDialog = new javax.swing.JDialog();
    queueDrainedDialogOKButton = new javax.swing.JButton();
    itemsDrainedLabel = new javax.swing.JLabel();
    itemsDrainedTextField = new javax.swing.JTextField();
    queueDrainedScrollPane = new javax.swing.JScrollPane();
    queueDrainedTextPane = new javax.swing.JTextPane();

    org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance()
            .getContext().getResourceMap(QueueBrowserView.class);
    mainPanel.setBackground(resourceMap.getColor("mainPanel.background")); // NOI18N
    mainPanel.setForeground(resourceMap.getColor("mainPanel.foreground")); // NOI18N
    mainPanel.setName("mainPanel"); // NOI18N

    destinationLabel.setText(resourceMap.getString("destinationLabel.text")); // NOI18N
    destinationLabel.setName("destinationLabel"); // NOI18N

    destinationComboBox.setEditable(true);
    destinationComboBox.setModel(new javax.swing.DefaultComboBoxModel(destinationList.toArray()));
    destinationComboBox.setToolTipText(resourceMap.getString("destinationComboBox.toolTipText")); // NOI18N
    destinationComboBox.setName("destinationComboBox"); // NOI18N
    destinationComboBox.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            destinationComboBoxActionPerformed(evt);
        }
    });

    javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext()
            .getActionMap(QueueBrowserView.class, this);
    browseButton.setAction(actionMap.get("browseQueue")); // NOI18N
    browseButton.setText(resourceMap.getString("browseButton.text")); // NOI18N
    browseButton.setToolTipText(resourceMap.getString("browseButton.toolTipText")); // NOI18N
    browseButton.setName("browseButton"); // NOI18N

    cancelButton.setFont(resourceMap.getFont("cancelButton.font")); // NOI18N
    cancelButton.setText(resourceMap.getString("cancelButton.text")); // NOI18N
    cancelButton.setToolTipText(resourceMap.getString("cancelButton.toolTipText")); // NOI18N
    cancelButton.setEnabled(false);
    cancelButton.setName("cancelButton"); // NOI18N
    cancelButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            cancelButtonActionPerformed(evt);
        }
    });

    connectionFactoryLabel.setText(resourceMap.getString("connectionFactoryLabel.text")); // NOI18N
    connectionFactoryLabel.setName("connectionFactoryLabel"); // NOI18N

    connectionFactoryComboBox.setEditable(true);
    connectionFactoryComboBox.setModel(new javax.swing.DefaultComboBoxModel(connectionFactoryList.toArray()));
    connectionFactoryComboBox.setName("connectionFactoryComboBox"); // NOI18N
    connectionFactoryComboBox.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            connectionFactoryComboBoxActionPerformed(evt);
        }
    });

    messageSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
    messageSplitPane.setName("messageSplitPane"); // NOI18N
    messageSplitPane.setPreferredSize(new java.awt.Dimension(456, 400));

    messagePropertiesSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
    messagePropertiesSplitPane.setName("messagePropertiesSplitPane"); // NOI18N
    messagePropertiesSplitPane.setPreferredSize(new java.awt.Dimension(454, 200));

    messageScrollPane.setBackground(resourceMap.getColor("messageScrollPane.background")); // NOI18N
    messageScrollPane.setForeground(resourceMap.getColor("messageScrollPane.foreground")); // NOI18N
    messageScrollPane.setName("messageScrollPane"); // NOI18N

    messageTextArea.setBackground(resourceMap.getColor("messageTextArea.background")); // NOI18N
    messageTextArea.setColumns(20);
    messageTextArea.setForeground(resourceMap.getColor("messageTextArea.foreground")); // NOI18N
    messageTextArea.setLineWrap(true);
    messageTextArea.setRows(5);
    messageTextArea.setTabSize(2);
    messageTextArea.setToolTipText(resourceMap.getString("messageTextArea.toolTipText")); // NOI18N
    messageTextArea.setWrapStyleWord(true);
    messageTextArea.setName("messageTextArea"); // NOI18N
    messageScrollPane.setViewportView(messageTextArea);

    messagePropertiesSplitPane.setTopComponent(messageScrollPane);

    messagePropertiesScrollPane.setName("messagePropertiesScrollPane"); // NOI18N
    messagePropertiesScrollPane.setPreferredSize(new java.awt.Dimension(452, 202));

    messagePropertiesTable.setModel(messagePropertyTableModel);
    messagePropertiesTable.setAutoCreateRowSorter(true);
    messagePropertiesTable.setCellSelectionEnabled(true);
    messagePropertiesTable.setDoubleBuffered(true);
    messagePropertiesTable.setName("messagePropertiesTable"); // NOI18N
    messagePropertiesScrollPane.setViewportView(messagePropertiesTable);

    messagePropertiesSplitPane.setRightComponent(messagePropertiesScrollPane);

    messageSplitPane.setRightComponent(messagePropertiesSplitPane);

    messageRecordTableScrollPane.setName("messageRecordTableScrollPane"); // NOI18N
    messageRecordTableScrollPane.setPreferredSize(new java.awt.Dimension(452, 202));

    messageRecordTable.setModel(messageTableModel);
    messageRecordTable.setCellSelectionEnabled(true);
    messageRecordTable.setDoubleBuffered(true);
    messageRecordTable.setName("messageRecordTable"); // NOI18N
    messageRecordTable.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            messageRecordTableMouseClicked(evt);
        }
    });
    messageRecordTableScrollPane.setViewportView(messageRecordTable);

    messageSplitPane.setLeftComponent(messageRecordTableScrollPane);

    javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
    mainPanel.setLayout(mainPanelLayout);
    mainPanelLayout.setHorizontalGroup(mainPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup().addContainerGap().addGroup(mainPanelLayout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(mainPanelLayout.createSequentialGroup().addComponent(destinationLabel)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(destinationComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE))
                    .addGroup(mainPanelLayout.createSequentialGroup().addComponent(connectionFactoryLabel)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(connectionFactoryComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    240, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(browseButton)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(cancelButton).addGap(19, 19, 19))
            .addComponent(messageSplitPane, javax.swing.GroupLayout.DEFAULT_SIZE, 597, Short.MAX_VALUE));
    mainPanelLayout.setVerticalGroup(mainPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup().addContainerGap()
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(connectionFactoryLabel).addComponent(connectionFactoryComboBox,
                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(destinationLabel)
                            .addComponent(destinationComboBox, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cancelButton).addComponent(browseButton))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(
                            messageSplitPane, javax.swing.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE)));

    menuBar.setName("menuBar"); // NOI18N

    fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
    fileMenu.setName("fileMenu"); // NOI18N

    drainQueueMenuItem.setAction(actionMap.get("drainQueue")); // NOI18N
    drainQueueMenuItem.setText(resourceMap.getString("drainQueueMenuItem.text")); // NOI18N
    drainQueueMenuItem.setName("drainQueueMenuItem"); // NOI18N
    fileMenu.add(drainQueueMenuItem);

    exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
    exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X,
            java.awt.event.InputEvent.CTRL_MASK));
    exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
    exitMenuItem.setToolTipText(resourceMap.getString("exitMenuItem.toolTipText")); // NOI18N
    exitMenuItem.setName("exitMenuItem"); // NOI18N
    fileMenu.add(exitMenuItem);

    menuBar.add(fileMenu);

    helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
    helpMenu.setName("helpMenu"); // NOI18N

    aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
    aboutMenuItem.setName("aboutMenuItem"); // NOI18N
    helpMenu.add(aboutMenuItem);

    menuBar.add(helpMenu);

    statusPanel.setName("statusPanel"); // NOI18N
    statusPanel.setPreferredSize(new java.awt.Dimension(454, 30));

    statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

    statusMessageLabel.setAlignmentY(0.0F);
    statusMessageLabel.setName("statusMessageLabel"); // NOI18N

    statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

    progressBar.setName("progressBar"); // NOI18N

    javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
    statusPanel.setLayout(statusPanelLayout);
    statusPanelLayout.setHorizontalGroup(statusPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 597, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(statusMessageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 235,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 166, Short.MAX_VALUE)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(statusAnimationLabel).addContainerGap()));
    statusPanelLayout.setVerticalGroup(statusPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                    .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(statusPanelLayout.createSequentialGroup().addGroup(statusPanelLayout
                                    .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(statusMessageLabel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                            21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(statusAnimationLabel)).addGap(3, 3, 3))
                            .addGroup(statusPanelLayout.createSequentialGroup()
                                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE,
                                            javax.swing.GroupLayout.DEFAULT_SIZE,
                                            javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addContainerGap()))));

    messagePropertyTableModel.setData(messagePropertyTableModel.getData());

    queueDrainedDialog.setLocationByPlatform(true);
    queueDrainedDialog.setMinimumSize(new java.awt.Dimension(300, 180));
    queueDrainedDialog.setModal(true);
    queueDrainedDialog.setName("queueDrainedDialog"); // NOI18N
    queueDrainedDialog.setResizable(false);

    queueDrainedDialogOKButton.setText(resourceMap.getString("queueDrainedDialogOKButton.text")); // NOI18N
    queueDrainedDialogOKButton.setName("queueDrainedDialogOKButton"); // NOI18N
    queueDrainedDialogOKButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            queueDrainedDialogOKButtonActionPerformed(evt);
        }
    });

    itemsDrainedLabel.setText(resourceMap.getString("itemsDrainedLabel.text")); // NOI18N
    itemsDrainedLabel.setName("itemsDrainedLabel"); // NOI18N

    itemsDrainedTextField.setEditable(false);
    itemsDrainedTextField.setText(resourceMap.getString("itemsDrainedTextField.text")); // NOI18N
    itemsDrainedTextField.setName("itemsDrainedTextField"); // NOI18N

    queueDrainedScrollPane.setName("queueDrainedScrollPane"); // NOI18N

    queueDrainedTextPane.setEditable(false);
    queueDrainedTextPane.setText(resourceMap.getString("queueDrainedTextPane.text")); // NOI18N
    queueDrainedTextPane.setName("queueDrainedTextPane"); // NOI18N
    queueDrainedScrollPane.setViewportView(queueDrainedTextPane);

    javax.swing.GroupLayout queueDrainedDialogLayout = new javax.swing.GroupLayout(
            queueDrainedDialog.getContentPane());
    queueDrainedDialog.getContentPane().setLayout(queueDrainedDialogLayout);
    queueDrainedDialogLayout.setHorizontalGroup(queueDrainedDialogLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(queueDrainedDialogLayout.createSequentialGroup().addGroup(queueDrainedDialogLayout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(queueDrainedDialogLayout.createSequentialGroup().addContainerGap()
                            .addComponent(itemsDrainedLabel)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(itemsDrainedTextField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(queueDrainedDialogLayout.createSequentialGroup().addContainerGap().addComponent(
                            queueDrainedScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE))
                    .addGroup(queueDrainedDialogLayout.createSequentialGroup().addGap(127, 127, 127)
                            .addComponent(queueDrainedDialogOKButton)))
                    .addContainerGap()));
    queueDrainedDialogLayout.setVerticalGroup(
            queueDrainedDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(queueDrainedDialogLayout.createSequentialGroup().addContainerGap()
                            .addGroup(queueDrainedDialogLayout
                                    .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(itemsDrainedLabel).addComponent(itemsDrainedTextField,
                                            javax.swing.GroupLayout.PREFERRED_SIZE,
                                            javax.swing.GroupLayout.DEFAULT_SIZE,
                                            javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(queueDrainedScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 59,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(queueDrainedDialogOKButton).addGap(32, 32, 32)));

    setComponent(mainPanel);
    setMenuBar(menuBar);
    setStatusBar(statusPanel);
}

From source file:atlas.kingj.roi.FrmMain.java

/**
 * Initialize the contents of the frame.
 *///from   w ww. j a  v  a2 s  .  c o m
private void initialize() {

    frmTitanRoiCalculator = new JFrame();
    frmTitanRoiCalculator.addWindowListener(new FrmTitanRoiCalculatorWindowListener());
    frmTitanRoiCalculator.setResizable(false);
    frmTitanRoiCalculator.setTitle("Titan Production Calculator");
    try {
        frmTitanRoiCalculator.setIconImage(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/logo.png")));//Toolkit.getDefaultToolkit().getImage(FrmMain.class.getResource("/atlas/logo.png")));
    } catch (NullPointerException e) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    frmTitanRoiCalculator.setBounds(100, 100, 800, 600);
    frmTitanRoiCalculator.setLocationRelativeTo(null);
    frmTitanRoiCalculator.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);//JFrame.EXIT_ON_CLOSE);

    JMenuBar menuBar = new JMenuBar();
    frmTitanRoiCalculator.setJMenuBar(menuBar);

    JMenu mnFile = new JMenu("File");
    mnFile.setMnemonic('F');
    menuBar.add(mnFile);

    mntmOpen = new JMenuItem("Open");
    mntmOpen.setMnemonic('O');
    mntmOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));
    mntmOpen.addActionListener(new MntmOpenActionListener());
    mnFile.add(mntmOpen);

    mntmSave = new JMenuItem("Save");
    mntmSave.setMnemonic('S');
    mntmSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
    mntmSave.addActionListener(new MntmSaveActionListener());
    mnFile.add(mntmSave);

    JMenuItem mntmExit = new JMenuItem("Exit");
    mntmExit.setMnemonic('X');
    mntmExit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            SaveAndClose();
        }
    });

    mntmSaveAll = new JMenuItem("Save All");
    mntmSaveAll.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            SaveAll();
        }
    });

    mntmOpenAll = new JMenuItem("Open All");
    mntmOpenAll.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            OpenAll();
        }
    });
    mnFile.add(mntmOpenAll);
    mntmSaveAll.setMnemonic('V');
    mnFile.add(mntmSaveAll);

    mnExport = new JMenu("Export");
    mnFile.add(mnExport);

    mntmSpreadsheet = new JMenuItem("Spreadsheet");
    mntmSpreadsheet.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            ResetStatusLabel();

            fc = new OpenSaveFileChooser();
            fc.setFileFilter(new XLSfilter());
            fc.type = 3;

            int returnVal = fc.showSaveDialog(frmTitanRoiCalculator);
            if (returnVal == JFileChooser.APPROVE_OPTION) {

                File file = fc.getSelectedFile();

                String path = file.getAbsolutePath();

                String extension = ".xls";

                if (!path.endsWith(extension)) {
                    file = new File(path + extension);
                }

                StatusDialog a = new StatusDialog("Generating spreadsheet...");

                SaveFileWorker worker = new SaveFileWorker(file, a, false);

                worker.execute();

                a.setLocationRelativeTo(frmTitanRoiCalculator);
                a.setVisible(true);

                if (FileSaveError)
                    ShowMessage("File save error");
                else if (FileSaveWarning)
                    ShowMessage("File saved, but possible errors.");
                else
                    ShowMessageSuccess("File saved.");

            }
        }
    });
    mnExport.add(mntmSpreadsheet);
    mnFile.add(mntmExit);

    JMenu mnView = new JMenu("View");
    mnView.setMnemonic('V');
    menuBar.add(mnView);

    RoiData = new ROIData();

    mntmUnitConverter = new JMenuItem("Unit Converter");
    mntmUnitConverter.setMnemonic('C');
    mntmUnitConverter.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK));
    mntmUnitConverter.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            new UnitConverter();
        }
    });
    mnView.add(mntmUnitConverter);

    mnSettings = new JMenu("Settings");
    mnSettings.setMnemonic('E');
    menuBar.add(mnSettings);

    mnUnits = new JMenu("Units");
    mnUnits.setMnemonic('U');
    mnSettings.add(mnUnits);

    rdbtnmntmImperial = new JRadioButtonMenuItem("Imperial");
    rdbtnmntmImperial.setMnemonic('I');
    rdbtnmntmImperial.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_MASK));
    rdbtnmntmImperial.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (metric) {
                // Change units from metric to imperial
                ChangeUnits();
            }
        }
    });
    mnUnits.add(rdbtnmntmImperial);

    rdbtnmntmMetric = new JRadioButtonMenuItem("Metric");
    rdbtnmntmMetric.setMnemonic('M');
    rdbtnmntmMetric.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, InputEvent.CTRL_MASK));
    rdbtnmntmMetric.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (!metric) {
                // Change units from imperial to metric
                ChangeUnits();
            }
        }
    });
    rdbtnmntmMetric.setSelected(true);
    mnUnits.add(rdbtnmntmMetric);

    btnsUnits.add(rdbtnmntmMetric);
    btnsUnits.add(rdbtnmntmImperial);

    JMenuItem mntmOptions_1 = new JMenuItem("Options");
    mntmOptions_1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_MASK));
    mntmOptions_1.setMnemonic('O');
    mntmOptions_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            Machine machine = null;
            if (listMachines.getSelectedIndex() > -1)
                machine = (Machine) listMachines.getSelectedValue();
            OptionDialog options = new OptionDialog(environment, machine);
            options.setLocationRelativeTo(frmTitanRoiCalculator);
            options.addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosed(WindowEvent e) {
                    UpdateAnalysis();
                }
            });
            options.setVisible(true);
        }
    });

    mnTimings = new JMenu("Timings");
    mnSettings.add(mnTimings);

    mntmSaveToFile = new JMenuItem("Save to File");
    mntmSaveToFile.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            OperatorTimings times = environment.timings;

            fc = new OpenSaveFileChooser();
            fc.setFileFilter(new OBJfilter(3));
            fc.type = 1;

            int returnVal = fc.showSaveDialog(frmTitanRoiCalculator);
            if (returnVal == JFileChooser.APPROVE_OPTION) {

                File file = fc.getSelectedFile();

                String path = file.getAbsolutePath();

                String extension = ".ser";

                if (!path.endsWith(extension)) {
                    file = new File(path + extension);
                }

                try {
                    FileOutputStream fout = new FileOutputStream(file);
                    ObjectOutputStream oos = new ObjectOutputStream(fout);
                    oos.writeObject(times);
                    oos.close();
                    ShowMessageSuccess("File saved.");
                } catch (Exception e1) {
                    JOptionPane.showMessageDialog(frmTitanRoiCalculator, "Error writing file.", "Error",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    });
    mnTimings.add(mntmSaveToFile);

    mntmLoadFromFile = new JMenuItem("Load from File");
    mntmLoadFromFile.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            fc = new OpenSaveFileChooser();
            fc.setFileFilter(new OBJfilter(3));
            fc.type = 1;

            int returnVal = fc.showOpenDialog(frmTitanRoiCalculator);
            if (returnVal == JFileChooser.APPROVE_OPTION) {

                File file = fc.getSelectedFile();

                try {
                    FileInputStream fin = new FileInputStream(file);
                    ObjectInputStream ois = new ObjectInputStream(fin);
                    environment.timings = (OperatorTimings) ois.readObject();
                    ois.close();

                    ShowMessageSuccess("File loaded.");

                } catch (Exception e1) {
                    ShowMessage("File error.");
                }
            }
        }
    });
    mnTimings.add(mntmLoadFromFile);
    mnSettings.add(mntmOptions_1);

    JMenu mnHelp = new JMenu("Help");
    mnHelp.setMnemonic('H');
    menuBar.add(mnHelp);

    JMenuItem mntmInstructions = new JMenuItem("Instructions");
    mntmInstructions.setMnemonic('I');
    mntmInstructions.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            InstructDialog instructions = new InstructDialog();
            instructions.setLocationRelativeTo(frmTitanRoiCalculator);
            instructions.setVisible(true);
        }
    });
    mnHelp.add(mntmInstructions);

    JMenuItem mntmAbout = new JMenuItem("About");
    mntmAbout.setMnemonic('A');
    mntmAbout.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            AboutDialog about = new AboutDialog();
            about.setLocationRelativeTo(frmTitanRoiCalculator);
            about.setVisible(true);
        }
    });
    mnHelp.add(mntmAbout);

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.addChangeListener(TabChangeListener);
    frmTitanRoiCalculator.getContentPane().add(tabbedPane, BorderLayout.CENTER);

    pnlMachine = new JPanel();
    tabbedPane.addTab("Machine Selection", null, pnlMachine, "Add and configure machine setups");
    tabbedPane.setEnabledAt(0, true);
    pnlMachine.setLayout(null);

    grpMachines = new JPanel();
    grpMachines.setFont(new Font("Tahoma", Font.PLAIN, 11));
    grpMachines.setBounds(20, 72, 182, 256);
    grpMachines.setBorder(
            new TitledBorder(null, "Machine Type", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    pnlMachine.add(grpMachines);
    grpMachines.setLayout(null);

    try {
        rdbtnER610 = new JRadioButton(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/er610.png"))));
        rdbtnER610.setDisabledIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/er610_dis.png"))));
        rdbtnER610.setDisabledSelectedIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/er610_dis.png"))));
        rdbtnER610.setEnabled(false);
        rdbtnER610.setToolTipText("Titan ER610");
    } catch (NullPointerException e1) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    rdbtnER610.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            rdbtnClick("ER610");
            UpdateMachine();
            listMachines.repaint();
        }
    });
    rdbtnER610.setSelected(true);
    rdbtnER610.setBounds(13, 24, 155, 40);
    try {
        rdbtnER610.setPressedIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/er610_down.png"))));
        rdbtnER610.setRolloverEnabled(true);
        rdbtnER610.setRolloverIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/er610_over.png"))));
        rdbtnER610.setSelectedIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/er610_select.png"))));
    } catch (NullPointerException e11) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    grpMachines.add(rdbtnER610);

    try {
        rdbtnSR9DS = new JRadioButton(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/sr9ds.png"))));
        rdbtnSR9DS.setDisabledIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/sr9ds_dis.png"))));
        rdbtnSR9DS.setEnabled(false);
        rdbtnSR9DS.setToolTipText("Titan SR9-DS");
    } catch (NullPointerException e11) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    rdbtnSR9DS.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            rdbtnClick("SR9DS");
            UpdateMachine();
            listMachines.repaint();
        }
    });

    try {
        rdbtnSR9DS.setPressedIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/sr9ds_down.png"))));
        rdbtnSR9DS.setRolloverEnabled(true);
        rdbtnSR9DS.setRolloverIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/sr9ds_over.png"))));
        rdbtnSR9DS.setSelectedIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/sr9ds_select.png"))));
        rdbtnSR9DS.setBounds(13, 68, 155, 40);
        grpMachines.add(rdbtnSR9DS);

        rdbtnSR9DT = new JRadioButton(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/sr9dt.png"))));
        rdbtnSR9DT.setDisabledIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/sr9dt_dis.png"))));
        rdbtnSR9DT.setEnabled(false);
        rdbtnSR9DT.setToolTipText("Titan SR9-DT");
    } catch (NullPointerException e11) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    rdbtnSR9DT.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            rdbtnClick("SR9DT");
            UpdateMachine();
            listMachines.repaint();
        }
    });
    rdbtnSR9DT.setBounds(13, 112, 155, 40);
    try {
        rdbtnSR9DT.setPressedIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/sr9dt_down.png"))));
        rdbtnSR9DT.setRolloverEnabled(true);
        rdbtnSR9DT.setRolloverIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/sr9dt_over.png"))));
        rdbtnSR9DT.setSelectedIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/sr9dt_select.png"))));
    } catch (NullPointerException e11) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    grpMachines.add(rdbtnSR9DT);

    try {
        rdbtnSR800 = new JRadioButton(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/sr800.png"))));
        rdbtnSR800.setDisabledIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/sr800_dis.png"))));
        rdbtnSR800.setEnabled(false);
        rdbtnSR800.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                rdbtnClick("SR800");
                UpdateMachine();
                listMachines.repaint();
            }
        });
        rdbtnSR800.setPressedIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/sr800_down.png"))));
        rdbtnSR800.setRolloverEnabled(true);
        rdbtnSR800.setRolloverIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/sr800_over.png"))));
        rdbtnSR800.setSelectedIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/sr800_select.png"))));
    } catch (IOException e2) {
        e2.printStackTrace();
    }
    rdbtnSR800.setToolTipText("Titan SR800");
    rdbtnSR800.setRolloverEnabled(true);
    rdbtnSR800.setBounds(13, 156, 155, 40);
    grpMachines.add(rdbtnSR800);

    try {
        rdbtnCustom = new JRadioButton(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/custom.png"))));
        rdbtnCustom.setDisabledIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/custom_dis.png"))));
        rdbtnCustom.setEnabled(false);
        rdbtnCustom.setPressedIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/custom_down.png"))));
        rdbtnCustom.setRolloverEnabled(true);
        rdbtnCustom.setRolloverIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/custom_over.png"))));
        rdbtnCustom.setSelectedIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/custom_select.png"))));
    } catch (IOException e2) {
        e2.printStackTrace();
    }
    rdbtnCustom.setToolTipText("Custom Machine");
    rdbtnCustom.setRolloverEnabled(true);
    rdbtnCustom.setBounds(13, 200, 155, 40);
    grpMachines.add(rdbtnCustom);
    rdbtnCustom.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            rdbtnClick("Custom");
            UpdateMachine();
            ResetStatusLabel();
            listMachines.repaint();
        }
    });

    rdbtnsMachines.add(rdbtnER610);
    rdbtnsMachines.add(rdbtnSR9DS);
    rdbtnsMachines.add(rdbtnSR9DT);
    rdbtnsMachines.add(rdbtnSR800);
    rdbtnsMachines.add(rdbtnCustom);

    grpVariants = new JPanel();
    grpVariants.setFont(new Font("Tahoma", Font.PLAIN, 11));
    grpVariants.setBounds(20, 339, 482, 112);
    grpVariants
            .setBorder(new TitledBorder(null, "Variants", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    pnlMachine.add(grpVariants);
    grpVariants.setLayout(null);

    cmbCorepos = new JComboBox();
    cmbCorepos.setFont(new Font("Tahoma", Font.PLAIN, 11));
    cmbCorepos.setToolTipText("Set the core positioning system");
    cmbCorepos.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (formReady)
                UpdateMachine();
        }
    });
    cmbCorepos.setEnabled(false);
    cmbCorepos.setBounds(104, 70, 122, 20);
    grpVariants.add(cmbCorepos);
    cmbCorepos.setModel(new DefaultComboBoxModel(new String[] { "Manual", "Laser" }));

    lblCorePositioning = new JLabel("Core Positioning:");
    lblCorePositioning.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblCorePositioning.setToolTipText("Set the core positioning system");
    lblCorePositioning.setEnabled(false);
    lblCorePositioning.setHorizontalAlignment(SwingConstants.RIGHT);
    lblCorePositioning.setBounds(12, 73, 88, 14);
    grpVariants.add(lblCorePositioning);

    lblKnifeControl = new JLabel("Knife Control:");
    lblKnifeControl.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblKnifeControl.setToolTipText("Set the type of knife positioning system");
    lblKnifeControl.setEnabled(false);
    lblKnifeControl.setHorizontalAlignment(SwingConstants.RIGHT);
    lblKnifeControl.setBounds(22, 48, 78, 14);
    grpVariants.add(lblKnifeControl);

    cmbKnives = new JComboBox();
    cmbKnives.setFont(new Font("Tahoma", Font.PLAIN, 11));
    cmbKnives.setToolTipText("Set the type of knife positioning system");
    cmbKnives.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (formReady)
                UpdateMachine();
        }
    });
    cmbKnives.setEnabled(false);
    cmbKnives.setBounds(104, 45, 122, 20);
    grpVariants.add(cmbKnives);
    cmbKnives.setModel(new DefaultComboBoxModel(new String[] { "Manual", "Auto" }));

    cmbUnloader = new JComboBox();
    cmbUnloader.setFont(new Font("Tahoma", Font.PLAIN, 11));
    cmbUnloader.setToolTipText("Set the unloader type");
    cmbUnloader.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (formReady)
                UpdateMachine();
        }
    });
    cmbUnloader.setEnabled(false);
    cmbUnloader.setBounds(350, 20, 122, 20);
    grpVariants.add(cmbUnloader);
    cmbUnloader.setModel(new DefaultComboBoxModel(new String[] { "Manual", "Pneumatic", "Electric" }));

    lblUnloader = new JLabel("Unloader:");
    lblUnloader.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblUnloader.setToolTipText("Set the unloader type");
    lblUnloader.setEnabled(false);
    lblUnloader.setHorizontalAlignment(SwingConstants.RIGHT);
    lblUnloader.setBounds(259, 23, 87, 14);
    grpVariants.add(lblUnloader);

    cmbSpeed = new JComboBox();
    cmbSpeed.setFont(new Font("Tahoma", Font.PLAIN, 11));
    cmbSpeed.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (formReady)
                UpdateMachine();
        }
    });
    cmbSpeed.setEnabled(false);
    cmbSpeed.setToolTipText("Machine top speed in metres/min");
    cmbSpeed.setBounds(104, 20, 122, 20);
    grpVariants.add(cmbSpeed);
    cmbSpeed.setModel(new DefaultComboBoxModel(new String[] { "450", "550" }));

    lblSpeed = new JLabel("Speed:");
    lblSpeed.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblSpeed.setToolTipText("Machine top speed in metres/min");
    lblSpeed.setEnabled(false);
    lblSpeed.setHorizontalAlignment(SwingConstants.RIGHT);
    lblSpeed.setBounds(54, 23, 46, 14);
    grpVariants.add(lblSpeed);

    cmbUnwindDrive = new JComboBox();
    cmbUnwindDrive.setFont(new Font("Tahoma", Font.PLAIN, 11));
    cmbUnwindDrive.setToolTipText("Unwind drive type");
    cmbUnwindDrive.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (formReady)
                UpdateMachine();
        }
    });
    cmbUnwindDrive.setEnabled(false);
    cmbUnwindDrive.setBounds(350, 45, 122, 20);
    grpVariants.add(cmbUnwindDrive);
    cmbUnwindDrive.setModel(new DefaultComboBoxModel(new String[] { "Single", "Double" }));

    lblUnwindDrive = new JLabel("Unwind Drive:");
    lblUnwindDrive.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblUnwindDrive.setToolTipText("Unwind drive type");
    lblUnwindDrive.setEnabled(false);
    lblUnwindDrive.setHorizontalAlignment(SwingConstants.RIGHT);
    lblUnwindDrive.setBounds(259, 48, 87, 14);
    grpVariants.add(lblUnwindDrive);

    lblRewindControlLoop = new JLabel("Rewind Control Loop:");
    lblRewindControlLoop.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblRewindControlLoop.setToolTipText("Rewind control loop type");
    lblRewindControlLoop.setEnabled(false);
    lblRewindControlLoop.setHorizontalAlignment(SwingConstants.RIGHT);
    lblRewindControlLoop.setBounds(224, 73, 122, 14);
    grpVariants.add(lblRewindControlLoop);

    cmbRewindCtrl = new JComboBox();
    cmbRewindCtrl.setFont(new Font("Tahoma", Font.PLAIN, 11));
    cmbRewindCtrl.setToolTipText("Rewind control loop type");
    cmbRewindCtrl.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (formReady)
                UpdateMachine();
        }
    });
    cmbRewindCtrl.setEnabled(false);
    cmbRewindCtrl.setBounds(350, 70, 122, 20);
    grpVariants.add(cmbRewindCtrl);
    cmbRewindCtrl.setModel(new DefaultComboBoxModel(new String[] { "Open", "Closed" }));

    listModel = new DefaultListModel();
    jobModel = new DefaultListModel();
    scheduleModel = new DefaultListModel();
    listModel.removeAllElements();
    /*listMachines.setModel(new AbstractListModel() {
       String[] values = new String[] {"ER610: My test 1", "SR9-DS: this is another test", "SR9-DT: third test", "ER610:  test 2", "ER610: bla bla", "SR9-DS: this is another test", "SR9-DT: hello", "SR9-DT: third test"};
       public int getSize() {
    return values.length;
       }
       public Object getElementAt(int index) {
    return values[index];
       }
    });*/

    JLabel lblMachines = new JLabel("Machines");
    lblMachines.setFont(new Font("Tahoma", Font.BOLD, 12));
    lblMachines.setBounds(522, 19, 85, 14);
    pnlMachine.add(lblMachines);

    btnMachDelete = new JButton("");
    try {
        btnMachDelete
                .setIcon(new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/delete.png"))));
        btnMachDelete.setRolloverEnabled(true);
        btnMachDelete.setRolloverIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/delete_over.png"))));
        btnMachDelete.setDisabledIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/delete_dis.png"))));
    } catch (NullPointerException e11) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    btnMachDelete.setToolTipText("Delete machine");
    btnMachDelete.setEnabled(false);
    btnMachDelete.addActionListener(new DeleteButtonListener());
    btnMachDelete.setBounds(651, 460, 36, 36);
    pnlMachine.add(btnMachDelete);

    btnMachUp = new JButton("");
    btnMachUp.setToolTipText("Move machine up");
    btnMachUp.setEnabled(false);
    try {
        btnMachUp.setIcon(new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/up.png"))));
        btnMachUp.setRolloverEnabled(true);
        btnMachUp.setRolloverIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/up_over.png"))));
        btnMachUp.setDisabledIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/up_dis.png"))));
    } catch (NullPointerException e11) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    btnMachUp.addActionListener(new UpListener());
    btnMachUp.setBounds(700, 463, 30, 30);
    pnlMachine.add(btnMachUp);

    btnMachDown = new JButton("");
    btnMachDown.setToolTipText("Move machine down");
    btnMachDown.setEnabled(false);
    try {
        btnMachDown.setIcon(new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/down.png"))));
        btnMachDown.setRolloverEnabled(true);
        btnMachDown.setRolloverIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/down_over.png"))));
        btnMachDown.setDisabledIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/down_dis.png"))));
    } catch (NullPointerException e11) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    btnMachDown.addActionListener(new DownListener());
    btnMachDown.setBounds(737, 463, 30, 30);
    pnlMachine.add(btnMachDown);

    btnMachReset = new JButton("Reset");
    btnMachReset.setFont(new Font("Tahoma", Font.PLAIN, 11));
    btnMachReset.setEnabled(false);
    btnMachReset.setToolTipText("Reset the form");
    btnMachReset.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            ResetForm();
        }
    });

    btnMachReset.setBounds(20, 460, 100, 36);
    pnlMachine.add(btnMachReset);
    /*txtMachName.addKeyListener(new KeyAdapter() {
       @Override
       public void keyPressed(KeyEvent e) {
    int key = e.getKeyCode();  
    if (e.getKeyCode() == KeyEvent.VK_ENTER)  
       btnAddMachine.doClick();
       }
    });*/

    btnNewMachine = new JButton("Add New");
    btnNewMachine.setFont(new Font("Tahoma", Font.BOLD, 11));
    btnNewMachine.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            formReady = false;

            ResetStatusLabel();

            int index = listMachines.getSelectedIndex();
            int size = listModel.getSize();

            if (size >= Consts.MACH_LIST_LIMIT) { // Max list size
                ShowMessage(
                        "Maximum number of machines allocated. Please delete before attempting to add more.");
                return;
            }

            String newName = getUniqueName("Machine");
            txtMachName.setText(newName);
            machine = new Machine(newName);
            machNames.add(newName.toLowerCase());

            //If no selection or if item in last position is selected,
            //add the new one to end of list, and select new one.
            if (index == -1 || (index + 1 == size)) {

                listModel.addElement(machine);
                listMachines.setSelectedIndex(size);

                RoiData.energies.add(RoiData.new EnergyData());
                RoiData.maintenance.add(RoiData.new MaintData());
                listCompare.addSelectionInterval(size, size);

                //Otherwise insert the new one after the current selection,
                //and select new one.
            } else {
                int[] sel = listCompare.getSelectedIndices();
                int[] selection = new int[sel.length + 1];
                System.arraycopy(sel, 0, selection, 0, sel.length);
                listCompare.setSelectedIndices(new int[] {});
                listModel.insertElementAt(machine, index + 1);

                boolean max = false;
                for (int i = 0; i < selection.length; i++) {
                    if (selection[i] >= index + 1 && !max) {
                        if (i < selection.length - 1)
                            System.arraycopy(selection, i, selection, i + 1, selection.length - i - 1);
                        selection[i] = index + 1;
                        max = true;
                    } else if (selection[i] >= index + 1)
                        selection[i] = selection[i] + 1;
                }
                RoiData.energies.add(index + 1, RoiData.new EnergyData());
                RoiData.maintenance.add(index + 1, RoiData.new MaintData());
                listCompare.setSelectedIndices(selection);
                //listCompareRoi.setSelectedIndices(selection);
                listMachines.setSelectedIndex(index + 1);
                //listCompare.addSelectionInterval(index + 1, index + 1);
            }

            ResetStatusLabel();
            //UpdateForm();  already triggered in listchanged
            formReady = true;
            txtMachName.requestFocusInWindow();
        }
    });
    try {
        btnNewMachine
                .setIcon(new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/plus.png"))));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    btnNewMachine.setToolTipText("Add new machine");
    btnNewMachine.setBounds(522, 460, 110, 36);
    pnlMachine.add(btnNewMachine);

    grpOptions = new JPanel();
    grpOptions.setFont(new Font("Tahoma", Font.PLAIN, 11));
    grpOptions.setBounds(212, 72, 290, 256);
    pnlMachine.add(grpOptions);
    grpOptions.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Options",
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    grpOptions.setLayout(null);

    chckbxFlag = new JCheckBox("Flag Detection");
    chckbxFlag.setFont(new Font("Tahoma", Font.PLAIN, 11));
    chckbxFlag.setToolTipText("Whether an automatic flag detection system is used");
    chckbxFlag.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (formReady)
                UpdateMachine();
            if (!chckbxFlag.isSelected())
                chckbxSelectAll.setSelected(false);
            else
                UpdateSelectAllChckbx();
        }
    });
    chckbxFlag.setEnabled(false);
    chckbxFlag.setBounds(155, 104, 109, 23);
    grpOptions.add(chckbxFlag);

    chckbxSpliceTable = new JCheckBox("Splice Table");
    chckbxSpliceTable.setFont(new Font("Tahoma", Font.PLAIN, 11));
    chckbxSpliceTable.setToolTipText("Whether a splice table is fitted");
    chckbxSpliceTable.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (formReady)
                UpdateMachine();
            if (!chckbxSpliceTable.isSelected())
                chckbxSelectAll.setSelected(false);
            else
                UpdateSelectAllChckbx();
        }
    });
    chckbxSpliceTable.setEnabled(false);
    chckbxSpliceTable.setBounds(22, 104, 109, 23);
    grpOptions.add(chckbxSpliceTable);

    chckbxAlignmentGuide = new JCheckBox("Alignment Guide");
    chckbxAlignmentGuide.setFont(new Font("Tahoma", Font.PLAIN, 11));
    chckbxAlignmentGuide.setToolTipText("Whether an alignment guide is fitted");
    chckbxAlignmentGuide.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (formReady)
                UpdateMachine();
            if (!chckbxAlignmentGuide.isSelected())
                chckbxSelectAll.setSelected(false);
            else
                UpdateSelectAllChckbx();
        }
    });
    chckbxAlignmentGuide.setEnabled(false);
    chckbxAlignmentGuide.setBounds(22, 130, 127, 23);
    grpOptions.add(chckbxAlignmentGuide);

    chckbxRollConditioning = new JCheckBox("Roll Conditioning");
    chckbxRollConditioning.setFont(new Font("Tahoma", Font.PLAIN, 11));
    chckbxRollConditioning.setToolTipText("Whether the machine supports roll conditioning");
    chckbxRollConditioning.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (formReady)
                UpdateMachine();
            if (!chckbxRollConditioning.isSelected())
                chckbxSelectAll.setSelected(false);
            else
                UpdateSelectAllChckbx();
        }
    });
    chckbxRollConditioning.setEnabled(false);
    chckbxRollConditioning.setBounds(22, 156, 127, 23);
    grpOptions.add(chckbxRollConditioning);

    chckbxTurretSupport = new JCheckBox("Turret Support");
    chckbxTurretSupport.setFont(new Font("Tahoma", Font.PLAIN, 11));
    chckbxTurretSupport.setToolTipText("For dual turret machines: extra turret support");
    chckbxTurretSupport.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (formReady)
                UpdateMachine();
            if (!chckbxTurretSupport.isSelected())
                chckbxSelectAll.setSelected(false);
            else
                UpdateSelectAllChckbx();
        }
    });
    chckbxTurretSupport.setEnabled(false);
    chckbxTurretSupport.setBounds(22, 182, 127, 23);
    grpOptions.add(chckbxTurretSupport);

    chckbxAutostripping = new JCheckBox("Autostripping");
    chckbxAutostripping.setFont(new Font("Tahoma", Font.PLAIN, 11));
    chckbxAutostripping.setToolTipText("Whether an autostripping feature is present for reel unloading");
    chckbxAutostripping.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (formReady)
                UpdateMachine();
            if (!chckbxAutostripping.isSelected())
                chckbxSelectAll.setSelected(false);
            else
                UpdateSelectAllChckbx();
        }
    });
    chckbxAutostripping.setEnabled(false);
    chckbxAutostripping.setBounds(22, 208, 97, 23);
    grpOptions.add(chckbxAutostripping);

    chckbxExtraRewind = new JCheckBox("850mm Rewind");
    chckbxExtraRewind.setFont(new Font("Tahoma", Font.PLAIN, 11));
    chckbxExtraRewind.setToolTipText("Extra wide 850mm max diameter rewind support");
    chckbxExtraRewind.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (formReady)
                UpdateMachine();
            if (!chckbxExtraRewind.isSelected())
                chckbxSelectAll.setSelected(false);
            else
                UpdateSelectAllChckbx();
        }
    });
    chckbxExtraRewind.setEnabled(false);
    chckbxExtraRewind.setBounds(155, 208, 109, 23);
    grpOptions.add(chckbxExtraRewind);

    chckbxAutoCutoff = new JCheckBox("Auto Cut-off");
    chckbxAutoCutoff.setFont(new Font("Tahoma", Font.PLAIN, 11));
    chckbxAutoCutoff.setToolTipText("Whether the web is cut automatically when a run completes");
    chckbxAutoCutoff.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (formReady)
                UpdateMachine();
            if (!chckbxAutoCutoff.isSelected())
                chckbxSelectAll.setSelected(false);
            else
                UpdateSelectAllChckbx();
        }
    });
    chckbxAutoCutoff.setEnabled(false);
    chckbxAutoCutoff.setBounds(155, 130, 109, 23);
    grpOptions.add(chckbxAutoCutoff);

    chckbxAutoTapeCore = new JCheckBox("Auto Tape Core");
    chckbxAutoTapeCore.setFont(new Font("Tahoma", Font.PLAIN, 11));
    chckbxAutoTapeCore.setToolTipText("Whether new reels are automatically taped before a run begins");
    chckbxAutoTapeCore.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (formReady)
                UpdateMachine();
            if (!chckbxAutoTapeCore.isSelected())
                chckbxSelectAll.setSelected(false);
            else
                UpdateSelectAllChckbx();
        }
    });
    chckbxAutoTapeCore.setEnabled(false);
    chckbxAutoTapeCore.setBounds(155, 156, 109, 23);
    grpOptions.add(chckbxAutoTapeCore);

    chckbxAutoTapeTail = new JCheckBox("Auto Tape Tail");
    chckbxAutoTapeTail.setFont(new Font("Tahoma", Font.PLAIN, 11));
    chckbxAutoTapeTail.setToolTipText("Whether the tails of completed reels are automatically taped down");
    chckbxAutoTapeTail.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (formReady)
                UpdateMachine();
            if (!chckbxAutoTapeTail.isSelected())
                chckbxSelectAll.setSelected(false);
            else
                UpdateSelectAllChckbx();
        }
    });
    chckbxAutoTapeTail.setEnabled(false);
    chckbxAutoTapeTail.setBounds(155, 182, 109, 23);
    grpOptions.add(chckbxAutoTapeTail);

    txtMachName = new JTextField();
    txtMachName.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtMachName.selectAll();
        }
    });
    txtMachName.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent arg0) {
        }

        @Override
        public void insertUpdate(DocumentEvent arg0) {
            UpdateMachineName();
        }

        @Override
        public void removeUpdate(DocumentEvent arg0) {
            UpdateMachineName();
        }
    });
    txtMachName.setEnabled(false);
    txtMachName.setBounds(125, 35, 137, 28);
    grpOptions.add(txtMachName);
    txtMachName.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
        }

        public void removeUpdate(DocumentEvent e) {
            // text was deleted
        }

        public void insertUpdate(DocumentEvent e) {
            // text was inserted
        }
    });

    txtMachName.setToolTipText("Enter a name to refer to this particular machine by");
    txtMachName.setFont(new Font("Tahoma", Font.BOLD, 12));
    txtMachName.setColumns(10);

    lblMachName = new JLabel("Machine name:");
    lblMachName.setToolTipText("Enter a name to refer to this particular machine by");
    lblMachName.setEnabled(false);
    lblMachName.setBounds(26, 36, 91, 24);
    grpOptions.add(lblMachName);
    lblMachName.setFont(new Font("Tahoma", Font.PLAIN, 13));

    chckbxSelectAll = new JCheckBox("Select All");
    chckbxSelectAll.setFont(new Font("Tahoma", Font.PLAIN, 11));
    chckbxSelectAll.setToolTipText("Select all available options");
    chckbxSelectAll.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (chckbxSelectAll.isSelected()) {
                if (chckbxAlignmentGuide.isEnabled())
                    chckbxAlignmentGuide.setSelected(true);
                if (chckbxAutoCutoff.isEnabled())
                    chckbxAutoCutoff.setSelected(true);
                if (chckbxAutostripping.isEnabled())
                    chckbxAutostripping.setSelected(true);
                if (chckbxAutoTapeCore.isEnabled())
                    chckbxAutoTapeCore.setSelected(true);
                if (chckbxAutoTapeTail.isEnabled())
                    chckbxAutoTapeTail.setSelected(true);
                if (chckbxExtraRewind.isEnabled())
                    chckbxExtraRewind.setSelected(true);
                if (chckbxFlag.isEnabled())
                    chckbxFlag.setSelected(true);
                if (chckbxRollConditioning.isEnabled())
                    chckbxRollConditioning.setSelected(true);
                if (chckbxSpliceTable.isEnabled())
                    chckbxSpliceTable.setSelected(true);
                if (chckbxTurretSupport.isEnabled())
                    chckbxTurretSupport.setSelected(true);
            } else {
                chckbxAlignmentGuide.setSelected(false);
                chckbxAutoCutoff.setSelected(false);
                chckbxAutostripping.setSelected(false);
                chckbxAutoTapeCore.setSelected(false);
                chckbxAutoTapeTail.setSelected(false);
                chckbxExtraRewind.setSelected(false);
                chckbxFlag.setSelected(false);
                chckbxRollConditioning.setSelected(false);
                chckbxSpliceTable.setSelected(false);
                chckbxTurretSupport.setSelected(false);
            }

            if (formReady)
                UpdateMachine();
        }
    });
    chckbxSelectAll.setEnabled(false);
    chckbxSelectAll.setBounds(22, 78, 97, 23);
    grpOptions.add(chckbxSelectAll);

    lblMachineConfiguration = new JLabel("Machine Configuration");
    lblMachineConfiguration.setFont(new Font("Tahoma", Font.BOLD, 18));
    lblMachineConfiguration.setBounds(29, 18, 269, 22);
    pnlMachine.add(lblMachineConfiguration);

    lblAddNewMachines = new JLabel(
            "Add new machines to the list on the right, then configure their options and variants below");
    lblAddNewMachines.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblAddNewMachines.setBounds(29, 45, 433, 14);
    pnlMachine.add(lblAddNewMachines);

    btnCustomMachine = new JButton("Custom Machine Options");
    btnCustomMachine.setEnabled(false);
    btnCustomMachine.setFont(new Font("Tahoma", Font.PLAIN, 11));
    btnCustomMachine.setBounds(322, 460, 180, 36);
    pnlMachine.add(btnCustomMachine);
    btnCustomMachine.setToolTipText("Edit settings for a custom machine type");

    scrollPane = new JScrollPane();
    scrollPane.setBorder(null);
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setBounds(522, 44, 245, 405);
    pnlMachine.add(scrollPane);

    panel_6 = new JPanel();
    panel_6.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, new Color(192, 192, 192), null, null, null));
    panel_6.setBackground(Color.WHITE);
    panel_6.setToolTipText("Select a machine to edit options, re-order, or delete");
    scrollPane.setViewportView(panel_6);
    panel_6.setLayout(new BorderLayout(0, 0));

    //Create the list and put it in a scroll pane.
    listMachines = new JList(listModel);
    panel_6.add(listMachines, BorderLayout.NORTH);
    listMachines.addListSelectionListener(new MachineListSelectionListener());
    listMachines.setCellRenderer(new MachineListRenderer());

    listMachines.setBorder(null);
    listMachines.setToolTipText("Select a machine to edit options, re-order, or delete");
    listMachines.setFont(new Font("Tahoma", Font.PLAIN, 13));
    listMachines.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    btnOverrideDefaultAcceleration = new JButton("Override Default Acceleration");
    btnOverrideDefaultAcceleration.setFont(new Font("Tahoma", Font.PLAIN, 11));
    btnOverrideDefaultAcceleration
            .setToolTipText("Set new values for the acceleration/deceleration of this machine");
    btnOverrideDefaultAcceleration.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try { // check list selected
                listMachines.getSelectedIndex();
            } catch (Exception e2) {
                return;
            }
            Machine currMachine = (Machine) listMachines.getSelectedValue();
            AccelDecel dialog = new AccelDecel(currMachine);
            dialog.setLocationRelativeTo(frmTitanRoiCalculator);
            dialog.setVisible(true);
        }
    });
    btnOverrideDefaultAcceleration.setEnabled(false);
    btnOverrideDefaultAcceleration.setBounds(130, 460, 182, 36);
    pnlMachine.add(btnOverrideDefaultAcceleration);

    btnCustomMachine.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ResetStatusLabel();
            //rdbtnOther.doClick();
            MachineBuilder newmach = new MachineBuilder(machine);
            newmach.setLocationRelativeTo(frmTitanRoiCalculator);
            newmach.setVisible(true);
        }
    });

    pnlJob = new JPanel();
    tabbedPane.addTab("Job Selection", null, pnlJob, "Add and configure machine jobs");
    tabbedPane.setEnabledAt(1, true);
    pnlJob.setLayout(null);

    JPanel pnlMaterials = new JPanel();
    pnlMaterials.setBounds(280, 72, 227, 124);
    pnlMaterials.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Material Settings",
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    pnlJob.add(pnlMaterials);
    pnlMaterials.setLayout(null);

    Material[] materials = { new Material("Custom", 1.0, 20), new Material("Aluminium", 2.7, 40),
            new Material("Board", 1.3, 80), new Material("Cellophane", 1.5, 20),
            new Material("HDPE/BOPE", 0.94, 20), new Material("Laminate", 1.0, 20),
            new Material("LDPE/BOPE", 0.91, 20), new Material("LLDPE", 0.9, 20),
            new Material("MDPE", 0.925, 20), new Material("Nylon", 1.12, 20),
            new Material("Polypropylene", 0.91, 20), new Material("Polystyrene", 1.04, 20),
            new Material("Paper", 0.8, 100), new Material("PEEK", 1.3, 20), new Material("Polyester", 1.4, 20),
            new Material("PLA", 1.24, 20), new Material("Polyolefin", 0.92, 20),
            new Material("PSA Label", 1.1, 20), new Material("PVC", 1.36, 20),
            new Material("Shrink label", 0.91, 20), new Material("Tri. Lam.", 1.1, 20) };

    cmbMaterials = new JComboBox(materials);
    cmbMaterials.setMaximumRowCount(20);
    cmbMaterials.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (jobFormReady) {
                Material m = (Material) cmbMaterials.getSelectedItem();
                if (!(m.name.equals("Custom"))) {
                    jobFormReady = false;
                    txtThickness.setText(Double.toString(roundTwoDecimals(m.getThickness())));
                    if (lblGsm.getText().equals("(gsm)"))
                        txtDensity.setText(Double.toString(roundTwoDecimals(m.getDensity())));
                    else
                        txtDensity
                                .setText(Double.toString(roundTwoDecimals(m.getDensity() * m.getThickness())));
                    if (!metric) {
                        txtThickness
                                .setText(Double.toString(roundTwoDecimals(Core.MicroToMil(m.getThickness()))));
                    }
                    jobFormReady = true;
                }
                UpdateJob();
            }
        }
    });
    cmbMaterials.setEnabled(false);
    cmbMaterials.setSelectedIndex(0);
    cmbMaterials.setToolTipText("Choose a preset material");
    cmbMaterials.setBounds(81, 26, 117, 22);
    pnlMaterials.add(cmbMaterials);

    lblPresets = new JLabel("Presets:");
    lblPresets.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblPresets.setToolTipText("Choose a preset material");
    lblPresets.setEnabled(false);
    lblPresets.setBounds(37, 29, 40, 15);
    pnlMaterials.add(lblPresets);

    lblThickness_1 = new JLabel("Thickness:");
    lblThickness_1.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblThickness_1.setToolTipText("Material thickness");
    lblThickness_1.setEnabled(false);
    lblThickness_1.setHorizontalAlignment(SwingConstants.RIGHT);
    lblThickness_1.setBounds(7, 61, 70, 14);
    pnlMaterials.add(lblThickness_1);

    lblDensity_1 = new JLabel("Density:");
    lblDensity_1.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblDensity_1.setToolTipText("Material density (per volume, not area)");
    lblDensity_1.setEnabled(false);
    lblDensity_1.setHorizontalAlignment(SwingConstants.RIGHT);
    lblDensity_1.setBounds(31, 86, 46, 14);
    pnlMaterials.add(lblDensity_1);

    txtThickness = new JTextField();
    txtThickness.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtThickness.selectAll();
        }
    });
    txtThickness.setEnabled(false);
    txtThickness.getDocument().addDocumentListener(new JobInputChangeListener());

    txtThickness.setToolTipText("Material thickness");
    txtThickness.setText("20");
    txtThickness.setBounds(81, 58, 86, 20);
    pnlMaterials.add(txtThickness);
    txtThickness.setColumns(10);

    txtDensity = new JTextField();
    txtDensity.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtDensity.selectAll();
        }
    });
    txtDensity.setEnabled(false);
    txtDensity.getDocument().addDocumentListener(new JobInputChangeListener());

    txtDensity.setToolTipText("Material density (per volume, not area)");
    txtDensity.setText("0.92");
    txtDensity.setBounds(81, 83, 86, 20);
    pnlMaterials.add(txtDensity);
    txtDensity.setColumns(10);

    lblmicro0 = new JLabel("(\u00B5m)");
    lblmicro0.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblmicro0.setEnabled(false);
    lblmicro0.setBounds(177, 61, 46, 14);
    pnlMaterials.add(lblmicro0);

    lblgm3 = new JLabel("(g/cm  )");
    lblgm3.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblgm3.setEnabled(false);
    lblgm3.setBounds(177, 86, 46, 14);
    pnlMaterials.add(lblgm3);

    label_3 = new JLabel("3");
    label_3.setEnabled(false);
    label_3.setFont(new Font("Tahoma", Font.PLAIN, 8));
    label_3.setBounds(204, 83, 14, 14);
    pnlMaterials.add(label_3);

    JPanel pnlJobs = new JPanel();
    pnlJobs.setBounds(20, 168, 250, 283);
    pnlJobs.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Rewind Settings",
            TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
    pnlJob.add(pnlJobs);
    pnlJobs.setLayout(null);

    lblTargetRewindLength = new JLabel("Rewind Output:");
    lblTargetRewindLength.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblTargetRewindLength.setToolTipText("Quantity of rewind output");
    lblTargetRewindLength.setEnabled(false);
    lblTargetRewindLength.setHorizontalAlignment(SwingConstants.RIGHT);
    lblTargetRewindLength.setBounds(17, 197, 88, 14);
    pnlJobs.add(lblTargetRewindLength);

    lblSlitWidth = new JLabel("Slit Width:");
    lblSlitWidth.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblSlitWidth.setToolTipText("Width of each output reel");
    lblSlitWidth.setEnabled(false);
    lblSlitWidth.setHorizontalAlignment(SwingConstants.RIGHT);
    lblSlitWidth.setBounds(46, 60, 59, 14);
    pnlJobs.add(lblSlitWidth);

    lblSlitCount = new JLabel("Reel Count:");
    lblSlitCount.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblSlitCount.setToolTipText("Number of reels per set at the output");
    lblSlitCount.setEnabled(false);
    lblSlitCount.setHorizontalAlignment(SwingConstants.RIGHT);
    lblSlitCount.setBounds(46, 33, 59, 14);
    pnlJobs.add(lblSlitCount);

    lblTrimtotal = new JLabel("Trim (total):");
    lblTrimtotal.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblTrimtotal.setToolTipText("The trim resulting from the given slit widths");
    lblTrimtotal.setEnabled(false);
    lblTrimtotal.setHorizontalAlignment(SwingConstants.RIGHT);
    lblTrimtotal.setBounds(20, 114, 85, 14);
    pnlJobs.add(lblTrimtotal);

    txtSlits = new JTextField();
    txtSlits.setToolTipText("Number of reels per set at the output");
    txtSlits.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtSlits.selectAll();
        }
    });
    txtSlits.getDocument().addDocumentListener(new JobInputChangeListener());
    txtSlits.setEnabled(false);

    txtSlits.setText("1");
    txtSlits.setBounds(109, 30, 86, 20);
    pnlJobs.add(txtSlits);
    txtSlits.setColumns(10);

    txtSlitWidth = new JTextField();
    txtSlitWidth.setToolTipText("Width of each output reel");
    txtSlitWidth.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtSlitWidth.selectAll();
        }
    });
    txtSlitWidth.getDocument().addDocumentListener(new JobInputChangeListener());
    txtSlitWidth.setEnabled(false);

    txtSlitWidth.setText("1350");
    txtSlitWidth.setBounds(109, 58, 86, 20);
    pnlJobs.add(txtSlitWidth);
    txtSlitWidth.setColumns(10);

    txtRewindAmount = new JTextField();
    txtRewindAmount.setToolTipText("Quantity of rewind output");
    txtRewindAmount.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtRewindAmount.selectAll();
        }
    });
    txtRewindAmount.getDocument().addDocumentListener(new JobInputChangeListener());
    txtRewindAmount.setEnabled(false);
    txtRewindAmount.setName("RewindLength");

    txtRewindAmount.setText("1000");
    txtRewindAmount.setBounds(109, 194, 86, 20);
    pnlJobs.add(txtRewindAmount);
    txtRewindAmount.setColumns(10);

    lblTrim = new JLabel("0 mm");
    lblTrim.setToolTipText("The trim resulting from the given slit widths");
    lblTrim.setEnabled(false);
    lblTrim.setBounds(111, 114, 65, 14);
    pnlJobs.add(lblTrim);

    cmbRewindCore = new JComboBox();
    cmbRewindCore.setToolTipText("Core diameter of rewind reels");
    ((JTextField) cmbRewindCore.getEditor().getEditorComponent()).getDocument()
            .addDocumentListener(new DocumentListener() {
                @Override
                public void removeUpdate(DocumentEvent arg0) {
                    UpdateJob();
                }

                @Override
                public void insertUpdate(DocumentEvent arg0) {
                    UpdateJob();
                }

                @Override
                public void changedUpdate(DocumentEvent arg0) {
                }
            });
    /*cmbRewindCore.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e) {
    UpdateJob(jobIndex);
       }
    });*/
    cmbRewindCore.setEnabled(false);

    cmbRewindCore.setModel(new DefaultComboBoxModel(Consts.REWIND_CORE_MM));
    cmbRewindCore.setSelectedIndex(1);
    cmbRewindCore.setBounds(109, 137, 87, 20);
    pnlJobs.add(cmbRewindCore);
    cmbRewindCore.setEditable(true);

    lblRewindCoremm = new JLabel("Rewind Core:");
    lblRewindCoremm.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblRewindCoremm.setToolTipText("Core diameter of rewind reels");
    lblRewindCoremm.setEnabled(false);
    lblRewindCoremm.setBounds(40, 140, 65, 14);
    pnlJobs.add(lblRewindCoremm);

    lblPer_1 = new JLabel("per:");
    lblPer_1.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblPer_1.setToolTipText("Set whether rewind output is measured per reel or per set");
    lblPer_1.setEnabled(false);
    lblPer_1.setBounds(85, 248, 20, 14);
    pnlJobs.add(lblPer_1);

    cmbJobDomain = new JComboBox();
    cmbJobDomain.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            UpdateSetReel();
            //UpdateJob();
        }
    });
    cmbJobDomain.setEnabled(false);
    cmbJobDomain.setToolTipText("Set whether rewind output is measured per reel or per set");
    cmbJobDomain.setModel(new DefaultComboBoxModel(new String[] { "Reel", "Set" }));
    cmbJobDomain.setBounds(109, 246, 95, 20);
    pnlJobs.add(cmbJobDomain);

    lblmm3 = new JLabel("(mm)");
    lblmm3.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblmm3.setEnabled(false);
    lblmm3.setBounds(205, 61, 27, 14);
    pnlJobs.add(lblmm3);

    lblmm2 = new JLabel("(mm)");
    lblmm2.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblmm2.setEnabled(false);
    lblmm2.setBounds(206, 140, 27, 14);
    pnlJobs.add(lblmm2);

    pnlUnwinds = new JPanel();
    pnlUnwinds.setLayout(null);
    pnlUnwinds.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Unwind Settings",
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    pnlUnwinds.setBounds(280, 207, 227, 162);
    pnlJob.add(pnlUnwinds);

    lblUnwindLength = new JLabel("Unwind Size:");
    lblUnwindLength.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblUnwindLength.setToolTipText("Quantity of material per mother roll");
    lblUnwindLength.setEnabled(false);
    lblUnwindLength.setHorizontalAlignment(SwingConstants.RIGHT);
    lblUnwindLength.setBounds(21, 104, 66, 14);
    pnlUnwinds.add(lblUnwindLength);

    txtUnwindAmount = new JTextField();
    txtUnwindAmount.setToolTipText("Quantity of material per mother roll");
    txtUnwindAmount.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent arg0) {
            txtUnwindAmount.selectAll();
        }
    });
    txtUnwindAmount.getDocument().addDocumentListener(new JobInputChangeListener());
    txtUnwindAmount.setEnabled(false);
    txtUnwindAmount.setName("UnwindLength");
    txtUnwindAmount.setText("10000");
    txtUnwindAmount.setBounds(92, 100, 86, 20);
    pnlUnwinds.add(txtUnwindAmount);
    txtUnwindAmount.setColumns(10);

    lblWebWidthmm = new JLabel("Web Width:");
    lblWebWidthmm.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblWebWidthmm.setToolTipText("Width of mother rolls");
    lblWebWidthmm.setEnabled(false);
    lblWebWidthmm.setBounds(31, 29, 57, 14);
    pnlUnwinds.add(lblWebWidthmm);

    lblUnwindCoremm = new JLabel("Unwind Core:");
    lblUnwindCoremm.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblUnwindCoremm.setToolTipText("Core diameter of mother rolls");
    lblUnwindCoremm.setEnabled(false);
    lblUnwindCoremm.setBounds(22, 54, 66, 14);
    pnlUnwinds.add(lblUnwindCoremm);

    cmbUnwindCore = new JComboBox();
    cmbUnwindCore.setToolTipText("Core diameter of mother rolls");
    ((JTextField) cmbUnwindCore.getEditor().getEditorComponent()).getDocument()
            .addDocumentListener(new DocumentListener() {
                @Override
                public void removeUpdate(DocumentEvent arg0) {
                    UpdateJob();
                }

                @Override
                public void insertUpdate(DocumentEvent arg0) {
                    UpdateJob();
                }

                @Override
                public void changedUpdate(DocumentEvent arg0) {
                }
            });
    cmbUnwindCore.setEnabled(false);

    cmbUnwindCore.setModel(new DefaultComboBoxModel(new String[] { "76", "152", "254" }));
    cmbUnwindCore.setBounds(92, 51, 86, 20);
    pnlUnwinds.add(cmbUnwindCore);
    cmbUnwindCore.setEditable(true);

    lblmm0 = new JLabel("(mm)");
    lblmm0.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblmm0.setEnabled(false);
    lblmm0.setBounds(189, 29, 32, 14);
    pnlUnwinds.add(lblmm0);

    lblmm1 = new JLabel("(mm)");
    lblmm1.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblmm1.setEnabled(false);
    lblmm1.setBounds(189, 53, 32, 14);
    pnlUnwinds.add(lblmm1);

    pnlEnviron = new JPanel();
    tabbedPane.addTab("Job Scheduling", null, pnlEnviron, "Edit the schedule of jobs to be analysed");
    tabbedPane.setEnabledAt(2, true);
    pnlEnviron.setLayout(null);

    JPanel pnlShifts = new JPanel();
    pnlShifts.setLayout(null);
    pnlShifts.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Shift Options",
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    pnlShifts.setBounds(20, 72, 287, 162);
    pnlEnviron.add(pnlShifts);

    JLabel lblShiftLength = new JLabel("Shift Length:");
    lblShiftLength.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblShiftLength.setToolTipText("Hours per working shift");
    lblShiftLength.setHorizontalAlignment(SwingConstants.RIGHT);
    lblShiftLength.setBounds(15, 28, 108, 14);
    pnlShifts.add(lblShiftLength);

    JLabel lblDayLength = new JLabel("Day Length:");
    lblDayLength.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblDayLength.setToolTipText("Working hours per day");
    lblDayLength.setHorizontalAlignment(SwingConstants.RIGHT);
    lblDayLength.setBounds(29, 78, 94, 14);
    pnlShifts.add(lblDayLength);

    JLabel lblShiftsDay = new JLabel("Shifts per Day:");
    lblShiftsDay.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblShiftsDay.setToolTipText("Shifts per day");
    lblShiftsDay.setHorizontalAlignment(SwingConstants.RIGHT);
    lblShiftsDay.setBounds(15, 53, 108, 14);
    pnlShifts.add(lblShiftsDay);

    JLabel lblDays = new JLabel("Days per Year:");
    lblDays.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblDays.setToolTipText("Days per year");
    lblDays.setHorizontalAlignment(SwingConstants.RIGHT);
    lblDays.setBounds(0, 106, 123, 14);
    pnlShifts.add(lblDays);

    txtShiftLength = new JTextField();
    txtShiftLength.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent arg0) {
            UpdateShifts();
        }

        @Override
        public void insertUpdate(DocumentEvent arg0) {
            UpdateShifts();
        }

        @Override
        public void changedUpdate(DocumentEvent arg0) {
        }
    });
    txtShiftLength.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent arg0) {
            txtShiftLength.selectAll();
        }
    });
    txtShiftLength.setToolTipText("Hours per working shift");

    txtShiftLength.setText("8");
    txtShiftLength.setBounds(133, 25, 86, 20);
    pnlShifts.add(txtShiftLength);
    txtShiftLength.setColumns(10);

    txtShiftCount = new JTextField();
    txtShiftCount.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent arg0) {
            UpdateShifts();
        }

        @Override
        public void insertUpdate(DocumentEvent arg0) {
            UpdateShifts();
        }

        @Override
        public void changedUpdate(DocumentEvent arg0) {
        }
    });
    txtShiftCount.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtShiftCount.selectAll();
        }
    });
    txtShiftCount.setToolTipText("Shifts per day");

    txtShiftCount.setText("3");
    txtShiftCount.setBounds(133, 50, 86, 20);
    pnlShifts.add(txtShiftCount);
    txtShiftCount.setColumns(10);

    txtDaysYear = new JTextField();
    txtDaysYear.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent arg0) {
            UpdateShifts();
        }

        @Override
        public void insertUpdate(DocumentEvent arg0) {
            UpdateShifts();
        }

        @Override
        public void changedUpdate(DocumentEvent arg0) {
        }
    });
    txtDaysYear.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtDaysYear.selectAll();
        }
    });
    txtDaysYear.setToolTipText("Days per year");

    txtDaysYear.setText("250");
    txtDaysYear.setBounds(133, 103, 86, 20);
    pnlShifts.add(txtDaysYear);
    txtDaysYear.setColumns(10);

    lblDayLength2 = new JLabel("24 hours");
    lblDayLength2.setToolTipText("Working hours per day");
    lblDayLength2.setBounds(133, 78, 86, 14);
    pnlShifts.add(lblDayLength2);

    lblHoursYear = new JLabel("Hours per Year:");
    lblHoursYear.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblHoursYear.setToolTipText("Working hours per year");
    lblHoursYear.setBounds(47, 131, 76, 14);
    pnlShifts.add(lblHoursYear);

    lblHoursYear2 = new JLabel("6000 hours");
    lblHoursYear2.setToolTipText("Working hours per year");
    lblHoursYear2.setBounds(133, 131, 86, 14);
    pnlShifts.add(lblHoursYear2);

    lblHrs = new JLabel("hrs");
    lblHrs.setBounds(229, 28, 46, 14);
    pnlShifts.add(lblHrs);

    btnAddAll = new JButton("Add All");
    btnAddAll.setToolTipText("Add all jobs to the schedule in order");
    btnAddAll.setFont(new Font("Tahoma", Font.BOLD, 11));
    btnAddAll.setEnabled(false);
    try {
        btnAddAll.setIcon(new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/plus.png"))));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    btnAddAll.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            for (int i = 0; i < jobModel.getSize(); ++i) {
                listJobsAvail.setSelectedIndex(i);
                btnAddJob.doClick();
            }
        }
    });
    btnAddAll.setBounds(327, 460, 110, 36);
    pnlEnviron.add(btnAddAll);

    btnAddJob = new JButton("");
    btnAddJob.setToolTipText("Add this job to the schedule");
    btnAddJob.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //AddToSchedule(listJobsAvail.getSelectedValue());

            ResetStatusLabel();

            int index = listSchedule.getSelectedIndex();
            //int source_index = listJobsAvail.getSelectedIndex();
            Job sel = (Job) listJobsAvail.getSelectedValue();
            JobItem j = environment.getSchedule().new JobItem(sel, 0, sel.getTotWeight(), sel.getTotLength());
            int size = scheduleModel.getSize();

            // no limit now there are scroll bars
            /* if(size >= Consts.JOB_LIST_LIMIT){    // Max list size
              ShowMessage("Maximum number of jobs scheduled. Please delete before attempting to add more.");
              return;
            }*/

            //If no selection or if item in last position is selected,
            //add the new one to end of list, and select new one.
            if (index == -1 || (index + 1 == size)) {

                scheduleModel.addElement(sel);
                listSchedule.setSelectedIndex(size);
                environment.getSchedule().addJob(j);

                //Otherwise insert the new one after the current selection,
                //and select new one.
            } else {
                scheduleModel.insertElementAt(sel, index + 1);
                listSchedule.setSelectedIndex(index + 1);
                environment.getSchedule().insertJob(j, index + 1);
            }

            btnClearSchedule.setEnabled(true);
        }
    });
    btnAddJob.setEnabled(false);
    try {
        btnAddJob.setIcon(new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/add_job.png"))));
        btnAddJob.setDisabledIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/add_job_dis.png"))));
        btnAddJob.setRolloverEnabled(true);
        btnAddJob.setRolloverIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/add_job_over.png"))));
    } catch (NullPointerException e111) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    btnAddJob.setBounds(521, 178, 54, 54);
    pnlEnviron.add(btnAddJob);

    btnRemoveJob = new JButton("");
    btnRemoveJob.setToolTipText("Remove job from schedule");
    btnRemoveJob.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ResetStatusLabel();

            // Uncomment this code to allow jobs to be saved back after removal from schedule
            /*if(listSchedule.getSelectedIndex() > -1){
               Job j = (Job) listSchedule.getSelectedValue();
               String name = j.getName().toLowerCase();
               if(!jobNames.contains(name) && !jobModel.contains(j)){
                  if(jobModel.size() < Consts.JOB_LIST_LIMIT){
             jobNames.add(name);
             jobFormReady = true;
             int index = -1;
             if(listJobsAvail.getSelectedIndex() > -1)
                index = listJobsAvail.getSelectedIndex();
             if(index < 0){
                jobModel.addElement(j);
                listJobsAvail.setSelectedIndex(jobModel.size()-1);
                listJobs.setSelectedIndex(jobModel.size()-1);
             }else{
                jobModel.insertElementAt(j, index+1);
                listJobsAvail.setSelectedIndex(index+1);
                listJobs.setSelectedIndex(index+1);
             }
                  }
               }
            }*/

            ListSelectionModel lsm = listSchedule.getSelectionModel();
            int firstSelected = lsm.getMinSelectionIndex();
            int lastSelected = lsm.getMaxSelectionIndex();
            scheduleModel.removeRange(firstSelected, lastSelected);
            environment.getSchedule().remove(firstSelected);

            int size = scheduleModel.size();

            if (size == 0) {
                //List is empty: disable delete, up, and down buttons.
                btnClearSchedule.setEnabled(false);
                btnUpSchedule.setEnabled(false);
                btnDownSchedule.setEnabled(false);
                listSchedule.clearSelection();
                btnRemoveJob.setEnabled(false);
                btnViewSchedule.setEnabled(false);
            } else {
                //Adjust the selection.
                if (firstSelected == scheduleModel.getSize()) {
                    //Removed item in last position.
                    firstSelected--;
                }
                listSchedule.setSelectedIndex(firstSelected);

                if (size == 21) { // No longer full list
                    ResetStatusLabel();
                }

            }
        }
    });
    btnRemoveJob.setEnabled(false);
    try {
        btnRemoveJob
                .setIcon(new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/del_job.png"))));
        btnRemoveJob.setDisabledIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/del_job_dis.png"))));
        btnRemoveJob.setRolloverEnabled(true);
        btnRemoveJob.setRolloverIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/del_job_over.png"))));
    } catch (NullPointerException e111) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    btnRemoveJob.setBounds(520, 243, 54, 54);
    pnlEnviron.add(btnRemoveJob);

    lblJobSchedule_1 = new JLabel("Job Schedule");
    lblJobSchedule_1.setFont(new Font("Tahoma", Font.BOLD, 18));
    lblJobSchedule_1.setBounds(29, 18, 269, 22);
    pnlEnviron.add(lblJobSchedule_1);

    lblScheduleJobsTo = new JLabel("Schedule jobs to the right, then set shift options below");
    lblScheduleJobsTo.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblScheduleJobsTo.setBounds(29, 45, 279, 14);
    pnlEnviron.add(lblScheduleJobsTo);

    lblAvailableJobs_1 = new JLabel("Available Jobs");
    lblAvailableJobs_1.setFont(new Font("Tahoma", Font.BOLD, 12));
    lblAvailableJobs_1.setBounds(327, 19, 137, 14);
    pnlEnviron.add(lblAvailableJobs_1);

    lblJobSchedule_2 = new JLabel("Job Schedule");
    lblJobSchedule_2.setFont(new Font("Tahoma", Font.BOLD, 12));
    lblJobSchedule_2.setBounds(577, 19, 110, 14);
    pnlEnviron.add(lblJobSchedule_2);

    panel = new JPanel();
    panel.setLayout(null);
    panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Schedule Options",
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    panel.setBounds(20, 245, 287, 104);
    pnlEnviron.add(panel);

    btnViewSchedule = new JButton("View Schedule Diagram");
    btnViewSchedule.setFont(new Font("Tahoma", Font.PLAIN, 11));
    btnViewSchedule.setToolTipText("View chart of schedule timings");
    btnViewSchedule.setEnabled(false);
    btnViewSchedule.setBounds(33, 27, 170, 29);
    panel.add(btnViewSchedule);

    chckbxSimulateScheduleStart = new JCheckBox("Ignore machine config & knife positioning times");
    chckbxSimulateScheduleStart.setFont(new Font("Tahoma", Font.PLAIN, 11));
    chckbxSimulateScheduleStart.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (!initialising)
                environment.StartStopTimes = !chckbxSimulateScheduleStart.isSelected();
        }
    });
    chckbxSimulateScheduleStart.setToolTipText(
            "WARNING:  Use ONLY when you wish to model the output of a single job over a long time period \u2013 such that the initial set-up time has no material impact on the production volume");
    chckbxSimulateScheduleStart.setBounds(30, 62, 251, 18);
    panel.add(chckbxSimulateScheduleStart);

    lblhoverForInfo = new JLabel("(hover for info)");
    lblhoverForInfo.setToolTipText(
            "WARNING:  Use ONLY when you wish to model the output of a single job over a long time period \u2013 such that the initial set-up time has no material impact on the production volume");
    lblhoverForInfo.setForeground(Color.GRAY);
    lblhoverForInfo.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblhoverForInfo.setBounds(34, 80, 147, 14);
    panel.add(lblhoverForInfo);

    btnUpSchedule = new JButton("");
    btnUpSchedule.setToolTipText("Move job earlier in schedule");
    btnUpSchedule.addActionListener(new ScheduleUpListener());
    try {
        btnUpSchedule.setIcon(new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/up.png"))));
        btnUpSchedule.setRolloverEnabled(true);
        btnUpSchedule.setRolloverIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/up_over.png"))));
        btnUpSchedule.setDisabledIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/up_dis.png"))));
    } catch (NullPointerException e11) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    btnUpSchedule.setEnabled(false);
    btnUpSchedule.setBounds(700, 463, 30, 30);
    pnlEnviron.add(btnUpSchedule);

    btnDownSchedule = new JButton("");
    btnDownSchedule.setToolTipText("Move job later in schedule");
    btnDownSchedule.addActionListener(new ScheduleDownListener());
    try {
        btnDownSchedule
                .setIcon(new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/down.png"))));
        btnDownSchedule.setRolloverEnabled(true);
        btnDownSchedule.setRolloverIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/down_over.png"))));
        btnDownSchedule.setDisabledIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/down_dis.png"))));
    } catch (NullPointerException e11) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    btnDownSchedule.setEnabled(false);
    btnDownSchedule.setBounds(737, 463, 30, 30);
    pnlEnviron.add(btnDownSchedule);

    btnClearSchedule = new JButton("Clear");
    btnClearSchedule.setToolTipText("Clear all jobs from the schedule");
    btnClearSchedule.setFont(new Font("Tahoma", Font.BOLD, 11));
    btnClearSchedule.setEnabled(false);
    try {
        btnClearSchedule
                .setIcon(new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/delete.png"))));
        btnClearSchedule.setRolloverEnabled(true);
        btnClearSchedule.setRolloverIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/delete_over.png"))));
        btnClearSchedule.setDisabledIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/delete_dis.png"))));
    } catch (NullPointerException e11) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    btnClearSchedule.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scheduleModel.removeAllElements();
            environment.getSchedule().empty();
        }
    });
    btnClearSchedule.setBounds(577, 460, 110, 36);
    pnlEnviron.add(btnClearSchedule);
    //listSchedule.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
    //listSchedule.setBounds(577, 44, 190, 405);
    //pnlEnviron.add(listSchedule);
    btnViewSchedule.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            ScheduleChart ch = new ScheduleChart(environment.getSchedule());
            ch.pack();
            try {
                ch.setIconImage(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/logo.png")));
            } catch (NullPointerException e11) {
                System.out.println("Image load error");
            } catch (IOException e) {
                e.printStackTrace();
            }
            ch.setLocationRelativeTo(frmTitanRoiCalculator);
            ch.setVisible(true);
        }
    });

    scrlSchedule = new JScrollPane();
    scrlSchedule.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrlSchedule.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, null, null, null));
    scrlSchedule.setBounds(577, 44, 190, 405);
    scrlSchedule.getVerticalScrollBar().setUnitIncrement(16);
    pnlEnviron.add(scrlSchedule);

    panel_8 = new JPanel();
    panel_8.setToolTipText("Select job to re-order or remove from schedule");
    panel_8.setBackground(Color.WHITE);
    panel_8.setBorder(null);
    scrlSchedule.setViewportView(panel_8);
    panel_8.setLayout(new BorderLayout(0, 0));

    listSchedule = new JList(scheduleModel);
    panel_8.add(listSchedule, BorderLayout.NORTH);
    listSchedule.setToolTipText("Select job to re-order or remove from schedule");
    listSchedule.addListSelectionListener(new ScheduleSelectionListener());
    listSchedule.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listSchedule.setCellRenderer(new JobListRenderer());

    panel_5 = new JPanel();
    panel_5.setLayout(null);
    panel_5.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Notes",
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    panel_5.setBounds(20, 360, 287, 136);
    pnlEnviron.add(panel_5);

    lblToViewAnalysis = new JLabel("To view analysis for 1 job only, add just that job");
    lblToViewAnalysis.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblToViewAnalysis.setBounds(24, 24, 241, 14);
    panel_5.add(lblToViewAnalysis);

    lblToTheSchedule = new JLabel("to the schedule.");
    lblToTheSchedule.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblToTheSchedule.setBounds(24, 38, 241, 14);
    panel_5.add(lblToTheSchedule);

    lblToModelMaintenance = new JLabel("To model maintenance or other downtime, edit the");
    lblToModelMaintenance.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblToModelMaintenance.setBounds(24, 59, 253, 14);
    panel_5.add(lblToModelMaintenance);

    lblShiftOptionsAbove = new JLabel("shift options above. This will affect annual output,");
    lblShiftOptionsAbove.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblShiftOptionsAbove.setBounds(24, 73, 253, 14);
    panel_5.add(lblShiftOptionsAbove);

    lblButNotThe = new JLabel("but not the rates or efficiencies. For these, use the");
    lblButNotThe.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblButNotThe.setBounds(24, 87, 253, 14);
    panel_5.add(lblButNotThe);

    lbladvancedTabIn = new JLabel("'advanced' tab in the options menu box.");
    lbladvancedTabIn.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lbladvancedTabIn.setBounds(24, 101, 253, 14);
    panel_5.add(lbladvancedTabIn);

    scrollPane_2 = new JScrollPane();
    scrollPane_2.setBorder(null);
    scrollPane_2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
    scrollPane_2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane_2.setBounds(327, 44, 190, 405);
    pnlEnviron.add(scrollPane_2);

    panel_9 = new JPanel();
    panel_9.setToolTipText("Select job to be added");
    scrollPane_2.setViewportView(panel_9);
    panel_9.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, null, null, null));
    panel_9.setBackground(Color.WHITE);
    panel_9.setLayout(new BorderLayout(0, 0));

    listJobsAvail = new JList(jobModel);
    panel_9.add(listJobsAvail, BorderLayout.NORTH);
    listJobsAvail.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "add");
    listJobsAvail.getActionMap().put("add", new AddScheduleBtn());
    listJobsAvail.setToolTipText("Select job to be added");
    listJobsAvail.addListSelectionListener(new JobAvailSelectionListener());
    listJobsAvail.setCellRenderer(new JobListRenderer());
    listJobsAvail.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listJobsAvail.setBorder(null);

    pnlCompare = new JPanel();
    tabbedPane.addTab("Productivity Comparison", null, pnlCompare, "Productivity comparison data & graphs");
    tabbedPane.setEnabledAt(3, true);
    pnlCompare.setLayout(null);

    pnlResults = new JPanel();
    pnlResults.setBorder(
            new TitledBorder(null, "Numerical Results", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    pnlResults.setBounds(20, 72, 479, 134);
    pnlCompare.add(pnlResults);
    pnlResults.setLayout(null);

    lblOutputLength = new JLabel("Output length over time period:");
    lblOutputLength.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblOutputLength.setEnabled(false);
    lblOutputLength.setToolTipText("Quantity produced");
    lblOutputLength.setBounds(220, 54, 152, 14);
    pnlResults.add(lblOutputLength);

    lblOutputWeight = new JLabel("Output weight over time period:");
    lblOutputWeight.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblOutputWeight.setEnabled(false);
    lblOutputWeight.setToolTipText("Quantity produced");
    lblOutputWeight.setBounds(220, 79, 162, 14);
    pnlResults.add(lblOutputWeight);

    cmbTimeRef = new JComboBox();
    cmbTimeRef.setEnabled(false);
    cmbTimeRef.setToolTipText("Select a time range to display results over");
    cmbTimeRef.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // Refresh analyses
            UpdateNumericalAnalysis();
        }
    });
    cmbTimeRef.setModel(
            new DefaultComboBoxModel(new String[] { "Schedule", "Year", "Hour", "Shift", "Day"/*, "Week"*/ }));
    cmbTimeRef.setBounds(247, 98, 125, 24);
    pnlResults.add(cmbTimeRef);

    lblPer = new JLabel("Per:");
    lblPer.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblPer.setEnabled(false);
    lblPer.setBounds(220, 103, 20, 14);
    pnlResults.add(lblPer);

    lblAverageMmin = new JLabel("Average rate:");
    lblAverageMmin.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblAverageMmin.setEnabled(false);
    lblAverageMmin.setToolTipText("Average quantity processed");
    lblAverageMmin.setBounds(20, 54, 95, 14);
    pnlResults.add(lblAverageMmin);

    lblNumericsWeight = new JLabel("0.0 tons");
    lblNumericsWeight.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblNumericsWeight.setEnabled(false);
    lblNumericsWeight.setToolTipText("Quantity produced");
    lblNumericsWeight.setBounds(380, 79, 89, 14);
    pnlResults.add(lblNumericsWeight);

    lblNumericsLength = new JLabel("0.0 metres");
    lblNumericsLength.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblNumericsLength.setEnabled(false);
    lblNumericsLength.setToolTipText("Quantity produced");
    lblNumericsLength.setBounds(380, 54, 89, 14);
    pnlResults.add(lblNumericsLength);

    lblNumericsRate = new JLabel("0.0 m/hr");
    lblNumericsRate.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblNumericsRate.setEnabled(false);
    lblNumericsRate.setToolTipText("Average quantity processed");
    lblNumericsRate.setBounds(128, 54, 82, 14);
    pnlResults.add(lblNumericsRate);

    lblEfficiency = new JLabel("Machine running:");
    lblEfficiency.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblEfficiency.setEnabled(false);
    lblEfficiency.setToolTipText("Proportion of total time for which the machine is running");
    lblEfficiency.setBounds(20, 104, 95, 14);
    pnlResults.add(lblEfficiency);

    cmbMachines = new JComboBox();
    cmbMachines.setMaximumRowCount(15);
    cmbMachines.setFont(new Font("Tahoma", Font.BOLD, 11));
    cmbMachines.setEnabled(false);
    cmbMachines.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            UpdateNumericalAnalysis();
        }
    });
    cmbMachines.setToolTipText("Select machine");
    cmbMachines.setBounds(128, 20, 244, 24);
    pnlResults.add(cmbMachines);

    lblMachine = new JLabel("Select Machine:");
    lblMachine.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblMachine.setEnabled(false);
    lblMachine.setToolTipText("Select machine");
    lblMachine.setBounds(20, 25, 77, 14);
    pnlResults.add(lblMachine);

    lblNumericsEff = new JLabel("0.0 %");
    lblNumericsEff.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblNumericsEff.setEnabled(false);
    lblNumericsEff.setToolTipText("Machine efficiency");
    lblNumericsEff.setBounds(128, 104, 65, 14);
    pnlResults.add(lblNumericsEff);

    lblscheduletimelbl = new JLabel("Time to run schedule:");
    lblscheduletimelbl.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblscheduletimelbl.setToolTipText("Time to run schedule");
    lblscheduletimelbl.setEnabled(false);
    lblscheduletimelbl.setBounds(20, 79, 103, 14);
    pnlResults.add(lblscheduletimelbl);

    lblscheduletime = new JLabel("0.0 hr");
    lblscheduletime.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblscheduletime.setToolTipText("Time to run schedule");
    lblscheduletime.setEnabled(false);
    lblscheduletime.setBounds(128, 79, 77, 14);
    pnlResults.add(lblscheduletime);

    pnlROI = new JPanel();
    tabbedPane.addTab("Return on Investment", (Icon) null, pnlROI,
            "Return on investment comparison and analysis");
    pnlROI.setLayout(null);
    tabbedPane.setEnabledAt(4, true);

    lblProductivityComparison = new JLabel("Productivity Comparison");
    lblProductivityComparison.setFont(new Font("Tahoma", Font.BOLD, 18));
    lblProductivityComparison.setBounds(29, 18, 269, 22);
    pnlCompare.add(lblProductivityComparison);

    lblSelectMultipleMachines = new JLabel(
            "Select multiple machines from the list on the right, then compare them below");
    lblSelectMultipleMachines.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblSelectMultipleMachines.setBounds(29, 45, 433, 14);
    pnlCompare.add(lblSelectMultipleMachines);

    label_2 = new JLabel("Machines");
    label_2.setFont(new Font("Tahoma", Font.BOLD, 12));
    label_2.setBounds(522, 19, 85, 14);
    pnlCompare.add(label_2);

    pnlProdGraph = new JPanel();
    pnlProdGraph.setBounds(20, 222, 479, 274);
    pnlCompare.add(pnlProdGraph);
    pnlProdGraph.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Graphical Results",
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    pnlProdGraph.setLayout(null);

    btnShowGraph = new JButton("Open Graph");
    btnShowGraph.setFont(new Font("Tahoma", Font.BOLD, 11));
    btnShowGraph.setToolTipText("Open graph in new window");
    btnShowGraph.setEnabled(false);
    btnShowGraph.setBounds(366, 51, 99, 39);
    pnlProdGraph.add(btnShowGraph);

    btnSaveToFile = new JButton("Save to File");
    btnSaveToFile.setFont(new Font("Tahoma", Font.PLAIN, 11));
    btnSaveToFile.setToolTipText("Save image to disk");
    btnSaveToFile.setEnabled(false);
    btnSaveToFile.addActionListener(SaveActionListener);
    btnSaveToFile.setBounds(366, 97, 99, 24);
    pnlProdGraph.add(btnSaveToFile);

    pnlPreview = new JPanel();
    pnlPreview.setBackground(Color.WHITE);
    pnlPreview.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, null, null, null));
    pnlPreview.setBounds(21, 51, 335, 205);
    pnlProdGraph.add(pnlPreview);
    pnlPreview.setLayout(null);
    pnlGraph = new ChartPanel(chart);
    pnlGraph.setBounds(2, 2, 331, 201);
    //pnlGraph.setPreferredSize(new java.awt.Dimension(243, 171));
    pnlPreview.add(pnlGraph);
    try {
        picLabel = new JLabel(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/no_preview.png"))));
    } catch (IOException e2) {
        e2.printStackTrace();
    }
    picLabel.setBounds(2, 2, 331, 201);
    pnlPreview.add(picLabel);
    pnlGraph.setVisible(false);

    lblPreview = new JLabel("Graph Preview");
    lblPreview.setForeground(Color.DARK_GRAY);
    lblPreview.setFont(new Font("Tahoma", Font.BOLD, 12));
    lblPreview.setEnabled(false);
    lblPreview.setBounds(21, 24, 99, 16);
    pnlProdGraph.add(lblPreview);

    lblType = new JLabel("Graph Type:");
    lblType.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblType.setEnabled(false);
    lblType.setToolTipText("Choose measurement type");
    lblType.setBounds(184, 26, 65, 14);
    pnlProdGraph.add(lblType);

    btnShowTimings = new JButton("Machine Runs");
    btnShowTimings.setFont(new Font("Tahoma", Font.PLAIN, 11));
    btnShowTimings.setToolTipText("Show timing diagram for a single machine run");
    btnShowTimings.setEnabled(false);
    btnShowTimings.addActionListener(new BtnShowTimingsActionListener());
    btnShowTimings.setBounds(366, 201, 99, 24);
    pnlProdGraph.add(btnShowTimings);

    btnDowntime = new JButton("Productivity");
    btnDowntime.setFont(new Font("Tahoma", Font.PLAIN, 11));
    btnDowntime.setToolTipText("View productivity breakdown charts for the selected machines");
    btnDowntime.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ShowTimingBreakdown();
        }
    });
    btnDowntime.setEnabled(false);
    btnDowntime.setBounds(366, 232, 99, 24);
    pnlProdGraph.add(btnDowntime);

    lblbreakdown1 = new JLabel("Show timing");
    lblbreakdown1.setEnabled(false);
    lblbreakdown1.setBounds(370, 166, 99, 14);
    pnlProdGraph.add(lblbreakdown1);

    lblbreakdown2 = new JLabel("breakdown for:");
    lblbreakdown2.setEnabled(false);
    lblbreakdown2.setBounds(370, 182, 99, 14);
    pnlProdGraph.add(lblbreakdown2);

    panel_3 = new JPanel();
    panel_3.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    panel_3.setBounds(522, 459, 245, 37);
    pnlCompare.add(panel_3);
    panel_3.setLayout(null);

    btnNone = new JButton("None");
    btnNone.setFont(new Font("Tahoma", Font.PLAIN, 11));
    btnNone.setEnabled(false);
    btnNone.setBounds(172, 7, 57, 23);
    panel_3.add(btnNone);
    btnNone.setToolTipText("Clear machine selection");

    btnAll = new JButton("All");
    btnAll.setFont(new Font("Tahoma", Font.PLAIN, 11));
    btnAll.setEnabled(false);
    btnAll.setBounds(105, 7, 57, 23);
    panel_3.add(btnAll);
    btnAll.setToolTipText("Select all machines");

    lblSelect = new JLabel("Select:");
    lblSelect.setEnabled(false);
    lblSelect.setBounds(37, 11, 46, 14);
    panel_3.add(lblSelect);

    scrollPane_3 = new JScrollPane();
    scrollPane_3.setBorder(null);
    scrollPane_3.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
    scrollPane_3.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane_3.setBounds(522, 44, 245, 405);
    pnlCompare.add(scrollPane_3);

    panel_10 = new JPanel();
    panel_10.setToolTipText(
            "Click a machine to select it. Select multiple machines to compare their performance under the chosen job schedule.");
    panel_10.setBackground(Color.WHITE);
    scrollPane_3.setViewportView(panel_10);
    panel_10.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, null, null, null));
    panel_10.setLayout(new BorderLayout(0, 0));

    listCompare = new JList(listModel);
    panel_10.add(listCompare, BorderLayout.NORTH);
    listCompare.setCellRenderer(new MachineListRenderer());
    listCompare.setToolTipText(
            "Click a machine to select it. Select multiple machines to compare their performance under the chosen job schedule.");
    listCompare.setBorder(null);
    listCompare.addListSelectionListener(new MultiSelectionListener());

    btnAll.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int[] count = new int[listModel.size()];
            for (int i = 0; i < listModel.size(); ++i)
                count[i] = i;
            listCompare.setSelectedIndices(count);
        }
    });
    btnNone.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            listCompare.clearSelection();
        }
    });
    btnShowGraph.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            // TODO base on cmbGraphType: or not if just using chart

            /*PieChart test = new PieChart("title","this is a pie chart");
            test.pack();
            test.setVisible(true);
            test.setLocationRelativeTo(null);*/
            JFrame popGraph = new JFrame();

            JFreeChart chartBig = null;
            try {
                chartBig = (JFreeChart) chart.clone();
            } catch (CloneNotSupportedException e) {
                e.printStackTrace();
            }
            //chartBig.setTitle("Productivity Comparison");

            ChartPanel cpanel = new ChartPanel(chartBig);
            cpanel.setPreferredSize(new java.awt.Dimension(500, 300));
            popGraph.setContentPane(cpanel);
            try {
                popGraph.setIconImage(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/logo.png")));
            } catch (NullPointerException e11) {
                System.out.println("Image load error");
            } catch (IOException e) {
                e.printStackTrace();
            }
            popGraph.setTitle("Productivity Graph");
            popGraph.setSize(450, 300);

            popGraph.pack();
            popGraph.setVisible(true);
            popGraph.setLocationRelativeTo(frmTitanRoiCalculator);
        }
    });

    cmbGraphType = new JComboBox();
    cmbGraphType.setMaximumRowCount(10);
    cmbGraphType.setFont(new Font("Tahoma", Font.PLAIN, 11));
    cmbGraphType.setEnabled(false);
    cmbGraphType.setToolTipText("Choose measurement type");
    cmbGraphType.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // Refresh analyses
            UpdateGraph();
        }
    });
    cmbGraphType.setModel(new DefaultComboBoxModel(new String[] { "Schedule Time", "Length per Hour",
            "Weight per Hour", "Length per Year", "Weight per Year", "Run Percentage" }));
    cmbGraphType.setSelectedIndex(0);
    cmbGraphType.setBounds(251, 21, 105, 24);
    pnlProdGraph.add(cmbGraphType);

    lblReturnOnInvestment = new JLabel("Return on Investment");
    lblReturnOnInvestment.setFont(new Font("Tahoma", Font.BOLD, 18));
    lblReturnOnInvestment.setBounds(29, 18, 269, 22);
    pnlROI.add(lblReturnOnInvestment);

    lblSelectMultipleMachines_1 = new JLabel(
            "Select multiple machines from the list on the right, then compare them below");
    lblSelectMultipleMachines_1.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblSelectMultipleMachines_1.setBounds(29, 45, 433, 14);
    pnlROI.add(lblSelectMultipleMachines_1);

    lblCompareroiList = new JLabel("Machines");
    lblCompareroiList.setFont(new Font("Tahoma", Font.BOLD, 12));
    lblCompareroiList.setBounds(522, 19, 85, 14);
    pnlROI.add(lblCompareroiList);

    panel_4 = new JPanel();
    panel_4.setLayout(null);
    panel_4.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    panel_4.setBounds(522, 459, 245, 37);
    pnlROI.add(panel_4);

    btnROIselectnone = new JButton("None");
    btnROIselectnone.setFont(new Font("Tahoma", Font.PLAIN, 11));
    btnROIselectnone.setEnabled(false);
    btnROIselectnone.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            listCompareRoi.clearSelection();
        }
    });
    btnROIselectnone.setToolTipText("Clear machine selection");
    btnROIselectnone.setBounds(172, 7, 57, 23);
    panel_4.add(btnROIselectnone);

    btnROIselectall = new JButton("All");
    btnROIselectall.setFont(new Font("Tahoma", Font.PLAIN, 11));
    btnROIselectall.setEnabled(false);
    btnROIselectall.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            int[] count = new int[listModel.size()];
            for (int i = 0; i < listModel.size(); ++i)
                count[i] = i;
            listCompareRoi.setSelectedIndices(count);
        }
    });
    btnROIselectall.setToolTipText("Select all machines");
    btnROIselectall.setBounds(105, 7, 57, 23);
    panel_4.add(btnROIselectall);

    lblROIselect = new JLabel("Select:");
    lblROIselect.setEnabled(false);
    lblROIselect.setBounds(37, 11, 46, 14);
    panel_4.add(lblROIselect);

    tabsROI = new JTabbedPane(JTabbedPane.TOP);
    tabsROI.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent arg0) {
            try {
                ResetStatusLabel();
            } catch (NullPointerException e) {
                // Form is still initialising
                return;
            }

            int tab = tabsROI.getSelectedIndex();
            switch (tab) {
            case 0:
                UpdateROIProd();
                break;
            case 1:
                UpdateROIEnergy();
                break;
            case 2:
                UpdateROIMaint();
                break;
            case 3:
                UpdateROIWaste();
                break;
            }
        }
    });
    tabsROI.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
    tabsROI.setBounds(29, 72, 470, 424);
    pnlROI.add(tabsROI);

    pnlProdROI = new JPanel();
    pnlProdROI.setBackground(Color.WHITE);
    tabsROI.addTab("Productivity", null, pnlProdROI, "ROI based on productivity");
    pnlProdROI.setLayout(null);

    lblThisToolIlllustrates = new JLabel(
            "This tool illlustrates the long-term financial benfits of particular machines and options in");
    lblThisToolIlllustrates.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblThisToolIlllustrates.setForeground(Color.GRAY);
    lblThisToolIlllustrates.setBounds(10, 11, 439, 14);
    pnlProdROI.add(lblThisToolIlllustrates);

    lblInTermsOf = new JLabel("terms of productivity gains.");
    lblInTermsOf.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblInTermsOf.setForeground(Color.GRAY);
    lblInTermsOf.setBounds(10, 27, 317, 14);
    pnlProdROI.add(lblInTermsOf);

    pnlGraphProd = new JPanel();
    pnlGraphProd.setBackground(Color.WHITE);
    pnlGraphProd.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, null, null, null));
    pnlGraphProd.setBounds(10, 100, 439, 230);
    pnlProdROI.add(pnlGraphProd);
    pnlGraphProd.setLayout(null);

    pnlGraphProdInner = new ChartPanel(null);
    pnlGraphProdInner.setBounds(2, 2, 435, 226);
    //pnlGraphProd.add(pnlGraphProdInner);

    try {
        lblNoGraph = new JLabel(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/no_preview.png"))));
    } catch (IOException e2) {
        e2.printStackTrace();
    }
    lblNoGraph.setBounds(2, 2, 435, 226);
    pnlGraphProd.add(lblNoGraph);

    lblSellingPrice = new JLabel("Selling price:");
    lblSellingPrice.setEnabled(false);
    lblSellingPrice.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblSellingPrice.setBounds(10, 52, 60, 14);
    pnlProdROI.add(lblSellingPrice);

    txtsellingprice = new JTextField();
    txtsellingprice.setToolTipText("Average selling price of the material per unit weight");
    txtsellingprice.setEnabled(false);
    txtsellingprice.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent arg0) {
            txtsellingprice.selectAll();
        }
    });
    txtsellingprice.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent arg0) {
        }

        @Override
        public void insertUpdate(DocumentEvent arg0) {
            UpdateROIValue();
        }

        @Override
        public void removeUpdate(DocumentEvent arg0) {
            UpdateROIValue();
        }

    });
    txtsellingprice.setFont(new Font("Tahoma", Font.PLAIN, 11));
    txtsellingprice.setBounds(90, 49, 65, 20);
    pnlProdROI.add(txtsellingprice);
    txtsellingprice.setColumns(10);

    lblPerTonne = new JLabel("per tonne");
    lblPerTonne.setEnabled(false);
    lblPerTonne.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblPerTonne.setBounds(160, 52, 70, 14);
    pnlProdROI.add(lblPerTonne);

    lblContribution = new JLabel("Contribution:");
    lblContribution.setEnabled(false);
    lblContribution.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblContribution.setBounds(10, 75, 70, 14);
    pnlProdROI.add(lblContribution);

    txtcontribution = new JTextField();
    txtcontribution.setToolTipText("Contribution percentage");
    txtcontribution.setEnabled(false);
    txtcontribution.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtcontribution.selectAll();
        }
    });
    txtcontribution.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            UpdateROIValue();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            UpdateROIValue();
        }
    });
    txtcontribution.setFont(new Font("Tahoma", Font.PLAIN, 11));
    txtcontribution.setBounds(90, 73, 65, 20);
    pnlProdROI.add(txtcontribution);
    txtcontribution.setColumns(10);

    lblpercent = new JLabel("%");
    lblpercent.setEnabled(false);
    lblpercent.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblpercent.setBounds(160, 76, 11, 14);
    pnlProdROI.add(lblpercent);

    lblValueAddedlbl = new JLabel("Value added:");
    lblValueAddedlbl.setEnabled(false);
    lblValueAddedlbl.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblValueAddedlbl.setBounds(279, 52, 70, 14);
    pnlProdROI.add(lblValueAddedlbl);

    lblvalueadded = new JLabel("\u00A30.00 / tonne");
    lblvalueadded.setToolTipText("Value added per unit weight");
    lblvalueadded.setEnabled(false);
    lblvalueadded.setFont(new Font("Tahoma", Font.BOLD, 12));
    lblvalueadded.setBounds(279, 71, 170, 20);
    pnlProdROI.add(lblvalueadded);

    cmbMarg1 = new JComboBox();
    cmbMarg1.setToolTipText("Old machine");
    cmbMarg1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            UpdateROIProd();
        }
    });
    cmbMarg1.setEnabled(false);
    cmbMarg1.setFont(new Font("Tahoma", Font.PLAIN, 11));
    cmbMarg1.setBounds(10, 359, 111, 20);
    pnlProdROI.add(cmbMarg1);

    cmbMarg2 = new JComboBox();
    cmbMarg2.setToolTipText("New machine");
    cmbMarg2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            UpdateROIProd();
        }
    });
    cmbMarg2.setEnabled(false);
    cmbMarg2.setFont(new Font("Tahoma", Font.PLAIN, 11));
    cmbMarg2.setBounds(141, 359, 111, 20);
    pnlProdROI.add(cmbMarg2);

    lblMarginalImprovement = new JLabel("\u00A30.00 per annum");
    lblMarginalImprovement.setToolTipText("Marginal improvement");
    lblMarginalImprovement.setEnabled(false);
    lblMarginalImprovement.setFont(new Font("Tahoma", Font.BOLD, 13));
    lblMarginalImprovement.setBounds(279, 358, 170, 20);
    pnlProdROI.add(lblMarginalImprovement);

    lblSelectMachines = new JLabel("Select 2 machines to view the marginal improvement between them:");
    lblSelectMachines.setForeground(Color.GRAY);
    lblSelectMachines.setFont(new Font("Tahoma", Font.BOLD, 11));
    lblSelectMachines.setBounds(10, 338, 412, 14);
    pnlProdROI.add(lblSelectMachines);

    lblpound1 = new JLabel("\u00A3");
    lblpound1.setEnabled(false);
    lblpound1.setBounds(80, 52, 11, 14);
    pnlProdROI.add(lblpound1);

    lblTo = new JLabel("to");
    lblTo.setForeground(Color.GRAY);
    lblTo.setFont(new Font("Tahoma", Font.BOLD, 11));
    lblTo.setBounds(125, 362, 16, 14);
    pnlProdROI.add(lblTo);

    label = new JLabel("=");
    label.setForeground(Color.GRAY);
    label.setFont(new Font("Tahoma", Font.BOLD, 13));
    label.setBounds(259, 362, 11, 14);
    pnlProdROI.add(label);

    pnlEnergy = new JPanel();
    pnlEnergy.setBackground(Color.WHITE);
    tabsROI.addTab("Energy Efficiency", null, pnlEnergy, "ROI based on machine power usage");
    pnlEnergy.setLayout(null);

    lblThisToolHighlights = new JLabel(
            "This tool highlights power consumption differences between machines, and the resulting");
    lblThisToolHighlights.setForeground(Color.GRAY);
    lblThisToolHighlights.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblThisToolHighlights.setBounds(10, 11, 439, 14);
    pnlEnergy.add(lblThisToolHighlights);

    lblImpactOnFinancial = new JLabel("impact on financial returns.");
    lblImpactOnFinancial.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblImpactOnFinancial.setForeground(Color.GRAY);
    lblImpactOnFinancial.setBounds(10, 27, 439, 14);
    pnlEnergy.add(lblImpactOnFinancial);

    rdbtnAveragePower = new JRadioButton("Average power");
    rdbtnAveragePower.setToolTipText("Select \"average power\" input type");
    rdbtnAveragePower.setFont(new Font("Tahoma", Font.PLAIN, 11));
    rdbtnAveragePower.setEnabled(false);
    rdbtnAveragePower.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            ClearPowerTxts();
            txtaveragepower.setEnabled(true);
            txthourlyusage.setEnabled(false);
            txtannualusage.setEnabled(false);
            lblKw.setEnabled(true);
            lblKwh.setEnabled(false);
            lblKwh_1.setEnabled(false);
            txtaveragepower.requestFocusInWindow();
            UpdateEnergyData();
        }
    });
    rdbtnAveragePower.setSelected(true);
    rdbtnAveragePower.setBackground(Color.WHITE);
    rdbtnAveragePower.setBounds(349, 44, 109, 23);
    pnlEnergy.add(rdbtnAveragePower);

    rdbtnHourlyUsage = new JRadioButton("Hourly usage");
    rdbtnHourlyUsage.setToolTipText("Select \"hourly usage\" input type");
    rdbtnHourlyUsage.setFont(new Font("Tahoma", Font.PLAIN, 11));
    rdbtnHourlyUsage.setEnabled(false);
    rdbtnHourlyUsage.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ClearPowerTxts();
            txtaveragepower.setEnabled(false);
            txthourlyusage.setEnabled(true);
            txtannualusage.setEnabled(false);
            lblKw.setEnabled(false);
            lblKwh.setEnabled(true);
            lblKwh_1.setEnabled(false);
            txthourlyusage.requestFocusInWindow();
            UpdateEnergyData();
        }
    });
    rdbtnHourlyUsage.setBackground(Color.WHITE);
    rdbtnHourlyUsage.setBounds(349, 70, 109, 23);
    pnlEnergy.add(rdbtnHourlyUsage);

    rdbtnAnnualUsage = new JRadioButton("Annual usage");
    rdbtnAnnualUsage.setToolTipText("Select \"annual usage\" input type");
    rdbtnAnnualUsage.setFont(new Font("Tahoma", Font.PLAIN, 11));
    rdbtnAnnualUsage.setEnabled(false);
    rdbtnAnnualUsage.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ClearPowerTxts();
            txtaveragepower.setEnabled(false);
            txthourlyusage.setEnabled(false);
            txtannualusage.setEnabled(true);
            lblKw.setEnabled(false);
            lblKwh.setEnabled(false);
            lblKwh_1.setEnabled(true);
            txtannualusage.requestFocusInWindow();
            UpdateEnergyData();
        }
    });
    rdbtnAnnualUsage.setBackground(Color.WHITE);
    rdbtnAnnualUsage.setBounds(349, 97, 109, 23);
    pnlEnergy.add(rdbtnAnnualUsage);

    rdbtnsPower.add(rdbtnAveragePower);
    rdbtnsPower.add(rdbtnHourlyUsage);
    rdbtnsPower.add(rdbtnAnnualUsage);

    lblEnergyCostl = new JLabel("Energy cost:");
    lblEnergyCostl.setEnabled(false);
    lblEnergyCostl.setFont(new Font("Tahoma", Font.BOLD, 11));
    lblEnergyCostl.setBounds(10, 101, 72, 14);
    pnlEnergy.add(lblEnergyCostl);

    lblpound2 = new JLabel("\u00A3");
    lblpound2.setEnabled(false);
    lblpound2.setFont(new Font("Tahoma", Font.PLAIN, 12));
    lblpound2.setBounds(91, 100, 13, 14);
    pnlEnergy.add(lblpound2);

    txtenergycost = new JTextField();
    txtenergycost.setToolTipText("Raw energy cost, per kWh");
    txtenergycost.setEnabled(false);
    txtenergycost.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent arg0) {
            txtenergycost.selectAll();
        }
    });
    txtenergycost.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent arg0) {
            UpdateROIEnergy();
        }

        @Override
        public void insertUpdate(DocumentEvent arg0) {
            UpdateROIEnergy();
        }

        @Override
        public void changedUpdate(DocumentEvent arg0) {
        }
    });
    txtenergycost.setFont(new Font("Tahoma", Font.PLAIN, 12));
    txtenergycost.setBounds(102, 98, 74, 20);
    pnlEnergy.add(txtenergycost);
    txtenergycost.setColumns(10);

    lblPerKwh = new JLabel("per kWh");
    lblPerKwh.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblPerKwh.setEnabled(false);
    lblPerKwh.setBounds(179, 101, 46, 14);
    pnlEnergy.add(lblPerKwh);

    txtaveragepower = new JTextField();
    txtaveragepower.setToolTipText("Average power in kW");
    txtaveragepower.setEnabled(false);
    txtaveragepower.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent arg0) {
            UpdateEnergyData();
        }

        @Override
        public void insertUpdate(DocumentEvent arg0) {
            UpdateEnergyData();
        }

        @Override
        public void changedUpdate(DocumentEvent arg0) {
        }
    });
    txtaveragepower.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtaveragepower.selectAll();
        }
    });
    txtaveragepower.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent arg0) {
            if (txtLimitRunSpeed.contains(arg0.getPoint())) {
                if (!txtaveragepower.isEnabled()) {
                    rdbtnAveragePower.doClick();
                }
            }
        }
    });
    txtaveragepower.setBounds(233, 47, 86, 20);
    pnlEnergy.add(txtaveragepower);
    txtaveragepower.setColumns(10);

    txthourlyusage = new JTextField();
    txthourlyusage.setToolTipText("Average hourly energy usage");
    txthourlyusage.setEnabled(false);
    txthourlyusage.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            UpdateEnergyData();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            UpdateEnergyData();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }
    });
    txthourlyusage.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txthourlyusage.selectAll();
        }
    });
    txthourlyusage.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent arg0) {
            if (txtLimitRunSpeed.contains(arg0.getPoint())) {
                if (!txthourlyusage.isEnabled())
                    rdbtnHourlyUsage.doClick();
            }
        }
    });
    txthourlyusage.setColumns(10);
    txthourlyusage.setBounds(233, 73, 86, 20);
    pnlEnergy.add(txthourlyusage);

    txtannualusage = new JTextField();
    txtannualusage.setToolTipText("Average annual energy usage");
    txtannualusage.setEnabled(false);
    txtannualusage.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            UpdateEnergyData();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            UpdateEnergyData();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }
    });
    txtannualusage.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtannualusage.selectAll();
        }
    });
    txtannualusage.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent arg0) {
            if (txtLimitRunSpeed.contains(arg0.getPoint())) {
                if (!txtannualusage.isEnabled())
                    rdbtnAnnualUsage.doClick();
            }
        }
    });
    txtannualusage.setColumns(10);
    txtannualusage.setBounds(233, 99, 86, 20);
    pnlEnergy.add(txtannualusage);

    cmbMachineEnergy = new JComboBox();
    cmbMachineEnergy.setEnabled(false);
    cmbMachineEnergy.setToolTipText("Select machine to edit");
    cmbMachineEnergy.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            UpdateEnergyView();
        }
    });
    cmbMachineEnergy.setBounds(69, 46, 152, 23);
    pnlEnergy.add(cmbMachineEnergy);

    lblMachine_1 = new JLabel("Machine:");
    lblMachine_1.setEnabled(false);
    lblMachine_1.setFont(new Font("Tahoma", Font.BOLD, 11));
    lblMachine_1.setBounds(10, 50, 59, 14);
    pnlEnergy.add(lblMachine_1);

    lblKw = new JLabel("kW");
    lblKw.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblKw.setEnabled(false);
    lblKw.setBounds(323, 50, 15, 14);
    pnlEnergy.add(lblKw);

    lblKwh = new JLabel("kWh");
    lblKwh.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblKwh.setEnabled(false);
    lblKwh.setBounds(323, 76, 26, 14);
    pnlEnergy.add(lblKwh);

    lblKwh_1 = new JLabel("MWh");
    lblKwh_1.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblKwh_1.setEnabled(false);
    lblKwh_1.setBounds(323, 102, 26, 14);
    pnlEnergy.add(lblKwh_1);

    pnlGraphEnergy = new JPanel();
    pnlGraphEnergy.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, null, null, null));
    pnlGraphEnergy.setBackground(Color.WHITE);
    pnlGraphEnergy.setBounds(10, 126, 439, 226);
    pnlEnergy.add(pnlGraphEnergy);
    pnlGraphEnergy.setLayout(null);
    try {
        lblNoGraph2 = new JLabel(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/no_preview.png"))));
    } catch (IOException e2) {
        e2.printStackTrace();
    }
    lblNoGraph2.setBounds(2, 2, 435, 222);
    pnlGraphEnergy.add(lblNoGraph2);

    lblPleaseSetPower = new JLabel("Please set power usage for each machine");
    lblPleaseSetPower.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblPleaseSetPower.setEnabled(false);
    lblPleaseSetPower.setForeground(Color.GRAY);
    lblPleaseSetPower.setBounds(10, 74, 215, 14);
    pnlEnergy.add(lblPleaseSetPower);

    lblMarginalEnergy = new JLabel("\u00A30.00 per annum");
    lblMarginalEnergy.setToolTipText("Marginal improvement");
    lblMarginalEnergy.setFont(new Font("Tahoma", Font.BOLD, 13));
    lblMarginalEnergy.setEnabled(false);
    lblMarginalEnergy.setBounds(279, 358, 170, 20);
    pnlEnergy.add(lblMarginalEnergy);

    label_4 = new JLabel("=");
    label_4.setForeground(Color.GRAY);
    label_4.setFont(new Font("Tahoma", Font.BOLD, 13));
    label_4.setBounds(259, 362, 11, 14);
    pnlEnergy.add(label_4);

    cmbMargEnergy2 = new JComboBox();
    cmbMargEnergy2.setToolTipText("New machine");
    cmbMargEnergy2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            UpdateROIEnergy();
        }
    });
    cmbMargEnergy2.setFont(new Font("Tahoma", Font.PLAIN, 11));
    cmbMargEnergy2.setEnabled(false);
    cmbMargEnergy2.setBounds(141, 359, 111, 20);
    pnlEnergy.add(cmbMargEnergy2);

    label_5 = new JLabel("to");
    label_5.setForeground(Color.GRAY);
    label_5.setFont(new Font("Tahoma", Font.BOLD, 11));
    label_5.setBounds(125, 362, 16, 14);
    pnlEnergy.add(label_5);

    cmbMargEnergy1 = new JComboBox();
    cmbMargEnergy1.setToolTipText("Old machine");
    cmbMargEnergy1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            UpdateROIEnergy();
        }
    });
    cmbMargEnergy1.setFont(new Font("Tahoma", Font.PLAIN, 11));
    cmbMargEnergy1.setEnabled(false);
    cmbMargEnergy1.setBounds(10, 359, 111, 20);
    pnlEnergy.add(cmbMargEnergy1);

    pnlMaint = new JPanel();
    pnlMaint.setBackground(Color.WHITE);
    tabsROI.addTab("Maintenance", null, pnlMaint, "ROI based on maintenance costs");
    tabsROI.setMnemonicAt(2, 65);
    pnlMaint.setLayout(null);

    lblThisToolDemonstrates_1 = new JLabel(
            "This tool demonstrates the maintenance reduction benefits of machines.");
    lblThisToolDemonstrates_1.setBounds(10, 11, 421, 14);
    lblThisToolDemonstrates_1.setForeground(Color.GRAY);
    lblThisToolDemonstrates_1.setFont(new Font("Tahoma", Font.PLAIN, 11));
    pnlMaint.add(lblThisToolDemonstrates_1);

    lblMaintenanceHoursPer = new JLabel("Annual downtime:");
    lblMaintenanceHoursPer.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblMaintenanceHoursPer.setEnabled(false);
    lblMaintenanceHoursPer.setBounds(10, 64, 86, 14);
    pnlMaint.add(lblMaintenanceHoursPer);

    lblRepairCostsPer = new JLabel("Labour costs per hour:");
    lblRepairCostsPer.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblRepairCostsPer.setEnabled(false);
    lblRepairCostsPer.setBounds(255, 36, 111, 14);
    pnlMaint.add(lblRepairCostsPer);

    lblPartsCostsPer = new JLabel("Parts costs per year:");
    lblPartsCostsPer.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblPartsCostsPer.setEnabled(false);
    lblPartsCostsPer.setBounds(255, 64, 101, 14);
    pnlMaint.add(lblPartsCostsPer);

    cmbMachinesmaintenance = new JComboBox();
    cmbMachinesmaintenance.setEnabled(false);
    cmbMachinesmaintenance.setToolTipText("Please set maintenance costs for each machine");
    cmbMachinesmaintenance.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ViewMaintCosts();
        }
    });
    cmbMachinesmaintenance.setBounds(79, 30, 152, 23);
    pnlMaint.add(cmbMachinesmaintenance);

    txtmaintenancehours = new JTextField();
    txtmaintenancehours.setToolTipText("Hours per year for which machine is not running due to maintenance");
    txtmaintenancehours.setEnabled(false);
    txtmaintenancehours.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtmaintenancehours.selectAll();
        }
    });
    txtmaintenancehours.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            UpdateMaintCosts();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            UpdateMaintCosts();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }
    });
    txtmaintenancehours.setBounds(106, 61, 67, 20);
    pnlMaint.add(txtmaintenancehours);
    txtmaintenancehours.setColumns(10);

    txtmaintenanceperhour = new JTextField();
    txtmaintenanceperhour.setToolTipText("Hourly labour costs for maintenance");
    txtmaintenanceperhour.setEnabled(false);
    txtmaintenanceperhour.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtmaintenanceperhour.selectAll();
        }
    });
    txtmaintenanceperhour.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            UpdateMaintCosts();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            UpdateMaintCosts();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }
    });
    txtmaintenanceperhour.setColumns(10);
    txtmaintenanceperhour.setBounds(382, 33, 67, 20);
    pnlMaint.add(txtmaintenanceperhour);

    txtmaintenanceparts = new JTextField();
    txtmaintenanceparts.setToolTipText("Annual cost of maintenance parts for this machine");
    txtmaintenanceparts.setEnabled(false);
    txtmaintenanceparts.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtmaintenanceparts.selectAll();
        }
    });
    txtmaintenanceparts.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            UpdateMaintCosts();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            UpdateMaintCosts();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }
    });
    txtmaintenanceparts.setColumns(10);
    txtmaintenanceparts.setBounds(382, 61, 67, 20);
    pnlMaint.add(txtmaintenanceparts);

    lbltotalmaintcost = new JLabel("\u00A30.00 / year");
    lbltotalmaintcost.setToolTipText("Total annual spend on maintenance for this machine (labour + parts)");
    lbltotalmaintcost.setForeground(Color.GRAY);
    lbltotalmaintcost.setEnabled(false);
    lbltotalmaintcost.setHorizontalAlignment(SwingConstants.LEFT);
    lbltotalmaintcost.setFont(new Font("Tahoma", Font.BOLD, 11));
    lbltotalmaintcost.setBounds(344, 87, 105, 14);
    pnlMaint.add(lbltotalmaintcost);

    lblpound10 = new JLabel("\u00A3");
    lblpound10.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblpound10.setEnabled(false);
    lblpound10.setBounds(373, 36, 11, 14);
    pnlMaint.add(lblpound10);

    lblpound11 = new JLabel("\u00A3");
    lblpound11.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblpound11.setEnabled(false);
    lblpound11.setBounds(373, 64, 11, 14);
    pnlMaint.add(lblpound11);

    pnlGraphMaint = new JPanel();
    pnlGraphMaint.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, null, null, null));
    pnlGraphMaint.setBackground(Color.WHITE);
    pnlGraphMaint.setBounds(10, 110, 439, 242);
    pnlMaint.add(pnlGraphMaint);
    pnlGraphMaint.setLayout(null);
    try {
        lblNoGraph3 = new JLabel(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/no_preview.png"))));
    } catch (IOException e2) {
        e2.printStackTrace();
    }
    lblNoGraph3.setBounds(2, 2, 435, 238);
    pnlGraphMaint.add(lblNoGraph3);

    cmbMargMaint1 = new JComboBox();
    cmbMargMaint1.setToolTipText("Old machine");
    cmbMargMaint1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            UpdateROIMaint();
        }
    });
    cmbMargMaint1.setFont(new Font("Tahoma", Font.PLAIN, 11));
    cmbMargMaint1.setEnabled(false);
    cmbMargMaint1.setBounds(10, 359, 111, 20);
    pnlMaint.add(cmbMargMaint1);

    label_8 = new JLabel("to");
    label_8.setForeground(Color.GRAY);
    label_8.setFont(new Font("Tahoma", Font.BOLD, 11));
    label_8.setBounds(125, 362, 16, 14);
    pnlMaint.add(label_8);

    cmbMargMaint2 = new JComboBox();
    cmbMargMaint2.setToolTipText("New machine");
    cmbMargMaint2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            UpdateROIMaint();
        }
    });
    cmbMargMaint2.setFont(new Font("Tahoma", Font.PLAIN, 11));
    cmbMargMaint2.setEnabled(false);
    cmbMargMaint2.setBounds(141, 359, 111, 20);
    pnlMaint.add(cmbMargMaint2);

    label_9 = new JLabel("=");
    label_9.setForeground(Color.GRAY);
    label_9.setFont(new Font("Tahoma", Font.BOLD, 13));
    label_9.setBounds(259, 362, 11, 14);
    pnlMaint.add(label_9);

    lblMarginalMaint = new JLabel("\u00A30.00 per annum");
    lblMarginalMaint.setToolTipText("Marginal improvement");
    lblMarginalMaint.setFont(new Font("Tahoma", Font.BOLD, 13));
    lblMarginalMaint.setEnabled(false);
    lblMarginalMaint.setBounds(279, 358, 170, 20);
    pnlMaint.add(lblMarginalMaint);

    lblProdLoss = new JLabel("\u00A30.00 / year");
    lblProdLoss.setToolTipText("Loss in production value due to downtime");
    lblProdLoss.setForeground(Color.GRAY);
    lblProdLoss.setEnabled(false);
    lblProdLoss.setHorizontalAlignment(SwingConstants.LEFT);
    lblProdLoss.setFont(new Font("Tahoma", Font.BOLD, 11));
    lblProdLoss.setBounds(106, 87, 125, 14);
    pnlMaint.add(lblProdLoss);

    lblHrs_1 = new JLabel("hrs");
    lblHrs_1.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblHrs_1.setEnabled(false);
    lblHrs_1.setBounds(180, 64, 16, 14);
    pnlMaint.add(lblHrs_1);

    label_10 = new JLabel("Machine:");
    label_10.setEnabled(false);
    label_10.setFont(new Font("Tahoma", Font.BOLD, 11));
    label_10.setBounds(10, 34, 59, 14);
    pnlMaint.add(label_10);

    label_11 = new JLabel("=");
    label_11.setEnabled(false);
    label_11.setForeground(Color.GRAY);
    label_11.setFont(new Font("Tahoma", Font.BOLD, 13));
    label_11.setBounds(88, 87, 11, 14);
    pnlMaint.add(label_11);

    label_12 = new JLabel("=");
    label_12.setEnabled(false);
    label_12.setForeground(Color.GRAY);
    label_12.setFont(new Font("Tahoma", Font.BOLD, 13));
    label_12.setBounds(323, 87, 11, 14);
    pnlMaint.add(label_12);

    lblAnnualTotal = new JLabel("Annual total");
    lblAnnualTotal.setEnabled(false);
    lblAnnualTotal.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblAnnualTotal.setBounds(255, 87, 67, 14);
    pnlMaint.add(lblAnnualTotal);

    lblProductionLoss = new JLabel("Production loss");
    lblProductionLoss.setEnabled(false);
    lblProductionLoss.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblProductionLoss.setBounds(10, 87, 77, 14);
    pnlMaint.add(lblProductionLoss);

    pnlWaste = new JPanel();
    pnlWaste.setBackground(Color.WHITE);
    tabsROI.addTab("Waste Reduction", null, pnlWaste, "ROI based on waste reduction");
    pnlWaste.setLayout(null);

    lblThisToolDemonstrates = new JLabel(
            "This tool demonstrates the waste reduction capabilities of particular machines.");
    lblThisToolDemonstrates.setForeground(Color.GRAY);
    lblThisToolDemonstrates.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblThisToolDemonstrates.setBounds(10, 11, 439, 14);
    pnlWaste.add(lblThisToolDemonstrates);

    lblWasteSavedPer_1 = new JLabel("Waste saved per splice due to flag detection camera:");
    lblWasteSavedPer_1.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblWasteSavedPer_1.setEnabled(false);
    lblWasteSavedPer_1.setBounds(10, 39, 256, 14);
    pnlWaste.add(lblWasteSavedPer_1);

    txtwastesavedflags = new JTextField();
    txtwastesavedflags.setToolTipText("Saving per splice");
    txtwastesavedflags.setEnabled(false);
    txtwastesavedflags.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtwastesavedflags.selectAll();
        }
    });
    txtwastesavedflags.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            UpdateROIWaste();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            UpdateROIWaste();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }
    });
    txtwastesavedflags.setBounds(286, 36, 86, 20);
    pnlWaste.add(txtwastesavedflags);
    txtwastesavedflags.setColumns(10);

    lblM_1 = new JLabel("m");
    lblM_1.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblM_1.setEnabled(false);
    lblM_1.setBounds(378, 39, 46, 14);
    pnlWaste.add(lblM_1);

    lblWasteSavedPer_2 = new JLabel("Waste saved per mother roll due to alignment guide:");
    lblWasteSavedPer_2.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblWasteSavedPer_2.setEnabled(false);
    lblWasteSavedPer_2.setBounds(10, 64, 256, 14);
    pnlWaste.add(lblWasteSavedPer_2);

    txtwastesavedguide = new JTextField();
    txtwastesavedguide.setToolTipText("Saving per mother roll");
    txtwastesavedguide.setEnabled(false);
    txtwastesavedguide.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            UpdateROIWaste();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            UpdateROIWaste();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }
    });
    txtwastesavedguide.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtwastesavedguide.selectAll();
        }
    });
    txtwastesavedguide.setBounds(286, 61, 86, 20);
    pnlWaste.add(txtwastesavedguide);
    txtwastesavedguide.setColumns(10);

    lblM_2 = new JLabel("m");
    lblM_2.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblM_2.setEnabled(false);
    lblM_2.setBounds(378, 64, 46, 14);
    pnlWaste.add(lblM_2);

    pnlGraphWaste = new JPanel();
    pnlGraphWaste.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, null, null, null));
    pnlGraphWaste.setBackground(Color.WHITE);
    pnlGraphWaste.setBounds(10, 90, 439, 262);
    pnlWaste.add(pnlGraphWaste);
    pnlGraphWaste.setLayout(null);
    try {
        lblNoGraph4 = new JLabel(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/no_preview.png"))));
    } catch (IOException e2) {
        e2.printStackTrace();
    }
    lblNoGraph4.setBounds(2, 2, 435, 258);
    pnlGraphWaste.add(lblNoGraph4);

    cmbMargWaste1 = new JComboBox();
    cmbMargWaste1.setToolTipText("Old machine");
    cmbMargWaste1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            UpdateROIWaste();
        }
    });
    cmbMargWaste1.setFont(new Font("Tahoma", Font.PLAIN, 11));
    cmbMargWaste1.setEnabled(false);
    cmbMargWaste1.setBounds(10, 359, 111, 20);
    pnlWaste.add(cmbMargWaste1);

    label_1 = new JLabel("to");
    label_1.setForeground(Color.GRAY);
    label_1.setFont(new Font("Tahoma", Font.BOLD, 11));
    label_1.setBounds(125, 362, 16, 14);
    pnlWaste.add(label_1);

    cmbMargWaste2 = new JComboBox();
    cmbMargWaste2.setToolTipText("New machine");
    cmbMargWaste2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            UpdateROIWaste();
        }
    });
    cmbMargWaste2.setFont(new Font("Tahoma", Font.PLAIN, 11));
    cmbMargWaste2.setEnabled(false);
    cmbMargWaste2.setBounds(141, 359, 111, 20);
    pnlWaste.add(cmbMargWaste2);

    label_6 = new JLabel("=");
    label_6.setForeground(Color.GRAY);
    label_6.setFont(new Font("Tahoma", Font.BOLD, 13));
    label_6.setBounds(259, 362, 11, 14);
    pnlWaste.add(label_6);

    lblMarginalWaste = new JLabel("0.00m per annum");
    lblMarginalWaste.setToolTipText("Marginal improvement");
    lblMarginalWaste.setFont(new Font("Tahoma", Font.BOLD, 13));
    lblMarginalWaste.setEnabled(false);
    lblMarginalWaste.setBounds(279, 355, 170, 16);
    pnlWaste.add(lblMarginalWaste);

    lblMarginalWasteValue = new JLabel("(\u00A30.00 per annum)");
    lblMarginalWasteValue.setToolTipText("Marginal improvement value");
    lblMarginalWasteValue.setForeground(Color.GRAY);
    lblMarginalWasteValue.setFont(new Font("Tahoma", Font.BOLD, 11));
    lblMarginalWasteValue.setBounds(279, 370, 170, 16);
    pnlWaste.add(lblMarginalWasteValue);

    machNames = new HashSet<String>();
    jobNames = new HashSet<String>();

    lblStatus = new JLabel(" Ready.");
    lblStatus.setFont(new Font("Tahoma", Font.PLAIN, 12));
    frmTitanRoiCalculator.getContentPane().add(lblStatus, BorderLayout.SOUTH);

    lblmmin = new JLabel("(m/min)");
    lblmmin.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblmmin.setEnabled(false);
    lblmmin.setBounds(206, 168, 44, 14);
    pnlJobs.add(lblmmin);

    objfilter = new OBJfilter(1);

    // labels for unit conversion
    labs = new JLabel[7];
    labs[0] = lblmm0;
    labs[1] = lblmm1;
    labs[2] = lblmm2;
    labs[3] = lblgm3;
    labs[4] = lblmm3;
    labs[5] = lblmicro0;

    lblGsm = new JLabel("(gsm)");
    lblGsm.setToolTipText("Switch the input type for density between gsm and g/cc");
    lblGsm.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblGsm.setEnabled(false);
    lblGsm.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent arg0) {
            if (lblGsm.isEnabled() && lblGsm.contains(arg0.getPoint())) {
                jobFormReady = false;
                try {
                    //double oldval = Double.parseDouble(txtDensity.getText());
                    //double thickness = Double.parseDouble(txtThickness.getText());
                    double oldval = ((Job) listJobs.getSelectedValue()).getDensity();
                    double thickness = ((Job) listJobs.getSelectedValue()).getThickness();
                    if (lblGsm.getText().equals("(gsm)")) {
                        lblGsm.setText("(g/cc)");
                        label_3.setVisible(false);
                        lblgm3.setText("(gsm)");
                        txtDensity.setText(Double.toString(roundTwoDecimals(oldval * thickness)));
                        ((Job) listJobs.getSelectedValue()).gsm = true;
                    } else {
                        lblGsm.setText("(gsm)");
                        label_3.setVisible(true);
                        lblgm3.setText("(g/cm  )");
                        txtDensity.setText(Double.toString(roundTwoDecimals(oldval)));
                        ((Job) listJobs.getSelectedValue()).gsm = false;
                    }
                } catch (Exception e) {
                    lblGsm.setText("(gsm)");
                    label_3.setVisible(true);
                    lblgm3.setText("(g/cm  )");
                    txtDensity.setText("0.92");
                }
                jobFormReady = true;

            }
        }

        @Override
        public void mouseEntered(MouseEvent arg0) {
            lblGsm.setForeground(new Color(0, 0, 128));
        }

        @Override
        public void mouseExited(MouseEvent e) {
            lblGsm.setForeground(Color.black);
        }
    });
    lblGsm.setForeground(new Color(0, 0, 0));
    lblGsm.setCursor(new Cursor(Cursor.HAND_CURSOR));
    lblGsm.setBounds(177, 102, 46, 14);
    pnlMaterials.add(lblGsm);

    lblOr = new JLabel("or:");
    lblOr.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblOr.setEnabled(false);
    lblOr.setBounds(155, 102, 14, 14);
    pnlMaterials.add(lblOr);
    labs[6] = lblmmin;

    cmbUnwindType = new JComboBox();
    cmbUnwindType.setToolTipText("Type of measure to use for the unwind quantity above");
    cmbUnwindType.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            UpdateUnwindAmount();
        }
    });
    cmbUnwindType.setEnabled(false);
    cmbUnwindType
            .setModel(new DefaultComboBoxModel(new String[] { "Length (m)", "Weight (kg)", "Diameter (mm)" }));
    cmbUnwindType.setBounds(92, 124, 95, 20);
    pnlUnwinds.add(cmbUnwindType);

    txtWebWidth = new JTextField();
    txtWebWidth.setToolTipText("Width of mother rolls");
    txtWebWidth.setText("1350");
    txtWebWidth.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent arg0) {
            txtWebWidth.selectAll();
        }
    });
    txtWebWidth.setEnabled(false);
    txtWebWidth.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent arg0) {
            UpdateJob();
        }

        @Override
        public void insertUpdate(DocumentEvent arg0) {
            UpdateJob();
        }

        @Override
        public void changedUpdate(DocumentEvent arg0) {
        }
    });
    txtWebWidth.setBounds(92, 26, 86, 20);
    pnlUnwinds.add(txtWebWidth);
    txtWebWidth.setColumns(10);

    lblAverageFlags = new JLabel("Average Flags:");
    lblAverageFlags.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblAverageFlags.setToolTipText("The average number of flags in each mother roll");
    lblAverageFlags.setEnabled(false);
    lblAverageFlags.setBounds(14, 79, 75, 14);
    pnlUnwinds.add(lblAverageFlags);

    txtFlagCount = new JTextField();
    txtFlagCount.setToolTipText("The average number of flags in each mother roll");
    txtFlagCount.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent arg0) {
            txtFlagCount.selectAll();
        }
    });
    txtFlagCount.getDocument().addDocumentListener(new JobInputChangeListener());
    txtFlagCount.setEnabled(false);
    txtFlagCount.setText("1");
    txtFlagCount.setBounds(92, 76, 43, 20);
    pnlUnwinds.add(txtFlagCount);
    txtFlagCount.setColumns(10);

    lblPerRoll = new JLabel("per roll");
    lblPerRoll.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblPerRoll.setEnabled(false);
    lblPerRoll.setBounds(140, 79, 46, 14);
    pnlUnwinds.add(lblPerRoll);

    txtLimitRunSpeed = new JTextField();
    txtLimitRunSpeed.setToolTipText(
            "Override for top machine speed (may be required for particular materials or environments)");
    txtLimitRunSpeed.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent arg0) {
            if (txtLimitRunSpeed.contains(arg0.getPoint())) {
                txtLimitRunSpeed.setEnabled(true);
                chckbxLimitRunSpeed.setSelected(true);
                txtLimitRunSpeed.requestFocusInWindow();
                txtLimitRunSpeed.selectAll();
                UpdateJob();
            }
        }
    });
    txtLimitRunSpeed.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            if (txtLimitRunSpeed.isEnabled()) {
                txtLimitRunSpeed.selectAll();
                chckbxLimitRunSpeed.setSelected(true);
            }
        }
    });
    txtLimitRunSpeed.getDocument().addDocumentListener(new JobInputChangeListener());
    txtLimitRunSpeed.setEnabled(false);

    txtLimitRunSpeed.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            chckbxLimitRunSpeed.setSelected(true);
        }
    });
    txtLimitRunSpeed.setText("800");
    txtLimitRunSpeed.setColumns(10);
    txtLimitRunSpeed.setBounds(130, 165, 65, 20);
    pnlJobs.add(txtLimitRunSpeed);

    cmbRewindType = new JComboBox();
    cmbRewindType.setToolTipText("Type of measure to use for rewind output above");
    cmbRewindType.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            UpdateRewindAmount();
            //UpdateJob();
        }
    });
    cmbRewindType.setEnabled(false);
    cmbRewindType
            .setModel(new DefaultComboBoxModel(new String[] { "Length (m)", "Weight (kg)", "Diameter (mm)" }));
    cmbRewindType.setBounds(109, 218, 95, 20);
    pnlJobs.add(cmbRewindType);

    chckbxLimitRunSpeed = new JCheckBox("");
    chckbxLimitRunSpeed.setToolTipText(
            "Override for top machine speed (may be required for particular materials or environments)");
    chckbxLimitRunSpeed.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (chckbxLimitRunSpeed.isSelected()) {
                txtLimitRunSpeed.setEnabled(true);
                txtLimitRunSpeed.requestFocusInWindow();
                txtLimitRunSpeed.selectAll();
            } else {
                txtLimitRunSpeed.setEnabled(false);
            }

            UpdateJob();
        }
    });
    chckbxLimitRunSpeed.setEnabled(false);
    chckbxLimitRunSpeed.setBounds(105, 164, 20, 20);
    pnlJobs.add(chckbxLimitRunSpeed);

    lblLimitRunSpeed = new JLabel("Speed Limit:");
    lblLimitRunSpeed.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblLimitRunSpeed.setToolTipText(
            "Override for top machine speed (may be required for particular materials or environments)");
    lblLimitRunSpeed.setEnabled(false);
    lblLimitRunSpeed.setBounds(47, 168, 59, 14);
    pnlJobs.add(lblLimitRunSpeed);

    lblKnifeType = new JLabel("Knife Type:");
    lblKnifeType.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblKnifeType.setToolTipText("Select knife type for this job");
    lblKnifeType.setEnabled(false);
    lblKnifeType.setHorizontalAlignment(SwingConstants.RIGHT);
    lblKnifeType.setBounds(46, 89, 59, 14);
    pnlJobs.add(lblKnifeType);

    cmbKnifeType = new JComboBox();
    cmbKnifeType.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            UpdateJob();
        }
    });
    cmbKnifeType.setModel(new DefaultComboBoxModel(new String[] { "Razor in Air", "Rotary Shear" }));
    cmbKnifeType.setToolTipText("Select knife type for this job");
    cmbKnifeType.setEnabled(false);
    cmbKnifeType.setBounds(109, 86, 95, 20);
    pnlJobs.add(cmbKnifeType);

    tabbedPane.setMnemonicAt(0, KeyEvent.VK_M);
    tabbedPane.setMnemonicAt(1, KeyEvent.VK_J);
    tabbedPane.setMnemonicAt(2, KeyEvent.VK_S);
    tabbedPane.setMnemonicAt(3, KeyEvent.VK_P);
    tabbedPane.setMnemonicAt(4, KeyEvent.VK_R);

    tabsROI.setMnemonicAt(0, KeyEvent.VK_D);
    tabsROI.setMnemonicAt(1, KeyEvent.VK_N);
    tabsROI.setMnemonicAt(3, KeyEvent.VK_W);

    scrollPane_4 = new JScrollPane();
    scrollPane_4.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
    scrollPane_4.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane_4.setBorder(null);
    scrollPane_4.setBounds(522, 44, 245, 405);
    pnlROI.add(scrollPane_4);

    panel_11 = new JPanel();
    panel_11.setToolTipText(
            "Click a machine to select it. Select two or more machines to compare their ROI measures.");
    scrollPane_4.setViewportView(panel_11);
    panel_11.setBackground(Color.WHITE);
    panel_11.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, null, null, null));
    panel_11.setLayout(new BorderLayout(0, 0));

    listCompareRoi = new JList(listModel);
    panel_11.add(listCompareRoi, BorderLayout.NORTH);
    listCompareRoi.setToolTipText(
            "Click a machine to select it. Select two or more machines to compare their ROI measures.");
    listCompareRoi.setBorder(null);
    listCompareRoi.setSelectionModel(new DefaultListSelectionModel() {
        private static final long serialVersionUID = 1L;

        boolean gestureStarted = false;

        @Override
        public void setSelectionInterval(int index0, int index1) {
            if (!gestureStarted) {
                if (isSelectedIndex(index0)) {
                    super.removeSelectionInterval(index0, index1);
                } else {
                    super.addSelectionInterval(index0, index1);
                }
            }
            gestureStarted = true;
        }

        @Override
        public void setValueIsAdjusting(boolean isAdjusting) {
            if (isAdjusting == false) {
                gestureStarted = false;
            }
        }

    });
    listCompareRoi.addListSelectionListener(new ROIListSelectionListener());
    listCompareRoi.setCellRenderer(new MachineListRenderer());
    listCompare.setSelectionModel(listCompareRoi.getSelectionModel());

    btnJobUp = new JButton("");
    btnJobUp.setToolTipText("Move job up");
    btnJobUp.addActionListener(new JobUpListener());
    try {
        btnJobUp.setIcon(new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/up.png"))));
        btnJobUp.setRolloverEnabled(true);
        btnJobUp.setRolloverIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/up_over.png"))));
        btnJobUp.setDisabledIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/up_dis.png"))));
    } catch (NullPointerException e11) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    btnJobUp.setEnabled(false);
    btnJobUp.setBounds(700, 463, 30, 30);
    pnlJob.add(btnJobUp);

    btnJobDown = new JButton("");
    btnJobDown.setToolTipText("Move job down");
    btnJobDown.addActionListener(new JobDownListener());
    try {
        btnJobDown.setIcon(new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/down.png"))));
        btnJobDown.setRolloverEnabled(true);
        btnJobDown.setRolloverIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/down_over.png"))));
        btnJobDown.setDisabledIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/down_dis.png"))));
    } catch (NullPointerException e11) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    btnJobDown.setEnabled(false);
    btnJobDown.setBounds(737, 463, 30, 30);
    pnlJob.add(btnJobDown);

    btnNewJob = new JButton("Add New");
    btnNewJob.setFont(new Font("Tahoma", Font.BOLD, 11));
    btnNewJob.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            jobFormReady = false;
            ResetStatusLabel();

            EnableJobForm();

            // new
            ResetJobForm();
            lblGsm.setText("(gsm)");
            label_3.setVisible(true);
            lblgm3.setText("(g/cm  )");
            txtDensity.setText("0.92");

            btnJobDelete.setEnabled(true);

            btnAddAll.setEnabled(true);

            /*if(listJobs.getSelectedIndex() == 0)
               btnJobUp.setEnabled(false);
            else
               btnJobUp.setEnabled(true);
                    
            if(listJobs.getSelectedIndex() == jobModel.getSize()-1)
               btnJobDown.setEnabled(false);
            else
               btnJobDown.setEnabled(true);*/

            int index = listJobs.getSelectedIndex();
            int size = jobModel.getSize();

            if (size >= Consts.JOB_LIST_LIMIT) { // Max list size
                ShowMessage("Maximum number of jobs allocated. Please delete before attempting to add more.");
                return;
            }

            String newName = getUniqueJobName("Job");
            txtJobName.setText(newName);
            job = new Job(newName);
            jobNames.add(newName.toLowerCase());

            //If no selection or if item in last position is selected,
            //add the new one to end of list, and select new one.
            if (index == -1 || (index + 1 == size)) {

                jobModel.addElement(job);
                listJobs.setSelectedIndex(size);
                listJobsAvail.setSelectedIndex(size);
                if (size > 0)
                    btnJobUp.setEnabled(true);

                //Otherwise insert the new one after the current selection,
                //and select new one.
            } else {
                jobModel.insertElementAt(job, index + 1);
                listJobs.setSelectedIndex(index + 1);
                listJobsAvail.setSelectedIndex(index + 1);
            }

            // TODO don't reset form, or add copy button

            ResetStatusLabel();
            jobFormReady = true;

            UpdateJob();
            txtJobName.requestFocusInWindow();
        }
    });
    try {
        btnNewJob.setIcon(new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/plus.png"))));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    btnNewJob.setToolTipText("Add new job");
    btnNewJob.setBounds(522, 460, 110, 36);
    pnlJob.add(btnNewJob);

    lblJobConfiguration = new JLabel("Job Configuration");
    lblJobConfiguration.setFont(new Font("Tahoma", Font.BOLD, 18));
    lblJobConfiguration.setBounds(29, 18, 269, 22);
    pnlJob.add(lblJobConfiguration);

    btnJobDelete = new JButton("");
    btnJobDelete.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ResetStatusLabel();

            Job selected = (Job) listJobs.getSelectedValue();
            jobNames.remove(selected.getName().toLowerCase());

            ListSelectionModel lsm = listJobs.getSelectionModel();
            int firstSelected = lsm.getMinSelectionIndex();
            int lastSelected = lsm.getMaxSelectionIndex();
            jobModel.removeRange(firstSelected, lastSelected);

            int size = jobModel.size();

            if (size == 0) {
                //List is empty: disable delete, up, and down buttons.
                /*btnJobDelete.setEnabled(false);
                btnJobUp.setEnabled(false);
                btnJobDown.setEnabled(false);*/

            } else {
                //Adjust the selection.
                if (firstSelected == jobModel.getSize()) {
                    //Removed item in last position.
                    firstSelected--;
                }
                listJobs.setSelectedIndex(firstSelected);

                if (size == 21) { // No longer full list
                    ResetStatusLabel();
                }

                job = (Job) listJobs.getSelectedValue();
            }
        }
    });

    try {
        btnJobDelete
                .setIcon(new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/delete.png"))));
        btnJobDelete.setRolloverEnabled(true);
        btnJobDelete.setRolloverIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/delete_over.png"))));
        btnJobDelete.setDisabledIcon(
                new ImageIcon(ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/delete_dis.png"))));
    } catch (NullPointerException e11) {
        System.out.println("Image load error");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    btnJobDelete.setToolTipText("Delete job");
    btnJobDelete.setRolloverEnabled(true);
    btnJobDelete.setEnabled(false);
    btnJobDelete.setBounds(651, 460, 36, 36);
    pnlJob.add(btnJobDelete);

    lblAddNewJobs = new JLabel(
            "Add new jobs to the list on the right, then configure unwind, rewind and material settings below");
    lblAddNewJobs.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblAddNewJobs.setBounds(29, 45, 483, 14);
    pnlJob.add(lblAddNewJobs);

    lblJobs = new JLabel("Jobs");
    lblJobs.setFont(new Font("Tahoma", Font.BOLD, 12));
    lblJobs.setBounds(522, 19, 85, 14);
    pnlJob.add(lblJobs);

    panel_1 = new JPanel();
    panel_1.setLayout(null);
    panel_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Total Output",
            TitledBorder.LEADING, TitledBorder.TOP, null, null));
    panel_1.setBounds(280, 380, 227, 116);
    pnlJob.add(panel_1);

    lblTargetOutputFor = new JLabel("Target output for job:");
    lblTargetOutputFor.setEnabled(false);
    lblTargetOutputFor.setBounds(30, 22, 129, 14);
    panel_1.add(lblTargetOutputFor);

    txtTargetTotal = new JTextField();
    txtTargetTotal.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtTargetTotal.selectAll();
        }
    });
    txtTargetTotal.getDocument().addDocumentListener(new JobInputChangeListener());
    txtTargetTotal.setToolTipText("Total output quantity for this job");
    txtTargetTotal.setText("10000");
    txtTargetTotal.setEnabled(false);
    txtTargetTotal.setColumns(10);
    txtTargetTotal.setBounds(30, 43, 118, 20);

    panel_1.add(txtTargetTotal);

    cmbTargetTotal = new JComboBox();
    cmbTargetTotal.setToolTipText("Type of measure to use for output quantity above");
    cmbTargetTotal.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            UpdateTotalsAmount();
        }
    });
    cmbTargetTotal.setModel(
            new DefaultComboBoxModel(new String[] { "Length (m)", "Weight (kg)", "Weight (tonnes)" }));
    cmbTargetTotal.setEnabled(false);
    cmbTargetTotal.setBounds(30, 67, 118, 20);
    panel_1.add(cmbTargetTotal);

    lblCounts = new JLabel("0 reel(s), 0 set(s), 0 mother(s)");
    lblCounts.setFont(new Font("Tahoma", Font.PLAIN, 11));
    lblCounts.setForeground(Color.GRAY);
    lblCounts.setBounds(30, 92, 187, 14);
    panel_1.add(lblCounts);

    panel_2 = new JPanel();
    panel_2.setLayout(null);
    panel_2.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Name", TitledBorder.LEADING,
            TitledBorder.TOP, null, new Color(0, 0, 0)));
    panel_2.setBounds(20, 72, 250, 83);
    pnlJob.add(panel_2);

    txtJobName = new JTextField();
    txtJobName.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            txtJobName.selectAll();
        }
    });
    txtJobName.setBounds(90, 30, 145, 28);
    panel_2.add(txtJobName);
    txtJobName.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent arg0) {
        }

        @Override
        public void insertUpdate(DocumentEvent arg0) {
            UpdateJobName();
        }

        @Override
        public void removeUpdate(DocumentEvent arg0) {
            UpdateJobName();
        }
    });
    txtJobName.setToolTipText("Set the name of this job");
    txtJobName.setFont(new Font("Tahoma", Font.BOLD, 12));
    txtJobName.setEnabled(false);
    txtJobName.setColumns(10);

    lblJobName = new JLabel("Job name:");
    lblJobName.setToolTipText("Set the name of this job");
    lblJobName.setEnabled(false);
    lblJobName.setBounds(22, 31, 60, 24);
    panel_2.add(lblJobName);
    lblJobName.setFont(new Font("Tahoma", Font.PLAIN, 13));

    btnResetJobs = new JButton("Reset");
    btnResetJobs.setBounds(20, 460, 100, 36);
    pnlJob.add(btnResetJobs);
    btnResetJobs.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ResetJobForm();
            UpdateJob();
        }
    });
    btnResetJobs.setToolTipText("Reset the form");
    btnResetJobs.setEnabled(false);

    scrollPane_1 = new JScrollPane();
    scrollPane_1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
    scrollPane_1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane_1.setBorder(null);
    scrollPane_1.setBounds(522, 44, 245, 405);
    pnlJob.add(scrollPane_1);

    panel_7 = new JPanel();
    panel_7.setToolTipText("Select a job to edit options, re-order, or delete");
    scrollPane_1.setViewportView(panel_7);
    panel_7.setBackground(Color.WHITE);
    panel_7.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, null, null, null));
    panel_7.setLayout(new BorderLayout(0, 0));

    listJobs = new JList(jobModel);
    listJobs.setSelectionModel(listJobsAvail.getSelectionModel());
    panel_7.add(listJobs, BorderLayout.NORTH);
    listJobs.setToolTipText("Select a job to edit options, re-order, or delete");
    listJobs.addListSelectionListener(new JobListSelectionListener());
    listJobs.setBorder(null);
    listJobs.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    listJobs.setCellRenderer(new JobListRenderer());
    pnlJob.setFocusTraversalPolicy(new FocusTraversalOnArray(
            new Component[] { cmbMaterials, txtThickness, txtDensity, cmbUnwindCore, txtUnwindAmount, txtSlits,
                    txtSlitWidth, cmbRewindCore, txtRewindAmount, cmbJobDomain, lblPresets, lblThickness_1,
                    lblDensity_1, pnlMaterials, lblWebWidthmm, lblmm0, lblUnwindCoremm, lblmm1, lblUnwindLength,
                    pnlUnwinds, lblmicro0, lblgm3, label_3, pnlJobs, lblTargetRewindLength, lblSlitWidth,
                    lblSlitCount, lblTrimtotal, lblTrim, lblRewindCoremm, lblPer_1, lblmm3, lblmm2 }));
    Image img = null;
    try {
        img = ImageIO.read(FrmMain.class.getResourceAsStream("/atlas/refresh.png"));
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
    Graphics g = bi.createGraphics();
    g.drawImage(img, 0, 0, 25, 25, null);

    LoadSettings();

    DoLicenceCheck();

    initialising = false;

}

From source file:nl.detoren.ijsco.ui.Mainscreen.java

private void addMenubar() {
    // Menu bar met 1 niveau
    Mainscreen ms = this;
    JMenuBar menubar = new JMenuBar();
    JMenu filemenu = new JMenu("Bestand");
    // File menu//w  w w . j  a va 2  s  .c o m
    JMenuItem item;
    /*      item = new JMenuItem("Openen...");
          item.setAccelerator(KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask()));
            
          item.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent arg0) {
    // Create a file chooser
    final JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File(System.getProperty("user.dir")));
    // In response to a button click:
    int returnVal = fc.showOpenDialog(ms);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
       File file = fc.getSelectedFile();
       logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + ".");
       //controller.leesBestand(file.getAbsolutePath());
       ms.repaint();
    }
             }
          });
          filemenu.add(item);
    */
    /*      item = new JMenuItem("Opslaan");
          item.setAccelerator(KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask()));
          item.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent arg0) {
    //controller.saveState(true, "save");
             }
          });
          filemenu.add(item);
    */
    filemenu.addSeparator();
    item = new JMenuItem("Instellingen...");
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            actieInstellingen();
        }
    });
    item.setAccelerator(KeyStroke.getKeyStroke('I', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    filemenu.add(item);
    filemenu.addSeparator();
    item = new JMenuItem("Afsluiten");
    item.setAccelerator(KeyStroke.getKeyStroke('Q', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            controller.saveState(false, null);
            System.exit(EXIT_ON_CLOSE);
        }
    });
    filemenu.add(item);
    menubar.add(filemenu);

    /**
     *  Toernooi menu 
      */

    JMenu toernooimenu = new JMenu("Toernooi");
    item = new JMenuItem("Toernooiinformatie");
    item.setAccelerator(KeyStroke.getKeyStroke('T', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //actieNieuweSpeler(null, null);
            bewerkToernooi();
            hoofdPanel.repaint();
        }
    });
    toernooimenu.add(item);
    menubar.add(toernooimenu);

    /**
     *  Spelersdatabase menu 
      */

    JMenu spelermenu = new JMenu("Spelersdatabase");

    item = new JMenuItem("OSBO JSON lijst ophalen (Online)");
    item.setAccelerator(KeyStroke.getKeyStroke('J', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //actieNieuweSpeler(null, null);
            leeslijstOnline("www.osbo.nl", "/jeugd/currentratings.json");
            hoofdPanel.repaint();
        }
    });
    spelermenu.add(item);

    item = new JMenuItem("OSBO htmllijst ophalen !verouderd! (Online)");
    item.setAccelerator(KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //actieNieuweSpeler(null, null);
            leeslijstOnline("www.osbo.nl", "/jeugd/jrating.htm");
            hoofdPanel.repaint();
        }
    });
    spelermenu.add(item);

    item = new JMenuItem("OSBO/IJSCO compatible lijst inlezen (Bestand)");
    item.setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // Create a file chooser
            final JFileChooser fc = new JFileChooser();
            fc.setCurrentDirectory(new File(System.getProperty("user.dir")));
            // In response to a button click:
            int returnVal = fc.showOpenDialog(ms);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + ".");
                leesOSBOlijstBestand(file.getAbsolutePath());
            }
            hoofdPanel.repaint();
        }
    });
    spelermenu.add(item);

    /*      item = new JMenuItem("Groslijst CSV inlezen (Bestand) N/A");
          item.setAccelerator(KeyStroke.getKeyStroke('C', Toolkit.getDefaultToolkit ().getMenuShortcutKeyMask()));
          item.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
    //actieNieuweSpeler(null, null);
    // Create a file chooser
    final JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(new File(System.getProperty("user.dir")));
    // In response to a button click:
    int returnVal = fc.showOpenDialog(ms);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
       File file = fc.getSelectedFile();
       logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + ".");
       leesCSV(file.getAbsolutePath());
    }
    hoofdPanel.repaint();
             }
          });
          spelermenu.add(item);
    */
    menubar.add(spelermenu);

    JMenu deelnemersmenu = new JMenu("Deelnemers");

    item = new JMenuItem("Wis Deelnemerslijst");
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // Create a file chooser
            wisDeelnemers();
            hoofdPanel.repaint();
        }
    });
    deelnemersmenu.add(item);

    item = new JMenuItem("Importeren Deelnemerslijst");
    item.setAccelerator(KeyStroke.getKeyStroke('I', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // Create a file chooser
            final JFileChooser fc = new JFileChooser();
            fc.setCurrentDirectory(new File(System.getProperty("user.dir")));
            // In response to a button click:
            int returnVal = fc.showOpenDialog(ms);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + ".");
                leesDeelnemers(file.getAbsolutePath());
            }
            hoofdPanel.repaint();
        }
    });
    deelnemersmenu.add(item);

    item = new JMenuItem("Export Deelnemerslijst (JSON)");
    item.setAccelerator(KeyStroke.getKeyStroke('E', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // Create a file chooser
            final JFileChooser fc = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter("JSON", "json");
            fc.setFileFilter(filter);
            fc.setCurrentDirectory(new File(System.getProperty("user.dir")));
            // In response to a button click:
            int returnVal = fc.showSaveDialog(ms);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + ".");
                schrijfDeelnemers(file.getAbsolutePath());
            }
            hoofdPanel.repaint();
        }
    });
    deelnemersmenu.add(item);

    menubar.add(deelnemersmenu);

    JMenu uitslagenmenu = new JMenu("Uitslagen");
    Component hs = this;
    item = new JMenuItem("Importeer uitslagenbestand");
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // Create a file chooser
            final JFileChooser fc = new JFileChooser();
            fc.setCurrentDirectory(new File(System.getProperty("user.dir")));

            // In response to a button click:
            int returnVal = fc.showOpenDialog(hs);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                logger.log(Level.INFO, "Opening: " + file.getAbsolutePath() + ".");
                status.groepenuitslagen = (GroepsUitslagen) new ExcelImport().importeerUitslagen(file);
                OutputUitslagen ou = new OutputUitslagen();
                ou.exportuitslagen(status.groepenuitslagen);
                IJSCOController.t().wisUitslagen();
                ou.exportJSON(status.groepenuitslagen);
                GroepsUitslagen verwerkteUitslag = new Uitslagverwerker()
                        .verwerkUitslag(status.groepenuitslagen);
                logger.log(Level.INFO, verwerkteUitslag.ToString());
                new OutputUitslagen().exporteindresultaten(verwerkteUitslag);
                JOptionPane.showMessageDialog(null, "Uitslagen geimporteerd en bestanden aangemaakt.");
            }
            hoofdPanel.repaint();
        }
    });

    uitslagenmenu.add(item);
    menubar.add(uitslagenmenu);

    JMenu osbomenu = new JMenu("OSBO");

    item = new JMenuItem("Verstuur uitslagen handmatig.");
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // Create a file chooser
            SendAttachmentInEmail SAIM = new SendAttachmentInEmail();
            SAIM.sendAttachement("Uitslagen.json");
            hoofdPanel.repaint();
        }
    });

    osbomenu.add(item);
    menubar.add(osbomenu);

    JMenu helpmenu = new JMenu("Help");

    item = new JMenuItem("Verstuur logging");
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // Create a file chooser
            SendAttachmentInEmail SAIM = new SendAttachmentInEmail();
            SAIM.sendAttachement("IJSCO_UI.log");
            hoofdPanel.repaint();
        }
    });

    helpmenu.add(item);
    item = new JMenuItem("About");
    item.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            AboutDialog ad = new AboutDialog(ms);
            ad.setVisible(true);
            hoofdPanel.repaint();
        }
    });

    helpmenu.add(item);
    menubar.add(helpmenu);

    /*      JMenu indelingMenu = new JMenu("Indeling");
          //item = new JMenuItem("Automatisch aan/uit");
          item = new JMenuItem("N/A");
          item.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent event) {
    //actieAutomatisch();
             }
          });
            
          indelingMenu.add(item);
          //item = new JMenuItem("Maak wedstrijdgroep");
          item = new JMenuItem("N/A");
          item.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
    //actieMaakWedstrijdgroep();
             }
          });
            
          indelingMenu.add(item);
          //item = new JMenuItem("Maak speelschema");
          item = new JMenuItem("N/A");
          item.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent evetn) {
    //actieMaakSpeelschema();
             }
          });
          indelingMenu.add(item);
          //item = new JMenuItem("Bewerk speelschema");
          item = new JMenuItem("N/A");
          item.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent event) {
    //updateAutomatisch(false);
    // ResultaatDialoog
    //actieBewerkSchema();
             }
          });
            
          indelingMenu.add(item);
          indelingMenu.addSeparator();
          //item = new JMenuItem("Export");
          item = new JMenuItem("N/A");
          item.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent event) {
    //actieExport();
             }
          });
          indelingMenu.add(item);
          indelingMenu.addSeparator();
          //item = new JMenuItem("Vul uitslagen in");
          item = new JMenuItem("N/A");
          item.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
    //actieVoerUitslagenIn();
             }
          });
          indelingMenu.add(item);
          //item = new JMenuItem("Externe spelers");
          item = new JMenuItem("N/A");
          item.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
    //actieExterneSpelers();
             }
          });
          indelingMenu.add(item);
          //item = new JMenuItem("Maak nieuwe stand");
          item = new JMenuItem("N/A");
          item.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
    //actieUpdateStand();
             }
          });
          indelingMenu.add(item);
          indelingMenu.addSeparator();
          //item = new JMenuItem("Volgende ronde");
          item = new JMenuItem("N/A");
          item.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
    //actieVolgendeRonde();
             }
          });
          indelingMenu.add(item);
          menubar.add(indelingMenu);
    */
    /*      JMenu overigmenu = new JMenu("Overig");
            
          //item = new JMenuItem("Reset punten");
          item = new JMenuItem("N/A");
          item.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent e) {
    //controller.resetPunten();
    hoofdPanel.repaint();
             }
          });
            
          overigmenu.add(item);
          menubar.add(overigmenu);
    */
    this.setJMenuBar(menubar);

}

From source file:org.apache.pdfbox.debugger.PDFDebugger.java

private JMenu createFileMenu() {
    JMenuItem openMenuItem = new JMenuItem("Open...");
    openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, SHORCUT_KEY_MASK));
    openMenuItem.addActionListener(new ActionListener() {
        @Override/*from w ww.j  a  v  a2s.c o m*/
        public void actionPerformed(ActionEvent evt) {
            openMenuItemActionPerformed(evt);
        }
    });

    JMenu fileMenu = new JMenu("File");
    fileMenu.add(openMenuItem);
    fileMenu.setMnemonic('F');

    JMenuItem openUrlMenuItem = new JMenuItem("Open URL...");
    openUrlMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, SHORCUT_KEY_MASK));
    openUrlMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            String urlString = JOptionPane.showInputDialog("Enter an URL");
            if (urlString == null || urlString.isEmpty()) {
                return;
            }
            try {
                readPDFurl(urlString, "");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
    fileMenu.add(openUrlMenuItem);

    reopenMenuItem = new JMenuItem("Reopen");
    reopenMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, SHORCUT_KEY_MASK));
    reopenMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                if (currentFilePath.startsWith("http")) {
                    readPDFurl(currentFilePath, "");
                } else {
                    readPDFFile(currentFilePath, "");
                }
            } catch (IOException e) {
                new ErrorDialog(e).setVisible(true);
            }
        }
    });
    reopenMenuItem.setEnabled(false);
    fileMenu.add(reopenMenuItem);

    try {
        recentFiles = new RecentFiles(this.getClass(), 5);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    recentFilesMenu = new JMenu("Open Recent");
    recentFilesMenu.setEnabled(false);
    addRecentFileItems();
    fileMenu.add(recentFilesMenu);

    printMenuItem = new JMenuItem("Print");
    printMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, SHORCUT_KEY_MASK));
    printMenuItem.setEnabled(false);
    printMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            printMenuItemActionPerformed(evt);
        }
    });

    if (!IS_MAC_OS) {
        fileMenu.addSeparator();
        fileMenu.add(printMenuItem);
    }

    JMenuItem exitMenuItem = new JMenuItem("Exit");
    exitMenuItem.setAccelerator(KeyStroke.getKeyStroke("alt F4"));
    exitMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            exitMenuItemActionPerformed(evt);
        }
    });

    if (!IS_MAC_OS) {
        fileMenu.addSeparator();
        fileMenu.add(exitMenuItem);
    }

    return fileMenu;
}

From source file:org.executequery.gui.editor.QueryEditorPopupMenu.java

private JMenuItem createExecuteMenuItem() {
    JMenuItem menuItem = MenuItemFactory.createMenuItem(action());
    menuItem.setText("Execute");
    menuItem.setActionCommand("execute");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
    executeActionButtons().add(menuItem);
    return menuItem;
}