| 1 | /* |
|---|
| 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. |
|---|
| 5 | */ |
|---|
| 6 | package tmcsim.client; |
|---|
| 7 | |
|---|
| 8 | import java.util.LinkedList; |
|---|
| 9 | import java.util.Queue; |
|---|
| 10 | import java.util.Vector; |
|---|
| 11 | import javax.swing.AbstractListModel; |
|---|
| 12 | import javax.swing.JList; |
|---|
| 13 | |
|---|
| 14 | /** |
|---|
| 15 | * |
|---|
| 16 | * @author jdalbey |
|---|
| 17 | */ |
|---|
| 18 | public class ATMSBatchViewer extends javax.swing.JFrame |
|---|
| 19 | { |
|---|
| 20 | /** |
|---|
| 21 | * Creates new form ATMSBatchViewer |
|---|
| 22 | */ |
|---|
| 23 | public ATMSBatchViewer() |
|---|
| 24 | { |
|---|
| 25 | initComponents(); |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | public void update(String currentTime, Queue<String> events) |
|---|
| 29 | { |
|---|
| 30 | lstEvents.setModel(new MyListModel(events)); |
|---|
| 31 | txtClockTime.setText(currentTime); |
|---|
| 32 | } |
|---|
| 33 | class MyListModel extends AbstractListModel<String> |
|---|
| 34 | { |
|---|
| 35 | String[] strings = { "item 1", "item 2" }; |
|---|
| 36 | public MyListModel(Queue<String> events) |
|---|
| 37 | { |
|---|
| 38 | strings = events.toArray(new String[events.size()]); |
|---|
| 39 | } |
|---|
| 40 | public int getSize() { return strings.length; } |
|---|
| 41 | public String getElementAt(int i) { return strings[i]; } |
|---|
| 42 | } |
|---|
| 43 | /** |
|---|
| 44 | * This method is called from within the constructor to initialize the form. |
|---|
| 45 | * WARNING: Do NOT modify this code. The content of this method is always |
|---|
| 46 | * regenerated by the Form Editor. |
|---|
| 47 | */ |
|---|
| 48 | @SuppressWarnings("unchecked") |
|---|
| 49 | // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents |
|---|
| 50 | private void initComponents() { |
|---|
| 51 | |
|---|
| 52 | pnlEvents = new javax.swing.JPanel(); |
|---|
| 53 | scrollEvents = new javax.swing.JScrollPane(); |
|---|
| 54 | lstEvents = new javax.swing.JList<>(); |
|---|
| 55 | txtClockTime = new javax.swing.JLabel(); |
|---|
| 56 | |
|---|
| 57 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); |
|---|
| 58 | |
|---|
| 59 | lstEvents.setFont(new java.awt.Font("Noto Mono", 0, 12)); // NOI18N |
|---|
| 60 | lstEvents.setModel(new javax.swing.AbstractListModel<String>() { |
|---|
| 61 | String[] strings = { "item 1", "item 2" }; |
|---|
| 62 | public int getSize() { return strings.length; } |
|---|
| 63 | public String getElementAt(int i) { return strings[i]; } |
|---|
| 64 | }); |
|---|
| 65 | scrollEvents.setViewportView(lstEvents); |
|---|
| 66 | |
|---|
| 67 | txtClockTime.setFont(new java.awt.Font("Noto Sans", 1, 14)); // NOI18N |
|---|
| 68 | txtClockTime.setText("0:00:00"); |
|---|
| 69 | |
|---|
| 70 | javax.swing.GroupLayout pnlEventsLayout = new javax.swing.GroupLayout(pnlEvents); |
|---|
| 71 | pnlEvents.setLayout(pnlEventsLayout); |
|---|
| 72 | pnlEventsLayout.setHorizontalGroup( |
|---|
| 73 | pnlEventsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
|---|
| 74 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlEventsLayout.createSequentialGroup() |
|---|
| 75 | .addContainerGap(83, Short.MAX_VALUE) |
|---|
| 76 | .addComponent(scrollEvents, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE) |
|---|
| 77 | .addGap(59, 59, 59)) |
|---|
| 78 | .addGroup(pnlEventsLayout.createSequentialGroup() |
|---|
| 79 | .addGap(186, 186, 186) |
|---|
| 80 | .addComponent(txtClockTime, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE) |
|---|
| 81 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) |
|---|
| 82 | ); |
|---|
| 83 | pnlEventsLayout.setVerticalGroup( |
|---|
| 84 | pnlEventsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
|---|
| 85 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlEventsLayout.createSequentialGroup() |
|---|
| 86 | .addComponent(txtClockTime, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) |
|---|
| 87 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
|---|
| 88 | .addComponent(scrollEvents, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE) |
|---|
| 89 | .addContainerGap()) |
|---|
| 90 | ); |
|---|
| 91 | |
|---|
| 92 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); |
|---|
| 93 | getContentPane().setLayout(layout); |
|---|
| 94 | layout.setHorizontalGroup( |
|---|
| 95 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
|---|
| 96 | .addGroup(layout.createSequentialGroup() |
|---|
| 97 | .addComponent(pnlEvents, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) |
|---|
| 98 | .addContainerGap()) |
|---|
| 99 | ); |
|---|
| 100 | layout.setVerticalGroup( |
|---|
| 101 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
|---|
| 102 | .addGroup(layout.createSequentialGroup() |
|---|
| 103 | .addComponent(pnlEvents, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) |
|---|
| 104 | .addGap(0, 129, Short.MAX_VALUE)) |
|---|
| 105 | ); |
|---|
| 106 | |
|---|
| 107 | pack(); |
|---|
| 108 | }// </editor-fold>//GEN-END:initComponents |
|---|
| 109 | |
|---|
| 110 | /** |
|---|
| 111 | * @param args the command line arguments |
|---|
| 112 | */ |
|---|
| 113 | public static void main(String args[]) { |
|---|
| 114 | /* Set the Nimbus look and feel */ |
|---|
| 115 | //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> |
|---|
| 116 | /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. |
|---|
| 117 | * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html |
|---|
| 118 | */ |
|---|
| 119 | try { |
|---|
| 120 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { |
|---|
| 121 | if ("Nimbus".equals(info.getName())) { |
|---|
| 122 | javax.swing.UIManager.setLookAndFeel(info.getClassName()); |
|---|
| 123 | break; |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | } catch (ClassNotFoundException ex) { |
|---|
| 127 | java.util.logging.Logger.getLogger(ATMSBatchViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
|---|
| 128 | } catch (InstantiationException ex) { |
|---|
| 129 | java.util.logging.Logger.getLogger(ATMSBatchViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
|---|
| 130 | } catch (IllegalAccessException ex) { |
|---|
| 131 | java.util.logging.Logger.getLogger(ATMSBatchViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
|---|
| 132 | } catch (javax.swing.UnsupportedLookAndFeelException ex) { |
|---|
| 133 | java.util.logging.Logger.getLogger(ATMSBatchViewer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
|---|
| 134 | } |
|---|
| 135 | //</editor-fold> |
|---|
| 136 | |
|---|
| 137 | /* Create and display the form */ |
|---|
| 138 | java.awt.EventQueue.invokeLater(new Runnable() { |
|---|
| 139 | public void run() { |
|---|
| 140 | Queue<String> sample = new LinkedList<String>(); |
|---|
| 141 | sample.add("Greetings"); |
|---|
| 142 | sample.add("Earthling"); |
|---|
| 143 | ATMSBatchViewer view = new ATMSBatchViewer(); |
|---|
| 144 | view.setVisible(true); |
|---|
| 145 | view.update("01", sample); |
|---|
| 146 | |
|---|
| 147 | } |
|---|
| 148 | }); |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | // Variables declaration - do not modify//GEN-BEGIN:variables |
|---|
| 152 | private javax.swing.JList<String> lstEvents; |
|---|
| 153 | private javax.swing.JPanel pnlEvents; |
|---|
| 154 | private javax.swing.JScrollPane scrollEvents; |
|---|
| 155 | private javax.swing.JLabel txtClockTime; |
|---|
| 156 | // End of variables declaration//GEN-END:variables |
|---|
| 157 | } |
|---|