Manage Legal Notices functionality
[habeas.git] / src / habeas / ManageNoticesDialog.java
diff --git a/src/habeas/ManageNoticesDialog.java b/src/habeas/ManageNoticesDialog.java
new file mode 100644 (file)
index 0000000..c23923e
--- /dev/null
@@ -0,0 +1,187 @@
+/*
+ * 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 habeas;
+
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.util.ArrayList;
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
+import javax.swing.table.DefaultTableModel;
+
+/**
+ *
+ * @author hari
+ */
+public class ManageNoticesDialog extends javax.swing.JDialog {
+
+    /**
+     * Creates new form ManageNoticesDialog
+     */
+    public ManageNoticesDialog(java.awt.Frame parent, boolean modal) {
+        super(parent, modal);
+        initComponents();
+        populateNotices ();
+        tableNotices.add(popMenu);
+        tableNotices.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mousePressed(MouseEvent arg0) {
+                if (arg0.isPopupTrigger()) {
+                    popMenu.show(arg0.getComponent(), arg0.getX(), arg0.getY());
+                }
+            }
+
+        });
+    }
+
+    /**
+     * 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() {
+
+        popMenu = new javax.swing.JPopupMenu();
+        menuDraftStatus = new javax.swing.JMenuItem();
+        jScrollPane1 = new javax.swing.JScrollPane();
+        tableNotices = new javax.swing.JTable();
+
+        menuDraftStatus.setMnemonic('D');
+        menuDraftStatus.setText("Draft Status...");
+        menuDraftStatus.setToolTipText("");
+        menuDraftStatus.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                menuDraftStatusActionPerformed(evt);
+            }
+        });
+        popMenu.add(menuDraftStatus);
+
+        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+        setTitle("Manage Notices");
+        setLocationByPlatform(true);
+
+        tableNotices.setModel(new javax.swing.table.DefaultTableModel(
+            new Object [][] {
+
+            },
+            new String [] {
+                "id", "Reference Number", "Description"
+            }
+        ) {
+            Class[] types = new Class [] {
+                java.lang.Integer.class, java.lang.String.class, java.lang.String.class
+            };
+            boolean[] canEdit = new boolean [] {
+                false, false, false
+            };
+
+            public Class getColumnClass(int columnIndex) {
+                return types [columnIndex];
+            }
+
+            public boolean isCellEditable(int rowIndex, int columnIndex) {
+                return canEdit [columnIndex];
+            }
+        });
+        tableNotices.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
+        tableNotices.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
+        jScrollPane1.setViewportView(tableNotices);
+
+        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
+        getContentPane().setLayout(layout);
+        layout.setHorizontalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
+        );
+
+        pack();
+    }// </editor-fold>//GEN-END:initComponents
+
+    private void menuDraftStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDraftStatusActionPerformed
+        // TODO add your handling code here:
+        int selid = getSelectedNotice ();
+        if (selid == -1) return;
+        
+        System.out.println (selid);
+        
+    }//GEN-LAST:event_menuDraftStatusActionPerformed
+
+    /**
+     * @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(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (InstantiationException ex) {
+            java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (IllegalAccessException ex) {
+            java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+            java.util.logging.Logger.getLogger(ManageNoticesDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        }
+        //</editor-fold>
+
+        /* Create and display the dialog */
+        java.awt.EventQueue.invokeLater(new Runnable() {
+            public void run() {
+                ManageNoticesDialog dialog = new ManageNoticesDialog(new javax.swing.JFrame(), true);
+                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
+                    @Override
+                    public void windowClosing(java.awt.event.WindowEvent e) {
+                        System.exit(0);
+                    }
+                });
+                dialog.setVisible(true);
+            }
+        });
+    }
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JScrollPane jScrollPane1;
+    private javax.swing.JMenuItem menuDraftStatus;
+    private javax.swing.JPopupMenu popMenu;
+    private javax.swing.JTable tableNotices;
+    // End of variables declaration//GEN-END:variables
+
+    private void populateNotices() {
+        DefaultTableModel mdl = (DefaultTableModel) tableNotices.getModel ();
+        mdl.setRowCount(0);        
+        ArrayList<Object> notices = Utility.getNotices ();
+        if (notices == null) return;
+        for (int i = 0; i < notices.size(); i += 3) {
+            mdl.addRow (new Object[] { notices.get(i), notices.get(i+1),
+                notices.get(i+2)});
+        }
+    }
+
+    private int getSelectedNotice() {
+        int selid = tableNotices.getSelectedRow();
+        if (selid == -1)
+            return -1;
+        DefaultTableModel mdl = (DefaultTableModel) tableNotices.getModel();
+        int rkey = (int) mdl.getValueAt(selid, 0);
+        return rkey;
+    }
+}