source: trunk/src/org/expeditee/items/MagneticConstraint/Utilities/TextLogic.java@ 1102

Last change on this file since 1102 was 1102, checked in by davidb, 6 years ago

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File size: 1.7 KB
Line 
1package org.expeditee.items.MagneticConstraint.Utilities;
2
3import org.expeditee.gio.EcosystemManager;
4import org.expeditee.gui.DisplayController;
5import org.expeditee.items.Text;
6
7public class TextLogic {
8
9 public static boolean XIsTowardsRight(final int x, final Text text) {
10 if(text.getPixelBoundsUnion() == null) return false;
11 final double distanceThroughText = x - text.getPixelBoundsUnion().getMinX();
12 return /*text.getText().length() == 1 ||*/ distanceThroughText > (text.getPixelBoundsUnion().getWidth() / 2);
13 }
14
15 public static boolean XIsTowardsLeft(final Text text, final int x) {
16 if(text.getPixelBoundsUnion() == null) return false;
17 final double distanceThroughText = x - text.getPixelBoundsUnion().getMinX();
18 return distanceThroughText < (text.getPixelBoundsUnion().getWidth() / 2);
19 }
20
21 public static boolean XIsBeforeCharacters(final Text text, final int x) {
22 try {
23 final int firstLetterWidth = EcosystemManager.getTextLayoutManager().getStringWidth(null, text.getText().substring(0, 1));
24 final double distanceThroughText = x - text.getPixelBoundsUnion().getMinX();
25 return firstLetterWidth > distanceThroughText;
26 } catch (NullPointerException e) {
27 return false;
28 } catch (StringIndexOutOfBoundsException e) {
29 return false;
30 }
31 }
32
33 public static boolean XIsAfterCharacters(final Text text, final int x) {
34 try {
35 final double distanceThroughText = x - text.getPixelBoundsUnion().getMinX();
36 return distanceThroughText > text.getPixelBoundsUnion().getWidth();
37 } catch (NullPointerException e) {
38 return false;
39 }
40 }
41
42 public static int GetInsertionIndexSelected(final Text text) {
43 return text.getCharPosition(0, DisplayController.getMouseX()).getInsertionIndex();
44 }
45}
Note: See TracBrowser for help on using the repository browser.