package event.editor; import java.awt.event.*; import java.util.Observable; import scriptbuilder.structures.events.ScriptEventInterface; import scriptbuilder.structures.events.UnitEvent; /** * * @author nathaniellehrer */ public class UnitPanel extends javax.swing.JPanel implements RemoveablePanel, ScriptEventEditorPanel { private ActionListener removeListener; private UnitEvent event; /** * Creates new form UnitPanel */ public UnitPanel() { initComponents(); txtUnitNumber.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { help.setText("Unit number is formatted as #-#\t\tExample: 5-5"); } public void focusLost(FocusEvent e) { help.setText(""); } }); } public void setRemoveListener(ActionListener listener) { removeListener = listener; } public void getEventObject(ScriptEventInterface sei) { event = (UnitEvent) sei; txtUnitNumber.setText(event.unitNum); for (int i = 0; i < ActiveDropdown.getItemCount(); i++) { if (event.unitActive.equalsIgnoreCase((String) ActiveDropdown.getItemAt(i))) { ActiveDropdown.setSelectedIndex(i); } } txtUnitNumber.addKeyListener(new KeyListener() { public void keyTyped(KeyEvent e) { } public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { event.unitNum = txtUnitNumber.getText(); } } public void keyReleased(KeyEvent e) { } }); ActiveDropdown.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { event.unitActive = ActiveDropdown.getSelectedItem().toString(); } }); for (int i = 0; i < PrimaryDropdown.getItemCount(); i++) { if (event.unitPrimary.equalsIgnoreCase((String) PrimaryDropdown.getItemAt(i))) { PrimaryDropdown.setSelectedIndex(i); } } PrimaryDropdown.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { event.unitPrimary = PrimaryDropdown.getSelectedItem().toString(); } }); boolean containsItem = false; for (int i = 0; i < StatusDropdown.getItemCount() && !containsItem; i++) { if (event.unitStatus.equalsIgnoreCase((String) StatusDropdown.getItemAt(i))) { StatusDropdown.setSelectedIndex(i); containsItem = true; } } if (!containsItem) { StatusDropdown.addItem(event.unitStatus); StatusDropdown.setSelectedItem(StatusDropdown.getItemCount() - 1); } StatusDropdown.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { event.unitStatus = StatusDropdown.getSelectedItem().toString(); } }); } public void update(Observable o, Object arg) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } /** * 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") // //GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); txtUnitNumber = new javax.swing.JFormattedTextField(); removeButton = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); StatusDropdown = new javax.swing.JComboBox(); jLabel3 = new javax.swing.JLabel(); PrimaryDropdown = new javax.swing.JComboBox(); jLabel4 = new javax.swing.JLabel(); ActiveDropdown = new javax.swing.JComboBox(); help = new javax.swing.JLabel(); jLabel1.setText("Unit Number"); txtUnitNumber.setText(" - "); txtUnitNumber.setToolTipText(""); removeButton.setText("Remove"); removeButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { removeThisProperty(evt); } }); jLabel2.setText("Status"); StatusDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1098", "1097", "ENRT" })); jLabel3.setText("Primary"); PrimaryDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "True", "False" })); jLabel4.setText("Active"); ActiveDropdown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "True", "False" })); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, removeButton) .add(org.jdesktop.layout.GroupLayout.TRAILING, help, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jLabel1) .add(jLabel2)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(StatusDropdown, 0, 475, Short.MAX_VALUE) .add(txtUnitNumber, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE))) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jLabel3) .add(jLabel4)) .add(43, 43, 43) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(ActiveDropdown, 0, 475, Short.MAX_VALUE) .add(PrimaryDropdown, 0, 475, Short.MAX_VALUE)))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(removeButton) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel1) .add(txtUnitNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel2) .add(StatusDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel3) .add(PrimaryDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel4) .add(ActiveDropdown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 128, Short.MAX_VALUE) .add(help, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); }// //GEN-END:initComponents private void removeThisProperty(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeThisProperty if (removeListener != null) { removeListener.actionPerformed(new ActionEvent(this, 0, "")); } }//GEN-LAST:event_removeThisProperty // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox ActiveDropdown; private javax.swing.JComboBox PrimaryDropdown; private javax.swing.JComboBox StatusDropdown; private javax.swing.JLabel help; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JButton removeButton; private javax.swing.JFormattedTextField txtUnitNumber; // End of variables declaration//GEN-END:variables }