Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/trapezium/attractor/AttractorSelector.java


1   /*
2    * @(#)AttractorSelector.java
3    *
4    * Copyright (c) 1998 by Trapezium Development LLC.  All Rights Reserved.
5    *
6    * The information in this file is the property of Trapezium Development LLC
7    * and may be used only in accordance with the terms of the license granted
8    * by Trapezium.
9    *
10   */
11  package com.trapezium.attractor;
12  
13  /** The AttractorSelector or one of its subclasses is created by the
14   *  CoordAttractor factory method "createAttractorSelector".  It is used
15   *  to track the currently selected attractor as a floater is matched
16   *  one by one to each attractor.  Subclasses handle marking of the
17   *  preserved floaters in each attracted floater set.
18   *
19   *  @author          Johannes N. Johannsen
20   *  @version         1.0, 8 Oct 1998
21   *
22   *  @since           1.0
23   */
24  
25  public class AttractorSelector {
26      protected int selectedAttractor;
27      protected float selectionDistance;
28  
29      /** Class constructor */
30      public AttractorSelector() {
31          reset();
32      }
33  
34      /** Initialize the object, AttractorSelector reset each time matching
35       *  for a new floater is started.
36       */
37      public void reset() {
38          selectedAttractor = -1;
39          selectionDistance = 0f;
40      }
41  
42      /** Attempt the selection of a particular attractor.  Floaters are
43       *  attracted to the nearest attractor.
44       *
45       *  @param attractorOffset the attractor to attempt to select
46       *  @param distanceToFloater the distance for the "attractorOffset"
47       *     attractor to the floater
48       */
49      public void attemptAttractorSelection( int attractorOffset, 
50          float distanceToFloater ) {
51          if (( selectedAttractor == -1 ) ||
52              ( distanceToFloater < selectionDistance )) {
53              selectedAttractor = attractorOffset;
54              selectionDistance = distanceToFloater;
55          }
56      }
57  
58      /** Template, subclasses use this to mark preserved floaters in
59       *  the array parameters passed from the CoordAttractor.
60       */
61      public void updatePreservedInfo( int[] floaterOffsets,
62          float[] floaterDistances, int floaterOffset ) {
63      }
64  
65      /** Get the selected attractor offset */
66      public int getSelection() {
67          return( selectedAttractor );
68      }
69  }