Normand Briere
2018-10-27 d34fd9341c61d13677e029cb187d4dacff5e44ea
timeflow/views/TimelineView.java
....@@ -1,21 +1,24 @@
11 package timeflow.views;
22
33 import timeflow.app.ui.ComponentCluster;
4
-import timeflow.data.db.*;
4
+import timeflow.app.ui.EditRecordPanel;
5
+import timeflow.data.db.DBUtils;
56 import timeflow.data.time.*;
67 import timeflow.model.*;
7
-import timeflow.views.CalendarView.CalendarPanel;
8
-import timeflow.views.CalendarView.ScrollingCalendar;
9
-import timeflow.vis.*;
8
+//import timeflow.views.CalendarView.CalendarPanel;
9
+//import timeflow.views.CalendarView.ScrollingCalendar;
10
+import timeflow.vis.Mouseover;
11
+import timeflow.vis.TimeScale;
12
+import timeflow.vis.VisualAct;
1013 import timeflow.vis.timeline.*;
1114
1215 import java.awt.*;
1316 import java.awt.event.*;
14
-import java.awt.image.*;
17
+//import java.awt.image.*;
1518
1619 import javax.swing.*;
1720
18
-import java.util.*;
21
+import java.util.ArrayList;
1922
2023 public class TimelineView extends AbstractView
2124 {
....@@ -67,12 +70,23 @@
6770
6871 // top part of grid: zoom buttons.
6972 ComponentCluster buttons = new ComponentCluster("Zoom");
70
- ImageIcon zoomOutIcon = new ImageIcon("images/zoom_out.gif");
71
- JButton zoomOut = new JButton(zoomOutIcon);
73
+ //ImageIcon zoomOutIcon = new ImageIcon("images/zoom_out.gif");
74
+ JButton zoomIn = new JButton("In 1/2X");
75
+ buttons.addContent(zoomIn);
76
+ zoomIn.addActionListener(new ActionListener()
77
+ {
78
+ @Override
79
+ public void actionPerformed(ActionEvent e)
80
+ {
81
+ Interval zoom = visuals.getViewInterval().subinterval(0.333, 0.667).intersection(visuals.getGlobalInterval());
82
+ moveTime(zoom);
83
+ }
84
+ });
85
+
86
+ JButton zoomOut = new JButton("Out 2X");
7287 buttons.addContent(zoomOut);
7388 zoomOut.addActionListener(new ActionListener()
7489 {
75
-
7690 @Override
7791 public void actionPerformed(ActionEvent e)
7892 {
....@@ -82,7 +96,7 @@
8296 });
8397
8498 ImageIcon zoomOut100Icon = new ImageIcon("images/zoom_out_100.gif");
85
- JButton zoomOutAll = new JButton(zoomOut100Icon);
99
+ JButton zoomOutAll = new JButton("Fit 100%");
86100 buttons.addContent(zoomOutAll);
87101 zoomOutAll.addActionListener(new ActionListener()
88102 {
....@@ -221,17 +235,27 @@
221235
222236 public void run()
223237 {
224
- int n = 15;
238
+ int n = 8;
225239 for (int i = 0; i < n; i++)
226240 {
227
- long start = ((n - i) * i1.start + i * i2.start) / n;
228
- long end = ((n - i) * i1.end + i * i2.end) / n;
241
+ final long start = ((n - i) * i1.start + i * i2.start) / n;
242
+ final long end = ((n - i) * i1.end + i * i2.end) / n;
229243 try
230244 {
231
- visuals.setTimeBounds(start, end);
232
- redraw();
245
+// visuals.setTimeBounds(start, end);
246
+// redraw();
247
+ SwingUtilities.invokeAndWait(new Runnable()
248
+ {
249
+
250
+ @Override
251
+ public void run()
252
+ {
253
+ visuals.setTimeBounds(start, end);
254
+ redraw();
255
+ }
256
+ });
233257
234
- sleep(20);
258
+ //sleep(20);
235259 } catch (Exception e)
236260 {
237261 }
....@@ -312,7 +336,20 @@
312336 {
313337 if (e.getClickCount() == 2)
314338 {
315
- moveTime(visuals.getViewInterval().subinterval(.333, .667));
339
+ Point p = new Point(e.getX(), e.getY());
340
+ Mouseover o = find(p);
341
+ //moveTime(visuals.getViewInterval().subinterval(.333, .667));
342
+ boolean onAct = o != null && o.thing instanceof VisualAct;
343
+ if (onAct)
344
+ {
345
+ VisualAct v = (VisualAct) o.thing;
346
+ selectedAct = v.getAct();
347
+ EditRecordPanel.edit(getModel(), selectedAct);
348
+ } else
349
+ {
350
+ selectedTime = getTime(p);
351
+ EditRecordPanel.add(getModel(), selectedTime);
352
+ }
316353 }
317354 }
318355
....@@ -358,6 +395,11 @@
358395 int a = firstMouse.x;
359396 int b = mouse.x;
360397
398
+ if (a == b)
399
+ {
400
+ return;
401
+ }
402
+
361403 long start = visuals.getTimeScale().toTime(a);
362404 long end = visuals.getTimeScale().toTime(b);
363405 if (b - a < 0)
....@@ -397,12 +439,18 @@
397439 @Override
398440 public void mouseWheelMoved(MouseWheelEvent e)
399441 {
400
- //bar.setValue(bar.getValue() + e.getWheelRotation() * 10);
401
- visuals.scale *= Math.exp(e.getWheelRotation()/10.0);
402
- visuals.scale = visuals.layout();
403
- //System.out.println(visuals.scale);
404
- timelinePanel.drawVisualization();
405
- scroller.calibrate();
442
+ if (e.isMetaDown())
443
+ {
444
+ visuals.scale *= Math.exp(e.getWheelRotation()/10.0);
445
+ visuals.scale = visuals.layout();
446
+ //System.out.println(visuals.scale);
447
+ timelinePanel.drawVisualization();
448
+ scroller.calibrate();
449
+ }
450
+ else
451
+ {
452
+ bar.setValue(bar.getValue() + e.getWheelRotation() * 40);
453
+ }
406454 repaint();
407455 }
408456 });