Package teamnotepad

Source Code of teamnotepad.MainFrame

/*
* 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 teamnotepad;

import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.tree.*;
import teamnotepad.dialogwindows.OpenRemoteNotebookDialog;
import teamnotepad.entities.Note;
import teamnotepad.entities.NotesSuite;
import teamnotepad.entities.SerializedNote;
import teamnotepad.entities.SerializedNotesSuite;
import teamnotepad.entities.User;

/**
*
* @author User
*/
public class MainFrame extends javax.swing.JFrame {
  private DefaultTreeModel treeModel = null;
  /**
   * Creates new form NewJFrame
   */
  public MainFrame() {
    initComponents();
  }

  void feedNotesTree(List<NotesSuite> notesSuites, User currentUser) throws Exception{
    feedNotesTree(notesSuites, currentUser, "My notebook");
  }
 
  void feedNotesTree(List<NotesSuite> notesSuites, User currentUser, String rootName) throws Exception{
    DefaultMutableTreeNode top = new DefaultMutableTreeNode(rootName);
    treeModel = new DefaultTreeModel(top);
    for(NotesSuite notesSuite : notesSuites){
      DefaultMutableTreeNode notesSuiteNode = new DefaultMutableTreeNode(notesSuite.getTitle())
      Note[] notes = notesSuite.getNotes();
      for(Note note : notes){
        DefaultMutableTreeNode noteNode = new DefaultMutableTreeNode(note.getTitle(), false);
        noteNode.setUserObject(note);
        notesSuiteNode.add(noteNode);
      }
      addNewEmptyNote(notesSuiteNode, notesSuite, currentUser);
      top.add(notesSuiteNode);
    }
    notebookTree.setModel(treeModel);
    notebookTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  }
 
  void feedNotesTreeWithRemoteNotes(List<SerializedNotesSuite> notesSuites, String rootName){
    DefaultMutableTreeNode top = new DefaultMutableTreeNode(rootName);
    treeModel = new DefaultTreeModel(top);
    for(SerializedNotesSuite notesSuite : notesSuites){
      DefaultMutableTreeNode notesSuiteNode = new DefaultMutableTreeNode(notesSuite.getTitle())
      SerializedNote[] notes = notesSuite.getNotes();
      for(SerializedNote note : notes){
        DefaultMutableTreeNode noteNode = new DefaultMutableTreeNode(note.getTitle(), false);
        noteNode.setUserObject(note);
        notesSuiteNode.add(noteNode);
      }
      top.add(notesSuiteNode);
    }
    notebookTree.setModel(treeModel);
    notebookTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  }

  private void addNewEmptyNote(DefaultMutableTreeNode notesSuiteNode, NotesSuite suite, User user) {
    Note blankNote = new Note(user, suite, "[new note]", "Your content here");
    DefaultMutableTreeNode newNoteNode =  new DefaultMutableTreeNode("[add note]", false);
    newNoteNode.setUserObject(blankNote);
    notesSuiteNode.add(newNoteNode);
  }

  void addNotesSuiteListener(ActionListener listener){
    addNotesSuiteButton.addActionListener(listener);
  }

  void addTreeNodeClickedListener(MouseListener listener){
    notebookTree.addMouseListener(listener);
  }
 
  void addSaveNoteListener(ActionListener listener){
    saveNoteButton.addActionListener(listener);
  }
 
  void addOpenRemoteNotebookMenuItemListener(ActionListener listener){
    openRemoteNotebookMenuItem.addActionListener(listener);
  }
 
  void addShareNotebookMenuItemListener(TeamNotepadController.ShareNotebookClickedListener listener) {
    shareNotebookMenuItem.addActionListener(listener);
  }

  Object getLastSelectedNote(){
    return ((DefaultMutableTreeNode)notebookTree.getLastSelectedPathComponent()).getUserObject();
  }

  void showErrorMessage(String errorMessage){
    JOptionPane.showMessageDialog(this, errorMessage);
  }
 
  void showMessageDialog(String title, String message){
    JOptionPane.showMessageDialog(this, message, title, JOptionPane.PLAIN_MESSAGE);
  }

  JTextField getNoteTitleTextField(){
    return noteTitleTextField;
  }

  JTextArea getNoteContentTextArea(){
    return noteContentTextArea;
  }

  JLabel getNoteDateAndAuthorLabel(){
    return noteDateAndAuthorLabel;
  }

  TreePath getTreePathAt(int x, int y){
    return notebookTree.getPathForLocation(x, y);
  }

  void selectTreeRowAt(int x, int y){
    int row = notebookTree.getClosestRowForLocation(x, y);
    notebookTree.setSelectionRow(row);
  }

  void showTreeContextMenu(int x, int y){
    //TODO; clean this popup mess  
    //check what note item was clicked and run specific method
    //showTreeNoteContextMenu(x, y);
  }
 
  void showTreeNotebookContextMenu(int x, int y){
    //TODO
    //JPopupMenu menu = new JPopupMenu();
        //menu.add(new JMenuItem("Add notes suite"));
    //menu.show(notebookTree, x, y);
  }
 
  void showTreeNotesSuiteContextMenu(int x, int y){
    //TODO
    //JPopupMenu menu = new JPopupMenu();
        //menu.add(new JMenuItem("Delete"));
    //menu.show(notebookTree, x, y);
  }
 
  void showTreeNoteContextMenu(int x, int y){
    //TODO
    //JPopupMenu menu = new JPopupMenu();
    //menu.add(new JMenuItem("Open"));
        //menu.add(new JMenuItem("Delete"));
    //menu.show(notebookTree, x, y);
  }

