, CLIENT> {
/**
- * Check if the given event can be broadcasted by this {@link EventChannel}
+ * Check if the given event can be broadcasted by this channel
*
* @param event event object
* @return can be broadcasted
diff --git a/src/mightypork/util/control/eventbus/clients/BusNode.java b/src/mightypork/util/control/eventbus/clients/BusNode.java
index c2e36ca..52d79f5 100644
--- a/src/mightypork/util/control/eventbus/clients/BusNode.java
+++ b/src/mightypork/util/control/eventbus/clients/BusNode.java
@@ -65,9 +65,7 @@ public abstract class BusNode implements BusAccess, ClientHub {
throw new IllegalArgumentException("Cannot nest RootBusNode.");
}
- if (getEventBus().isClientValid(client)) {
- clients.add(client);
- }
+ clients.add(client);
}
diff --git a/src/mightypork/util/control/eventbus/events/Event.java b/src/mightypork/util/control/eventbus/events/Event.java
index 19fbbd5..7a4780a 100644
--- a/src/mightypork/util/control/eventbus/events/Event.java
+++ b/src/mightypork/util/control/eventbus/events/Event.java
@@ -9,7 +9,7 @@ import mightypork.util.control.eventbus.events.flags.UnloggedEvent;
/**
*
- * Something that can be handled by HANDLER.
+ * Something that can be handled by HANDLER, subscribing to the event bus.
*
*
* Can be annotated as {@link SingleReceiverEvent} to be delivered once only,
diff --git a/src/mightypork/util/files/FileTreeDiff.java b/src/mightypork/util/files/FileTreeDiff.java
index 41d4cfc..44cec84 100644
--- a/src/mightypork/util/files/FileTreeDiff.java
+++ b/src/mightypork/util/files/FileTreeDiff.java
@@ -72,9 +72,11 @@ public class FileTreeDiff {
ck1.reset();
ck2.reset();
- try (FileInputStream in1 = new FileInputStream(pair.a); FileInputStream in2 = new FileInputStream(pair.b)) {
+ try(FileInputStream in1 = new FileInputStream(pair.a);
+ FileInputStream in2 = new FileInputStream(pair.b)) {
- try (CheckedInputStream cin1 = new CheckedInputStream(in1, ck1); CheckedInputStream cin2 = new CheckedInputStream(in2, ck2)) {
+ try(CheckedInputStream cin1 = new CheckedInputStream(in1, ck1);
+ CheckedInputStream cin2 = new CheckedInputStream(in2, ck2)) {
while (true) {
final int read1 = cin1.read(BUFFER);
diff --git a/src/mightypork/util/files/FileUtils.java b/src/mightypork/util/files/FileUtils.java
index 88835f7..acb4419 100644
--- a/src/mightypork/util/files/FileUtils.java
+++ b/src/mightypork/util/files/FileUtils.java
@@ -95,7 +95,8 @@ public class FileUtils {
public static void copyFile(File source, File target) throws IOException
{
- try (InputStream in = new FileInputStream(source); OutputStream out = new FileOutputStream(target)) {
+ try(InputStream in = new FileInputStream(source);
+ OutputStream out = new FileOutputStream(target)) {
copyStream(in, out);
}
@@ -160,7 +161,7 @@ public class FileUtils {
*/
public static String fileToString(File file) throws IOException
{
- try (FileInputStream fin = new FileInputStream(file)) {
+ try(FileInputStream fin = new FileInputStream(file)) {
return streamToString(fin);
}
@@ -360,7 +361,7 @@ public class FileUtils {
*/
public static void stringToFile(File file, String text) throws IOException
{
- try (PrintStream out = new PrintStream(new FileOutputStream(file), false, "UTF-8")) {
+ try(PrintStream out = new PrintStream(new FileOutputStream(file), false, "UTF-8")) {
out.print(text);
@@ -481,7 +482,8 @@ public class FileUtils {
*/
public static void resourceToFile(String resname, File file) throws IOException
{
- try (InputStream in = FileUtils.getResource(resname); OutputStream out = new FileOutputStream(file)) {
+ try(InputStream in = FileUtils.getResource(resname);
+ OutputStream out = new FileOutputStream(file)) {
FileUtils.copyStream(in, out);
}
@@ -498,7 +500,7 @@ public class FileUtils {
*/
public static String resourceToString(String resname) throws IOException
{
- try (InputStream in = FileUtils.getResource(resname)) {
+ try(InputStream in = FileUtils.getResource(resname)) {
return streamToString(in);
}
}
diff --git a/src/mightypork/util/files/ion/Ion.java b/src/mightypork/util/files/ion/Ion.java
index 1ce8735..475e005 100644
--- a/src/mightypork/util/files/ion/Ion.java
+++ b/src/mightypork/util/files/ion/Ion.java
@@ -67,7 +67,7 @@ public class Ion {
*/
public static Object fromFile(File file) throws IonException
{
- try (InputStream in = new FileInputStream(file)) {
+ try(InputStream in = new FileInputStream(file)) {
final Object obj = fromStream(in);
return obj;
@@ -113,7 +113,7 @@ public class Ion {
*/
public static void toFile(File path, Object obj) throws IonException
{
- try (OutputStream out = new FileOutputStream(path)) {
+ try(OutputStream out = new FileOutputStream(path)) {
final String f = path.toString();
final File dir = new File(f.substring(0, f.lastIndexOf(File.separator)));
diff --git a/src/mightypork/util/files/zip/ZipBuilder.java b/src/mightypork/util/files/zip/ZipBuilder.java
index 98fbd9a..85dcd27 100644
--- a/src/mightypork/util/files/zip/ZipBuilder.java
+++ b/src/mightypork/util/files/zip/ZipBuilder.java
@@ -75,7 +75,7 @@ public class ZipBuilder {
out.putNextEntry(new ZipEntry(path));
- try (InputStream in = FileUtils.stringToStream(text)) {
+ try(InputStream in = FileUtils.stringToStream(text)) {
FileUtils.copyStream(in, out);
}
}
@@ -96,7 +96,7 @@ public class ZipBuilder {
out.putNextEntry(new ZipEntry(path));
- try (InputStream in = FileUtils.getResource(resPath)) {
+ try(InputStream in = FileUtils.getResource(resPath)) {
FileUtils.copyStream(in, out);
}
}
diff --git a/src/mightypork/util/files/zip/ZipUtils.java b/src/mightypork/util/files/zip/ZipUtils.java
index a647efb..a136bcd 100644
--- a/src/mightypork/util/files/zip/ZipUtils.java
+++ b/src/mightypork/util/files/zip/ZipUtils.java
@@ -34,7 +34,7 @@ public class ZipUtils {
*/
public static List extractZip(File file, File outputDir, StringFilter filter) throws IOException
{
- try (ZipFile zip = new ZipFile(file)) {
+ try(ZipFile zip = new ZipFile(file)) {
return extractZip(zip, outputDir, filter);
}
}
@@ -90,7 +90,7 @@ public class ZipUtils {
*/
public static List listZip(File zipFile) throws IOException
{
- try (ZipFile zip = new ZipFile(zipFile)) {
+ try(ZipFile zip = new ZipFile(zipFile)) {
return listZip(zip);
}
}
@@ -134,7 +134,10 @@ public class ZipUtils {
{
if (!destFile.getParentFile().mkdirs()) throw new IOException("Could not create output directory.");
- try (InputStream in = zip.getInputStream(entry); BufferedInputStream is = new BufferedInputStream(in); FileOutputStream fos = new FileOutputStream(destFile); BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) {
+ try(InputStream in = zip.getInputStream(entry);
+ BufferedInputStream is = new BufferedInputStream(in);
+ FileOutputStream fos = new FileOutputStream(destFile);
+ BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) {
FileUtils.copyStream(is, dest);
}
@@ -168,7 +171,7 @@ public class ZipUtils {
public static boolean entryExists(File selectedFile, String string)
{
- try (ZipFile zf = new ZipFile(selectedFile)) {
+ try(ZipFile zf = new ZipFile(selectedFile)) {
return zf.getEntry(string) != null;
} catch (final IOException | RuntimeException e) {
Log.w("Error reading zip.", e);
diff --git a/src/mightypork/util/math/color/CGA.java b/src/mightypork/util/math/color/CGA.java
new file mode 100644
index 0000000..e3e142d
--- /dev/null
+++ b/src/mightypork/util/math/color/CGA.java
@@ -0,0 +1,29 @@
+package mightypork.util.math.color;
+
+
+/**
+ * CGA palette
+ *
+ * @author MightyPork
+ */
+public interface CGA {
+
+ Color BLACK = Color.fromHex(0x000000);
+ Color GRAY_DARK = Color.fromHex(0x686868);
+ Color GRAY_LIGHT = Color.fromHex(0xB8B8B8);
+ Color WHITE = Color.fromHex(0xFFFFFF);
+
+ Color RED_DARK = Color.fromHex(0xC41F0C);
+ Color RED_LIGHT = Color.fromHex(0xFF706A);
+ Color MAGENTA_DARK = Color.fromHex(0xC12BB6);
+ Color MAGENTA_LIGHT = Color.fromHex(0xFF76FD);
+ Color BLUE_DARK = Color.fromHex(0x0019B6);
+ Color BLUE_LIGHT = Color.fromHex(0x5F6EFC);
+ Color CYAN_DARK = Color.fromHex(0x00B6B8);
+ Color CYAN_LIGHT = Color.fromHex(0x23FCFE);
+ Color GREEN_DARK = Color.fromHex(0x00B41D);
+ Color GREEN_LIGHT = Color.fromHex(0x39FA6F);
+
+ Color YELLOW = Color.fromHex(0xFFFD72);
+ Color BROWN = Color.fromHex(0xC16A14);
+}
diff --git a/src/mightypork/util/math/color/COMMODORE.java b/src/mightypork/util/math/color/COMMODORE.java
new file mode 100644
index 0000000..ab8ad61
--- /dev/null
+++ b/src/mightypork/util/math/color/COMMODORE.java
@@ -0,0 +1,27 @@
+package mightypork.util.math.color;
+
+
+/**
+ * COMMODORE palette
+ *
+ * @author MightyPork
+ */
+public interface COMMODORE {
+
+ Color BLACK = Color.fromHex(0x040013);
+ Color WHITE = Color.fromHex(0xFFFFFF);
+ Color RED = Color.fromHex(0x883932);
+ Color CYAN = Color.fromHex(0x67B6BD);
+ Color PURPLE = Color.fromHex(0x8B3F96);
+ Color GREEN = Color.fromHex(0x55A049);
+ Color BLUE = Color.fromHex(0x40318D);
+ Color YELLOW = Color.fromHex(0xBFCE72);
+ Color ORANGE = Color.fromHex(0x8B5429);
+ Color BROWN = Color.fromHex(0x574200);
+ Color RED_LIGHT = Color.fromHex(0xB86962);
+ Color GRAY_DARK = Color.fromHex(0x505050);
+ Color GRAY = Color.fromHex(0x787878);
+ Color GREEN_LIGHT = Color.fromHex(0x94E089);
+ Color BLUE_LIGHT = Color.fromHex(0x7869C4);
+ Color GRAY_LIGHT = Color.fromHex(0x9F9F9F);
+}
diff --git a/src/mightypork/util/math/color/Color.java b/src/mightypork/util/math/color/Color.java
index 732ae31..864304c 100644
--- a/src/mightypork/util/math/color/Color.java
+++ b/src/mightypork/util/math/color/Color.java
@@ -19,9 +19,9 @@ public abstract class Color {
public static final Color NONE = rgba(0, 0, 0, 0);
public static final Color SHADOW = rgba(0, 0, 0, 0.5);
- public static final Color WHITE = rgb(1, 1, 1);
- public static final Color BLACK = rgb(0, 0, 0);
- public static final Color DARK_GRAY = rgb(0.25, 0.25, 0.25);
+ public static final Color WHITE = fromHex(0xFFFFFF);
+ public static final Color BLACK = fromHex(0x000000);
+ public static final Color DARK_GRAY = fromHex(0x808080);
public static final Color GRAY = rgb(0.5, 0.5, 0.5);
public static final Color LIGHT_GRAY = rgb(0.75, 0.75, 0.75);
@@ -40,6 +40,16 @@ public abstract class Color {
private static volatile boolean alphaStackEnabled = true;
+ @FactoryMethod
+ public static final Color fromHex(int rgb_hex)
+ {
+ final int bi = rgb_hex & 0xff;
+ final int gi = (rgb_hex >> 8) & 0xff;
+ final int ri = (rgb_hex >> 16) & 0xff;
+ return rgb(ri / 255D, gi / 255D, bi / 255D);
+ }
+
+
@FactoryMethod
public static final Color rgb(double r, double g, double b)
{
@@ -163,7 +173,7 @@ public abstract class Color {
if (alphaStackEnabled) {
- for (Num n : alphaStack) {
+ for (final Num n : alphaStack) {
alpha *= clamp(n.value());
}
}
@@ -241,4 +251,16 @@ public abstract class Color {
{
return alphaStackEnabled;
}
+
+
+ public Color withAlpha(double multiplier)
+ {
+ return new ColorAlphaAdjuster(this, Num.make(multiplier));
+ }
+
+
+ public Color withAlpha(Num multiplier)
+ {
+ return new ColorAlphaAdjuster(this, Num.make(multiplier));
+ }
}
diff --git a/src/mightypork/util/math/color/ColorAlphaAdjuster.java b/src/mightypork/util/math/color/ColorAlphaAdjuster.java
new file mode 100644
index 0000000..3868789
--- /dev/null
+++ b/src/mightypork/util/math/color/ColorAlphaAdjuster.java
@@ -0,0 +1,46 @@
+package mightypork.util.math.color;
+
+
+import mightypork.util.constraints.num.Num;
+
+
+public class ColorAlphaAdjuster extends Color {
+
+ private final Color source;
+ private final Num alphaAdjust;
+
+
+ public ColorAlphaAdjuster(Color source, Num alphaMul) {
+ this.source = source;
+ this.alphaAdjust = alphaMul;
+ }
+
+
+ @Override
+ public double red()
+ {
+ return source.red();
+ }
+
+
+ @Override
+ public double green()
+ {
+ return source.green();
+ }
+
+
+ @Override
+ public double blue()
+ {
+ return source.blue();
+ }
+
+
+ @Override
+ protected double rawAlpha()
+ {
+ return source.rawAlpha() * alphaAdjust.value();
+ }
+
+}
diff --git a/src/mightypork/util/math/color/PAL16.java b/src/mightypork/util/math/color/PAL16.java
new file mode 100644
index 0000000..42922f8
--- /dev/null
+++ b/src/mightypork/util/math/color/PAL16.java
@@ -0,0 +1,31 @@
+package mightypork.util.math.color;
+
+
+/**
+ * PAL16 palette via http://androidarts.com/palette/16pal.htm
+ *
+ * @author MightyPork
+ */
+public interface PAL16 {
+
+ Color VOID = Color.fromHex(0x000000);
+ Color ASH = Color.fromHex(0x9D9D9D);
+ Color BLIND = Color.fromHex(0xFFFFFF);
+
+ Color BLOODRED = Color.fromHex(0xBE2633);
+ Color PIGMEAT = Color.fromHex(0xE06F8B);
+
+ Color OLDPOOP = Color.fromHex(0x493C2B);
+ Color NEWPOOP = Color.fromHex(0xA46422);
+ Color BLAZE = Color.fromHex(0xEB8931);
+ Color ZORNSKIN = Color.fromHex(0xF7E26B);
+
+ Color SHADEGREEN = Color.fromHex(0x2F484E);
+ Color LEAFGREEN = Color.fromHex(0x44891A);
+ Color SLIMEGREEN = Color.fromHex(0xA3CE27);
+
+ Color NIGHTBLUE = Color.fromHex(0x1B2632);
+ Color SEABLUE = Color.fromHex(0x005784);
+ Color SKYBLUE = Color.fromHex(0x31A2F2);
+ Color CLOUDBLUE = Color.fromHex(0xB2DCEF);
+}
diff --git a/src/mightypork/util/math/color/RGB.java b/src/mightypork/util/math/color/RGB.java
new file mode 100644
index 0000000..ec48861
--- /dev/null
+++ b/src/mightypork/util/math/color/RGB.java
@@ -0,0 +1,26 @@
+package mightypork.util.math.color;
+
+
+/**
+ * Basic RGB palette
+ *
+ * @author MightyPork
+ */
+public interface RGB {
+
+ Color WHITE = Color.fromHex(0xFFFFFF);
+ Color BLACK = Color.fromHex(0x000000);
+ Color GRAY_DARK = Color.fromHex(0x808080);
+ Color GRAY_LIGHT = Color.fromHex(0xC0C0C0);
+
+ Color RED = Color.fromHex(0xFF0000);
+ Color GREEN = Color.fromHex(0x00FF00);
+ Color BLUE = Color.fromHex(0x0000FF);
+
+ Color YELLOW = Color.fromHex(0xFFFF00);
+ Color CYAN = Color.fromHex(0x00FFFF);
+ Color MAGENTA = Color.fromHex(0xFF00FF);
+
+ Color PINK = Color.fromHex(0xFF3FFC);
+ Color ORANGE = Color.fromHex(0xFC4800);
+}
diff --git a/src/mightypork/util/math/color/ZX.java b/src/mightypork/util/math/color/ZX.java
new file mode 100644
index 0000000..418082a
--- /dev/null
+++ b/src/mightypork/util/math/color/ZX.java
@@ -0,0 +1,28 @@
+package mightypork.util.math.color;
+
+
+/**
+ * ZX Spectrum palette
+ *
+ * @author MightyPork
+ */
+public interface ZX {
+
+ Color BLACK = Color.fromHex(0x000000);
+ Color GRAY = Color.fromHex(0xCBCBCB);
+ Color WHITE = Color.fromHex(0xFFFFFF);
+
+ Color RED_DARK = Color.fromHex(0xD8240F);
+ Color RED_LIGHT = Color.fromHex(0xFF3016);
+ Color MAGENTA_DARK = Color.fromHex(0xD530C9);
+ Color MAGENTA_LIGHT = Color.fromHex(0xFF3FFC);
+ Color BLUE_DARK = Color.fromHex(0x001DC8);
+ Color BLUE_LIGHT = Color.fromHex(0x0027FB);
+ Color CYAN_DARK = Color.fromHex(0x00C9CB);
+ Color CYAN_LIGHT = Color.fromHex(0xFFFD33);
+ Color GREEN_DARK = Color.fromHex(0x00C721);
+ Color GREEN_LIGHT = Color.fromHex(0x00F92C);
+
+ Color YELLOW_DARK = Color.fromHex(0xCECA26);
+ Color YELLOW_LIGHT = Color.fromHex(0xFFFD33);
+}