Author: laylaoesper
Date: 2010-07-18 09:37:28 -0700 (Sun, 18 Jul 2010)
New Revision: 20961
Added:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WidestStringComboBoxModel.java
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WidestStringComboBoxPopupMenuListener.java
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WidestStringProvider.java
Modified:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SemanticSummary.jar
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SemanticSummaryInputPanel.java
Log:
Making the SemanticSummary Plugin compatible with Cytoscape version 2.6.3.
Modified:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SemanticSummary.jar
===================================================================
(Binary files differ)
Modified:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SemanticSummaryInputPanel.java
===================================================================
---
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SemanticSummaryInputPanel.java
2010-07-17 03:55:22 UTC (rev 20960)
+++
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/SemanticSummaryInputPanel.java
2010-07-18 16:37:28 UTC (rev 20961)
@@ -61,8 +61,6 @@
import cytoscape.Cytoscape;
import cytoscape.data.CyAttributes;
-import cytoscape.util.swing.WidestStringComboBoxModel;
-import cytoscape.util.swing.WidestStringComboBoxPopupMenuListener;
/**
* The SemanticSummaryInputPanel class defines the panel that appears for
Added:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WidestStringComboBoxModel.java
===================================================================
---
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WidestStringComboBoxModel.java
(rev 0)
+++
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WidestStringComboBoxModel.java
2010-07-18 16:37:28 UTC (rev 20961)
@@ -0,0 +1,222 @@
+/*
+ Copyright (c) 2009, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+
+package cytoscape.csplugins.semanticsummary;
+
+import java.util.Vector;
+import javax.swing.DefaultComboBoxModel;
+
+/**
+ * @author Noel Ruddock
+ * This ComboBoxModel tracks the widest string
+ * getLabel(Object anObject) should be overridden to derive the String from
+ * an Object in the model when getString() doesn't provide what will be
+ * displayed.
+ */
+public class WidestStringComboBoxModel extends DefaultComboBoxModel implements
WidestStringProvider {
+ private String widest = null;
+ private boolean widestValid = false;
+
+ /**
+ * Class Constructor.
+ */
+ public WidestStringComboBoxModel() {
+ super();
+ }
+
+ /**
+ * Class Constructor specifying an array of Objects to form the model.
+ *
+ * @param items
+ */
+ public WidestStringComboBoxModel(Object[] items) {
+ super(items);
+ }
+
+ /**
+ * Class Constructor specifying a vector of Objects to form the model.
+ *
+ * @param v
+ */
+ public WidestStringComboBoxModel(Vector<?> v) {
+ super(v);
+ }
+
+ /**
+ * Adds the given object to the model.
+ * Additionally updates cached longest String.
+ *
+ * @param anObject the object to be added to the model
+ */
+ @Override
+ public void addElement(Object anObject) {
+ updateWidest(anObject, true);
+ super.addElement(anObject);
+ }
+
+ /**
+ * Inserts an object into the model at the given index.
+ * Additionally updates cached longest String.
+ *
+ * @param anObject the object to be added to the model
+ * @param index the index at which the given object is to be added
+ */
+ @Override
+ public void insertElementAt(Object anObject, int index) {
+ updateWidest(anObject, true);
+ super.insertElementAt(anObject, index);
+ }
+
+ /**
+ * Removes all objects from the model.
+ * Additionally updates cached longest String.
+ */
+ @Override
+ public void removeAllElements() {
+ resetWidest();
+ super.removeAllElements();
+ }
+
+ /**
+ * Removes the given object from the model.
+ * Additionally updates cached longest String.
+ *
+ * @param anObject the object to be removed from the model
+ */
+ @Override
+ public void removeElement(Object anObject) {
+ updateWidest(anObject, false);
+ super.removeElement(anObject);
+ }
+
+ /**
+ * Removes the object at the specified index from the model.
+ * Additionally updates cached longest String.
+ */
+ @Override
+ public void removeElementAt(int index) {
+ updateWidest(getElementAt(index), false);
+ super.removeElementAt(index);
+ }
+
+ /**
+ * Invalidates the cached longest String.
+ */
+ public void resetWidest() {
+ widest = null;
+ widestValid = false;
+ }
+
+ /**
+ * Returns the longest display String for the objects in this model.
+ * If the cached longest String is not valid, the longest String is
+ * determined and cached.
+ * @return the longest display String for the objects in this model
+ */
+ public String getWidest() {
+ if (!widestValid) {
+ findWidest();
+ }
+
+ return widest;
+ }
+
+ /**
+ * Update the cached longest String if required when a new object is added
+ * to the model, or invalidate it when removing.
+ *
+ * @param anObject the Object being added or removed
+ * @param adding true if the anObject is being added to the model, false if
+ * it is being removed
+ */
+ private void updateWidest(Object anObject, boolean adding) {
+ String label;
+
+ label = getLabel(anObject);
+ if (widestValid) {
+ if (adding) {
+ if (label.length() > widest.length()) {
+ widest = label;
+ }
+ }
+ else {
+ if (widest.equals(label)) {
+ resetWidest();
+ }
+ }
+ }
+ else {
+ if (adding) {
+ widest = label;
+ widestValid = true;
+ }
+ }
+ }
+
+ /**
+ * Find which display string for the objects in the model is the longest.
+ */
+ private void findWidest() {
+ int size;
+
+ size = getSize();
+ widest = "";
+ for (int i = 0; i < size; i++) {
+ String label;
+
+ label = getLabel(getElementAt(i));
+ if (label.length() > widest.length()) {
+ widest = label;
+ }
+ }
+ widestValid = true;
+ }
+
+ /**
+ * Returns the String corresponding to the parameter object for use in
+ * calculating the width of popup required.
+ * This method should be overridden when the toString method of whatever
+ * objects are stored in the model, doesn't return a suitable String.
+ * Should return an empty string when anObject == null.
+ *
+ * @param anObject
+ * @return the string that will be displayed for anObject. "" is returned
+ * when the passed object is null
+ */
+ protected String getLabel(Object anObject) {
+ return (anObject != null) ? anObject.toString() : "";
+ }
+}
+
Added:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WidestStringComboBoxPopupMenuListener.java
===================================================================
---
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WidestStringComboBoxPopupMenuListener.java
(rev 0)
+++
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WidestStringComboBoxPopupMenuListener.java
2010-07-18 16:37:28 UTC (rev 20961)
@@ -0,0 +1,119 @@
+/*
+ Copyright (c) 2009, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+
+package cytoscape.csplugins.semanticsummary;
+
+import java.awt.Dimension;
+import java.awt.FontMetrics;
+import javax.swing.ComboBoxModel;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JPopupMenu;
+import javax.swing.JScrollPane;
+import javax.swing.event.PopupMenuEvent;
+import javax.swing.event.PopupMenuListener;
+
+/**
+ * @author Noel Ruddock
+ *
+ * Listener that can be attached to a JComboBox.
+ * When the JComboBox to which it is attached uses a ComboBoxModel that
+ * implements WidestStringProvider, the popup list will be resized so that the
+ * longest String will be completely visible.
+ */
+public class WidestStringComboBoxPopupMenuListener implements
PopupMenuListener {
+ /**
+ * Resize the popup list based on the longest display string for objects in
+ * the model of the JComboBox being listened to.
+ * The model must implement WidestStringProvider for the popup to be sized.
+ *
+ * @param e
+ */
+ public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
+ ComboBoxModel cbm;
+ WidestStringProvider wsp;
+ int w, h;
+ Dimension d;
+
+ JComboBox box = (JComboBox)e.getSource();
+ cbm = box.getModel();
+
+ if (!(cbm instanceof WidestStringProvider)) {
+ // Silently ignore if not listening to a JComboBox with a suitable
model object
+ return;
+ }
+ wsp = (WidestStringProvider)cbm;
+
+ Object comp = box.getUI().getAccessibleChild(box, 0);
+
+ if (!(comp instanceof JPopupMenu)) {
+ return;
+ }
+
+ Object scrollObject = ((JComponent)comp).getComponent(0);
+
+ if (!(scrollObject instanceof JScrollPane)) {
+ return;
+ }
+
+ JScrollPane scrollPane = (JScrollPane)scrollObject;
+
+ FontMetrics fm = box.getFontMetrics(scrollPane.getFont());
+ w = (int)fm.stringWidth(wsp.getWidest());
+ h = (int)scrollPane.getMinimumSize().getHeight();
+ d = new Dimension(Math.max((int)((double)w +
scrollPane.getVerticalScrollBar().getMinimumSize().getWidth()),
box.getWidth()), h);
+ scrollPane.setPreferredSize(d);
+ scrollPane.setMaximumSize(d);
+ }
+
+ /**
+ * Not interested in this event.
+ *
+ * @param e
+ */
+ public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
+ return;
+ }
+
+ /**
+ * Not interested in this event.
+ *
+ * @param e
+ */
+ public void popupMenuCanceled(PopupMenuEvent e) {
+ return;
+ }
+}
+
Added:
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WidestStringProvider.java
===================================================================
---
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WidestStringProvider.java
(rev 0)
+++
csplugins/trunk/soc/layla/SemanticSummary/src/cytoscape/csplugins/semanticsummary/WidestStringProvider.java
2010-07-18 16:37:28 UTC (rev 20961)
@@ -0,0 +1,57 @@
+/*
+ Copyright (c) 2009, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+
+package cytoscape.csplugins.semanticsummary;
+
+/**
+ * @author Noel Ruddock
+ *
+ * Marker interface to decouple WidestStringComboBoxPopupMenuListener from
+ * WidestStringComboBoxModel.
+ */
+public interface WidestStringProvider {
+ /**
+ * Return the longest display String
+ *
+ * @return
+ */
+ public String getWidest();
+
+ /**
+ * Invalidate any cached longest String.
+ */
+ public void resetWidest();
+}
+
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.