/** * Adds a FunctionPanel. * * @param name a descriptive name * @param panel the FunctionPanel * @return the added panel */ @Override public FunctionPanel addPanel(String name, FunctionPanel panel) { super.addPanel(name, panel); // autoload data functions, if any, for this track type Class<?> trackType = null; try { trackType = Class.forName(panel.getDescription()); } catch (ClassNotFoundException ex) { } // load from Strings read from tracker.prefs (deprecated Dec 2014) for (String xml : Tracker.dataFunctionControlStrings) { XMLControl control = new XMLControlElement(xml); // determine what track type the control is for Class<?> controlTrackType = null; try { controlTrackType = Class.forName(control.getString("description")); // $NON-NLS-1$); } catch (Exception ex) { } if (controlTrackType == trackType) { control.loadObject(panel); } } // load from XMLControls autoloaded from XML files in search paths for (String path : Tracker.dataFunctionControls.keySet()) { ArrayList<XMLControl> controls = Tracker.dataFunctionControls.get(path); for (XMLControl control : controls) { // determine what track type the control is for Class<?> controlTrackType = null; try { controlTrackType = Class.forName(control.getString("description")); // $NON-NLS-1$); } catch (Exception ex) { } if (controlTrackType == trackType) { // copy the control for modification if any functions are autoload_off XMLControl copyControl = new XMLControlElement(control); eliminateExcludedFunctions(copyControl, path); // change duplicate function names without requiring user confirmation FunctionEditor editor = panel.getFunctionEditor(); boolean confirmChanges = editor.getConfirmChanges(); editor.setConfirmChanges(false); copyControl.loadObject(panel); editor.setConfirmChanges(confirmChanges); } } } return panel; }
public Object loadObject(XMLControl control, Object obj) { VisualizationHints hints = (VisualizationHints) obj; hints.setDecorationType(control.getInt("decoration type")); // $NON-NLS-1$ hints.setCursorType(control.getInt("cursor type")); // $NON-NLS-1$ hints.setRemoveHiddenLines(control.getBoolean("remove hidden lines")); // $NON-NLS-1$ hints.setAllowQuickRedraw(control.getBoolean("allow quick redraw")); // $NON-NLS-1$ hints.setUseColorDepth(control.getBoolean("use color depth")); // $NON-NLS-1$ hints.setShowCoordinates(control.getInt("show coordinates at")); // $NON-NLS-1$ hints.setXFormat(control.getString("x format")); // $NON-NLS-1$ hints.setYFormat(control.getString("y format")); // $NON-NLS-1$ hints.setZFormat(control.getString("z format")); // $NON-NLS-1$ hints.setAxesLabels((String[]) control.getObject("axes labels")); // $NON-NLS-1$ return obj; }
public Object loadObject(XMLControl control, Object obj) { super.loadObject(control, obj); ElementImage element = (ElementImage) obj; element.setImageFile(control.getString("image file")); element.setRotationAngle(control.getDouble("rotation angle")); return obj; }
/** * Chooses data functions from a DataBuilder XMLControl. * * @param control the XMLControl * @param description "Save" or "Load" * @param selectedFunctions collection of DataFunction choices * @return true if user clicked OK */ @SuppressWarnings("unchecked") protected boolean chooseBuilderDataFunctions( XMLControl control, String description, Collection<String[]> selectedFunctions) { ListChooser listChooser = new ListChooser( TrackerRes.getString( "TrackerPanel.DataBuilder." + description + ".Title"), // $NON-NLS-1$ //$NON-NLS-2$ TrackerRes.getString( "TrackerPanel.DataBuilder." + description + ".Message"), //$NON-NLS-1$ //$NON-NLS-2$ this); listChooser.setSeparator(" = "); // $NON-NLS-1$ // choose the elements and save ArrayList<String[]> originals = new ArrayList<String[]>(); ArrayList<String[]> choices = new ArrayList<String[]>(); ArrayList<String> names = new ArrayList<String>(); ArrayList<String> expressions = new ArrayList<String>(); ArrayList<String> trackTypes = new ArrayList<String>(); Map<String, XMLControl> xmlControlMap = new TreeMap<String, XMLControl>(); Map<String, ArrayList<Parameter>> parameterMap = new TreeMap<String, ArrayList<Parameter>>(); Map<String, ArrayList<String[]>> functionMap = new TreeMap<String, ArrayList<String[]>>(); for (Object obj : control.getPropertyContent()) { if (obj instanceof XMLProperty) { XMLProperty prop = (XMLProperty) obj; for (XMLControl xmlControl : prop.getChildControls()) { if (xmlControl.getObjectClass() != DataFunctionPanel.class) continue; // get track type (description) and map to panel xmlControl String trackType = xmlControl.getString("description"); // $NON-NLS-1$ xmlControlMap.put(trackType, xmlControl); // get the list of functions for this track type ArrayList<String[]> functions = functionMap.get(trackType); if (functions == null) { functions = new ArrayList<String[]>(); functionMap.put(trackType, functions); } // add functions found in this xmlControl unless already present ArrayList<String[]> panelFunctions = (ArrayList<String[]>) xmlControl.getObject("functions"); // $NON-NLS-1$ outer: for (String[] f : panelFunctions) { // check for duplicate function names for (String[] existing : functions) { if (existing[0].equals(f[0])) continue outer; } functions.add(f); } // get the list of parameters for this track type ArrayList<Parameter> params = parameterMap.get(trackType); if (params == null) { params = new ArrayList<Parameter>(); parameterMap.put(trackType, params); } // add parameters found in this xmlControl unless already present Parameter[] panelParams = (Parameter[]) xmlControl.getObject("user_parameters"); // $NON-NLS-1$ outer: for (Parameter p : panelParams) { if (trackType.endsWith("PointMass") && p.getName().equals("m")) { // $NON-NLS-1$ //$NON-NLS-2$ continue outer; } // check for duplicate parameter names for (Parameter existing : params) { if (existing.getName().equals(p.getName())) continue outer; } params.add(p); } } } } for (String trackType : functionMap.keySet()) { ArrayList<String[]> functions = functionMap.get(trackType); for (String[] f : functions) { originals.add(f); choices.add(f); names.add(f[0]); expressions.add(f[1]); String shortName = XML.getExtension(trackType); String localized = TrackerRes.getString(shortName + ".Name"); // $NON-NLS-1$ if (!localized.startsWith("!")) shortName = localized; // $NON-NLS-1$ trackTypes.add("[" + shortName + "]"); // $NON-NLS-1$ //$NON-NLS-2$ } } // select all by default boolean[] selected = new boolean[choices.size()]; for (int i = 0; i < selected.length; i++) { selected[i] = true; } if (listChooser.choose(choices, names, expressions, trackTypes, selected)) { // compare choices with originals and remove unwanted object content for (String[] function : originals) { if (!choices.contains(function)) { for (String trackType : xmlControlMap.keySet()) { ArrayList<String[]> functions = functionMap.get(trackType); functions.remove(function); } } } // set functions in xmlControl for each trackType for (String trackType : xmlControlMap.keySet()) { ArrayList<String[]> functions = functionMap.get(trackType); ArrayList<Parameter> paramList = parameterMap.get(trackType); Parameter[] params = paramList.toArray(new Parameter[paramList.size()]); XMLControl xmlControl = xmlControlMap.get(trackType); xmlControl.setValue("functions", functions); // $NON-NLS-1$ xmlControl.setValue("user_parameters", params); // $NON-NLS-1$ } // keep only xmlControls that have functions and are in xmlControlMap for (Object next : control.getPropertyContent()) { if (next instanceof XMLProperty && ((XMLProperty) next).getPropertyName().equals("functions")) { // $NON-NLS-1$ XMLProperty panels = (XMLProperty) next; java.util.List<Object> content = panels.getPropertyContent(); ArrayList<Object> toRemove = new ArrayList<Object>(); for (Object child : content) { XMLControl xmlControl = ((XMLProperty) child).getChildControls()[0]; if (!xmlControlMap.values().contains(xmlControl)) { toRemove.add(child); } else { // check to see if functions is empty ArrayList<String[]> functions = (ArrayList<String[]>) xmlControl.getObject("functions"); // $NON-NLS-1$ if (functions == null || functions.isEmpty()) { toRemove.add(child); } } } for (Object remove : toRemove) { content.remove(remove); } } } return true; } return false; }