1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
2 | //
|
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
4 | // you may not use this file except in compliance with the License.
|
---|
5 | // You may obtain a copy of the License at
|
---|
6 | //
|
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
8 | //
|
---|
9 | // Unless required by applicable law or agreed to in writing, software
|
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
12 | // See the License for the specific language governing permissions and
|
---|
13 | // limitations under the License.
|
---|
14 |
|
---|
15 | package de.ugoe.cs.autoquest.usability.sandboxapp;
|
---|
16 |
|
---|
17 | import static de.ugoe.cs.autoquest.usability.tasktree.filter.EventTypeFilter.MOUSE_BUTTON_INTERACTION;
|
---|
18 |
|
---|
19 | import java.awt.Color;
|
---|
20 | import java.awt.Graphics2D;
|
---|
21 | import java.awt.RenderingHints;
|
---|
22 | import java.awt.image.BufferedImage;
|
---|
23 | import java.io.File;
|
---|
24 | import java.io.IOException;
|
---|
25 |
|
---|
26 | import javax.imageio.ImageIO;
|
---|
27 |
|
---|
28 | import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction;
|
---|
29 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
|
---|
30 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
|
---|
31 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
|
---|
32 | import de.ugoe.cs.autoquest.usability.tasktree.filter.FilterStatistic;
|
---|
33 | import de.ugoe.cs.autoquest.usability.tasktree.filter.IterativeDFSFilterStrategy;
|
---|
34 | import de.ugoe.cs.autoquest.usability.tasktree.filter.TaskTreeFilter;
|
---|
35 | import de.ugoe.cs.autoquest.usability.testutil.GenerateTaskTreeUtil;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * <p>
|
---|
39 | * TODO comment
|
---|
40 | * </p>
|
---|
41 | *
|
---|
42 | * @author Alexander Deicke
|
---|
43 | */
|
---|
44 | public class CreateClickstreamImageFromTaskTreeDemoApp {
|
---|
45 |
|
---|
46 | private static final String fileToParse = "javatrace.xml";
|
---|
47 |
|
---|
48 | private static final String clickstreamFilename = "clickstream.png";
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * <p>
|
---|
52 | * TODO: comment
|
---|
53 | * </p>
|
---|
54 | *
|
---|
55 | * @param args
|
---|
56 | * @throws IOException
|
---|
57 | */
|
---|
58 | public static void main(String[] args) throws IOException {
|
---|
59 | ITaskTree taskTree = GenerateTaskTreeUtil.getTaskTreeFromFile(fileToParse);
|
---|
60 | FilterStatistic mouseInteractions = filterMouseInteractions(taskTree);
|
---|
61 |
|
---|
62 | BufferedImage clickstreamImage = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_ARGB);
|
---|
63 | Graphics2D drawArea = clickstreamImage.createGraphics();
|
---|
64 | drawArea.setColor(Color.BLACK);
|
---|
65 | drawArea.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
---|
66 | RenderingHints.VALUE_ANTIALIAS_ON);
|
---|
67 |
|
---|
68 | drawClickstream(mouseInteractions, drawArea);
|
---|
69 |
|
---|
70 | ImageIO.write(clickstreamImage, "png", new File(clickstreamFilename));
|
---|
71 | }
|
---|
72 |
|
---|
73 | private static void drawClickstream(FilterStatistic mouseInteractions, Graphics2D g2) {
|
---|
74 | int xb = -1;
|
---|
75 | int yb = -1;
|
---|
76 |
|
---|
77 | for (ITaskTreeNode node : mouseInteractions.nodesMatchedFilter()) {
|
---|
78 | MouseButtonInteraction interaction =
|
---|
79 | (MouseButtonInteraction) ((IEventTask) node).getEventType();
|
---|
80 | int x = interaction.getX();
|
---|
81 | int y = interaction.getY();
|
---|
82 | g2.fillOval(x, y, 1, 1);
|
---|
83 | if (xb != -1 && y != -1)
|
---|
84 | g2.drawLine(x, y, xb, yb);
|
---|
85 | xb = x;
|
---|
86 | yb = y;
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | private static FilterStatistic filterMouseInteractions(ITaskTree taskTree) {
|
---|
91 | return new TaskTreeFilter(new IterativeDFSFilterStrategy())
|
---|
92 | .filterByEventType(MOUSE_BUTTON_INTERACTION).from(taskTree);
|
---|
93 | }
|
---|
94 |
|
---|
95 | }
|
---|