diff --git a/vcell-client/src/main/java/org/vcell/imagej/ImageJHelper.java b/vcell-client/src/main/java/org/vcell/imagej/ImageJHelper.java index 61c003a69f..cdffe6b62c 100644 --- a/vcell-client/src/main/java/org/vcell/imagej/ImageJHelper.java +++ b/vcell-client/src/main/java/org/vcell/imagej/ImageJHelper.java @@ -21,11 +21,12 @@ import java.util.Date; import java.util.HashMap; import java.util.Hashtable; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.StringTokenizer; -import javax.print.attribute.standard.Finishings; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -46,7 +47,6 @@ import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandlerCollection; -import org.eclipse.jetty.server.handler.DebugHandler; import org.jdom.Namespace; import org.vcell.imagej.ImageJHelper.ApiSolverHandler.IJGeom; import org.vcell.util.BeanUtils; @@ -140,6 +140,7 @@ import cbit.vcell.solver.SimulationOwner; import cbit.vcell.solver.SolverDescription; import cbit.vcell.solver.SolverUtilities; +import cbit.vcell.solver.TempSimulation; import cbit.vcell.solver.VCSimulationDataIdentifier; import cbit.vcell.solver.VCSimulationIdentifier; import cbit.vcell.solver.ode.ODESimData; @@ -1400,6 +1401,14 @@ private static void addSimToIJContextInfo(ArrayListijContextInfos ArrayList ijSimInfos = new ArrayList<>(); for(Simulation sim:sims) { ijSimInfos.add(new IJSimInfo(true, false, sim.getSimulationID(), sim.getName())); + final Iterator> iterator = TempSimulation.mapTempSimIDToModelAppSim.entrySet().iterator(); + String modelAppSim = TempSimulation.createModelAppSimName(sim); + while(iterator.hasNext()) { + final Entry next = iterator.next(); + if(next.getValue().equals(modelAppSim)) { + ijSimInfos.add(new IJSimInfo(true, false, next.getKey().toString(), sim.getName()+" (quickrun_"+next.getKey().toString()+")")); + } + } } ijContextInfos.add(new IJContextInfo(contextName,mathType,geomDim,geomName, ijSimInfos)); } @@ -1421,11 +1430,11 @@ private static void populateDesktopIJModelInfos(IJDocType docType,ArrayList refreshIJModelInfoCache(IJDocType ijDocType if(bOpenOnly == null || bOpenOnly.booleanValue() == false || (bOpenOnly.booleanValue() == true && bOpenOnDesktop == true)){ ArrayList contInfos = new ArrayList<>(); ArrayList ijsimfos= new ArrayList<>(); - ijsimfos.add(new IJSimInfo(bOpenOnDesktop, false,Simulation.createSimulationID(new KeyValue(quickrunKey)), parentSimName)); + ijsimfos.add(new IJSimInfo(bOpenOnDesktop, false,quickrunKey/*Simulation.createSimulationID(new KeyValue(quickrunKey))*/, parentSimName)); // ijsimfos.add(new IJSimInfo(quickrunKey, parentSimName)); contInfos.add(new IJContextInfo(parentContextName, parentMathType, parentGeomDim, parentGeomName, ijsimfos)); modelInfos.add(new IJModelInfo(parentModelName, parentDate, docType, (docType != IJDocType.quick?true:false), parentUser,parentModelKey,contInfos)); @@ -2430,7 +2439,9 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques StringTokenizer st = new StringTokenizer(file.getName(), "_"); st.nextToken(); String quickrunKey = st.nextToken(); - if(Simulation.createSimulationID(new KeyValue(quickrunKey)).equals(ijSimInfo.simId)) { +// if(TempSimulation.mapTempSimIDToOriginalSimID.get(quickrunKey) != null && TempSimulation.mapTempSimIDToOriginalSimID.get(quickrunKey).equals(ijSimInfo.simId)) { +// if(Simulation.createSimulationID(new KeyValue(quickrunKey)).equals(ijSimInfo.simId)) { + if(quickrunKey.equals(ijSimInfo.simId)) { ijDataResponder = IJDataResponder.create(new KeyValue(quickrunKey),file.getParentFile().getParentFile(), jobIndex); break fileloop; } @@ -2494,6 +2505,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques response.setContentType("text/plain; charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().write("VCellApi"); + //response.getWriter().write("VCellApi:"+VCellClientTest.getVCellClient().getRequestManager().getDocumentManager().getUser().getName()); baseRequest.setHandled(true); } diff --git a/vcell-core/src/main/java/cbit/vcell/solver/TempSimulation.java b/vcell-core/src/main/java/cbit/vcell/solver/TempSimulation.java index 95888d64fe..d67a137843 100644 --- a/vcell-core/src/main/java/cbit/vcell/solver/TempSimulation.java +++ b/vcell-core/src/main/java/cbit/vcell/solver/TempSimulation.java @@ -1,16 +1,34 @@ package cbit.vcell.solver; +import java.util.TreeMap; + import org.vcell.util.document.SimulationVersion; import org.vcell.util.document.VCellSoftwareVersion; import org.vcell.util.document.Version; +import cbit.vcell.mapping.SimulationContext; + @SuppressWarnings("serial") public class TempSimulation extends Simulation { + //Store association of tempSimID to originalSimID for use in ImageJHelper + public static final TreeMap mapTempSimIDToOriginalSimID = new TreeMap(); + public static final TreeMap mapTempSimIDToModelAppSim = new TreeMap(); final private SimulationVersion tempSimVersion = SimulationVersion.createTempSimulationVersion(); public TempSimulation(Simulation simulation, boolean bCloneMath) { super(simulation, bCloneMath); + mapTempSimIDToModelAppSim.put(tempSimVersion.getVersionKey().toString(), createModelAppSimName(simulation)); + mapTempSimIDToOriginalSimID.put(tempSimVersion.getVersionKey().toString(), (simulation.getVersion()==null || simulation.getVersion().getVersionKey()==null?"":simulation.getVersion().getVersionKey().toString())); } + public static String createModelAppSimName(Simulation simulation) { + String modelAppSim = simulation.getName(); + if(simulation.getSimulationOwner() instanceof SimulationContext) {//biomodel + modelAppSim = ((SimulationContext)simulation.getSimulationOwner()).getBioModel().getName()+"_"+simulation.getSimulationOwner().getName()+"_"+modelAppSim; + }else {//mathmodel + modelAppSim = simulation.getSimulationOwner().getName()+"_"+modelAppSim; + } + return modelAppSim; + } @Override public Version getVersion() { return tempSimVersion; diff --git a/vcell-core/src/main/java/cbit/vcell/xml/XmlHelper.java b/vcell-core/src/main/java/cbit/vcell/xml/XmlHelper.java index c530a6dcc6..cc2a618ed8 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/XmlHelper.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/XmlHelper.java @@ -52,6 +52,7 @@ import org.jlibsedml.execution.ModelResolver; import org.jlibsedml.modelsupport.KisaoOntology; import org.jlibsedml.modelsupport.KisaoTerm; +import org.jlibsedml.modelsupport.SUPPORTED_LANGUAGE; import org.sbml.jsbml.SBMLException; import org.vcell.cellml.CellQuanVCTranslator; import org.vcell.sbml.SbmlException; @@ -591,6 +592,7 @@ public static List sedmlToBioModel(VCLogger transLogger, ExternalDoc org.jlibsedml.Simulation sedmlSimulation = null; // this will become the vCell simulation org.jlibsedml.Model sedmlOriginalModel = null; // the "original" model referred to by the task String sedmlOriginalModelName = null; // this will be used in the BioModel name + String sedmlOriginalModelLanguage = null; // can be sbml or vcml ArchiveComponents ac = null; if(externalDocInfo.getFile().getPath().toLowerCase().endsWith("sedx") || externalDocInfo.getFile().getPath().toLowerCase().endsWith("omex")) { ac = Libsedml.readSEDMLArchive(new FileInputStream(externalDocInfo.getFile().getPath())); @@ -626,6 +628,7 @@ public static List sedmlToBioModel(VCLogger transLogger, ExternalDoc throw new RuntimeException("Unexpected task " + selectedTask); } sedmlOriginalModelName = sedmlOriginalModel.getId(); + sedmlOriginalModelLanguage = sedmlOriginalModel.getLanguage(); // at this point we assume that the sedml simulation, algorithm and kisaoID are all valid Algorithm algorithm = sedmlSimulation.getAlgorithm(); @@ -681,11 +684,24 @@ public static List sedmlToBioModel(VCLogger transLogger, ExternalDoc } // make it if we didn't and mark it as fresh if (bioModel == null) { - XMLSource sbmlSource = new XMLSource(newMdl); // sbmlSource with all the changes applied - bioModel = (BioModel)XmlHelper.importSBML(transLogger, sbmlSource, bSpatial); - bioModel.setName(bioModelName); - docs.add(bioModel); - justMade = true; + if(sedmlOriginalModelLanguage.contentEquals(SUPPORTED_LANGUAGE.VCELL_GENERIC.getURN())) { // vcml + XMLSource vcmlSource = new XMLSource(newMdl); + bioModel = (BioModel)XmlHelper.XMLToBioModel(vcmlSource); + bioModel.setName(bioModelName); + docs.add(bioModel); + justMade = true; + try { + bioModel.getVCMetaData().createBioPaxObjects(bioModel); + } catch (Exception e) { + e.printStackTrace(); + } + } else { // we assume it's sbml, if it's neither import will fail + XMLSource sbmlSource = new XMLSource(newMdl); // sbmlSource with all the changes applied + bioModel = (BioModel)XmlHelper.importSBML(transLogger, sbmlSource, bSpatial); + bioModel.setName(bioModelName); + docs.add(bioModel); + justMade = true; + } } // even if we just created the biomodel from the sbml file we have at least one application with initial conditions and stuff // see if there is a suitable application type for the sedml kisao diff --git a/vcell-imagej-helper/pom.xml b/vcell-imagej-helper/pom.xml index b4603ca754..5a1c0d3560 100644 --- a/vcell-imagej-helper/pom.xml +++ b/vcell-imagej-helper/pom.xml @@ -147,5 +147,12 @@ jaxb-impl 2.3.0 + + + org.jfree + jfreechart + + + diff --git a/vcell-imagej-helper/src/main/java/org/vcell/imagej/helper/VCellHelper.java b/vcell-imagej-helper/src/main/java/org/vcell/imagej/helper/VCellHelper.java index 776d86d87e..59fc70d65f 100644 --- a/vcell-imagej-helper/src/main/java/org/vcell/imagej/helper/VCellHelper.java +++ b/vcell-imagej-helper/src/main/java/org/vcell/imagej/helper/VCellHelper.java @@ -397,6 +397,9 @@ public ArrayList getSearchedModelSimCacheKey(Boolean bO Node node = si.item(i); String currentUser = (node.getAttributes().getNamedItem("user")==null?null:node.getAttributes().getNamedItem("user").getNodeValue()); boolean bUserMatch = vcCellModelSearch.getUserId() == null || vcCellModelSearch.getUserId().equals(currentUser); + if(node.getAttributes().getNamedItem("name")==null) { + continue; + } String currentModel = node.getAttributes().getNamedItem("name").getNodeValue(); Long longDate = (node.getAttributes().getNamedItem("date")==null?null:Long.parseLong(node.getAttributes().getNamedItem("date").getNodeValue())); if(longDate != null && vcellModelVersionTimeRange != null && (longDate < vcellModelVersionTimeRange.getEarliest().getTime() || longDate > vcellModelVersionTimeRange.getLatest().getTime())) { diff --git a/vcell-imagej-helper/src/main/java/org/vcell/imagej/plugin/LinePlot.java b/vcell-imagej-helper/src/main/java/org/vcell/imagej/plugin/LinePlot.java new file mode 100644 index 0000000000..f14fb3a548 --- /dev/null +++ b/vcell-imagej-helper/src/main/java/org/vcell/imagej/plugin/LinePlot.java @@ -0,0 +1,201 @@ +package org.vcell.imagej.plugin; + +import java.util.ArrayList; + +import javax.swing.JFrame; + +import org.jfree.chart.ChartFactory; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.data.Range; +import org.jfree.data.xy.DefaultXYDataset; +import org.scijava.command.ContextCommand; +import org.scijava.plugin.Parameter; +import org.scijava.plugin.Plugin; +import org.scijava.ui.DialogPrompt.MessageType; +import org.scijava.ui.UIService; +import org.vcell.imagej.helper.VCellHelper; +import org.vcell.imagej.helper.VCellHelper.IJDataList; +import org.vcell.imagej.helper.VCellHelper.IJTimeSeriesJobResults; +import org.vcell.imagej.helper.VCellHelper.IJVarInfos; +import org.vcell.imagej.helper.VCellHelper.VARTYPE_POSTPROC; +import org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults; + +import net.imagej.ImageJ; + +@Plugin(type = ContextCommand.class, menuPath = "Plugins>LinePlot") +public class LinePlot extends ContextCommand{ + + @Parameter + private UIService uiService; + + @Parameter + private VCellHelper vcellHelper; + + @Parameter (choices={"bm", "mm"}, style="listBox") + private String modelType; + + @Parameter + private String vCellUser = "colreeze"; + + @Parameter + private String vCellModel = "Monkeyflower_pigmentation_v2"; + + @Parameter + private String application = "Pattern_formation"; + + @Parameter + private String simulation = "WT"; + + //String[] require more complicated programming + //For now use just 1 string + @Parameter + private String variable = "A"; + + @Parameter + private int timePoint = 500; + + @Parameter + private int startIndex = 1279; + + @Parameter + private int endIndex = 1321; + + @Parameter + private String imageName = "test"; + + public static void main(String[] args) { + // create the ImageJ application context with all available services + final ImageJ ij = new ImageJ(); + ij.ui().showUI(); + } + + @Override + public void run() { + + try { + //Find the port that a separately running VCell client is listening on + System.out.println("vcell service port="+vcellHelper.findVCellApiServerPort()); + } catch (Exception e) { + uiService.showDialog("Activate VCell client ImageJ service\nTools->'Start Fiji (ImageJ) service'\n"+e.getMessage(), "Couldn't contact VCell client", MessageType.ERROR_MESSAGE); + return; + } + String theCacheKey = null; + VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.valueOf(modelType),vCellUser,vCellModel,application,simulation,null,null); + try { + ArrayList vcmsr = vcellHelper.getSearchedModelSimCacheKey(false,vcms,null); + if(vcmsr.size() == 0) { + throw new Exception("No Results for search found"); + } + theCacheKey = vcmsr.get(0).getCacheKey(); + System.out.println("theCacheKey="+theCacheKey); + } catch (Exception e) { + uiService.showDialog(modelType+", "+vCellUser+", "+vCellModel+", "+application+", "+simulation+", null, null\n"+e.getMessage(), "Search failed", MessageType.ERROR_MESSAGE); + return; + } + + IJDataList timePointData = null; + int[] timePointIndexes = new int[1]; // there is 1 timePoint + int theTimePointIndex = 0; + timePointIndexes[theTimePointIndex] = timePoint; + try { + timePointData = vcellHelper.getTimePointData(theCacheKey, variable, VARTYPE_POSTPROC.NotPostProcess, timePointIndexes, 0); + } catch (Exception e) { + uiService.showDialog(modelType+", "+vCellUser+", "+vCellModel+", "+application+", "+simulation+", "+variable+", "+timePoint+"\n"+e.getMessage(), "Get Data failed", MessageType.ERROR_MESSAGE); + return; + } + double[] theTimePointData = timePointData.ijData[theTimePointIndex].getDoubleData(); + Range xAxisRange = null; + int[] dataIndexes = new int[endIndex-startIndex+1]; + double[] dataIndexesDouble = new double[dataIndexes.length];// This is just for JFreeChart + for(int i=startIndex;i<=endIndex;i++) { + dataIndexes[i-startIndex] = i; + dataIndexesDouble[i-startIndex] = i; + xAxisRange = Range.expandToInclude(xAxisRange, dataIndexesDouble[i-startIndex]); + } + + Range yAxisRange = null; + double[] chartTheseDataPoints = new double[dataIndexes.length]; + for(int i=0;i{EclipseVCellWorkspaceRootDir}/vcell/vcell-imagej-helper/target/vcell-imagej-helper-0.0.1-SNAPSHOT-sources.jar. *

*/ -@Plugin(type = ContextCommand.class, menuPath = "Plugins>VCellPlugin") -public class VCellPluginTest extends ContextCommand { +@Plugin(type = ContextCommand.class, menuPath = "Plugins>Load VCell Model") +public class ModelLoad extends ContextCommand { // // Feel free to add more parameters here... // diff --git a/vcell-imagej-helper/src/main/java/org/vcell/imagej/plugin/ModelSearch.java b/vcell-imagej-helper/src/main/java/org/vcell/imagej/plugin/ModelSearch.java new file mode 100644 index 0000000000..e292c0f2b1 --- /dev/null +++ b/vcell-imagej-helper/src/main/java/org/vcell/imagej/plugin/ModelSearch.java @@ -0,0 +1,627 @@ +/* + * To the extent possible under law, the ImageJ developers have waived + * all copyright and related or neighboring rights to this tutorial code. + * + * See the CC0 1.0 Universal license for details: + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +package org.vcell.imagej.plugin; + +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.text.DateFormat; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Date; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.TreeSet; + +import javax.swing.DefaultComboBoxModel; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.SwingUtilities; +import javax.swing.plaf.basic.BasicComboBoxUI; +import javax.swing.plaf.basic.BasicComboPopup; +import javax.swing.plaf.basic.ComboPopup; + +import org.scijava.command.ContextCommand; +import org.scijava.module.Module; +import org.scijava.module.ModuleItem; +import org.scijava.module.process.AbstractPreprocessorPlugin; +import org.scijava.module.process.PreprocessorPlugin; +import org.scijava.plugin.Parameter; +import org.scijava.plugin.Plugin; +import org.scijava.ui.DialogPrompt.MessageType; +import org.scijava.ui.UIService; +import org.vcell.imagej.helper.VCellHelper; +import org.vcell.imagej.helper.VCellHelper.BasicStackDimensions; +import org.vcell.imagej.helper.VCellHelper.IJDataList; +import org.vcell.imagej.helper.VCellHelper.IJVarInfos; +import org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults; + +import net.imagej.ImageJ; +import net.imglib2.img.array.ArrayImg; +import net.imglib2.img.array.ArrayImgs; +import net.imglib2.img.basictypeaccess.array.DoubleArray; +import net.imglib2.type.numeric.real.DoubleType; + + +/** + * This example illustrates how to create an ImageJ {@link ContextCommand} plugin that uses VCellHelper. + *

+ * You should replace the parameter fields with your own inputs and outputs, + * and replace the {@link run} method implementation with your own logic. + *

+ *

+ * To add VCellHelper to this project, + * rt-click on topmost tree element + * "imagej-plugin2"->Properties->Libraries tab->Add External Jars...-> + * File Dialog->{EclipseVCellWorkspaceRootDir}/vcell/vcell-imagej-helper/target/vcell-imagej-helper-0.0.1-SNAPSHOT.jar. + *

+ *

+ * Once vcell-imagej-helper-0.0.1-SNAPSHOT.jar has been added to the Libraries tab open + * the small arrow to the left and select "Source Attachment"->Add/Edit->External Location-> + * External File Dialog->{EclipseVCellWorkspaceRootDir}/vcell/vcell-imagej-helper/target/vcell-imagej-helper-0.0.1-SNAPSHOT-sources.jar. + *

+ *

+ * When editing the original VCellHelper in another running Eclipse, + * to make the changes show up in this project choose thisEclipse->Project->Clean...->clean. + *

+ */ +@Plugin(type = ContextCommand.class, menuPath = "Plugins>VCellPluginSearch") +public class VCellPluginSearch extends ContextCommand { + + + + public static class StyledComboBoxUI extends BasicComboBoxUI { + protected ComboPopup createPopup() { + BasicComboPopup popup = new BasicComboPopup(comboBox) { + @Override + protected Rectangle computePopupBounds(int px,int py,int pw,int ph) { + return super.computePopupBounds( + px,py,Math.max(comboBox.getPreferredSize().width,pw),ph + ); + } + }; + popup.getAccessibleContext().setAccessibleParent(comboBox); + return popup; + } + } + + public static class StyledComboBox extends JComboBox { + public StyledComboBox() { + setUI(new StyledComboBoxUI()); + } + public StyledComboBox(E[] items) { + setUI(new StyledComboBoxUI()); + setModel(new DefaultComboBoxModel(items)); + } + } + + public static class VCellSelection { + public String theCacheKey; + public String userid; + public String modelName; + public String appName; + public String simname; + public String varName; + public int timePointIndex; + public Exception exception; + public VCellSelection(String theCacheKey, String userid,String modelName, String appName, String simname,String varName,int timePointIndex) { + super(); + this.theCacheKey = theCacheKey; + this.userid=userid; + this.modelName = modelName; + this.appName = appName; + this.simname = simname; + this.varName = varName; + this.timePointIndex = timePointIndex; + } + public VCellSelection(Exception exception) { + this.exception = exception; + } + } + + @Plugin(type = PreprocessorPlugin.class) + public static class MyPreProcessor extends AbstractPreprocessorPlugin { + + public static final String CANCELLED = "cancelled"; + + @Parameter + private UIService uiService; + + @Parameter(required = true) + private VCellHelper vcellHelper; + + + @Override + public void process(Module module) { + final ModuleItem vcellModelsInput = getvcellModelsInput(module); + if (vcellModelsInput == null) { + return; + } + Comparator comp = new Comparator() { + @Override + public int compare(String o1, String o2) { + return o1.toLowerCase().compareTo(o2.toLowerCase()); + }}; + TreeSet useridSet = new TreeSet(comp); + Hashtable> mapUseridToModelNameTime = new Hashtable>(); + Hashtable mapModelNameTimeToActualModelname = new Hashtable(); + Hashtable> mapModelToApps = new Hashtable>(); + Hashtable> mapAppsToSims = new Hashtable>(); +// VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.bm,"tutorial","Tutorial_MultiApp","3D pde","Simulation4",null,null); + displayProgressBar(true, "Searching Database...", "VCell Model Loader", 25,uiService); + VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.bm,null,null,null,null,null,null); + displayProgressBar(true, "Creating GUI...", "VCell Model Loader", 100,uiService); + try { + final DateFormat dateTimeInstance = DateFormat.getDateTimeInstance(); + ArrayList vcmsr = vcellHelper.getSearchedModelSimCacheKey(false,vcms,null); + final Iterator iterator = vcmsr.iterator(); + while(iterator.hasNext()) { + final VCellModelSearchResults next = iterator.next(); + String userid = next.getUserId(); + useridSet.add(userid); + final String modelName = next.getModelName(); + final String modelNameTime = modelName+" - "+(next.getDate()==null?"unsaved":dateTimeInstance.format(new Date(next.getDate()))); + TreeSet modelsForUserid = mapUseridToModelNameTime.get(userid); + if(modelsForUserid == null) { + modelsForUserid = new TreeSet(); + mapUseridToModelNameTime.put(userid, modelsForUserid); + } + modelsForUserid.add(modelNameTime); + mapModelNameTimeToActualModelname.put(modelNameTime, modelName); + //System.out.println(modelName+" "+next.getApplicationName()+" "+next.getSimulationName()); + TreeSet appsForModel = mapModelToApps.get(modelNameTime); + if(appsForModel == null) { + appsForModel = new TreeSet(); + mapModelToApps.put(modelNameTime, appsForModel); + } + appsForModel.add(next.getApplicationName()); + String modelNameTimeApp = modelNameTime+" "+next.getApplicationName(); + TreeSet simsForApp = mapAppsToSims.get(modelNameTimeApp); + if(simsForApp == null) { + simsForApp = new TreeSet(); + mapAppsToSims.put(modelNameTimeApp, simsForApp); + } + simsForApp.add(next.getSimulationName()); + } + } catch (Exception e) { + //e.printStackTrace(); + displayProgressBar(false, "Creating GUI...", "VCell Model Loader", 100,uiService); + vcellModelsInput.setValue(module, new VCellSelection(e));//return empty VCellSelection + module.resolveInput(vcellModelsInput.getName()); + return; + }finally { + displayProgressBar(false, "Creating GUI...", "VCell Model Loader", 100,uiService); + } + + JFrame applicationFrame = (JFrame)uiService.getDefaultUI().getApplicationFrame(); + final Dimension dim = new Dimension(300,120); + JPanel jp = new JPanel() { + @Override + public Dimension getPreferredSize() { + return dim; + } + }; + jp.setLayout(new GridLayout(7,2)); + + jp.add(new JLabel("VCell Userid")); + JComboBox jcbUserid = new StyledComboBox(useridSet.toArray(new String[0])); + jp.add(jcbUserid); + + jp.add(new JLabel("Model Name")); + JComboBox jcbModelNames = new StyledComboBox(mapUseridToModelNameTime.get(jcbUserid.getSelectedItem()).toArray(new String[0])); + jcbUserid.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + jcbModelNames.removeAllItems(); + if(jcbUserid.getSelectedItem() != null && mapUseridToModelNameTime.get(jcbUserid.getSelectedItem()) != null) { + jcbModelNames.setModel(new DefaultComboBoxModel(mapUseridToModelNameTime.get(jcbUserid.getSelectedItem()).toArray(new String[0]))); + jcbModelNames.setSelectedIndex(0); + } + }}); + jp.add(jcbModelNames); + + + jp.add(new JLabel("App Name")); + JComboBox jcbAppNames = new StyledComboBox(mapModelToApps.get(jcbModelNames.getSelectedItem()).toArray(new String[0])); + jcbModelNames.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + jcbAppNames.removeAllItems(); + if(jcbModelNames.getSelectedItem() != null && mapModelToApps.get(jcbModelNames.getSelectedItem()) != null) { + jcbAppNames.setModel(new DefaultComboBoxModel(mapModelToApps.get(jcbModelNames.getSelectedItem()).toArray(new String[0]))); + jcbAppNames.setSelectedIndex(0); + } + }}); + jp.add(jcbAppNames); + + final JComboBox jcbVars = new StyledComboBox(); + jcbVars.setEnabled(false); + + final JComboBox jcbTimes = new StyledComboBox(); + jcbTimes.setEnabled(false); + + jp.add(new JLabel("Sim Name")); + JComboBox jcbSimNames = new StyledComboBox(mapAppsToSims.get(jcbModelNames.getSelectedItem()+" "+jcbAppNames.getSelectedItem()).toArray(new String[0])); + jcbAppNames.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + jcbVars.removeAllItems(); + jcbTimes.removeAllItems(); + jcbSimNames.removeAllItems(); + if(jcbAppNames.getSelectedItem() != null && mapAppsToSims.get(jcbModelNames.getSelectedItem()+" "+jcbAppNames.getSelectedItem()) != null) { + jcbSimNames.setModel(new DefaultComboBoxModel(mapAppsToSims.get(jcbModelNames.getSelectedItem()+" "+jcbAppNames.getSelectedItem()).toArray(new String[0]))); + jcbSimNames.setSelectedIndex(0); + } + }}); + jp.add(jcbSimNames); + + jp.add(new JLabel("Variables")); + jp.add(jcbVars); + jp.add(new JLabel("Times")); + jp.add(jcbTimes); + + final String[] cacheKeyHolder = new String[1]; + final IJVarInfos[] ijVarInfosHolder = new IJVarInfos[1]; + + jp.add(new JLabel("Load Vars and Times")); + JButton loadVarsAndTimesBtn = new JButton("Load..."); + loadVarsAndTimesBtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + new Thread(new Runnable() { + @Override + public void run() { + displayProgressBar(true, "Getting Vars and Times...", "VCell Model Loader", 25,uiService); + String userid = jcbUserid.getSelectedItem().toString(); + String modelName = (jcbModelNames.getSelectedItem()==null?null:mapModelNameTimeToActualModelname.get(jcbModelNames.getSelectedItem()).toString()); + String appName = (jcbModelNames.getSelectedItem()==null?null:jcbAppNames.getSelectedItem().toString()); + String simName = (jcbModelNames.getSelectedItem()==null?null:jcbSimNames.getSelectedItem().toString()); + VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.bm,userid,modelName,appName,simName,null,null); + try { + ArrayList vcmsr = vcellHelper.getSearchedModelSimCacheKey(false,vcms,null); + if(vcmsr.size() == 0) { + throw new Exception("No Results for search found"); + } + cacheKeyHolder[0] = vcmsr.get(0).getCacheKey(); + System.out.println("theCacheKey="+cacheKeyHolder[0]); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + try { + displayProgressBar(true, "Setting Var Times GUI...", "VCell Model Loader", 100,uiService); + jcbVars.setEnabled(true); + ijVarInfosHolder[0] = vcellHelper.getVarInfos(cacheKeyHolder[0]); + for(int i=0;i vcmsr = vcellHelper.getSearchedModelSimCacheKey(false,vcms,null); +// if(vcmsr.size() == 0) { +// throw new Exception("No Results for search found"); +// } +// theCacheKey = vcmsr.get(0).getCacheKey(); +// System.out.println("theCacheKey="+theCacheKey); +// +// jcbTimes.setEnabled(true); +// IJVarInfos ijVarInfos = vcellHelper.getVarInfos(theCacheKey); +// for(int i=0;i inputs = module.getInputs(); +// for(String key:inputs.keySet()) { +// System.out.println(" "+key+" "+inputs.get(key)); +// } + } + + private ModuleItem getvcellModelsInput(final Module module) { + ModuleItem result = null; + for (final ModuleItem input : module.getInfo().inputs()) { + if (module.isInputResolved(input.getName())) continue; + final Class type = input.getType(); + if (!VCellSelection.class.isAssignableFrom(type)) { + // not a VCellSelection parameter; abort + return null; + } + if (result != null) { + // second VCellSelection parameter; abort + return null; + } + @SuppressWarnings("unchecked") + final ModuleItem vcellSelect = (ModuleItem) input; + result = vcellSelect; + } + return result; + } + + private JPanel getLabeledJComboBox(String labelName,String[] items) { + JPanel jp = new JPanel(new FlowLayout()); + jp.add(new JLabel(labelName)); + JComboBox jcbModelNames = new JComboBox(items); + jp.add(jcbModelNames); + return jp; + } + + } + + @Parameter + private UIService uiService; + + @Parameter + private VCellHelper vcellHelper; + + @Parameter + private VCellSelection vcellSelection = new VCellSelection("-1", "colreeze","Monkeyflower_pigmentation_v2", "Pattern_formation", "WT","A",50); + //private VCellSelection vcellSelection; + + + /** + * This main function serves for development purposes. + * It allows you to run the plugin immediately out of + * your integrated development environment (IDE). + * + * @param args whatever, it's ignored + * @throws Exception + */ + public static void main(final String... args) throws Exception { + // create the ImageJ application context with all available services + final ImageJ ij = new ImageJ(); + ij.ui().showUI(); + } + + private static JDialog progressDialog = null; + private static final Dimension dim = new Dimension(200,30); + private static final JProgressBar jProgressBar = new JProgressBar(0,100) { + @Override + public Dimension getPreferredSize() { + return dim; + } + @Override + public Dimension getSize(Dimension rv) { + return dim; + } + }; + private static void displayProgressBar(boolean bShow,String message,String title,int progress,UIService uiService) { + if(progressDialog == null) { + JFrame applicationFrame = (JFrame)uiService.getDefaultUI().getApplicationFrame(); + progressDialog = new JDialog(applicationFrame,"Checking for VCell Client",false); + progressDialog.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + super.windowClosing(e); + progressDialog.dispose(); + progressDialog = null; + }}); + progressDialog.getContentPane().add(jProgressBar); + jProgressBar.setStringPainted(true); + jProgressBar.setString("setting up..."); + progressDialog.pack(); + + } + + if(SwingUtilities.isEventDispatchThread()) { + if(progressDialog ==null) { + return; + } + if(!bShow) { + progressDialog.dispose(); + progressDialog = null; + return; + } + progressDialog.setVisible(true); + jProgressBar.setValue(progress); + progressDialog.setTitle(title); + jProgressBar.setString(message); + jProgressBar.invalidate(); + progressDialog.revalidate(); + + }else { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + if(progressDialog ==null) { + return; + } + if(!bShow) { + progressDialog.dispose(); + progressDialog = null; + return; + } + progressDialog.setVisible(true); + jProgressBar.setValue(progress); + progressDialog.setTitle(title); + jProgressBar.setString(message); + jProgressBar.invalidate(); + progressDialog.revalidate(); + } + }); + } + } + +// private Hashtable threadHash = new Hashtable(); +// private void startJProgressThread0(String lastName,String newName) { +// if(lastName != null && threadHash.get(lastName) != null) { +// threadHash.get(lastName).interrupt(); +// while(threadHash.get(lastName) != null) { +// try { +// Thread.sleep(50); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// break; +// } +// } +// } +// if(newName == null) { +// return; +// } +// final Thread progressThread = new Thread(new Runnable(){ +// @Override +// public void run() { +// final int[] progress = new int[] {1}; +// while(progressDialog.isVisible()) { +// if(Thread.currentThread().isInterrupted()) { +// break; +// } +// SwingUtilities.invokeLater(new Runnable() { +// @Override +// public void run() { +// jProgressBar.setValue(progress[0]); +// }}); +// progress[0]++; +// try { +// Thread.sleep(500); +// } catch (InterruptedException e) { +// break; +// } +// } +// threadHash.remove(Thread.currentThread().getName()); +// }}); +// threadHash.put(newName, progressThread); +// progressThread.setName(newName); +// progressThread.setDaemon(true);//So not block JVM exit +// progressThread.start(); +// } + + @Override + public void run() { + try { + if(vcellSelection != null && vcellSelection.exception != null) { + if(!vcellSelection.exception.getMessage().equals(MyPreProcessor.CANCELLED)) { + uiService.showDialog("Model search failed\n"+vcellSelection.exception.getClass().getName()+"\n"+vcellSelection.exception.getMessage(), MessageType.ERROR_MESSAGE); + } + return; + } + if(vcellSelection == null || vcellSelection.theCacheKey==null) { + return; + } + String var = vcellSelection.varName; + int[] time = new int[] {vcellSelection.timePointIndex}; + displayProgressBar(true, "loading Image...", "VCell Model Loader", 50,uiService); + IJDataList tpd = vcellHelper.getTimePointData(vcellSelection.theCacheKey,var,VCellHelper.VARTYPE_POSTPROC.NotPostProcess,time,0); + displayProgressBar(true, "displaying Image...", "VCell Model Loader", 100,uiService); + double[] data = tpd.ijData[0].getDoubleData(); + BasicStackDimensions bsd = tpd.ijData[0].stackInfo; + System.out.println(bsd.xsize+" "+bsd.ysize); + ArrayImg testimg = ArrayImgs.doubles( data, bsd.xsize,bsd.ysize,bsd.zsize); + uiService.show(testimg); + } catch (Exception e) { + displayProgressBar(false, "displaying Image...", "VCell Model Loader", 100,uiService); + uiService.showDialog("theCacheKey,var,VCellHelper.VARTYPE_POSTPROC.NotPostProcess,time,0\n"+e.getMessage(), "getTimePoint(...) failed", MessageType.ERROR_MESSAGE); + }finally { + displayProgressBar(false, "displaying Image...", "VCell Model Loader", 100,uiService); + } + } +} diff --git a/vcell-imagej-helper/src/main/java/org/vcell/imagej/plugin/NikitaTest.java b/vcell-imagej-helper/src/main/java/org/vcell/imagej/plugin/NikitaTest.java new file mode 100644 index 0000000000..fa3aea0f7d --- /dev/null +++ b/vcell-imagej-helper/src/main/java/org/vcell/imagej/plugin/NikitaTest.java @@ -0,0 +1,201 @@ +package org.vcell.imagej.plugin; + +import java.util.ArrayList; + +import javax.swing.JFrame; + +import org.jfree.chart.ChartFactory; +import org.jfree.chart.ChartPanel; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.data.Range; +import org.jfree.data.xy.DefaultXYDataset; +import org.scijava.command.ContextCommand; +import org.scijava.plugin.Parameter; +import org.scijava.plugin.Plugin; +import org.scijava.ui.DialogPrompt.MessageType; +import org.scijava.ui.UIService; +import org.vcell.imagej.helper.VCellHelper; +import org.vcell.imagej.helper.VCellHelper.IJDataList; +import org.vcell.imagej.helper.VCellHelper.IJTimeSeriesJobResults; +import org.vcell.imagej.helper.VCellHelper.IJVarInfos; +import org.vcell.imagej.helper.VCellHelper.VARTYPE_POSTPROC; +import org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults; + +import net.imagej.ImageJ; + +@Plugin(type = ContextCommand.class, menuPath = "Plugins>NikitaTest") +public class NikitaTest extends ContextCommand{ + + @Parameter + private UIService uiService; + + @Parameter + private VCellHelper vcellHelper; + + @Parameter (choices={"bm", "mm"}, style="listBox") + private String modelType; + + @Parameter + private String vCellUser = "colreeze"; + + @Parameter + private String vCellModel = "Monkeyflower_pigmentation_v2"; + + @Parameter + private String application = "Pattern_formation"; + + @Parameter + private String simulation = "WT"; + + //String[] require more complicated programming + //For now use just 1 string + @Parameter + private String variable = "A"; + + @Parameter + private int timePoint = 500; + + @Parameter + private int startIndex = 1279; + + @Parameter + private int endIndex = 1321; + + @Parameter + private String imageName = "test"; + + public static void main(String[] args) { + // create the ImageJ application context with all available services + final ImageJ ij = new ImageJ(); + ij.ui().showUI(); + } + + @Override + public void run() { + + try { + //Find the port that a separately running VCell client is listening on + System.out.println("vcell service port="+vcellHelper.findVCellApiServerPort()); + } catch (Exception e) { + uiService.showDialog("Activate VCell client ImageJ service\nTools->'Start Fiji (ImageJ) service'\n"+e.getMessage(), "Couldn't contact VCell client", MessageType.ERROR_MESSAGE); + return; + } + String theCacheKey = null; + VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.valueOf(modelType),vCellUser,vCellModel,application,simulation,null,null); + try { + ArrayList vcmsr = vcellHelper.getSearchedModelSimCacheKey(false,vcms,null); + if(vcmsr.size() == 0) { + throw new Exception("No Results for search found"); + } + theCacheKey = vcmsr.get(0).getCacheKey(); + System.out.println("theCacheKey="+theCacheKey); + } catch (Exception e) { + uiService.showDialog(modelType+", "+vCellUser+", "+vCellModel+", "+application+", "+simulation+", null, null\n"+e.getMessage(), "Search failed", MessageType.ERROR_MESSAGE); + return; + } + + IJDataList timePointData = null; + int[] timePointIndexes = new int[1]; // there is 1 timePoint + int theTimePointIndex = 0; + timePointIndexes[theTimePointIndex] = timePoint; + try { + timePointData = vcellHelper.getTimePointData(theCacheKey, variable, VARTYPE_POSTPROC.NotPostProcess, timePointIndexes, 0); + } catch (Exception e) { + uiService.showDialog(modelType+", "+vCellUser+", "+vCellModel+", "+application+", "+simulation+", "+variable+", "+timePoint+"\n"+e.getMessage(), "Get Data failed", MessageType.ERROR_MESSAGE); + return; + } + double[] theTimePointData = timePointData.ijData[theTimePointIndex].getDoubleData(); + Range xAxisRange = null; + int[] dataIndexes = new int[endIndex-startIndex+1]; + double[] dataIndexesDouble = new double[dataIndexes.length];// This is just for JFreeChart + for(int i=startIndex;i<=endIndex;i++) { + dataIndexes[i-startIndex] = i; + dataIndexesDouble[i-startIndex] = i; + xAxisRange = Range.expandToInclude(xAxisRange, dataIndexesDouble[i-startIndex]); + } + + Range yAxisRange = null; + double[] chartTheseDataPoints = new double[dataIndexes.length]; + for(int i=0;i extends JComboBox { + @SuppressWarnings("serial") + public static class StyledComboBox extends JComboBox { public StyledComboBox() { setUI(new StyledComboBoxUI()); } - public StyledComboBox(E[] items) { + public StyledComboBox(String[] items) { setUI(new StyledComboBoxUI()); - setModel(new DefaultComboBoxModel(items)); + setModel(new DefaultComboBoxModel(items)); } } public static class VCellSelection { public String theCacheKey; + public VCellHelper.ModelType modelType; public String userid; public String modelName; public String appName; public String simname; - public String varName; - public int timePointIndex; + public String[] varName; + public int[] timePointIndexes; public Exception exception; - public VCellSelection(String theCacheKey, String userid,String modelName, String appName, String simname,String varName,int timePointIndex) { + public VCellSelection(String theCacheKey, VCellHelper.ModelType modelType,String userid,String modelName, String appName, String simname,String[] varName,int[] timePointIndexes) { super(); this.theCacheKey = theCacheKey; + this.modelType = modelType; this.userid=userid; this.modelName = modelName; this.appName = appName; this.simname = simname; this.varName = varName; - this.timePointIndex = timePointIndex; + this.timePointIndexes = timePointIndexes; } public VCellSelection(Exception exception) { this.exception = exception; } } + + @Plugin(type = PreprocessorPlugin.class) public static class MyPreProcessor extends AbstractPreprocessorPlugin { @@ -147,37 +173,64 @@ public static class MyPreProcessor extends AbstractPreprocessorPlugin { @Parameter(required = true) private VCellHelper vcellHelper; + private JComboBox jcbModelType = new StyledComboBox(new String[] {ModelType.bm.name(),ModelType.mm.name(),ModelType.quick.name()}); + private JComboBox jcbUserid = new StyledComboBox(); + private JComboBox jcbModelNames = new StyledComboBox(); + private JComboBox jcbAppNames = new StyledComboBox(); + private JComboBox jcbSimNames = new StyledComboBox(); + - @Override - public void process(Module module) { - final ModuleItem vcellModelsInput = getvcellModelsInput(module); - if (vcellModelsInput == null) { - return; + private Comparator comp = new Comparator() { + @Override + public int compare(String o1, String o2) { + return o1.toLowerCase().compareTo(o2.toLowerCase()); } - Comparator comp = new Comparator() { - @Override - public int compare(String o1, String o2) { - return o1.toLowerCase().compareTo(o2.toLowerCase()); - }}; - TreeSet useridSet = new TreeSet(comp); - Hashtable> mapUseridToModelNameTime = new Hashtable>(); - Hashtable mapModelNameTimeToActualModelname = new Hashtable(); - Hashtable> mapModelToApps = new Hashtable>(); - Hashtable> mapAppsToSims = new Hashtable>(); -// VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.bm,"tutorial","Tutorial_MultiApp","3D pde","Simulation4",null,null); + }; + private TreeSet useridSet = new TreeSet(comp); + private Hashtable> mapUseridToModelNameTime = new Hashtable>(); + private Hashtable mapModelNameTimeToActualModelname = new Hashtable(); + private Hashtable> mapModelToApps = new Hashtable>(); + private Hashtable> mapAppsToSims = new Hashtable>(); + + public MyPreProcessor() { +// jcbModelType.addActionListener(new ActionListener() { +// @Override +// public void actionPerformed(ActionEvent e) { +// try { +// searchVCell(); +// } catch (Exception e1) { +//// // TODO Auto-generated catch block +//// e1.printStackTrace(); +// } +// }}); +// jcbModelType.setSelectedIndex(0); + + } + + private String createMapAppToSimsKeyName(String modelName,String appName) { + //return jcbModelNames.getSelectedItem()+" "+jcbAppNames.getSelectedItem(); + return modelName+" "+(appName==null?modelName:appName); + } + private void searchVCell() throws Exception{ displayProgressBar(true, "Searching Database...", "VCell Model Loader", 25,uiService); - VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.bm,null,null,null,null,null,null); + VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(ModelType.valueOf(jcbModelType.getSelectedItem().toString()),null,null,null,null,null,null); displayProgressBar(true, "Creating GUI...", "VCell Model Loader", 100,uiService); try { final DateFormat dateTimeInstance = DateFormat.getDateTimeInstance(); ArrayList vcmsr = vcellHelper.getSearchedModelSimCacheKey(false,vcms,null); + useridSet = new TreeSet(comp); + mapUseridToModelNameTime = new Hashtable>(); + mapModelNameTimeToActualModelname = new Hashtable(); + mapModelToApps = new Hashtable>(); + mapAppsToSims = new Hashtable>(); + final Iterator iterator = vcmsr.iterator(); while(iterator.hasNext()) { final VCellModelSearchResults next = iterator.next(); String userid = next.getUserId(); useridSet.add(userid); final String modelName = next.getModelName(); - final String modelNameTime = modelName+" - "+(next.getDate()==null?"unsaved":dateTimeInstance.format(new Date(next.getDate()))); + final String modelNameTime = modelName+" ("+next.getModelType().name()+")"+" - "+(next.getDate()==null?"unsaved":dateTimeInstance.format(new Date(next.getDate()))); TreeSet modelsForUserid = mapUseridToModelNameTime.get(userid); if(modelsForUserid == null) { modelsForUserid = new TreeSet(); @@ -191,8 +244,8 @@ public int compare(String o1, String o2) { appsForModel = new TreeSet(); mapModelToApps.put(modelNameTime, appsForModel); } - appsForModel.add(next.getApplicationName()); - String modelNameTimeApp = modelNameTime+" "+next.getApplicationName(); + appsForModel.add((next.getModelType()==ModelType.mm?modelNameTime:next.getApplicationName())); + String modelNameTimeApp = createMapAppToSimsKeyName(modelNameTime,(next.getModelType()==ModelType.mm?null:next.getApplicationName()));//modelNameTime+(next.getModelType()==ModelType.mm?"":" "+next.getApplicationName()); TreeSet simsForApp = mapAppsToSims.get(modelNameTimeApp); if(simsForApp == null) { simsForApp = new TreeSet(); @@ -200,192 +253,428 @@ public int compare(String o1, String o2) { } simsForApp.add(next.getSimulationName()); } +// DefaultComboBoxModel a= null; +// ((DefaultComboBoxModel)jcbUserid.getModel()). } catch (Exception e) { - //e.printStackTrace(); - displayProgressBar(false, "Creating GUI...", "VCell Model Loader", 100,uiService); - vcellModelsInput.setValue(module, new VCellSelection(e));//return empty VCellSelection - module.resolveInput(vcellModelsInput.getName()); - return; + throw e; +// //e.printStackTrace(); +// displayProgressBar(false, "Creating GUI...", "VCell Model Loader", 100,uiService); +// vcellModelsInput.setValue(module, new VCellSelection(e));//return empty VCellSelection +// module.resolveInput(vcellModelsInput.getName()); +// return; }finally { displayProgressBar(false, "Creating GUI...", "VCell Model Loader", 100,uiService); } + + } + @Override + public void process(Module module) { + final ModuleItem vcellModelsInput = getvcellModelsInput(module); + if (vcellModelsInput == null) { + return; + } +// try { +// searchVCell(); +// } catch (Exception e) { +// vcellModelsInput.setValue(module, new VCellSelection(e));//return empty VCellSelection +// module.resolveInput(vcellModelsInput.getName()); +// return; +// } - JFrame applicationFrame = (JFrame)uiService.getDefaultUI().getApplicationFrame(); +// displayProgressBar(true, "Searching Database...", "VCell Model Loader", 25,uiService); +// VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(ModelType.valueOf(jcbModelType.getSelectedItem().toString()),null,null,null,null,null,null); +// displayProgressBar(true, "Creating GUI...", "VCell Model Loader", 100,uiService); +// try { +// final DateFormat dateTimeInstance = DateFormat.getDateTimeInstance(); +// ArrayList vcmsr = vcellHelper.getSearchedModelSimCacheKey(false,vcms,null); +// final Iterator iterator = vcmsr.iterator(); +// while(iterator.hasNext()) { +// final VCellModelSearchResults next = iterator.next(); +// String userid = next.getUserId(); +// useridSet.add(userid); +// final String modelName = next.getModelName(); +// final String modelNameTime = modelName+" ("+next.getModelType().name()+")"+" - "+(next.getDate()==null?"unsaved":dateTimeInstance.format(new Date(next.getDate()))); +// TreeSet modelsForUserid = mapUseridToModelNameTime.get(userid); +// if(modelsForUserid == null) { +// modelsForUserid = new TreeSet(); +// mapUseridToModelNameTime.put(userid, modelsForUserid); +// } +// modelsForUserid.add(modelNameTime); +// mapModelNameTimeToActualModelname.put(modelNameTime, modelName); +// //System.out.println(modelName+" "+next.getApplicationName()+" "+next.getSimulationName()); +// TreeSet appsForModel = mapModelToApps.get(modelNameTime); +// if(appsForModel == null) { +// appsForModel = new TreeSet(); +// mapModelToApps.put(modelNameTime, appsForModel); +// } +// appsForModel.add(next.getApplicationName()); +// String modelNameTimeApp = modelNameTime+" "+next.getApplicationName(); +// TreeSet simsForApp = mapAppsToSims.get(modelNameTimeApp); +// if(simsForApp == null) { +// simsForApp = new TreeSet(); +// mapAppsToSims.put(modelNameTimeApp, simsForApp); +// } +// simsForApp.add(next.getSimulationName()); +// } +// } catch (Exception e) { +// //e.printStackTrace(); +// displayProgressBar(false, "Creating GUI...", "VCell Model Loader", 100,uiService); +// vcellModelsInput.setValue(module, new VCellSelection(e));//return empty VCellSelection +// module.resolveInput(vcellModelsInput.getName()); +// return; +// }finally { +// displayProgressBar(false, "Creating GUI...", "VCell Model Loader", 100,uiService); +// } + + //ApplicationFrame applicationFrame = uiService.getDefaultUI().getApplicationFrame(); final Dimension dim = new Dimension(300,120); - JPanel jp = new JPanel() { + @SuppressWarnings("serial") + final JPanel jp = new JPanel() { @Override public Dimension getPreferredSize() { return dim; } }; - jp.setLayout(new GridLayout(7,2)); + jp.setLayout(new GridLayout(8,2)); + + final boolean[] bUseVCellSelectionHolder = new boolean[] {false}; + + //jcbModelType + jp.add(new JLabel("Model Type")); + jp.add(jcbModelType); + jp.add(new JLabel("VCell Userid")); - JComboBox jcbUserid = new StyledComboBox(useridSet.toArray(new String[0])); +// JComboBox jcbUserid = new StyledComboBox(useridSet.toArray(new String[0])); + jcbModelType.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + new Thread(new Runnable() { + @Override + public void run() { + try { + searchVCell(); + } catch (Exception e1) { + uiService.showDialog("Error in searchVCell()\n"+e1.getClass().getName()+"\n"+e1.getMessage()); +// JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(jp); +// topFrame.dispose(); + return; + } + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + if(vcellModelsInput.getDefaultValue() != null && vcellModelsInput.getDefaultValue().modelType.name().equals(jcbModelType.getSelectedItem().toString())) { + bUseVCellSelectionHolder[0] = true; + } + jcbUserid.removeAllItems(); + jcbUserid.setModel(new DefaultComboBoxModel(useridSet.toArray(new String[0]))); + if(jcbUserid.getItemCount()==0) { + jcbUserid.addItem("Nothing Found"); + }else if(bUseVCellSelectionHolder[0]) { + jcbUserid.setSelectedItem(vcellModelsInput.getDefaultValue().userid); + }else { + jcbUserid.setSelectedIndex(0); + } + bUseVCellSelectionHolder[0] = false; + }}); + }}).start(); + }}); jp.add(jcbUserid); jp.add(new JLabel("Model Name")); - JComboBox jcbModelNames = new StyledComboBox(mapUseridToModelNameTime.get(jcbUserid.getSelectedItem()).toArray(new String[0])); +// JComboBox jcbModelNames = new StyledComboBox(mapUseridToModelNameTime.get(jcbUserid.getSelectedItem()).toArray(new String[0])); jcbUserid.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { jcbModelNames.removeAllItems(); if(jcbUserid.getSelectedItem() != null && mapUseridToModelNameTime.get(jcbUserid.getSelectedItem()) != null) { jcbModelNames.setModel(new DefaultComboBoxModel(mapUseridToModelNameTime.get(jcbUserid.getSelectedItem()).toArray(new String[0]))); - jcbModelNames.setSelectedIndex(0); + if(bUseVCellSelectionHolder[0]) { + for(int i=0;i jcbAppNames = new StyledComboBox(mapModelToApps.get(jcbModelNames.getSelectedItem()).toArray(new String[0])); +// JComboBox jcbAppNames = new StyledComboBox(mapModelToApps.get(jcbModelNames.getSelectedItem()).toArray(new String[0])); jcbModelNames.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { jcbAppNames.removeAllItems(); if(jcbModelNames.getSelectedItem() != null && mapModelToApps.get(jcbModelNames.getSelectedItem()) != null) { jcbAppNames.setModel(new DefaultComboBoxModel(mapModelToApps.get(jcbModelNames.getSelectedItem()).toArray(new String[0]))); - jcbAppNames.setSelectedIndex(0); + if(bUseVCellSelectionHolder[0]) { + jcbAppNames.setSelectedItem(vcellModelsInput.getDefaultValue().appName); + }else { + jcbAppNames.setSelectedIndex(0); + } } }}); jp.add(jcbAppNames); - final JComboBox jcbVars = new StyledComboBox(); - jcbVars.setEnabled(false); + //final JComboBox jcbVars = new StyledComboBox(); + //jcbVars.setEnabled(false); - final JComboBox jcbTimes = new StyledComboBox(); - jcbTimes.setEnabled(false); + // JComboBox jcbTimes = new StyledComboBox(); + //jcbTimes.setEnabled(false); jp.add(new JLabel("Sim Name")); - JComboBox jcbSimNames = new StyledComboBox(mapAppsToSims.get(jcbModelNames.getSelectedItem()+" "+jcbAppNames.getSelectedItem()).toArray(new String[0])); jcbAppNames.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - jcbVars.removeAllItems(); - jcbTimes.removeAllItems(); +// jcbVars.removeAllItems(); +// jcbTimes.removeAllItems(); jcbSimNames.removeAllItems(); if(jcbAppNames.getSelectedItem() != null && mapAppsToSims.get(jcbModelNames.getSelectedItem()+" "+jcbAppNames.getSelectedItem()) != null) { jcbSimNames.setModel(new DefaultComboBoxModel(mapAppsToSims.get(jcbModelNames.getSelectedItem()+" "+jcbAppNames.getSelectedItem()).toArray(new String[0]))); - jcbSimNames.setSelectedIndex(0); + if(bUseVCellSelectionHolder[0]) { + jcbSimNames.setSelectedItem(vcellModelsInput.getDefaultValue().simname); + }else { + jcbSimNames.setSelectedIndex(0); + } } }}); jp.add(jcbSimNames); - jp.add(new JLabel("Variables")); - jp.add(jcbVars); - jp.add(new JLabel("Times")); - jp.add(jcbTimes); +// if(vcellModelsInput.getDefaultValue() != null) {//If user provided an inital value for VCellSelection var in VCellPlugin +// final VCellSelection defaultValue = vcellModelsInput.getDefaultValue(); +// jcbUserid.setSelectedItem(defaultValue.userid); +// System.out.println(jcbUserid.getSelectedItem()); +// for(int i=0;i vcmsr = vcellHelper.getSearchedModelSimCacheKey(false,vcms,null); - if(vcmsr.size() == 0) { - throw new Exception("No Results for search found"); - } - cacheKeyHolder[0] = vcmsr.get(0).getCacheKey(); - System.out.println("theCacheKey="+cacheKeyHolder[0]); - - SwingUtilities.invokeAndWait(new Runnable() { - @Override - public void run() { - try { - displayProgressBar(true, "Setting Var Times GUI...", "VCell Model Loader", 100,uiService); - jcbVars.setEnabled(true); - ijVarInfosHolder[0] = vcellHelper.getVarInfos(cacheKeyHolder[0]); - for(int i=0;i maxTimeJSlider1.getValue()){ + maxTimeJSlider1.setValue(minTimeJSlider1.getValue()); + return; + }else if(ce.getSource()==maxTimeJSlider1 && maxTimeJSlider1.getValue() < minTimeJSlider1.getValue()){ + minTimeJSlider1.setValue(maxTimeJSlider1.getValue()); + return; } - } catch (Exception e) { - //e.printStackTrace(); - uiService.showDialog("VCellHelper.ModelType.bm,\"tutorial\",\""+modelName+"\",\""+appName+"\",\""+simName+"\",null,null\n"+e.getMessage(), "GUI setupfailed", MessageType.ERROR_MESSAGE); + minTimeJLabel.setText(MINTIMESTR+ijVarInfosHolder[0].getTimes()[minTimeJSlider1.getValue()]); + maxTimeJLabel.setText(MAXTIMESTR+ijVarInfosHolder[0].getTimes()[maxTimeJSlider1.getValue()]); + }}; + + minTimeJSlider1.setName("minTime"); + minTimeJSlider1.setPaintTicks(true); + minTimeJSlider1.setMajorTickSpacing(10); + minTimeJSlider1.setSnapToTicks(true); + minTimeJSlider1.setMinorTickSpacing(1); + minTimeJSlider1.setMaximum(ijVarInfosHolder[0].getTimes().length - 1); + minTimeJSlider1.setValue(0); + minTimeJSlider1.addChangeListener(changeListener); + + maxTimeJSlider1.setName("maxTime"); + maxTimeJSlider1.setPaintTicks(true); + maxTimeJSlider1.setMajorTickSpacing(10); + maxTimeJSlider1.setSnapToTicks(true); + maxTimeJSlider1.setMinorTickSpacing(1); + maxTimeJSlider1.setMaximum(ijVarInfosHolder[0].getTimes().length - 1); + maxTimeJSlider1.setValue(ijVarInfosHolder[0].getTimes().length - 1); + maxTimeJSlider1.addChangeListener(changeListener); - }finally { - displayProgressBar(false, "Getting Vars and Times...", "VCell Model Loader", 25,uiService); +// Object[][] dataVars = new Object[jcbVars.getModel().getSize()][1]; +// for(int i=0;i compList = new ArrayList(); + compList.add(SwingUtilities.getAncestorOfClass(Window.class, selectMultipleVarsAndTimesBtn)); + while(compList.size() > 0) { + Container container = compList.remove(0); + for(int i=0;i jcbVars, + * final JComboBox jcbTimes, final String[] cacheKeyHolder, final + * IJVarInfos[] ijVarInfosHolder + */){ + displayProgressBar(true, "Getting Vars and Times...", "VCell Model Loader", 25,uiService); + String userid = jcbUserid.getSelectedItem().toString(); + String modelName = (jcbModelNames.getSelectedItem()==null?null:mapModelNameTimeToActualModelname.get(jcbModelNames.getSelectedItem()).toString()); + String appName = (jcbModelNames.getSelectedItem()==null?null:jcbAppNames.getSelectedItem().toString()); + String simName = (jcbModelNames.getSelectedItem()==null?null:jcbSimNames.getSelectedItem().toString()); + VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(ModelType.valueOf(jcbModelType.getSelectedItem().toString()),userid,modelName,appName,simName,null,null); + try { +// jcbVars.removeAllItems(); +// jcbTimes.removeAllItems(); + ArrayList vcmsr = vcellHelper.getSearchedModelSimCacheKey(false,vcms,null); + if(vcmsr.size() == 0) { + throw new Exception("No Results for search found"); + } + cacheKeyHolder[0] = vcmsr.get(0).getCacheKey(); + System.out.println("theCacheKey="+cacheKeyHolder[0]); + ijVarInfosHolder[0] = vcellHelper.getVarInfos(cacheKeyHolder[0]); + + ijVarInfosHolder[0].getIjVarInfo().sort(new Comparator() { + @Override + public int compare(IJVarInfo o1, IJVarInfo o2) { + return o1.getName().compareToIgnoreCase(o2.getName()); + }}); + +// SwingUtilities.invokeAndWait(new Runnable() { +// @Override +// public void run() { +// try { +// displayProgressBar(true, "Getting Var Times GUI...", "VCell Model Loader", 100,uiService); +// jcbVars.setEnabled(true); +// ijVarInfosHolder[0] = vcellHelper.getVarInfos(cacheKeyHolder[0]); +// for(int i=0;i getvcellModelsInput(final Module module) { ModuleItem result = null; for (final ModuleItem input : module.getInfo().inputs()) { @@ -447,24 +824,27 @@ private ModuleItem getvcellModelsInput(final Module module) { return result; } - private JPanel getLabeledJComboBox(String labelName,String[] items) { - JPanel jp = new JPanel(new FlowLayout()); - jp.add(new JLabel(labelName)); - JComboBox jcbModelNames = new JComboBox(items); - jp.add(jcbModelNames); - return jp; - } +// private JPanel getLabeledJComboBox(String labelName,String[] items) { +// JPanel jp = new JPanel(new FlowLayout()); +// jp.add(new JLabel(labelName)); +// JComboBox jcbModelNames = new JComboBox(items); +// jp.add(jcbModelNames); +// return jp; +// } } @Parameter private UIService uiService; + @Parameter + private DisplayService displayService; + @Parameter private VCellHelper vcellHelper; @Parameter - private VCellSelection vcellSelection = new VCellSelection("-1", "tutorial","Tutorial_MultiApp", "3D pde", "Simulation4","C_cyt",50); + private VCellSelection vcellSelection = new VCellSelection("-1",ModelType.bm, "tutorial","Tutorial_MultiApp", "3D pde", "Simulation4",new String[] {"C_cyt"},new int[] {50}); //private VCellSelection vcellSelection; @@ -484,6 +864,7 @@ public static void main(final String... args) throws Exception { private static JDialog progressDialog = null; private static final Dimension dim = new Dimension(200,30); + @SuppressWarnings("serial") private static final JProgressBar jProgressBar = new JProgressBar(0,100) { @Override public Dimension getPreferredSize() { @@ -496,7 +877,7 @@ public Dimension getSize(Dimension rv) { }; private static void displayProgressBar(boolean bShow,String message,String title,int progress,UIService uiService) { if(progressDialog == null) { - JFrame applicationFrame = (JFrame)uiService.getDefaultUI().getApplicationFrame(); + Frame applicationFrame = IJ.getInstance();//(Frame)uiService.getDefaultUI().getApplicationFrame(); progressDialog = new JDialog(applicationFrame,"Checking for VCell Client",false); progressDialog.addWindowListener(new WindowAdapter() { @Override @@ -598,6 +979,11 @@ public void run() { @Override public void run() { try { +// final List>> displayPlugins = ((DefaultDisplayService)displayService).getDisplayPlugins(); +// for(PluginInfo> pi:displayPlugins) { +// System.out.println(pi); +// } + if(vcellSelection != null && vcellSelection.exception != null) { if(!vcellSelection.exception.getMessage().equals(MyPreProcessor.CANCELLED)) { uiService.showDialog("Model search failed\n"+vcellSelection.exception.getClass().getName()+"\n"+vcellSelection.exception.getMessage(), MessageType.ERROR_MESSAGE); @@ -607,8 +993,8 @@ public void run() { if(vcellSelection == null || vcellSelection.theCacheKey==null) { return; } - String var = vcellSelection.varName; - int[] time = new int[] {vcellSelection.timePointIndex}; + String var = vcellSelection.varName[0]; + int[] time = vcellSelection.timePointIndexes; displayProgressBar(true, "loading Image...", "VCell Model Loader", 50,uiService); IJDataList tpd = vcellHelper.getTimePointData(vcellSelection.theCacheKey,var,VCellHelper.VARTYPE_POSTPROC.NotPostProcess,time,0); displayProgressBar(true, "displaying Image...", "VCell Model Loader", 100,uiService); @@ -616,6 +1002,9 @@ public void run() { BasicStackDimensions bsd = tpd.ijData[0].stackInfo; System.out.println(bsd.xsize+" "+bsd.ysize); ArrayImg testimg = ArrayImgs.doubles( data, bsd.xsize,bsd.ysize,bsd.zsize); +// final Display createDisplay = displayService.createDisplay(testimg); +// ((DefaultImageDisplay)createDisplay) +// System.out.println(createDisplay); uiService.show(testimg); } catch (Exception e) { displayProgressBar(false, "displaying Image...", "VCell Model Loader", 100,uiService);