Ignore:
Timestamp:
09/15/15 12:32:33 (9 years ago)
Author:
bln4
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/items/MagneticConstraint/Actions/RepelTextDownAction.java

    r962 r963  
    1515public class RepelTextDownAction extends MagneticConstraintAction {
    1616       
    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 //      }
     17        public static boolean MergeSameLineParagraphCollisions = false;
    2318       
    2419        @Override
    2520        public boolean exec(final Item item) {
    26                 if(item == null || item.getParent() == null) return false;
    27                 callback(item);
     21                if(item == null || item.getParent() == null) return false;             
     22                callback(item); 
    2823                //Calculate content that needs to be moved to next line.
    2924                        //1. Get remainder of line
     
    3732                }
    3833                       
    39                 //Move content below this line down
    40                         //1. Get current line & current paragraph.
    4134                final Line currentLine = Line.getLineContainingToken(item);
    4235                final Paragraph currentParagraph = Paragraph.getParagraphFromLine(currentLine);
    43                         //2. Split current paragraph
    44                 final Point newLineAt = currentParagraph.split(currentLine);
     36                final Line nextLine = currentLine.next();
     37               
     38                final Point newLineAt;
    4539                //Move content contained in 'remainderOfLine'
    46                         //1. Is remainderOfLine not Empty?
    47                 if(!remainderOfLine.isEmpty()) {
    48                                 //2a. Yes. Move the content
     40
     41               
     42                if(!remainderOfLine.isEmpty() && currentParagraph.contains(nextLine) && MergeSameLineParagraphCollisions) {
     43                        nextLine.prependLine(remainderOfLine);
     44                        DisplayIO.setTextCursor((Text) remainderOfLine.getFirst(), Text.HOME);
     45                        callback(remainderOfLine.getFirst());
     46                        FrameIO.SaveFrame(remainderOfLine.getLast().getParent());
     47                } else if(!remainderOfLine.isEmpty()) {
     48                        newLineAt = currentParagraph.split(currentLine);
    4949                        final Point first = remainderOfLine.getBoundingBox().getLocation();
    5050                        for(final Item token : remainderOfLine) {
     
    5252                                token.setPosition((float) newX, (float) newLineAt.getY());
    5353                        }
    54                                 //2b. Move the cursor; refresh the screen and use callback to update the magnets
    5554                        DisplayIO.setTextCursor((Text) remainderOfLine.getFirst(), Text.HOME);
    56                         callback(null);
     55                        callback(remainderOfLine.getFirst());
    5756                        FrameIO.SaveFrame(remainderOfLine.getLast().getParent());
    58                 } else {
    59                                 //3a No. Move the cursor; refresh the screen and use callback to update the magnets
     57                }else {
     58                                //3a No. Move the cursor
     59                        newLineAt = currentParagraph.split(currentLine);
    6060                        DisplayIO.setCursorPosition(newLineAt);
    6161                }
    62 
     62               
    6363                return true;
    6464        }
Note: See TracChangeset for help on using the changeset viewer.