From f3e493bd9d2d059b74f8a1c2a1e4f7eb332e7692 Mon Sep 17 00:00:00 2001 From: Chris Myers Date: Sun, 30 Apr 2017 10:30:48 -0400 Subject: [PATCH] Start of redo of preferences. --- .../dataModels/util/IBioSimPreferences.java | 257 ++++++++++++++++++ .../async/ibiosim/dataModels/util/Infos.java | 75 +++++ .../ibiosim/dataModels/util/PersonInfo.java | 26 ++ .../edu/utah/ece/async/ibiosim/gui/Gui.java | 7 +- .../sbol/SBOLAssociationPanel2.java | 2 +- .../sbol/SBOLDescriptorPanel2.java | 2 +- .../gui/modelEditor/sbol/SBOLField2.java | 2 +- .../gui/modelEditor/schematic/BioGraph.java | 1 - .../modelEditor/schematic/ModelEditor.java | 16 +- .../gui/modelEditor/schematic/Schematic.java | 1 - .../gui/modelEditor/schematic/Utils.java | 3 - .../ibiosim/gui/sbolBrowser/SBOLBrowser2.java | 2 +- .../gui/synthesisView/SynthesisView.java | 2 +- .../preferences/AnalysisPreferencesTab.java | 98 +++++++ .../{ => preferences}/EditPreferences.java | 13 +- .../preferences/GeneralPreferencesTab.java | 98 +++++++ .../util/preferences/LearnPreferencesTab.java | 98 +++++++ .../ModelEditorPreferencesTab.java | 98 +++++++ .../util/preferences/ModelPreferencesTab.java | 98 +++++++ .../preferences/PartEditorPreferencesTab.java | 98 +++++++ .../util/preferences/PreferencesDialog.java | 167 ++++++++++++ .../preferences/RegistryPreferencesTab.java | 246 +++++++++++++++++ .../gui/util/preferences/UserInfoTab.java | 117 ++++++++ .../ece/async/ibiosim/gui/icons/general.png | Bin 0 -> 1007 bytes .../ece/async/ibiosim/gui/icons/registry.png | Bin 0 -> 202 bytes .../utah/ece/async/ibiosim/gui/icons/user.png | Bin 0 -> 296 bytes manifast | 2 + 27 files changed, 1504 insertions(+), 25 deletions(-) create mode 100644 dataModels/src/main/java/edu/utah/ece/async/ibiosim/dataModels/util/IBioSimPreferences.java create mode 100644 dataModels/src/main/java/edu/utah/ece/async/ibiosim/dataModels/util/Infos.java create mode 100644 dataModels/src/main/java/edu/utah/ece/async/ibiosim/dataModels/util/PersonInfo.java create mode 100644 gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/AnalysisPreferencesTab.java rename gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/{ => preferences}/EditPreferences.java (99%) create mode 100644 gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/GeneralPreferencesTab.java create mode 100644 gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/LearnPreferencesTab.java create mode 100644 gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/ModelEditorPreferencesTab.java create mode 100644 gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/ModelPreferencesTab.java create mode 100644 gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/PartEditorPreferencesTab.java create mode 100644 gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/PreferencesDialog.java create mode 100644 gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/RegistryPreferencesTab.java create mode 100644 gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/UserInfoTab.java create mode 100644 gui/src/main/resources/edu/utah/ece/async/ibiosim/gui/icons/general.png create mode 100644 gui/src/main/resources/edu/utah/ece/async/ibiosim/gui/icons/registry.png create mode 100644 gui/src/main/resources/edu/utah/ece/async/ibiosim/gui/icons/user.png create mode 100644 manifast diff --git a/dataModels/src/main/java/edu/utah/ece/async/ibiosim/dataModels/util/IBioSimPreferences.java b/dataModels/src/main/java/edu/utah/ece/async/ibiosim/dataModels/util/IBioSimPreferences.java new file mode 100644 index 000000000..43b18edb9 --- /dev/null +++ b/dataModels/src/main/java/edu/utah/ece/async/ibiosim/dataModels/util/IBioSimPreferences.java @@ -0,0 +1,257 @@ +/* + * Copyright (c) 2012 - 2015, Clark & Parsia, LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package edu.utah.ece.async.ibiosim.dataModels.util; + +import java.util.prefs.Preferences; + +import edu.utah.ece.async.ibiosim.dataModels.util.Infos; +import edu.utah.ece.async.ibiosim.dataModels.util.PersonInfo; + +public enum IBioSimPreferences { + INSTANCE; + + private PersonInfo userInfo = null; + + public PersonInfo getUserInfo() { + if (userInfo == null) { + Preferences prefs = Preferences.userNodeForPackage(IBioSimPreferences.class).node("user"); + String name = prefs.get("name", ""); + String email = prefs.get("email", ""); + String uri = prefs.get("uri", "http://www.dummy.org"); + userInfo = Infos.forPerson(uri, name, email); + } + + return userInfo; + } + + public void saveUserInfo(PersonInfo userInfo) { + this.userInfo = userInfo; + + Preferences prefs = Preferences.userNodeForPackage(IBioSimPreferences.class).node("user"); + + try { + if (userInfo == null) { + prefs.removeNode(); + } else { + prefs.put("uri", userInfo.getURI().toString()); + prefs.put("name", userInfo.getName()); + if (userInfo.getEmail() != null) { + prefs.put("email", userInfo.getEmail().toString()); + } else { + prefs.put("email", ""); + } + } + + prefs.flush(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public boolean getValidate() { + return false; + } + + private Boolean enableFileDialog = null; + + public boolean isFileDialogEnabled() { + if (enableFileDialog == null) { + enableFileDialog = Preferences.userRoot().get("biosim.general.file_browser", "").equals("FileDialog"); + } + + return enableFileDialog; + } + + public void setFileDialogEnabled(boolean enableFileDialog) { + this.enableFileDialog = enableFileDialog; + if (enableFileDialog) { + Preferences.userRoot().put("biosim.general.file_browser", "FileDialog"); + } else { + Preferences.userRoot().put("biosim.general.file_browser", "JFileChooser"); + } + } + + private Boolean enablePlusMinusIcons = null; + + public boolean isPlusMinusIconsEnabled() { + if (enablePlusMinusIcons == null) { + enablePlusMinusIcons = Preferences.userRoot().get("biosim.general.tree_icons", "").equals("plus_minus"); + } + + return enablePlusMinusIcons; + } + + public void setPlusMinusIconsEnabled(boolean enablePlusMinusIcons) { + this.enablePlusMinusIcons = enablePlusMinusIcons; + if (enablePlusMinusIcons) { + Preferences.userRoot().put("biosim.general.tree_icons", "plus_minus"); + } else { + Preferences.userRoot().put("biosim.general.tree_icons", "default"); + } + } + + private Boolean enableNoConfirm = null; + + public boolean isNoConfirmEnabled() { + if (enableNoConfirm == null) { + enableNoConfirm = Preferences.userRoot().get("biosim.general.delete", "").equals("noconfirm"); + } + + return enableNoConfirm; + } + + public void setNoConfirmEnabled(boolean enableNoConfirm) { + this.enableNoConfirm = enableNoConfirm; + if (enableNoConfirm) { + Preferences.userRoot().put("biosim.general.delete", "noconfirm"); + } else { + Preferences.userRoot().put("biosim.general.delete", "confirm"); + } + } + + private Boolean enableLibSBMLFlatten = null; + + public boolean isLibSBMLFlattenEnabled() { + if (enableLibSBMLFlatten == null) { + enableLibSBMLFlatten = Preferences.userRoot().get("biosim.general.flatten", "").equals("libsbml"); + } + + return enableLibSBMLFlatten; + } + + public void setLibSBMLFlattenEnabled(boolean enableLibSBMLFlatten) { + this.enableLibSBMLFlatten = enableLibSBMLFlatten; + if (enableLibSBMLFlatten) { + Preferences.userRoot().put("biosim.general.flatten", "libsbml"); + } else { + Preferences.userRoot().put("biosim.general.flatten", "default"); + } + } + + private Boolean enableLibSBMLValidate = null; + + public boolean isLibSBMLValidateEnabled() { + if (enableLibSBMLValidate == null) { + enableLibSBMLValidate = Preferences.userRoot().get("biosim.general.validate", "").equals("libsbml"); + } + + return enableLibSBMLValidate; + } + + public void setLibSBMLValidateEnabled(boolean enableLibSBMLValidate) { + this.enableLibSBMLValidate = enableLibSBMLValidate; + if (enableLibSBMLValidate) { + Preferences.userRoot().put("biosim.general.validate", "libsbml"); + } else { + Preferences.userRoot().put("biosim.general.validate", "default"); + } + } + + private Boolean enableWarnings = null; + + public boolean isWarningsEnabled() { + if (enableWarnings == null) { + enableWarnings = Preferences.userRoot().get("biosim.general.warnings", "").equals("true"); + } + + return enableWarnings; + } + + public void setWarningsEnabled(boolean enableWarnings) { + this.enableWarnings = enableWarnings; + if (enableWarnings) { + Preferences.userRoot().put("biosim.general.warnings", "true"); + } else { + Preferences.userRoot().put("biosim.general.warnings", "false"); + } + } + + private Boolean enableBranching = null; + private Boolean enableVersioning = null; + + public boolean isBranchingEnabled() { + if (enableBranching == null) { + Preferences prefs = Preferences.userNodeForPackage(IBioSimPreferences.class).node("versioning"); + enableBranching = prefs.getBoolean("enableBranching", false); + } + + return enableBranching; + } + + public void setBranchingEnabled(boolean enableBranching) { + Preferences prefs = Preferences.userNodeForPackage(IBioSimPreferences.class).node("versioning"); + prefs.putBoolean("enableBranching", enableBranching); + } + + public boolean isVersioningEnabled() { + if (enableVersioning == null) { + Preferences prefs = Preferences.userNodeForPackage(IBioSimPreferences.class).node("versioning"); + // versioning is no longer supported + enableVersioning = prefs.getBoolean("enable", false); + } + + return enableVersioning; + } + + public void setVersioningEnabled(boolean enableVersioning) { + Preferences prefs = Preferences.userNodeForPackage(IBioSimPreferences.class).node("versioning"); + prefs.putBoolean("enable", enableVersioning); + } + + private Integer seqBehavior = null; + + /** + * askUser is 0, overwrite is 1, and keep is 2 + */ + public Integer getSeqBehavior() { + if (seqBehavior == null) { + Preferences prefs = Preferences.userNodeForPackage(IBioSimPreferences.class).node("settings"); + seqBehavior = prefs.getInt("seqBehavior", 2); + } + return seqBehavior; + } + + /** + * askUser is 0, overwrite is 1, and keep is 2 + */ + public void setSeqBehavior(int seqBehavior) { + Preferences prefs = Preferences.userNodeForPackage(IBioSimPreferences.class).node("settings"); + prefs.putInt("seqBehavior", seqBehavior); + this.seqBehavior = seqBehavior; + } + + private Integer nameDisplayIdBehavior = null; + + /** + * show name is 0, show displayId is 1 + */ + public Integer getNameDisplayIdBehavior() { + if (nameDisplayIdBehavior == null) { + Preferences prefs = Preferences.userNodeForPackage(IBioSimPreferences.class).node("settings"); + nameDisplayIdBehavior = prefs.getInt("nameDisplayIdBehavior", 0); + } + return nameDisplayIdBehavior; + } + + /** + * show name is 0, show displayId is 1 + */ + public void setNameDisplayIdBehavior(int showNameOrDisplayId) { + Preferences prefs = Preferences.userNodeForPackage(IBioSimPreferences.class).node("settings"); + prefs.putInt("nameDisplayIdBehavior", showNameOrDisplayId); + this.nameDisplayIdBehavior = showNameOrDisplayId; + } +} diff --git a/dataModels/src/main/java/edu/utah/ece/async/ibiosim/dataModels/util/Infos.java b/dataModels/src/main/java/edu/utah/ece/async/ibiosim/dataModels/util/Infos.java new file mode 100644 index 000000000..0fab2ea04 --- /dev/null +++ b/dataModels/src/main/java/edu/utah/ece/async/ibiosim/dataModels/util/Infos.java @@ -0,0 +1,75 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package edu.utah.ece.async.ibiosim.dataModels.util; + +import java.net.URI; + +import com.google.common.base.Preconditions; + +public class Infos { + public static PersonInfo forPerson(String uri) { + return forPerson(URI.create(uri), "", null); + } + + public static PersonInfo forPerson(URI uri) { + return forPerson(uri, "", null); + } + + public static PersonInfo forPerson(String uri, String name, String email) { + return forPerson(URI.create(uri), name, email); + } + + public static PersonInfo forPerson(URI uri, String name, String email) { + return new ImmutablePersonInfo(uri, name, email); + } + + private static class ImmutablePersonInfo implements PersonInfo { + private final URI uri; + private final String name; + private final String email; + + public ImmutablePersonInfo(URI user, String name, String email) { + Preconditions.checkNotNull(user, "Person URI cannot be null"); + this.uri = user; + this.name = name; + this.email = email; + } + + @Override + public URI getURI() { + return uri; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getEmail() { + return email; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(name); + if (email != null) { + sb.append(" <").append(email.toString()).append(">"); + } + return sb.toString(); + } + } + +} diff --git a/dataModels/src/main/java/edu/utah/ece/async/ibiosim/dataModels/util/PersonInfo.java b/dataModels/src/main/java/edu/utah/ece/async/ibiosim/dataModels/util/PersonInfo.java new file mode 100644 index 000000000..5a59a8829 --- /dev/null +++ b/dataModels/src/main/java/edu/utah/ece/async/ibiosim/dataModels/util/PersonInfo.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2012 - 2015, Clark & Parsia, LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package edu.utah.ece.async.ibiosim.dataModels.util; + +import java.net.URI; + +public interface PersonInfo { + public URI getURI(); + + public String getName(); + + public String getEmail(); +} diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/Gui.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/Gui.java index 87d201008..80d5c4495 100644 --- a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/Gui.java +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/Gui.java @@ -156,7 +156,6 @@ import com.apple.eawt.PreferencesHandler; import com.apple.eawt.QuitHandler; import com.apple.eawt.QuitResponse; import edu.utah.ece.async.sboldesigner.sbol.editor.SBOLDesignerPlugin; - import uk.ac.ebi.biomodels.ws.BioModelsWSClient; import uk.ac.ebi.biomodels.ws.BioModelsWSException; import de.unirostock.sems.cbarchive.CombineArchive; @@ -186,10 +185,11 @@ import edu.utah.ece.async.ibiosim.gui.modelEditor.schematic.Utils; import edu.utah.ece.async.ibiosim.gui.sbolBrowser.SBOLBrowser2; import edu.utah.ece.async.ibiosim.gui.synthesisView.SynthesisView; import edu.utah.ece.async.ibiosim.gui.synthesisView.SynthesisViewATACS; -import edu.utah.ece.async.ibiosim.gui.util.EditPreferences; import edu.utah.ece.async.ibiosim.gui.util.FileTree; import edu.utah.ece.async.ibiosim.gui.util.Log; import edu.utah.ece.async.ibiosim.gui.util.Utility; +import edu.utah.ece.async.ibiosim.gui.util.preferences.EditPreferences; +import edu.utah.ece.async.ibiosim.gui.util.preferences.PreferencesDialog; import edu.utah.ece.async.ibiosim.gui.util.tabs.CloseAndMaxTabbedPane; import edu.utah.ece.async.ibiosim.gui.verificationView.AbstractionPanel; import edu.utah.ece.async.ibiosim.gui.verificationView.VerificationView; @@ -339,6 +339,7 @@ public class Gui implements Observer, MouseListener, ActionListener, MouseMotion app.setPreferencesHandler(new PreferencesHandler() { public void handlePreferences(PreferencesEvent pe) { + PreferencesDialog.showPreferences(frame); EditPreferences editPreferences = new EditPreferences(frame, async, tree); editPreferences.preferences(); if (sbolDocument != null) { @@ -2947,6 +2948,7 @@ public class Gui implements Observer, MouseListener, ActionListener, MouseMotion } // if the open project menu item is selected else if (e.getSource() == pref) { + PreferencesDialog.showPreferences(frame); EditPreferences editPreferences = new EditPreferences(frame, async, tree); editPreferences.preferences(); if (sbolDocument != null) { @@ -6279,6 +6281,7 @@ public class Gui implements Observer, MouseListener, ActionListener, MouseMotion addTab(sbolDesignerPlugin.getRootDisplayId(), sbolDesignerPlugin, "SBOL Designer"); } } catch (Exception e) { + e.printStackTrace(); JOptionPane.showMessageDialog(Gui.frame, "SBOL file at " + fileName + " is invalid.", "Invalid SBOL", JOptionPane.ERROR_MESSAGE); } diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/sbol/SBOLAssociationPanel2.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/sbol/SBOLAssociationPanel2.java index d0b1710db..1f2d1d30c 100644 --- a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/sbol/SBOLAssociationPanel2.java +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/sbol/SBOLAssociationPanel2.java @@ -36,7 +36,7 @@ import edu.utah.ece.async.ibiosim.dataModels.util.exceptions.SBOLException; import edu.utah.ece.async.ibiosim.gui.Gui; import edu.utah.ece.async.ibiosim.gui.modelEditor.schematic.ModelEditor; import edu.utah.ece.async.ibiosim.gui.sbolBrowser.SBOLBrowser2; -import edu.utah.ece.async.ibiosim.gui.util.EditPreferences; +import edu.utah.ece.async.ibiosim.gui.util.preferences.EditPreferences; import java.net.URI; import java.net.URISyntaxException; diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/sbol/SBOLDescriptorPanel2.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/sbol/SBOLDescriptorPanel2.java index 31101218a..b692401ab 100644 --- a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/sbol/SBOLDescriptorPanel2.java +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/sbol/SBOLDescriptorPanel2.java @@ -40,7 +40,7 @@ import edu.utah.ece.async.ibiosim.dataModels.sbol.SBOLIdentityManager; import edu.utah.ece.async.ibiosim.dataModels.util.GlobalConstants; import edu.utah.ece.async.ibiosim.dataModels.util.exceptions.SBOLException; import edu.utah.ece.async.ibiosim.gui.Gui; -import edu.utah.ece.async.ibiosim.gui.util.EditPreferences; +import edu.utah.ece.async.ibiosim.gui.util.preferences.EditPreferences; /** * diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/sbol/SBOLField2.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/sbol/SBOLField2.java index dadeb3b2b..fd273370e 100644 --- a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/sbol/SBOLField2.java +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/sbol/SBOLField2.java @@ -42,7 +42,7 @@ import edu.utah.ece.async.ibiosim.dataModels.sbol.SBOLUtility; import edu.utah.ece.async.ibiosim.dataModels.util.GlobalConstants; import edu.utah.ece.async.ibiosim.gui.Gui; import edu.utah.ece.async.ibiosim.gui.modelEditor.schematic.ModelEditor; -import edu.utah.ece.async.ibiosim.gui.util.EditPreferences; +import edu.utah.ece.async.ibiosim.gui.util.preferences.EditPreferences; import edu.utah.ece.async.sboldesigner.sbol.editor.dialog.PartEditDialog; public class SBOLField2 extends JPanel implements ActionListener { diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/schematic/BioGraph.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/schematic/BioGraph.java index 0c2fab5d8..7652de872 100644 --- a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/schematic/BioGraph.java +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/schematic/BioGraph.java @@ -69,7 +69,6 @@ import com.mxgraph.view.mxStylesheet; import edu.utah.ece.async.ibiosim.dataModels.biomodel.annotation.AnnotationUtility; import edu.utah.ece.async.ibiosim.dataModels.biomodel.parser.BioModel; import edu.utah.ece.async.ibiosim.dataModels.biomodel.util.SBMLutilities; -import edu.utah.ece.async.ibiosim.dataModels.biomodel.util.Utility; import edu.utah.ece.async.ibiosim.dataModels.util.GlobalConstants; import edu.utah.ece.async.ibiosim.gui.Gui; import edu.utah.ece.async.ibiosim.gui.ResourceManager; diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/schematic/ModelEditor.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/schematic/ModelEditor.java index 7bc2add9e..f62fc16d3 100644 --- a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/schematic/ModelEditor.java +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/schematic/ModelEditor.java @@ -28,7 +28,6 @@ import java.io.PrintStream; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.Observable; import java.util.Observer; import java.util.Scanner; @@ -142,9 +141,9 @@ import edu.utah.ece.async.ibiosim.gui.modelEditor.util.AbstractRunnableNamedButt import edu.utah.ece.async.ibiosim.gui.modelEditor.util.PropertyList; import edu.utah.ece.async.ibiosim.gui.modelEditor.util.Runnable; import edu.utah.ece.async.ibiosim.gui.modelEditor.util.UndoManager; -import edu.utah.ece.async.ibiosim.gui.util.EditPreferences; import edu.utah.ece.async.ibiosim.gui.util.Log; import edu.utah.ece.async.ibiosim.gui.util.SpringUtilities; +import edu.utah.ece.async.ibiosim.gui.util.preferences.EditPreferences; import edu.utah.ece.async.ibiosim.synthesis.assembly.Assembler2; import edu.utah.ece.async.ibiosim.synthesis.assembly.AssemblyGraph2; import edu.utah.ece.async.ibiosim.synthesis.assembly.SequenceTypeValidator; @@ -725,8 +724,11 @@ public class ModelEditor extends JPanel implements ActionListener, MouseListener //String submissionVersion = cd.isSetVersion() ? cd.getVersion() : "1"; JComboBox registries = new JComboBox(); + registries.addItem("http://synbiohub.org"); registries.addItem("http://synbiohub.utah.edu"); + registries.addItem("http://cidarlab.org:7777"); + registries.addItem("https://synbiohub.cidarlab.org"); registries.addItem("http://localhost:7777"); registries.addItem("http://14compsci099.ncl.ac.uk:7777"); JTextField userField = new JTextField(12); @@ -785,7 +787,7 @@ public class ModelEditor extends JPanel implements ActionListener, MouseListener "Submission Error", JOptionPane.ERROR_MESSAGE); error = true; } - String password = passwordField.getText().trim(); + String password = passwordField.getPassword().toString().trim(); if (password.equals("")) { JOptionPane.showMessageDialog(Gui.frame, "Password Required", "Submission Error", JOptionPane.ERROR_MESSAGE); @@ -2005,7 +2007,7 @@ public class ModelEditor extends JPanel implements ActionListener, MouseListener private static void updateValue(SBMLDocument d,String id,String factor,String paramId,String value,String type) { SBase sbase = SBMLutilities.getElementBySId(d, id); - if (d.getModel().getInitialAssignment(id)!=null) { + if (d.getModel().getInitialAssignmentBySymbol(id)!=null) { d.getModel().getListOfInitialAssignments().remove(id); } if (sbase != null) { @@ -3362,7 +3364,7 @@ public class ModelEditor extends JPanel implements ActionListener, MouseListener if (lower!=upper) { bound = "[" + lower + "," + upper + "]"; } - InitialAssignment ia = flatSBML.getModel().getInitialAssignment(p.getId()); + InitialAssignment ia = flatSBML.getModel().getInitialAssignmentBySymbol(p.getId()); if (ia != null) { ASTNode math = ia.getMath(); if (math.getType()==ASTNode.Type.FUNCTION && math.getName().equals("uniform")) { @@ -3393,7 +3395,7 @@ public class ModelEditor extends JPanel implements ActionListener, MouseListener if (lrate!=urate) { boundRate = "[" + lrate + "," + urate + "]"; } - ia = flatSBML.getModel().getInitialAssignment(rp.getId()); + ia = flatSBML.getModel().getInitialAssignmentBySymbol(rp.getId()); if (ia != null) { ASTNode math = ia.getMath(); if (math.getType()==ASTNode.Type.FUNCTION && math.getName().equals("uniform")) { @@ -3469,7 +3471,7 @@ public class ModelEditor extends JPanel implements ActionListener, MouseListener for (int j = 0; j < postset.size(); j++) { t.addPostset(lpn.getPlace(postset.get(j))); } - Rule r = sbml.getModel().getRule(GlobalConstants.TRIGGER + "_" + e.getId()); + Rule r = sbml.getModel().getRuleByVariable(GlobalConstants.TRIGGER + "_" + e.getId()); if (r != null) { t.setPersistent(true); ASTNode triggerMath = r.getMath(); diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/schematic/Schematic.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/schematic/Schematic.java index 78228a515..257c776af 100644 --- a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/schematic/Schematic.java +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/schematic/Schematic.java @@ -101,7 +101,6 @@ import com.mxgraph.util.mxRectangle; import edu.utah.ece.async.ibiosim.dataModels.biomodel.annotation.AnnotationUtility; import edu.utah.ece.async.ibiosim.dataModels.biomodel.parser.BioModel; import edu.utah.ece.async.ibiosim.dataModels.biomodel.util.SBMLutilities; -import edu.utah.ece.async.ibiosim.dataModels.biomodel.util.Utility; import edu.utah.ece.async.ibiosim.dataModels.util.GlobalConstants; import edu.utah.ece.async.ibiosim.gui.Gui; import edu.utah.ece.async.ibiosim.gui.ResourceManager; diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/schematic/Utils.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/schematic/Utils.java index 5a6d6d00a..d9d7b36b4 100644 --- a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/schematic/Utils.java +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/modelEditor/schematic/Utils.java @@ -13,7 +13,6 @@ *******************************************************************************/ package edu.utah.ece.async.ibiosim.gui.modelEditor.schematic; -import java.awt.Dimension; import java.awt.event.ActionListener; import java.io.IOException; import java.net.URL; @@ -59,8 +58,6 @@ import org.sbml.jsbml.ext.arrays.ArraysSBasePlugin; import org.sbml.jsbml.ext.arrays.util.ArraysMath; import org.sbml.jsbml.ext.arrays.validator.ArraysValidator; import org.sbml.jsbml.validator.SBMLValidator; -import org.sbml.jsbml.validator.SBMLValidator.CHECK_CATEGORY; -import org.sbml.libsbml.SBMLReader; import org.sbml.libsbml.libsbmlConstants; import edu.utah.ece.async.ibiosim.dataModels.biomodel.util.SBMLutilities; diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/sbolBrowser/SBOLBrowser2.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/sbolBrowser/SBOLBrowser2.java index fe259a69e..d61a7413c 100644 --- a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/sbolBrowser/SBOLBrowser2.java +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/sbolBrowser/SBOLBrowser2.java @@ -31,7 +31,7 @@ import org.sbolstandard.core2.Collection; import edu.utah.ece.async.ibiosim.dataModels.sbol.SBOLUtility; import edu.utah.ece.async.ibiosim.dataModels.util.GlobalConstants; import edu.utah.ece.async.ibiosim.gui.Gui; -import edu.utah.ece.async.ibiosim.gui.util.EditPreferences; +import edu.utah.ece.async.ibiosim.gui.util.preferences.EditPreferences; /** * diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/synthesisView/SynthesisView.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/synthesisView/SynthesisView.java index ca865f0f1..38d9f21f7 100644 --- a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/synthesisView/SynthesisView.java +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/synthesisView/SynthesisView.java @@ -53,9 +53,9 @@ import edu.utah.ece.async.ibiosim.dataModels.sbol.SBOLFileManager; import edu.utah.ece.async.ibiosim.dataModels.util.GlobalConstants; import edu.utah.ece.async.ibiosim.dataModels.util.exceptions.SBOLException; import edu.utah.ece.async.ibiosim.gui.Gui; -import edu.utah.ece.async.ibiosim.gui.util.EditPreferences; import edu.utah.ece.async.ibiosim.gui.util.Log; import edu.utah.ece.async.ibiosim.gui.util.Utility; +import edu.utah.ece.async.ibiosim.gui.util.preferences.EditPreferences; import edu.utah.ece.async.ibiosim.synthesis.SBMLTechMapping.SynthesisGraph; import edu.utah.ece.async.ibiosim.synthesis.SBMLTechMapping.Synthesizer; diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/AnalysisPreferencesTab.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/AnalysisPreferencesTab.java new file mode 100644 index 000000000..b1b9ac3fd --- /dev/null +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/AnalysisPreferencesTab.java @@ -0,0 +1,98 @@ +package edu.utah.ece.async.ibiosim.gui.util.preferences; + +import java.awt.Component; + +import javax.swing.ButtonGroup; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JRadioButton; + +import edu.utah.ece.async.ibiosim.dataModels.util.IBioSimPreferences; +import edu.utah.ece.async.ibiosim.gui.ResourceManager; +import edu.utah.ece.async.ibiosim.gui.util.preferences.PreferencesDialog.PreferencesTab; +import edu.utah.ece.async.sboldesigner.sbol.editor.Images; +import edu.utah.ece.async.sboldesigner.swing.FormBuilder; + +public enum AnalysisPreferencesTab implements PreferencesTab { + INSTANCE; + + // askUser is 0, overwrite is 1, and keep is 2 + private JRadioButton seqAskUser = new JRadioButton("Ask", IBioSimPreferences.INSTANCE.getSeqBehavior() == 0); + private JRadioButton seqOverwrite = new JRadioButton("Overwrite", + IBioSimPreferences.INSTANCE.getSeqBehavior() == 1); + private JRadioButton seqKeep = new JRadioButton("Keep", IBioSimPreferences.INSTANCE.getSeqBehavior() == 2); + + // show name is 0, show displayId is 1 + private JRadioButton showName = new JRadioButton("Show name when set", + IBioSimPreferences.INSTANCE.getNameDisplayIdBehavior() == 0); + private JRadioButton showDisplayId = new JRadioButton("Show displayId", + IBioSimPreferences.INSTANCE.getNameDisplayIdBehavior() == 1); + + @Override + public String getTitle() { + return "Analysis"; + } + + @Override + public String getDescription() { + return "Default Analysis Settings"; + } + + @Override + public Icon getIcon() { + return ResourceManager.getImageIcon("simulation.jpg"); + } + + @Override + public Component getComponent() { + JLabel impliedSequence = new JLabel( + "Every time the implied sequence is shorter than the original
sequence, would you like to overwrite or keep the original sequence?"); + ButtonGroup seqGroup = new ButtonGroup(); + seqGroup.add(seqAskUser); + seqGroup.add(seqOverwrite); + seqGroup.add(seqKeep); + + JLabel showNameOrDisplayId = new JLabel("Always show displayId or always show name when set?"); + ButtonGroup nameDisplayIdGroup = new ButtonGroup(); + nameDisplayIdGroup.add(showName); + nameDisplayIdGroup.add(showDisplayId); + + FormBuilder builder = new FormBuilder(); + builder.add("", impliedSequence); + builder.add("", seqAskUser); + builder.add("", seqOverwrite); + builder.add("", seqKeep); + builder.add("", showNameOrDisplayId); + builder.add("", showName); + builder.add("", showDisplayId); + + return builder.build(); + } + + @Override + public void save() { + int seqBehavior = 0; + if (seqAskUser.isSelected()) { + seqBehavior = 0; + } else if (seqOverwrite.isSelected()) { + seqBehavior = 1; + } else if (seqKeep.isSelected()) { + seqBehavior = 2; + } + IBioSimPreferences.INSTANCE.setSeqBehavior(seqBehavior); + + int showNameOrDisplayId = 0; + if (showName.isSelected()) { + showNameOrDisplayId = 0; + } else if (showDisplayId.isSelected()) { + showNameOrDisplayId = 1; + } + IBioSimPreferences.INSTANCE.setNameDisplayIdBehavior(showNameOrDisplayId); + } + + @Override + public boolean requiresRestart() { + return false; + } +} diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/EditPreferences.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/EditPreferences.java similarity index 99% rename from gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/EditPreferences.java rename to gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/EditPreferences.java index f70d4a5d8..143ceec6d 100644 --- a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/EditPreferences.java +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/EditPreferences.java @@ -11,7 +11,7 @@ * and also available online at . * *******************************************************************************/ -package edu.utah.ece.async.ibiosim.gui.util; +package edu.utah.ece.async.ibiosim.gui.util.preferences; import java.awt.BorderLayout; import java.awt.Color; @@ -44,6 +44,7 @@ import edu.utah.ece.async.ibiosim.dataModels.biomodel.parser.CompatibilityFixer; import edu.utah.ece.async.ibiosim.dataModels.sbol.SBOLUtility; import edu.utah.ece.async.ibiosim.dataModels.util.GlobalConstants; import edu.utah.ece.async.ibiosim.gui.Gui; +import edu.utah.ece.async.ibiosim.gui.util.FileTree; /** * @@ -779,10 +780,10 @@ public class EditPreferences { return biosimrc.get(GlobalConstants.SBOL_AUTHORITY_PREFERENCE, GlobalConstants.SBOL_AUTHORITY_DEFAULT); } - private JPanel assemblyPreferences(Preferences biosimrc) { + private JPanel SBOLPreferences(Preferences biosimrc) { // assembly preferences JPanel assemblyLabels = new JPanel(new GridLayout(13, 1)); - assemblyLabels.add(new JLabel("URI Authority")); + assemblyLabels.add(new JLabel("Namespace")); assemblyLabels.add(new JLabel("Assemble Complete Genetic Construct")); assemblyLabels.add(new JLabel("Regex for Complete Genetic Construct")); assemblyLabels.add(new JLabel("Validate Assembled Constructs")); @@ -1405,7 +1406,7 @@ public class EditPreferences { return problem; } - private boolean saveAssemblyPreferences(Preferences biosimrc) { + private boolean saveSBOLPreferences(Preferences biosimrc) { boolean problem = false; if (!uriField.getText().trim().equals("")) { biosimrc.put(GlobalConstants.SBOL_AUTHORITY_PREFERENCE, uriField.getText().trim()); @@ -1456,7 +1457,7 @@ public class EditPreferences { JPanel generalPrefs = generalPreferences(biosimrc); JPanel schematicPrefs = schematicPreferences(biosimrc); JPanel modelPrefs = modelPreferences(biosimrc); - JPanel assemblyPrefs = assemblyPreferences(biosimrc); + JPanel assemblyPrefs = SBOLPreferences(biosimrc); JPanel analysisPrefs = analysisPreferences(biosimrc); JPanel learnPrefs = learnPreferences(biosimrc); @@ -1484,7 +1485,7 @@ public class EditPreferences { if (!problem) problem = saveModelPreferences(biosimrc); if (!problem) problem = saveAnalysisPreferences(biosimrc); if (!problem) problem = saveLearnPreferences(biosimrc); - if (!problem) problem = saveAssemblyPreferences(biosimrc); + if (!problem) problem = saveSBOLPreferences(biosimrc); try { biosimrc.sync(); } diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/GeneralPreferencesTab.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/GeneralPreferencesTab.java new file mode 100644 index 000000000..c3f89b5d0 --- /dev/null +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/GeneralPreferencesTab.java @@ -0,0 +1,98 @@ +package edu.utah.ece.async.ibiosim.gui.util.preferences; + +import java.awt.Component; + +import javax.swing.ButtonGroup; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JRadioButton; + +import edu.utah.ece.async.ibiosim.dataModels.util.IBioSimPreferences; +import edu.utah.ece.async.ibiosim.gui.ResourceManager; +import edu.utah.ece.async.ibiosim.gui.util.preferences.PreferencesDialog.PreferencesTab; +import edu.utah.ece.async.sboldesigner.sbol.editor.Images; +import edu.utah.ece.async.sboldesigner.swing.FormBuilder; + +public enum GeneralPreferencesTab implements PreferencesTab { + INSTANCE; + + // askUser is 0, overwrite is 1, and keep is 2 + private JRadioButton seqAskUser = new JRadioButton("Ask", IBioSimPreferences.INSTANCE.getSeqBehavior() == 0); + private JRadioButton seqOverwrite = new JRadioButton("Overwrite", + IBioSimPreferences.INSTANCE.getSeqBehavior() == 1); + private JRadioButton seqKeep = new JRadioButton("Keep", IBioSimPreferences.INSTANCE.getSeqBehavior() == 2); + + // show name is 0, show displayId is 1 + private JRadioButton showName = new JRadioButton("Show name when set", + IBioSimPreferences.INSTANCE.getNameDisplayIdBehavior() == 0); + private JRadioButton showDisplayId = new JRadioButton("Show displayId", + IBioSimPreferences.INSTANCE.getNameDisplayIdBehavior() == 1); + + @Override + public String getTitle() { + return "General"; + } + + @Override + public String getDescription() { + return "General Preferences"; + } + + @Override + public Icon getIcon() { + return ResourceManager.getImageIcon("general.png"); + } + + @Override + public Component getComponent() { + JLabel impliedSequence = new JLabel( + "Every time the implied sequence is shorter than the original
sequence, would you like to overwrite or keep the original sequence?"); + ButtonGroup seqGroup = new ButtonGroup(); + seqGroup.add(seqAskUser); + seqGroup.add(seqOverwrite); + seqGroup.add(seqKeep); + + JLabel showNameOrDisplayId = new JLabel("Always show displayId or always show name when set?"); + ButtonGroup nameDisplayIdGroup = new ButtonGroup(); + nameDisplayIdGroup.add(showName); + nameDisplayIdGroup.add(showDisplayId); + + FormBuilder builder = new FormBuilder(); + builder.add("", impliedSequence); + builder.add("", seqAskUser); + builder.add("", seqOverwrite); + builder.add("", seqKeep); + builder.add("", showNameOrDisplayId); + builder.add("", showName); + builder.add("", showDisplayId); + + return builder.build(); + } + + @Override + public void save() { + int seqBehavior = 0; + if (seqAskUser.isSelected()) { + seqBehavior = 0; + } else if (seqOverwrite.isSelected()) { + seqBehavior = 1; + } else if (seqKeep.isSelected()) { + seqBehavior = 2; + } + IBioSimPreferences.INSTANCE.setSeqBehavior(seqBehavior); + + int showNameOrDisplayId = 0; + if (showName.isSelected()) { + showNameOrDisplayId = 0; + } else if (showDisplayId.isSelected()) { + showNameOrDisplayId = 1; + } + IBioSimPreferences.INSTANCE.setNameDisplayIdBehavior(showNameOrDisplayId); + } + + @Override + public boolean requiresRestart() { + return false; + } +} diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/LearnPreferencesTab.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/LearnPreferencesTab.java new file mode 100644 index 000000000..673149d7d --- /dev/null +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/LearnPreferencesTab.java @@ -0,0 +1,98 @@ +package edu.utah.ece.async.ibiosim.gui.util.preferences; + +import java.awt.Component; + +import javax.swing.ButtonGroup; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JRadioButton; + +import edu.utah.ece.async.ibiosim.dataModels.util.IBioSimPreferences; +import edu.utah.ece.async.ibiosim.gui.ResourceManager; +import edu.utah.ece.async.ibiosim.gui.util.preferences.PreferencesDialog.PreferencesTab; +import edu.utah.ece.async.sboldesigner.sbol.editor.Images; +import edu.utah.ece.async.sboldesigner.swing.FormBuilder; + +public enum LearnPreferencesTab implements PreferencesTab { + INSTANCE; + + // askUser is 0, overwrite is 1, and keep is 2 + private JRadioButton seqAskUser = new JRadioButton("Ask", IBioSimPreferences.INSTANCE.getSeqBehavior() == 0); + private JRadioButton seqOverwrite = new JRadioButton("Overwrite", + IBioSimPreferences.INSTANCE.getSeqBehavior() == 1); + private JRadioButton seqKeep = new JRadioButton("Keep", IBioSimPreferences.INSTANCE.getSeqBehavior() == 2); + + // show name is 0, show displayId is 1 + private JRadioButton showName = new JRadioButton("Show name when set", + IBioSimPreferences.INSTANCE.getNameDisplayIdBehavior() == 0); + private JRadioButton showDisplayId = new JRadioButton("Show displayId", + IBioSimPreferences.INSTANCE.getNameDisplayIdBehavior() == 1); + + @Override + public String getTitle() { + return "Learn"; + } + + @Override + public String getDescription() { + return "Default Learn Settings"; + } + + @Override + public Icon getIcon() { + return ResourceManager.getImageIcon("learn.jpg"); + } + + @Override + public Component getComponent() { + JLabel impliedSequence = new JLabel( + "Every time the implied sequence is shorter than the original
sequence, would you like to overwrite or keep the original sequence?"); + ButtonGroup seqGroup = new ButtonGroup(); + seqGroup.add(seqAskUser); + seqGroup.add(seqOverwrite); + seqGroup.add(seqKeep); + + JLabel showNameOrDisplayId = new JLabel("Always show displayId or always show name when set?"); + ButtonGroup nameDisplayIdGroup = new ButtonGroup(); + nameDisplayIdGroup.add(showName); + nameDisplayIdGroup.add(showDisplayId); + + FormBuilder builder = new FormBuilder(); + builder.add("", impliedSequence); + builder.add("", seqAskUser); + builder.add("", seqOverwrite); + builder.add("", seqKeep); + builder.add("", showNameOrDisplayId); + builder.add("", showName); + builder.add("", showDisplayId); + + return builder.build(); + } + + @Override + public void save() { + int seqBehavior = 0; + if (seqAskUser.isSelected()) { + seqBehavior = 0; + } else if (seqOverwrite.isSelected()) { + seqBehavior = 1; + } else if (seqKeep.isSelected()) { + seqBehavior = 2; + } + IBioSimPreferences.INSTANCE.setSeqBehavior(seqBehavior); + + int showNameOrDisplayId = 0; + if (showName.isSelected()) { + showNameOrDisplayId = 0; + } else if (showDisplayId.isSelected()) { + showNameOrDisplayId = 1; + } + IBioSimPreferences.INSTANCE.setNameDisplayIdBehavior(showNameOrDisplayId); + } + + @Override + public boolean requiresRestart() { + return false; + } +} diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/ModelEditorPreferencesTab.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/ModelEditorPreferencesTab.java new file mode 100644 index 000000000..bdbf040b2 --- /dev/null +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/ModelEditorPreferencesTab.java @@ -0,0 +1,98 @@ +package edu.utah.ece.async.ibiosim.gui.util.preferences; + +import java.awt.Component; + +import javax.swing.ButtonGroup; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JRadioButton; + +import edu.utah.ece.async.ibiosim.dataModels.util.IBioSimPreferences; +import edu.utah.ece.async.ibiosim.gui.ResourceManager; +import edu.utah.ece.async.ibiosim.gui.util.preferences.PreferencesDialog.PreferencesTab; +import edu.utah.ece.async.sboldesigner.sbol.editor.Images; +import edu.utah.ece.async.sboldesigner.swing.FormBuilder; + +public enum ModelEditorPreferencesTab implements PreferencesTab { + INSTANCE; + + // askUser is 0, overwrite is 1, and keep is 2 + private JRadioButton seqAskUser = new JRadioButton("Ask", IBioSimPreferences.INSTANCE.getSeqBehavior() == 0); + private JRadioButton seqOverwrite = new JRadioButton("Overwrite", + IBioSimPreferences.INSTANCE.getSeqBehavior() == 1); + private JRadioButton seqKeep = new JRadioButton("Keep", IBioSimPreferences.INSTANCE.getSeqBehavior() == 2); + + // show name is 0, show displayId is 1 + private JRadioButton showName = new JRadioButton("Show name when set", + IBioSimPreferences.INSTANCE.getNameDisplayIdBehavior() == 0); + private JRadioButton showDisplayId = new JRadioButton("Show displayId", + IBioSimPreferences.INSTANCE.getNameDisplayIdBehavior() == 1); + + @Override + public String getTitle() { + return "Model Editor"; + } + + @Override + public String getDescription() { + return "Preferences for Model Editor Schematic"; + } + + @Override + public Icon getIcon() { + return ResourceManager.getImageIcon("sbml.jpg"); + } + + @Override + public Component getComponent() { + JLabel impliedSequence = new JLabel( + "Every time the implied sequence is shorter than the original
sequence, would you like to overwrite or keep the original sequence?"); + ButtonGroup seqGroup = new ButtonGroup(); + seqGroup.add(seqAskUser); + seqGroup.add(seqOverwrite); + seqGroup.add(seqKeep); + + JLabel showNameOrDisplayId = new JLabel("Always show displayId or always show name when set?"); + ButtonGroup nameDisplayIdGroup = new ButtonGroup(); + nameDisplayIdGroup.add(showName); + nameDisplayIdGroup.add(showDisplayId); + + FormBuilder builder = new FormBuilder(); + builder.add("", impliedSequence); + builder.add("", seqAskUser); + builder.add("", seqOverwrite); + builder.add("", seqKeep); + builder.add("", showNameOrDisplayId); + builder.add("", showName); + builder.add("", showDisplayId); + + return builder.build(); + } + + @Override + public void save() { + int seqBehavior = 0; + if (seqAskUser.isSelected()) { + seqBehavior = 0; + } else if (seqOverwrite.isSelected()) { + seqBehavior = 1; + } else if (seqKeep.isSelected()) { + seqBehavior = 2; + } + IBioSimPreferences.INSTANCE.setSeqBehavior(seqBehavior); + + int showNameOrDisplayId = 0; + if (showName.isSelected()) { + showNameOrDisplayId = 0; + } else if (showDisplayId.isSelected()) { + showNameOrDisplayId = 1; + } + IBioSimPreferences.INSTANCE.setNameDisplayIdBehavior(showNameOrDisplayId); + } + + @Override + public boolean requiresRestart() { + return false; + } +} diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/ModelPreferencesTab.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/ModelPreferencesTab.java new file mode 100644 index 000000000..7f661708f --- /dev/null +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/ModelPreferencesTab.java @@ -0,0 +1,98 @@ +package edu.utah.ece.async.ibiosim.gui.util.preferences; + +import java.awt.Component; + +import javax.swing.ButtonGroup; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JRadioButton; + +import edu.utah.ece.async.ibiosim.dataModels.util.IBioSimPreferences; +import edu.utah.ece.async.ibiosim.gui.ResourceManager; +import edu.utah.ece.async.ibiosim.gui.util.preferences.PreferencesDialog.PreferencesTab; +import edu.utah.ece.async.sboldesigner.sbol.editor.Images; +import edu.utah.ece.async.sboldesigner.swing.FormBuilder; + +public enum ModelPreferencesTab implements PreferencesTab { + INSTANCE; + + // askUser is 0, overwrite is 1, and keep is 2 + private JRadioButton seqAskUser = new JRadioButton("Ask", IBioSimPreferences.INSTANCE.getSeqBehavior() == 0); + private JRadioButton seqOverwrite = new JRadioButton("Overwrite", + IBioSimPreferences.INSTANCE.getSeqBehavior() == 1); + private JRadioButton seqKeep = new JRadioButton("Keep", IBioSimPreferences.INSTANCE.getSeqBehavior() == 2); + + // show name is 0, show displayId is 1 + private JRadioButton showName = new JRadioButton("Show name when set", + IBioSimPreferences.INSTANCE.getNameDisplayIdBehavior() == 0); + private JRadioButton showDisplayId = new JRadioButton("Show displayId", + IBioSimPreferences.INSTANCE.getNameDisplayIdBehavior() == 1); + + @Override + public String getTitle() { + return "Model"; + } + + @Override + public String getDescription() { + return "Default Model Parameters"; + } + + @Override + public Icon getIcon() { + return ResourceManager.getImageIcon("dot.jpg"); + } + + @Override + public Component getComponent() { + JLabel impliedSequence = new JLabel( + "Every time the implied sequence is shorter than the original
sequence, would you like to overwrite or keep the original sequence?"); + ButtonGroup seqGroup = new ButtonGroup(); + seqGroup.add(seqAskUser); + seqGroup.add(seqOverwrite); + seqGroup.add(seqKeep); + + JLabel showNameOrDisplayId = new JLabel("Always show displayId or always show name when set?"); + ButtonGroup nameDisplayIdGroup = new ButtonGroup(); + nameDisplayIdGroup.add(showName); + nameDisplayIdGroup.add(showDisplayId); + + FormBuilder builder = new FormBuilder(); + builder.add("", impliedSequence); + builder.add("", seqAskUser); + builder.add("", seqOverwrite); + builder.add("", seqKeep); + builder.add("", showNameOrDisplayId); + builder.add("", showName); + builder.add("", showDisplayId); + + return builder.build(); + } + + @Override + public void save() { + int seqBehavior = 0; + if (seqAskUser.isSelected()) { + seqBehavior = 0; + } else if (seqOverwrite.isSelected()) { + seqBehavior = 1; + } else if (seqKeep.isSelected()) { + seqBehavior = 2; + } + IBioSimPreferences.INSTANCE.setSeqBehavior(seqBehavior); + + int showNameOrDisplayId = 0; + if (showName.isSelected()) { + showNameOrDisplayId = 0; + } else if (showDisplayId.isSelected()) { + showNameOrDisplayId = 1; + } + IBioSimPreferences.INSTANCE.setNameDisplayIdBehavior(showNameOrDisplayId); + } + + @Override + public boolean requiresRestart() { + return false; + } +} diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/PartEditorPreferencesTab.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/PartEditorPreferencesTab.java new file mode 100644 index 000000000..1cd500ade --- /dev/null +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/PartEditorPreferencesTab.java @@ -0,0 +1,98 @@ +package edu.utah.ece.async.ibiosim.gui.util.preferences; + +import java.awt.Component; + +import javax.swing.ButtonGroup; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JRadioButton; + +import edu.utah.ece.async.ibiosim.dataModels.util.IBioSimPreferences; +import edu.utah.ece.async.ibiosim.gui.ResourceManager; +import edu.utah.ece.async.ibiosim.gui.util.preferences.PreferencesDialog.PreferencesTab; +import edu.utah.ece.async.sboldesigner.sbol.editor.Images; +import edu.utah.ece.async.sboldesigner.swing.FormBuilder; + +public enum PartEditorPreferencesTab implements PreferencesTab { + INSTANCE; + + // askUser is 0, overwrite is 1, and keep is 2 + private JRadioButton seqAskUser = new JRadioButton("Ask", IBioSimPreferences.INSTANCE.getSeqBehavior() == 0); + private JRadioButton seqOverwrite = new JRadioButton("Overwrite", + IBioSimPreferences.INSTANCE.getSeqBehavior() == 1); + private JRadioButton seqKeep = new JRadioButton("Keep", IBioSimPreferences.INSTANCE.getSeqBehavior() == 2); + + // show name is 0, show displayId is 1 + private JRadioButton showName = new JRadioButton("Show name when set", + IBioSimPreferences.INSTANCE.getNameDisplayIdBehavior() == 0); + private JRadioButton showDisplayId = new JRadioButton("Show displayId", + IBioSimPreferences.INSTANCE.getNameDisplayIdBehavior() == 1); + + @Override + public String getTitle() { + return "Part Editor"; + } + + @Override + public String getDescription() { + return "Settings for SBOLDesigner Plugin"; + } + + @Override + public Icon getIcon() { + return ResourceManager.getImageIcon("sbol.jpg"); + } + + @Override + public Component getComponent() { + JLabel impliedSequence = new JLabel( + "Every time the implied sequence is shorter than the original
sequence, would you like to overwrite or keep the original sequence?"); + ButtonGroup seqGroup = new ButtonGroup(); + seqGroup.add(seqAskUser); + seqGroup.add(seqOverwrite); + seqGroup.add(seqKeep); + + JLabel showNameOrDisplayId = new JLabel("Always show displayId or always show name when set?"); + ButtonGroup nameDisplayIdGroup = new ButtonGroup(); + nameDisplayIdGroup.add(showName); + nameDisplayIdGroup.add(showDisplayId); + + FormBuilder builder = new FormBuilder(); + builder.add("", impliedSequence); + builder.add("", seqAskUser); + builder.add("", seqOverwrite); + builder.add("", seqKeep); + builder.add("", showNameOrDisplayId); + builder.add("", showName); + builder.add("", showDisplayId); + + return builder.build(); + } + + @Override + public void save() { + int seqBehavior = 0; + if (seqAskUser.isSelected()) { + seqBehavior = 0; + } else if (seqOverwrite.isSelected()) { + seqBehavior = 1; + } else if (seqKeep.isSelected()) { + seqBehavior = 2; + } + IBioSimPreferences.INSTANCE.setSeqBehavior(seqBehavior); + + int showNameOrDisplayId = 0; + if (showName.isSelected()) { + showNameOrDisplayId = 0; + } else if (showDisplayId.isSelected()) { + showNameOrDisplayId = 1; + } + IBioSimPreferences.INSTANCE.setNameDisplayIdBehavior(showNameOrDisplayId); + } + + @Override + public boolean requiresRestart() { + return false; + } +} diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/PreferencesDialog.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/PreferencesDialog.java new file mode 100644 index 000000000..90f2cfe41 --- /dev/null +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/PreferencesDialog.java @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2012 - 2015, Clark & Parsia, LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package edu.utah.ece.async.ibiosim.gui.util.preferences; + +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.DefaultListCellRenderer; +import javax.swing.DefaultListModel; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.KeyStroke; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + +import com.google.common.base.Objects; + +/** + * + * @author Evren Sirin + */ +public class PreferencesDialog extends JDialog implements ActionListener { + private static final String TITLE = "Preferences"; + + private static final PreferencesTab[] TABS = { UserInfoTab.INSTANCE, RegistryPreferencesTab.INSTANCE, + GeneralPreferencesTab.INSTANCE, PartEditorPreferencesTab.INSTANCE, ModelEditorPreferencesTab.INSTANCE, + ModelPreferencesTab.INSTANCE, AnalysisPreferencesTab.INSTANCE, LearnPreferencesTab.INSTANCE + /** + * SOMappingTab.INSTANCE, + * VersioningPreferencesTab.INSTANCE + **/ + }; + + public static void showPreferences(Component parent) { + showPreferences(parent, null); + } + + public static void showPreferences(Component parent, String selectTab) { + PreferencesDialog dialog = new PreferencesDialog(parent, selectTab); + dialog.setVisible(true); + } + + private PreferencesDialog(Component parent, String selectTab) { + super(JOptionPane.getFrameForComponent(parent), TITLE, true); + + final JButton closeButton = new JButton("Close"); + closeButton.addActionListener(this); + closeButton.registerKeyboardAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), + JComponent.WHEN_IN_FOCUSED_WINDOW); + getRootPane().setDefaultButton(closeButton); + + // Create the panel that contains the "cards". + final JPanel cards = new JPanel(new CardLayout()); + DefaultListModel listModel = new DefaultListModel(); + int selectedIndex = 0; + for (PreferencesTab tab : TABS) { + cards.add(new JScrollPane(tab.getComponent()), tab.getTitle()); + if (Objects.equal(tab.getTitle(), selectTab)) { + selectedIndex = listModel.size(); + } + listModel.addElement(tab); + } + + final JList list = new JList(listModel); + list.setFocusable(false); + list.setPreferredSize(new Dimension(100, 100)); + list.setCellRenderer(new DefaultListCellRenderer() { + public Component getListCellRendererComponent(JList list, // the + // list + Object value, // value to display + int index, // cell index + boolean isSelected, // is the cell selected + boolean cellHasFocus) // does the cell have focus + { + super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + PreferencesTab tab = (PreferencesTab) value; + setText(tab.getTitle()); + setIcon(tab.getIcon()); + setToolTipText(tab.getDescription()); + return this; + } + }); + + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + list.addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent event) { + if (!event.getValueIsAdjusting()) { + CardLayout layout = (CardLayout) cards.getLayout(); + layout.show(cards, ((PreferencesTab) list.getSelectedValue()).getTitle()); + } + } + }); + list.setSelectedIndex(selectedIndex); + + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); + buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); + buttonPane.add(Box.createHorizontalGlue()); + buttonPane.add(closeButton); + + Container contentPane = getContentPane(); + contentPane.add(new JScrollPane(list), BorderLayout.WEST); + contentPane.add(cards, BorderLayout.CENTER); + contentPane.add(buttonPane, BorderLayout.SOUTH); + + setSize(600, 450); + setLocationRelativeTo(getOwner()); + } + + public void actionPerformed(ActionEvent e) { + boolean restart = false; + for (PreferencesTab tab : TABS) { + restart = tab.requiresRestart(); + tab.save(); + } + + if (restart) { + JOptionPane.showMessageDialog(this, "Your changes will take effect next time the program is started"); + } + + setVisible(false); + } + + interface PreferencesTab { + String getTitle(); + + String getDescription(); + + Icon getIcon(); + + Component getComponent(); + + void save(); + + boolean requiresRestart(); + } +} diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/RegistryPreferencesTab.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/RegistryPreferencesTab.java new file mode 100644 index 000000000..9765b77cf --- /dev/null +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/RegistryPreferencesTab.java @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2012 - 2015, Clark & Parsia, LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package edu.utah.ece.async.ibiosim.gui.util.preferences; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableRowSorter; + +import edu.utah.ece.async.ibiosim.gui.ResourceManager; +import edu.utah.ece.async.ibiosim.gui.util.preferences.PreferencesDialog.PreferencesTab; +import edu.utah.ece.async.sboldesigner.sbol.editor.Images; +import edu.utah.ece.async.sboldesigner.sbol.editor.Registries; +import edu.utah.ece.async.sboldesigner.sbol.editor.Registry; +import edu.utah.ece.async.sboldesigner.sbol.editor.dialog.RegistryAddDialog; + +public enum RegistryPreferencesTab implements PreferencesTab { + INSTANCE; + + @Override + public String getTitle() { + return "Registries"; + } + + @Override + public String getDescription() { + return "Configuration options for part registries"; + } + + @Override + public Icon getIcon() { + return ResourceManager.getImageIcon("registry.png"); + } + + @Override + public Component getComponent() { + final RegistryTableModel tableModel = new RegistryTableModel(); + final JTable table = new JTable(tableModel); + table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + + ActionListener listener = new ActionListener() { + public void actionPerformed(ActionEvent e) { + RegistryTableModel model = (RegistryTableModel) table.getModel(); + Action action = Action.valueOf(e.getActionCommand()); + switch (action) { + case ADD: + Registry registry = new RegistryAddDialog(table, null).getInput(); + if (registry != null) { + model.add(registry); + Registries.get().save(); + } + break; + case REMOVE: + int row = table.convertRowIndexToModel(table.getSelectedRow()); + model.remove(row); + Registries.get().save(); + break; + case RESTORE: + model.restoreDefaults(); + Registries.get().save(); + break; + case EDIT: + row = table.convertRowIndexToModel(table.getSelectedRow()); + if (row > model.getRowCount()) { + return; + } else { + Registry oldRegistry = model.getComponent(row); + registry = new RegistryAddDialog(table, oldRegistry).getInput(); + if (registry != null) { + model.remove(row); + model.add(registry); + Registries.get().save(); + } + } + break; + } + } + }; + + final JButton addButton = new JButton("Add"); + addButton.setActionCommand(Action.ADD.toString()); + addButton.addActionListener(listener); + + final JButton editButton = new JButton("Edit"); + editButton.setActionCommand(Action.EDIT.toString()); + editButton.addActionListener(listener); + editButton.setEnabled(false); + + final JButton removeButton = new JButton("Remove"); + removeButton.setActionCommand(Action.REMOVE.toString()); + removeButton.addActionListener(listener); + removeButton.setEnabled(false); + + final JButton restoreButton = new JButton("Restore defaults"); + restoreButton.setActionCommand(Action.RESTORE.toString()); + restoreButton.addActionListener(listener); + restoreButton.setEnabled(true); + + table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + @Override + public void valueChanged(ListSelectionEvent event) { + // Everything can be removed/edited except Built-In parts. + removeButton.setEnabled(table.getSelectedRow() >= 2); + editButton.setEnabled(table.getSelectedRow() >= 2); + } + }); + + //OldInputDialog.setWidthAsPercentages(table, 0.2, 0.2, 0.6); + + TableRowSorter sorter = new TableRowSorter(tableModel); + table.setRowSorter(sorter); + + JScrollPane tableScroller = new JScrollPane(table); + tableScroller.setPreferredSize(new Dimension(450, 200)); + tableScroller.setAlignmentX(Component.LEFT_ALIGNMENT); + + JPanel tablePane = new JPanel(); + tablePane.setLayout(new BoxLayout(tablePane, BoxLayout.PAGE_AXIS)); + JLabel label = new JLabel("Registry list"); + label.setLabelFor(table); + tablePane.add(label); + tablePane.add(Box.createRigidArea(new Dimension(0, 5))); + tablePane.add(tableScroller); + tablePane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); + buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); + buttonPane.add(addButton); + buttonPane.add(editButton); + buttonPane.add(removeButton); + buttonPane.add(Box.createHorizontalGlue()); + buttonPane.add(restoreButton); + + Container contentPane = new JPanel(new BorderLayout()); + contentPane.add(tablePane, BorderLayout.CENTER); + contentPane.add(buttonPane, BorderLayout.SOUTH); + return contentPane; + } + + @Override + public void save() { + } + + @Override + public boolean requiresRestart() { + return false; + } + + private static enum Action { + ADD, REMOVE, RESTORE, EDIT + } + + private static class RegistryTableModel extends AbstractTableModel { + private static final String[] COLUMNS = { "Name", "URL/Path", "Description" }; + private Registries registries; + + public RegistryTableModel() { + this.registries = Registries.get(); + } + + public void restoreDefaults() { + registries.restoreDefaults(); + fireTableDataChanged(); + } + + public void add(Registry registry) { + registries.add(registry); + fireTableDataChanged(); + } + + public void remove(int row) { + registries.remove(row); + fireTableDataChanged(); + } + + public int getColumnCount() { + return COLUMNS.length; + } + + public int getRowCount() { + return registries.size(); + } + + public String getColumnName(int col) { + return COLUMNS[col]; + } + + public Registry getComponent(int row) { + return registries.get(row); + } + + public Object getValueAt(int row, int col) { + Registry registry = getComponent(row); + switch (col) { + case 0: + return registry.getName(); + case 1: + return registry.getLocation(); + case 2: + return registry.getDescription(); + default: + throw new IndexOutOfBoundsException(); + } + } + + public Class getColumnClass(int col) { + return Object.class; + } + + public boolean isCellEditable(int row, int col) { + return false; + } + } +} \ No newline at end of file diff --git a/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/UserInfoTab.java b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/UserInfoTab.java new file mode 100644 index 000000000..8dcd40397 --- /dev/null +++ b/gui/src/main/java/edu/utah/ece/async/ibiosim/gui/util/preferences/UserInfoTab.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2012 - 2015, Clark & Parsia, LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package edu.utah.ece.async.ibiosim.gui.util.preferences; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.net.URI; + +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import com.google.common.base.Strings; + +import edu.utah.ece.async.ibiosim.dataModels.util.IBioSimPreferences; +import edu.utah.ece.async.ibiosim.dataModels.util.Infos; +import edu.utah.ece.async.ibiosim.dataModels.util.PersonInfo; +import edu.utah.ece.async.ibiosim.gui.ResourceManager; +import edu.utah.ece.async.ibiosim.gui.util.preferences.PreferencesDialog.PreferencesTab; +import edu.utah.ece.async.sboldesigner.sbol.editor.Images; +import edu.utah.ece.async.sboldesigner.swing.FormBuilder; + +public enum UserInfoTab implements PreferencesTab { + INSTANCE; + + private JTextField name; + private JTextField email; + private JTextField uri; + + @Override + public String getTitle() { + return "User"; + } + + @Override + public String getDescription() { + return "User information added to designs"; + } + + @Override + public Icon getIcon() { + return ResourceManager.getImageIcon("user.png"); + } + + @Override + public Component getComponent() { + PersonInfo info = IBioSimPreferences.INSTANCE.getUserInfo(); + FormBuilder builder = new FormBuilder(); + name = builder.addTextField("Full name", info == null ? null : info.getName()); + email = builder.addTextField("Email", + info == null || info.getEmail() == null ? null : info.getEmail().toString()); + uri = builder.addTextField("Namespace [required]", info == null ? null : info.getURI().toString()); + JPanel formPanel = builder.build(); + + JButton deleteInfo = new JButton("Delete user info"); + deleteInfo.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + PersonInfo userInfo = Infos.forPerson(uri.getText()); + IBioSimPreferences.INSTANCE.saveUserInfo(userInfo); + name.setText(null); + email.setText(null); + } + }); + deleteInfo.setAlignmentX(Component.RIGHT_ALIGNMENT); + deleteInfo.setEnabled(info != null); + + Box buttonPanel = Box.createHorizontalBox(); + buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); + buttonPanel.add(Box.createHorizontalGlue()); + buttonPanel.add(deleteInfo); + + JPanel p = new JPanel(new BorderLayout()); + p.add(formPanel, BorderLayout.NORTH); + p.add(buttonPanel, BorderLayout.SOUTH); + + return p; + } + + @Override + public void save() { + boolean noURI = Strings.isNullOrEmpty(uri.getText()); + boolean noName = Strings.isNullOrEmpty(name.getText()); + boolean noEmail = Strings.isNullOrEmpty(email.getText()); + if (!(noURI && noName && noEmail)) { + URI personURI = URI.create(uri.getText()); + String personName = noName ? "" : name.getText(); + String personEmail = noEmail ? null : email.getText(); + PersonInfo info = Infos.forPerson(personURI, personName, personEmail); + IBioSimPreferences.INSTANCE.saveUserInfo(info); + } + } + + @Override + public boolean requiresRestart() { + return false; + } +} \ No newline at end of file diff --git a/gui/src/main/resources/edu/utah/ece/async/ibiosim/gui/icons/general.png b/gui/src/main/resources/edu/utah/ece/async/ibiosim/gui/icons/general.png new file mode 100644 index 0000000000000000000000000000000000000000..4ca24df6a069df05041dd28e2bd4e007c564720a GIT binary patch literal 1007 zcmeAS@N?(olHy`uVBq!ia0y~yU=RUe4mJh`hTcwDUIqpR#^NA%Cx&(BWL`2bFt8D(@8W?*2> z_jGX#u{hlu>gy96DPjBmre9{9n+}gMb4pUrWQmJzL9;C+<{dkl!=tti3cN$&~e=+~J0*r~Cf*Z*9N#9)J9I)y9py3_P*^sY(+Ifpprio*_xy zrflaOeNojFN0Y=}J9HmiGrg|l?e-+ zb_sEbUS0bw)L};8ln2+A75+B6+;rf`#^fuDFP>WX>6cY_diqRBxo3a&)y8bRow+J2 zwcahTNlPKYW74jo*-SHngMG|Q3eLTL>Sh-0FDy3M^W3)W##e87X-`)4e3oRG?J;SW zLG8yy_1Yf~KRw;krL;M8>ea(V_4dnI8&`)q`Nr;eApX6=CXQi2X41=}+#h}v*1Roy zZxN^a{QTkzcY2N9q=@Z}YU12kzbL`_FtZ?eMz8?Gr0MFB2*@G23?Y z$XQn{0f%dwCdkSk=fA1*W_S5}k1RQhhM=oaEDBE7gBc!7NPV-nh_(9mt%Nh@-+OGE z=y!OY$AZPXcMC0Ex7SA8o1|^|Ib~T5Z}?OBFS>8|5#BrcM)!+kUg+?!yOj&-wAi?LGD7_V%e=XDjZ+ z{JtZ@;J`d#dg}b2GiztI9o$+n%hLDvqFQ4St*6yhb=S598@w;t$?M7)bz5SMXm@1W zB9_mlJYg$bqnKD6C-rrupPwgeE4O~b&si&8YibK|Mz8ucrS;H~&Bw$)2$silU#^QZ SdBwoMz~JfX=d#Wzp$Py2(ACBO literal 0 HcmV?d00001 diff --git a/gui/src/main/resources/edu/utah/ece/async/ibiosim/gui/icons/registry.png b/gui/src/main/resources/edu/utah/ece/async/ibiosim/gui/icons/registry.png new file mode 100644 index 0000000000000000000000000000000000000000..d94482e14bc0353aae22d37308021216b725d85f GIT binary patch literal 202 zcmeAS@N?(olHy`uVBq!ia0y~yU=RUeCT0c(h7Zrb&SPL;U@Q)DcVbv~PUa;80|RG( zPlziw3pWQF2PZ41)-u*WkcyHZzhDN3XE)M7oFs2|7lsa2Sr3r%0*}aI1_s{iAk65b zF}s3+fq}im)7O>#A&VT7xK2XojSmbA47#2!jv*Y^lM@)4*MzPPTbmNW%A}#flEFAr tJK!WMPfUSOuvqgHrb)pIR3sP}-U;fhn5K}>&%nUI;OXk;vd$@?2>@LRF!lfd literal 0 HcmV?d00001 diff --git a/gui/src/main/resources/edu/utah/ece/async/ibiosim/gui/icons/user.png b/gui/src/main/resources/edu/utah/ece/async/ibiosim/gui/icons/user.png new file mode 100644 index 0000000000000000000000000000000000000000..13d999ed529ace4b2383cecdf8b84c6364c2ee29 GIT binary patch literal 296 zcmeAS@N?(olHy`uVBq!ia0y~yU=RUe4rT@hhF#%r?HL#t7>k44ofy`glX=O&z+e;L z6XME%0+<;Xm>C$Dn81jUff0%|+IbytIXODPX&3>)78&qol`;+0Qcoc Av;Y7A literal 0 HcmV?d00001 diff --git a/manifast b/manifast new file mode 100644 index 000000000..58630c02e --- /dev/null +++ b/manifast @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 +