Changeset 1513


Ignore:
Timestamp:
02/19/20 15:29:48 (4 years ago)
Author:
bnemhaus
Message:

You now have the ability to anchor Items to the center of the frame. AnchorCenterX: 0 will anchor a item directly to the vertical center of the frame. AnchorCenterY: 0 to the horizontal center of the frame. Negative numbers go left/up from the center, positive numbers right/down.

More work to come to deal with connected items such as rectangles made up on connected dots.

Location:
trunk/src/org/expeditee
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/core/Anchoring.java

    r1097 r1513  
    44
    55/**
    6  * Class for anchoring the position of items within the frame.
    7  * Anchoring is when the position of the item is defined relative
    8  * to the edge of the frame instead of being defined in absolute
    9  * coordinates. Can't be anchored to the left and right edge at
    10  * the same time, nor the top and bottom edge at the same time.
     6 * Class for anchoring the position of items within the frame. Anchoring is when
     7 * the position of the item is defined relative to the edge of the frame instead
     8 * of being defined in absolute coordinates. Can't be anchored to the left and
     9 * right edge at the same time, nor the top and bottom edge at the same time.
    1110 *
    1211 * @author cts16
    1312 */
    1413public class Anchoring {
     14       
     15        private enum VerticalDirection { left, center, right }
     16        private enum HorizontalDirection { top, center, bottom }
    1517
    16         /** The relative distance from the left or right edge (null means unanchored). */
     18        /**
     19         * The relative distance from the left, center or right edge (null means unanchored).
     20         */
    1721        private Integer _xAnchor = null;
    18         /** The relative distance from the top or bottom edge (null means unanchored). */
     22        /**
     23         * The relative distance from the top, center or bottom edge (null means unanchored).
     24         */
    1925        private Integer _yAnchor = null;
     26
    2027        /** Whether the x-anchor is relative to the left or right edge. */
    21         private boolean _left = true;
     28        private VerticalDirection verticalDirection = VerticalDirection.left;
    2229        /** Whether the y-anchor is relative to the top or bottom edge. */
    23         private boolean _top = true;
    24        
    25         public Anchoring()
    26         {
     30        private HorizontalDirection horizonalDirection = HorizontalDirection.top;
     31
     32        public Anchoring() {
    2733        }
    2834       
    29         public void setXAnchor(Integer offset, boolean left)
    30         {
    31                 _xAnchor = offset;
    32                 _left = left;
     35        public void setXAnchor(Anchoring other) {
     36                if (other == null) {
     37                        return;
     38                }
     39               
     40                setXAnchor(other._xAnchor, other.verticalDirection);
     41        }
     42
     43        public void setYAnchor(Anchoring other) {
     44                if (other == null)
     45                        return;
     46
     47                setYAnchor(other._yAnchor, other.horizonalDirection);
     48        }
     49
     50        public void setLeftAnchor(Integer offset) {
     51                setXAnchor(offset, VerticalDirection.left);
    3352        }
    3453       
    35         public void setYAnchor(Integer offset, boolean top)
    36         {
    37                 _yAnchor = offset;
    38                 _top = top;
     54        public void setCenterXAnchor(Integer offset) {
     55                setXAnchor(offset, VerticalDirection.center);
     56        }
     57
     58        public void setRightAnchor(Integer offset) {
     59                setXAnchor(offset, VerticalDirection.right);
     60        }
     61
     62        public void setTopAnchor(Integer offset) {
     63                setYAnchor(offset, HorizontalDirection.top);
    3964        }
    4065       
    41         public void setXAnchor(Anchoring other)
    42         {
    43                 if (other == null) return;
    44                
    45                 setXAnchor(other._xAnchor, other._left);
     66        public void setCenterYAnchor(Integer offset) {
     67                setYAnchor(offset, HorizontalDirection.center);
    4668        }
    4769
    48         public void setYAnchor(Anchoring other)
    49         {
    50                 if (other == null) return;
    51                
    52                 setYAnchor(other._yAnchor, other._top);
     70        public void setBottomAnchor(Integer offset) {
     71                setYAnchor(offset, HorizontalDirection.bottom);
    5372        }
    5473       
    55         public void setLeftAnchor(Integer offset)
    56         {
    57                 setXAnchor(offset, true);
     74        public void removeXAnchor() {
     75                setXAnchor(null, verticalDirection);
    5876        }
    59        
    60         public void setRightAnchor(Integer offset)
    61         {
    62                 setXAnchor(offset, false);
     77
     78        public void removeYAnchor() {
     79                setYAnchor(null, horizonalDirection);
    6380        }
    64        
    65         public void setTopAnchor(Integer offset)
    66         {
    67                 setYAnchor(offset, true);
    68         }
    69        
    70         public void setBottomAnchor(Integer offset)
    71         {
    72                 setYAnchor(offset, false);
    73         }
    74        
    75         public void removeXAnchor()
    76         {
    77                 setXAnchor(null, _left);
    78         }
    79        
    80         public void removeYAnchor()
    81         {
    82                 setYAnchor(null, _top);
    83         }
    84        
    85         public void removeAllAnchors()
    86         {
     81
     82        public void removeAllAnchors() {
    8783                removeXAnchor();
    8884                removeYAnchor();
    8985        }
     86
     87        public Point getPositionInBox(AxisAlignedBoxBounds box) {
     88                Integer x = getXPositionInBox(box);
     89                Integer y = getYPositionInBox(box);
     90
     91                if (x == null || y == null)
     92                        return null;
     93
     94                return new Point(x, y);
     95        }
     96
     97        public boolean isXAnchored() {
     98                return _xAnchor != null;
     99        }
     100
     101        public boolean isYAnchored() {
     102                return _yAnchor != null;
     103        }
     104
     105        public boolean isAnchored() {
     106                return isXAnchored() || isYAnchored();
     107        }
    90108       
    91         public Integer getXPositionInBox(AxisAlignedBoxBounds box)
    92         {
    93                 if (box == null || _xAnchor == null) return null;
     109        public Integer getLeftAnchor() {
     110                return verticalDirection.equals(VerticalDirection.left) ? _xAnchor : null;
     111        }
     112       
     113        public Integer getCenterXAnchor() {
     114                return verticalDirection.equals(VerticalDirection.center) ? _xAnchor : null;
     115        }
     116
     117        public Integer getRightAnchor() {
     118                return verticalDirection.equals(VerticalDirection.right) ? _xAnchor : null;
     119        }
     120
     121        public Integer getTopAnchor() {
     122                return horizonalDirection.equals(HorizontalDirection.top) ? _yAnchor : null;
     123        }
     124       
     125        public Integer getCenterYAnchor() {
     126                return horizonalDirection.equals(HorizontalDirection.center) ? _yAnchor : null;
     127        }
     128       
     129        public Integer getBottomAnchor() {
     130                return horizonalDirection.equals(HorizontalDirection.bottom) ? _yAnchor : null;
     131        }
     132                       
     133        private void setXAnchor(Integer offset, VerticalDirection left) {
     134                _xAnchor = offset;
     135                verticalDirection = left;
     136        }
     137
     138        private void setYAnchor(Integer offset, HorizontalDirection top) {
     139                _yAnchor = offset;
     140                horizonalDirection = top;
     141        }
     142       
     143        private Integer getXPositionInBox(AxisAlignedBoxBounds box) {
     144                if (box == null || _xAnchor == null)
     145                        return null;
    94146               
    95                 if (_left) {
     147                switch (verticalDirection) {
     148                case left:
    96149                        return box.getMinX() + _xAnchor;
    97                 } else {
     150                case center:
     151                        return box.getCentreX() + _xAnchor;
     152                case right:
    98153                        return box.getMaxX() - _xAnchor;
     154                default:
     155                        System.err.println("Anchoring::getXPositionInBox::VerticalDirection does not match available options.  Has the enum been updated without this function being updated?");
     156                        return null;
    99157                }
    100158        }
    101159       
    102         public Integer getYPositionInBox(AxisAlignedBoxBounds box)
    103         {
    104                 if (box == null || _yAnchor == null) return null;
     160        private Integer getYPositionInBox(AxisAlignedBoxBounds box) {
     161                if (box == null || _yAnchor == null) {
     162                        return null;
     163                }
    105164               
    106                 if (_top) {
     165                switch (horizonalDirection) {
     166                case top:
    107167                        return box.getMinY() + _yAnchor;
    108                 } else {
     168                case center:
     169                        return box.getCentreY() + _yAnchor;
     170                case bottom:
    109171                        return box.getMaxY() - _yAnchor;
     172                default:
     173                        System.err.println("Anchoring::getYPositionInBox::HorizonalDirection does not match available options.  Has the enum been updated without this function being updated?");
     174                        return null;
    110175                }
    111176        }
    112        
    113         public Point getPositionInBox(AxisAlignedBoxBounds box)
    114         {
    115                 Integer x = getXPositionInBox(box);
    116                 Integer y = getYPositionInBox(box);
    117                
    118                 if (x == null || y == null) return null;
    119                
    120                 return new Point(x, y);
    121         }
    122        
    123         public boolean isXAnchored()
    124         {
    125                 return _xAnchor != null;
    126         }
    127        
    128         public boolean isYAnchored()
    129         {
    130                 return _yAnchor != null;
    131         }
    132        
    133         public boolean isAnchored()
    134         {
    135                 return isXAnchored() || isYAnchored();
    136         }
    137        
    138         public Integer getLeftAnchor()
    139         {
    140                 return _left ? _xAnchor : null;
    141         }
    142        
    143         public Integer getRightAnchor()
    144         {
    145                 return !_left ? _xAnchor : null;
    146         }
    147        
    148         public Integer getTopAnchor()
    149         {
    150                 return _top ? _yAnchor : null;
    151         }
    152        
    153         public Integer getBottomAnchor()
    154         {
    155                 return !_top ? _yAnchor : null;
    156         }
    157177}
  • trunk/src/org/expeditee/gio/gesture/StandardGestureActions.java

    r1511 r1513  
    26702670                for (Item i : items) {
    26712671                        Integer anchorLeft = i.getAnchorLeft();
     2672                        Integer anchorCenterX = i.getAnchorCenterX();
    26722673                        Integer anchorRight = i.getAnchorRight();
    26732674                        Integer anchorTop = i.getAnchorTop();
     2675                        Integer anchorCenterY = i.getAnchorCenterY();
    26742676                        Integer anchorBottom = i.getAnchorBottom();
    26752677
     
    26802682                                }
    26812683                        }
     2684                       
     2685                        if (anchorCenterX != null) {
     2686                                i.setAnchorCenterX(anchorCenterX);
     2687                                if (i.hasVector()) {
     2688                                        bReparse = true;
     2689                                }
     2690                        }
    26822691
    26832692                        if (anchorRight != null) {
     
    26902699                        if (anchorTop != null) {
    26912700                                i.setAnchorTop(anchorTop);
     2701                                if (i.hasVector()) {
     2702                                        bReparse = true;
     2703                                }
     2704                        }
     2705                       
     2706                        if (anchorCenterY != null) {
     2707                                i.setAnchorCenterY(anchorCenterY);
    26922708                                if (i.hasVector()) {
    26932709                                        bReparse = true;
  • trunk/src/org/expeditee/gui/AttributeUtils.java

    r1509 r1513  
    244244                        _Attrib.put("AnchorBottom",         Item.class.getMethod("getAnchorBottom"),
    245245                                                            Item.class.getMethod("setAnchorBottom", pIntO));
     246                        _Attrib.put("AnchorCenterX",            Item.class.getMethod("getAnchorCenterX"),
     247                                                                                                Item.class.getMethod("setAnchorCenterX", pIntO));
     248                        _Attrib.put("AnchorCenterY",            Item.class.getMethod("getAnchorCenterY"),
     249                                                                                                Item.class.getMethod("setAnchorCenterY", pIntO));
    246250                        _Attrib.put("Position",             Item.class.getMethod("getPosition"),
    247251                                                            Item.class.getMethod("setPosition", pPoint));
  • trunk/src/org/expeditee/gui/Frame.java

    r1511 r1513  
    10041004                for (Item i : getSortedItems()) {
    10051005                        Integer anchorLeft   = i.getAnchorLeft();
     1006                        Integer anchorCenterX = i.getAnchorCenterX();
    10061007                        Integer anchorRight  = i.getAnchorRight();
    10071008                        Integer anchorTop    = i.getAnchorTop();
     1009                        Integer anchorCenterY = i.getAnchorCenterY();
    10081010                        Integer anchorBottom = i.getAnchorBottom();
    10091011       
     
    10161018                        }
    10171019                       
     1020                        if (anchorCenterX != null) {
     1021                                i.setAnchorCenterX(anchorCenterX);
     1022                                if (i.hasVector()) {
     1023                                        bReparse = true;
     1024                                }
     1025                        }
     1026                       
    10181027                        if (anchorRight != null) {
    10191028                                i.setAnchorRight(anchorRight);
     
    10251034                        if (anchorTop != null) {
    10261035                                i.setAnchorTop(anchorTop);
     1036                                if (i.hasVector()) {
     1037                                        bReparse = true;
     1038                                }
     1039                        }
     1040                       
     1041                        if (anchorCenterY != null) {
     1042                                i.setAnchorCenterY(anchorCenterY);
    10271043                                if (i.hasVector()) {
    10281044                                        bReparse = true;
  • trunk/src/org/expeditee/io/DefaultFrameReader.java

    r1508 r1513  
    195195                        _ItemTagsExt.put(DefaultFrameWriter.TAB_INDEX_STR, Text.class.getMethod("setTabIndex", pInt));
    196196                        _ItemTagsExt.put(DefaultFrameWriter.ACCEPTS_ENTER, Item.class.getMethod("setAcceptsEnter", pBool));
     197                        _ItemTagsExt.put(DefaultFrameWriter.ANCHOR_CENTERX_STR, Item.class.getMethod("setAnchorCenterX", pIntO));
    197198                } catch (Exception e) {
    198199                        e.printStackTrace();
  • trunk/src/org/expeditee/io/DefaultFrameWriter.java

    r1506 r1513  
    101101        public static final String ENCRYPTION_LABEL_STR = "_el";
    102102        public static final String ACCEPTS_ENTER = "_ae";
     103        public static final String ANCHOR_CENTERX_STR = "_ax";
     104        public static final String ANCHOR_CENTERY_STR = "_ay";
    103105        public static final String MAGNETIZED_ITEM_BOTTOM_STR = MAGNETIZED_ITEM_BOTTOM + "";
    104106        public static final String MAGNETIZED_ITEM_TOP_STR = MAGNETIZED_ITEM_TOP + "";
     
    276278                        _ItemStrTags.put(DefaultFrameWriter.TAB_INDEX_STR, Text.class.getMethod("getTabIndex"));
    277279                        _ItemStrTags.put(DefaultFrameWriter.ACCEPTS_ENTER, Item.class.getMethod("acceptsKeyboardEnter"));
     280                        _ItemStrTags.put(DefaultFrameWriter.ANCHOR_CENTERX_STR, Item.class.getMethod("getAnchorCenterX"));
    278281                } catch (Exception e) {
    279282                        e.printStackTrace();
  • trunk/src/org/expeditee/items/Item.java

    r1511 r1513  
    36583658                }
    36593659        }
     3660       
     3661        public void setAnchorCenterX(Integer anchor) {
     3662                this._anchoring.setCenterXAnchor(anchor);
     3663                if (anchor != null) {
     3664                        anchorConstraints();
     3665                        int alignedToLeft = DisplayController.getFramePaintArea().getCentreX() + anchor;
     3666                        int alignedToCenter = alignedToLeft - (getBoundsWidth() / 2);
     3667                        setX(alignedToCenter);
     3668                }
     3669               
     3670                if (isSurrogate()) {
     3671                        surrogatePropertyInheritance.put(DefaultFrameWriter.ANCHOR_CENTERX_STR, false);
     3672                        Item primary = getPrimary();
     3673                        if (subjectToInheritanceCheckOnSave(DefaultFrameWriter.ANCHOR_CENTERX_STR)) {
     3674                                EncryptionDetail inheritanceCheckOnSave = new EncryptionDetail(EncryptionDetail.Type.InheritanceCheckOnSave);
     3675                                primary.primaryPropertyEncryption.put(DefaultFrameWriter.ANCHOR_CENTERX_STR, inheritanceCheckOnSave);
     3676                        }
     3677                }
     3678        }
    36603679
    36613680        public void setAnchorRight(Integer anchor) {
     
    36943713                }
    36953714        }
     3715       
     3716        public void setAnchorCenterY(Integer anchor) {
     3717                this._anchoring.setCenterYAnchor(anchor);
     3718                if (anchor != null) {
     3719                        anchorConstraints();
     3720                        int alignedToTop = DisplayController.getFramePaintArea().getCentreY() + anchor;
     3721                        int alignedToCenter = alignedToTop - (getBoundsHeight() / 2);
     3722                        setY(alignedToCenter);
     3723                }
     3724               
     3725                if (isSurrogate()) {
     3726                        surrogatePropertyInheritance.put(DefaultFrameWriter.ANCHOR_CENTERY_STR, false);
     3727                        Item primary = getPrimary();
     3728                        if (subjectToInheritanceCheckOnSave(DefaultFrameWriter.ANCHOR_CENTERY_STR)) {
     3729                                EncryptionDetail inheritanceCheckOnSave = new EncryptionDetail(EncryptionDetail.Type.InheritanceCheckOnSave);
     3730                                primary.primaryPropertyEncryption.put(DefaultFrameWriter.ANCHOR_CENTERY_STR, inheritanceCheckOnSave);
     3731                        }
     3732                }
     3733        }
    36963734
    36973735
     
    37123750                }
    37133751        }
    3714 
     3752               
    37153753        public boolean isAnchored()
    37163754        {
     
    37553793                } else {
    37563794                        return _anchoring.getBottomAnchor();
     3795                }
     3796        }
     3797       
     3798        public Integer getAnchorCenterX() {
     3799                if (isSurrogate() && surrogatePropertyInheritance.get(DefaultFrameWriter.ANCHOR_CENTERX_STR)) {
     3800                        return this.getPrimary().getAnchorCenterX();
     3801                } else {
     3802                        return _anchoring.getCenterXAnchor();
     3803                }
     3804        }
     3805       
     3806        public Integer getAnchorCenterY() {
     3807                if (isSurrogate() && surrogatePropertyInheritance.get(DefaultFrameWriter.ANCHOR_CENTERY_STR)) {
     3808                        return this.getPrimary().getAnchorCenterY();
     3809                } else {
     3810                        return _anchoring.getCenterYAnchor();
    37573811                }
    37583812        }
  • trunk/src/org/expeditee/items/Text.java

    r1511 r1513  
    393393        @Override
    394394        public void setWidth(Integer width) {
    395                 System.err.println("Text::setWidth::Text content=" + getText() + ", new width=" + width);
    396395                invalidateAll();
    397396
Note: See TracChangeset for help on using the changeset viewer.