Changeset 962
- Timestamp:
- 09/08/15 13:10:16 (9 years ago)
- Location:
- trunk/src/org/expeditee/items/MagneticConstraint
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/MagneticConstraint/Actions/DownALineAction.java
r934 r962 1 1 package org.expeditee.items.MagneticConstraint.Actions; 2 2 3 import java.awt.Point;4 5 3 import org.expeditee.gui.DisplayIO; 6 import org.expeditee.gui.FrameGraphics;7 4 import org.expeditee.items.Item; 8 5 import org.expeditee.items.Text; … … 45 42 if(toMoveTo instanceof Text) { 46 43 final Text asText = (Text) toMoveTo; 47 final Point position = toMoveTo.getPosition(); 48 DisplayIO.setCursorPosition(position.x + asText.getPixelBoundsUnion().width, position.y, false); 49 FrameGraphics.refresh(false); 44 DisplayIO.setTextCursor(asText, Text.END); 50 45 } else DisplayIO.setCursorPosition(toMoveTo.getPosition(), false); 51 46 return true; -
trunk/src/org/expeditee/items/MagneticConstraint/Actions/RepelTextAction.java
r960 r962 1 1 package org.expeditee.items.MagneticConstraint.Actions; 2 2 3 import java.awt.Point; 4 5 import org.expeditee.gui.FrameUtils; 3 6 import org.expeditee.items.Item; 4 7 import org.expeditee.items.MagneticConstraint.MagneticConstraintActionWithArguments; … … 20 23 @Override 21 24 public boolean exec(final Item item, final Float... args) { 22 if(item .getParent() == null || item.getText().startsWith("@")) {25 if(item == null || item.getParent() == null || item.getText().startsWith("@") || !isSpIDERCodePage(item.getParent())) { 23 26 return false; 24 27 } 25 if (item.getMagnetizedItemRight() == -1) { 26 if(item.getParent() == null) return false; 27 if(BoxLogic.boxCollision(item)) { 28 callback(null); 29 // BoxLogic.resolveCollision(item, this); 30 // callback(null); 31 // MagneticConstraints.Log(this.getClass(), new Item[]{item}, 32 // Line.getLineContainingToken(item).toArray(new Item[]{}), 33 // "No item found to right to repel. Collision occured."); 34 } else { 35 MagneticConstraints.Log(this.getClass(), new Item[]{item}, 36 Line.getLineContainingToken(item).toArray(new Item[]{}), 37 "No item found to right to repel."); 38 } 39 return false; 40 } else if (item.getParent().getItemWithID(item.getMagnetizedItemRight()) == null) { 28 if(FrameUtils.getCurrentItem() == null) return false; 29 final Point selectedItemPosition = FrameUtils.getCurrentItem().getPosition(); 30 if(!selectedItemPosition.equals(item.getPosition())) return false; 31 32 if(item.getMagnetizedItemRight() == -1) { 33 34 } else if(item.getParent().getItemWithID(item.getMagnetizedItemRight()) == null) { 41 35 item.setMagnetizedItemRight(null); 42 MagneticConstraints.Log(this.getClass(), new Item[]{item},43 Line.getLineContainingToken(item).toArray(new Item[]{}),44 "Right neighbor has id: " + item.getMagnetizedItemRight() +45 " according to datastructure but no item on frame has that id.");46 36 return false; 47 37 } else { 48 final Item toMyRight = item.getParent().getItemWithID( 49 item.getMagnetizedItemRight()); 50 if(item.getX() + item.getBoundsWidth() + args[0] >= toMyRight.getX()) { 51 float newX = toMyRight.getX() + args[0]; 52 //System.err.println("Repeling item with text: " + toMyRight.getText() + " Origonal X: " + toMyRight.getX() + " New X: " + newX); 53 if(newX < toMyRight.getX()) { 54 System.err.println(); 38 final Line tokensToMove = Line.getLineFromToken(item); 39 tokensToMove.removeFirst(); 40 tokensToMove.deltaX(args[0].intValue()); 41 for(final Item token : tokensToMove) { 42 if(BoxLogic.boxCollision(token)) { 43 final RepelTextDownAction textDownAction = new RepelTextDownAction(); 44 textDownAction.setCallbackAction(this.callbackAction); 45 textDownAction.exec(token); 46 break; 55 47 } 56 toMyRight.setX(newX); 57 MagneticConstraints.Log(this.getClass(), new Item[]{item, toMyRight}, 58 Line.getLineContainingToken(item).toArray(new Item[]{}), 59 "Repeling second primary to first. Delta: " + args[0] + ". NewX: " + newX + ". Recursing."); 60 RepelTextAction recurse = new RepelTextAction(); 61 recurse.setCallbackAction(this.callbackAction); 62 recurse.exec(toMyRight, args); 63 return true; 64 } else return false; 48 } 65 49 } 50 51 52 53 54 callback(item); 55 56 return true; 66 57 } 67 58 -
trunk/src/org/expeditee/items/MagneticConstraint/Actions/RepelTextDownAction.java
r955 r962 5 5 import org.expeditee.gui.DisplayIO; 6 6 import org.expeditee.gui.FrameIO; 7 import org.expeditee.items.*; 7 import org.expeditee.gui.FrameUtils; 8 import org.expeditee.items.Item; 9 import org.expeditee.items.Text; 8 10 import org.expeditee.items.MagneticConstraint.MagneticConstraintAction; 9 11 import org.expeditee.items.MagneticConstraint.Utilities.Line; … … 13 15 public class RepelTextDownAction extends MagneticConstraintAction { 14 16 17 // private void f(final Item item) { 18 // final List<Item> items = item.getParent().getItems(); 19 // for (final Item item2 : items) { 20 // if(item2.getText().compareTo("main") == 0) System.err.println("#Found main"); 21 // } 22 // } 23 15 24 @Override 16 25 public boolean exec(final Item item) { 17 if(item == null ) return false;18 callback( null);26 if(item == null || item.getParent() == null) return false; 27 callback(item); 19 28 //Calculate content that needs to be moved to next line. 20 29 //1. Get remainder of line … … 22 31 //2. Check if the current item should be included; remove it if not. 23 32 if(remainderOfLine.getFirst().getText().isEmpty() || 24 (remainderOfLine.size() > 0 && TextLogic.XIsTowardsRight(DisplayIO.getMouseX(), (Text) remainderOfLine.getFirst()))) 33 (FrameUtils.getCurrentItem().getPosition().equals(item.getPosition()) 34 && remainderOfLine.size() > 0 35 && TextLogic.XIsTowardsRight(DisplayIO.getMouseX(), (Text) remainderOfLine.getFirst()))) { 25 36 remainderOfLine.removeFirst(); 37 } 38 26 39 //Move content below this line down 27 40 //1. Get current line & current paragraph. … … 34 47 if(!remainderOfLine.isEmpty()) { 35 48 //2a. Yes. Move the content 36 final Point first = remainderOfLine.get (0).getPosition();49 final Point first = remainderOfLine.getBoundingBox().getLocation(); 37 50 for(final Item token : remainderOfLine) { 38 51 double newX = token.getX() - first.getX() + newLineAt.getX(); 39 double newY = token.getY() - first.getY() + newLineAt.getY(); 40 token.setPosition((float) newX, (float) newY); 52 token.setPosition((float) newX, (float) newLineAt.getY()); 41 53 } 42 54 //2b. Move the cursor; refresh the screen and use callback to update the magnets 43 DisplayIO.setCursorPosition(remainderOfLine.get(0).getPosition()); 44 FrameIO.ForceSaveFrame(item.getParent()); 45 FrameIO.Reload(); 55 DisplayIO.setTextCursor((Text) remainderOfLine.getFirst(), Text.HOME); 46 56 callback(null); 57 FrameIO.SaveFrame(remainderOfLine.getLast().getParent()); 47 58 } else { 48 59 //3a No. Move the cursor; refresh the screen and use callback to update the magnets 49 60 DisplayIO.setCursorPosition(newLineAt); 50 FrameIO.ForceSaveFrame(item.getParent());51 FrameIO.Reload();52 callback(null);53 61 } 62 54 63 return true; 55 64 } -
trunk/src/org/expeditee/items/MagneticConstraint/Actions/UpALineAction.java
r934 r962 1 1 package org.expeditee.items.MagneticConstraint.Actions; 2 2 3 import java.awt.Point;4 5 3 import org.expeditee.gui.DisplayIO; 6 import org.expeditee.gui.FrameGraphics;7 4 import org.expeditee.items.Item; 8 5 import org.expeditee.items.Text; … … 39 36 if(toMoveTo instanceof Text) { 40 37 final Text asText = (Text) toMoveTo; 41 final Point position = toMoveTo.getPosition(); 42 DisplayIO.setCursorPosition(position.x + asText.getPixelBoundsUnion().width, position.y, false); 43 FrameGraphics.refresh(false); 38 DisplayIO.setTextCursor(asText, Text.END); 44 39 } else DisplayIO.setCursorPosition(toMoveTo.getPosition(), false); 45 40 return true; -
trunk/src/org/expeditee/items/MagneticConstraint/MagneticConstraintAction.java
r931 r962 19 19 package org.expeditee.items.MagneticConstraint; 20 20 21 import java.util.List; 22 23 import org.expeditee.gui.Frame; 21 24 import org.expeditee.items.Item; 22 25 … … 35 38 callbackAction = action; 36 39 } 40 41 protected boolean isSpIDERCodePage(final Frame frame) { 42 if(frame.getTitleItem() == null) return false; 43 final List<String> data = frame.getTitleItem().getData(); 44 boolean hasProjectTag = false; 45 boolean hasPackageTag = false; 46 boolean hasClassTag = false; 47 if(data == null) return false; 48 for(final String s : data) { 49 if(s.startsWith("Project:")) hasProjectTag = true; 50 else if(s.startsWith("Package:")) hasPackageTag = true; 51 else if(s.startsWith("Class:")) hasClassTag = true; 52 } 53 return hasProjectTag && hasPackageTag && hasClassTag; 54 } 37 55 } -
trunk/src/org/expeditee/items/MagneticConstraint/Utilities/Line.java
r960 r962 68 68 69 69 public Line next() { 70 final Item lastInThisLine = this.get (this.size() - 1);70 final Item lastInThisLine = this.getLast();//this.get(this.size() - 1); 71 71 if(lastInThisLine.getMagnetizedItemBottom() == -1) return null; 72 72 else return getLineFromToken(this.get(0).getParent().getItemWithID(lastInThisLine.getMagnetizedItemBottom())); … … 74 74 75 75 public Line last() { 76 final Item firstInThisLine = this.get (0);76 final Item firstInThisLine = this.getFirst();//this.get(0); 77 77 if(firstInThisLine.getMagnetizedItemTop() == -1) return null; 78 78 else return getLineContainingToken(this.get(0).getParent().getItemWithID(firstInThisLine.getMagnetizedItemTop())); … … 80 80 81 81 private static Line getLineFromToken(final Item token, final Line acc) { 82 if(token == null) return acc; 82 83 if(token.getMagnetizedItemRight() == -1) { 83 84 acc.add(token); … … 85 86 } else { 86 87 final Line lineSoFar = new Line(acc); 88 if(lineSoFar.contains(token)) return lineSoFar; 87 89 lineSoFar.add(token); 88 90 return getLineFromToken(token.getParent().getItemWithID(token.getMagnetizedItemRight()), lineSoFar); -
trunk/src/org/expeditee/items/MagneticConstraint/Utilities/Paragraph.java
r960 r962 3 3 import java.awt.*; 4 4 import java.util.LinkedList; 5 import org.expeditee.items.Text; 5 6 6 7 @SuppressWarnings("serial") … … 58 59 //4b. No; then we simply need to calculate the position of the next line and return that. 59 60 final Rectangle boundingBox = splitAt.getBoundingBox(); 60 return new Point(( int)boundingBox.getX(), (int)boundingBox.getMaxY() + lineHeight);61 return new Point(((Text) splitAt.getFirst()).getX(), (int)boundingBox.getMaxY() + lineHeight); 61 62 } 62 63 //NB at this point we know that there are lines below our 'splitAt' line in the same paragraph so they need to be moved down. … … 64 65 paragraphStartingAtNextLine.deltaY(lineHeight); 65 66 //6. Return the position of the new line we have made space for. 67 66 68 final Rectangle boundingBox = splitAt.getBoundingBox(); 67 return new Point((int)boundingBox.getX(), (int)boundingBox.getMinY() + lineHeight); 69 final int x = ((Text) splitAt.getFirst()).getX(); 70 return new Point(x, (int)boundingBox.getMaxY() + lineHeight); 68 71 } 69 72 -
trunk/src/org/expeditee/items/MagneticConstraint/Utilities/TextLogic.java
r934 r962 9 9 if(text.getPixelBoundsUnion() == null) return false; 10 10 final double distanceThroughText = x - text.getPixelBoundsUnion().getX(); 11 return text.getText().length() == 1 ||distanceThroughText > (text.getPixelBoundsUnion().getWidth() / 2);11 return /*text.getText().length() == 1 ||*/ distanceThroughText > (text.getPixelBoundsUnion().getWidth() / 2); 12 12 } 13 13
Note:
See TracChangeset
for help on using the changeset viewer.