Skip to content

Commit 4cf2348

Browse files
committed
new-style switch statements
1 parent 93ef064 commit 4cf2348

File tree

1 file changed

+30
-55
lines changed

1 file changed

+30
-55
lines changed

core/src/processing/opengl/PSurfaceJOGL.java

Lines changed: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,18 +1019,12 @@ protected void nativeMouseEvent(com.jogamp.newt.event.MouseEvent nativeEvent,
10191019
InputEvent.ALT_MASK);
10201020
*/
10211021

1022-
int peButton = 0;
1023-
switch (nativeEvent.getButton()) {
1024-
case com.jogamp.newt.event.MouseEvent.BUTTON1:
1025-
peButton = PConstants.LEFT;
1026-
break;
1027-
case com.jogamp.newt.event.MouseEvent.BUTTON2:
1028-
peButton = PConstants.CENTER;
1029-
break;
1030-
case com.jogamp.newt.event.MouseEvent.BUTTON3:
1031-
peButton = PConstants.RIGHT;
1032-
break;
1033-
}
1022+
int peButton = switch (nativeEvent.getButton()) {
1023+
case com.jogamp.newt.event.MouseEvent.BUTTON1 -> PConstants.LEFT;
1024+
case com.jogamp.newt.event.MouseEvent.BUTTON2 -> PConstants.CENTER;
1025+
case com.jogamp.newt.event.MouseEvent.BUTTON3 -> PConstants.RIGHT;
1026+
default -> 0;
1027+
};
10341028

10351029
int peCount;
10361030
if (peAction == MouseEvent.WHEEL) {
@@ -1150,58 +1144,39 @@ private static boolean isPCodedKey(short code, boolean printable) {
11501144
// Relevant discussion and links here:
11511145
// http://forum.jogamp.org/Newt-wrong-keycode-for-key-td4033690.html#a4033697
11521146
// (I don't think this is a complete solution).
1153-
@SuppressWarnings("SuspiciousNameCombination")
11541147
private static int mapToPConst(short code) {
1155-
switch (code) {
1156-
case com.jogamp.newt.event.KeyEvent.VK_UP:
1157-
return PConstants.UP;
1158-
case com.jogamp.newt.event.KeyEvent.VK_DOWN:
1159-
return PConstants.DOWN;
1160-
case com.jogamp.newt.event.KeyEvent.VK_LEFT:
1161-
return PConstants.LEFT;
1162-
case com.jogamp.newt.event.KeyEvent.VK_RIGHT:
1163-
return PConstants.RIGHT;
1164-
case com.jogamp.newt.event.KeyEvent.VK_ALT:
1165-
return PConstants.ALT;
1166-
case com.jogamp.newt.event.KeyEvent.VK_CONTROL:
1167-
return PConstants.CONTROL;
1168-
case com.jogamp.newt.event.KeyEvent.VK_SHIFT:
1169-
return PConstants.SHIFT;
1170-
case com.jogamp.newt.event.KeyEvent.VK_WINDOWS:
1171-
return java.awt.event.KeyEvent.VK_META;
1172-
default:
1173-
return code;
1174-
}
1148+
return switch (code) {
1149+
case com.jogamp.newt.event.KeyEvent.VK_UP -> PConstants.UP;
1150+
case com.jogamp.newt.event.KeyEvent.VK_DOWN -> PConstants.DOWN;
1151+
case com.jogamp.newt.event.KeyEvent.VK_LEFT -> PConstants.LEFT;
1152+
case com.jogamp.newt.event.KeyEvent.VK_RIGHT -> PConstants.RIGHT;
1153+
case com.jogamp.newt.event.KeyEvent.VK_ALT -> PConstants.ALT;
1154+
case com.jogamp.newt.event.KeyEvent.VK_CONTROL -> PConstants.CONTROL;
1155+
case com.jogamp.newt.event.KeyEvent.VK_SHIFT -> PConstants.SHIFT;
1156+
case com.jogamp.newt.event.KeyEvent.VK_WINDOWS -> java.awt.event.KeyEvent.VK_META;
1157+
default -> code;
1158+
};
11751159
}
11761160

11771161

11781162
private static boolean isHackyKey(short code) {
1179-
switch (code) {
1180-
case com.jogamp.newt.event.KeyEvent.VK_BACK_SPACE:
1181-
case com.jogamp.newt.event.KeyEvent.VK_TAB:
1182-
case com.jogamp.newt.event.KeyEvent.VK_ENTER:
1183-
case com.jogamp.newt.event.KeyEvent.VK_ESCAPE:
1184-
case com.jogamp.newt.event.KeyEvent.VK_DELETE:
1185-
return true;
1186-
}
1187-
return false;
1163+
return (code == com.jogamp.newt.event.KeyEvent.VK_BACK_SPACE ||
1164+
code == com.jogamp.newt.event.KeyEvent.VK_TAB ||
1165+
code == com.jogamp.newt.event.KeyEvent.VK_ENTER ||
1166+
code == com.jogamp.newt.event.KeyEvent.VK_ESCAPE ||
1167+
code == com.jogamp.newt.event.KeyEvent.VK_DELETE);
11881168
}
11891169

11901170

11911171
private static char hackToChar(short code, char def) {
1192-
switch (code) {
1193-
case com.jogamp.newt.event.KeyEvent.VK_BACK_SPACE:
1194-
return PConstants.BACKSPACE;
1195-
case com.jogamp.newt.event.KeyEvent.VK_TAB:
1196-
return PConstants.TAB;
1197-
case com.jogamp.newt.event.KeyEvent.VK_ENTER:
1198-
return PConstants.ENTER;
1199-
case com.jogamp.newt.event.KeyEvent.VK_ESCAPE:
1200-
return PConstants.ESC;
1201-
case com.jogamp.newt.event.KeyEvent.VK_DELETE:
1202-
return PConstants.DELETE;
1203-
}
1204-
return def;
1172+
return switch (code) {
1173+
case com.jogamp.newt.event.KeyEvent.VK_BACK_SPACE -> PConstants.BACKSPACE;
1174+
case com.jogamp.newt.event.KeyEvent.VK_TAB -> PConstants.TAB;
1175+
case com.jogamp.newt.event.KeyEvent.VK_ENTER -> PConstants.ENTER;
1176+
case com.jogamp.newt.event.KeyEvent.VK_ESCAPE -> PConstants.ESC;
1177+
case com.jogamp.newt.event.KeyEvent.VK_DELETE -> PConstants.DELETE;
1178+
default -> def;
1179+
};
12051180
}
12061181

12071182

0 commit comments

Comments
 (0)