final/src/UtilityFunction.java

33 lines
1.1 KiB
Java

import java.awt.event.KeyEvent;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.lang.reflect.Array;
import java.util.ArrayList;
public final class UtilityFunction {
private UtilityFunction(){}
public static KeyEvent intercept(KeyEvent e, ArrayList<Middleware> middlewareArray) {
for (Middleware m: middlewareArray) {
if (m.canIntercept(e)) {
e = m.interceptKey(e);
return e;
}
}
return e;
}
public static int processBox(KeyEvent e, int currentBox, ArrayList<TextBox> textBoxArray) {
if (e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_W) {
// if currentBox > 0, subtract one
// else, set to TOTAL_BOXES-1
return currentBox > 0 ? currentBox - 1:textBoxArray.size() - 1;
} else if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_S) {
// if currentBox > total box amount - 1, set to 0
// else, set to TOTAL_BOXES-1
return currentBox < textBoxArray.size() - 1 ? currentBox + 1:0;
}
return currentBox;
}
}