Changeset 962


Ignore:
Timestamp:
09/08/15 13:10:16 (9 years ago)
Author:
bln4
Message:
 
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  
    11package org.expeditee.items.MagneticConstraint.Actions;
    22
    3 import java.awt.Point;
    4 
    53import org.expeditee.gui.DisplayIO;
    6 import org.expeditee.gui.FrameGraphics;
    74import org.expeditee.items.Item;
    85import org.expeditee.items.Text;
     
    4542                if(toMoveTo instanceof Text) {
    4643                        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);
    5045                } else DisplayIO.setCursorPosition(toMoveTo.getPosition(), false);
    5146                return true;
  • trunk/src/org/expeditee/items/MagneticConstraint/Actions/RepelTextAction.java

    r960 r962  
    11package org.expeditee.items.MagneticConstraint.Actions;
    22
     3import java.awt.Point;
     4
     5import org.expeditee.gui.FrameUtils;
    36import org.expeditee.items.Item;
    47import org.expeditee.items.MagneticConstraint.MagneticConstraintActionWithArguments;
     
    2023        @Override
    2124        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())) {
    2326                        return false;
    2427                }
    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) {
    4135                        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.");
    4636                        return false;
    4737                } 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;
    5547                                }
    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                        }
    6549                }
     50               
     51
     52
     53               
     54                callback(item);
     55
     56                return true;
    6657        }
    6758
  • trunk/src/org/expeditee/items/MagneticConstraint/Actions/RepelTextDownAction.java

    r955 r962  
    55import org.expeditee.gui.DisplayIO;
    66import org.expeditee.gui.FrameIO;
    7 import org.expeditee.items.*;
     7import org.expeditee.gui.FrameUtils;
     8import org.expeditee.items.Item;
     9import org.expeditee.items.Text;
    810import org.expeditee.items.MagneticConstraint.MagneticConstraintAction;
    911import org.expeditee.items.MagneticConstraint.Utilities.Line;
     
    1315public class RepelTextDownAction extends MagneticConstraintAction {
    1416       
     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       
    1524        @Override
    1625        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);
    1928                //Calculate content that needs to be moved to next line.
    2029                        //1. Get remainder of line
     
    2231                        //2. Check if the current item should be included; remove it if not.
    2332                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()))) {
    2536                        remainderOfLine.removeFirst();
     37                }
     38                       
    2639                //Move content below this line down
    2740                        //1. Get current line & current paragraph.
     
    3447                if(!remainderOfLine.isEmpty()) {
    3548                                //2a. Yes. Move the content
    36                         final Point first = remainderOfLine.get(0).getPosition();
     49                        final Point first = remainderOfLine.getBoundingBox().getLocation();
    3750                        for(final Item token : remainderOfLine) {
    3851                                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());
    4153                        }
    4254                                //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);
    4656                        callback(null);
     57                        FrameIO.SaveFrame(remainderOfLine.getLast().getParent());
    4758                } else {
    4859                                //3a No. Move the cursor; refresh the screen and use callback to update the magnets
    4960                        DisplayIO.setCursorPosition(newLineAt);
    50                         FrameIO.ForceSaveFrame(item.getParent());
    51                         FrameIO.Reload();
    52                         callback(null);
    5361                }
     62
    5463                return true;
    5564        }
  • trunk/src/org/expeditee/items/MagneticConstraint/Actions/UpALineAction.java

    r934 r962  
    11package org.expeditee.items.MagneticConstraint.Actions;
    22
    3 import java.awt.Point;
    4 
    53import org.expeditee.gui.DisplayIO;
    6 import org.expeditee.gui.FrameGraphics;
    74import org.expeditee.items.Item;
    85import org.expeditee.items.Text;
     
    3936                if(toMoveTo instanceof Text) {
    4037                        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);
    4439                } else DisplayIO.setCursorPosition(toMoveTo.getPosition(), false);
    4540                return true;
  • trunk/src/org/expeditee/items/MagneticConstraint/MagneticConstraintAction.java

    r931 r962  
    1919package org.expeditee.items.MagneticConstraint;
    2020
     21import java.util.List;
     22
     23import org.expeditee.gui.Frame;
    2124import org.expeditee.items.Item;
    2225
     
    3538                callbackAction = action;
    3639        }
     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        }
    3755}
  • trunk/src/org/expeditee/items/MagneticConstraint/Utilities/Line.java

    r960 r962  
    6868       
    6969        public Line next() {
    70                 final Item lastInThisLine = this.get(this.size() - 1);
     70                final Item lastInThisLine = this.getLast();//this.get(this.size() - 1);
    7171                if(lastInThisLine.getMagnetizedItemBottom() == -1) return null;
    7272                else return getLineFromToken(this.get(0).getParent().getItemWithID(lastInThisLine.getMagnetizedItemBottom()));
     
    7474       
    7575        public Line last() {
    76                 final Item firstInThisLine = this.get(0);
     76                final Item firstInThisLine = this.getFirst();//this.get(0);
    7777                if(firstInThisLine.getMagnetizedItemTop() == -1) return null;
    7878                else return getLineContainingToken(this.get(0).getParent().getItemWithID(firstInThisLine.getMagnetizedItemTop()));
     
    8080               
    8181        private static Line getLineFromToken(final Item token, final Line acc) {
     82                if(token == null) return acc;
    8283                if(token.getMagnetizedItemRight() == -1) {
    8384                        acc.add(token);
     
    8586                } else {
    8687                        final Line lineSoFar = new Line(acc);
     88                        if(lineSoFar.contains(token)) return lineSoFar;
    8789                        lineSoFar.add(token);
    8890                        return getLineFromToken(token.getParent().getItemWithID(token.getMagnetizedItemRight()), lineSoFar);
  • trunk/src/org/expeditee/items/MagneticConstraint/Utilities/Paragraph.java

    r960 r962  
    33import java.awt.*;
    44import java.util.LinkedList;
     5import org.expeditee.items.Text;
    56
    67@SuppressWarnings("serial")
     
    5859                        //4b. No; then we simply need to calculate the position of the next line and return that.
    5960                        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);
    6162                }
    6263                //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.
     
    6465                paragraphStartingAtNextLine.deltaY(lineHeight);
    6566                //6. Return the position of the new line we have made space for.
     67               
    6668                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);
    6871        }
    6972       
  • trunk/src/org/expeditee/items/MagneticConstraint/Utilities/TextLogic.java

    r934 r962  
    99                if(text.getPixelBoundsUnion() == null) return false;
    1010                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);
    1212        }
    1313       
Note: See TracChangeset for help on using the changeset viewer.