/* * Copyright (C) 2013-2014 Dio * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package gui; import java.awt.Container; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Writer; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.filechooser.FileFilter; import logic.Colors; import logic.Node; import logic.NodeTreePane; import logic.ScreenImage; import logic.Serializer; import logic.Tracker; import logic.TreeNodeExtentProvider; import org.abego.treelayout.TreeForTreeLayout; import org.abego.treelayout.TreeLayout; import org.abego.treelayout.util.DefaultConfiguration; import org.abego.treelayout.util.DefaultTreeForTreeLayout; import javax.swing.JViewport.*; /** * * @author Dio */ public class MainWindow extends javax.swing.JFrame { /** * Creates new form MainWindow */ public MainWindow() { initComponents(); this.setLocationRelativeTo(null); this.setTitle("DataTracker"); jPanel4.setEnabled(false); getRootPane().setDefaultButton(jButton2); //create the tracker that holds data and methods for initialization tracker = new Tracker(); mainWindowRef = this; } /** * 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() { java.awt.GridBagConstraints gridBagConstraints; buttonGroup1 = new javax.swing.ButtonGroup(); jRadioButtonMenuItem1 = new javax.swing.JRadioButtonMenuItem(); jMenuItem5 = new javax.swing.JMenuItem(); jMenuItem14 = new javax.swing.JMenuItem(); jPanel1 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); jPanel7 = new javax.swing.JPanel(); jButton2 = new javax.swing.JButton(); jTextField4 = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); jPanel4 = new MyPanel(); jLabel1 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); jTextField2 = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jTextField3 = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jComboBox1 = new javax.swing.JComboBox<String>(); BoundsPopupMenuListener listener2 = new BoundsPopupMenuListener(); jComboBox1.addPopupMenuListener( listener2 ); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jLabel3 = new javax.swing.JLabel(); jComboBox2 = new javax.swing.JComboBox<String>(); BoundsPopupMenuListener listener = new BoundsPopupMenuListener(); jComboBox2.addPopupMenuListener( listener ); jButton1 = new javax.swing.JButton(); jPanel3 = new javax.swing.JPanel(); jPanel5 = new javax.swing.JPanel(); jButton3 = new javax.swing.JButton(); jToolBar2 = new javax.swing.JToolBar(); OpenAction open = new OpenAction(); jButton7 = new javax.swing.JButton(open); jButton5 = new javax.swing.JButton(save); jButton14 = new javax.swing.JButton(export); jSeparator3 = new javax.swing.JToolBar.Separator(); jButton6 = new javax.swing.JButton(clearAll); jButton13 = new javax.swing.JButton(deleteNode); jButton15 = new javax.swing.JButton(edit); jButton16 = new javax.swing.JButton(get); jButton17 = new javax.swing.JButton(viewCategory); jSeparator7 = new javax.swing.JToolBar.Separator(); jButton8 = new javax.swing.JButton(customColors); jButton4 = new javax.swing.JButton(defaultColors); jButton11 = new javax.swing.JButton(saveProfile); jButton10 = new javax.swing.JButton(loadProfile); jSeparator2 = new javax.swing.JToolBar.Separator(); jButton12 = new javax.swing.JButton(snapshot); jButton9 = new javax.swing.JButton(info); jTextField5 = new javax.swing.JTextField(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem1 = new javax.swing.JMenuItem(open); jMenuItem2 = new javax.swing.JMenuItem(save); jSeparator8 = new javax.swing.JPopupMenu.Separator(); jMenuItem15 = new javax.swing.JMenuItem(export); jSeparator1 = new javax.swing.JPopupMenu.Separator(); jMenuItem3 = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu(); jMenuItem8 = new javax.swing.JMenuItem(clearAll); jMenuItem13 = new javax.swing.JMenuItem(deleteNode); jMenuItem16 = new javax.swing.JMenuItem(edit); jMenuItem17 = new javax.swing.JMenuItem(get); jMenuItem18 = new javax.swing.JMenuItem(viewCategory); jSeparator4 = new javax.swing.JPopupMenu.Separator(); jMenuItem4 = new javax.swing.JMenuItem(customColors); jMenuItem9 = new javax.swing.JMenuItem(defaultColors); jSeparator5 = new javax.swing.JPopupMenu.Separator(); jMenuItem10 = new javax.swing.JMenuItem(saveProfile); jMenuItem11 = new javax.swing.JMenuItem(loadProfile); jSeparator6 = new javax.swing.JPopupMenu.Separator(); jMenuItem12 = new javax.swing.JMenuItem(snapshot); jMenu3 = new javax.swing.JMenu(); jMenuItem6 = new javax.swing.JMenuItem(info); jMenuItem7 = new javax.swing.JMenuItem(); jRadioButtonMenuItem1.setSelected(true); jRadioButtonMenuItem1.setText("jRadioButtonMenuItem1"); jMenuItem5.setText("jMenuItem5"); jMenuItem14.setText("jMenuItem14"); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setResizable(false); jPanel1.setLayout(new java.awt.GridBagLayout()); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Main control")); jPanel2.setLayout(new java.awt.GridBagLayout()); jButton2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jButton2.setText("Track it"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jTextField4.setFont(new java.awt.Font("SansSerif", 0, 13)); // NOI18N jLabel6.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N jLabel6.setText("What do you want to track?"); javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7); jPanel7.setLayout(jPanel7Layout); jPanel7Layout.setHorizontalGroup( jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton2) .addGap(18, 18, Short.MAX_VALUE) .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(jPanel7Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel6) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel7Layout.setVerticalGroup( jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel6) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)) .addGap(20, 20, 20)) ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; jPanel2.add(jPanel7, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.ipadx = 51; gridBagConstraints.ipady = 2; gridBagConstraints.insets = new java.awt.Insets(5, 6, 0, 0); jPanel1.add(jPanel2, gridBagConstraints); jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Node data")); jPanel4.setMaximumSize(new java.awt.Dimension(277, 335)); jPanel4.setMinimumSize(new java.awt.Dimension(277, 335)); jPanel4.setPreferredSize(new java.awt.Dimension(320, 358)); jPanel4.setLayout(new java.awt.GridBagLayout()); jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N jLabel1.setText("Title"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(29, 86, 0, 0); jPanel4.add(jLabel1, gridBagConstraints); jTextField1.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 3; gridBagConstraints.gridheight = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.ipadx = 178; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(27, 10, 0, 16); jPanel4.add(jTextField1, gridBagConstraints); jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N jLabel2.setText("Category"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(13, 61, 0, 0); jPanel4.add(jLabel2, gridBagConstraints); jTextField2.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jTextField2.setMaximumSize(new java.awt.Dimension(140, 20)); jTextField2.setMinimumSize(new java.awt.Dimension(140, 20)); jTextField2.setPreferredSize(new java.awt.Dimension(140, 20)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 3; gridBagConstraints.gridheight = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.ipadx = 44; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 16); jPanel4.add(jTextField2, gridBagConstraints); jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N jLabel4.setText("Link"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 8; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(13, 89, 0, 0); jPanel4.add(jLabel4, gridBagConstraints); jTextField3.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jTextField3.setMaximumSize(new java.awt.Dimension(140, 20)); jTextField3.setMinimumSize(new java.awt.Dimension(140, 20)); jTextField3.setPreferredSize(new java.awt.Dimension(140, 20)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 8; gridBagConstraints.gridwidth = 3; gridBagConstraints.gridheight = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.ipadx = 44; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 16); jPanel4.add(jTextField3, gridBagConstraints); jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N jLabel5.setText("Parent Category"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(13, 21, 0, 0); jPanel4.add(jLabel5, gridBagConstraints); jComboBox1.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jComboBox1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jComboBox1ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 4; gridBagConstraints.gridwidth = 3; gridBagConstraints.gridheight = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.ipadx = 185; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 16); jPanel4.add(jComboBox1, gridBagConstraints); jScrollPane1.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jTextArea1.setColumns(20); jTextArea1.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N jTextArea1.setLineWrap(true); jTextArea1.setRows(5); jTextArea1.setWrapStyleWord(true); jTextArea1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Description", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP)); jTextArea1.setEnabled(false); jTextArea1.setMaximumSize(null); jTextArea1.setMinimumSize(null); jScrollPane1.setViewportView(jTextArea1); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 10; gridBagConstraints.gridwidth = 4; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 16); jPanel4.add(jScrollPane1, gridBagConstraints); jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N jLabel3.setText("Parent entry"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 6; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(13, 41, 0, 0); jPanel4.add(jLabel3, gridBagConstraints); jComboBox2.setMaximumSize(new java.awt.Dimension(140, 20)); jComboBox2.setMinimumSize(new java.awt.Dimension(140, 20)); jComboBox2.setPreferredSize(new java.awt.Dimension(140, 20)); jComboBox2.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { jComboBox2ItemStateChanged(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 6; gridBagConstraints.gridwidth = 3; gridBagConstraints.gridheight = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.ipadx = 44; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 16); jPanel4.add(jComboBox2, gridBagConstraints); jButton1.setFont(new java.awt.Font("Tahoma", 0, 13)); // NOI18N jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/entry (Custom) (2).png"))); // NOI18N jButton1.setText("Add new entry"); jButton1.setToolTipText(""); jButton1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); jButton1.setIconTextGap(3); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 11; gridBagConstraints.gridwidth = 4; gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 16); jPanel4.add(jButton1, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.gridheight = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.ipady = 23; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0); jPanel1.add(jPanel4, gridBagConstraints); jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Preview Parent entry")); jPanel3.setToolTipText("This will be the parent entry of the new inserted node"); jPanel3.setPreferredSize(new java.awt.Dimension(328, 180)); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 320, Short.MAX_VALUE) ); jPanel3Layout.setVerticalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 156, Short.MAX_VALUE) ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.ipadx = 4; gridBagConstraints.insets = new java.awt.Insets(5, 6, 0, 0); jPanel1.add(jPanel3, gridBagConstraints); jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Function", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP)); jPanel5.setPreferredSize(new java.awt.Dimension(221, 90)); jPanel5.setLayout(new java.awt.GridBagLayout()); jButton3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/diagram (Custom) (2).png"))); // NOI18N jButton3.setText("View tree graph"); jButton3.setToolTipText("Render tree"); jButton3.setEnabled(false); jButton3.setPreferredSize(new java.awt.Dimension(180, 50)); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridheight = 2; gridBagConstraints.ipadx = 13; gridBagConstraints.ipady = 7; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(16, 16, 19, 0); jPanel5.add(jButton3, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.gridheight = 4; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(5, 6, 0, 0); jPanel1.add(jPanel5, gridBagConstraints); jToolBar2.setBorder(javax.swing.BorderFactory.createTitledBorder("")); jToolBar2.setFloatable(false); jToolBar2.setRollover(true); jToolBar2.setMaximumSize(new java.awt.Dimension(32772, 40)); jToolBar2.setMinimumSize(new java.awt.Dimension(615, 40)); jToolBar2.setPreferredSize(new java.awt.Dimension(615, 40)); jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/open_30x30.png"))); // NOI18N jButton7.setToolTipText("Open"); jButton7.setFocusable(false); jButton7.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton7.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar2.add(jButton7); jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/save_30x30.png"))); // NOI18N jButton5.setToolTipText("Save"); jButton5.setEnabled(false); jButton5.setFocusable(false); jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar2.add(jButton5); jButton14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/txt_32x32.png"))); // NOI18N jButton14.setToolTipText("Export tree graph to .txt"); jButton14.setEnabled(false); jButton14.setFocusable(false); jButton14.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton14.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar2.add(jButton14); jToolBar2.add(jSeparator3); jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/clear_30x30.png"))); // NOI18N jButton6.setToolTipText("Clear all"); jButton6.setEnabled(false); jButton6.setFocusable(false); jButton6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton6.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar2.add(jButton6); jButton13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/remove2_30x30.png"))); // NOI18N jButton13.setToolTipText("Remove node from tree"); jButton13.setEnabled(false); jButton13.setFocusable(false); jButton13.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton13.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar2.add(jButton13); jButton15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/edit_30x30.png"))); // NOI18N jButton15.setToolTipText("Edit node fields"); jButton15.setEnabled(false); jButton15.setFocusable(false); jButton15.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton15.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar2.add(jButton15); jButton16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/get_32x32.png"))); // NOI18N jButton16.setToolTipText("Get node fields"); jButton16.setEnabled(false); jButton16.setFocusable(false); jButton16.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton16.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar2.add(jButton16); jButton17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/viewTreeCategory_30x30.png"))); // NOI18N jButton17.setToolTipText("View tree category"); jButton17.setEnabled(false); jButton17.setFocusable(false); jButton17.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton17.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar2.add(jButton17); jToolBar2.add(jSeparator7); jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/palette_30x30.png"))); // NOI18N jButton8.setToolTipText("Customize colors"); jButton8.setFocusable(false); jButton8.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton8.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar2.add(jButton8); jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/default color_25x25.png"))); // NOI18N jButton4.setToolTipText("Set default colors"); jButton4.setFocusable(false); jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar2.add(jButton4); jButton11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/save color profile_35x35.png"))); // NOI18N jButton11.setToolTipText("Save this color profile"); jButton11.setFocusable(false); jButton11.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton11.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar2.add(jButton11); jButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/load color profile_35x35.png"))); // NOI18N jButton10.setToolTipText("Load color profile"); jButton10.setEnabled(false); jButton10.setFocusable(false); jButton10.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton10.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar2.add(jButton10); jToolBar2.add(jSeparator2); jButton12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/snapshot_35x35.png"))); // NOI18N jButton12.setToolTipText("Take tree graph snapshot"); jButton12.setEnabled(false); jButton12.setFocusable(false); jButton12.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton12.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar2.add(jButton12); jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/info_30x30.png"))); // NOI18N jButton9.setToolTipText("Info"); jButton9.setFocusable(false); jButton9.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton9.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar2.add(jButton9); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; jPanel1.add(jToolBar2, gridBagConstraints); jTextField5.setBackground(new java.awt.Color(238, 238, 238)); jTextField5.setBorder(null); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 6; gridBagConstraints.gridheight = 5; gridBagConstraints.ipadx = 200; gridBagConstraints.ipady = 13; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(6, 23, 5, 0); jPanel1.add(jTextField5, gridBagConstraints); Date now = new Date(); String format2 = new SimpleDateFormat("EEEE, d MMMM yyyy").format(now); jTextField5.setText(format2); jMenu1.setText("File"); jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/open_20x20.png"))); // NOI18N jMenuItem1.setText("Open"); jMenu1.add(jMenuItem1); jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/save_20x20.png"))); // NOI18N jMenuItem2.setText("Save"); jMenu1.add(jMenuItem2); jMenu1.add(jSeparator8); jMenuItem15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/txt_22x22.png"))); // NOI18N jMenuItem15.setText("Export to .txt"); jMenu1.add(jMenuItem15); jMenu1.add(jSeparator1); jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/exit20x20.png"))); // NOI18N jMenuItem3.setText("Exit"); jMenuItem3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem3ActionPerformed(evt); } }); jMenu1.add(jMenuItem3); jMenuBar1.add(jMenu1); jMenu2.setText("Options"); jMenuItem8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/clear_20x20.png"))); // NOI18N jMenuItem8.setText("Clear all"); jMenuItem8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem8ActionPerformed(evt); } }); jMenu2.add(jMenuItem8); jMenuItem13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/remove2_20x20.png"))); // NOI18N jMenuItem13.setText("Delete node"); jMenu2.add(jMenuItem13); jMenuItem16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/edit_20x20.png"))); // NOI18N jMenuItem16.setText("Edit node fields"); jMenu2.add(jMenuItem16); jMenuItem17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/get_22x22.png"))); // NOI18N jMenuItem17.setText("Get node fields"); jMenu2.add(jMenuItem17); jMenuItem18.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/viewTreeCategory_20x20.png"))); // NOI18N jMenuItem18.setText("View tree category"); jMenu2.add(jMenuItem18); jMenu2.add(jSeparator4); jMenuItem4.setText("Customize Graph colors"); jMenu2.add(jMenuItem4); jMenuItem9.setText("Set default colors"); jMenu2.add(jMenuItem9); jMenu2.add(jSeparator5); jMenuItem10.setText("Save this color profile"); jMenu2.add(jMenuItem10); jMenuItem11.setText("Load saved color profile"); jMenu2.add(jMenuItem11); jMenu2.add(jSeparator6); jMenuItem12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/camera_20x20.png"))); // NOI18N jMenuItem12.setText("Take graph snapshot"); jMenu2.add(jMenuItem12); jMenuBar1.add(jMenu2); jMenu3.setText("About"); jMenuItem6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/info_20x20.png"))); // NOI18N jMenuItem6.setText("Info"); jMenu3.add(jMenuItem6); jMenuItem7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/gplv3_new.png"))); // NOI18N jMenuItem7.setText("Read license GPL v3.0"); jMenuItem7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem7ActionPerformed(evt); } }); jMenu3.add(jMenuItem7); jMenuBar1.add(jMenu3); 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() .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(0, 0, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) ); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed dispayTree(getDefaultTree()); }//GEN-LAST:event_jButton3ActionPerformed private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed updateComboBox2(); }//GEN-LAST:event_jComboBox1ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed String category = jTextField2.getText().replaceAll("\\s", ""); //check if field Category is empty. If true throw an error if (category.isEmpty()) { JOptionPane.showMessageDialog(this, "You need to enter Category", "No category", JOptionPane.ERROR_MESSAGE); } else { String timestamp = tracker.createTimestamp(); int id = tracker.createId(); String key = "#" + Integer.toString(id) + ", " + timestamp; //create and initialize Node Node newNode = new Node(key, jTextField1.getText(), jTextField2.getText(), jTextField3.getText(), jTextArea1.getText(), id, timestamp); String curCategory = jTextField2.getText(); String parentEntry = String.valueOf(jComboBox2.getSelectedItem()); int start = parentEntry.indexOf("#") + 1; int end = parentEntry.indexOf(","); int nodeId = Integer.parseInt(parentEntry.substring(start, end)); //find the node with nodeId id to make it parent Node foundNode = findNodeInTree(getDefaultTree().getRoot(), nodeId); if (foundNode == null) { JOptionPane.showMessageDialog(this, "No such entry", "Error", JOptionPane.ERROR_MESSAGE); } else { getDefaultTree().addChild(foundNode, newNode); updateComboBox2(); } if (tracker.getCategories().contains(curCategory) == false) { tracker.getCategories().add(curCategory); jComboBox1.addItem(curCategory); } jTextField1.setText(""); jTextField2.setText(""); jTextField3.setText(""); jTextArea1.setText(""); dispayTree(getDefaultTree()); } }//GEN-LAST:event_jButton1ActionPerformed public static FontMetrics returnFontMetrics() { Font font = new Font("SansSerif", Font.PLAIN, 11); BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); FontMetrics fm = img.getGraphics().getFontMetrics(font); return fm; } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed String imput = jTextField4.getText().replaceAll("\\s", ""); if (imput.isEmpty()) { JOptionPane.showMessageDialog(this, "You did not enter anything to track!", "Nothing to track", JOptionPane.ERROR_MESSAGE); } else { //enable and disable components after jButton2 is pressed jTextField4.setEnabled(false); jButton2.setEnabled(false); jPanel4.setEnabled(true); jTextArea1.setEnabled(true); jButton3.setEnabled(true); jButton6.setEnabled(true); jButton13.setEnabled(true); jButton12.setEnabled(true); jButton5.setEnabled(true); jButton14.setEnabled(true); jButton15.setEnabled(true); jButton16.setEnabled(true); jButton17.setEnabled(true); String timestamp = tracker.createTimestamp(); int id = tracker.createId(); String key = "#" + Integer.toString(id) + ", " + timestamp; //crate and initialize the root node Node root = new Node(key, "", jTextField4.getText(), "", "", id, timestamp); //categories = new ArrayList<>(); tracker.getCategories().add(root.getCategory()); //categories.add(root.getTitle()); jComboBox1.addItem(root.getCategory()); jComboBox2.addItem("#" + root.getId() + ", " + root.getCategory()); jComboBox2.setSelectedIndex(0); setDefaultTree(new DefaultTreeForTreeLayout<>(root)); lastPreviewdTree = getDefaultTree(); updatefLastPreviewed(); dispayTree(getDefaultTree()); } }//GEN-LAST:event_jButton2ActionPerformed private void jComboBox2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox2ItemStateChanged String selected = String.valueOf(jComboBox2.getSelectedItem()); if ((getDefaultTree() != null) && (!"null".equals(selected))) { DefaultTreeForTreeLayout<Node> newDefaultTree = null; int start = selected.indexOf("#") + 1; int end = selected.indexOf(","); int nodeId = Integer.parseInt(selected.substring(start, end)); Node foundNode = findNodeInTree(getDefaultTree().getRoot(), nodeId); if (foundNode == null) { JOptionPane.showMessageDialog(this, "No such entry", "Error", JOptionPane.ERROR_MESSAGE); } else { newDefaultTree = new DefaultTreeForTreeLayout<>(foundNode); lastPreviewdTree = newDefaultTree; } previewNode(newDefaultTree, jPanel3); } }//GEN-LAST:event_jComboBox2ItemStateChanged private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jMenuItem8ActionPerformed private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed System.exit(0); }//GEN-LAST:event_jMenuItem3ActionPerformed private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed final int PIXELS = 50; JDialog win = new JDialog(mainWindowRef, true); JPanel panel = new JPanel(); JTextArea textArea = new JTextArea(); JScrollPane scroll = new JScrollPane(textArea); JScrollPane scroll2 = new JScrollPane(panel); textArea.setFont(new java.awt.Font("Tahoma", 0, 13)); textArea.setEditable(false); panel.add(scroll); win.add(scroll2); //load file from resources ClassLoader classloader = Thread.currentThread().getContextClassLoader(); InputStream is = classloader.getResourceAsStream("license/gplv3.txt"); try (BufferedReader br = new BufferedReader(new InputStreamReader(is));) { String line; while ((line = br.readLine()) != null) { textArea.append(line + "\n"); } } catch (IOException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } //get system's resolution GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); int height = gd.getDisplayMode().getHeight() - PIXELS; win.setTitle("General Public License v3.0"); win.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); win.pack(); win.setSize(win.getWidth(), height); win.setLocationRelativeTo(mainWindowRef); win.setVisible(true); }//GEN-LAST:event_jMenuItem7ActionPerformed public void traverseTree(DefaultTreeForTreeLayout<Node> tree, Node node, ArrayList<Node> list) { list.add(node); for (Node child : tree.getChildrenList(node)) { if (tree.isLeaf(child) == false) { traverseTree(tree, child, list); } else { list.add(child); } } } /** * @param args the command line arguments */ public static void main(String args[]) { try { /* Set the System look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { Logger.getLogger(MainWindow.class .getName()).log(Level.SEVERE, null, ex); } /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { new MainWindow().setVisible(true); } }); } //<editor-fold defaultstate="collapsed" desc="member variables declarations"> private final JFrame mainWindowRef; final Tracker tracker; private DefaultTreeForTreeLayout<Node> lastPreviewdTree; private DefaultTreeForTreeLayout<Node> defaultTree; // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.ButtonGroup buttonGroup1; private javax.swing.JButton jButton1; LoadColorProfileAction loadProfile = new LoadColorProfileAction(); private javax.swing.JButton jButton10; SaveColorProfileAction saveProfile = new SaveColorProfileAction(); private javax.swing.JButton jButton11; SnapshotAction snapshot = new SnapshotAction(); private javax.swing.JButton jButton12; DeleteNodeAction deleteNode = new DeleteNodeAction(); private javax.swing.JButton jButton13; ExportAction export = new ExportAction(); private javax.swing.JButton jButton14; EditAction edit = new EditAction(); private javax.swing.JButton jButton15; GetAction get = new GetAction(); private javax.swing.JButton jButton16; ViewCategoryAction viewCategory = new ViewCategoryAction(); private javax.swing.JButton jButton17; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; SetDefaultColorsAction defaultColors = new SetDefaultColorsAction(); private javax.swing.JButton jButton4; SaveAction save = new SaveAction(); private javax.swing.JButton jButton5; ClearAllAction clearAll = new ClearAllAction(); private javax.swing.JButton jButton6; private javax.swing.JButton jButton7; CustomColorsAction customColors = new CustomColorsAction(); private javax.swing.JButton jButton8; InfoAction info = new InfoAction(); private javax.swing.JButton jButton9; javax.swing.JComboBox<String> jComboBox1; private javax.swing.JComboBox<String> jComboBox2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenu jMenu3; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem10; private javax.swing.JMenuItem jMenuItem11; private javax.swing.JMenuItem jMenuItem12; private javax.swing.JMenuItem jMenuItem13; private javax.swing.JMenuItem jMenuItem14; private javax.swing.JMenuItem jMenuItem15; private javax.swing.JMenuItem jMenuItem16; private javax.swing.JMenuItem jMenuItem17; private javax.swing.JMenuItem jMenuItem18; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenuItem3; private javax.swing.JMenuItem jMenuItem4; private javax.swing.JMenuItem jMenuItem5; private javax.swing.JMenuItem jMenuItem6; private javax.swing.JMenuItem jMenuItem7; private javax.swing.JMenuItem jMenuItem8; private javax.swing.JMenuItem jMenuItem9; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; private javax.swing.JPanel jPanel7; private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JPopupMenu.Separator jSeparator1; private javax.swing.JToolBar.Separator jSeparator2; private javax.swing.JToolBar.Separator jSeparator3; private javax.swing.JPopupMenu.Separator jSeparator4; private javax.swing.JPopupMenu.Separator jSeparator5; private javax.swing.JPopupMenu.Separator jSeparator6; private javax.swing.JToolBar.Separator jSeparator7; private javax.swing.JPopupMenu.Separator jSeparator8; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3; private javax.swing.JTextField jTextField4; private javax.swing.JTextField jTextField5; private javax.swing.JToolBar jToolBar2; // End of variables declaration//GEN-END:variables //</editor-fold> public static boolean isInteger(String s) { try { Integer.parseInt(s); } catch (NumberFormatException e) { return false; } // only got here if we didn't return false return true; } void updatefLastPreviewed() { if (lastPreviewdTree != null) { previewNode(lastPreviewdTree, jPanel3); } } private void previewNode(DefaultTreeForTreeLayout<Node> defaultTree, JPanel previewPanel) { TreeForTreeLayout<Node> tree = defaultTree; double gapBetweenLevels = 50; double gapBetweenNodes = 10; DefaultConfiguration<Node> configuration = new DefaultConfiguration<>( gapBetweenLevels, gapBetweenNodes); // create the NodeExtentProvider for Node nodes TreeNodeExtentProvider nodeExtentProvider = new TreeNodeExtentProvider(); // create the layout TreeLayout<Node> treeLayout = new TreeLayout<>(tree, nodeExtentProvider, configuration); // Create a panel that draws the nodes and edges and show the panel NodeTreePane panel = new NodeTreePane(treeLayout); previewPanel.removeAll(); //previewPanel.setLayout(new GridBagLayout()); panel.setFont(returnFontMetrics().getFont()); previewPanel.setLayout(new GridBagLayout()); previewPanel.add(panel); previewPanel.revalidate(); previewPanel.repaint(); this.pack(); } void dispayTree(DefaultTreeForTreeLayout<Node> defaultTree) { TreeForTreeLayout<Node> tree = defaultTree; double gapBetweenLevels = 50; double gapBetweenNodes = 10; DefaultConfiguration<Node> configuration = new DefaultConfiguration<>( gapBetweenLevels, gapBetweenNodes); // create the NodeExtentProvider for Node nodes TreeNodeExtentProvider nodeExtentProvider = new TreeNodeExtentProvider(); // create the layout TreeLayout<Node> treeLayout = new TreeLayout<>(tree, nodeExtentProvider, configuration); // Create a panel that draws the nodes and edges and show the panelF NodeTreePane panel = new NodeTreePane(treeLayout); showInDialog(panel); } private void showInDialog(JComponent panel) { final int PIXELS = 50; JDialog dialog = new JDialog(); panel.setFont(returnFontMetrics().getFont()); javax.swing.JScrollPane scroll = new javax.swing.JScrollPane(panel); Container contentPane = dialog.getContentPane(); ((JComponent) contentPane).setBorder(BorderFactory.createEmptyBorder( 10, 10, 10, 10)); contentPane.add(scroll); dialog.pack(); //get system's resolution GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); int width = gd.getDisplayMode().getWidth() - PIXELS; int height = gd.getDisplayMode().getHeight() - PIXELS; //With this code the Jdialog becomes scrollable when it gets very large Dimension dialogDim = dialog.getSize(); if (dialogDim.height > height) { Dimension dim = new Dimension(dialogDim.width, height); dialog.setSize(dim); } else if (dialogDim.width > width) { Dimension dim = new Dimension(width, dialogDim.height); dialog.setSize(dim); } dialog.setTitle("Tracking: " + getDefaultTree().getRoot().getCategory()); dialog.setModal(true); dialog.setLocationRelativeTo(null); dialog.setVisible(true); } void updateComboBox2() { String selCategory = String.valueOf(jComboBox1.getSelectedItem()); if (getDefaultTree() != null) { jComboBox2.removeAllItems(); ArrayList<Node> sameCategoryNodes = new ArrayList<>(); findSimilarNodes(getDefaultTree().getRoot(), sameCategoryNodes, selCategory); for (Node aNode : sameCategoryNodes) { if (aNode.getId() == 0)//if it is the root node { jComboBox2.addItem("#0, " + sameCategoryNodes.get(0).getCategory()); } else { jComboBox2.addItem("#" + aNode.getId() + ", " + aNode.getTitle()); } } } } void findSimilarNodes(Node aNode, ArrayList<Node> theList, String category) { if (aNode.getCategory().equals(category)) { theList.add(aNode); } for (Node child : getDefaultTree().getChildren(aNode)) { findSimilarNodes(child, theList, category); } } Node findNodeInTree(Node node, int id) { if (node != null) { if (node.getId() == id) { return node; } else { for (Node child : getDefaultTree().getChildren(node)) { Node temp = findNodeInTree(child, id); if (temp != null) { return temp; } } } } else { return null; } return null; } private int populateCategoriesAndId(DefaultTreeForTreeLayout<Node> tree, Node node, int maxId) { String category = node.getCategory(); if (node.getId() > maxId) { maxId = node.getId(); } if (tracker.getCategories().contains(category) == false) { tracker.getCategories().add(category); jComboBox1.addItem(category); } List<Node> children = tree.getChildrenList(node); for (Node child : children) { int a = populateCategoriesAndId(tree, child, maxId); if (a > maxId) { maxId = a; } } return maxId; } /** * @return the defaultTree */ DefaultTreeForTreeLayout<Node> getDefaultTree() { return defaultTree; } /** * @param defaultTree the defaultTree to set */ void setDefaultTree(DefaultTreeForTreeLayout<Node> defaultTree) { this.defaultTree = defaultTree; } private class OpenAction extends AbstractAction { @Override public void actionPerformed(ActionEvent ae) { //Create a file chooser final JFileChooser fc = new JFileChooser(); fc.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } final String name = f.getName(); return name.endsWith(".dt"); } @Override public String getDescription() { return "*.dt, DataTracker file"; } }); int returnVal = fc.showOpenDialog(jMenuItem1); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); String filePath = file.getPath(); System.out.println("Opening: " + file.getName() + "." + "\n"); try { Serializer.deserialize(filePath); String error = String.valueOf(Serializer.error()); System.out.println("this is error: " + error); if (error.equals("null") == true) { setDefaultTree(Serializer.buidTree()); if (getDefaultTree() != null) { //re-initialize jTextField4.setText(getDefaultTree().getRoot().getCategory()); jTextField4.setEnabled(false); jButton2.setEnabled(false); jPanel4.setEnabled(true); jTextArea1.setEnabled(true); jButton3.setEnabled(true); jButton6.setEnabled(true); jButton13.setEnabled(true); jButton12.setEnabled(true); jButton5.setEnabled(true); jButton14.setEnabled(true); jButton15.setEnabled(true); jButton16.setEnabled(true); jButton17.setEnabled(true); jComboBox1.removeAllItems(); tracker.clearCategories(); int id = populateCategoriesAndId(getDefaultTree(), getDefaultTree().getRoot(), 0); tracker.setId(id); dispayTree(getDefaultTree()); } else { JOptionPane.showMessageDialog(mainWindowRef, "No Data!", "Error", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(mainWindowRef, "Incompatible file!", "Error", JOptionPane.ERROR_MESSAGE); } } catch (ClassNotFoundException ex) { JOptionPane.showMessageDialog(mainWindowRef, "Bad file!", "Error", JOptionPane.ERROR_MESSAGE); } } } } private class SaveAction extends AbstractAction { @Override public void actionPerformed(ActionEvent ae) { if (getDefaultTree() == null) { JOptionPane.showMessageDialog(mainWindowRef, "No data to save!", "Error", JOptionPane.ERROR_MESSAGE); } else { final String extension = ".dt"; final JFileChooser fc = new JFileChooser(); fc.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } final String name = f.getName(); return name.endsWith(extension); } @Override public String getDescription() { return "*.dt, DataTracker file"; } }); int returnVal = fc.showSaveDialog(jMenuItem2); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); String filePath = file.getPath() + extension; System.out.println("Saving: " + file.getName() + "." + "'\n"); Serializer.createSerNode(getDefaultTree(), getDefaultTree().getRoot()); Serializer.serialize(filePath); JOptionPane.showMessageDialog(mainWindowRef, "File saved!", "Saved", JOptionPane.INFORMATION_MESSAGE); } else { System.out.println("Save command cancelled by user." + "\n"); } } } } private class CustomColorsAction extends AbstractAction { @Override public void actionPerformed(ActionEvent ae) { Colors.setCurColorsAsLast(); CustomizeGraph dialog = new CustomizeGraph(mainWindowRef, true); dialog.setVisible(true); dialog.pack(); updatefLastPreviewed(); } } private class ClearAllAction extends AbstractAction { @Override public void actionPerformed(ActionEvent ae) { Colors.setdefaultColors(); tracker.clearCategories();; tracker.resetId(); //re-init fields jTextField1.setText(""); jTextField2.setText(""); jTextField3.setText(""); jTextField4.setText(""); jTextArea1.setText(""); jComboBox1.removeAllItems(); jComboBox2.removeAllItems(); jTextArea1.setEnabled(false); jPanel4.setEnabled(false); jTextField4.setEnabled(true); jButton2.setEnabled(true); jButton3.setEnabled(false); jButton6.setEnabled(false); jPanel3.removeAll(); jPanel3.repaint(); jButton13.setEnabled(false); jButton12.setEnabled(false); jButton5.setEnabled(false); jButton14.setEnabled(false); jButton15.setEnabled(false); jButton16.setEnabled(false); jButton17.setEnabled(false); mainWindowRef.pack(); setDefaultTree(null); lastPreviewdTree = null; } } private class SetDefaultColorsAction extends AbstractAction { @Override public void actionPerformed(ActionEvent ae) { Colors.setdefaultColors(); updatefLastPreviewed(); } } private class SaveColorProfileAction extends AbstractAction { @Override public void actionPerformed(ActionEvent ae) { Colors.saveProfile(); jButton10.setEnabled(true); JOptionPane.showMessageDialog(mainWindowRef, "Profile saved!", "Save", JOptionPane.INFORMATION_MESSAGE); } } private class LoadColorProfileAction extends AbstractAction { @Override public void actionPerformed(ActionEvent ae) { if (Colors.getProfile() != null) { Colors.loadProfile(); updatefLastPreviewed(); JOptionPane.showMessageDialog(mainWindowRef, "Profile loaded successfully!", "Loaded", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(mainWindowRef, "No profile found! Save one and load again!", "No profile to load", JOptionPane.ERROR_MESSAGE); } } } private class SnapshotAction extends AbstractAction { @Override public void actionPerformed(ActionEvent ae) { if (getDefaultTree() != null) { final String extension = ".png"; final JFileChooser fc = new JFileChooser(); fc.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } final String name = f.getName(); return name.endsWith(extension); } @Override public String getDescription() { return "*" + extension + ", image file"; } }); int returnVal = fc.showSaveDialog(jMenuItem12); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); String filePath = file.getPath(); TreeForTreeLayout<Node> tree = getDefaultTree(); double gapBetweenLevels = 50; double gapBetweenNodes = 10; DefaultConfiguration<Node> configuration = new DefaultConfiguration<>( gapBetweenLevels, gapBetweenNodes); // create the NodeExtentProvider for Node nodes TreeNodeExtentProvider nodeExtentProvider = new TreeNodeExtentProvider(); // create the layout TreeLayout<Node> treeLayout = new TreeLayout<>(tree, nodeExtentProvider, configuration); // Create a panel that draws the nodes and edges and show the panelF NodeTreePane panel = new NodeTreePane(treeLayout); panel.setFont(returnFontMetrics().getFont()); javax.swing.JScrollPane scroll = new javax.swing.JScrollPane(panel); ScreenImage si = new ScreenImage(); try { si.writeImage(si.createImage(scroll), filePath + extension); JOptionPane.showMessageDialog(mainWindowRef, "Snapshot taken!", "Image saved", JOptionPane.INFORMATION_MESSAGE); } catch (IOException ex) { JOptionPane.showMessageDialog(mainWindowRef, "There was an unknown error!", "Unknown Error", JOptionPane.ERROR_MESSAGE); Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } } } else { JOptionPane.showMessageDialog(mainWindowRef, "No graph created", "No graph", JOptionPane.ERROR_MESSAGE); } } } private class InfoAction extends AbstractAction { @Override public void actionPerformed(ActionEvent ae) { String copyright = "<html><b>Copyright (c)</b> 2013-2014, Lappas Dionysis \n"; String version = "<html><b>Version:</b> 1.0 \n"; String description = "<html><b>Description:</b> DataTracker helps you keep track and \nvisualize your tasks and ideas! \n"; String license = "<html><b>Released</b> under the GNU General Public License v3.0 \n"; //String a.setContent(copyright, "text/html; charset=utf-8");` JOptionPane.showMessageDialog(mainWindowRef, copyright + version + description + license, "Info", JOptionPane.INFORMATION_MESSAGE); } } private class DeleteNodeAction extends AbstractAction { @Override public void actionPerformed(ActionEvent ae) { if (getDefaultTree() == null) { JOptionPane.showMessageDialog(mainWindowRef, "Add data first!", "Error", JOptionPane.ERROR_MESSAGE); } else { String s = (String) JOptionPane.showInputDialog( mainWindowRef, "Enter the ID of the node you want to delete. " + "\ni.e. 5 to delete Node #5 ", "Delete node:", JOptionPane.PLAIN_MESSAGE, null, null, ""); if (isInteger(s) == true) { int id = Integer.parseInt(s); if (id == 0) { JOptionPane.showMessageDialog(mainWindowRef, "Cannot remove the ROOT (#0) node", "Error", JOptionPane.ERROR_MESSAGE); } else { DefaultTreeForTreeLayout<Node> updatedTree; Node delNode = findNodeInTree(getDefaultTree().getRoot(), id); if (delNode != null) { String oldCategory = delNode.getCategory(); updatedTree = tracker.deleteNode(getDefaultTree(), getDefaultTree().getRoot(), id); System.out.println("this is tracker id and id: <" + tracker.getId() + ", " + id + ">"); if (tracker.getId() == id) { tracker.setId(id - 1); } setDefaultTree(updatedTree); //ssearch for nodes with the same OLD category ArrayList<Node> list = new ArrayList<>(); findSimilarNodes(getDefaultTree().getRoot(), list, oldCategory); //IF there is only one node, remove old data if (list.isEmpty() == true) { tracker.getCategories().remove(oldCategory); jComboBox1.removeItem(oldCategory); } updateComboBox2(); updatefLastPreviewed(); dispayTree(getDefaultTree()); } else { JOptionPane.showMessageDialog(mainWindowRef, "Node not found", "Error", JOptionPane.ERROR_MESSAGE); } } } else { if (s != null) { JOptionPane.showMessageDialog(mainWindowRef, "Wrong input!", "Error", JOptionPane.ERROR_MESSAGE); } } } } } private class ExportAction extends AbstractAction { @Override public void actionPerformed(ActionEvent ae) { if (getDefaultTree() == null) { JOptionPane.showMessageDialog(mainWindowRef, "Nothing to export!", "Error", JOptionPane.ERROR_MESSAGE); } else { final JFileChooser fc = new JFileChooser(); fc.setFileFilter(new FileFilter() { @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } final String name = f.getName(); return name.endsWith(".txt"); } @Override public String getDescription() { return "*.txt, text file"; } }); int returnVal = fc.showSaveDialog(jMenuItem15); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); String filePath = file.getPath(); File fileDir = new File(filePath + ".txt"); try (Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileDir), "UTF8"))) { ArrayList<Node> nodes = new ArrayList<>(); traverseTree(getDefaultTree(), getDefaultTree().getRoot(), nodes); for (Node node : nodes) { String id = String.valueOf(node.getId()); String timestamp = String.valueOf(node.getTimestamp()); String category = node.getCategory(); String title = node.getTitle(); String link = node.getLink(); String description = node.getDescription(); out.append("#" + id + ", " + timestamp).append("\r\n"); out.append("Title: " + title).append("\r\n"); out.append("Category: " + category).append("\r\n"); out.append("Link: " + link).append("\r\n"); out.append("Description: " + description).append("\r\n\r\n"); } } catch (IOException ex) { JOptionPane.showMessageDialog(mainWindowRef, "Unknown I/O error!", "Error", JOptionPane.ERROR_MESSAGE); } JOptionPane.showMessageDialog(mainWindowRef, "Graph exported successfully!", "Save", JOptionPane.INFORMATION_MESSAGE); } } } } private class EditAction extends AbstractAction { @Override public void actionPerformed(ActionEvent ae) { if (getDefaultTree() == null) { JOptionPane.showMessageDialog(mainWindowRef, "No node to edit!", "Error", JOptionPane.ERROR_MESSAGE); } else { EditWin edit = new EditWin(mainWindowRef, true); edit.pack();; edit.setVisible(true); } } } private class GetAction extends AbstractAction { @Override public void actionPerformed(ActionEvent ae) { if (getDefaultTree() == null) { JOptionPane.showMessageDialog(mainWindowRef, "No node to get!", "Error", JOptionPane.ERROR_MESSAGE); } else { GetWin get = new GetWin(mainWindowRef, true); get.pack();; get.setVisible(true); } } } private class ViewCategoryAction extends AbstractAction { @Override public void actionPerformed(ActionEvent ae) { if (getDefaultTree() == null) { JOptionPane.showMessageDialog(mainWindowRef, "No category to view!", "Error", JOptionPane.ERROR_MESSAGE); } else { ArrayList<String> categoriesList = tracker.getCategories(); String[] categoriesArray = new String[categoriesList.size()]; categoriesArray = categoriesList.toArray(categoriesArray); String s = (String) JOptionPane.showInputDialog( mainWindowRef, "Select the category you would like to view: ", "View category", JOptionPane.PLAIN_MESSAGE, null, categoriesArray, ""); if (s != null == true) { ArrayList<Node> categories = new ArrayList<>(); findSimilarNodes(getDefaultTree().getRoot(), categories, s); Colors.setShadowing(true); for (Node node : categories) { node.setShadowed(true); } dispayTree(getDefaultTree()); for (Node node : categories) { node.setShadowed(false); } Colors.setShadowing(false); } } } } }