Changeset 145 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/gui/panels
- Timestamp:
- 11/04/2019 08:14:32 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/scriptbuilder/gui/panels/IncidentTimelinePanel.java
r133 r145 202 202 * Determine if the mouse click happened within a valid timeSlice on 203 203 * this incident; if so, activate the Editor window for that timeSlice. 204 * 205 * @param ethe mouse event204 *todo: fix bug where the event editor window appears even when a event type is not selected. 205 * @param clickEvent the mouse event 206 206 */ 207 207 @Override 208 public void mouseClicked(MouseEvent e)209 { 210 Editor ed = null;211 ScriptBuilderFrame f= null;212 IncidentEditorFrame g= null;208 public void mouseClicked(MouseEvent clickEvent) 209 { 210 Editor editor = null; 211 ScriptBuilderFrame scriptBuilderFrameCurrent = null; 212 IncidentEditorFrame incidentEditFrameCurrent = null; 213 213 if (getTopLevelAncestor() instanceof ScriptBuilderFrame) 214 214 { 215 f= (ScriptBuilderFrame) getTopLevelAncestor();215 scriptBuilderFrameCurrent = (ScriptBuilderFrame) getTopLevelAncestor(); 216 216 217 217 } 218 218 else if (getTopLevelAncestor() instanceof IncidentEditorFrame) 219 219 { 220 g = (IncidentEditorFrame) getTopLevelAncestor(); 221 ed = new Editor(g); 222 } 223 224 x = cursorTime = e.getX(); 225 y = e.getY(); 226 227 if (e.getX() % ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK 220 incidentEditFrameCurrent = (IncidentEditorFrame) getTopLevelAncestor(); 221 editor = new Editor(incidentEditFrameCurrent); 222 } 223 224 x = cursorTime = clickEvent.getX(); 225 y = clickEvent.getY(); 226 //System.out.println(cursorTime); 227 //logic that follows is used to "snap" the cursor location to the lines displayed on the timeline panel 228 if (clickEvent.getX() % ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK 228 229 > ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK / 2) 229 230 { 230 231 cursorTime += ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK 231 - e.getX()232 - clickEvent.getX() 232 233 % ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK; 233 234 } 234 235 else 235 236 { 236 cursorTime -= e.getX()237 cursorTime -= clickEvent.getX() 237 238 % ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK; 238 239 } 239 240 240 241 int newSlice = (cursorTime / ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK); 242 241 243 newSlice *= ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION; 242 244 /** … … 248 250 } 249 251 250 if (ed != null) 251 { 252 ed.setSlice(incident.slices.get(newSlice)); 253 } 252 254 253 255 254 /** 256 * Add a new icon if left mouse button was clicked *255 * Add a new icon if left mouse button was clicked 257 256 */ 258 if ( e.getButton() == MouseEvent.BUTTON1)259 { 260 257 if (clickEvent.getButton() == MouseEvent.BUTTON1) 258 { 259 261 260 if (getTopLevelAncestor() instanceof IncidentEditorFrame) 262 261 { 263 if (incident.slices.size() == 0 && newSlice != 0) 262 263 if (incidentEditFrameCurrent.currentEventType != null) 264 264 { 265 JOptionPane.showMessageDialog(g, "This is the first event in the incident.\n" 266 + "Therefore, it will be automatically positioned at time 00:00:00,\n" 267 + "relative to the start of the incident.", "Event will be moved", JOptionPane.INFORMATION_MESSAGE); 268 newSlice = 0; 269 } 270 if (g.currentEventType != null) 271 { 272 I_ScriptEvent s = ScriptEvent.factoryByType(g.currentEventType); 273 if (ed != null) 265 if ((incident.slices.size() == 0 && newSlice != 0)||(incident.slices.get(0).events.isEmpty())) 274 266 { 275 ed.addEvent(eventTypeToPropertyMap.get(g.currentEventType), s); 267 268 JOptionPane.showMessageDialog(incidentEditFrameCurrent, "This is the first event in the incident.\n" 269 + "Therefore, it will be automatically positioned at time 00:00:00,\n" 270 + "relative to the start of the incident.", "Event will be moved", JOptionPane.INFORMATION_MESSAGE); 271 newSlice = 0; 276 272 } 277 if (incident.slices.get(newSlice) == null) 273 //add the time of addition to be passed through to the event itself somewhere in here? Stored in newSlice 274 I_ScriptEvent newScriptEvent = ScriptEvent.factoryByType(incidentEditFrameCurrent.currentEventType); 275 // if (editor != null) 276 // { 277 // //this is not necessary if we just load the slices after we create a new one in the window, creates some extra dummy slice for no reason. 278 // //this adds a new event to the existing editor window 279 // editor.addEvent(eventTypeToPropertyMap.get(incidentEditFrameCurrent.currentEventType), newScriptEvent); 280 // } 281 if (incident.slices.get(newSlice) == null || incident.slices.get(newSlice).events.isEmpty()) 278 282 { 279 incident.addNewEvent(s, newSlice); 283 //if there is no slice at the newSlice time, then create a new event with a new slice at that time 284 285 incident.addNewEvent(newScriptEvent, newSlice); 286 //find out where the new slice is added and then make it 287 //possible to 288 //editor.setSlice(incident.getSlices().get(newSlice)); 280 289 } 281 290 else 282 291 { 283 incident.slices.get(newSlice).addEvent(s); 292 //if there is already a slice there, just add the event to the 293 incident.slices.get(newSlice).addEvent(newScriptEvent); 284 294 } 285 g.update(null, g.getIncident());295 incidentEditFrameCurrent.update(null, incidentEditFrameCurrent.getIncident()); 286 296 } 287 297 } 288 298 } 289 299 300 if (editor != null) 301 { 302 editor.setSlice(incident.slices.get(newSlice)); 303 } 290 304 if (incident.slices.get(newSlice) != null 291 305 && getTopLevelAncestor() instanceof IncidentEditorFrame) 292 306 { 293 ed .setVisible(true);307 editor.setVisible(true); 294 308 } 295 309 } … … 498 512 if (focused) 499 513 { 514 //System.out.println("Cursor Time: " + cursorTime); 500 515 CursorDrawer.DrawCursor(g2d, cursorTime, false); 501 516 if (this.getTopLevelAncestor() instanceof ScriptBuilderFrame)
Note: See TracChangeset
for help on using the changeset viewer.
