Coverage Report - org.openpermis.editor.policy.gui.SmartConstraints
 
Classes in this File Line Coverage Branch Coverage Complexity
SmartConstraints
0%
0/28
N/A
1
 
 1  
 /*
 2  
  * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport
 3  
  *                     (http://www.vbs.admin.ch)
 4  
  * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch)
 5  
  * All rights reserved.
 6  
  *
 7  
  * Licensed under the Open Permis License which accompanies this distribution,
 8  
  * and is available at http://www.openpermis.org/BSDlicenceKent.txt
 9  
  */
 10  
 package org.openpermis.editor.policy.gui;
 11  
 
 12  
 import com.jgoodies.forms.layout.CellConstraints;
 13  
 
 14  
 
 15  
 /**
 16  
  * Smarter version of {@link CellConstraints} that holds the current locataion.
 17  
  * @since 0.3.0
 18  
  */
 19  
 public class SmartConstraints {
 20  
 
 21  
         //---- State
 22  
         
 23  
         /**
 24  
          * The actual cell constraints object used.
 25  
          * @since 0.3.0
 26  
          */
 27  
         private final CellConstraints cellConstraints;
 28  
 
 29  
         /**
 30  
          * The initial x coordinate to reset to.
 31  
          * @since 0.3.0
 32  
          */
 33  
         private int initialX;
 34  
         
 35  
         /**
 36  
          * The current x coordinate.
 37  
          * @since 0.3.0
 38  
          */
 39  
         private int x;
 40  
         
 41  
         /**
 42  
          * The current y coordinate.
 43  
          * @since 0.3.0
 44  
          */
 45  
         private int y;
 46  
         
 47  
         //---- Constructors
 48  
         
 49  
         /**
 50  
          * Returns a new smart constraints object starting at <tt>(1, 1)</tt>.
 51  
          * <p>The initial x coordinate is also set to <tt>1</tt>.</p>
 52  
          * @since 0.3.0
 53  
          */
 54  
         public SmartConstraints () {
 55  0
                 this(1, 1);
 56  0
         }
 57  
         
 58  
         /**
 59  
          * Creates a new smart constraints object with the specified initial coordinates.
 60  
          * @param x the x coordinate, also serves as initial x coordinate.
 61  
          * @param y the y coordinate.
 62  
          * @since 0.3.0
 63  
          */
 64  0
         public SmartConstraints (int x, int y) {
 65  0
                 this.cellConstraints = new CellConstraints();
 66  0
                 this.initialX = x;
 67  0
                 this.x = x;
 68  0
                 this.y = y;
 69  0
         }
 70  
         
 71  
         //---- Methods
 72  
         
 73  
         /**
 74  
          * Resets the smart constraints to the specified coordinates.
 75  
          * <p>The x coordinate also server as initial x coordinate.</p>
 76  
          * @param startX the x coordinate, also serves as initial x coordinate.
 77  
          * @param startY the y coordinate.
 78  
          * @since 0.3.0
 79  
          */
 80  
         public void reset (int startX, int startY) {
 81  0
                 this.initialX = startX;
 82  0
                 this.x = startX;
 83  0
                 this.y = startY;
 84  0
         }
 85  
         
 86  
         /**
 87  
          * Returns a cell constraints with the current location and a width and height of one.
 88  
          * <p>The x coordinate is incremented by the specified offset once the constraints are 
 89  
          * determined, the y coordinate is left untouched.</p>
 90  
          * @param offsetX the x coordinate offset.
 91  
          * @return the cell constraints requested.
 92  
          * @since 0.3.0
 93  
          */
 94  
         public CellConstraints x (int offsetX) {
 95  0
                 final int curX = this.x;
 96  0
                 this.x += offsetX;
 97  0
                 return this.cellConstraints.xy(curX, this.y);
 98  
         }
 99  
         
 100  
         /**
 101  
          * Returns a cell constraints with the current location, the specified width and height of one.
 102  
          * <p>The x coordinate is incremented by the specified offset once the constraints are 
 103  
          * determined, the y coordinate is left untouched.</p>
 104  
          * @param offsetX the x coordinate offset.
 105  
          * @param width the width of the cell constraint returned.
 106  
          * @return the cell constraints requested.
 107  
          * @since 0.3.0
 108  
          */
 109  
         public CellConstraints xw (int offsetX, int width) {
 110  0
                 final int curX = this.x;
 111  0
                 this.x += offsetX;
 112  0
                 return this.cellConstraints.xyw(curX, this.y, width);
 113  
         }
 114  
         
 115  
         /**
 116  
          * Returns a cell constraints with the current location and a width and height of one.
 117  
          * <p>The x coordinate is reset to the initial value and the y coordinate is incremented by
 118  
          * the specified offset once the constraints are determined.</p>
 119  
          * @param offsetY the y coordinate offset.
 120  
          * @return the cell constraints requested.
 121  
          * @since 0.3.0
 122  
          */
 123  
         public CellConstraints y (int offsetY) {
 124  0
                 final int curX = this.x;
 125  0
                 final int curY = this.y;
 126  0
                 this.x = this.initialX;
 127  0
                 this.y += offsetY;
 128  0
                 return this.cellConstraints.xy(curX, curY);
 129  
         }
 130  
         
 131  
         /**
 132  
          * Returns a cell constraints with the current location and a width and height of one.
 133  
          * <p>The x coordinate is reset to the initial value and the y coordinate is incremented by
 134  
          * the specified offset once the constraints are determined.</p>
 135  
          * @param offsetY the y coordinate offset.
 136  
          * @param width the width of the cell constraint returned.
 137  
          * @return the cell constraints requested.
 138  
          * @since 0.3.0
 139  
          */
 140  
         public CellConstraints yw (int offsetY, int width) {
 141  0
                 final int curX = this.x;
 142  0
                 final int curY = this.y;
 143  0
                 this.x = this.initialX;
 144  0
                 this.y += offsetY;
 145  0
                 return this.cellConstraints.xyw(curX, curY, width);
 146  
         }
 147  
         
 148  
 }