4,14 → 4,16 |
* Coded by: Group 5, software practice summer 2003 |
* University of Bielefeld, Germany |
* |
* @version $Revision: 1.47 $ |
* @version $Revision: 1.48 $ |
* |
* Last modification: $Date: 2003/07/21 17:33:21 $ |
* $Id: PluginManager.java,v 1.47 2003/07/21 17:33:21 smcsporr Exp $ |
* Last modification: $Date: 2003/07/21 17:55:22 $ |
* $Id: PluginManager.java,v 1.48 2003/07/21 17:55:22 smcsporr Exp $ |
*/ |
|
package src.plugins; |
|
import java.awt.event.ActionEvent; |
import java.awt.event.ActionListener; |
import java.io.File; |
import java.io.IOException; |
import java.net.URL; |
54,10 → 56,16 |
* |
* @author Sascha Walkenhorst |
* |
* @version $Revision: 1.47 $ Last modification: $Date: 2003/07/21 17:33:21 $ |
* @version $Revision: 1.48 $ Last modification: $Date: 2003/07/21 17:55:22 $ |
*/ |
public class PluginManager implements TreeSelectionListener, PluginManagerInterface, OurEventListener { |
public class PluginManager implements TreeSelectionListener, |
PluginManagerInterface, |
OurEventListener, |
ActionListener { |
|
/** for the path of the configuration file */ |
private String configurationFilePath; |
|
/** for the parsed configuration file */ |
private Document configuration; |
|
74,7 → 82,7 |
private Hashtable associations; |
|
/** list for loaded documents as keys and as value all names of plugins which |
* have an instance for this document, the name of the active plugin first |
* have an instance for this document, the name of the active plugin first, |
* in a LinkedList */ |
private Hashtable documents; |
|
130,7 → 138,9 |
GuiInterface newGuiInterface, |
OurEventListener newOurEventListener, |
LogInterface newLogInterface) { |
/* set the internal variable for the GuiInterface, OurEventListener and LogInterface */ |
/* set the internal variable for the path of the configuration file, |
* GuiInterface, OurEventListener and LogInterface */ |
configurationFilePath = configFilePath; |
guiInterface = newGuiInterface; |
ownOurEventListener = newOurEventListener; |
logInterfaceReference = newLogInterface; |
668,7 → 678,7 |
* @return The name of the default plugin. <code>null</code> if wanted plugin |
* is not available. |
* |
* TODO improve dialog |
* TODO test selection |
* |
* author Sascha Walkenhorst |
* |
700,22 → 710,10 |
/* case: no plugin chosen as default plugin, or chosen plugin is not available |
* -> user should choose another plugin as default plugin */ |
if ( (candidate == null) |
|| (candidate.equals("")) |
|| (candidate == "") |
|| !plugins.containsKey(candidate) |
) { |
/* create the available plugins as options for dialog */ |
Object[] options = plugins.keySet().toArray(); |
|
int selected = JOptionPane.showOptionDialog(null, |
"default plugin selection", |
"which plugin should act as the default plugin", |
JOptionPane.CANCEL_OPTION, |
JOptionPane.QUESTION_MESSAGE, |
null, |
options, |
null); |
|
candidate = (String) options[selected]; |
candidate = chooseDefaultPluginName(); |
|
// ... |
|
728,6 → 726,39 |
|
|
/** |
* ... |
* |
* @return The chosen plugin. <code>null</code> if none is selected. |
* |
* TODO improve dialog, comment |
* |
* author Sascha Walkenhorst |
* |
* Last revision: 21-Jul-2003 by Sascha W. |
*/ |
private String chooseDefaultPluginName() { |
/* create the available plugins as options for dialog */ |
Object[] options = plugins.keySet().toArray(); |
|
int selected = JOptionPane.showOptionDialog(null, |
"default plugin selection", |
"which plugin should act as the default plugin", |
JOptionPane.CANCEL_OPTION, |
JOptionPane.QUESTION_MESSAGE, |
null, |
options, |
null); |
|
/* case: the selection was not aborted */ |
if (selected != JOptionPane.CANCEL_OPTION) { |
return (String) options[selected]; |
} |
|
return null; |
} |
|
|
/** |
* This method manages to stop the plugin of the old element and to start the |
* plugin which is associated with the element now selected. The name of the |
* selected element in a tree (especially in <code>PopUpJTree</code>) is |
1144,4 → 1175,88 |
// } |
} |
|
|
/** |
* ... |
* |
* TODO set up, comment |
* |
* author Sascha Walkenhorst |
* |
* Last revision: 21-Jul-2003 by Sascha W. |
*/ |
private void switchToAndFroDefaultPlugin() { |
//for testing only! |
System.out.println("PluginManager - method \"switchToAndFroDefaultPlugin()\" running..."); |
return; |
|
// /* get name of active plugin for actual document */ |
// String actualDocumentName = documentManagerInterface.getActualDocumentName(); |
// LinkedList lL = (LinkedList) documents.get(actualDocumentName); |
// String actualPlugin = (String) lL.getFirst(); |
// |
// /* case: actual plugin and default plugin are the same plugin |
// * -> no need to change */ |
// if (actualPlugin == defaultPluginName) { |
// |
// } |
// else { |
// /* stop the active plugin */ |
// PluginLoader pL = (PluginLoader) ((Hashtable) plugins.get(actualPlugin)).get("loader"); |
// pL.stopPlugin(actualDocumentName); |
// |
// //get node, transform it?, which TreePath? |
// |
// /* get environment for default plugin (the actual document) and make it 'final' */ |
// final Document environment = documentManagerInterface.getActualDocument(); |
// |
// /* get 'PluginLoader' of default plugin */ |
// PluginLoader defaultPL = (PluginLoader) ((Hashtable) plugins.get(defaultPluginName)).get("loader"); |
// |
// /* start the default plugin with transformed node and environment */ |
// //defaultPL.startPlugin(transformedNode, environment, tp, actualDocumentName); |
// |
// //... |
// } |
} |
|
|
/** |
* The <code>actionPerformed</code> method is needed by an <code>ActionListener</code>. |
* It takes <code>ActionEvent</code>s and starts the appropiate actions. |
* The current implementation handles events with the following <code>ActionCommand</code>s: |
* 'reset configuration', 'change default plugin', 'switch to and fro default plugin' |
* and 'show actual configuration'. |
* |
* @param event: The <code>ActionEvent</code> that occured. |
* |
* @see java.awt.event.ActionEvent |
* @see java.awt.event.ActionListener |
* |
* author Sascha Walkenhorst |
* |
* Last revision: 21-Jul-2003 by Sascha W. |
*/ |
public void actionPerformed(ActionEvent e) { |
/* case: user wants to reset plugin settings */ |
if (e.getActionCommand() == "reset configuration") { |
reset(configurationFilePath); |
} |
|
/* case: user wants to change default plugin */ |
if (e.getActionCommand() == "change default plugin") { |
defaultPluginName = chooseDefaultPluginName(); |
} |
|
/* case: user wants to switch between associated plugin and default plugin */ |
if (e.getActionCommand() == "switch to and fro default plugin") { |
switchToAndFroDefaultPlugin(); |
} |
|
/* case: show the actual configuration */ |
if (e.getActionCommand() == "show actual configuration") { |
listVariables(); |
} |
} |
|
} |