jadex.bpmn.editor.gui.Settings Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-editor-bpmn Show documentation
Show all versions of jadex-editor-bpmn Show documentation
Editor for Business Process Model and Notation (BPMN).
package jadex.bpmn.editor.gui;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Modifier;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import java.util.jar.JarEntry;
import javax.swing.SwingUtilities;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Opcodes;
import com.mxgraph.view.mxStylesheet;
import jadex.bpmn.editor.BpmnEditor;
import jadex.bpmn.editor.gui.propertypanels.PropertyPanelFactory;
import jadex.bpmn.model.task.ITask;
import jadex.bpmn.model.task.annotation.Task;
import jadex.bridge.ClassInfo;
import jadex.commons.IFilter;
import jadex.commons.SReflect;
import jadex.commons.SUtil;
import jadex.commons.Tuple2;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.commons.future.IResultListener;
/**
* The editor settings.
*/
public class Settings
{
/** The settings file name. */
protected static final String SETTINGS_FILE_NAME = "settings.cfg";
/** The class cache file name. */
protected static final String CLASS_CACHE_FILE_NAME = "classes.cache";
/** The property panel factory */
protected PropertyPanelFactory propertypanelfactory;
/** The progress bar for background tasks. */
protected BackgroundProgressBar bgprogressbar;
/** The image provider. */
protected ImageProvider imageprovider = new ImageProvider();
/** The last file opened or saved. */
protected File lastfile;
/** Files that were opened when editor was closed. */
protected File[] openedfiles;
/** The last file opened or saved. */
protected int toolbariconsize = GuiConstants.DEFAULT_ICON_SIZE;
/** The name of the look and feel */
protected String lfname = "Metal";
/** Sequence edge enabled flag. */
protected boolean sequenceedges = true;
/** Data edge enabled flag. */
protected boolean dataedges = true;
/** Flag if simple name/type data edge auto-connect is enabled. */
protected boolean nametypedataautoconnect = true;
/** Flag if simple direct sequence edge auto-connect is enabled. */
protected boolean directsequenceautoconnect = true;
/** Flag if save settings on exit is enabled. */
protected boolean savesettingsonexit = true;
/** Flag if Jadex extensions are enabled. */
protected boolean jadexextensions = true;
/** Smooth zoom flag. */
protected boolean smoothzoom = true;
/** The selected style sheet */
protected String selectedsheet = BpmnEditor.STYLE_SHEETS.get(0).getFirstEntity();
/** The library home. */
//protected File libraryhome;
/** The library class loader entries. */
protected File[] libentries;
/** The library class loader. */
protected ClassLoader libclassloader;
/** Global task classes */
protected List globaltaskclasses = new ArrayList();
/** Global interfaces */
protected List globalinterfaces = new ArrayList();
/** Global exceptions. */
protected List globalexceptions = new ArrayList();
/** Global allclasses */
protected List globalallclasses = new ArrayList();
/** Flag if a scan is in progress */
protected boolean scanning;
/**
* Gets the progress bar.
*
* @return The progress bar.
*/
public BackgroundProgressBar getProgressBar()
{
return bgprogressbar;
}
/**
* Sets the progress bar.
*
* @param bgprogressbar The progress bar.
*/
public void setProgressBar(BackgroundProgressBar progressbar)
{
this.bgprogressbar = progressbar;
}
/**
* Returns the image provider.
*
* @return The image provider.
*/
public ImageProvider getImageProvider()
{
return imageprovider;
}
/**
* Gets the selected style sheet.
*
* @return The selected sheet.
*/
public String getSelectedSheet()
{
return selectedsheet;
}
/**
* Sets the selected style sheet.
*
* @param selectedsheet The selected sheet.
*/
public void setSelectedSheet(String selectedsheet)
{
this.selectedsheet = selectedsheet;
}
/**
* Gets the opened files.
*
* @return The opened files.
*/
public File[] getOpenedFiles()
{
return openedfiles;
}
/**
* Sets the opened files.
*
* @param openedfiles The opened files.
*/
public void setOpenedFiles(File[] openedfiles)
{
this.openedfiles = openedfiles;
}
/**
* Gets the look and feel name.
*
* @return The name.
*/
public String getLfName()
{
return lfname;
}
/**
* Sets the look and feel name.
*
* @param lfname The name.
*/
public void setLfName(String lfname)
{
this.lfname = lfname;
}
/**
*
* @return
*/
public int getToolbarIconSize()
{
return toolbariconsize;
}
/**
* @param toolbariconsize
*/
public void setToolbarIconSize(int toolbariconsize)
{
this.toolbariconsize = toolbariconsize;
}
/**
*
*/
public boolean isSmoothZoom()
{
return smoothzoom;
}
/**
*
*/
public void setSmoothZoom(boolean smoothzoom)
{
this.smoothzoom = smoothzoom;
}
/**
*
*/
public boolean isJadexExtensions()
{
return jadexextensions;
}
/**
*
*/
public void setJadexExtensions(boolean jadexextensions)
{
this.jadexextensions = jadexextensions;
}
/**
* Gets the sequenceedges.
*
* @return The sequenceedges.
*/
public boolean isSequenceEdges()
{
return sequenceedges;
}
/**
* Sets the sequenceedges.
*
* @param sequenceedges The sequenceedges.
*/
public void setSequenceEdges(boolean sequenceedges)
{
this.sequenceedges = sequenceedges;
}
/**
* Gets the dataedges.
*
* @return The dataedges.
*/
public boolean isDataEdges()
{
return dataedges;
}
/**
* Sets the dataedges.
*
* @param dataedges The dataedges.
*/
public void setDataEdges(boolean dataedges)
{
this.dataedges = dataedges;
}
/**
* Gets the nametypedataautoconnect.
*
* @return The nametypedataautoconnect.
*/
public boolean isNameTypeDataAutoConnect()
{
return nametypedataautoconnect;
}
/**
* Sets the nametypedataautoconnect.
*
* @param nametypedataautoconnect The nametypedataautoconnect.
*/
public void setNameTypeDataAutoConnect(boolean nametypedataautoconnect)
{
this.nametypedataautoconnect = nametypedataautoconnect;
}
/**
* Gets the directsequenceautoconnect.
*
* @return The directsequenceautoconnect.
*/
public boolean isDirectSequenceAutoConnect()
{
return directsequenceautoconnect;
}
/**
* Sets the directsequenceautoconnect.
*
* @param directsequenceautoconnect The directsequenceautoconnect.
*/
public void setDirectSequenceAutoConnect(boolean directsequenceautoconnect)
{
this.directsequenceautoconnect = directsequenceautoconnect;
}
/**
* Gets the last file.
*
* @return The last file.
*/
public File getLastFile()
{
return lastfile;
}
/**
* Sets the last file.
*
* @param lastfile The last file.
*/
public void setLastFile(File lastfile)
{
this.lastfile = lastfile;
}
/**
* Gets the library home.
*
* @return The library home.
*/
// public File getLibraryHome()
// {
// return libraryhome;
// }
/**
* Sets the library home.
*
* @param libraryhome The library home.
*/
// public void addLibraryHome(File libhome)
// {
// if (libhome != null && libhome.getPath().length() > 0)
// {
//// this.libraryhome = libraryhome;
//
// File libdir = new File(libhome.getAbsolutePath() + File.separator + "lib");
// if (!libdir.exists() || !libdir.isDirectory())
// {
// libdir = libhome;
// }
//
// Set entries = new HashSet();
// File[] files = libdir.listFiles();
//// List urls = new ArrayList();
// if (files != null)
// {
// for (File file : files)
// {
// if (file.getAbsolutePath().endsWith(".jar"))
// {
// entries.add(file);
// urls.add(file.toURI().toURL());
// }
// }
// }
//
// if (entries.isEmpty())
// {
// // Attempt developer-mode search.
// File[] dirs = libdir.listFiles();
// for (File dir : dirs)
// {
// if (dir.isDirectory())
// {
// File targetdir = new File(dir.getAbsolutePath() + File.separator + "target" + File.separator + "classes");
// if (targetdir.exists() && targetdir.isDirectory())
// {
// entries.add(targetdir);
// urls.add(targetdir.toURI().toURL());
// }
// }
// }
// }
//
// if (libentries != null)
// {
// entries.addAll(Arrays.asList(libentries));
// }
//
// setLibraryEntries(entries);
// }
// else
// {
// this.libraryhome = null;
// homeclassloader = Settings.class.getClassLoader();
// }
// }
/**
* Sets the library entries.
* @param entries The entries.
*/
public File[] getLibraryEntries()
{
return libentries;
}
/**
* Scans for the global classes.
*/
public IFuture scanForClasses()
{
// Set[] tmp = Settings.scanForClasses(this, getLibraryClassLoader(), true);
if (scanning)
{
return IFuture.DONE;
}
scanning = true;
final Set[] stmp = new Set[4];
for (int i = 0; i < 4; ++i)
{
stmp[i] = new HashSet();
}
IFuture ret = Settings.scanForClasses(this, getLibraryClassLoader(), new FileFilter("$", false), new BpmnClassFilter(stmp, true), true);
ret.addResultListener(new IResultListener()
{
public void resultAvailable(Void result)
{
Comparator comp = new Comparator()
{
public int compare(ClassInfo o1, ClassInfo o2)
{
String str1 = SReflect.getUnqualifiedTypeName(o1.toString());
String str2 = SReflect.getUnqualifiedTypeName(o2.toString());
return str1.compareTo(str2);
}
};
final List[] ltmp = new List[4];
for(int i = 0; i < 4; ++i)
{
ltmp[i] = new ArrayList(stmp[i]);
Collections.sort(ltmp[i], comp);
}
// System.out.println("found2: "+stmp[0]+" "+stmp[0].getClass());
setGlobalTaskClasses(ltmp[0]);
setGlobalInterfaces(ltmp[1]);
setGlobalExceptions(ltmp[2]);
setGlobalAllClasses(ltmp[3]);
try
{
save();
}
catch (IOException e)
{
}
scanning = false;
}
public void exceptionOccurred(Exception exception)
{
scanning = false;
}
});
return ret;
}
/**
* Sets the library entries.
* @param entries The entries.
*/
public void setLibraryEntries(Collection entries)
{
libentries = entries.toArray(new File[entries.size()]);
URL[] urls = new URL[libentries.length];
for (int i = 0; i < urls.length; ++i)
{
try
{
urls[i] = libentries[i].toURI().toURL();
}
catch (MalformedURLException e)
{
}
}
if (urls.length > 0)
{
libclassloader = new URLClassLoader(urls, Settings.class.getClassLoader());
}
else
{
libclassloader = Settings.class.getClassLoader();
}
}
/**
* Get the globaltaskclasses.
* @return The globaltaskclasses.
*/
public List getGlobalTaskClasses()
{
return globaltaskclasses;
}
/**
* Set the globaltaskclasses.
* @param globaltaskclasses The globaltaskclasses to set.
*/
public void setGlobalTaskClasses(List globaltaskclasses)
{
// System.out.println("task cls: "+globaltaskclasses);
this.globaltaskclasses = globaltaskclasses;
}
/**
* Get the globalinterfaces.
* @return The globalinterfaces.
*/
public List getGlobalInterfaces()
{
return globalinterfaces;
}
/**
* Set the globalinterfaces.
* @param globalinterfaces The globalinterfaces to set.
*/
public void setGlobalInterfaces(List globalinterfaces)
{
this.globalinterfaces = globalinterfaces;
}
/**
* Gets the globalexceptions.
*
* @return The globalexceptions.
*/
public List getGlobalExceptions()
{
return globalexceptions;
}
/**
* Sets the globalexceptions.
*
* @param globalexceptions The globalexceptions.
*/
public void setGlobalExceptions(List globalexceptions)
{
this.globalexceptions = globalexceptions;
}
/**
* Get the allclasses.
* @return The allclasses.
*/
public List getGlobalAllClasses()
{
return globalallclasses;
}
/**
* Set all classes.
* @param allclasses The classes to set.
*/
public void setGlobalAllClasses(List allclasses)
{
this.globalallclasses = allclasses;
}
/**
* Gets the save settings on exit setting.
*
* @return The save settings on exit setting.
*/
public boolean isSaveSettingsOnExit()
{
return savesettingsonexit;
}
/**
* Sets the save settings on exit setting.
*
* @param savesettingsonexit The save settings on exit setting.
*/
public void setSaveSettingsOnExit(boolean savesettingsonexit)
{
this.savesettingsonexit = savesettingsonexit;
}
/**
* Gets the library class loader.
*
* @return The library class loader.
*/
public ClassLoader getLibraryClassLoader()
{
return libclassloader;
}
/**
* Gets the property panel factory.
*
* @return The property panel factory.
*/
public PropertyPanelFactory getPropertyPanelFactory()
{
return propertypanelfactory;
}
/**
* Sets the property panel factory.
*
* @param propertypanelfactory The property panel factory.
*/
public void setPropertyPanelFactory(PropertyPanelFactory propertypanelfactory)
{
this.propertypanelfactory = propertypanelfactory;
}
/**
* Save the settings.
*/
public void save() throws IOException
{
File settingsdir = new File(BpmnEditor.HOME_DIR);
if (!settingsdir.exists())
{
if (!settingsdir.mkdir())
{
throw new IOException("Could not create settings directory: " + settingsdir.getAbsolutePath());
}
}
File settingsfile = new File(settingsdir.getAbsolutePath() + File.separator + SETTINGS_FILE_NAME);
File tmpfile = File.createTempFile(SETTINGS_FILE_NAME, ".cfg");
Properties props = new Properties();
if (lastfile != null)
{
props.put("lastfile", lastfile.getAbsolutePath());
}
if (selectedsheet != null)
{
props.put("stylesheet", selectedsheet);
}
// if (libraryhome != null)
// {
// props.put("homepath", libraryhome.getPath());
// }
props.put("lfname", lfname);
props.put("smoothzoom", String.valueOf(smoothzoom));
props.put("jadexextensions", String.valueOf(jadexextensions));
props.put("sequenceedges", String.valueOf(sequenceedges));
props.put("directsequenceautoconnect", String.valueOf(directsequenceautoconnect));
props.put("dataedges", String.valueOf(dataedges));
props.put("nametypedataautoconnect", String.valueOf(nametypedataautoconnect));
props.put("savesettingsonexit", String.valueOf(savesettingsonexit));
props.put("toolbariconsize", String.valueOf(toolbariconsize));
if (openedfiles != null)
{
int counter = 0;
for (File file : openedfiles)
{
props.put("openfile" + ++counter, file.getAbsolutePath());
}
}
if (libentries != null)
{
int counter = 0;
for (File file : libentries)
{
props.put("libentry" + ++counter, file.getAbsolutePath());
}
}
Properties ccprops = new Properties();
if(globalinterfaces!=null && globalinterfaces.size()>0)
{
for(int i=0; i0)
{
for(int i=0; i0)
{
for(int i=0; i0)
{
for(int i=0; i sheet : BpmnEditor.STYLE_SHEETS)
{
if (sheet.getFirstEntity().equals(prop))
{
ret.setSelectedSheet(prop);
break;
}
}
}
prop = props.getProperty("smoothzoom");
if (prop != null)
{
try
{
ret.setSmoothZoom(Boolean.parseBoolean(prop));
}
catch (Exception e)
{
}
}
prop = props.getProperty("jadexextensions");
if (prop != null)
{
try
{
ret.setJadexExtensions(Boolean.parseBoolean(prop));
}
catch (Exception e)
{
}
}
prop = props.getProperty("sequenceedges");
if (prop != null)
{
try
{
ret.setSequenceEdges(Boolean.parseBoolean(prop));
}
catch (Exception e)
{
}
}
prop = props.getProperty("directsequenceautoconnect");
if (prop != null)
{
try
{
ret.setDirectSequenceAutoConnect(Boolean.parseBoolean(prop));
}
catch (Exception e)
{
}
}
prop = props.getProperty("dataedges");
if (prop != null)
{
try
{
ret.setDataEdges(Boolean.parseBoolean(prop));
}
catch (Exception e)
{
}
}
prop = props.getProperty("nametypedataautoconnect");
if (prop != null)
{
try
{
ret.setNameTypeDataAutoConnect(Boolean.parseBoolean(prop));
}
catch (Exception e)
{
}
}
prop = props.getProperty("toolbariconsize");
if (prop != null)
{
try
{
int size = Integer.parseInt(prop);
for (int i = 0; i < GuiConstants.ICON_SIZES.length; ++i)
{
if (GuiConstants.ICON_SIZES[i] == size)
{
ret.setToolbarIconSize(size);
break;
}
}
}
catch (NumberFormatException e)
{
}
}
Map openfiles = new TreeMap();
for(Object okey: props.keySet())
{
if(okey instanceof String)
{
String key = (String) okey;
if (key.startsWith("openfile"))
{
int index = 0;
try
{
index = Integer.parseInt(key.substring(8));
}
catch (Exception e)
{
}
openfiles.put(index, new File(props.getProperty(key)));
}
}
}
ret.setOpenedFiles(openfiles.values().toArray(new File[openfiles.size()]));
List lentries = new ArrayList();
for(Object okey: props.keySet())
{
if(okey instanceof String)
{
String key = (String) okey;
if (key.startsWith("libentry"))
{
lentries.add(new File(props.getProperty(key)));
}
}
}
ret.setLibraryEntries(lentries);
File classcachefile = new File(BpmnEditor.HOME_DIR + File.separator + CLASS_CACHE_FILE_NAME);
props = new Properties();
is = new FileInputStream(classcachefile);
props.load(is);
is.close();
try
{
List gis = new ArrayList();
List gts = new ArrayList();
List ges = new ArrayList();
List ac = new ArrayList();
if (Integer.parseInt(props.getProperty("build")) == BpmnEditor.BUILD)
{
for(Object okey: props.keySet())
{
if(okey instanceof String)
{
String key = (String) okey;
if(key.startsWith("gi"))
{
gis.add(new ClassInfo(props.getProperty(key)));
}
else if(key.startsWith("gt"))
{
gts.add(new ClassInfo(props.getProperty(key)));
}
else if(key.startsWith("ge"))
{
ges.add(new ClassInfo(props.getProperty(key)));
}
else if(key.startsWith("ac"))
{
ac.add(new ClassInfo(props.getProperty(key)));
}
}
}
ret.setGlobalInterfaces(gis);
ret.setGlobalTaskClasses(gts);
ret.setGlobalExceptions(ges);
ret.setGlobalAllClasses(ac);
}
}
catch (Exception e)
{
}
}
catch (IOException e)
{
}
return ret;
}
/**
* Scan for task classes.
*/
// public static final Set[] scanForClasses(Settings settings, final ClassLoader cl, final boolean includeboot)
// {
// final Set res1 = new HashSet();
// final Set res2 = new HashSet();
// final Set res3 = new HashSet();
// final Set res4 = new HashSet();
//
// scanForClasses(settings, cl, new FileFilter("$", false), new BpmnClassFilter(res1, res2, res3, res4, includeboot), includeboot);
//
// return new Set[]{res1, res2, res3, res4};
// }
/**
* Scan for task classes.
*/
protected static final IFuture scanForClasses(Settings settings, ClassLoader cl, IFilter