pl.piotrsukiennik.jbrain.gui.JBrainMainFrame.java Source code

Java tutorial

Introduction

Here is the source code for pl.piotrsukiennik.jbrain.gui.JBrainMainFrame.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.piotrsukiennik.jbrain.gui;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import pl.piotrsukiennik.jbrain.app.AppController;
import pl.piotrsukiennik.jbrain.app.GuiManager;

import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import java.io.File;

/**
 * @author Piotr Sukiennik
 */
@Component
public class JBrainMainFrame extends javax.swing.JFrame {

    @Autowired
    private GuiManager guiManager;

    @Autowired
    private AppController appController;

    /**
     * Creates new form JBrainManager
     */
    public JBrainMainFrame() {
        initComponents();
        lockInput();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * 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() {

        bottomDescription = new javax.swing.JLabel();
        leftColumnMenu = new javax.swing.JTree();
        mainPanel = new javax.swing.JPanel();
        mainMenuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        newMenuItem = new javax.swing.JMenuItem();
        openMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        saveMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("JBrain Manager");

        bottomDescription.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        bottomDescription.setText("Piotr Sukiennik @ PJIIT 2014");

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("options");
        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("model");
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("simulations");
        javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode(
                "new simulation");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("history");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        leftColumnMenu.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        leftColumnMenu.setRootVisible(false);
        leftColumnMenu.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                leftColumnMenuValueChanged(evt);
            }
        });

        mainPanel.setBackground(new java.awt.Color(255, 255, 255));
        mainPanel.setLayout(new java.awt.CardLayout());

        fileMenu.setText("File");

        newMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N,
                java.awt.event.InputEvent.CTRL_MASK));
        newMenuItem.setIcon(new javax.swing.ImageIcon(
                getClass().getResource("/pl/piotrsukiennik/jbrain/gui/icons/file-2x.png"))); // NOI18N
        newMenuItem.setText("New");
        newMenuItem.setEnabled(false);
        newMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(newMenuItem);

        openMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O,
                java.awt.event.InputEvent.CTRL_MASK));
        openMenuItem.setIcon(new javax.swing.ImageIcon(
                getClass().getResource("/pl/piotrsukiennik/jbrain/gui/icons/folder-2x.png"))); // NOI18N
        openMenuItem.setText("Open");
        openMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(openMenuItem);
        fileMenu.add(jSeparator1);

        saveMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S,
                java.awt.event.InputEvent.CTRL_MASK));
        saveMenuItem.setIcon(new javax.swing.ImageIcon(
                getClass().getResource("/pl/piotrsukiennik/jbrain/gui/icons/data-transfer-download-2x.png"))); // NOI18N
        saveMenuItem.setText("Save");
        saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(saveMenuItem);

        mainMenuBar.add(fileMenu);

        setJMenuBar(mainMenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addComponent(leftColumnMenu, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                .addComponent(bottomDescription, javax.swing.GroupLayout.DEFAULT_SIZE, 721, Short.MAX_VALUE));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(leftColumnMenu, javax.swing.GroupLayout.DEFAULT_SIZE, 360,
                                        Short.MAX_VALUE)
                                .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bottomDescription, javax.swing.GroupLayout.PREFERRED_SIZE, 22,
                                javax.swing.GroupLayout.PREFERRED_SIZE)));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
        appController.displayOpenFileWindow();
    }//GEN-LAST:event_openMenuItemActionPerformed

    private void newMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newMenuItemActionPerformed
        throw new UnsupportedOperationException();
    }//GEN-LAST:event_newMenuItemActionPerformed

    private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItemActionPerformed
        appController.displaySaveFileWindow();
    }//GEN-LAST:event_saveMenuItemActionPerformed

    private void leftColumnMenuValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_leftColumnMenuValueChanged
        TreePath newPath = evt.getNewLeadSelectionPath();
        String lastComponent = (String) ((DefaultMutableTreeNode) newPath.getLastPathComponent()).getUserObject();
        switch (lastComponent) {
        case "model":
            appController.displayModelManagement();
            break;
        case "new simulation":
            appController.displayNewSimulation();
            break;
        case "history":
            appController.displaySimulationHistory();
            break;
        }

    }//GEN-LAST:event_leftColumnMenuValueChanged

    public void lockInput() {
        leftColumnMenu.setEnabled(false);
        mainPanel.setEnabled(false);

    }

    public void unlockInput() {
        leftColumnMenu.setEnabled(true);
        mainPanel.setEnabled(true);
    }

    public JPanel getMainPanel() {
        return mainPanel;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    protected javax.swing.JLabel bottomDescription;
    protected javax.swing.JMenu fileMenu;
    protected javax.swing.JPanel mainPanel;
    protected javax.swing.JPopupMenu.Separator jSeparator1;
    protected javax.swing.JTree leftColumnMenu;
    protected javax.swing.JMenuBar mainMenuBar;
    protected javax.swing.JMenuItem newMenuItem;
    protected javax.swing.JMenuItem openMenuItem;
    protected javax.swing.JMenuItem saveMenuItem;
    // End of variables declaration//GEN-END:variables
}