Skip to content

Commit

Permalink
Merge pull request #45 from ChristopheCVB/develop
Browse files Browse the repository at this point in the history
v8.1.0
  • Loading branch information
ChristopheCVB authored Jan 21, 2022
2 parents 65e2f40 + 8a022e2 commit 1748585
Show file tree
Hide file tree
Showing 17 changed files with 347 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private Pair<JsonObject, TypeSpec.Builder> processPlugin(RoundEnvironment roundE
jsonConfiguration.addProperty(PluginHelper.CONFIGURATION_COLOR_DARK, plugin.colorDark());
jsonConfiguration.addProperty(PluginHelper.CONFIGURATION_COLOR_LIGHT, plugin.colorLight());
jsonPlugin.add(PluginHelper.CONFIGURATION, jsonConfiguration);
jsonPlugin.addProperty(PluginHelper.PLUGIN_START_COMMAND, "java -jar ./" + pluginElement.getSimpleName() + ".jar " + PluginHelper.COMMAND_START);
jsonPlugin.addProperty(PluginHelper.PLUGIN_START_COMMAND, "java -Dapple.awt.UIElement=true -jar ./" + pluginElement.getSimpleName() + ".jar " + PluginHelper.COMMAND_START);

TypeSpec.Builder settingsTypeSpecBuilder = TypeSpec.classBuilder("Settings").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
JsonArray jsonSettings = new JsonArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

package com.christophecvb.touchportal.helpers;

import com.christophecvb.touchportal.annotations.Action;
import com.christophecvb.touchportal.annotations.Category;
import com.christophecvb.touchportal.annotations.Connector;

import javax.lang.model.element.Element;
import java.lang.reflect.Method;
import java.util.Map;

/**
* Touch Portal Plugin Action Helper
Expand All @@ -36,6 +36,9 @@ public class ConnectorHelper {
public static final String TYPE = GenericHelper.TYPE;
public static final String DATA = "data";
public static final String FORMAT = "format";
public static final String UPDATE_PREFIX = "pc";
public static final String UPDATE_ID_SEPARATOR = "_";
public static final String UPDATE_DATA_SEPARATOR = "|";

protected static final String KEY_CONNECTOR = "connector";

Expand All @@ -56,28 +59,28 @@ public static String getConnectorId(Element pluginElement, Element categoryEleme
/**
* Get the generated Connector Name
*
* @param actionElement Element
* @param connector {@link Action}
* @param connectorElement Element
* @param connector {@link Connector}
* @return String connectorName
*/
public static String getConnectorName(Element actionElement, Connector connector) {
return connector.name().isEmpty() ? actionElement.getSimpleName().toString() : connector.name();
public static String getConnectorName(Element connectorElement, Connector connector) {
return connector.name().isEmpty() ? connectorElement.getSimpleName().toString() : connector.name();
}

/**
* Get the generated Connector ID
*
* @param pluginClass Class
* @param actionMethodName String
* @param pluginClass Class
* @param connectorMethodName String
* @return String connectorId
*/
public static String getConnectorId(Class<?> pluginClass, String actionMethodName) {
public static String getConnectorId(Class<?> pluginClass, String connectorMethodName) {
String connectorId = "";

for (Method method : pluginClass.getDeclaredMethods()) {
if (method.isAnnotationPresent(Action.class) && method.getName().equals(actionMethodName)) {
Action action = method.getDeclaredAnnotation(Action.class);
connectorId = ConnectorHelper._getConnectorId(CategoryHelper.getCategoryId(pluginClass, action.categoryId()), (!action.id().isEmpty() ? action.id() : actionMethodName));
if (method.isAnnotationPresent(Connector.class) && method.getName().equals(connectorMethodName)) {
Connector connector = method.getDeclaredAnnotation(Connector.class);
connectorId = ConnectorHelper.getConnectorId(pluginClass, method, connector);
}
}

Expand All @@ -96,20 +99,80 @@ public static String getConnectorId(Class<?> pluginClass, Method connectorMethod

if (connectorMethod.isAnnotationPresent(Connector.class)) {
Connector connector = connectorMethod.getDeclaredAnnotation(Connector.class);
connectorId = ConnectorHelper._getConnectorId(CategoryHelper.getCategoryId(pluginClass, connector.categoryId()), (!connector.id().isEmpty() ? connector.id() : connectorMethod.getName()));
connectorId = ConnectorHelper.getConnectorId(pluginClass, connectorMethod, connector);
}

return connectorId;
}

/**
* Get the generated Connector ID
*
* @param pluginClass Class
* @param connectorMethod Method
* @param connector {@link Connector}
* @return String connectorId
*/
public static String getConnectorId(Class<?> pluginClass, Method connectorMethod, Connector connector) {
return ConnectorHelper._getConnectorId(CategoryHelper.getCategoryId(pluginClass, connector.categoryId()), !connector.id().isEmpty() ? connector.id() : connectorMethod.getName());
}

/**
* Internal - Get the formatted Connector ID
*
* @param categoryId String
* @param rawActionId String
* @return String actionId
* @param rawConnectorId String
* @return String connectorId
*/
private static String _getConnectorId(String categoryId, String rawActionId) {
return categoryId + "." + ConnectorHelper.KEY_CONNECTOR + "." + rawActionId;
private static String _getConnectorId(String categoryId, String rawConnectorId) {
return categoryId + "." + ConnectorHelper.KEY_CONNECTOR + "." + rawConnectorId;
}

/**
* Compute a Linear Translate
*
* @param inputMin float
* @param inputMax float
* @param outputMin float
* @param outputMax float
* @param inputValue float
* @return float computedValue
*/
public static Float linearTranslate(float inputMin, float inputMax, float outputMin, float outputMax, float inputValue) {
float inputRange = inputMax - inputMin;
float outputRange = outputMax - outputMin;
float computedCross = outputRange / inputRange * (inputValue - inputMin);
return computedCross + outputMin;
}

/**
* Get the constructed Connector Id for Connector Update
*
* @param pluginId String
* @param connectorId String
* @param value Integer
* @param data Map&lt;String, Object&gt;
* @return String constructedConnectorId
*/
public static String getConstructedId(String pluginId, String connectorId, Integer value, Map<String, Object> data) {
String constructedConnectorId = null;

if (pluginId != null && !pluginId.isEmpty() && connectorId != null && !connectorId.isEmpty() && value != null && value >= 0 && value <= 100) {
StringBuilder constructedConnectorIdBuilder = new StringBuilder(ConnectorHelper.UPDATE_PREFIX)
.append(ConnectorHelper.UPDATE_ID_SEPARATOR)
.append(pluginId)
.append(ConnectorHelper.UPDATE_ID_SEPARATOR)
.append(connectorId);
if (data != null && data.size() > 0) {
for (String dataKey : data.keySet()) {
constructedConnectorIdBuilder.append(ConnectorHelper.UPDATE_DATA_SEPARATOR)
.append(dataKey)
.append("=")
.append(data.get(dataKey));
}
}
constructedConnectorId = constructedConnectorIdBuilder.toString();
}

return constructedConnectorId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import javax.lang.model.element.Element;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.Arrays;

/**
* Touch Portal Plugin Data Helper
Expand Down Expand Up @@ -96,14 +95,14 @@ public static String getDataLabel(Element dataElement, Data data) {
* @param actionParameterName String
* @return String actionDataId
*/
public static String getActionDataId(Class<?> pluginClass, String actionMethodName, String actionParameterName) {
public static String getDataId(Class<?> pluginClass, String actionMethodName, String actionParameterName) {
String actionDataId = "";
for (Method declaredMethod : pluginClass.getDeclaredMethods()) {
if (declaredMethod.getName().equals(actionMethodName)) {
for (Parameter parameter : declaredMethod.getParameters()) {
for (Method method : pluginClass.getDeclaredMethods()) {
if (method.getName().equals(actionMethodName)) {
for (Parameter parameter : method.getParameters()) {
Data data = parameter.getAnnotation(Data.class);
if (data != null && parameter.getName().equals(actionParameterName)) {
actionDataId = DataHelper._getDataId(ActionHelper.getActionId(pluginClass, actionMethodName), data.id().isEmpty() ? actionParameterName : data.id());
actionDataId = DataHelper.getDataId(pluginClass, method, parameter);
}
}
}
Expand All @@ -117,7 +116,7 @@ public static String getActionDataId(Class<?> pluginClass, String actionMethodNa
* @param pluginClass Class
* @param method Method
* @param methodParameter Parameter
* @return String actionId
* @return String dataId
*/
public static String getDataId(Class<?> pluginClass, Method method, Parameter methodParameter) {
String dataId = "";
Expand All @@ -139,7 +138,12 @@ else if (method.isAnnotationPresent(Connector.class)) {
}
}
else {
dataId = DataHelper._getDataId(ActionHelper.getActionId(pluginClass, method), data.id().isEmpty() ? methodParameter.getName() : data.id());
if (method.isAnnotationPresent(Action.class)) {
dataId = DataHelper._getDataId(ActionHelper.getActionId(pluginClass, method), data.id().isEmpty() ? methodParameter.getName() : data.id());
}
else if (method.isAnnotationPresent(Connector.class)) {
dataId = DataHelper._getDataId(ConnectorHelper.getConnectorId(pluginClass, method), data.id().isEmpty() ? methodParameter.getName() : data.id());
}
}
}

Expand All @@ -149,11 +153,11 @@ else if (method.isAnnotationPresent(Connector.class)) {
/**
* Internal - Get the formatted Data Id
*
* @param parentId String
* @param dataId String
* @param parentId String
* @param rawDataId String
* @return String dataId
*/
private static String _getDataId(String parentId, String dataId) {
return parentId + "." + DataHelper.KEY_DATA + "." + dataId;
private static String _getDataId(String parentId, String rawDataId) {
return parentId + "." + DataHelper.KEY_DATA + "." + rawDataId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class PluginHelper {
/**
* Touch Portal Plugin System version
*/
public static final int TOUCH_PORTAL_PLUGIN_VERSION = 4;
public static final int TOUCH_PORTAL_PLUGIN_VERSION = 5;
/**
* Argument passed to the jar to start the plugin
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ public class ReceivedMessageHelper {
public static final String TYPE_HOLD_DOWN = "down";
public static final String TYPE_HOLD_UP = "up";
public static final String TYPE_CONNECTOR_CHANGE = "connectorChange";
public static final String TYPE_SHORT_CONNECTOR_ID_NOTIFICATION = "shortConnectorIdNotification";
public static final String TYPE_INFO = "info";
public static final String TYPE_LIST_CHANGE = "listChange";
public static final String TYPE_CLOSE_PLUGIN = "closePlugin";
public static final String TYPE_BROADCAST = "broadcast";
public static final String TYPE_SETTINGS = "settings";
public static final String TYPE_NOTIFICATION_OPTION_CLICKED = "notificationOptionClicked";
public static final String PLUGIN_ID = "pluginId";
public static final String ACTION_ID = "actionId";
public static final String CONNECTOR_ID = "connectorId";
public static final String SHORT_ID = "shortId";
public static final String LIST_ID = "listId";
public static final String INSTANCE_ID = "instanceId";
public static final String VALUE = GenericHelper.VALUE;
Expand Down Expand Up @@ -173,7 +176,7 @@ public static String getActionDataValue(JsonObject jsonMessage, String actionDat
* @return String dataValue
*/
public static String getActionDataValue(JsonObject jsonMessage, Class<?> pluginClass, String actionMethodName, String actionParameterName) {
return ReceivedMessageHelper.getActionDataValue(jsonMessage, DataHelper.getActionDataId(pluginClass, actionMethodName, actionParameterName));
return ReceivedMessageHelper.getActionDataValue(jsonMessage, DataHelper.getDataId(pluginClass, actionMethodName, actionParameterName));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,20 @@ public class SentMessageHelper {
public static final String TYPE_REMOVE_STATE = "removeState";
public static final String TYPE_ACTION_DATA_UPDATE = "updateActionData";
public static final String TYPE_SETTING_UPDATE = "settingUpdate";
public static final String TYPE_SHOW_NOTIFICATION = "showNotification";
public static final String TYPE_CONNECTOR_UPDATE = "connectorUpdate";
public static final String INSTANCE_ID = "instanceId";
public static final String ID = GenericHelper.ID;
public static final String VALUE = GenericHelper.VALUE;
public static final String DATA = "data";
public static final String NAME = "name";
public static final String DESCRIPTION = StateHelper.DESC;
public static final String DEFAULT_VALUE = "defaultValue";
public static final String NOTIFICATION_ID = "notificationId";
public static final String TITLE = "title";
public static final String MSG = "msg";
public static final String OPTIONS = "options";
public static final String CONNECTOR_ID = "connectorId";
public static final String SHORT_ID = "shortId";

}
Loading

0 comments on commit 1748585

Please sign in to comment.