public void execute(Object o) { DefaultTreeModel models = null; try { models = customManager.getCustomModels(); } catch (IOException e) { } DefaultMutableTreeNode root = (DefaultMutableTreeNode) models.getRoot(); FunctionFactorySherpaHelper.SetRoot(root); FunctionFactorySherpaHelper.AddTreeSelectionListener(new ComponentTreeSelectionListener()); }
public void valueChanged(TreeSelectionEvent e) { JTree tree = FunctionFactorySherpaHelper.GetJTree(); DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null) { return; } Object node_object = node.getUserObject(); if (node.isLeaf()) { try { // analytic Sherpa functions. Function rf = (Function) node_object; try { if (rf instanceof Polynomial) { rf = new Polynomial(1); } else { rf = (Function) rf.clone(); } } catch (CloneNotSupportedException ex) { rf = null; } FunctionFactorySherpaHelper.SetFunction(rf); } catch (ClassCastException e1) { // templates, tables and user files try { DefaultCustomModel model = (DefaultCustomModel) node_object; String functionName = model.getFunctionName(); SherpaFunction function = new SherpaFunction(); URL url = model.getUrl(); String path = url.getPath(); function.addPath(path); String name = model.getName(); if (path.contains("/tables/")) { name = "tablemodel"; } if (path.contains("/functions/")) { name = "usermodel"; } if (path.contains("/templates/")) { name = "templatemodel"; } function.setUserID(name); function.setName(name); function.setFunctionName(functionName); // Converting a DefaultCustomModel to a SherpaFunction might // require more than this. We'll see as we go further down // the road... // First, we need to break up the comma-separated string // parameters into something that can actually be used to // build instances of Function. String[] parNames = model.getParnames().split("\\,"); String[] parVals = model.getParvals().split("\\,"); String[] parMins = model.getParmins().split("\\,"); String[] parMaxs = model.getParmaxs().split("\\,"); String[] parFrozen = model.getParfrozen().split("\\,"); int npars = parNames.length; if (npars != parVals.length || npars != parMins.length || npars != parMaxs.length || npars != parFrozen.length) { ExceptionHandler.handleException( new Exception("Parameter lists wih different lengths.")); tree.clearSelection(); FunctionFactorySherpaHelper.dispose(); return; } // now we loop over the parameter lists, building // each parameter in turn and adding it to the Function. for (int i = 0; i < npars; i++) { SherpaFParameter functionParameter = null; try { double value = Double.valueOf(parVals[i]); double min = Double.valueOf(parMins[i]); double max = Double.valueOf(parMaxs[i]); functionParameter = new SherpaFParameter(parNames[i], value, min, max, new NonSupportedUnits("")); String frozen = parFrozen[i]; if (frozen != null) { boolean fixed = (frozen.equalsIgnoreCase("True")) ? true : false; functionParameter.setFixed(fixed); } } catch (NumberFormatException ex) { ExceptionHandler.handleException(ex); tree.clearSelection(); FunctionFactorySherpaHelper.dispose(); return; } catch (ArrayIndexOutOfBoundsException ex) { ExceptionHandler.handleException(ex); tree.clearSelection(); FunctionFactorySherpaHelper.dispose(); return; } function.addParameter(functionParameter); } FunctionFactorySherpaHelper.SetFunction(function); } catch (ClassCastException e2) { } } tree.clearSelection(); FunctionFactorySherpaHelper.dispose(); } }
public void init(IrisApplication app, IWorkspace workspace) { visualizer = this; sedManager = (SedlibSedManager) workspace.getSedManager(); SpvInitialization spvinit = new SpvInitialization(new String[] {}, null); SpvProperties.SetProperty(Include.APP_NAME, Include.IRIS_APP_NAME); SpvProperties.SetProperty(Include.APP_VERSION, Include.IRIS_VERSION); spvinit.initialize(null, false); FunctionFactorySherpaHelper.initialize(); this.app = app; ws = workspace; idm = new IrisDisplayManager(sedManager, ws, this); idm.setDesktopMode(true); idm.setConnection(app.getSAMPController()); File rootDir = new File( app.getConfigurationDir() + File.separator + "analysis" + File.separator + "custom_models"); try { customManager = new CustomModelsManager(rootDir); TreeRefresher treeRefresher = new TreeRefresher(); treeRefresher.execute(null); FunctionFactorySherpaHelper.SetTreeRefresher(treeRefresher); } catch (Exception ex) { Logger.getLogger(IrisVisualizer.class.getName()).log(Level.SEVERE, null, ex); int ans = NarrowOptionPane.showConfirmDialog( ws.getRootFrame(), "Error initializing Custom Fit Component Manager: " + ex.getMessage() + "\nDo you want to reset custom models?", "Iris Visualizer", NarrowOptionPane.ERROR_MESSAGE); if (ans == NarrowOptionPane.OK_OPTION) { try { if (rootDir.isDirectory()) { deleteDirectory(rootDir); } else { rootDir.delete(); } rootDir.mkdir(); customManager = new CustomModelsManager(rootDir); } catch (IOException ex1) { Logger.getLogger(IrisVisualizer.class.getName()).log(Level.SEVERE, null, ex1); } } } SedEvent.getInstance() .add( new SedListener() { public void process(final ExtSed source, SedCommand payload) { if (payload == SedCommand.SELECTED || payload == SedCommand.CHANGED) { if (source.getNumberOfSegments() > 0) { display(source); } } else if (payload == SedCommand.REMOVED) { remove(source); } } }); SegmentEvent.getInstance() .add( new SegmentListener() { public void process(Segment source, final SegmentPayload payload) { if (payload.getSedCommand() == SedCommand.REMOVED) { return; } ExtSed sed = payload.getSed(); // If the sed structure was modified, invalidate // any model associated with it. invalidateModel(sed); display(payload.getSed()); } }); MultipleSegmentEvent.getInstance() .add( new MultipleSegmentListener() { public void process(List<Segment> source, final SegmentPayload payload) { ExtSed sed = payload.getSed(); // If the sed structure was modified, invalidate // any model associated with it. invalidateModel(sed); display(payload.getSed()); } }); }