Changeset 101 in tmcsimulator-scriptbuilder for trunk/src/event/editor/frame/Editor.java


Ignore:
Timestamp:
08/30/2017 10:05:35 AM (9 years ago)
Author:
bmcguffin
Message:

Added text field, txtEventStart, to bottom of event editor screen. This text field by default displays the time that the event starts. Altering this field will change the start time of the selected event to the new value.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/event/editor/frame/Editor.java

    r97 r101  
    88import java.util.*; 
    99import java.awt.event.*; 
     10import java.text.SimpleDateFormat; 
    1011import scriptbuilder.gui.IncidentEditorFrame; 
     12import scriptbuilder.gui.panels.IncidentTimelinePanel; 
     13import scriptbuilder.structures.ScriptEvent; 
    1114import scriptbuilder.structures.ScriptIncident; 
     15import scriptbuilder.structures.TimeSlice; 
    1216import scriptbuilder.structures.events.*; 
    1317 
     
    1620 
    1721    IncidentEditorFrame topFrame = null; 
     22 
     23    ScriptIncident incident = null; 
     24 
     25    TimeSlice slice = null; 
    1826 
    1927    private PropertyModel model = new PropertyModel(); 
     
    2331//        return model; 
    2432//    } 
    25     public void addProperty(Properties property, I_ScriptEvent se) 
    26     { 
    27         model.addProperty(property, se); 
     33    public void addEvent(Properties property, I_ScriptEvent se) 
     34    { 
     35        model.addEventPanel(property, se); 
     36    } 
     37 
     38    public void setSlice(TimeSlice ts) 
     39    { 
     40        slice = ts; 
     41 
     42        if (slice != null) 
     43 
     44        { 
     45            for (I_ScriptEvent se : slice.events) 
     46            { 
     47 
     48                this.addEvent(IncidentTimelinePanel.eventTypeToPropertyMap.get(se.getScriptEventType()), se); 
     49 
     50            } 
     51            System.out.println("Current time = " + slice.getTime() + " seconds"); 
     52            SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss"); 
     53            df.setTimeZone(TimeZone.getTimeZone("GMT")); 
     54            String eventTime = df.format(new Date(slice.getTime() * 1000)); 
     55            System.out.println("[" + eventTime + "]"); 
     56            txtEventStart.setText(eventTime); 
     57        } 
     58 
    2859    } 
    2960 
     
    3768            if (src.isSelected()) 
    3869            { 
    39                 model.addProperty(property, new CCTVEvent()); 
     70                model.addEventPanel(property, new CCTVEvent()); 
    4071            } 
    4172            else 
     
    5182        { 
    5283            JMenuItem src = (JMenuItem) evt.getSource(); 
    53             model.addProperty(Properties.valueOf(src.getText().replaceAll(" ", "")), new CCTVEvent()); 
     84            model.addEventPanel(Properties.valueOf(src.getText().replaceAll(" ", "")), new CCTVEvent()); 
    5485        } 
    5586    }; 
     
    6293        topFrame = frame; 
    6394        initComponents(); 
     95 
     96        incident = frame.getIncident(); 
    6497 
    6598        model.addObserver(this); 
     
    91124            } 
    92125        } 
     126 
     127        String eventTime = ""; 
     128 
     129        txtEventStart.setText(eventTime); 
     130 
     131        txtEventStart.addKeyListener(new KeyListener() 
     132        { 
     133 
     134            @Override 
     135            public void keyTyped(KeyEvent e) 
     136            { 
     137            } 
     138 
     139            @Override 
     140            public void keyPressed(KeyEvent e) 
     141            { 
     142                if (e.getKeyCode() == KeyEvent.VK_ENTER) 
     143                { 
     144                    updateEventTime(); 
     145                } 
     146            } 
     147 
     148            @Override 
     149            public void keyReleased(KeyEvent e) 
     150            { 
     151            } 
     152        }); 
    93153    } 
    94154 
     
    106166        jTabbedPane1 = new javax.swing.JTabbedPane(); 
    107167        jPanel2 = new javax.swing.JPanel(); 
     168        txtEventStart = new javax.swing.JTextField(); 
    108169        btnRemoveCurrentEvent = new javax.swing.JButton(); 
    109170        jMenuBar1 = new javax.swing.JMenuBar(); 
     
    143204        setTitle("Event Editor"); 
    144205 
    145         btnRemoveCurrentEvent.setText("Remove This Event"); 
    146         btnRemoveCurrentEvent.addActionListener(new java.awt.event.ActionListener() 
    147         { 
    148             public void actionPerformed(java.awt.event.ActionEvent evt) 
    149             { 
    150                 btnRemoveCurrentEventActionPerformed(evt); 
    151             } 
    152         }); 
    153  
    154206        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2); 
    155207        jPanel2.setLayout(jPanel2Layout); 
    156208        jPanel2Layout.setHorizontalGroup( 
    157209            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 
    158             .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup() 
    159                 .addContainerGap(701, Short.MAX_VALUE) 
    160                 .add(btnRemoveCurrentEvent, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 226, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 
    161                 .addContainerGap()) 
     210            .add(0, 613, Short.MAX_VALUE) 
    162211        ); 
    163212        jPanel2Layout.setVerticalGroup( 
    164213            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 
    165             .add(btnRemoveCurrentEvent) 
     214            .add(0, 34, Short.MAX_VALUE) 
    166215        ); 
     216 
     217        txtEventStart.setText("00:00:00"); 
     218 
     219        btnRemoveCurrentEvent.setText("Remove This Event"); 
     220        btnRemoveCurrentEvent.addActionListener(new java.awt.event.ActionListener() 
     221        { 
     222            public void actionPerformed(java.awt.event.ActionEvent evt) 
     223            { 
     224                btnRemoveCurrentEventActionPerformed(evt); 
     225            } 
     226        }); 
    167227 
    168228        jMenu1.setText("Evaluations"); 
     
    347407            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 
    348408            .add(org.jdesktop.layout.GroupLayout.TRAILING, jTabbedPane1) 
    349             .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
     409            .add(layout.createSequentialGroup() 
     410                .addContainerGap() 
     411                .add(txtEventStart, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 
     412                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 
     413                .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
     414                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 
     415                .add(btnRemoveCurrentEvent, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 226, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 
     416                .addContainerGap()) 
    350417        ); 
    351418        layout.setVerticalGroup( 
     
    353420            .add(layout.createSequentialGroup() 
    354421                .addContainerGap() 
    355                 .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 539, Short.MAX_VALUE) 
     422                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 534, Short.MAX_VALUE) 
    356423                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 
    357                 .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 
     424                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 
     425                    .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 
     426                    .add(txtEventStart, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 
     427                    .add(btnRemoveCurrentEvent))) 
    358428        ); 
    359429 
     
    386456 
    387457    }//GEN-LAST:event_btnRemoveCurrentEventActionPerformed 
     458 
     459    private void updateEventTime() 
     460    { 
     461        String[] tokens = txtEventStart.getText().split(":"); 
     462 
     463        int hrs = Integer.parseInt(tokens[0]); 
     464        int mins = Integer.parseInt(tokens[1]); 
     465        int secs = Integer.parseInt(tokens[2]); 
     466 
     467        int time = (3600 * hrs) + (60 * mins) + secs; 
     468 
     469        int index = jTabbedPane1.getSelectedIndex(); 
     470 
     471        if (index >= 0 && jTabbedPane1.getTabComponentAt(index) != null) 
     472        { 
     473            JPanel removable = (JPanel) jTabbedPane1 
     474                    .getSelectedComponent(); 
     475            I_ScriptEvent ise = this.model.eventMap.get(removable); 
     476            if (time != slice.getTime()) 
     477            { 
     478                System.out.println("New time = " + time); 
     479                this.model.properties.removeProperty(removable); 
     480                incident.addNewEvent(ise, time); 
     481                SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss"); 
     482                df.setTimeZone(TimeZone.getTimeZone("GMT")); 
     483                String eventTime = df.format(new Date(slice.getTime() * 1000)); 
     484                txtEventStart.setText(eventTime); 
     485            } 
     486        } 
     487    } 
    388488 
    389489    /** 
     
    427527    private javax.swing.JPanel jPanel2; 
    428528    private javax.swing.JTabbedPane jTabbedPane1; 
     529    private javax.swing.JTextField txtEventStart; 
    429530    // End of variables declaration//GEN-END:variables 
    430531 
Note: See TracChangeset for help on using the changeset viewer.