diff --git a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/CopyAction.java b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/CopyAction.java index a3570d33240529319f1539e9b8a66c8b6f5634b5..159598e7dc0ec8a81d954774990dc5ea46a51102 100644 --- a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/CopyAction.java +++ b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/CopyAction.java @@ -1,5 +1,7 @@ package lcsb.mapviewer.cdplugin.copypaste; +import org.apache.log4j.Logger; + import jp.sbi.celldesigner.MainWindow; import jp.sbi.celldesigner.plugin.PluginListOf; import jp.sbi.celldesigner.plugin.PluginReaction; @@ -9,8 +11,6 @@ import jp.sbi.celldesigner.plugin.PluginSpeciesAlias; import lcsb.mapviewer.common.SystemClipboard; import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; -import org.apache.log4j.Logger; - /** * CD Plugin action resposible for translating annotation stored in notes to xml * format stored in annotations. @@ -19,72 +19,72 @@ import org.apache.log4j.Logger; * */ public class CopyAction extends CopyPasteAbstractAction { - /** - * Default class logger. - */ - private final Logger logger = Logger.getLogger(CopyAction.class.getName()); + /** + * Default class logger. + */ + private final Logger logger = Logger.getLogger(CopyAction.class.getName()); - /** - * Method that perform annotation of a celldesigner species listed in - * speciesList. - * - * @param plug - * - a plugin object - * @param speciesList - * - list of species to annotate - * @param win - * - main window of cell designer - */ - public void performAnnotation(CopyPastePlugin plug, PluginListOf speciesList, MainWindow win) { + /** + * Method that perform annotation of a celldesigner species listed in + * speciesList. + * + * @param plug + * - a plugin object + * @param speciesList + * - list of species to annotate + * @param win + * - main window of cell designer + */ + public void performAnnotation(CopyPastePlugin plug, PluginListOf speciesList, MainWindow win) { - // if list is empty then just return from the method - if (speciesList.size() == 0) { - return; - } + // if list is empty then just return from the method + if (speciesList.size() == 0) { + return; + } - SystemClipboard sc = new SystemClipboard(); + SystemClipboard sc = new SystemClipboard(); - this.setWindow(win); - this.setPlug(plug); + this.setWindow(win); + this.setPlug(plug); - int size = speciesList.size(); + int size = speciesList.size(); - PluginSBase chosenElement = null; - String id = ""; - for (int i = 0; i < size; i++) { - PluginSBase element = speciesList.get(i); - if (element instanceof PluginSpeciesAlias) { - PluginSpeciesAlias alias = (PluginSpeciesAlias) element; - PluginSpecies species = alias.getSpecies(); + PluginSBase chosenElement = null; + String id = ""; + for (int i = 0; i < size; i++) { + PluginSBase element = speciesList.get(i); + if (element instanceof PluginSpeciesAlias) { + PluginSpeciesAlias alias = (PluginSpeciesAlias) element; + PluginSpecies species = alias.getSpecies(); - if (chosenElement == null) { - chosenElement = species; - id = species.getId(); - } else if (id.compareTo(species.getId()) < 0) { - chosenElement = species; - id = species.getId(); - } - } else if (element instanceof PluginReaction) { - PluginReaction reaction = (PluginReaction) element; - if (chosenElement == null) { - chosenElement = reaction; - id = reaction.getId(); - } else if (id.compareTo(reaction.getId()) < 0) { - chosenElement = reaction; - id = reaction.getId(); - } - } else { - logger.warn("Unknown class type :" + element.getClass()); - } - } + if (chosenElement == null) { + chosenElement = species; + id = species.getId(); + } else if (id.compareTo(species.getId()) < 0) { + chosenElement = species; + id = species.getId(); + } + } else if (element instanceof PluginReaction) { + PluginReaction reaction = (PluginReaction) element; + if (chosenElement == null) { + chosenElement = reaction; + id = reaction.getId(); + } else if (id.compareTo(reaction.getId()) < 0) { + chosenElement = reaction; + id = reaction.getId(); + } + } else { + logger.warn("Unknown class type :" + element.getClass()); + } + } - if (chosenElement != null) { - try { - sc.setClipboardContents(getCopyString(chosenElement.getAnnotationString(), chosenElement.getNotesString())); - } catch (InvalidXmlSchemaException e) { - logger.warn("Problem with creating copy-paste String", e); - } - } - } + if (chosenElement != null) { + try { + sc.setClipboardContents(getCopyString(chosenElement.getAnnotationString(), chosenElement.getNotesString())); + } catch (InvalidXmlSchemaException e) { + logger.warn("Problem with creating copy-paste String", e); + } + } + } } diff --git a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/CopyPasteAbstractAction.java b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/CopyPasteAbstractAction.java index 74f7b881175730d43942abdc186190e76d54790e..04180351ed7c37888c681aa912193a44c0fd4fac 100644 --- a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/CopyPasteAbstractAction.java +++ b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/CopyPasteAbstractAction.java @@ -7,7 +7,6 @@ import org.apache.log4j.Logger; import jp.sbi.celldesigner.MainWindow; import lcsb.mapviewer.common.Pair; -import lcsb.mapviewer.common.XmlParser; import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; import lcsb.mapviewer.converter.annotation.XmlAnnotationParser; import lcsb.mapviewer.model.map.MiriamData; @@ -22,165 +21,166 @@ import lcsb.mapviewer.model.map.MiriamType; * */ public class CopyPasteAbstractAction { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private final Logger logger = Logger.getLogger(CopyPasteAbstractAction.class); - - /** - * Prefix used for serialization/deserialization of {@link MiriamData} to - * string stored in system clipboard. - */ - private static final String PREFIX = "[MIRIAM]"; - /** - * Plugin object which ran this action. This object is used to update - * information about species - */ - private CopyPastePlugin plug; - /** - * Object of CellDesigner main form. - */ - private MainWindow window; - - /** - * Serializes {@link MiriamData} into string that will be stored into system - * clipboard. - * - * @param md - * object to serialize - * @return string representation of {@link MiriamData} - */ - protected String serialize(MiriamData md) { - return PREFIX + "\t" + md.getRelationType().getStringRepresentation() + "\t" + md.getDataType().getUris().get(0) + "\t" + md.getResource(); - } - - /** - * Deserialize {@link MiriamData} from string creted by - * {@link #serialize(MiriamData)} method. - * - * @param string - * string representation of {@link MiriamData} - * @return {@link MiriamData} obtained from input string - */ - protected MiriamData deserialize(String string) { - if (string == null) { - return null; - } - String[] tmp = string.split("\t"); - - // CHECKSTYLE:OFF - if (tmp.length == 4) { - if (PREFIX.equals(tmp[0])) { - String relation = tmp[1]; - String uri = tmp[2]; - String resource = tmp[3]; - MiriamType mt = MiriamType.getTypeByUri(uri); - MiriamRelationType mrt = MiriamRelationType.getTypeByStringRepresentation(relation); - if (mt == null || mrt == null) { - return null; - } - return new MiriamData(mrt, mt, resource); - } - } - // CHECKSTYLE:ON - return null; - } - - /** - * Returns serialized string of annotations and notes. - * - * @param annotationString - * xml string representing annotations in CellDesigner - * @param notesString - * flat notes String - * @return serialized string - * @throws InvalidXmlSchemaException - * thrown when xmlString is invalid - */ - protected String getCopyString(String annotationString, String notesString) throws InvalidXmlSchemaException { - XmlAnnotationParser xap = new XmlAnnotationParser(); - Set<MiriamData> set = xap.parse(annotationString); - StringBuilder result = new StringBuilder(); - for (MiriamData md : set) { - result.append(serialize(md) + "\n"); - } - result.append(notesString); - return result.toString(); - } - - /** - * Deserialize string created by {@link #getCopyString(String, String)} - * method. Used to create {@link MiriamData} set and notes from clipboard. - * - * @param value - * string for deserialization - * - * @return {@link Pair} of {@link MiriamData} set and notes string - */ - protected Pair<Set<MiriamData>, String> getAnnotationDataFromClipboardString(String value) { - if (value == null) { - return new Pair<Set<MiriamData>, String>(null, null); - } - String[] rows = value.split("\n"); - - StringBuilder sb = new StringBuilder(""); - - boolean miriam = true; - - Set<MiriamData> set = new HashSet<MiriamData>(); - for (int i = 0; i < rows.length; i++) { - String row = rows[i]; - if (miriam) { - MiriamData md = deserialize(row); - if (md != null) { - set.add(md); - } else { - miriam = false; - } - } - if (!miriam) { - sb.append(row); - sb.append("\n"); - } - } - String notes = sb.toString().trim(); - - return new Pair<Set<MiriamData>, String>(set, notes); - } - - /** - * @return the plug - * @see #plug - */ - protected CopyPastePlugin getPlug() { - return plug; - } - - /** - * @param plug - * the plug to set - * @see #plug - */ - protected void setPlug(CopyPastePlugin plug) { - this.plug = plug; - } - - /** - * @return the window - * @see #window - */ - protected MainWindow getWindow() { - return window; - } - - /** - * @param window - * the window to set - * @see #window - */ - protected void setWindow(MainWindow window) { - this.window = window; - } + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private final Logger logger = Logger.getLogger(CopyPasteAbstractAction.class); + + /** + * Prefix used for serialization/deserialization of {@link MiriamData} to string + * stored in system clipboard. + */ + private static final String PREFIX = "[MIRIAM]"; + /** + * Plugin object which ran this action. This object is used to update + * information about species + */ + private CopyPastePlugin plug; + /** + * Object of CellDesigner main form. + */ + private MainWindow window; + + /** + * Serializes {@link MiriamData} into string that will be stored into system + * clipboard. + * + * @param md + * object to serialize + * @return string representation of {@link MiriamData} + */ + protected String serialize(MiriamData md) { + return PREFIX + "\t" + md.getRelationType().getStringRepresentation() + "\t" + md.getDataType().getUris().get(0) + + "\t" + md.getResource(); + } + + /** + * Deserialize {@link MiriamData} from string creted by + * {@link #serialize(MiriamData)} method. + * + * @param string + * string representation of {@link MiriamData} + * @return {@link MiriamData} obtained from input string + */ + protected MiriamData deserialize(String string) { + if (string == null) { + return null; + } + String[] tmp = string.split("\t"); + + // CHECKSTYLE:OFF + if (tmp.length == 4) { + if (PREFIX.equals(tmp[0])) { + String relation = tmp[1]; + String uri = tmp[2]; + String resource = tmp[3]; + MiriamType mt = MiriamType.getTypeByUri(uri); + MiriamRelationType mrt = MiriamRelationType.getTypeByStringRepresentation(relation); + if (mt == null || mrt == null) { + return null; + } + return new MiriamData(mrt, mt, resource); + } + } + // CHECKSTYLE:ON + return null; + } + + /** + * Returns serialized string of annotations and notes. + * + * @param annotationString + * xml string representing annotations in CellDesigner + * @param notesString + * flat notes String + * @return serialized string + * @throws InvalidXmlSchemaException + * thrown when xmlString is invalid + */ + protected String getCopyString(String annotationString, String notesString) throws InvalidXmlSchemaException { + XmlAnnotationParser xap = new XmlAnnotationParser(); + Set<MiriamData> set = xap.parse(annotationString); + StringBuilder result = new StringBuilder(); + for (MiriamData md : set) { + result.append(serialize(md) + "\n"); + } + result.append(notesString); + return result.toString(); + } + + /** + * Deserialize string created by {@link #getCopyString(String, String)} method. + * Used to create {@link MiriamData} set and notes from clipboard. + * + * @param value + * string for deserialization + * + * @return {@link Pair} of {@link MiriamData} set and notes string + */ + protected Pair<Set<MiriamData>, String> getAnnotationDataFromClipboardString(String value) { + if (value == null) { + return new Pair<Set<MiriamData>, String>(null, null); + } + String[] rows = value.split("\n"); + + StringBuilder sb = new StringBuilder(""); + + boolean miriam = true; + + Set<MiriamData> set = new HashSet<MiriamData>(); + for (int i = 0; i < rows.length; i++) { + String row = rows[i]; + if (miriam) { + MiriamData md = deserialize(row); + if (md != null) { + set.add(md); + } else { + miriam = false; + } + } + if (!miriam) { + sb.append(row); + sb.append("\n"); + } + } + String notes = sb.toString().trim(); + + return new Pair<Set<MiriamData>, String>(set, notes); + } + + /** + * @return the plug + * @see #plug + */ + protected CopyPastePlugin getPlug() { + return plug; + } + + /** + * @param plug + * the plug to set + * @see #plug + */ + protected void setPlug(CopyPastePlugin plug) { + this.plug = plug; + } + + /** + * @return the window + * @see #window + */ + protected MainWindow getWindow() { + return window; + } + + /** + * @param window + * the window to set + * @see #window + */ + protected void setWindow(MainWindow window) { + this.window = window; + } } \ No newline at end of file diff --git a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/CopyPastePlugin.java b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/CopyPastePlugin.java index 17bdd87eeb291787f641d2036540c93a50130881..c9a139cf0dcf04f5b108477a56569103268e7415 100644 --- a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/CopyPastePlugin.java +++ b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/CopyPastePlugin.java @@ -4,12 +4,12 @@ import java.awt.KeyEventDispatcher; import java.awt.KeyboardFocusManager; import java.awt.event.KeyEvent; +import org.apache.log4j.Logger; + import jp.sbi.celldesigner.MainWindow; import jp.sbi.celldesigner.plugin.CellDesignerPlugin; import jp.sbi.celldesigner.plugin.PluginSBase; -import org.apache.log4j.Logger; - /** * This class represent a plugin to cell designer with copy past functionality * that allows to copy and paste notes and annotations of species. @@ -29,103 +29,101 @@ import org.apache.log4j.Logger; */ public class CopyPastePlugin extends CellDesignerPlugin { - /** - * Default class logger. - */ - private Logger logger = Logger.getLogger(CopyPastePlugin.class.getName()); - /** - * Main window of cell designer. - */ - private MainWindow win; - - /** - * Paste action. - */ - private PastePluginAction ppa; - - /** - * Paste action. - */ - private CopyPluginAction cpa; - - /** - * Default constructor. Creates menu and InfoFrame. - */ - public CopyPastePlugin() { - try { - // PropertyConfigurator.configure("D:/log4j.properties"); - logger.debug("Loading copy-paste plugin..."); - - win = MainWindow.getLastInstance(); - - ppa = new PastePluginAction(this, win); - cpa = new CopyPluginAction(this, win); - - // create keyboard listener for shortcuts - KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() { - public boolean dispatchKeyEvent(KeyEvent e) { - switch (e.getID()) { - case KeyEvent.KEY_PRESSED: - if (e.getKeyCode() == java.awt.event.KeyEvent.VK_V - && e.isControlDown() - && e.isAltDown() - ) { - ppa.myActionPerformed(null); - return true; - } else if (e.getKeyCode() == java.awt.event.KeyEvent.VK_C - && e.isControlDown() - && e.isAltDown() - ) { - cpa.myActionPerformed(null); - return true; - } else { - return false; - } - default: - return false; - } - } - }); - - } catch (Exception exception) { - logger.error(exception, exception); - } - } - - // CHECKSTYLE:OFF - @Override - public void SBaseAdded(PluginSBase arg0) { - - } - - @Override - public void SBaseChanged(PluginSBase arg0) { - - } - - @Override - public void SBaseDeleted(PluginSBase arg0) { - } - - // CHECKSTYLE:ON - - @Override - public void addPluginMenu() { - } - - @Override - public void modelClosed(PluginSBase arg0) { - - } - - @Override - public void modelOpened(PluginSBase arg0) { - - } - - @Override - public void modelSelectChanged(PluginSBase arg0) { - - } + /** + * Default class logger. + */ + private Logger logger = Logger.getLogger(CopyPastePlugin.class.getName()); + /** + * Main window of cell designer. + */ + private MainWindow win; + + /** + * Paste action. + */ + private PastePluginAction ppa; + + /** + * Paste action. + */ + private CopyPluginAction cpa; + + /** + * Default constructor. Creates menu and InfoFrame. + */ + public CopyPastePlugin() { + try { + // PropertyConfigurator.configure("D:/log4j.properties"); + logger.debug("Loading copy-paste plugin..."); + + win = MainWindow.getLastInstance(); + + ppa = new PastePluginAction(this, win); + cpa = new CopyPluginAction(this, win); + + // create keyboard listener for shortcuts + KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() { + public boolean dispatchKeyEvent(KeyEvent e) { + switch (e.getID()) { + case KeyEvent.KEY_PRESSED: + if (e.getKeyCode() == java.awt.event.KeyEvent.VK_V + && e.isControlDown() + && e.isAltDown()) { + ppa.myActionPerformed(null); + return true; + } else if (e.getKeyCode() == java.awt.event.KeyEvent.VK_C + && e.isControlDown() + && e.isAltDown()) { + cpa.myActionPerformed(null); + return true; + } else { + return false; + } + default: + return false; + } + } + }); + + } catch (Exception exception) { + logger.error(exception, exception); + } + } + + // CHECKSTYLE:OFF + @Override + public void SBaseAdded(PluginSBase arg0) { + + } + + @Override + public void SBaseChanged(PluginSBase arg0) { + + } + + @Override + public void SBaseDeleted(PluginSBase arg0) { + } + + // CHECKSTYLE:ON + + @Override + public void addPluginMenu() { + } + + @Override + public void modelClosed(PluginSBase arg0) { + + } + + @Override + public void modelOpened(PluginSBase arg0) { + + } + + @Override + public void modelSelectChanged(PluginSBase arg0) { + + } } \ No newline at end of file diff --git a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/CopyPluginAction.java b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/CopyPluginAction.java index 8fee9aee00c6487125e41c34eefc37552445603a..e38720c08d9be2b9e30496d37822be6173c23e80 100644 --- a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/CopyPluginAction.java +++ b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/CopyPluginAction.java @@ -2,12 +2,12 @@ package lcsb.mapviewer.cdplugin.copypaste; import java.awt.event.ActionEvent; +import org.apache.log4j.Logger; + import jp.sbi.celldesigner.MainWindow; import jp.sbi.celldesigner.plugin.PluginAction; import jp.sbi.celldesigner.plugin.PluginListOf; -import org.apache.log4j.Logger; - /** * This class represent action that copy species/reaction annotations and notes * into clipboard. @@ -17,46 +17,46 @@ import org.apache.log4j.Logger; */ public class CopyPluginAction extends PluginAction { - /** - * Default class logger. - */ - private Logger logger = Logger.getLogger(PasteAction.class.getName()); - /** - * - */ - private static final long serialVersionUID = 1L; - - /** - * Plugin that access this action. - */ - private CopyPastePlugin plug = null; - /** - * Main window of CellDesigner. - */ - private MainWindow window; - - /** - * Default constructor. - * - * @param plugin - * {@link #plug} - * @param win - * {@link #window} - */ - public CopyPluginAction(CopyPastePlugin plugin, MainWindow win) { - this.plug = plugin; - this.window = win; - } - - @Override - public void myActionPerformed(ActionEvent e) { - try { - CopyAction annotateAction = new CopyAction(); - PluginListOf list = plug.getSelectedAllNode(); - annotateAction.performAnnotation(plug, list, window); - } catch (Exception ex) { - logger.error(ex, ex); - } - } + /** + * Default class logger. + */ + private Logger logger = Logger.getLogger(PasteAction.class.getName()); + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Plugin that access this action. + */ + private CopyPastePlugin plug = null; + /** + * Main window of CellDesigner. + */ + private MainWindow window; + + /** + * Default constructor. + * + * @param plugin + * {@link #plug} + * @param win + * {@link #window} + */ + public CopyPluginAction(CopyPastePlugin plugin, MainWindow win) { + this.plug = plugin; + this.window = win; + } + + @Override + public void myActionPerformed(ActionEvent e) { + try { + CopyAction annotateAction = new CopyAction(); + PluginListOf list = plug.getSelectedAllNode(); + annotateAction.performAnnotation(plug, list, window); + } catch (Exception ex) { + logger.error(ex, ex); + } + } } \ No newline at end of file diff --git a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/PasteAction.java b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/PasteAction.java index d554598646d7e42956bdd3a68bbd393366a55b9a..4715616172b73217587bd43e2b633560383c7072 100644 --- a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/PasteAction.java +++ b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/PasteAction.java @@ -23,60 +23,60 @@ import lcsb.mapviewer.model.map.MiriamData; * */ public class PasteAction extends CopyPasteAbstractAction { - /** - * Default class logger. - */ - private final Logger logger = Logger.getLogger(PasteAction.class.getName()); + /** + * Default class logger. + */ + private final Logger logger = Logger.getLogger(PasteAction.class.getName()); - /** - * Method that perform annotation of a celldesigner species listed in - * speciesList. - * - * @param plug - * - a plugin object - * @param speciesList - * - list of species to annotate - * @param win - * - main window of cell designer - */ - public void performAnnotation(CopyPastePlugin plug, PluginListOf speciesList, MainWindow win) { + /** + * Method that perform annotation of a celldesigner species listed in + * speciesList. + * + * @param plug + * - a plugin object + * @param speciesList + * - list of species to annotate + * @param win + * - main window of cell designer + */ + public void performAnnotation(CopyPastePlugin plug, PluginListOf speciesList, MainWindow win) { - XmlAnnotationParser xap = new XmlAnnotationParser(); + XmlAnnotationParser xap = new XmlAnnotationParser(); - // if list is empty then just return from the method - if (speciesList.size() == 0) { - return; - } + // if list is empty then just return from the method + if (speciesList.size() == 0) { + return; + } - SystemClipboard sc = new SystemClipboard(); - String value = sc.getClipboardContents(); + SystemClipboard sc = new SystemClipboard(); + String value = sc.getClipboardContents(); - Pair<Set<MiriamData>, String> data = getAnnotationDataFromClipboardString(value); - String notes = data.getRight(); - Set<MiriamData> set = data.getLeft(); + Pair<Set<MiriamData>, String> data = getAnnotationDataFromClipboardString(value); + String notes = data.getRight(); + Set<MiriamData> set = data.getLeft(); - this.setWindow(win); - this.setPlug(plug); + this.setWindow(win); + this.setPlug(plug); - int size = speciesList.size(); - for (int i = 0; i < size; i++) { - PluginSBase element = speciesList.get(i); - if (element instanceof PluginSpeciesAlias) { - PluginSpeciesAlias alias = (PluginSpeciesAlias) element; - PluginSpecies species = alias.getSpecies(); - species.setNotes(notes); - species.setAnnotationString(xap.dataSetToXmlString(set)); - plug.notifySBaseChanged(element); - plug.notifySBaseChanged(species); - } else if (element instanceof PluginReaction) { - PluginReaction reaction = (PluginReaction) element; - reaction.setNotes(notes); - reaction.setAnnotationString(xap.dataSetToXmlString(set)); - plug.notifySBaseChanged(element); - } else { - logger.warn("Unknown class type :" + element.getClass()); - } - } - } + int size = speciesList.size(); + for (int i = 0; i < size; i++) { + PluginSBase element = speciesList.get(i); + if (element instanceof PluginSpeciesAlias) { + PluginSpeciesAlias alias = (PluginSpeciesAlias) element; + PluginSpecies species = alias.getSpecies(); + species.setNotes(notes); + species.setAnnotationString(xap.dataSetToXmlString(set)); + plug.notifySBaseChanged(element); + plug.notifySBaseChanged(species); + } else if (element instanceof PluginReaction) { + PluginReaction reaction = (PluginReaction) element; + reaction.setNotes(notes); + reaction.setAnnotationString(xap.dataSetToXmlString(set)); + plug.notifySBaseChanged(element); + } else { + logger.warn("Unknown class type :" + element.getClass()); + } + } + } } diff --git a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/PastePluginAction.java b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/PastePluginAction.java index 16e44f3ff2d12c1418ff47481cda6a49543fa8bd..0cf65ce58cdaca0a7d5baf548718cf774640533a 100644 --- a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/PastePluginAction.java +++ b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/PastePluginAction.java @@ -2,12 +2,12 @@ package lcsb.mapviewer.cdplugin.copypaste; import java.awt.event.ActionEvent; +import org.apache.log4j.Logger; + import jp.sbi.celldesigner.MainWindow; import jp.sbi.celldesigner.plugin.PluginAction; import jp.sbi.celldesigner.plugin.PluginListOf; -import org.apache.log4j.Logger; - /** * This class represent action that paste annotations and notes from clipboard * into selected species/reactions. @@ -17,45 +17,45 @@ import org.apache.log4j.Logger; */ public class PastePluginAction extends PluginAction { - /** - * Default class logger. - */ - private Logger logger = Logger.getLogger(PasteAction.class.getName()); - /** - * - */ - private static final long serialVersionUID = 1L; - /** - * Plugin that access this action. - */ - private CopyPastePlugin plug = null; - /** - * Main window of CellDesigner. - */ - private MainWindow window; - - /** - * Default constructor. - * - * @param plugin - * {@link #plug} - * @param win - * {@link #window} - */ - public PastePluginAction(CopyPastePlugin plugin, MainWindow win) { - this.plug = plugin; - this.window = win; - } - - @Override - public void myActionPerformed(ActionEvent e) { - try { - PasteAction annotateAction = new PasteAction(); - PluginListOf list = plug.getSelectedAllNode(); - annotateAction.performAnnotation(plug, list, window); - } catch (Exception ex) { - logger.error(ex, ex); - } - } + /** + * Default class logger. + */ + private Logger logger = Logger.getLogger(PasteAction.class.getName()); + /** + * + */ + private static final long serialVersionUID = 1L; + /** + * Plugin that access this action. + */ + private CopyPastePlugin plug = null; + /** + * Main window of CellDesigner. + */ + private MainWindow window; + + /** + * Default constructor. + * + * @param plugin + * {@link #plug} + * @param win + * {@link #window} + */ + public PastePluginAction(CopyPastePlugin plugin, MainWindow win) { + this.plug = plugin; + this.window = win; + } + + @Override + public void myActionPerformed(ActionEvent e) { + try { + PasteAction annotateAction = new PasteAction(); + PluginListOf list = plug.getSelectedAllNode(); + annotateAction.performAnnotation(plug, list, window); + } catch (Exception ex) { + logger.error(ex, ex); + } + } } \ No newline at end of file diff --git a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/package-info.java b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/package-info.java index aea1cfceeaacf72e56d8d0870b5122860cee1247..00a7777f53c9f3757dc730c3edbeb5e4609e3d1f 100644 --- a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/package-info.java +++ b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/copypaste/package-info.java @@ -6,4 +6,3 @@ * {@link lcsb.mapviewer.cdplugin.copypaste.CopyPastePlugin}. */ package lcsb.mapviewer.cdplugin.copypaste; - diff --git a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/info/InfoFrame.java b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/info/InfoFrame.java index f480bc4101a454d9682b6ba439588b98942e5cd1..161cc2f346ae22eea57b323f0671f4255ea49d96 100644 --- a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/info/InfoFrame.java +++ b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/info/InfoFrame.java @@ -17,10 +17,10 @@ import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; -import jp.sbi.celldesigner.plugin.PluginSpeciesAlias; - import org.apache.log4j.Logger; +import jp.sbi.celldesigner.plugin.PluginSpeciesAlias; + /** * This class represent a frame that visualise MIRIAM data and notes for a * species. Only one instance of JFrame is stored in the class (only one window @@ -31,242 +31,243 @@ import org.apache.log4j.Logger; */ public final class InfoFrame { - /** - * What should be the distance between description of different aliases. - */ - private static final int DISTANCE_BETWEEN_PANELS = 5; - - /** - * How many columns should be in the info panel grid. - */ - private static final int GRID_INFO_COL_NUMBER = 2; - - /** - * How many rows should be in the info panel grid. - */ - private static final int GRID_INFO_ROW_NUMBER = 3; - - /** - * Frame height. - */ - private static final int FRAME_HEIGHT = 200; - - /** - * Frame width. - */ - private static final int FRAME_WIDTH = 200; - - /** - * Font size of the caption label. - */ - private static final int CAPTION_FONT_SIZE = 18; - - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private final Logger logger = Logger.getLogger(InfoFrame.class.getName()); - - /** - * Instance of the JFrame representation of windows. - */ - private JFrame frame = null; - - /** - * Singleton instance of this class (there can be only one instance of the - * frame). - */ - private static InfoFrame instance = null; - - /** - * Font used for captions. - */ - private Font captionFont = new Font("Default", Font.PLAIN, CAPTION_FONT_SIZE); - - /** - * List of selected aliases. - */ - private ArrayList<PluginSpeciesAlias> species = new ArrayList<PluginSpeciesAlias>(); - - /** - * Default constructor. - */ - private InfoFrame() { - int width = FRAME_WIDTH; - int height = FRAME_HEIGHT; - - // check the resolution of the screen - Toolkit tk = Toolkit.getDefaultToolkit(); - Dimension screenSize = tk.getScreenSize(); - int screenHeight = screenSize.height; - int screenWidth = screenSize.width; - - // if the resultion of the screen changed in a meantime adjust position to - // be - // visible on the screen - width = Math.min(width, screenWidth); - height = Math.min(height, screenHeight); - - int posX = (screenWidth - width) / 2; - int posY = (screenHeight - height) / 2; - - frame = new JFrame("Element information"); - frame.setSize(width, height); - frame.setLocation(posX, posY); - frame.setAlwaysOnTop(true); - frame.setVisible(false); - } - - /** - * Returns singleton instance of the class. - * - * @return singleton instance of this class - */ - public static InfoFrame getInstance() { - if (InfoFrame.instance == null) { - instance = new InfoFrame(); - } - return instance; - } - - /** - * Set visible flag for {@link #frame}. - * - * @param visible - * should the frame be visible or not - */ - public void setVisible(boolean visible) { - frame.setVisible(visible); - } - - /** - * This method assign a set of species to this form. - * - * @param species - * - species to be shown in the form - */ - public void setSpecies(ArrayList<PluginSpeciesAlias> species) { - this.species = species; - updateSpecies(); - } - - /** - * Updates information about species in the form. - */ - protected void updateSpecies() { - int panels = species.size() + 1; - - JPanel controlArea = new JPanel(new GridLayout(panels, 1)); - controlArea.setLayout(new BoxLayout(controlArea, BoxLayout.Y_AXIS)); - // for every species create a panel and add it to general form - for (PluginSpeciesAlias sp : this.species) { - JPanel panel = getPanelViewForSpecies(sp); - controlArea.add(panel); - } - // after adding all species add a text area which is "invisible", the main - // purpose of it is to fill the empty space in the form - JTextArea text = new JTextArea(); - text.setEditable(false); - text.setBackground(frame.getBackground()); - controlArea.add(text); - - Container content = frame.getContentPane(); - content.removeAll(); - - // the whole panel should be scrollable - JScrollPane scrollBar = new JScrollPane(controlArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); - scrollBar.setPreferredSize(new Dimension(0, 0)); - content.add(scrollBar); - - frame.validate(); - } - - /** - * This method create a panel for a species with all information to be - * presented. - * - * @param species - * CellDesigner species alias - * @return {@link JPanel} object with information about species - */ - private JPanel getPanelViewForSpecies(PluginSpeciesAlias species) { - JPanel result = new JPanel(); - result.setLayout(new BoxLayout(result, BoxLayout.Y_AXIS)); - - // create a caption - JPanel tmpPanel = new JPanel(new GridLayout(GRID_INFO_ROW_NUMBER, GRID_INFO_COL_NUMBER)); - JLabel label = new JLabel("Element: ", JLabel.RIGHT); - label.setFont(captionFont); - tmpPanel.add(label, Component.RIGHT_ALIGNMENT); - JTextField textField = new JTextField(species.getSpecies().getName(), JLabel.LEFT); - textField.setFont(captionFont); - textField.setEditable(false); - tmpPanel.add(textField, Component.LEFT_ALIGNMENT); - - tmpPanel.add(new JLabel("Alias id: ", JLabel.RIGHT), Component.RIGHT_ALIGNMENT); - textField = new JTextField(species.getAliasID(), JLabel.LEFT); - textField.setEditable(false); - tmpPanel.add(textField, Component.LEFT_ALIGNMENT); - - tmpPanel.add(new JLabel("Species id: ", JLabel.RIGHT), Component.RIGHT_ALIGNMENT); - textField = new JTextField(species.getSpecies().getId(), JLabel.LEFT); - textField.setEditable(false); - tmpPanel.add(textField, Component.LEFT_ALIGNMENT); - - result.add(tmpPanel); - - // add empty space between labels - result.add(Box.createRigidArea(new Dimension(DISTANCE_BETWEEN_PANELS, DISTANCE_BETWEEN_PANELS))); - - return result; - } - - /** - * Returns info if the frame is visible. - * - * @return info if the frame is visible - */ - public boolean isVisible() { - return frame.isVisible(); - } - - /** - * Sets frame title. - * - * @param title - * title of the frame - */ - public void setTitle(String title) { - frame.setTitle(title); - } - - /** - * Returns frame title. - * - * @return frame title - */ - public JFrame getFrame() { - return frame; - } - - /** - * Set {@link JFrame#defaultCloseOperation}. - * - * @param type - * new {@link JFrame#defaultCloseOperation} value - */ - public void setDefaultCloseOperation(int type) { - frame.setDefaultCloseOperation(type); - } - - /** - * Set {@link JFrame#setAlwaysOnTop(boolean)}. - * - * @param always - * new {@link JFrame#isAlwaysOnTop()} value - */ - public void setAlwaysOnTop(boolean always) { - frame.setAlwaysOnTop(always); - } + /** + * What should be the distance between description of different aliases. + */ + private static final int DISTANCE_BETWEEN_PANELS = 5; + + /** + * How many columns should be in the info panel grid. + */ + private static final int GRID_INFO_COL_NUMBER = 2; + + /** + * How many rows should be in the info panel grid. + */ + private static final int GRID_INFO_ROW_NUMBER = 3; + + /** + * Frame height. + */ + private static final int FRAME_HEIGHT = 200; + + /** + * Frame width. + */ + private static final int FRAME_WIDTH = 200; + + /** + * Font size of the caption label. + */ + private static final int CAPTION_FONT_SIZE = 18; + + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private final Logger logger = Logger.getLogger(InfoFrame.class.getName()); + + /** + * Instance of the JFrame representation of windows. + */ + private JFrame frame = null; + + /** + * Singleton instance of this class (there can be only one instance of the + * frame). + */ + private static InfoFrame instance = null; + + /** + * Font used for captions. + */ + private Font captionFont = new Font("Default", Font.PLAIN, CAPTION_FONT_SIZE); + + /** + * List of selected aliases. + */ + private ArrayList<PluginSpeciesAlias> species = new ArrayList<PluginSpeciesAlias>(); + + /** + * Default constructor. + */ + private InfoFrame() { + int width = FRAME_WIDTH; + int height = FRAME_HEIGHT; + + // check the resolution of the screen + Toolkit tk = Toolkit.getDefaultToolkit(); + Dimension screenSize = tk.getScreenSize(); + int screenHeight = screenSize.height; + int screenWidth = screenSize.width; + + // if the resultion of the screen changed in a meantime adjust position to + // be + // visible on the screen + width = Math.min(width, screenWidth); + height = Math.min(height, screenHeight); + + int posX = (screenWidth - width) / 2; + int posY = (screenHeight - height) / 2; + + frame = new JFrame("Element information"); + frame.setSize(width, height); + frame.setLocation(posX, posY); + frame.setAlwaysOnTop(true); + frame.setVisible(false); + } + + /** + * Returns singleton instance of the class. + * + * @return singleton instance of this class + */ + public static InfoFrame getInstance() { + if (InfoFrame.instance == null) { + instance = new InfoFrame(); + } + return instance; + } + + /** + * Set visible flag for {@link #frame}. + * + * @param visible + * should the frame be visible or not + */ + public void setVisible(boolean visible) { + frame.setVisible(visible); + } + + /** + * This method assign a set of species to this form. + * + * @param species + * - species to be shown in the form + */ + public void setSpecies(ArrayList<PluginSpeciesAlias> species) { + this.species = species; + updateSpecies(); + } + + /** + * Updates information about species in the form. + */ + protected void updateSpecies() { + int panels = species.size() + 1; + + JPanel controlArea = new JPanel(new GridLayout(panels, 1)); + controlArea.setLayout(new BoxLayout(controlArea, BoxLayout.Y_AXIS)); + // for every species create a panel and add it to general form + for (PluginSpeciesAlias sp : this.species) { + JPanel panel = getPanelViewForSpecies(sp); + controlArea.add(panel); + } + // after adding all species add a text area which is "invisible", the main + // purpose of it is to fill the empty space in the form + JTextArea text = new JTextArea(); + text.setEditable(false); + text.setBackground(frame.getBackground()); + controlArea.add(text); + + Container content = frame.getContentPane(); + content.removeAll(); + + // the whole panel should be scrollable + JScrollPane scrollBar = new JScrollPane(controlArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); + scrollBar.setPreferredSize(new Dimension(0, 0)); + content.add(scrollBar); + + frame.validate(); + } + + /** + * This method create a panel for a species with all information to be + * presented. + * + * @param species + * CellDesigner species alias + * @return {@link JPanel} object with information about species + */ + private JPanel getPanelViewForSpecies(PluginSpeciesAlias species) { + JPanel result = new JPanel(); + result.setLayout(new BoxLayout(result, BoxLayout.Y_AXIS)); + + // create a caption + JPanel tmpPanel = new JPanel(new GridLayout(GRID_INFO_ROW_NUMBER, GRID_INFO_COL_NUMBER)); + JLabel label = new JLabel("Element: ", JLabel.RIGHT); + label.setFont(captionFont); + tmpPanel.add(label, Component.RIGHT_ALIGNMENT); + JTextField textField = new JTextField(species.getSpecies().getName(), JLabel.LEFT); + textField.setFont(captionFont); + textField.setEditable(false); + tmpPanel.add(textField, Component.LEFT_ALIGNMENT); + + tmpPanel.add(new JLabel("Alias id: ", JLabel.RIGHT), Component.RIGHT_ALIGNMENT); + textField = new JTextField(species.getAliasID(), JLabel.LEFT); + textField.setEditable(false); + tmpPanel.add(textField, Component.LEFT_ALIGNMENT); + + tmpPanel.add(new JLabel("Species id: ", JLabel.RIGHT), Component.RIGHT_ALIGNMENT); + textField = new JTextField(species.getSpecies().getId(), JLabel.LEFT); + textField.setEditable(false); + tmpPanel.add(textField, Component.LEFT_ALIGNMENT); + + result.add(tmpPanel); + + // add empty space between labels + result.add(Box.createRigidArea(new Dimension(DISTANCE_BETWEEN_PANELS, DISTANCE_BETWEEN_PANELS))); + + return result; + } + + /** + * Returns info if the frame is visible. + * + * @return info if the frame is visible + */ + public boolean isVisible() { + return frame.isVisible(); + } + + /** + * Sets frame title. + * + * @param title + * title of the frame + */ + public void setTitle(String title) { + frame.setTitle(title); + } + + /** + * Returns frame title. + * + * @return frame title + */ + public JFrame getFrame() { + return frame; + } + + /** + * Set {@link JFrame#defaultCloseOperation}. + * + * @param type + * new {@link JFrame#defaultCloseOperation} value + */ + public void setDefaultCloseOperation(int type) { + frame.setDefaultCloseOperation(type); + } + + /** + * Set {@link JFrame#setAlwaysOnTop(boolean)}. + * + * @param always + * new {@link JFrame#isAlwaysOnTop()} value + */ + public void setAlwaysOnTop(boolean always) { + frame.setAlwaysOnTop(always); + } } diff --git a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/info/InfoPlugin.java b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/info/InfoPlugin.java index dfe0ec3728a9195f03a8e44082d70fbc49ea854e..52c69f6440d96da4c8f73f9cafb954e693359ef1 100644 --- a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/info/InfoPlugin.java +++ b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/info/InfoPlugin.java @@ -9,13 +9,13 @@ import java.util.ArrayList; import javax.swing.Timer; +import org.apache.log4j.Logger; + import jp.sbi.celldesigner.plugin.CellDesignerPlugin; import jp.sbi.celldesigner.plugin.PluginListOf; import jp.sbi.celldesigner.plugin.PluginSBase; import jp.sbi.celldesigner.plugin.PluginSpeciesAlias; -import org.apache.log4j.Logger; - /** * This class represent a plugin to CellDesigner that add info text box with * informations about species. Plugin run in pooling mode (there is no other way @@ -28,145 +28,146 @@ import org.apache.log4j.Logger; */ public class InfoPlugin extends CellDesignerPlugin { - /** - * What is the time between two consecutive checks if the set of selected - * elements changed. - */ - private static final int DELAY_BETWEEN_ON_SELECT_LISTENER_CHECKS = 250; - - /** - * Maximum number of elements that will be described in the text box. - */ - private static final int MAX_VISIBLE_ELEMENTS = 5; - - /** - * Default class logger. - */ - private Logger logger = Logger.getLogger(InfoPlugin.class.getName()); - - /** - * Listener called when set of selected elements in cell designer changed. - */ - private ActionListener onChangeSelectListener; - - /** - * Frame where visualization is generated. - */ - private InfoFrame frame; - - /** - * Default constructor. Creates menu and InfoFrame. - */ - public InfoPlugin() { - try { - // load logger information - - // PropertyConfigurator.configure("D:/log4j.properties"); - logger.debug("Loading info plugin..."); - - frame = InfoFrame.getInstance(); - - // create keyboard listener for shortcuts - KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() { - public boolean dispatchKeyEvent(KeyEvent e) { - if (KeyEvent.KEY_PRESSED == e.getID()) { - // if someone hits CTRL+T then open/hide info window - if (e.getKeyCode() == java.awt.event.KeyEvent.VK_T && e.getModifiers() == java.awt.event.InputEvent.CTRL_MASK) { - frame.setVisible(!frame.isVisible()); - return true; - } - } - return false; - } - }); - - // create a listener for refreshing selected elements - onChangeSelectListener = new ActionListener() { - - /** - * This string contains a simple hash of all species shown in the last - * run of this listener. Due to this information we don't have to - * refresh this information at every run. - */ - private String selectedElementsId = ""; - - @Override - public void actionPerformed(ActionEvent arg0) { - - // if there is no open model then getSelectedAllNode() will throw an - // exception... - PluginListOf list = null; - try { - list = getSelectedAllNode(); - } catch (Exception e) { - return; - } - try { - ArrayList<PluginSpeciesAlias> v = new ArrayList<PluginSpeciesAlias>(); - String newId = ""; - // max five elements should be shown in infofrmae - for (int i = 0; i < Math.min(list.size(), MAX_VISIBLE_ELEMENTS); i++) { - if (list.get(i) instanceof PluginSpeciesAlias) { - PluginSpeciesAlias alias = (PluginSpeciesAlias) list.get(i); - v.add(alias); - newId += alias.getSpecies().getName(); - } - } - // if the cache is exactly the same as in the previous run then - // don't update infoframe - if (!selectedElementsId.equals(newId)) { - selectedElementsId = newId; - frame.setSpecies(v); - } - } catch (Exception exception) { - logger.error(exception, exception); - } - - } - }; - - Timer timer = new Timer(DELAY_BETWEEN_ON_SELECT_LISTENER_CHECKS, onChangeSelectListener); - timer.start(); - - } catch (Exception exception) { - logger.error("Unhandled exception. ", exception); - } - } - - // CHECKSTYLE:OFF - @Override - public void SBaseAdded(PluginSBase arg0) { - - } - - @Override - public void SBaseChanged(PluginSBase arg0) { - - } - - @Override - public void SBaseDeleted(PluginSBase arg0) { - } - - // CHECKSTYLE:ON - - @Override - public void addPluginMenu() { - } - - @Override - public void modelClosed(PluginSBase arg0) { - - } - - @Override - public void modelOpened(PluginSBase arg0) { - - } - - @Override - public void modelSelectChanged(PluginSBase arg0) { - - } + /** + * What is the time between two consecutive checks if the set of selected + * elements changed. + */ + private static final int DELAY_BETWEEN_ON_SELECT_LISTENER_CHECKS = 250; + + /** + * Maximum number of elements that will be described in the text box. + */ + private static final int MAX_VISIBLE_ELEMENTS = 5; + + /** + * Default class logger. + */ + private Logger logger = Logger.getLogger(InfoPlugin.class.getName()); + + /** + * Listener called when set of selected elements in cell designer changed. + */ + private ActionListener onChangeSelectListener; + + /** + * Frame where visualization is generated. + */ + private InfoFrame frame; + + /** + * Default constructor. Creates menu and InfoFrame. + */ + public InfoPlugin() { + try { + // load logger information + + // PropertyConfigurator.configure("D:/log4j.properties"); + logger.debug("Loading info plugin..."); + + frame = InfoFrame.getInstance(); + + // create keyboard listener for shortcuts + KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() { + public boolean dispatchKeyEvent(KeyEvent e) { + if (KeyEvent.KEY_PRESSED == e.getID()) { + // if someone hits CTRL+T then open/hide info window + if (e.getKeyCode() == java.awt.event.KeyEvent.VK_T + && e.getModifiers() == java.awt.event.InputEvent.CTRL_MASK) { + frame.setVisible(!frame.isVisible()); + return true; + } + } + return false; + } + }); + + // create a listener for refreshing selected elements + onChangeSelectListener = new ActionListener() { + + /** + * This string contains a simple hash of all species shown in the last run of + * this listener. Due to this information we don't have to refresh this + * information at every run. + */ + private String selectedElementsId = ""; + + @Override + public void actionPerformed(ActionEvent arg0) { + + // if there is no open model then getSelectedAllNode() will throw an + // exception... + PluginListOf list = null; + try { + list = getSelectedAllNode(); + } catch (Exception e) { + return; + } + try { + ArrayList<PluginSpeciesAlias> v = new ArrayList<PluginSpeciesAlias>(); + String newId = ""; + // max five elements should be shown in infofrmae + for (int i = 0; i < Math.min(list.size(), MAX_VISIBLE_ELEMENTS); i++) { + if (list.get(i) instanceof PluginSpeciesAlias) { + PluginSpeciesAlias alias = (PluginSpeciesAlias) list.get(i); + v.add(alias); + newId += alias.getSpecies().getName(); + } + } + // if the cache is exactly the same as in the previous run then + // don't update infoframe + if (!selectedElementsId.equals(newId)) { + selectedElementsId = newId; + frame.setSpecies(v); + } + } catch (Exception exception) { + logger.error(exception, exception); + } + + } + }; + + Timer timer = new Timer(DELAY_BETWEEN_ON_SELECT_LISTENER_CHECKS, onChangeSelectListener); + timer.start(); + + } catch (Exception exception) { + logger.error("Unhandled exception. ", exception); + } + } + + // CHECKSTYLE:OFF + @Override + public void SBaseAdded(PluginSBase arg0) { + + } + + @Override + public void SBaseChanged(PluginSBase arg0) { + + } + + @Override + public void SBaseDeleted(PluginSBase arg0) { + } + + // CHECKSTYLE:ON + + @Override + public void addPluginMenu() { + } + + @Override + public void modelClosed(PluginSBase arg0) { + + } + + @Override + public void modelOpened(PluginSBase arg0) { + + } + + @Override + public void modelSelectChanged(PluginSBase arg0) { + + } } \ No newline at end of file diff --git a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/info/package-info.java b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/info/package-info.java index 311f2ff3bd00d6d38539f7c40937c92789cb75bf..cc230fa10816d3429385344e5d2bd98847a1b863 100644 --- a/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/info/package-info.java +++ b/CellDesigner-plugin/src/main/java/lcsb/mapviewer/cdplugin/info/package-info.java @@ -4,4 +4,3 @@ * {@link lcsb.mapviewer.cdplugin.info.InfoPlugin}. */ package lcsb.mapviewer.cdplugin.info; - diff --git a/CellDesigner-plugin/src/test/java/lcsb/mapviewer/cdplugin/copypaste/CopyPasteAbstractActionTest.java b/CellDesigner-plugin/src/test/java/lcsb/mapviewer/cdplugin/copypaste/CopyPasteAbstractActionTest.java index dc9a41e160029bf933b7e790b55660c481592e00..d1b7ccd956a2a69f1d8f6ab98a4ca55e0723e172 100644 --- a/CellDesigner-plugin/src/test/java/lcsb/mapviewer/cdplugin/copypaste/CopyPasteAbstractActionTest.java +++ b/CellDesigner-plugin/src/test/java/lcsb/mapviewer/cdplugin/copypaste/CopyPasteAbstractActionTest.java @@ -6,123 +6,125 @@ import static org.junit.Assert.assertNull; import java.util.Set; -import lcsb.mapviewer.common.Pair; -import lcsb.mapviewer.model.map.MiriamData; -import lcsb.mapviewer.model.map.MiriamRelationType; -import lcsb.mapviewer.model.map.MiriamType; - import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; +import lcsb.mapviewer.common.Pair; +import lcsb.mapviewer.model.map.MiriamData; +import lcsb.mapviewer.model.map.MiriamRelationType; +import lcsb.mapviewer.model.map.MiriamType; + public class CopyPasteAbstractActionTest { - Logger logger = Logger.getLogger(CopyPasteAbstractActionTest.class); - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testPaste() throws Exception { - try { - CopyPasteAbstractAction pa = new PasteAction(); - String clipboardString = "[MIRIAM]\t" + MiriamRelationType.BQ_BIOL_IS.getStringRepresentation() + "\t" + MiriamType.CHEBI.getUris().get(0) - + "\tCHEBI:12345\nasd"; - Pair<Set<MiriamData>, String> res = pa.getAnnotationDataFromClipboardString(clipboardString); - assertNotNull(res); - assertNotNull(res.getLeft()); - assertEquals(1, res.getLeft().size()); - assertNotNull(res.getRight()); - assertEquals("asd", res.getRight()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopyPaste() throws Exception { - try { - CopyPasteAbstractAction pa = new PasteAction(); - String annString = "<rdf:RDF xmlns:bqbiol=\"http://biomodels.net/biology-qualifiers/\" " - + "xmlns:bqmodel=\"http://biomodels.net/model-qualifiers/\" " - + "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n" - + "<rdf:Description rdf:about=\"#s1\">" + "<bqmodel:is>" + "<rdf:Bag>" + "<rdf:li rdf:resource=\"urn:miriam:hgnc:SNCA\"/>" + "</rdf:Bag>" - + "</bqmodel:is>" + "</rdf:Description>" + "</rdf:RDF>"; - - String str = pa.getCopyString(annString, "notes"); - - Pair<Set<MiriamData>, String> res = pa.getAnnotationDataFromClipboardString(str); - assertNotNull(res); - assertNotNull(res.getLeft()); - assertEquals(1, res.getLeft().size()); - assertNotNull(res.getRight()); - assertEquals("notes", res.getRight()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testSerializeMiriam() throws Exception { - try { - CopyPasteAbstractAction pa = new PasteAction(); - MiriamData md = new MiriamData(MiriamType.CHEBI, "CH:12"); - - String string = pa.serialize(md); - MiriamData md2 = pa.deserialize(string); - assertEquals(md, md2); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testDeserializeMiriam() throws Exception { - try { - CopyPasteAbstractAction pa = new PasteAction(); - - MiriamData md = pa.deserialize("ASDASDAS"); - assertNull(md); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testDeserializeMiriam2() throws Exception { - try { - CopyPasteAbstractAction pa = new PasteAction(); - - MiriamData md = pa.deserialize(null); - assertNull(md); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testDeserializeMiriam3() throws Exception { - try { - CopyPasteAbstractAction pa = new PasteAction(); - - MiriamData md = pa.deserialize("[MIRIAM]\tinvalid\ttype\tresource"); - assertNull(md); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + Logger logger = Logger.getLogger(CopyPasteAbstractActionTest.class); + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testPaste() throws Exception { + try { + CopyPasteAbstractAction pa = new PasteAction(); + String clipboardString = "[MIRIAM]\t" + MiriamRelationType.BQ_BIOL_IS.getStringRepresentation() + "\t" + + MiriamType.CHEBI.getUris().get(0) + + "\tCHEBI:12345\nasd"; + Pair<Set<MiriamData>, String> res = pa.getAnnotationDataFromClipboardString(clipboardString); + assertNotNull(res); + assertNotNull(res.getLeft()); + assertEquals(1, res.getLeft().size()); + assertNotNull(res.getRight()); + assertEquals("asd", res.getRight()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopyPaste() throws Exception { + try { + CopyPasteAbstractAction pa = new PasteAction(); + String annString = "<rdf:RDF xmlns:bqbiol=\"http://biomodels.net/biology-qualifiers/\" " + + "xmlns:bqmodel=\"http://biomodels.net/model-qualifiers/\" " + + "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n" + + "<rdf:Description rdf:about=\"#s1\">" + "<bqmodel:is>" + "<rdf:Bag>" + + "<rdf:li rdf:resource=\"urn:miriam:hgnc:SNCA\"/>" + "</rdf:Bag>" + + "</bqmodel:is>" + "</rdf:Description>" + "</rdf:RDF>"; + + String str = pa.getCopyString(annString, "notes"); + + Pair<Set<MiriamData>, String> res = pa.getAnnotationDataFromClipboardString(str); + assertNotNull(res); + assertNotNull(res.getLeft()); + assertEquals(1, res.getLeft().size()); + assertNotNull(res.getRight()); + assertEquals("notes", res.getRight()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testSerializeMiriam() throws Exception { + try { + CopyPasteAbstractAction pa = new PasteAction(); + MiriamData md = new MiriamData(MiriamType.CHEBI, "CH:12"); + + String string = pa.serialize(md); + MiriamData md2 = pa.deserialize(string); + assertEquals(md, md2); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testDeserializeMiriam() throws Exception { + try { + CopyPasteAbstractAction pa = new PasteAction(); + + MiriamData md = pa.deserialize("ASDASDAS"); + assertNull(md); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testDeserializeMiriam2() throws Exception { + try { + CopyPasteAbstractAction pa = new PasteAction(); + + MiriamData md = pa.deserialize(null); + assertNull(md); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testDeserializeMiriam3() throws Exception { + try { + CopyPasteAbstractAction pa = new PasteAction(); + + MiriamData md = pa.deserialize("[MIRIAM]\tinvalid\ttype\tresource"); + assertNull(md); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } }