Changeset 145 in tmcsimulator-scriptbuilder for trunk/src/event/editor/UnitPanel.java
- Timestamp:
- 11/04/2019 08:14:32 AM (7 years ago)
- File:
-
- 1 edited
-
trunk/src/event/editor/UnitPanel.java (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/event/editor/UnitPanel.java
r140 r145 3 3 import java.awt.event.*; 4 4 import java.util.Observable; 5 import java.util.List; 6 import java.util.ArrayList; 7 import javax.swing.DefaultComboBoxModel; 8 import javax.swing.ComboBoxModel; 5 9 import scriptbuilder.structures.events.I_ScriptEvent; 10 import scriptbuilder.structures.units.Unit; 6 11 import scriptbuilder.structures.events.UnitEvent; 7 12 … … 9 14 * 10 15 * @author nathaniellehrer 16 * 17 * 11 18 */ 12 19 public class UnitPanel extends javax.swing.JPanel implements I_ScriptEventEditorPanel … … 15 22 private ActionListener removeListener; 16 23 private UnitEvent event; 17 24 private List<Unit> units; 25 26 List<String> names = new ArrayList<String>(); 18 27 /** 19 28 * Creates new form UnitPanel … … 22 31 { 23 32 initComponents(); 24 25 txtUnitNumber.addFocusListener(new FocusListener() 26 { 27 28 public void focusGained(FocusEvent e) 29 { 30 help.setText("Unit number is formatted as #-#\t\tExample: 5-5"); 31 } 32 33 public void focusLost(FocusEvent e) 34 { 35 help.setText(""); 36 } 37 38 }); 39 } 40 33 34 //units = event.slice.getIncident().script.units; 35 36 } 37 38 /** 39 * Loads the event information into the event editor window. 40 * @param sei Scriptevent that is being loaded in 41 */ 41 42 @Override 42 43 public void getEventObject(I_ScriptEvent sei) 43 44 { 45 44 46 event = (UnitEvent) sei; 45 txtUnitNumber.setText(event.unitNum); 47 //loads the current unit list into the combobox on re-opening of unit event 48 loadSelector(); 46 49 for (int i = 0; i < ActiveDropdown.getItemCount(); i++) 47 50 { … … 49 52 { 50 53 ActiveDropdown.setSelectedIndex(i); 54 } 55 } 56 57 //for each name in the names list 58 for (int i = 0; i < names.size(); i++) 59 { 60 //which event equals which index in the names list? 61 if (event.unitNum.equalsIgnoreCase((String) names.get(i))) 62 { 63 64 //set the unit selector to the data model value 65 unitSelector.setSelectedIndex(i); 66 51 67 } 52 68 } … … 80 96 public void update(Observable o, Object arg) 81 97 { 98 //todo: make supported 82 99 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 83 100 } … … 90 107 return true; 91 108 } 109 110 111 private void loadSelector(){ 112 //checks if the event is exist 113 if(event != null) 114 { 115 //loads the names list from the top data model 116 loadNames(); 117 //asks if the unitselector already has some units added into it 118 119 if(unitSelector.getModel().equals(new DefaultComboBoxModel(names.toArray())) || (unitSelector.getModel().getSize() == 0)) 120 { 121 //if combobox empty, load combobox 122 unitSelector.setModel(new DefaultComboBoxModel(names.toArray())); 123 } 124 125 126 127 } 128 129 } 130 131 /** 132 * Loads the unit names from the unit list in SimulationScript 133 */ 134 private void loadNames(){ 135 //checks if the event is exist 136 if(event!=null) 137 { 138 //this sucks! try to change it sometime 139 //grabs the unit list from the top of the SimulationScript and 140 //appends them to the names list 141 units = event.slice.getIncident().script.units; 142 143 for(Unit u : units) 144 { 145 names.add(u.UnitNum); 146 } 147 } 148 } 92 149 93 150 @Override 151 /** 152 * when window is closed, these values are set. 153 */ 94 154 public void uponClose() 95 155 { 96 if (event != null) 97 { 98 event.unitNum = txtUnitNumber.getText(); 156 157 if (event != null && unitSelector.getItemCount() != 0) 158 { 159 event.unitNum = unitSelector.getSelectedItem().toString(); 99 160 event.unitActive = ActiveDropdown.getSelectedItem().toString(); 100 161 event.unitPrimary = PrimaryDropdown.getSelectedItem().toString(); 101 162 event.unitStatus = StatusDropdown.getSelectedItem().toString(); 163 164 //old logic for creating dummy unit 165 /*if(event.slice.getIncident().script.hasUnit(txtUnitNumber.getText())){ 166 //checks to see if there is already a unit selected there 167 //event.unitNum = (txtUnitNumber.getText()); 168 169 }else{ 170 //Creates a dummy unit here 171 event.slice.getIncident().script.addDummyUnit(txtUnitNumber.getText()); 172 //event.unitNum = (txtUnitNumber.getText()); 173 event.unitActive = ActiveDropdown.getSelectedItem().toString(); 174 event.unitPrimary = PrimaryDropdown.getSelectedItem().toString(); 175 event.unitStatus = StatusDropdown.getSelectedItem().toString(); 176 //System.out.println("invalid unit number"); 177 }*/ 178 102 179 } 103 180 } … … 110 187 @SuppressWarnings("unchecked") 111 188 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 112 private void initComponents() 113 { 114 115 jLabel1 = new javax.swing.JLabel(); 116 txtUnitNumber = new javax.swing.JFormattedTextField(); 189 private void initComponents() { 190 117 191 jLabel2 = new javax.swing.JLabel(); 118 192 StatusDropdown = new javax.swing.JComboBox(); … … 122 196 ActiveDropdown = new javax.swing.JComboBox(); 123 197 help = new javax.swing.JLabel(); 124 125 jLabel1.setText("Unit Number"); 126 127 txtUnitNumber.setText(" - "); 128 txtUnitNumber.setToolTipText(""); 198 jLabel5 = new javax.swing.JLabel(); 199 unitSelector = new javax.swing.JComboBox<>(); 129 200 130 201 jLabel2.setText("Status"); … … 139 210 140 211 ActiveDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "True", "False" })); 212 213 jLabel5.setText("Unit"); 214 215 unitSelector.addAncestorListener(new javax.swing.event.AncestorListener() { 216 public void ancestorMoved(javax.swing.event.AncestorEvent evt) { 217 } 218 public void ancestorAdded(javax.swing.event.AncestorEvent evt) { 219 unitSelectorAncestorAdded(evt); 220 } 221 public void ancestorRemoved(javax.swing.event.AncestorEvent evt) { 222 } 223 }); 224 unitSelector.addMouseListener(new java.awt.event.MouseAdapter() { 225 public void mouseEntered(java.awt.event.MouseEvent evt) { 226 unitSelectorMouseEntered(evt); 227 } 228 }); 229 unitSelector.addActionListener(new java.awt.event.ActionListener() { 230 public void actionPerformed(java.awt.event.ActionEvent evt) { 231 unitSelectorActionPerformed(evt); 232 } 233 }); 141 234 142 235 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); … … 150 243 .add(layout.createSequentialGroup() 151 244 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 152 .add(jLabel1)153 .add(jLabel2))154 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)155 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)156 .add(StatusDropdown, 0, 475, Short.MAX_VALUE)157 .add(txtUnitNumber, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)))158 .add(layout.createSequentialGroup()159 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)160 245 .add(jLabel3) 161 246 .add(jLabel4)) … … 163 248 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 164 249 .add(ActiveDropdown, 0, 475, Short.MAX_VALUE) 165 .add(PrimaryDropdown, 0, 475, Short.MAX_VALUE)))) 250 .add(PrimaryDropdown, 0, 475, Short.MAX_VALUE))) 251 .add(layout.createSequentialGroup() 252 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 253 .add(jLabel2) 254 .add(jLabel5)) 255 .add(54, 54, 54) 256 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 257 .add(layout.createSequentialGroup() 258 .add(StatusDropdown, 0, 419, Short.MAX_VALUE) 259 .add(57, 57, 57)) 260 .add(layout.createSequentialGroup() 261 .add(unitSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 262 .add(0, 0, Short.MAX_VALUE))))) 166 263 .addContainerGap()) 167 264 ); … … 169 266 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 170 267 .add(layout.createSequentialGroup() 171 .add( 47, 47, 47)268 .add(82, 82, 82) 172 269 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 173 .add(jLabel 1)174 .add( txtUnitNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))175 .addPreferredGap(org.jdesktop.layout.LayoutStyle. UNRELATED)270 .add(jLabel5) 271 .add(unitSelector, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 272 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 176 273 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 177 274 .add(jLabel2) … … 185 282 .add(jLabel4) 186 283 .add(ActiveDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 187 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 1 28, Short.MAX_VALUE)284 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 100, Short.MAX_VALUE) 188 285 .add(help, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 189 286 .addContainerGap()) 190 287 ); 191 288 }// </editor-fold>//GEN-END:initComponents 289 290 private void unitSelectorAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_unitSelectorAncestorAdded 291 //loads the unitSelector on the initialization of the window 292 loadSelector(); 293 }//GEN-LAST:event_unitSelectorAncestorAdded 294 295 private void unitSelectorMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_unitSelectorMouseEntered 296 297 }//GEN-LAST:event_unitSelectorMouseEntered 298 299 private void unitSelectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_unitSelectorActionPerformed 300 // TODO add your handling code here: 301 }//GEN-LAST:event_unitSelectorActionPerformed 192 302 193 303 … … 197 307 private javax.swing.JComboBox StatusDropdown; 198 308 private javax.swing.JLabel help; 199 private javax.swing.JLabel jLabel1;200 309 private javax.swing.JLabel jLabel2; 201 310 private javax.swing.JLabel jLabel3; 202 311 private javax.swing.JLabel jLabel4; 203 private javax.swing.JFormattedTextField txtUnitNumber; 312 private javax.swing.JLabel jLabel5; 313 private javax.swing.JComboBox<String> unitSelector; 204 314 // End of variables declaration//GEN-END:variables 205 315
Note: See TracChangeset
for help on using the changeset viewer.
