Class Operator

java.lang.Object
org.netbeans.jemmy.operators.Operator
All Implemented Interfaces:
Outputable, Timeoutable
Direct Known Subclasses:
ComponentOperator

public abstract class Operator extends Object implements Timeoutable, Outputable
Keeps all environment and low-level methods.
Author:
Alexandre Iline (alexandre.iline@sun.com)
  • Field Details

  • Constructor Details

    • Operator

      public Operator()
      Inits environment.
  • Method Details

    • setDefaultComponentVisualizer

      public static Operator.ComponentVisualizer setDefaultComponentVisualizer(Operator.ComponentVisualizer visualizer)
      Specifies an object to be used by default to prepare component. Each new operator created after the method using will have defined visualizer. Default implementation is org.netbeans.jemmy.util.DefaultVisualizer class.
      Parameters:
      visualizer - ComponentVisualizer implementation
      Returns:
      previous value
      See Also:
    • getDefaultComponentVisualizer

      public static Operator.ComponentVisualizer getDefaultComponentVisualizer()
      Returns an object to be used by default to prepare component.
      Returns:
      Object is used by default to prepare component
      See Also:
    • setDefaultStringComparator

      public static Operator.StringComparator setDefaultStringComparator(Operator.StringComparator comparator)
      Defines string comparator to be assigned in constructor.
      Parameters:
      comparator - the comparator to be used by default.
      Returns:
      previous value.
      See Also:
    • getDefaultStringComparator

      public static Operator.StringComparator getDefaultStringComparator()
      Returns string comparator used to init operators.
      Returns:
      the comparator used by default.
      See Also:
    • setDefaultPathParser

      public static Operator.PathParser setDefaultPathParser(Operator.PathParser parser)
      Specifies an object used for parsing of path-like strings.
      Parameters:
      parser - the parser.
      Returns:
      a previous value.
      See Also:
    • getDefaultPathParser

      public static Operator.PathParser getDefaultPathParser()
      Returns an object used for parsing of path-like strings.
      Returns:
      a parser used by default.
      See Also:
    • setDefaultVerification

      public static boolean setDefaultVerification(boolean verification)
      Defines weither newly created operators should perform operation verifications by default.
      Parameters:
      verification - a verification mode to be used by default.
      Returns:
      a prevoius value.
      See Also:
    • getDefaultVerification

      public static boolean getDefaultVerification()
      Says weither newly created operators perform operations verifications by default.
      Returns:
      a verification mode used by default.
      See Also:
    • isCaptionEqual

      public static boolean isCaptionEqual(String caption, String match, boolean ce, boolean ccs)
      Deprecated.
      use another methods with the same name.
      Compares caption (button text, window title, ...) with a sample text.
      Parameters:
      caption - String to be compared with match. Method returns false, if parameter is null.
      match - Sample to compare with. Method returns true, if parameter is null.
      ce - Compare exactly. If true, text can be a substring of caption.
      ccs - Compare case sensitively. If true, both text and caption are converted to upper case before comparison.
      Returns:
      true is the captions matched the match.
      See Also:
    • isCaptionEqual

      public static boolean isCaptionEqual(String caption, String match, Operator.StringComparator comparator)
      Compares caption (button text, window title, ...) with a sample text.
      Parameters:
      caption - String to be compared with match
      match - Sample to compare with
      comparator - StringComparator instance.
      Returns:
      true is the captions matched the match.
      See Also:
    • getDefaultMouseButton

      public static int getDefaultMouseButton()
      Returns default mouse button mask.
      Returns:
      InputEvent.BUTTON*_MASK field value
    • getPopupMouseButton

      public static int getPopupMouseButton()
      Returns mask of mouse button which used to popup expanding. (InputEvent.BUTTON3_MASK)
      Returns:
      InputEvent.BUTTON*_MASK field value
    • createOperator

      public static ComponentOperator createOperator(Component comp)
      Creates operator for component. Tries to find class with "operator package"."class name"Operator name, where "operator package" is a package from operator packages list, and "class name" is the name of class or one of its superclasses.
      Parameters:
      comp - Component to create operator for.
      Returns:
      a new operator with default environment.
      See Also:
    • addOperatorPackage

      public static void addOperatorPackage(String pkgName)
      Adds package to the list of packages containing operators.
      "org.netbeans.jemmy.operators" is in the list by default.
      Parameters:
      pkgName - Package name.
      See Also:
    • getEnvironmentOperator

      public static Operator getEnvironmentOperator()
      Returns an operator containing default environment.
      Returns:
      an empty operator (not having any component source) having default environment.
    • getSource

      public abstract Component getSource()
      Returns object operator is used for.
      Returns:
      an instance of java.awt.Component subclass which this operator was created for.
    • getQueueTool

      public QueueTool getQueueTool()
      Returns QueueTool is used to work with queue.
      Returns:
      a QueueTool.
    • copyEnvironment

      public void copyEnvironment(Operator anotherOperator)
      Copies all environment (output, timeouts, visualizer) from another operator.
      Parameters:
      anotherOperator - an operator to copy the environment to.
    • setTimeouts

      public void setTimeouts(Timeouts timeouts)
      Description copied from interface: Timeoutable
      Defines current timeouts.
      Specified by:
      setTimeouts in interface Timeoutable
      Parameters:
      timeouts - A collection of timeout assignments.
      See Also:
    • getTimeouts

      public Timeouts getTimeouts()
      Description copied from interface: Timeoutable
      Return current timeouts.
      Specified by:
      getTimeouts in interface Timeoutable
      Returns:
      the collection of current timeout assignments.
      See Also:
    • getVisualizer

      public Operator.ComponentVisualizer getVisualizer()
      Returns component visualizer. Visualizer is used from from makeComponentVisible() method.
      Returns:
      a visualizer assigned to this operator.
      See Also:
    • setVisualizer

      public void setVisualizer(Operator.ComponentVisualizer vo)
      Changes component visualizer. Visualizer is used from from makeComponentVisible() method.
      Parameters:
      vo - a visualizer to assign to this operator.
      See Also:
    • getProperties

      public JemmyProperties getProperties()
      Returns a JemmyProperty object assigned to this operator.
      Returns:
      a JemmyProperty object got from the top of property stack or from another operator by copyuing environment.
      See Also:
    • setProperties

      public JemmyProperties setProperties(JemmyProperties properties)
      Assigns a JemmyProperty object to this operator.
      Parameters:
      properties - a properties to assign to this operator.
      Returns:
      previously assigned properties.
      See Also:
    • setCharBindingMap

      public void setCharBindingMap(CharBindingMap map)
      Defines CharBindingMap.
      Parameters:
      map - a CharBindingMap to use for keyboard operations.
      See Also:
    • getCharBindingMap

      public CharBindingMap getCharBindingMap()
      Returns CharBindingMap used for keyboard operations.
      Returns:
      a map assigned to this object.
      See Also:
    • setOutput

      public void setOutput(TestOut out)
      Description copied from interface: Outputable
      Defines print output streams or writers.
      Specified by:
      setOutput in interface Outputable
      Parameters:
      out - Identify the streams or writers used for print output.
      See Also:
    • getOutput

      public TestOut getOutput()
      Description copied from interface: Outputable
      Returns print output streams or writers.
      Specified by:
      getOutput in interface Outputable
      Returns:
      an object that contains references to objects for printing to output and err streams.
      See Also:
    • getComparator

      public Operator.StringComparator getComparator()
      Returns object which is used for string comparison.
      Returns:
      a comparator assigned to this operator.
      See Also:
    • setComparator

      public void setComparator(Operator.StringComparator comparator)
      Defines object which is used for string comparison.
      Parameters:
      comparator - a comparator to use for string comparision.
      See Also:
    • getPathParser

      public Operator.PathParser getPathParser()
      Returns object which is used for parsing of path-like strings.
      Returns:
      a comparator assigned to this operator.
      See Also:
    • setPathParser

      public void setPathParser(Operator.PathParser parser)
      Specifies object which is used for parsing of path-like strings.
      Parameters:
      parser - a parser to use for path parsing.
      See Also:
    • setVerification

      public boolean setVerification(boolean verification)
      Defines weither operator should perform operation verifications.
      Parameters:
      verification - new value.
      Returns:
      old value
      See Also:
    • getVerification

      public boolean getVerification()
      Says weither operator performs operation verifications.
      Returns:
      old value
      See Also:
    • getParentPath

      public String[] getParentPath(String[] path)
      Creates new array which has all elements from first array, except last element.
      Parameters:
      path - an original array
      Returns:
      new array
    • getParentPath

      public ComponentChooser[] getParentPath(ComponentChooser[] path)
    • parseString

      public String[] parseString(String path)
      Parses a string to a string array using a PathParser assigned to this operator.
      Parameters:
      path - an original string
      Returns:
      created String array.
    • parseString

      public String[] parseString(String path, String delim)
      Parses strings like "1|2|3" into arrays {"1", "2", "3"}.
      Parameters:
      path - an original string
      delim - a delimiter string
      Returns:
      created String array.
    • getCharKey

      public int getCharKey(char c)
      Returns key code to be pressed for character typing.
      Parameters:
      c - Character to be typed.
      Returns:
      a value of one of the KeyEvent.VK_* fields.
      See Also:
    • getCharModifiers

      public int getCharModifiers(char c)
      Returns modifiers mask for character typing.
      Parameters:
      c - Character to be typed.
      Returns:
      a combination of InputEvent.*_MASK fields.
      See Also:
    • getCharsKeys

      public int[] getCharsKeys(char[] c)
      Returns key codes to by pressed for characters typing.
      Parameters:
      c - Characters to be typed.
      Returns:
      an array of KeyEvent.VK_* values.
      See Also:
    • getCharsModifiers

      public int[] getCharsModifiers(char[] c)
      Returns modifiers masks for characters typing.
      Parameters:
      c - Characters to be typed.
      Returns:
      an array of a combination of InputEvent.*_MASK fields.
      See Also:
    • getCharsKeys

      public int[] getCharsKeys(String s)
      Returns key codes to by pressed for the string typing.
      Parameters:
      s - String to be typed.
      Returns:
      an array of KeyEvent.VK_* values.
      See Also:
    • getCharsModifiers

      public int[] getCharsModifiers(String s)
      Returns modifiers masks for the string typing.
      Parameters:
      s - String to be typed.
      Returns:
      an array of a combination of InputEvent.*_MASK fields.
      See Also:
    • isCaptionEqual

      public boolean isCaptionEqual(String caption, String match)
      Compares string using getComparator StringComparator.
      Parameters:
      caption - a caption
      match - a pattern
      Returns:
      true if caption and match match
      See Also:
    • printDump

      public void printDump()
      Prints component information into operator output.
    • getDump

      public Hashtable getDump()
      Returns information about component. All records marked by simbolic constants defined in public static final *_DPROP fields for each operator type.
      Returns:
      a Hashtable containing name-value pairs.
    • waitState

      public void waitState(ComponentChooser state)
      Waits a state specified by a ComponentChooser instance.
      Parameters:
      state - a ComponentChooser defining the state criteria.
      Throws:
      TimeoutExpiredException - if the state has not achieved in a value defined by "ComponentOperator.WaitStateTimeout"
    • produceTimeRestricted

      protected Object produceTimeRestricted(Action action, Object param, long wholeTime)
      Performs an operation with time control.
      Parameters:
      action - an action to execute.
      param - an action parameters.
      wholeTime - a time for the action to be finished.
      Returns:
      an action result.
    • produceTimeRestricted

      protected Object produceTimeRestricted(Action action, long wholeTime)
      Performs an operation with time control.
      Parameters:
      action - an action to execute.
      wholeTime - a time for the action to be finished.
      Returns:
      an action result.
    • produceNoBlocking

      protected void produceNoBlocking(Operator.NoBlockingAction action, Object param)
      Performs an operation without time control.
      Parameters:
      action - an action to execute.
      param - an action parameters.
    • produceNoBlocking

      protected void produceNoBlocking(Operator.NoBlockingAction action)
      Performs an operation without time control.
      Parameters:
      action - an action to execute.
    • lockQueue

      protected void lockQueue()
      Equivalent to getQueue().lock();.
    • unlockQueue

      protected void unlockQueue()
      Equivalent to getQueue().unlock();.
    • unlockAndThrow

      protected void unlockAndThrow(Exception e)
      Unlocks Queue and then throw exception.
      Parameters:
      e - an exception to be thrown.
    • runMapping

      protected Object runMapping(Operator.MapAction action)
      To map nonprimitive type component's method.
      Parameters:
      action - a mapping action.
      Returns:
      an action result.
      See Also:
    • runMapping

      protected char runMapping(Operator.MapCharacterAction action)
      To map char component's method.
      Parameters:
      action - a mapping action.
      Returns:
      an action result.
      See Also:
    • runMapping

      protected byte runMapping(Operator.MapByteAction action)
      To map byte component's method.
      Parameters:
      action - a mapping action.
      Returns:
      an action result.
      See Also:
    • runMapping

      protected int runMapping(Operator.MapIntegerAction action)
      To map int component's method.
      Parameters:
      action - a mapping action.
      Returns:
      an action result.
      See Also:
    • runMapping

      protected long runMapping(Operator.MapLongAction action)
      To map long component's method.
      Parameters:
      action - a mapping action.
      Returns:
      an action result.
      See Also:
    • runMapping

      protected float runMapping(Operator.MapFloatAction action)
      To map float component's method.
      Parameters:
      action - a mapping action.
      Returns:
      an action result.
      See Also:
    • runMapping

      protected double runMapping(Operator.MapDoubleAction action)
      To map double component's method.
      Parameters:
      action - a mapping action.
      Returns:
      an action result.
      See Also:
    • runMapping

      protected boolean runMapping(Operator.MapBooleanAction action)
      To map boolean component's method.
      Parameters:
      action - a mapping action.
      Returns:
      an action result.
      See Also:
    • runMapping

      protected void runMapping(Operator.MapVoidAction action)
      To map void component's method.
      Parameters:
      action - a mapping action.
      See Also:
    • addToDump

      protected String[] addToDump(Hashtable table, String title, Object[] items)
      Adds array of objects to dump hashtable. Is used for multiple properties such as list items and tree nodes.
      Parameters:
      table - a table to add properties to.
      title - property names prefix. Property names are constructed by adding a number to the prefix: title + "_" + Iteger.toString("ordinal index")
      items - an array of property values.
      Returns:
      an array of property names (with added numbers).
    • addToDump

      protected String[] addToDump(Hashtable table, String title, Object[][] items)
      Adds two dimentional array of objects to dump hashtable. Is used for multiple properties such as table cells.
      Parameters:
      table - a table to add properties to.
      title - property names prefix. Property names are constructed by adding two numbers to the prefix: title + "_" + Iteger.toString("row index") + "_" + Iteger.toString("column index")
      items - an array of property values.
      Returns:
      an array of property names (with added numbers).
    • toStringSource

      public String toStringSource()
      Returns toString() result from component of this operator. It calls getSource().toString() in dispatch thread.
      Returns:
      toString() result from component of this operator.