001 /*
002 * The contents of this file are subject to the Mozilla Public
003 * License Version 1.1 (the "License"); you may not use this file
004 * except in compliance with the License. You may obtain a copy of
005 * the License at http://www.mozilla.org/MPL/
006 *
007 * Software distributed under the License is distributed on an "AS
008 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
009 * implied. See the License for the specific language governing
010 * rights and limitations under the License.
011 *
012 * The Original Code is Knowtator.
013 *
014 * The Initial Developer of the Original Code is University of Colorado.
015 * Copyright (C) 2005 - 2008. All Rights Reserved.
016 *
017 * Knowtator was developed by the Center for Computational Pharmacology
018 * (http://compbio.uchcs.edu) at the University of Colorado Health
019 * Sciences Center School of Medicine with support from the National
020 * Library of Medicine.
021 *
022 * Current information about Knowtator can be obtained at
023 * http://knowtator.sourceforge.net/
024 *
025 * Contributor(s):
026 * Philip V. Ogren <philip@ogren.info> (Original Author)
027 */
028
029 /**
030 * Changes
031 * 8/15/2005 pvo added two methods getAnnotationFilters and setAnnotationFilters
032 * instead of using the project client information for persisting the
033 * annotation filters that are selected, the knowtator.pprj was updated
034 * with a new instance for storing the selected filters. If the instance
035 * does not exist, then it is created.
036 */
037 package edu.uchsc.ccp.knowtator;
038
039 /*
040 * ProjectSettings
041 *
042 * Created on October 15, 2004, 8:20 AM
043 */
044
045 import java.lang.reflect.Method;
046
047 import edu.stanford.smi.protege.model.Project;
048 import edu.stanford.smi.protege.model.SimpleInstance;
049 import edu.uchsc.ccp.knowtator.textsource.TextSourceCollection;
050
051 public class ProjectSettings {
052
053 /**
054 * Records the most recent type of TextSourceCollection (tsc) used by this
055 * project.
056 */
057 public static final String PROJECT_RECENT_TSC = new String("PROJECT_RECENT_TSC");
058
059 public static final String PROJECT_RECENT_TSC_INDEX = new String("PROJECT_RECENT_TSC_INDEX");
060
061 public static final String SHOW_INSTANCES = new String("SHOW_INSTANCES");
062
063 public static final String DEFAULT_TOKEN_REGEX = new String("\\W+");
064
065 public static final String ACTIVE_CONFIGURATION = new String("ACTIVE_CONFIGURATION");
066
067 public static boolean getShowInstances(Project project) {
068 Object showInstances = project.getClientInformation(SHOW_INSTANCES);
069 if (showInstances == null || !(showInstances instanceof Boolean))
070 return false;
071 return ((Boolean) showInstances).booleanValue();
072 }
073
074 public static void setShowInstances(Project project, boolean showInstances) {
075 project.setClientInformation(SHOW_INSTANCES, new Boolean(showInstances));
076 }
077
078 public static TextSourceCollection getRecentTextSourceCollection(Project project) {
079 /**
080 *call static method getProjectRecentTextSourceCollection on TSC
081 */
082 try {
083 TextSourceCollection tsc;
084 String tscClassName = (String) project.getClientInformation(PROJECT_RECENT_TSC);
085 if (tscClassName != null) {
086 Class tscClass = Class.forName(tscClassName);
087 Method tscMethod = tscClass.getMethod("open", new Class[] { Project.class });
088 tsc = (TextSourceCollection) tscMethod.invoke(null, new Object[] { project });
089 return tsc;
090 }
091 } catch (Exception exception) {
092 exception.printStackTrace();
093 }
094 return null;
095 }
096
097 public static void setRecentTextSourceCollection(Project project, TextSourceCollection tsc) {
098 project.setClientInformation(ProjectSettings.PROJECT_RECENT_TSC, tsc.getClass().getName());
099 tsc.save(project);
100 }
101
102 public static int getRecentTextSourceCollectionIndex(Project project) {
103 Integer recentIndex = (Integer) project.getClientInformation(PROJECT_RECENT_TSC_INDEX);
104
105 if (recentIndex == null) {
106 return 0;
107 }
108 return recentIndex;
109 }
110
111 public static void setRecentTextSourceCollectionIndex(Project project, int recentIndex) {
112 project.setClientInformation(PROJECT_RECENT_TSC_INDEX, new Integer(recentIndex));
113 }
114
115 public static SimpleInstance getActiveConfiguration(Project project) {
116 return (SimpleInstance) project.getClientInformation(ACTIVE_CONFIGURATION);
117 }
118
119 public static void setActiveConfiguration(Project project, SimpleInstance configurationInstance) {
120 project.setClientInformation(ACTIVE_CONFIGURATION, configurationInstance);
121 }
122
123 // public void setAnnotationPicker
124 }