public static void printOperatorList() { OperationRegistry operationRegistry = JAI.getDefaultInstance().getOperationRegistry(); List<OperationDescriptor> descriptors = (List<OperationDescriptor>) operationRegistry.getDescriptors(OperationDescriptor.class); Collections.sort( descriptors, new Comparator<OperationDescriptor>() { public int compare(OperationDescriptor descriptor1, OperationDescriptor descriptor2) { return descriptor1.getName().compareTo(descriptor2.getName()); } }); int columnCount = 0; for (OperationDescriptor descriptor : descriptors) { columnCount = Math.max(columnCount, descriptor.getName().length()); } for (OperationDescriptor descriptor : descriptors) { String namePart = descriptor.getName(); if (namePart.length() < columnCount) { namePart += spaces(columnCount - namePart.length()); } String[][] resources = descriptor.getResources(Locale.getDefault()); String description = resources[3][1]; System.out.println(namePart + " - " + description); } }
private void construct() { final OperationRegistry operationRegistry = JAI.getDefaultInstance().getOperationRegistry(); final List<OperationDescriptor> operationDescriptors = (List<OperationDescriptor>) operationRegistry.getDescriptors(OperationDescriptor.class); for (OperationDescriptor operationDescriptor : operationDescriptors) { final JsJaiFunction jaiFunction = new JsJaiFunction(operationDescriptor); defineProperty(jaiFunction.getClassName(), jaiFunction, ScriptableObject.READONLY); final Field[] fields = operationDescriptor.getClass().getFields(); for (Field field : fields) { final int modifiers = field.getModifiers(); if (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)) { try { defineProperty(field.getName(), field.get(operationDescriptor), READONLY); } catch (IllegalAccessException e) { System.out.println( "Error: operationDescriptor=" + operationDescriptor + ", field=" + field + ", e=" + e); } } } } defineProperty( "INTERP_NEAREST", Interpolation.getInstance(Interpolation.INTERP_NEAREST), READONLY); defineProperty( "INTERP_BILINEAR", Interpolation.getInstance(Interpolation.INTERP_BILINEAR), READONLY); defineProperty( "INTERP_BICUBIC", Interpolation.getInstance(Interpolation.INTERP_BICUBIC), READONLY); defineProperty( "INTERP_BICUBIC_2", Interpolation.getInstance(Interpolation.INTERP_BICUBIC_2), READONLY); defineFunctionProperties(new String[] {"show", "help"}, JsJai.class, ScriptableObject.DONTENUM); }
private static void printOperatorUsage(String name) { OperationRegistry operationRegistry = JAI.getDefaultInstance().getOperationRegistry(); OperationDescriptor descriptor = (OperationDescriptor) operationRegistry.getDescriptor(OperationDescriptor.class, name); if (descriptor == null) { System.out.println("Unknown operation '" + name + "'"); return; } String[][] resources = descriptor.getResources(Locale.getDefault()); String globalName = resources[0][1]; String description = resources[3][1]; String[] sourceNames = descriptor.getSourceNames(); Class[] sourceTypes = descriptor.getSourceClasses("rendered"); ParameterListDescriptor parameterListDescriptor = descriptor.getParameterListDescriptor("rendered"); String[] paramNames = parameterListDescriptor.getParamNames(); Class[] paramTypes = parameterListDescriptor.getParamClasses(); StringBuilder text = new StringBuilder(); text.append("Usage: "); text.append(globalName); text.append('('); StringBuilder paramListText = new StringBuilder(); if (sourceNames != null) { for (String sourceName : sourceNames) { if (paramListText.length() > 0) { paramListText.append(", "); } paramListText.append(sourceName); } } if (paramNames != null) { for (String paramName : paramNames) { if (paramListText.length() > 0) { paramListText.append(", "); } paramListText.append(paramName); Object defaultValue = parameterListDescriptor.getParamDefaultValue(paramName); if (defaultValue != ParameterListDescriptor.NO_PARAMETER_DEFAULT) { paramListText.append("="); paramListText.append(format(defaultValue)); } } } text.append(paramListText); text.append(')'); text.append('\n'); text.append("Description: "); text.append(description); text.append('\n'); text.append("Arguments:\n"); if (sourceNames != null) { for (int i = 0; i < sourceNames.length; i++) { String sourceName = sourceNames[i]; Class sourceType = sourceTypes[i]; text.append(" "); text.append(sourceName); text.append(": "); text.append("A source."); text.append(" (" + sourceType.getName() + ")"); text.append('\n'); } } if (paramNames != null) { for (int i = 0; i < paramNames.length; i++) { String paramName = paramNames[i]; Class paramType = paramTypes[i]; text.append(" "); text.append(paramName); text.append(": "); text.append(resources[6 + i][1]); text.append(" (" + paramType.getName() + ")"); text.append('\n'); } } System.out.println(text); }