Initial
This commit is contained in:
commit
e2e5c283d3
73
build.xml
Normal file
73
build.xml
Normal file
@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||
<!-- the Compile on Save feature is turned off for the project. -->
|
||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||
<!-- in the project's Project Properties dialog box.-->
|
||||
<project name="Colorillo_Painter" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project Colorillo Painter.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar: JAR building
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="Colorillo_Painter-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
</project>
|
1419
nbproject/build-impl.xml
Normal file
1419
nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load Diff
8
nbproject/genfiles.properties
Normal file
8
nbproject/genfiles.properties
Normal file
@ -0,0 +1,8 @@
|
||||
build.xml.data.CRC32=a70e3604
|
||||
build.xml.script.CRC32=342e1232
|
||||
build.xml.stylesheet.CRC32=8064a381@1.79.0.48
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=a70e3604
|
||||
nbproject/build-impl.xml.script.CRC32=c795d3c0
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.0.48
|
2
nbproject/private/private.properties
Normal file
2
nbproject/private/private.properties
Normal file
@ -0,0 +1,2 @@
|
||||
compile.on.save=true
|
||||
user.properties.file=C:\\Users\\aNNiMON\\AppData\\Roaming\\NetBeans\\dev\\build.properties
|
12
nbproject/private/private.xml
Normal file
12
nbproject/private/private.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||
<group name="_TUTORIALS">
|
||||
<file>file:/C:/Users/aNNiMON/Documents/NetBeansProjects/_SAMPLES/Colorillo%20Painter/src/com/annimon/colorillopainter/DebugPanel.java</file>
|
||||
<file>file:/C:/Users/aNNiMON/Documents/NetBeansProjects/_SAMPLES/Colorillo%20Painter/src/com/annimon/colorillopainter/Main.java</file>
|
||||
<file>file:/C:/Users/aNNiMON/Documents/NetBeansProjects/_SAMPLES/Colorillo%20Painter/src/com/annimon/colorillopainter/CanvasBoard.java</file>
|
||||
<file>file:/C:/Users/aNNiMON/Documents/NetBeansProjects/_SAMPLES/Colorillo%20Painter/src/com/annimon/colorillopainter/ImagePainter.java</file>
|
||||
</group>
|
||||
</open-files>
|
||||
</project-private>
|
74
nbproject/project.properties
Normal file
74
nbproject/project.properties
Normal file
@ -0,0 +1,74 @@
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processor.options=
|
||||
annotation.processing.processors.list=
|
||||
annotation.processing.run.all.processors=true
|
||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||
build.classes.dir=${build.dir}/classes
|
||||
build.classes.excludes=**/*.java,**/*.form
|
||||
# This directory is removed when the project is cleaned:
|
||||
build.dir=build
|
||||
build.generated.dir=${build.dir}/generated
|
||||
build.generated.sources.dir=${build.dir}/generated-sources
|
||||
# Only compile against the classpath explicitly listed here:
|
||||
build.sysclasspath=ignore
|
||||
build.test.classes.dir=${build.dir}/test/classes
|
||||
build.test.results.dir=${build.dir}/test/results
|
||||
# Uncomment to specify the preferred debugger connection transport:
|
||||
#debug.transport=dt_socket
|
||||
debug.classpath=\
|
||||
${run.classpath}
|
||||
debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
# Files in build.classes.dir which should be excluded from distribution jar
|
||||
dist.archive.excludes=
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/Colorillo_Painter.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
excludes=
|
||||
includes=**
|
||||
jar.compress=false
|
||||
javac.classpath=
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
javac.external.vm=true
|
||||
javac.processorpath=\
|
||||
${javac.classpath}
|
||||
javac.source=1.8
|
||||
javac.target=1.8
|
||||
javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
javac.test.processorpath=\
|
||||
${javac.test.classpath}
|
||||
javadoc.additionalparam=
|
||||
javadoc.author=false
|
||||
javadoc.encoding=${source.encoding}
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
javadoc.private=false
|
||||
javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
main.class=com.annimon.colorillopainter.Main
|
||||
manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=false
|
||||
platform.active=default_platform
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
# Space-separated list of JVM arguments used when running the project.
|
||||
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
||||
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||
run.jvmargs=
|
||||
run.test.classpath=\
|
||||
${javac.test.classpath}:\
|
||||
${build.test.classes.dir}
|
||||
source.encoding=UTF-8
|
||||
src.dir=src
|
||||
test.src.dir=test
|
15
nbproject/project.xml
Normal file
15
nbproject/project.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>Colorillo Painter</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
80
src/com/annimon/colorillopainter/CanvasBoard.java
Normal file
80
src/com/annimon/colorillopainter/CanvasBoard.java
Normal file
@ -0,0 +1,80 @@
|
||||
package com.annimon.colorillopainter;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public final class CanvasBoard {
|
||||
|
||||
// (485, 170) -- (1283, 668)
|
||||
private static final int BOARD_X1 = 485, BOARD_Y1 = 170;
|
||||
private static final int BOARD_X2 = 1283, BOARD_Y2 = 668;
|
||||
|
||||
// ColorBox (375, 430) -- (430, 430)
|
||||
private static final int COLORBOX_X1 = 375, COLORBOX_Y1 = 430;
|
||||
private static final int COLORBOX_X2 = 430, COLORBOX_Y2 = 430;
|
||||
|
||||
private static final int DELAY = 105;
|
||||
private static final int BRUSH_SIZE = 1;
|
||||
private static final int OFFSET_X = 0;
|
||||
|
||||
private int lastColor;
|
||||
|
||||
public CanvasBoard() {
|
||||
lastColor = -1;
|
||||
}
|
||||
|
||||
public void drawPixel(int color, int x, int y) {
|
||||
if (color != lastColor) changeColor(color);
|
||||
|
||||
final int nx = convertX(x), ny = convertY(y);
|
||||
RobotUtils.getInstance().mouseMove(nx, ny);
|
||||
RobotUtils.getInstance().mousePressLong(MouseEvent.BUTTON1_MASK);
|
||||
RobotUtils.getInstance().delay(DELAY);
|
||||
RobotUtils.getInstance().mouseMove(nx, ny + 1);
|
||||
RobotUtils.getInstance().delay(DELAY);
|
||||
RobotUtils.getInstance().mousePressLongReset();
|
||||
}
|
||||
|
||||
public void changeColor(int color) {
|
||||
final int red = (color >> 16) & 0xFF;
|
||||
final int green = (color >> 8) & 0xFF;
|
||||
final int blue = color & 0xFF;
|
||||
|
||||
final StringBuilder sb = new StringBuilder(7);
|
||||
sb.append('#');
|
||||
if (red <= 0x0F) sb.append(0);
|
||||
sb.append(Integer.toHexString(red));
|
||||
if (green <= 0x0F) sb.append(0);
|
||||
sb.append(Integer.toHexString(green));
|
||||
if (blue <= 0x0F) sb.append(0);
|
||||
sb.append(Integer.toHexString(blue));
|
||||
|
||||
// Clear colorbox
|
||||
RobotUtils.getInstance().mouseMove(COLORBOX_X1, COLORBOX_Y1);
|
||||
RobotUtils.getInstance().mousePressLong(MouseEvent.BUTTON1_MASK);
|
||||
RobotUtils.getInstance().delay(DELAY);
|
||||
RobotUtils.getInstance().mouseMove(COLORBOX_X2, COLORBOX_Y2);
|
||||
RobotUtils.getInstance().delay(DELAY);
|
||||
RobotUtils.getInstance().mousePressLongReset();
|
||||
|
||||
// Type color
|
||||
RobotUtils.getInstance().writeMessage(sb.toString());
|
||||
|
||||
lastColor = color;
|
||||
}
|
||||
|
||||
private int convertX(int x) {
|
||||
final int result = BOARD_X1 + OFFSET_X + (x * BRUSH_SIZE);
|
||||
if (result > BOARD_X2) return BOARD_X2;
|
||||
return result;
|
||||
}
|
||||
|
||||
private int convertY(int y) {
|
||||
final int result = BOARD_Y1 + (y * BRUSH_SIZE);
|
||||
if (result > BOARD_Y2) return BOARD_Y2;
|
||||
return result;
|
||||
}
|
||||
}
|
84
src/com/annimon/colorillopainter/DebugPanel.form
Normal file
84
src/com/annimon/colorillopainter/DebugPanel.form
Normal file
@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="ySlider" min="-2" pref="25" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace min="-2" pref="11" max="-2" attributes="0"/>
|
||||
<Component id="xSlider" pref="344" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace min="-2" pref="89" max="-2" attributes="0"/>
|
||||
<Component id="infoLabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="checkButton" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="xSlider" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="checkButton" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="infoLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Component id="ySlider" pref="278" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JSlider" name="xSlider">
|
||||
<Properties>
|
||||
<Property name="maximum" type="int" value="2800"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JSlider" name="ySlider">
|
||||
<Properties>
|
||||
<Property name="maximum" type="int" value="1678"/>
|
||||
<Property name="orientation" type="int" value="1"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="checkButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Check"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="checkButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="infoLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="info"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
105
src/com/annimon/colorillopainter/DebugPanel.java
Normal file
105
src/com/annimon/colorillopainter/DebugPanel.java
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
*/
|
||||
package com.annimon.colorillopainter;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.GroupLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.LayoutStyle;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class DebugPanel extends javax.swing.JPanel {
|
||||
|
||||
/**
|
||||
* Creates new form DebugPanel
|
||||
*/
|
||||
public DebugPanel() {
|
||||
initComponents();
|
||||
xSlider.addChangeListener(e -> updateInfo());
|
||||
ySlider.addChangeListener(e -> updateInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to
|
||||
* initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is
|
||||
* always regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private void initComponents() {//GEN-BEGIN:initComponents
|
||||
|
||||
xSlider = new JSlider();
|
||||
ySlider = new JSlider();
|
||||
checkButton = new JButton();
|
||||
infoLabel = new JLabel();
|
||||
|
||||
xSlider.setMaximum(2800);
|
||||
|
||||
ySlider.setMaximum(1678);
|
||||
ySlider.setOrientation(JSlider.VERTICAL);
|
||||
|
||||
checkButton.setText("Check");
|
||||
checkButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
checkButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
infoLabel.setText("info");
|
||||
|
||||
GroupLayout layout = new GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(ySlider, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(11, 11, 11)
|
||||
.addComponent(xSlider, GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(89, 89, 89)
|
||||
.addComponent(infoLabel)
|
||||
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(checkButton)))
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(xSlider, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(checkButton)
|
||||
.addComponent(infoLabel)))
|
||||
.addComponent(ySlider, GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
);
|
||||
}//GEN-END:initComponents
|
||||
|
||||
private void checkButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_checkButtonActionPerformed
|
||||
final int x = xSlider.getValue();
|
||||
final int y = ySlider.getValue();
|
||||
RobotUtils.getInstance().mouseMove(x, y);
|
||||
}//GEN-LAST:event_checkButtonActionPerformed
|
||||
|
||||
private void updateInfo() {
|
||||
infoLabel.setText(String.format("x: %d, y: %d", xSlider.getValue(), ySlider.getValue()));
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private JButton checkButton;
|
||||
private JLabel infoLabel;
|
||||
private JSlider xSlider;
|
||||
private JSlider ySlider;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
80
src/com/annimon/colorillopainter/ImagePainter.java
Normal file
80
src/com/annimon/colorillopainter/ImagePainter.java
Normal file
@ -0,0 +1,80 @@
|
||||
package com.annimon.colorillopainter;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public final class ImagePainter {
|
||||
|
||||
|
||||
public static ImagePainter fromFile(String path) {
|
||||
try {
|
||||
return new ImagePainter( ImageIO.read(new File(path)) );
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException("Successfully failed to open image");
|
||||
}
|
||||
}
|
||||
|
||||
private final int width, height;
|
||||
private final int[] pixels;
|
||||
private final HashMap<Integer, List<Point>> colors;
|
||||
|
||||
private CanvasBoard canvas;
|
||||
|
||||
public ImagePainter(BufferedImage image) {
|
||||
width = image.getWidth();
|
||||
height = image.getHeight();
|
||||
pixels = new int[width * height];
|
||||
image.getRGB(0, 0, width, height, pixels, 0, width);
|
||||
|
||||
colors = new HashMap<>();
|
||||
scanPixels();
|
||||
}
|
||||
|
||||
private void scanPixels() {
|
||||
int index = 0;
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
final int color = pixels[index++];
|
||||
final List<Point> points;
|
||||
if (colors.containsKey(color)) {
|
||||
points = colors.get(color);
|
||||
} else {
|
||||
points = new ArrayList<>();
|
||||
colors.put(color, points);
|
||||
}
|
||||
points.add(new Point(x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCanvas(CanvasBoard canvas) {
|
||||
this.canvas = canvas;
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
colors.entrySet()
|
||||
.stream()
|
||||
.filter(entry -> {
|
||||
// Filter white and transparent color
|
||||
final int color = entry.getKey();
|
||||
if ( (color & 0xFFFFFF) == 0xFFFFFF) return false;
|
||||
if ( (color & 0xFFFFFF) == 0x000000) return false;
|
||||
final int alpha = (color >> 24) & 0xFF;
|
||||
return alpha == 0xFF;
|
||||
})
|
||||
.forEach(entry -> {
|
||||
final int color = entry.getKey();
|
||||
entry.getValue().forEach(point -> canvas.drawPixel(color, point.x, point.y));
|
||||
});
|
||||
}
|
||||
}
|
78
src/com/annimon/colorillopainter/Main.java
Normal file
78
src/com/annimon/colorillopainter/Main.java
Normal file
@ -0,0 +1,78 @@
|
||||
package com.annimon.colorillopainter;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
/**
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public final class Main extends JFrame {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Main().setVisible(true);
|
||||
}
|
||||
|
||||
private final CanvasBoard canvas;
|
||||
private final ImagePainter painter;
|
||||
|
||||
public Main() {
|
||||
super("Colorillo Painter");
|
||||
|
||||
setLocation(50, 130);
|
||||
setPreferredSize(new Dimension(300, 200));
|
||||
setAlwaysOnTop(true);
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
addWindowFocusListener(new WindowAdapter() {
|
||||
|
||||
private int counter = 0;
|
||||
|
||||
@Override
|
||||
public void windowGainedFocus(WindowEvent e) {
|
||||
super.windowGainedFocus(e);
|
||||
counter++;
|
||||
System.out.println("focus " + counter);
|
||||
if (counter == 6) {
|
||||
RobotUtils.getInstance().mousePressLongReset();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
JButton start = new JButton("Start");
|
||||
start.addActionListener(e -> new Thread(this::onStart).start());
|
||||
|
||||
add(start);
|
||||
// add(new DebugPanel());
|
||||
pack();
|
||||
|
||||
canvas = new CanvasBoard();
|
||||
painter = ImagePainter.fromFile("E:/ext_road_day.png");
|
||||
painter.setCanvas(canvas);
|
||||
}
|
||||
|
||||
private void onStart() {
|
||||
colorillo();
|
||||
}
|
||||
|
||||
private void colorillo() {
|
||||
// Canvas (485, 170) -- (1283, 668)
|
||||
// ColorBox (375, 430) -- (430, 430)
|
||||
// for(int x = 0; x < 50; x++)
|
||||
// canvas.drawPixel(0xFF0000, x, 0);
|
||||
// for(int x = 0; x < 50; x++)
|
||||
// canvas.drawPixel(0x00FF00, x, 10);
|
||||
painter.draw();
|
||||
}
|
||||
|
||||
private void postToTwitchChat() {
|
||||
RobotUtils.getInstance().mouseMove(2668, 800);
|
||||
RobotUtils.getInstance().mousePress(MouseEvent.BUTTON1_MASK);
|
||||
RobotUtils.getInstance().writeMessage("IT WORKS");
|
||||
RobotUtils.getInstance().mouseMove(2768, 860);
|
||||
RobotUtils.getInstance().mousePress(MouseEvent.BUTTON1_MASK);
|
||||
}
|
||||
}
|
122
src/com/annimon/colorillopainter/RobotUtils.java
Normal file
122
src/com/annimon/colorillopainter/RobotUtils.java
Normal file
@ -0,0 +1,122 @@
|
||||
package com.annimon.colorillopainter;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
/**
|
||||
* Work with Robot class.
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class RobotUtils {
|
||||
|
||||
private static RobotUtils instance;
|
||||
|
||||
public static synchronized RobotUtils getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new RobotUtils();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
private static final int CLICK_DELAY = 100;
|
||||
private static final int PRESS_DELAY = 112;
|
||||
private Robot robot;
|
||||
|
||||
private int code1, code2, code3, button1;
|
||||
|
||||
public RobotUtils() {
|
||||
try {
|
||||
robot = new Robot();
|
||||
} catch (AWTException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void delay(int time) {
|
||||
robot.delay(time);
|
||||
}
|
||||
|
||||
public void keyPress(int code) {
|
||||
robot.keyPress(code);
|
||||
robot.delay(PRESS_DELAY);
|
||||
robot.keyRelease(code);
|
||||
}
|
||||
|
||||
public void keyPressLong(int code1, int code2, int code3) {
|
||||
this.code1 = code1;
|
||||
this.code2 = code2;
|
||||
this.code3 = code3;
|
||||
|
||||
if (code1 != 0) robot.keyPress(code1);
|
||||
if (code2 != 0) robot.keyPress(code2);
|
||||
if (code3 != 0) robot.keyPress(code3);
|
||||
}
|
||||
|
||||
public void keyPressLongReset() {
|
||||
if (code1 != 0) robot.keyRelease(code1);
|
||||
if (code2 != 0) robot.keyRelease(code2);
|
||||
if (code3 != 0) robot.keyRelease(code3);
|
||||
|
||||
this.code1 = 0;
|
||||
this.code2 = 0;
|
||||
this.code3 = 0;
|
||||
}
|
||||
|
||||
public void mouseMove(int x, int y) {
|
||||
robot.mouseMove(x, y);
|
||||
}
|
||||
|
||||
public void mousePress(int button) {
|
||||
int mask = convertMouseButtonToMask(button);
|
||||
robot.mousePress(mask);
|
||||
robot.delay(CLICK_DELAY);
|
||||
robot.mouseRelease(mask);
|
||||
}
|
||||
|
||||
public void mousePressLong(int button) {
|
||||
this.button1 = button;
|
||||
|
||||
robot.mousePress(convertMouseButtonToMask(button));
|
||||
}
|
||||
|
||||
public void mousePressLongReset() {
|
||||
robot.mouseRelease(convertMouseButtonToMask(button1));
|
||||
this.button1 = 0;
|
||||
}
|
||||
|
||||
public void writeMessage(String text) {
|
||||
for (char symbol : text.toCharArray()) {
|
||||
boolean needShiftPress = Character.isUpperCase(symbol) && Character.isLetter(symbol);
|
||||
int symbolIndex = "+!@#$%^&*()_".indexOf(symbol);
|
||||
if (needShiftPress || (symbolIndex != -1)) {
|
||||
robot.keyPress(KeyEvent.VK_SHIFT);
|
||||
robot.delay(PRESS_DELAY);
|
||||
}
|
||||
if (symbolIndex != -1) {
|
||||
symbol = (char) ('0' + symbolIndex);
|
||||
}
|
||||
int event = KeyEvent.getExtendedKeyCodeForChar(symbol);
|
||||
try {
|
||||
robot.keyPress(event);
|
||||
} catch (Exception e) {}
|
||||
robot.delay(PRESS_DELAY);
|
||||
try {
|
||||
robot.keyRelease(event);
|
||||
} catch (Exception e) {}
|
||||
if (needShiftPress || (symbolIndex != -1)) {
|
||||
robot.delay(PRESS_DELAY);
|
||||
robot.keyRelease(KeyEvent.VK_SHIFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int convertMouseButtonToMask(int button) {
|
||||
if (button == 1) return MouseEvent.BUTTON1_MASK; // left
|
||||
if (button == 3) return MouseEvent.BUTTON2_MASK; // center
|
||||
if (button == 2) return MouseEvent.BUTTON3_MASK; // right
|
||||
return button;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user