  javax.swing.JTextField GetNewNotesSuiteNameTextField(){
    return newNotesSuiteNameTextField;
  }

  void setCurrentUserName(String name){
    currentUserNameLabel.setText(name);
  }

  /**
   * 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() {

        jInternalFrame1 = new javax.swing.JInternalFrame();
        jPopupMenu1 = new javax.swing.JPopupMenu();
        jPopupMenu2 = new javax.swing.JPopupMenu();
        newNotesSuiteNameTextField = new javax.swing.JTextField();
        addNotesSuiteButton = new javax.swing.JButton();
        saveNoteButton = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        currentUserNameLabel = new javax.swing.JLabel();
        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane4 = new javax.swing.JScrollPane();
        notebookTree = new javax.swing.JTree();
        jPanel1 = new javax.swing.JPanel();
        noteDateAndAuthorLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        noteContentTextArea = new javax.swing.JTextArea();
        noteTitleTextField = new javax.swing.JTextField();
        jMenuBar1 = new javax.swing.JMenuBar();
        headerMenu = new javax.swing.JMenu();
        openRemoteNotebookMenuItem = new javax.swing.JMenuItem();
        shareNotebookMenuItem = new javax.swing.JMenuItem();

        jInternalFrame1.setVisible(true);

        javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
        jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jInternalFrame1Layout.setVerticalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 8, Short.MAX_VALUE)
        );

        jPopupMenu1.setToolTipText("TREE TOOLTIP TEXT");
        jPopupMenu1.setMaximumSize(new java.awt.Dimension(40, 60));
        jPopupMenu1.setName("treePopupMenu"); // NOI18N
        jPopupMenu1.setPreferredSize(new java.awt.Dimension(10, 10));

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("TeamNotepad");
        setAutoRequestFocus(false);

        addNotesSuiteButton.setText("Add");

        saveNoteButton.setText("Save");

        jLabel2.setText("New notes suite:");

        currentUserNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        currentUserNameLabel.setText("[unknown user]");

        jSplitPane1.setDividerLocation(220);
        jSplitPane1.setResizeWeight(0.4);
        jSplitPane1.setOneTouchExpandable(true);

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        notebookTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        notebookTree.setAutoscrolls(true);
        notebookTree.setName("NotebookContentsTree"); // NOI18N
        jScrollPane4.setViewportView(notebookTree);
        notebookTree.getAccessibleContext().setAccessibleName("NotebookContentsTree");

        jSplitPane1.setLeftComponent(jScrollPane4);

        noteDateAndAuthorLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        noteDateAndAuthorLabel.setText(" ");

        noteContentTextArea.setColumns(20);
        noteContentTextArea.setFont(new java.awt.Font("Candara", 0, 14)); // NOI18N
        noteContentTextArea.setLineWrap(true);
        noteContentTextArea.setRows(20);
        noteContentTextArea.setTabSize(2);
        noteContentTextArea.setWrapStyleWord(true);
        noteContentTextArea.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        jScrollPane1.setViewportView(noteContentTextArea);

        noteTitleTextField.setToolTipText("");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 720, Short.MAX_VALUE)
                    .addComponent(noteDateAndAuthorLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(noteTitleTextField))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(noteDateAndAuthorLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(noteTitleTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jSplitPane1.setRightComponent(jPanel1);

        headerMenu.setText("Remote");

        openRemoteNotebookMenuItem.setText("Open remote notebook");
        headerMenu.add(openRemoteNotebookMenuItem);

        shareNotebookMenuItem.setText("Share notebook");
        shareNotebookMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                shareNotebookMenuItemActionPerformed(evt);
            }
        });
        headerMenu.add(shareNotebookMenuItem);

        jMenuBar1.add(headerMenu);

        setJMenuBar(jMenuBar1);

        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()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(newNotesSuiteNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 307, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(addNotesSuiteButton))
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 172, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(saveNoteButton, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(currentUserNameLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 410, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .addComponent(jSplitPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jSplitPane1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(newNotesSuiteNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(addNotesSuiteButton)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(saveNoteButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(currentUserNameLabel)))
                .addGap(25, 25, 25))
        );

        newNotesSuiteNameTextField.getAccessibleContext().setAccessibleName("NewNotesSuiteNameTextBox");

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

    private void shareNotebookMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shareNotebookMenuItemActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_shareNotebookMenuItemActionPerformed

 

  /**
   * @param args the command line arguments
   */
  public static void main(String args[]) {
    /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
     */
    try {
      for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          javax.swing.UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (ClassNotFoundException ex) {
      java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
      java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
      java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
      java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
        //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
        new MainFrame().setVisible(true);
      }
    });
  }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addNotesSuiteButton;
    private javax.swing.JLabel currentUserNameLabel;
    private javax.swing.JMenu headerMenu;
    private javax.swing.JInternalFrame jInternalFrame1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JPopupMenu jPopupMenu2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTextField newNotesSuiteNameTextField;
    private javax.swing.JTextArea noteContentTextArea;
    private javax.swing.JLabel noteDateAndAuthorLabel;
    private javax.swing.JTextField noteTitleTextField;
    private javax.swing.JTree notebookTree;
    private javax.swing.JMenuItem openRemoteNotebookMenuItem;
    private javax.swing.JButton saveNoteButton;
    private javax.swing.JMenuItem shareNotebookMenuItem;
    // End of variables declaration//GEN-END:variables

}
TOP

Related Classes of teamnotepad.MainFrame

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.