[rfc][icedtea-web] AWTHelper small modification
Jiri Vanek
jvanek at redhat.com
Thu May 2 06:40:49 PDT 2013
Yup. Give more sense. Thank you.
J.
On 05/02/2013 11:46 AM, Jana Fabrikova wrote:
> Hi, thank you for the comments, I have refactored the AWTHelper class
> more, completely getting rid of the unnecessary variable initStrGiven
> and the new patch is in the attachment.
>
> ChangeLog:
>
> 2013-05-02 Jana Fabrikova<jfabriko at redhat.com>
>
> * tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java:
> refactoring - removing initStrGiven variable - now it only
> matters if the initStr is null or not. Modifying the following
> two methods: (charReaded) - if initStr is null the run method
> can not be started from charReaded and the presence of initStr
> is not checked in stdout. Method (getInitStrAsRule) returns rule
> that is always true if initStr is null.
>
> cheers,
> Jana
>
> On Wed, 2013-05-01 at 14:06 +0200, Jiri Vanek wrote:
>> >On 04/30/2013 06:04 PM, Jana Fabrikova wrote:
>>> > >Hello, I am sending only a small modification to the file AWTHelper,
>>> > >part of AWTFramework, in dealing with an initialisation string (it can
>>> > >be null or given),
>>> > >thanks for any comments,
>>> > >Jana
>>> > >
>>> > >
>>> > >ChangeLog:
>>> > >
>>> > >2013-04-30 Jana Fabrikova<jfabriko at redhat.com>
>>> > >
>>> > > * tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java:
>>> > > modifying the (charrReaded) method
>>> > >
>>> > >
>>> > >modifying_AWTHelper_null_initStr.patch
>>> > >
>> >Hmm this does not seems to be correct.
>> >a) This should allow awt helper to work with null "magic string"
>> >b) this should allow awt helper to run without need of magic string.
>> >
>> >The (a) looks nearly ok, but I'm confused by initStrGiven variable. It jus disappeared from condition. So it is not needed any more? Then please remove it.
>> >Or have it just slipped from condition accidentally?
>> >
>> >for (b) I'm not sure if it is enough - is it?
>>> > >
>>> > >diff -r 3fa3d0fdce30 tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java
>>> > >--- a/tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java Tue Apr 30 11:31:28 2013 -0400
>>> > >+++ b/tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java Tue Apr 30 18:00:55 2013 +0200
>>> > >@@ -60,7 +60,7 @@
>>> > > public abstract class AWTHelper extends RulesFolowingClosingListener implements Runnable{
>>> > >
>>> > > //attributes possibly set by user
>>> > >- private String initStr = "";
>>> > >+ private String initStr = null;
>>> > > private Color appletColor;
>>> > > private BufferedImage marker;
>>> > > private Point markerPosition;
>>> > >@@ -171,6 +171,7 @@
>>> > > } catch (IOException e) {
>>> > > throw new RuntimeException("AWTHelper could not read marker.png.",e);
>>> > > }
>>> > >+
>>> > >
>>> > > this.appletWidth = appletWidth;
>>> > > this.appletHeight = appletHeight;
>>> > >@@ -206,7 +207,7 @@
>>> > > public void charReaded(char ch) {
>>> > > sb.append(ch);
>>> > > //is applet ready to start clicking?
>>> > >- if (initStrGiven&& !actionStarted&& appletIsReady(sb.toString())) {
>>> > >+ if ((initStr != null)&& !actionStarted&& appletIsReady(sb.toString())) {
>> >also pelase keep code according to rules - spaces on both sides of logical operators
>> >
>>> > > try{
>>> > > actionStarted = true;
>>> > > this.findAndActivateApplet();
>> >
>> >Thank you for keeping teh awt helper classes more usable - it was not possible without second person to try it.
>> >
>> > Thank you
>> > J.
>
>
> modifying_AWTHelper_initStrnull.patch
>
>
> diff -r 0e4641f585bf tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java
> --- a/tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java Thu May 02 11:16:36 2013 +0200
> +++ b/tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java Thu May 02 11:37:45 2013 +0200
> @@ -60,7 +60,7 @@
> public abstract class AWTHelper extends RulesFolowingClosingListener implements Runnable{
>
> //attributes possibly set by user
> - private String initStr = "";
> + private String initStr = null;
> private Color appletColor;
> private BufferedImage marker;
> private Point markerPosition;
> @@ -75,7 +75,6 @@
> private BufferedImage screenshot;
> private Robot robot;
> private boolean appletFound = false;
> - private boolean initStrGiven = false; //impossible to find in the output if not given
> private boolean appletColorGiven = false; //impossible to search for color difference if not given
> private boolean markerGiven = false; //impossible to find the applet if marker not given
> private boolean appletDimensionGiven = false;
> @@ -117,7 +116,6 @@
> this();
>
> this.initStr = initStr;
> - this.initStrGiven = true;
> }
>
> /**
> @@ -148,7 +146,6 @@
> this(icon, iconPosition, appletWidth, appletHeight);
>
> this.initStr = initString;
> - this.initStrGiven = true;
> }
>
> /**
> @@ -176,7 +173,6 @@
> public AWTHelper(String initString, int appletWidth, int appletHeight){
> this(appletWidth, appletHeight);
> this.initStr = initString;
> - this.initStrGiven = true;
> }
>
> /**
> @@ -194,6 +190,8 @@
> * override of method charReaded (from RulesFolowingClosingListener)
> *
> * waiting for the applet, when applet is ready run action thread
> + * (if initStr==null, do not check and do not call run)
> + *
> * when all the wanted strings are in the stdout, applet can be closed
> *
> * @param ch
> @@ -202,7 +200,8 @@
> public void charReaded(char ch) {
> sb.append(ch);
> //is applet ready to start clicking?
> - if (initStrGiven && !actionStarted && appletIsReady(sb.toString())) {
> + //check and run applet only if initStr is not null
> + if ((initStr != null) && !actionStarted && appletIsReady(sb.toString())) {
> try{
> actionStarted = true;
> this.findAndActivateApplet();
> @@ -241,22 +240,43 @@
> * @return
> */
> public Rule getInitStrAsRule(){
> - return new ContainsRule(this.initStr);
> + if( initStr != null ){
> + return new ContainsRule(this.initStr);
> + }else{
> + return new Rule(){
> +
> + @Override
> + public void setRule(Object rule) {
> + }
> +
> + @Override
> + public boolean evaluate(Object upon) {
> + return true;
> + }
> +
> + @Override
> + public String toPassingString() {
> + return "nothing to check, initStr is null";
> + }
> +
> + @Override
> + public String toFailingString() {
> + return "nothing to check, initStr is null";
> + }
> +
> + } ;
> + }
> }
>
> //boolean controls getters
> protected boolean appletIsReady(String content) {
> - return (content.contains(initStr));
> + return this.getInitStrAsRule().evaluate(content);
> }
>
> public boolean isActionStarted() {
> return actionStarted;
> }
>
> - public boolean isInitStrGiven(){
> - return initStrGiven;
> - }
> -
> public boolean isAppletColorGiven(){
> return appletColorGiven;
> }
> @@ -292,7 +312,6 @@
>
> public void setInitStr(String initStr) {
> this.initStr = initStr;
> - this.initStrGiven = true;
> }
>
> public void setMarker(BufferedImage marker, Point markerPosition) {
>
More information about the distro-pkg-dev
mailing list