2
* Copyright (c) 2005-2010 Substance Kirill Grouchnikov. All Rights Reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
7
* o Redistributions of source code must retain the above copyright notice,
8
* this list of conditions and the following disclaimer.
10
* o Redistributions in binary form must reproduce the above copyright notice,
11
* this list of conditions and the following disclaimer in the documentation
12
* and/or other materials provided with the distribution.
14
* o Neither the name of Substance Kirill Grouchnikov nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
package tools.docrobot;
32
import java.awt.Graphics;
33
import java.awt.Point;
34
import java.awt.image.BufferedImage;
36
import java.io.IOException;
38
import javax.imageio.ImageIO;
39
import javax.swing.ImageIcon;
40
import javax.swing.JButton;
41
import javax.swing.JFrame;
43
import org.fest.swing.core.BasicRobot;
44
import org.fest.swing.core.Robot;
45
import org.fest.swing.edt.GuiActionRunner;
46
import org.fest.swing.edt.GuiQuery;
47
import org.fest.swing.edt.GuiTask;
48
import org.fest.swing.timing.Pause;
49
import org.pushingpixels.substance.api.DecorationAreaType;
50
import org.pushingpixels.substance.api.SubstanceLookAndFeel;
51
import org.pushingpixels.substance.api.SubstanceSkin;
52
import org.pushingpixels.substance.internal.utils.SubstanceImageCreator;
54
import test.check.SampleFrame;
57
* The base class for taking screenshots of skins for Substance documentation.
59
* @author Kirill Grouchnikov
61
public abstract class SkinRobot {
63
* The associated Substance skin.
65
protected SubstanceSkin skin;
68
* The screenshot filename.
70
protected String screenshotFilename;
75
protected SampleFrame sf;
78
* Creates the new screenshot robot.
82
* @param screenshotFilename
83
* The screenshot filename.
85
public SkinRobot(SubstanceSkin skin, String screenshotFilename) {
87
this.screenshotFilename = screenshotFilename;
91
* Runs the screenshot process.
94
long start = System.currentTimeMillis();
96
Robot robot = BasicRobot.robotWithNewAwtHierarchy();
99
GuiActionRunner.execute(new GuiTask() {
101
protected void executeInEDT() throws Throwable {
102
SubstanceLookAndFeel.setSkin(skin);
103
JFrame.setDefaultLookAndFeelDecorated(true);
108
// create the frame and set the icon image
109
GuiActionRunner.execute(new GuiTask() {
111
protected void executeInEDT() throws Throwable {
112
sf = new SampleFrame();
113
sf.setIconImage(SubstanceImageCreator.getColorSchemeImage(null,
114
new ImageIcon(SkinRobot.class.getClassLoader()
116
"test/resource/image-x-generic.png")),
117
SubstanceLookAndFeel.getCurrentSkin(sf.getRootPane())
118
.getActiveColorScheme(
119
DecorationAreaType.PRIMARY_TITLE_PANE),
121
sf.setSize(338, 245);
122
sf.setLocationRelativeTo(null);
123
sf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
129
// get the default button
130
JButton defaultButton = GuiActionRunner
131
.execute(new GuiQuery<JButton>() {
133
protected JButton executeInEDT() throws Throwable {
134
return sf.getRootPane().getDefaultButton();
137
// and move the mouse to it
138
robot.moveMouse(defaultButton);
144
// make the first screenshot
145
GuiActionRunner.execute(new GuiTask() {
147
protected void executeInEDT() throws Throwable {
153
// switch to the last tab
154
GuiActionRunner.execute(new GuiTask() {
156
protected void executeInEDT() throws Throwable {
157
sf.switchToLastTab();
162
// move the mouse away from the frame
163
robot.moveMouse(new Point(0, 0));
166
// wait for two seconds
169
// make the second screenshot
170
GuiActionRunner.execute(new GuiTask() {
172
protected void executeInEDT() throws Throwable {
179
GuiActionRunner.execute(new GuiTask() {
181
protected void executeInEDT() throws Throwable {
187
long end = System.currentTimeMillis();
188
System.out.println(this.getClass().getSimpleName() + " : "
189
+ (end - start) + "ms");
193
* Creates the screenshot and saves it on the disk.
196
* Sequence number for the screenshot.
198
public void makeScreenshot(int count) {
199
BufferedImage bi = new BufferedImage(sf.getWidth(), sf.getHeight(),
200
BufferedImage.TYPE_INT_ARGB);
201
Graphics g = bi.getGraphics();
204
File output = new File(this.screenshotFilename + count + ".png");
205
output.getParentFile().mkdirs();
206
ImageIO.write(bi, "png", output);
207
} catch (IOException ioe) {
208
ioe.printStackTrace();