diff --git a/src/Str.java b/src/Str.java new file mode 100644 index 0000000..bc24f73 --- /dev/null +++ b/src/Str.java @@ -0,0 +1,82 @@ + + + +/** + * General purpose string utilities + * + * @author Ondřej Hruška (MightyPork) + */ +public class Str { + + public static String fromLastDot(String s) + { + return fromLastChar(s, '.'); + } + + + public static String toLastDot(String s) + { + return toLastChar(s, '.'); + } + + + public static String fromLastChar(String s, char c) + { + if (s == null) return null; + return s.substring(s.lastIndexOf(c) + 1, s.length()); + } + + + public static String toLastChar(String s, char c) + { + if (s == null) return null; + if (s.lastIndexOf(c) == -1) return s; + return s.substring(0, s.lastIndexOf(c)); + } + + + /** + * Repeat a string + * + * @param repeated string + * @param count + * @return output + */ + public static String repeat(String repeated, int count) + { + String s = ""; + for (int i = 0; i < count; i++) + s += repeated; + return s; + } + + + public static boolean isValidFilenameChar(char ch) + { + return isValidFilenameString(Character.toString(ch)); + } + + + public static boolean isValidFilenameString(String filename) + { + return filename.matches("[a-zA-Z0-9 +\\-.,_%@#!]+"); + } + + + public static String ellipsisStart(String orig, int length) + { + if (orig.length() > length) { + orig = "\u2026" + orig.substring(length, orig.length()); + } + return orig; + } + + + public static String ellipsisEnd(String orig, int length) + { + if (orig.length() > length) { + orig = orig.substring(0, length - 1) + "\u2026"; + } + return orig; + } +} diff --git a/src/mightypork/utils/eventbus/clients/DelegatingList.java b/src/mightypork/utils/eventbus/clients/DelegatingList.java index 6af7ea3..29b94ff 100644 --- a/src/mightypork/utils/eventbus/clients/DelegatingList.java +++ b/src/mightypork/utils/eventbus/clients/DelegatingList.java @@ -11,7 +11,7 @@ import mightypork.utils.interfaces.Enableable; * * @author Ondřej Hruška (MightyPork) */ -public class DelegatingList extends ClientList implements DelegatingClient, Enableable { +public class DelegatingList extends ClientList implements DelegatingClient, Enableable, ToggleableClient { private boolean enabled = true; @@ -47,6 +47,13 @@ public class DelegatingList extends ClientList implements DelegatingClient, Enab } + @Override + public boolean isListening() + { + return isEnabled(); + } + + @Override public void setEnabled(boolean yes) { diff --git a/src/mightypork/utils/math/color/Grad.java b/src/mightypork/utils/math/color/Grad.java new file mode 100644 index 0000000..7385b6a --- /dev/null +++ b/src/mightypork/utils/math/color/Grad.java @@ -0,0 +1,30 @@ +package mightypork.utils.math.color; + + + + +/** + * Linear gradient (each corner can have different color) + * + * @author MightyPork + */ +public class Grad { + + public final Color leftTop, rightTop, rightBottom, leftBottom; + + + /** + * Create a gradient + * + * @param leftTop left top color + * @param rightTop right top color + * @param rightBottom right bottom color + * @param leftBottom left bottom color + */ + public Grad(Color leftTop, Color rightTop, Color rightBottom, Color leftBottom) { + this.leftTop = leftTop; + this.rightTop = rightTop; + this.rightBottom = rightBottom; + this.leftBottom = leftBottom; + } +} diff --git a/src/mightypork/utils/math/color/GradH.java b/src/mightypork/utils/math/color/GradH.java new file mode 100644 index 0000000..17d758c --- /dev/null +++ b/src/mightypork/utils/math/color/GradH.java @@ -0,0 +1,16 @@ +package mightypork.utils.math.color; + + + + +/** + * Linear horizontal gradient + * + * @author MightyPork + */ +public class GradH extends Grad { + + public GradH(Color left, Color right) { + super(left, right, right, left); + } +} diff --git a/src/mightypork/utils/math/color/GradV.java b/src/mightypork/utils/math/color/GradV.java new file mode 100644 index 0000000..b723d25 --- /dev/null +++ b/src/mightypork/utils/math/color/GradV.java @@ -0,0 +1,16 @@ +package mightypork.utils.math.color; + + + + +/** + * Linear vertical gradient + * + * @author MightyPork + */ +public class GradV extends Grad { + + public GradV(Color top, Color bottom) { + super(top, top, bottom, bottom); + } +}