Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8090469

Provide contains methods which are independent of the current graphical appearance of a shape.

XMLWordPrintable

      I recently examined whether I could use JavaFX for a GIS application.
      One of the main tasks of this application is the display and selection
      of lots of shapes on top of a map. Here I will concentrate on the
      selection aspect.

      I found this to be problematic because in practice there are many
      possible shape selection policies and JavaFX just supports one
      and there is currently no way to change this easily. If you e.g.,
      want to select a shape on the screen via mouse click, the standard
      procedure is to attach a corresponding mouse event handler to each
      shape. If you then click the mouse button the system will then
      call this handler if the mouse pointer was over one of the shapes.

      So far so good - but there are a few problems:

      What happens when your shapes overlap, assuming they are translucent?
      What if you would want to select all shapes under the mouse pointer?
      What if you want to select very thin lines?

      Unfortunately the standard selection mechanism is strictly bound to
      the current visual appearance of a shape and cannot be changed.
      Additionally the system will only select the topmost shape and
      all other shapes below it will not be considered. For many
      applications this is not practical.

      In our application we have for example the following selection rule.
      If the user clicks the mouse, all shapes below the mouse pointer
      are considered as candidates for the selection. If this returns just
      one shape then the selection is unique and accepted. If however
      there is more than one candidate, the user can make this selection
      unique by moving the mouse closer to the inner border of a shape.
      If the selection has been made unique this way it will be accepted.

      A similar technique is also used to select thin lines. It is sufficient
      to be at a predefined distance to a line in order to select it (if the
      selection is unique) whereas JavaFX forces you to exactly hit the line
      which is very difficult for thin lines.

      I tried to implement this logic in JavaFX but found that to be
      difficult because there is no configurable selection mechanism.
      What is missing is a "Node.contains" method which can be configured
      and used independently of the current graphical appearance of a
      shape.

      I have provided a demo application (SelectionDemo4) to better show
      what I mean. The methods that I would like to be part of JavaFX
      are the public methods in ShapeUtils (fillContains and strokeContains).
      (The private methods are only copied there because I could not
      otherwise access them.)

      The demo application shows some overlapping shapes. You can select
      any of these shapes independently of their display order when you
      click on it with the mouse and the selection is unique. This is
      indicated by the color of the border of the shape. The border is
      black by default. If the selection is unique, the border turns
      green and if it is not unique the border will be red.

      This is just one example but I am sure there are many more
      use-cases where you need a more flexible selection mechanism.

        1. SelectionDemo4.java
          7 kB
          Dr. Michael Paus
        2. ShapeUtils.java
          3 kB
          Dr. Michael Paus

            Unassigned Unassigned
            dpausjfx Dr. Michael Paus (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Imported: