| 1 | /* |
|---|
| 2 | * To change this template, choose Tools | Templates |
|---|
| 3 | * and open the template in the editor. |
|---|
| 4 | */ |
|---|
| 5 | package tmcsim.client.cadclientgui.screens; |
|---|
| 6 | |
|---|
| 7 | import java.awt.Dimension; |
|---|
| 8 | import java.awt.Toolkit; |
|---|
| 9 | import java.awt.event.ActionEvent; |
|---|
| 10 | import java.awt.event.ActionListener; |
|---|
| 11 | import java.awt.event.KeyEvent; |
|---|
| 12 | import java.awt.event.KeyListener; |
|---|
| 13 | import java.rmi.RemoteException; |
|---|
| 14 | import java.text.DateFormat; |
|---|
| 15 | import java.text.SimpleDateFormat; |
|---|
| 16 | import java.util.Date; |
|---|
| 17 | import java.util.Scanner; |
|---|
| 18 | |
|---|
| 19 | import javax.swing.JComponent; |
|---|
| 20 | import javax.swing.event.DocumentEvent; |
|---|
| 21 | import javax.swing.event.DocumentListener; |
|---|
| 22 | import javax.swing.table.DefaultTableModel; |
|---|
| 23 | import javax.swing.text.BadLocationException; |
|---|
| 24 | |
|---|
| 25 | import tmcsim.client.cadclientgui.enums.CADDataEnums.INC_TABLE; |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * |
|---|
| 29 | * @author Stuart |
|---|
| 30 | */ |
|---|
| 31 | public class PowerlineUI extends javax.swing.JFrame { |
|---|
| 32 | |
|---|
| 33 | public static enum HINT{ |
|---|
| 34 | II ("II <Incident> Comment"), |
|---|
| 35 | UI ("UI <Incident> Comment"), |
|---|
| 36 | RCARD ("RCARD SearchText[NEW]"), |
|---|
| 37 | CARD ("CARD"), |
|---|
| 38 | OFF ("OFF"); |
|---|
| 39 | |
|---|
| 40 | public String tag; |
|---|
| 41 | |
|---|
| 42 | private HINT(String t) { |
|---|
| 43 | tag = t; |
|---|
| 44 | } |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | public static enum DESCRIPTION{ |
|---|
| 48 | II ("Inquire Incident/Update Incident"), |
|---|
| 49 | UI ("Update Incident Details"), |
|---|
| 50 | RCARD ("Recall: Cardfile Search"), |
|---|
| 51 | CARD ("Open Cardfile"), |
|---|
| 52 | OFF ("Exit System"); |
|---|
| 53 | |
|---|
| 54 | public String tag; |
|---|
| 55 | |
|---|
| 56 | private DESCRIPTION(String t) { |
|---|
| 57 | tag = t; |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | /** |
|---|
| 62 | * Creates new form PrototypeUI |
|---|
| 63 | */ |
|---|
| 64 | public PowerlineUI(boolean visible, int number) { |
|---|
| 65 | initComponents(visible,number); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | /** |
|---|
| 69 | * This method is called from within the constructor to initialize the form. |
|---|
| 70 | * WARNING: Do NOT modify this code. The content of this method is always |
|---|
| 71 | * regenerated by the Form Editor. |
|---|
| 72 | */ |
|---|
| 73 | @SuppressWarnings("unchecked") |
|---|
| 74 | // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents |
|---|
| 75 | private void initComponents(boolean visible, int number) { |
|---|
| 76 | |
|---|
| 77 | jTabbedPane1 = new javax.swing.JTabbedPane(); |
|---|
| 78 | jDesktopPane1 = new javax.swing.JDesktopPane(); |
|---|
| 79 | jToolBar1 = new javax.swing.JToolBar(); |
|---|
| 80 | cmdLabel = new javax.swing.JLabel(); |
|---|
| 81 | cmdComboField = new javax.swing.JComboBox(); |
|---|
| 82 | hintLabel = new javax.swing.JLabel(); |
|---|
| 83 | descriptionLabel = new javax.swing.JLabel(); |
|---|
| 84 | |
|---|
| 85 | jToolBar1.setRollover(true); |
|---|
| 86 | setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE); |
|---|
| 87 | setTitle("Powerline"); |
|---|
| 88 | |
|---|
| 89 | cmdLabel.setText("CMD:"); |
|---|
| 90 | |
|---|
| 91 | cmdComboField.setEditable(true); |
|---|
| 92 | ((javax.swing.text.JTextComponent) cmdComboField.getEditor().getEditorComponent()) |
|---|
| 93 | .getDocument().addDocumentListener(new DocumentListener(){ |
|---|
| 94 | |
|---|
| 95 | public void changedUpdate(DocumentEvent e) { |
|---|
| 96 | updateHint(e); |
|---|
| 97 | } |
|---|
| 98 | public void insertUpdate(DocumentEvent e) { |
|---|
| 99 | updateHint(e); |
|---|
| 100 | } |
|---|
| 101 | public void removeUpdate(DocumentEvent e) { |
|---|
| 102 | updateHint(e); |
|---|
| 103 | } |
|---|
| 104 | }); |
|---|
| 105 | |
|---|
| 106 | cmdComboField.addActionListener(new ActionListener(){ |
|---|
| 107 | public void actionPerformed(ActionEvent e) { |
|---|
| 108 | if(((String)cmdComboField.getEditor().getItem()).equals("OFF")){ |
|---|
| 109 | System.exit(0); |
|---|
| 110 | } |
|---|
| 111 | else if(((String)cmdComboField.getEditor().getItem()).equals("CARD")){ |
|---|
| 112 | ScreenManager.openCardfile(); |
|---|
| 113 | } |
|---|
| 114 | else if(((String)cmdComboField.getEditor().getItem()).startsWith("RCARD")){ |
|---|
| 115 | Scanner scanner = new Scanner((String)cmdComboField.getEditor().getItem()); |
|---|
| 116 | scanner.next(); |
|---|
| 117 | if(!scanner.hasNext()){ |
|---|
| 118 | return; |
|---|
| 119 | } |
|---|
| 120 | String search = scanner.next(); |
|---|
| 121 | ScreenManager.createPowerlineSearch(search); |
|---|
| 122 | |
|---|
| 123 | } |
|---|
| 124 | else if(((String)cmdComboField.getEditor().getItem()).startsWith("II")){ |
|---|
| 125 | Scanner scanner = new Scanner((String)cmdComboField.getEditor().getItem()); |
|---|
| 126 | scanner.next(); |
|---|
| 127 | if(!scanner.hasNextInt()){ |
|---|
| 128 | return; |
|---|
| 129 | } |
|---|
| 130 | int incidentId = scanner.nextInt(); |
|---|
| 131 | ScreenManager.openIncidentViewer(incidentId); |
|---|
| 132 | } |
|---|
| 133 | else if(((String)cmdComboField.getEditor().getItem()).startsWith("UI")){ |
|---|
| 134 | Scanner scanner = new Scanner((String)cmdComboField.getEditor().getItem()); |
|---|
| 135 | scanner.next(); |
|---|
| 136 | if(!scanner.hasNextInt()){ |
|---|
| 137 | return; |
|---|
| 138 | } |
|---|
| 139 | int incidentId = scanner.nextInt(); |
|---|
| 140 | try { |
|---|
| 141 | if(ScreenManager.theCoordinator.checkForValidIncidentID(incidentId)){ |
|---|
| 142 | if(!scanner.hasNext()){ |
|---|
| 143 | return; |
|---|
| 144 | } |
|---|
| 145 | String comment = scanner.next(); |
|---|
| 146 | DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); |
|---|
| 147 | DateFormat timeFormat = new SimpleDateFormat("HH:mm:ss"); |
|---|
| 148 | String[] fields = {dateFormat.format(new Date()), |
|---|
| 149 | timeFormat.format(new Date()), |
|---|
| 150 | "","",comment}; |
|---|
| 151 | try { |
|---|
| 152 | ScreenManager.theCoordinator.addCadDataIncidentTable( |
|---|
| 153 | INC_TABLE.COMMENTS_NOTES, incidentId, fields); |
|---|
| 154 | } catch (RemoteException e1) { |
|---|
| 155 | e1.printStackTrace(); |
|---|
| 156 | } |
|---|
| 157 | ScreenManager.openIncidentViewer(incidentId); |
|---|
| 158 | cmdComboField.getEditor().setItem(""); |
|---|
| 159 | } |
|---|
| 160 | } catch (RemoteException e1) { |
|---|
| 161 | e1.printStackTrace(); |
|---|
| 162 | } |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | cmdComboField.getEditor().setItem(""); |
|---|
| 166 | hintLabel.setText(""); |
|---|
| 167 | descriptionLabel.setText(""); |
|---|
| 168 | } |
|---|
| 169 | }); |
|---|
| 170 | |
|---|
| 171 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); |
|---|
| 172 | getContentPane().setLayout(layout); |
|---|
| 173 | layout.setHorizontalGroup( |
|---|
| 174 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
|---|
| 175 | .addGroup(layout.createSequentialGroup() |
|---|
| 176 | .addContainerGap() |
|---|
| 177 | .addComponent(cmdLabel) |
|---|
| 178 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
|---|
| 179 | .addComponent(cmdComboField, 0, 454, Short.MAX_VALUE) |
|---|
| 180 | .addContainerGap()) |
|---|
| 181 | .addGroup(layout.createSequentialGroup() |
|---|
| 182 | .addGap(42, 42, 42) |
|---|
| 183 | .addComponent(hintLabel)) |
|---|
| 184 | .addGroup(layout.createSequentialGroup() |
|---|
| 185 | .addGap(42, 42, 42) |
|---|
| 186 | .addComponent(descriptionLabel)) |
|---|
| 187 | ); |
|---|
| 188 | layout.setVerticalGroup( |
|---|
| 189 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
|---|
| 190 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() |
|---|
| 191 | .addGap(29, 29, 29) |
|---|
| 192 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) |
|---|
| 193 | .addComponent(cmdLabel) |
|---|
| 194 | .addComponent(cmdComboField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) |
|---|
| 195 | .addComponent(hintLabel) |
|---|
| 196 | .addComponent(descriptionLabel) |
|---|
| 197 | .addContainerGap(35, Short.MAX_VALUE)) |
|---|
| 198 | ); |
|---|
| 199 | |
|---|
| 200 | setTitle("<" + number + ">Powerline"); |
|---|
| 201 | if (visible){ |
|---|
| 202 | setVisible(true); |
|---|
| 203 | }else{ |
|---|
| 204 | setVisible(false); |
|---|
| 205 | } |
|---|
| 206 | pack(); |
|---|
| 207 | Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); |
|---|
| 208 | setLocation((int)(dim.getWidth() - this.getWidth()),0); |
|---|
| 209 | }// </editor-fold>//GEN-END:initComponents |
|---|
| 210 | |
|---|
| 211 | public void updateHint(DocumentEvent e){ |
|---|
| 212 | try { |
|---|
| 213 | if(e.getDocument().getLength() > 0){ |
|---|
| 214 | String firstLetter = e.getDocument().getText(0, 1); |
|---|
| 215 | if(firstLetter.equals("O")){ |
|---|
| 216 | hintLabel.setText(HINT.OFF.tag); |
|---|
| 217 | descriptionLabel.setText(DESCRIPTION.OFF.tag); |
|---|
| 218 | } |
|---|
| 219 | else if(firstLetter.equals("I")){ |
|---|
| 220 | hintLabel.setText(HINT.II.tag); |
|---|
| 221 | descriptionLabel.setText(DESCRIPTION.II.tag); |
|---|
| 222 | } |
|---|
| 223 | else if(firstLetter.equals("U")){ |
|---|
| 224 | hintLabel.setText(HINT.UI.tag); |
|---|
| 225 | descriptionLabel.setText(DESCRIPTION.UI.tag); |
|---|
| 226 | } |
|---|
| 227 | else if(firstLetter.equals("R")){ |
|---|
| 228 | hintLabel.setText(HINT.RCARD.tag); |
|---|
| 229 | descriptionLabel.setText(DESCRIPTION.RCARD.tag); |
|---|
| 230 | } |
|---|
| 231 | else if(firstLetter.equals("C")){ |
|---|
| 232 | hintLabel.setText(HINT.CARD.tag); |
|---|
| 233 | descriptionLabel.setText(DESCRIPTION.CARD.tag); |
|---|
| 234 | } |
|---|
| 235 | else { |
|---|
| 236 | hintLabel.setText(""); |
|---|
| 237 | descriptionLabel.setText(""); |
|---|
| 238 | } |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | } catch (BadLocationException e1) { |
|---|
| 242 | e1.printStackTrace(); |
|---|
| 243 | } |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | /* |
|---|
| 247 | * Clears text. |
|---|
| 248 | */ |
|---|
| 249 | public void clearText(){ |
|---|
| 250 | cmdComboField.getEditor().setItem(""); |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | /* |
|---|
| 254 | * Puts "RCARD" in textfield. |
|---|
| 255 | */ |
|---|
| 256 | public void putRCARD(){ |
|---|
| 257 | cmdComboField.getEditor().setItem("RCARD"); |
|---|
| 258 | } |
|---|
| 259 | |
|---|
| 260 | /* |
|---|
| 261 | * Makes screen visible. |
|---|
| 262 | */ |
|---|
| 263 | public void open(){ |
|---|
| 264 | setVisible(true); |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | /* |
|---|
| 268 | * Hides screen. |
|---|
| 269 | */ |
|---|
| 270 | public void close(){ |
|---|
| 271 | setVisible(false); |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | /*public void submitCmd() { |
|---|
| 275 | if (jComboBox1.getSelectedItem() instanceof String) { |
|---|
| 276 | try { |
|---|
| 277 | Document cmdDoc = DocumentBuilderFactory.newInstance() |
|---|
| 278 | .newDocumentBuilder().newDocument(); |
|---|
| 279 | Element cmdElem = cmdDoc.createElement(CAD_CLIENT_CMD.TERMINAL_CMD_LINE.type); |
|---|
| 280 | |
|---|
| 281 | parser.parseCommand(cmdElem, (String)jComboBox1.getSelectedItem()); |
|---|
| 282 | cmdDoc.appendChild(cmdElem); |
|---|
| 283 | |
|---|
| 284 | theModel.transmitCommand(cmdDoc); |
|---|
| 285 | } |
|---|
| 286 | catch (Exception ex) { |
|---|
| 287 | System.out.println(ex.getMessage()); |
|---|
| 288 | } |
|---|
| 289 | } |
|---|
| 290 | }*/ |
|---|
| 291 | |
|---|
| 292 | // Variables declaration - do not modify//GEN-BEGIN:variables |
|---|
| 293 | private javax.swing.JComboBox cmdComboField; |
|---|
| 294 | private javax.swing.JLabel cmdLabel; |
|---|
| 295 | private javax.swing.JDesktopPane jDesktopPane1; |
|---|
| 296 | private javax.swing.JTabbedPane jTabbedPane1; |
|---|
| 297 | private javax.swing.JToolBar jToolBar1; |
|---|
| 298 | private javax.swing.JLabel hintLabel; |
|---|
| 299 | private javax.swing.JLabel descriptionLabel; |
|---|
| 300 | // End of variables declaration//GEN-END:variables |
|---|
| 301 | } |
|---|