[sikuli] 349/385: added more options to the highlight frame color option and added java doc
Gilles Filippini
pini at moszumanska.debian.org
Sun Jun 29 19:26:35 UTC 2014
This is an automated email from the git hooks/post-receive script.
pini pushed a commit to tag upstream/1.1.0_beta1
in repository sikuli.
commit 6a01e5efaac8b12092cf422c8a29c32be1249f73
Author: Raimund Hocke <rmhdevelop at me.com>
Date: Thu Apr 10 10:25:42 2014 +0200
added more options to the highlight frame color option and added java doc
---
API/src/main/java/org/sikuli/script/Region.java | 18 +++++---
.../java/org/sikuli/script/ScreenHighlighter.java | 53 +++++++++++++++++-----
2 files changed, 53 insertions(+), 18 deletions(-)
diff --git a/API/src/main/java/org/sikuli/script/Region.java b/API/src/main/java/org/sikuli/script/Region.java
index c236cc4..968b3a6 100644
--- a/API/src/main/java/org/sikuli/script/Region.java
+++ b/API/src/main/java/org/sikuli/script/Region.java
@@ -1731,9 +1731,15 @@ public class Region {
}
/**
- * Toggle the regions Highlight visibility (frame of specified color)
- *
- * @param color Color of frame
+ * Toggle the regions Highlight visibility (frame of specified color)<br />
+ * allowed color specifications for frame color: <br />
+ * - a color name out of: black, blue, cyan, gray, green, magenta, orange, pink, red, white, yellow
+ * (lowercase and uppercase can be mixed, internally transformed to all uppercase) <br />
+ * - these colornames exactly written: lightGray, LIGHT_GRAY, darkGray and DARK_GRAY <br />
+ * - a hex value like in HTML: #XXXXXX (max 6 hex digits)
+ * - an RGB specification as: #rrrgggbbb where rrr, ggg, bbb are integer values in range 0 - 255
+ * padded with leading zeros if needed (hence exactly 9 digits)
+ * @param color Color of frame
* @return the region itself
*/
public Region highlight(String color) {
@@ -1746,7 +1752,7 @@ public class Region {
* Sets the regions Highlighting border
*
* @param toEnable set overlay enabled or disabled
- * @param color Color of frame
+ * @param color Color of frame (see method highlight(color))
*/
private Region highlight(boolean toEnable, String color) {
if (isOtherScreen()) {
@@ -1783,7 +1789,7 @@ public class Region {
* if 0 - use the global Settings.SlowMotionDelay
*
* @param secs time in seconds
- * @param color Color of frame
+ * @param color Color of frame (see method highlight(color))
* @return the region itself
*/
public Region highlight(float secs, String color) {
@@ -1816,7 +1822,7 @@ public class Region {
* Show highlight in selected color
*
* @param secs time in seconds
- * @param color Color of frame
+ * @param color Color of frame (see method highlight(color))
* @return this region
*/
public Region highlight(int secs, String color) {
diff --git a/API/src/main/java/org/sikuli/script/ScreenHighlighter.java b/API/src/main/java/org/sikuli/script/ScreenHighlighter.java
index 5691e34..1849acf 100644
--- a/API/src/main/java/org/sikuli/script/ScreenHighlighter.java
+++ b/API/src/main/java/org/sikuli/script/ScreenHighlighter.java
@@ -16,13 +16,12 @@ import java.util.Set;
import java.lang.reflect.Field;
/**
- * INTERNAL USE
- * produces and manages the red framed rectangles from Region.highlight()
+ * INTERNAL USE produces and manages the red framed rectangles from Region.highlight()
*/
public class ScreenHighlighter extends OverlayTransparentWindow implements MouseListener {
static Color _transparentColor = new Color(0F, 0F, 0F, 0.5F);
- Color _targetColor;
+ Color _targetColor = Color.RED;
final static int TARGET_SIZE = 50;
final static int DRAGGING_TIME = 200;
static int MARGIN = 20;
@@ -48,15 +47,45 @@ public class ScreenHighlighter extends OverlayTransparentWindow implements Mouse
setVisible(false);
setAlwaysOnTop(true);
- // Attempt to set the color of the frame to what the user provided.
- // If it fails, set to red. Valid colors are the ones defined in the Color class:
- // http://docs.oracle.com/javase/7/docs/api/java/awt/Color.html#field_summary
- try {
- Field field = Class.forName("java.awt.Color").getField(color);
- _targetColor = (Color)field.get(null);
- } catch (Exception e) {
- // Set to standard red color
- _targetColor = new Color(1F, 0F, 0F, 0.7F);
+ if (color != null) {
+ // a frame color is specified
+ // if not decodable, then predefined Color.RED is used
+ if (color.startsWith("#")) {
+ if (color.length() > 7) {
+ // might be the version #nnnnnnnnn
+ if (color.length() == 10) {
+ int cR = 255, cG = 0, cB = 0;
+ try {
+ cR = Integer.decode(color.substring(1, 4));
+ cG = Integer.decode(color.substring(4, 7));
+ cB = Integer.decode(color.substring(7, 10));
+ } catch (NumberFormatException ex) {
+ }
+ try {
+ _targetColor = new Color(cR, cG, cB);
+ } catch (IllegalArgumentException ex) {
+ }
+ }
+ } else {
+ // supposing it is a hex value
+ try {
+ _targetColor = new Color(Integer.decode(color));
+ } catch (NumberFormatException nex) {
+ }
+ }
+ } else {
+ // supposing color contains one of the defined color names
+ if (!color.endsWith("Gray") || "Gray".equals(color)) {
+ // the name might be given with any mix of lower/upper-case
+ // only lightGray, LIGHT_GRAY, darkGray and DARK_GRAY must be given exactly
+ color = color.toUpperCase();
+ }
+ try {
+ Field field = Class.forName("java.awt.Color").getField(color);
+ _targetColor = (Color) field.get(null);
+ } catch (Exception e) {
+ }
+ }
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/sikuli.git
More information about the pkg-java-commits
mailing list