[1040] | 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 |
|
---|
[1030] | 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 |
|
---|
[1040] | 37 | /**
|
---|
| 38 | * <p>
|
---|
| 39 | * TODO comment
|
---|
| 40 | * </p>
|
---|
| 41 | *
|
---|
| 42 | * @author Alexander Deicke
|
---|
| 43 | */
|
---|
[1030] | 44 | public class CreateClickstreamImageFromTaskTreeDemoApp {
|
---|
| 45 |
|
---|
| 46 | private static final String fileToParse = "javatrace.xml";
|
---|
[1040] | 47 |
|
---|
[1030] | 48 | private static final String clickstreamFilename = "clickstream.png";
|
---|
[1040] | 49 |
|
---|
[1030] | 50 | /**
|
---|
| 51 | * <p>
|
---|
| 52 | * TODO: comment
|
---|
| 53 | * </p>
|
---|
[1040] | 54 | *
|
---|
[1030] | 55 | * @param args
|
---|
[1040] | 56 | * @throws IOException
|
---|
[1030] | 57 | */
|
---|
| 58 | public static void main(String[] args) throws IOException {
|
---|
| 59 | ITaskTree taskTree = GenerateTaskTreeUtil.getTaskTreeFromFile(fileToParse);
|
---|
| 60 | FilterStatistic mouseInteractions = filterMouseInteractions(taskTree);
|
---|
[1040] | 61 |
|
---|
[1030] | 62 | BufferedImage clickstreamImage = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_ARGB);
|
---|
| 63 | Graphics2D drawArea = clickstreamImage.createGraphics();
|
---|
| 64 | drawArea.setColor(Color.BLACK);
|
---|
[1040] | 65 | drawArea.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
---|
| 66 | RenderingHints.VALUE_ANTIALIAS_ON);
|
---|
| 67 |
|
---|
[1030] | 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;
|
---|
[1040] | 76 |
|
---|
| 77 | for (ITaskTreeNode node : mouseInteractions.nodesMatchedFilter()) {
|
---|
| 78 | MouseButtonInteraction interaction =
|
---|
| 79 | (MouseButtonInteraction) ((IEventTask) node).getEventType();
|
---|
[1030] | 80 | int x = interaction.getX();
|
---|
| 81 | int y = interaction.getY();
|
---|
[1040] | 82 | g2.fillOval(x, y, 1, 1);
|
---|
| 83 | if (xb != -1 && y != -1)
|
---|
| 84 | g2.drawLine(x, y, xb, yb);
|
---|
[1030] | 85 | xb = x;
|
---|
| 86 | yb = y;
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
[1040] | 89 |
|
---|
[1030] | 90 | private static FilterStatistic filterMouseInteractions(ITaskTree taskTree) {
|
---|
| 91 | return new TaskTreeFilter(new IterativeDFSFilterStrategy())
|
---|
| 92 | .filterByEventType(MOUSE_BUTTON_INTERACTION).from(taskTree);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | }
|
---|