2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
8 import java
.awt
.event
.MouseAdapter
;
9 import java
.awt
.event
.MouseEvent
;
10 import java
.awt
.event
.MouseListener
;
11 import java
.util
.ArrayList
;
12 import javax
.swing
.JMenuItem
;
13 import javax
.swing
.JPopupMenu
;
14 import javax
.swing
.table
.DefaultTableModel
;
20 public class ManageNoticesDialog
extends javax
.swing
.JDialog
{
23 * Creates new form ManageNoticesDialog
25 public ManageNoticesDialog(java
.awt
.Frame parent
, boolean modal
) {
29 tableNotices
.add(popMenu
);
30 tableNotices
.addMouseListener(new MouseAdapter() {
32 public void mousePressed(MouseEvent arg0
) {
33 if (arg0
.isPopupTrigger()) {
34 popMenu
.show(arg0
.getComponent(), arg0
.getX(), arg0
.getY());
42 * This method is called from within the constructor to initialize the form.
43 * WARNING: Do NOT modify this code. The content of this method is always
44 * regenerated by the Form Editor.
46 @SuppressWarnings("unchecked")
47 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
48 private void initComponents() {
50 popMenu
= new javax
.swing
.JPopupMenu();
51 menuDraftStatus
= new javax
.swing
.JMenuItem();
52 jScrollPane1
= new javax
.swing
.JScrollPane();
53 tableNotices
= new javax
.swing
.JTable();
55 menuDraftStatus
.setMnemonic('D');
56 menuDraftStatus
.setText("Draft Status...");
57 menuDraftStatus
.setToolTipText("");
58 menuDraftStatus
.addActionListener(new java
.awt
.event
.ActionListener() {
59 public void actionPerformed(java
.awt
.event
.ActionEvent evt
) {
60 menuDraftStatusActionPerformed(evt
);
63 popMenu
.add(menuDraftStatus
);
65 setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
66 setTitle("Manage Notices");
67 setLocationByPlatform(true);
69 tableNotices
.setModel(new javax
.swing
.table
.DefaultTableModel(
74 "id", "Reference Number", "Description"
77 Class
[] types
= new Class
[] {
78 java
.lang
.Integer
.class, java
.lang
.String
.class, java
.lang
.String
.class
80 boolean[] canEdit
= new boolean [] {
84 public Class
getColumnClass(int columnIndex
) {
85 return types
[columnIndex
];
88 public boolean isCellEditable(int rowIndex
, int columnIndex
) {
89 return canEdit
[columnIndex
];
92 tableNotices
.setSelectionMode(javax
.swing
.ListSelectionModel
.SINGLE_SELECTION
);
93 tableNotices
.setSelectionMode(javax
.swing
.ListSelectionModel
.SINGLE_SELECTION
);
94 jScrollPane1
.setViewportView(tableNotices
);
96 javax
.swing
.GroupLayout layout
= new javax
.swing
.GroupLayout(getContentPane());
97 getContentPane().setLayout(layout
);
98 layout
.setHorizontalGroup(
99 layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
100 .addComponent(jScrollPane1
, javax
.swing
.GroupLayout
.DEFAULT_SIZE
, 537, Short
.MAX_VALUE
)
102 layout
.setVerticalGroup(
103 layout
.createParallelGroup(javax
.swing
.GroupLayout
.Alignment
.LEADING
)
104 .addComponent(jScrollPane1
, javax
.swing
.GroupLayout
.DEFAULT_SIZE
, 317, Short
.MAX_VALUE
)
108 }// </editor-fold>//GEN-END:initComponents
110 private void menuDraftStatusActionPerformed(java
.awt
.event
.ActionEvent evt
) {//GEN-FIRST:event_menuDraftStatusActionPerformed
111 // TODO add your handling code here:
112 int selid
= getSelectedNotice ();
113 if (selid
== -1) return;
115 System
.out
.println (selid
);
117 }//GEN-LAST:event_menuDraftStatusActionPerformed
120 * @param args the command line arguments
122 public static void main(String args
[]) {
123 /* Set the Nimbus look and feel */
124 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
125 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
126 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
129 for (javax
.swing
.UIManager
.LookAndFeelInfo info
: javax
.swing
.UIManager
.getInstalledLookAndFeels()) {
130 if ("Nimbus".equals(info
.getName())) {
131 javax
.swing
.UIManager
.setLookAndFeel(info
.getClassName());
135 } catch (ClassNotFoundException ex
) {
136 java
.util
.logging
.Logger
.getLogger(ManageNoticesDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
137 } catch (InstantiationException ex
) {
138 java
.util
.logging
.Logger
.getLogger(ManageNoticesDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
139 } catch (IllegalAccessException ex
) {
140 java
.util
.logging
.Logger
.getLogger(ManageNoticesDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
141 } catch (javax
.swing
.UnsupportedLookAndFeelException ex
) {
142 java
.util
.logging
.Logger
.getLogger(ManageNoticesDialog
.class.getName()).log(java
.util
.logging
.Level
.SEVERE
, null, ex
);
146 /* Create and display the dialog */
147 java
.awt
.EventQueue
.invokeLater(new Runnable() {
149 ManageNoticesDialog dialog
= new ManageNoticesDialog(new javax
.swing
.JFrame(), true);
150 dialog
.addWindowListener(new java
.awt
.event
.WindowAdapter() {
152 public void windowClosing(java
.awt
.event
.WindowEvent e
) {
156 dialog
.setVisible(true);
161 // Variables declaration - do not modify//GEN-BEGIN:variables
162 private javax
.swing
.JScrollPane jScrollPane1
;
163 private javax
.swing
.JMenuItem menuDraftStatus
;
164 private javax
.swing
.JPopupMenu popMenu
;
165 private javax
.swing
.JTable tableNotices
;
166 // End of variables declaration//GEN-END:variables
168 private void populateNotices() {
169 DefaultTableModel mdl
= (DefaultTableModel
) tableNotices
.getModel ();
171 ArrayList
<Object
> notices
= Utility
.getNotices ();
172 if (notices
== null) return;
173 for (int i
= 0; i
< notices
.size(); i
+= 3) {
174 mdl
.addRow (new Object
[] { notices
.get(i
), notices
.get(i
+1),
179 private int getSelectedNotice() {
180 int selid
= tableNotices
.getSelectedRow();
183 DefaultTableModel mdl
= (DefaultTableModel
) tableNotices
.getModel();
184 int rkey
= (int) mdl
.getValueAt(selid
, 0);