Changeset 1513
- Timestamp:
- 02/19/20 15:29:48 (4 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/core/Anchoring.java
r1097 r1513 4 4 5 5 /** 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. 11 10 * 12 11 * @author cts16 13 12 */ 14 13 public class Anchoring { 14 15 private enum VerticalDirection { left, center, right } 16 private enum HorizontalDirection { top, center, bottom } 15 17 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 */ 17 21 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 */ 19 25 private Integer _yAnchor = null; 26 20 27 /** Whether the x-anchor is relative to the left or right edge. */ 21 private boolean _left = true;28 private VerticalDirection verticalDirection = VerticalDirection.left; 22 29 /** 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() { 27 33 } 28 34 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); 33 52 } 34 53 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); 39 64 } 40 65 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); 46 68 } 47 69 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); 53 72 } 54 73 55 public void setLeftAnchor(Integer offset) 56 { 57 setXAnchor(offset, true); 74 public void removeXAnchor() { 75 setXAnchor(null, verticalDirection); 58 76 } 59 60 public void setRightAnchor(Integer offset) 61 { 62 setXAnchor(offset, false); 77 78 public void removeYAnchor() { 79 setYAnchor(null, horizonalDirection); 63 80 } 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() { 87 83 removeXAnchor(); 88 84 removeYAnchor(); 89 85 } 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 } 90 108 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; 94 146 95 if (_left) { 147 switch (verticalDirection) { 148 case left: 96 149 return box.getMinX() + _xAnchor; 97 } else { 150 case center: 151 return box.getCentreX() + _xAnchor; 152 case right: 98 153 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; 99 157 } 100 158 } 101 159 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 } 105 164 106 if (_top) { 165 switch (horizonalDirection) { 166 case top: 107 167 return box.getMinY() + _yAnchor; 108 } else { 168 case center: 169 return box.getCentreY() + _yAnchor; 170 case bottom: 109 171 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; 110 175 } 111 176 } 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 }157 177 } -
trunk/src/org/expeditee/gio/gesture/StandardGestureActions.java
r1511 r1513 2670 2670 for (Item i : items) { 2671 2671 Integer anchorLeft = i.getAnchorLeft(); 2672 Integer anchorCenterX = i.getAnchorCenterX(); 2672 2673 Integer anchorRight = i.getAnchorRight(); 2673 2674 Integer anchorTop = i.getAnchorTop(); 2675 Integer anchorCenterY = i.getAnchorCenterY(); 2674 2676 Integer anchorBottom = i.getAnchorBottom(); 2675 2677 … … 2680 2682 } 2681 2683 } 2684 2685 if (anchorCenterX != null) { 2686 i.setAnchorCenterX(anchorCenterX); 2687 if (i.hasVector()) { 2688 bReparse = true; 2689 } 2690 } 2682 2691 2683 2692 if (anchorRight != null) { … … 2690 2699 if (anchorTop != null) { 2691 2700 i.setAnchorTop(anchorTop); 2701 if (i.hasVector()) { 2702 bReparse = true; 2703 } 2704 } 2705 2706 if (anchorCenterY != null) { 2707 i.setAnchorCenterY(anchorCenterY); 2692 2708 if (i.hasVector()) { 2693 2709 bReparse = true; -
trunk/src/org/expeditee/gui/AttributeUtils.java
r1509 r1513 244 244 _Attrib.put("AnchorBottom", Item.class.getMethod("getAnchorBottom"), 245 245 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)); 246 250 _Attrib.put("Position", Item.class.getMethod("getPosition"), 247 251 Item.class.getMethod("setPosition", pPoint)); -
trunk/src/org/expeditee/gui/Frame.java
r1511 r1513 1004 1004 for (Item i : getSortedItems()) { 1005 1005 Integer anchorLeft = i.getAnchorLeft(); 1006 Integer anchorCenterX = i.getAnchorCenterX(); 1006 1007 Integer anchorRight = i.getAnchorRight(); 1007 1008 Integer anchorTop = i.getAnchorTop(); 1009 Integer anchorCenterY = i.getAnchorCenterY(); 1008 1010 Integer anchorBottom = i.getAnchorBottom(); 1009 1011 … … 1016 1018 } 1017 1019 1020 if (anchorCenterX != null) { 1021 i.setAnchorCenterX(anchorCenterX); 1022 if (i.hasVector()) { 1023 bReparse = true; 1024 } 1025 } 1026 1018 1027 if (anchorRight != null) { 1019 1028 i.setAnchorRight(anchorRight); … … 1025 1034 if (anchorTop != null) { 1026 1035 i.setAnchorTop(anchorTop); 1036 if (i.hasVector()) { 1037 bReparse = true; 1038 } 1039 } 1040 1041 if (anchorCenterY != null) { 1042 i.setAnchorCenterY(anchorCenterY); 1027 1043 if (i.hasVector()) { 1028 1044 bReparse = true; -
trunk/src/org/expeditee/io/DefaultFrameReader.java
r1508 r1513 195 195 _ItemTagsExt.put(DefaultFrameWriter.TAB_INDEX_STR, Text.class.getMethod("setTabIndex", pInt)); 196 196 _ItemTagsExt.put(DefaultFrameWriter.ACCEPTS_ENTER, Item.class.getMethod("setAcceptsEnter", pBool)); 197 _ItemTagsExt.put(DefaultFrameWriter.ANCHOR_CENTERX_STR, Item.class.getMethod("setAnchorCenterX", pIntO)); 197 198 } catch (Exception e) { 198 199 e.printStackTrace(); -
trunk/src/org/expeditee/io/DefaultFrameWriter.java
r1506 r1513 101 101 public static final String ENCRYPTION_LABEL_STR = "_el"; 102 102 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"; 103 105 public static final String MAGNETIZED_ITEM_BOTTOM_STR = MAGNETIZED_ITEM_BOTTOM + ""; 104 106 public static final String MAGNETIZED_ITEM_TOP_STR = MAGNETIZED_ITEM_TOP + ""; … … 276 278 _ItemStrTags.put(DefaultFrameWriter.TAB_INDEX_STR, Text.class.getMethod("getTabIndex")); 277 279 _ItemStrTags.put(DefaultFrameWriter.ACCEPTS_ENTER, Item.class.getMethod("acceptsKeyboardEnter")); 280 _ItemStrTags.put(DefaultFrameWriter.ANCHOR_CENTERX_STR, Item.class.getMethod("getAnchorCenterX")); 278 281 } catch (Exception e) { 279 282 e.printStackTrace(); -
trunk/src/org/expeditee/items/Item.java
r1511 r1513 3658 3658 } 3659 3659 } 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 } 3660 3679 3661 3680 public void setAnchorRight(Integer anchor) { … … 3694 3713 } 3695 3714 } 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 } 3696 3734 3697 3735 … … 3712 3750 } 3713 3751 } 3714 3752 3715 3753 public boolean isAnchored() 3716 3754 { … … 3755 3793 } else { 3756 3794 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(); 3757 3811 } 3758 3812 } -
trunk/src/org/expeditee/items/Text.java
r1511 r1513 393 393 @Override 394 394 public void setWidth(Integer width) { 395 System.err.println("Text::setWidth::Text content=" + getText() + ", new width=" + width);396 395 invalidateAll(); 397 396
Note:
See TracChangeset
for help on using the changeset viewer.