source: trunk/autoquest-core-usability-evaluation-test/src/main/java/de/ugoe/cs/autoquest/usability/sandboxapp/CreateClickstreamImageFromTaskTreeDemoApp.java @ 1040

Last change on this file since 1040 was 1040, checked in by adeicke, 11 years ago
  • Removed lombok related annotations and util class
  • Added comments and formating due to match project defaults
  • Property svn:mime-type set to text/plain
File size: 3.5 KB
Line 
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
15package de.ugoe.cs.autoquest.usability.sandboxapp;
16
17import static de.ugoe.cs.autoquest.usability.tasktree.filter.EventTypeFilter.MOUSE_BUTTON_INTERACTION;
18
19import java.awt.Color;
20import java.awt.Graphics2D;
21import java.awt.RenderingHints;
22import java.awt.image.BufferedImage;
23import java.io.File;
24import java.io.IOException;
25
26import javax.imageio.ImageIO;
27
28import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction;
29import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
30import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
31import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
32import de.ugoe.cs.autoquest.usability.tasktree.filter.FilterStatistic;
33import de.ugoe.cs.autoquest.usability.tasktree.filter.IterativeDFSFilterStrategy;
34import de.ugoe.cs.autoquest.usability.tasktree.filter.TaskTreeFilter;
35import de.ugoe.cs.autoquest.usability.testutil.GenerateTaskTreeUtil;
36
37/**
38 * <p>
39 * TODO comment
40 * </p>
41 *
42 * @author Alexander Deicke
43 */
44public 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}
Note: See TracBrowser for help on using the repository browser.