1 | package de.ugoe.cs.autoquest.usability.sandboxapp;
|
---|
2 |
|
---|
3 | import static de.ugoe.cs.autoquest.usability.tasktree.filter.EventTypeFilter.MOUSE_BUTTON_INTERACTION;
|
---|
4 |
|
---|
5 | import java.awt.Color;
|
---|
6 | import java.awt.Graphics2D;
|
---|
7 | import java.awt.RenderingHints;
|
---|
8 | import java.awt.image.BufferedImage;
|
---|
9 | import java.io.File;
|
---|
10 | import java.io.IOException;
|
---|
11 |
|
---|
12 | import javax.imageio.ImageIO;
|
---|
13 |
|
---|
14 | import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction;
|
---|
15 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
|
---|
16 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
|
---|
17 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
|
---|
18 | import de.ugoe.cs.autoquest.usability.tasktree.filter.FilterStatistic;
|
---|
19 | import de.ugoe.cs.autoquest.usability.tasktree.filter.IterativeDFSFilterStrategy;
|
---|
20 | import de.ugoe.cs.autoquest.usability.tasktree.filter.TaskTreeFilter;
|
---|
21 | import de.ugoe.cs.autoquest.usability.testutil.GenerateTaskTreeUtil;
|
---|
22 |
|
---|
23 | public class CreateClickstreamImageFromTaskTreeDemoApp {
|
---|
24 |
|
---|
25 | private static final String fileToParse = "javatrace.xml";
|
---|
26 |
|
---|
27 | private static final String clickstreamFilename = "clickstream.png";
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * <p>
|
---|
31 | * TODO: comment
|
---|
32 | * </p>
|
---|
33 | *
|
---|
34 | * @param args
|
---|
35 | * @throws IOException
|
---|
36 | */
|
---|
37 | public static void main(String[] args) throws IOException {
|
---|
38 | ITaskTree taskTree = GenerateTaskTreeUtil.getTaskTreeFromFile(fileToParse);
|
---|
39 | FilterStatistic mouseInteractions = filterMouseInteractions(taskTree);
|
---|
40 |
|
---|
41 | BufferedImage clickstreamImage = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_ARGB);
|
---|
42 | Graphics2D drawArea = clickstreamImage.createGraphics();
|
---|
43 | drawArea.setColor(Color.BLACK);
|
---|
44 | drawArea.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
---|
45 |
|
---|
46 | drawClickstream(mouseInteractions, drawArea);
|
---|
47 |
|
---|
48 | ImageIO.write(clickstreamImage, "png", new File(clickstreamFilename));
|
---|
49 | }
|
---|
50 |
|
---|
51 | private static void drawClickstream(FilterStatistic mouseInteractions, Graphics2D g2) {
|
---|
52 | int xb = -1;
|
---|
53 | int yb = -1;
|
---|
54 |
|
---|
55 | for(ITaskTreeNode node : mouseInteractions.nodesMatchedFilter()) {
|
---|
56 | MouseButtonInteraction interaction = (MouseButtonInteraction) ((IEventTask) node).getEventType();
|
---|
57 | int x = interaction.getX();
|
---|
58 | int y = interaction.getY();
|
---|
59 | g2.fillOval(x,y,1,1);
|
---|
60 | if(xb != -1 && y != -1) g2.drawLine(x, y, xb, yb);
|
---|
61 | xb = x;
|
---|
62 | yb = y;
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | private static FilterStatistic filterMouseInteractions(ITaskTree taskTree) {
|
---|
67 | return new TaskTreeFilter(new IterativeDFSFilterStrategy())
|
---|
68 | .filterByEventType(MOUSE_BUTTON_INTERACTION).from(taskTree);
|
---|
69 | }
|
---|
70 |
|
---|
71 | }
|
---|