Normand Briere
2019-04-22 a9e12f6c508810604c8c91ee15451776b08ce1a1
timeflow/views/TimelineView.java
....@@ -1,21 +1,25 @@
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
+
9
+//import timeflow.views.CalendarView.CalendarPanel;
10
+//import timeflow.views.CalendarView.ScrollingCalendar;
11
+import timeflow.vis.Mouseover;
12
+import timeflow.vis.TimeScale;
13
+import timeflow.vis.VisualAct;
1014 import timeflow.vis.timeline.*;
1115
1216 import java.awt.*;
1317 import java.awt.event.*;
14
-import java.awt.image.*;
18
+//import java.awt.image.*;
1519
1620 import javax.swing.*;
1721
18
-import java.util.*;
22
+import java.util.ArrayList;
1923
2024 public class TimelineView extends AbstractView
2125 {
....@@ -34,9 +38,10 @@
3438 return controls;
3539 }
3640
37
- public TimelineView(TFModel model)
41
+ public TimelineView(TimeflowModel model)
3842 {
3943 super(model);
44
+
4045 visuals = new TimelineVisuals(model);
4146 grid = new AxisRenderer(visuals);
4247 timeline = new TimelineRenderer(visuals);
....@@ -52,27 +57,39 @@
5257
5358 TimelineSlider slider = new TimelineSlider(visuals, 24 * 60 * 60 * 1000L, new Runnable()
5459 {
55
-
5660 @Override
5761 public void run()
5862 {
5963 redraw();
6064 }
6165 });
66
+
6267 bottom.add(slider, BorderLayout.CENTER);
6368
6469 controls = new JPanel();
65
- controls.setBackground(Color.white);
70
+ controls.setBackground(Color.red);
6671 controls.setLayout(new BorderLayout());//new GridLayout(2,1));
6772
6873 // top part of grid: zoom buttons.
6974 ComponentCluster buttons = new ComponentCluster("Zoom");
70
- ImageIcon zoomOutIcon = new ImageIcon("images/zoom_out.gif");
71
- JButton zoomOut = new JButton(zoomOutIcon);
75
+
76
+ //ImageIcon zoomOutIcon = new ImageIcon("images/zoom_out.gif");
77
+ JButton zoomIn = new JButton("In 1/2X");
78
+ buttons.addContent(zoomIn);
79
+ zoomIn.addActionListener(new ActionListener()
80
+ {
81
+ @Override
82
+ public void actionPerformed(ActionEvent e)
83
+ {
84
+ Interval zoom = visuals.getViewInterval().subinterval(0.333, 0.667).intersection(visuals.getGlobalInterval());
85
+ moveTime(zoom);
86
+ }
87
+ });
88
+
89
+ JButton zoomOut = new JButton("Out 2X");
7290 buttons.addContent(zoomOut);
7391 zoomOut.addActionListener(new ActionListener()
7492 {
75
-
7693 @Override
7794 public void actionPerformed(ActionEvent e)
7895 {
....@@ -82,7 +99,7 @@
8299 });
83100
84101 ImageIcon zoomOut100Icon = new ImageIcon("images/zoom_out_100.gif");
85
- JButton zoomOutAll = new JButton(zoomOut100Icon);
102
+ JButton zoomOutAll = new JButton("Fit 100%");
86103 buttons.addContent(zoomOutAll);
87104 zoomOutAll.addActionListener(new ActionListener()
88105 {
....@@ -109,7 +126,7 @@
109126 moveTime(visuals.getFitToVisibleRange());
110127 }});
111128 */
112
- controls.add(buttons, BorderLayout.NORTH);
129
+ controls.add(buttons, BorderLayout.SOUTH);
113130
114131 // ok, now do second part of grid: layout style buttons.
115132 ComponentCluster layoutPanel = new ComponentCluster("Layout");
....@@ -137,7 +154,7 @@
137154 graph.addActionListener(new LayoutSetter(TimelineVisuals.Layout.GRAPH));
138155 layoutGroup.add(graph);
139156
140
- controls.add(layoutPanel, BorderLayout.CENTER);
157
+ //controls.add(layoutPanel, BorderLayout.CENTER);
141158 }
142159
143160 class LayoutSetter implements ActionListener
....@@ -221,17 +238,27 @@
221238
222239 public void run()
223240 {
224
- int n = 15;
241
+ int n = 8;
225242 for (int i = 0; i < n; i++)
226243 {
227
- long start = ((n - i) * i1.start + i * i2.start) / n;
228
- long end = ((n - i) * i1.end + i * i2.end) / n;
244
+ final long start = ((n - i) * i1.start + i * i2.start) / n;
245
+ final long end = ((n - i) * i1.end + i * i2.end) / n;
229246 try
230247 {
231
- visuals.setTimeBounds(start, end);
232
- redraw();
248
+// visuals.setTimeBounds(start, end);
249
+// redraw();
250
+ SwingUtilities.invokeAndWait(new Runnable()
251
+ {
252
+
253
+ @Override
254
+ public void run()
255
+ {
256
+ visuals.setTimeBounds(start, end);
257
+ redraw();
258
+ }
259
+ });
233260
234
- sleep(20);
261
+ //sleep(20);
235262 } catch (Exception e)
236263 {
237264 }
....@@ -301,7 +328,7 @@
301328
302329 class TimelinePanel extends AbstractVisualizationView
303330 {
304
- public TimelinePanel(TFModel model)
331
+ public TimelinePanel(TimeflowModel model)
305332 {
306333 super(model);
307334
....@@ -312,7 +339,20 @@
312339 {
313340 if (e.getClickCount() == 2)
314341 {
315
- moveTime(visuals.getViewInterval().subinterval(.333, .667));
342
+ Point p = new Point(e.getX(), e.getY());
343
+ Mouseover o = find(p);
344
+ //moveTime(visuals.getViewInterval().subinterval(.333, .667));
345
+ boolean onAct = o != null && o.thing instanceof VisualAct;
346
+ if (onAct)
347
+ {
348
+ VisualAct v = (VisualAct) o.thing;
349
+ selectedAct = v.getAct();
350
+ EditRecordPanel.edit(getModel(), selectedAct);
351
+ } else
352
+ {
353
+ selectedTime = getTime(p);
354
+ EditRecordPanel.add(getModel(), selectedTime);
355
+ }
316356 }
317357 }
318358
....@@ -358,6 +398,11 @@
358398 int a = firstMouse.x;
359399 int b = mouse.x;
360400
401
+ if (a == b)
402
+ {
403
+ return;
404
+ }
405
+
361406 long start = visuals.getTimeScale().toTime(a);
362407 long end = visuals.getTimeScale().toTime(b);
363408 if (b - a < 0)
....@@ -397,12 +442,18 @@
397442 @Override
398443 public void mouseWheelMoved(MouseWheelEvent e)
399444 {
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();
445
+ if (e.isMetaDown())
446
+ {
447
+ visuals.scale *= Math.exp(e.getWheelRotation()/10.0);
448
+ visuals.scale = visuals.layout();
449
+ //System.out.println(visuals.scale);
450
+ timelinePanel.drawVisualization();
451
+ scroller.calibrate();
452
+ }
453
+ else
454
+ {
455
+ bar.setValue(bar.getValue() + e.getWheelRotation() * 40);
456
+ }
406457 repaint();
407458 }
408459 });