1 | package org.expeditee.items.MagneticConstraint.Utilities;
|
---|
2 |
|
---|
3 | import org.expeditee.gio.EcosystemManager;
|
---|
4 | import org.expeditee.gui.DisplayController;
|
---|
5 | import org.expeditee.items.Text;
|
---|
6 |
|
---|
7 | public 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 | }
|
---|