source: trunk/src/org/expeditee/items/MagneticConstraint/NextItemToRightAction.java@ 906

Last change on this file since 906 was 906, checked in by bln4, 10 years ago

Added Magnetic Constraints

Magnetic Constraints are a new type of constraint between items; particularly text. Items can have their neighbours set (for example: who is to my right) and then have custom actions run when a item and its neighbour interact in a defined way. For example: one text item grows enough for hits its right neighbour; so its right neighbour moves over to compensate.
Files changed: org.expeditee.{ gui.DisplayIO, io.DefaultFrameReader, io.DefaultFrameWriter, items.Item, items.Text }

Added ability to have 'delayed' properties on items. With the invention of Magnetic Constraints it was found that the saving and loading of properties now required (greatly benifited from) a way to set a property after all items have been loaded in; rather than as the perticular item was being loaded in. This is that ability.

Files changed: org.expeditee.io.{ DefaultFrameReader, ExpReader }

Let through some non letter characters as names of properties. The tokens ',', '', and '_' have been used as property names to describe neighbors. In order to do this the isValidLine(String) method was altered to let these through. This is not the ideal solution, and should be looked at later.

Files changed: org.expeditee.io.ExpReader

Bug fix: setting a custom title support was added previously. If a custom title had been set the title was: [Your Custom Title] ~ [Expeditee Title]. However the tildas where showing up even without a custom title set. This is now fixed.

File size: 1.0 KB
Line 
1package org.expeditee.items.MagneticConstraint;
2
3import java.awt.*;
4
5import org.expeditee.gui.Browser;
6import org.expeditee.gui.DisplayIO;
7import org.expeditee.gui.FrameGraphics;
8import org.expeditee.items.*;
9
10public class NextItemToRightAction implements MagneticConstraintAction {
11
12 @Override
13 public boolean exec(final Item item) {
14 final Item toRight = item.getParent().getItemWithID(item.getMagnetizedItemRight());
15 return moveCursor(toRight);
16 }
17
18 private boolean moveCursor(final Item toMoveTo) {
19 if(toMoveTo == null) return false;
20 if(toMoveTo instanceof Text) {
21 final Text asText = (Text) toMoveTo;
22 final Font font = asText.getFont();
23 final int indent = Browser._theBrowser.g.getFontMetrics(font).charWidth(asText.getText().charAt(0));
24 final Point position = toMoveTo.getPosition();
25 DisplayIO.setCursorPosition(position.x + indent, position.y, false);
26 FrameGraphics.refresh(false);
27 } else DisplayIO.setCursorPosition(toMoveTo.getPosition(), false);
28 return true;
29 }
30
31}
Note: See TracBrowser for help on using the repository browser.