Adding Data & selectedRow Properties to Custom Module

I guess I can share how NoteChart does this with the Classic Chart–you’ll have to adapt for the Power Table:

public class NoteChartBeanInfo extends CommonBeanInfo {

	public NoteChartBeanInfo() {
		super(NoteChart.class, new CustomizerDescriptor[] {
				ChartCustomizer.VALUE_DESCRIPTOR });
		getBeanDescriptor().setValue("dbl-click-customizer", ChartCustomizer.VALUE_DESCRIPTOR.getValueName());
	}

	@Override
	protected void initProperties() throws IntrospectionException {
		// Adds common properties
		super.initProperties();

		// Remove properties that NoteChart will define differently from CommonBeanInfo
		removeProp("opaque");

		// Add all notechart-specific properties
		addProp("notes", "Notes", "Dataset of text annotations to display",
				CAT_DATA, PREFERRED_MASK | BOUND_MASK);
		addProp("altNotes", "Alternate Notes", "Dataset of alternate annotations for live modifications",
				CAT_DATA, PREFERRED_MASK | BOUND_MASK);
		addProp("traceTS", "Trace Timestamp",
				"Timestamp for the selected annotation, or independent trace if no selection",
				CAT_DATA, PREFERRED_MASK | BOUND_MASK);
// ***** Much clipped out
		addProp("enableNoteSelect", "Enable Note Selection",
				"Annotations can clicked (at their text) to set selectedNote or selectedAltNote",
				CAT_BEHAVIOR, EXPERT_MASK);

		/*
		 * Hide properties from PMIChart that NoteChart can't use. They
		 * would show up from getAdditionalBeanInfo().
		 */
		addProp("chartType", "Must be an XY Chart", "", CAT_BEHAVIOR, HIDDEN_MASK);
		addProp("subplotMode", "Must be Combined Domain", "", CAT_BEHAVIOR, HIDDEN_MASK);
	}

	@Override
	public Image getIcon(int kind) {
		switch (kind) {
		case BeanInfo.ICON_COLOR_16x16:
		case BeanInfo.ICON_MONO_16x16:
			return new ImageIcon(getClass().getResource("/images/note-chart_16.png")).getImage();
		case SimpleBeanInfo.ICON_COLOR_32x32:
		case SimpleBeanInfo.ICON_MONO_32x32:
			return new ImageIcon(getClass().getResource("/images/note-chart_32.png")).getImage();
		}
		return null;
	}

	@Override
	protected void initDesc() {
		VisionBeanDescriptor bean = getBeanDescriptor();
		bean.setName("Classic Note Chart");
		bean.setDisplayName("Classic Note Chart");
		bean.setShortDescription("A component that displays time-series Plots with annotation marks.");
		BeanInfo superbi = new PMIChartBeanInfo();
		BeanDescriptor superbean = superbi.getBeanDescriptor();
		List<ExtensionFunctionDescriptor> extensionFunctionList = new ArrayList<ExtensionFunctionDescriptor>();
		@SuppressWarnings("unchecked")
		List<ExtensionFunctionDescriptor> superFunctionList = (List<ExtensionFunctionDescriptor>) superbean
				.getValue("vision-extension-functions");
		if (superFunctionList != null) {
			for (ExtensionFunctionDescriptor efd : superFunctionList) {
				if (!efd.getMethodName().equalsIgnoreCase("getXTraceLabel"))
					extensionFunctionList.add(efd);
			}
		}
		extensionFunctionList.add(ExtensionFunctionDescriptor.newFunction("formatTraceTS").returns(String.class)
				.description("Allows overriding the displayed timestamp in X-Trace mode.  Return the string or None for the default.")
				.arg("chart", "A JFreeChart object. Refer to the JFreeChart documentation for API details.")
				.arg("traceTS", "A java Date object.")
				.arg("textFmt", "A string with the date formatting pattern that would be used by default.")
				.defaultImpl("# Put your code here").build());
		extensionFunctionList.add(ExtensionFunctionDescriptor.newFunction("formatTraceValue").returns(String.class)
				.description("Allows overriding the displayed pen name and value in X-Trace mode.  Return the string or None for the default.")
				.arg("chart", "A JFreeChart object. Refer to the JFreeChart documentation for API details.")
				.arg("subPlot", "The integer subplot index within the chart.")
				.arg("plotDS", "The integer plot dataset index within the subplot.")
				.arg("penIdx", "The integer pen index within the plot dataset.")
				.arg("v", "The (interpolated) pen value to format.")
				.arg("rangeAxis", "The value axis object whose number format override would normally be used.")
				.arg("penName", "The name of the pen.  *Not* automatically prepended to your result string.")
				.defaultImpl("# Put your code here").build());
		bean.setValue("vision-extension-functions", extensionFunctionList);
	}

	@Override
	public BeanInfo[] getAdditionalBeanInfo() {
		BeanInfo[] superbi = { new PMIChartBeanInfo() };
		return superbi;
	}
}

While the complete file is commercially copyrighted, the above snippet is hereby placed in the public domain. The magic is in that last method definition. (:

5 Likes