001package Torello.Browser.BrowserAPI; 002 003import java.util.*; 004import javax.json.*; 005import javax.json.stream.*; 006import java.io.*; 007 008import java.lang.reflect.Method; 009import java.lang.reflect.Parameter; 010import java.util.function.Function; 011 012import Torello.Browser.BrowserEvent; 013import Torello.Browser.JavaScriptAPI.*; 014import Torello.Browser.helper.*; 015 016import Torello.Java.Additional.*; 017import Torello.Java.JSON.*; 018 019import static Torello.Java.JSON.JFlag.*; 020 021import Torello.Java.StrCmpr; 022import Torello.JavaDoc.StaticFunctional; 023import Torello.JavaDoc.JDHeaderBackgroundImg; 024import Torello.JavaDoc.Excuse; 025 026/** 027 * <SPAN CLASS=COPIEDJDK><B><CODE>[No Description Provided by Google]</CODE></B></SPAN> 028 * 029 * <EMBED CLASS='external-html' DATA-FILE-ID=CODE_GEN_NOTE> 030 */ 031@StaticFunctional(Excused={"counter"}, Excuses={Excuse.CONFIGURATION}) 032@JDHeaderBackgroundImg(EmbedTagFileID="WOOD_PLANK_NOTE") 033public class DeviceOrientation 034{ 035 // ******************************************************************************************** 036 // ******************************************************************************************** 037 // Class Header Stuff 038 // ******************************************************************************************** 039 // ******************************************************************************************** 040 041 042 // No Pubic Constructors 043 private DeviceOrientation () { } 044 045 // These two Vector's are used by all the "Methods" exported by this class. java.lang.reflect 046 // is used to generate the JSON String's. It saves thousands of lines of Auto-Generated Code. 047 private static final Map<String, Vector<String>> parameterNames = new HashMap<>(); 048 private static final Map<String, Vector<Class<?>>> parameterTypes = new HashMap<>(); 049 050 // Some Methods do not take any parameters - for instance all the "enable()" and "disable()" 051 // I simply could not get ride of RAW-TYPES and UNCHECKED warnings... so there are now, 052 // offically, two empty-vectors. One for String's, and the other for Classes. 053 054 private static final Vector<String> EMPTY_VEC_STR = new Vector<>(); 055 private static final Vector<Class<?>> EMPTY_VEC_CLASS = new Vector<>(); 056 057 static 058 { 059 for (Method m : DeviceOrientation.class.getMethods()) 060 { 061 // This doesn't work! The parameter names are all "arg0" ... "argN" 062 // It works for java.lang.reflect.Field, BUT NOT java.lang.reflect.Parameter! 063 // 064 // Vector<String> parameterNamesList = new Vector<>(); -- NOPE! 065 066 Vector<Class<?>> parameterTypesList = new Vector<>(); 067 068 for (Parameter p : m.getParameters()) parameterTypesList.add(p.getType()); 069 070 parameterTypes.put( 071 m.getName(), 072 (parameterTypesList.size() > 0) ? parameterTypesList : EMPTY_VEC_CLASS 073 ); 074 } 075 } 076 077 static 078 { 079 Vector<String> v = null; 080 081 parameterNames.put("clearDeviceOrientationOverride", EMPTY_VEC_STR); 082 083 v = new Vector<String>(3); 084 parameterNames.put("setDeviceOrientationOverride", v); 085 Collections.addAll(v, new String[] 086 { "alpha", "beta", "gamma", }); 087 } 088 089 090 // ******************************************************************************************** 091 // ******************************************************************************************** 092 // Types - Static Inner Classes 093 // ******************************************************************************************** 094 // ******************************************************************************************** 095 096 097 // Counter for keeping the WebSocket Request ID's distinct. 098 private static int counter = 1; 099 100 /** 101 * Clears the overridden Device Orientation. 102 * 103 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 104 * {@link Ret0}></CODE> 105 * 106 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 107 * browser receives the invocation-request. 108 * 109 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 110 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 111 * {@code >} to ensure the Browser Function has run to completion. 112 */ 113 public static Script<String, JsonObject, Ret0> clearDeviceOrientationOverride() 114 { 115 final int webSocketID = 22000000 + counter++; 116 final boolean[] optionals = new boolean[0]; 117 118 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 119 String requestJSON = WriteJSON.get( 120 parameterTypes.get("clearDeviceOrientationOverride"), 121 parameterNames.get("clearDeviceOrientationOverride"), 122 optionals, webSocketID, 123 "DeviceOrientation.clearDeviceOrientationOverride" 124 ); 125 126 // This Remote Command does not have a Return-Value. 127 return new Script<> 128 (webSocketID, requestJSON, VOID_RETURN.NoReturnValues); 129 } 130 131 /** 132 * Overrides the Device Orientation. 133 * 134 * @param alpha Mock alpha 135 * 136 * @param beta Mock beta 137 * 138 * @param gamma Mock gamma 139 * 140 * @return An instance of <CODE>{@link Script}<String, {@link JsonObject}, 141 * {@link Ret0}></CODE> 142 * 143 * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the 144 * browser receives the invocation-request. 145 * 146 * <BR /><BR />This Browser-Function <I>does not have</I> a return-value. You may choose to 147 * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0} 148 * {@code >} to ensure the Browser Function has run to completion. 149 */ 150 public static Script<String, JsonObject, Ret0> setDeviceOrientationOverride 151 (Number alpha, Number beta, Number gamma) 152 { 153 // Exception-Check(s) to ensure that if any parameters which are not declared as 154 // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw. 155 156 if (alpha == null) THROWS.throwNPE("alpha"); 157 if (beta == null) THROWS.throwNPE("beta"); 158 if (gamma == null) THROWS.throwNPE("gamma"); 159 160 final int webSocketID = 22001000 + counter++; 161 final boolean[] optionals = { false, false, false, }; 162 163 // Convert Method Parameters into JSON. Build the JSON Request-Object (as a String) 164 String requestJSON = WriteJSON.get( 165 parameterTypes.get("setDeviceOrientationOverride"), 166 parameterNames.get("setDeviceOrientationOverride"), 167 optionals, webSocketID, 168 "DeviceOrientation.setDeviceOrientationOverride", 169 alpha, beta, gamma 170 ); 171 172 // This Remote Command does not have a Return-Value. 173 return new Script<> 174 (webSocketID, requestJSON, VOID_RETURN.NoReturnValues); 175 } 176 177}