Author: kono
Date: 2010-12-02 16:42:00 -0800 (Thu, 02 Dec 2010)
New Revision: 23079
Added:
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/DiscreteValuePropertyEditor.java
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/propertyeditor/CyDiscreteValuePropertyEditor.java
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/valueeditor/DiscreteValueEditor.java
Removed:
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/valueeditor/DiscreteValueChooser.java
Modified:
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/EditorManagerImpl.java
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/propertyeditor/CyComboBoxPropertyEditor.java
core3/vizmap-gui-impl/trunk/src/main/resources/META-INF/spring/bundle-context-vizmapper.xml
Log:
Discrete value editor update mechanism had been fixed. Once new rendering
engine factory is provided by a bundle, it automatically scan the lexicon and
creates editor objects.
Added:
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/DiscreteValuePropertyEditor.java
===================================================================
---
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/DiscreteValuePropertyEditor.java
(rev 0)
+++
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/DiscreteValuePropertyEditor.java
2010-12-03 00:42:00 UTC (rev 23079)
@@ -0,0 +1,27 @@
+package org.cytoscape.view.vizmap.gui.internal.editor;
+
+import java.util.Set;
+
+import
org.cytoscape.view.vizmap.gui.internal.editor.propertyeditor.CyComboBoxPropertyEditor;
+
+/**
+ * Editor object for all kinds of discrete values such as Node Shape, Line
+ * Stroke, etc.
+ *
+ *
+ * @param <T>
+ */
+public class DiscreteValuePropertyEditor<T> extends
+ AbstractVisualPropertyEditor<T> {
+
+ public DiscreteValuePropertyEditor(Class<T> type, Set<T> values) {
+ super(type, new CyComboBoxPropertyEditor());
+
+ discreteTableCellRenderer = REG.getRenderer(type);
+ //continuousTableCellRenderer = new IconCellRenderer<T>(icons);
+
+ CyComboBoxPropertyEditor cbe = (CyComboBoxPropertyEditor)
propertyEditor;
+ cbe.setAvailableValues(values.toArray());
+
+ }
+}
Modified:
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/EditorManagerImpl.java
===================================================================
---
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/EditorManagerImpl.java
2010-12-03 00:18:55 UTC (rev 23078)
+++
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/EditorManagerImpl.java
2010-12-03 00:42:00 UTC (rev 23079)
@@ -52,8 +52,13 @@
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
import org.cytoscape.model.CyTableEntry;
+import org.cytoscape.view.model.DiscreteRange;
+import org.cytoscape.view.model.Range;
import org.cytoscape.view.model.VisualLexicon;
import org.cytoscape.view.model.VisualProperty;
+import org.cytoscape.view.presentation.events.RenderingEngineFactoryAddedEvent;
+import
org.cytoscape.view.presentation.events.RenderingEngineFactoryAddedListener;
+import org.cytoscape.view.vizmap.VisualMappingManager;
import org.cytoscape.view.vizmap.gui.MappingFunctionFactoryManager;
import org.cytoscape.view.vizmap.gui.editor.EditorManager;
import org.cytoscape.view.vizmap.gui.editor.ListEditor;
@@ -62,13 +67,14 @@
import org.cytoscape.view.vizmap.gui.internal.AttributeSetManager;
import
org.cytoscape.view.vizmap.gui.internal.editor.propertyeditor.AttributeComboBoxPropertyEditor;
import
org.cytoscape.view.vizmap.gui.internal.editor.propertyeditor.CyComboBoxPropertyEditor;
+import
org.cytoscape.view.vizmap.gui.internal.editor.valueeditor.DiscreteValueEditor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
-public class EditorManagerImpl implements EditorManager {
+public class EditorManagerImpl implements EditorManager,
RenderingEngineFactoryAddedListener {
private static final Logger logger = LoggerFactory
.getLogger(EditorManagerImpl.class);
@@ -87,7 +93,7 @@
/**
* Creates a new EditorFactory object.
*/
- public EditorManagerImpl(final AttributeSetManager attrManager) {
+ public EditorManagerImpl(final AttributeSetManager attrManager, final
VisualMappingManager vmm) {
editors = new HashMap<Class<?>, VisualPropertyEditor<?>>();
comboBoxEditors = new HashMap<String, PropertyEditor>();
@@ -105,8 +111,16 @@
// Create mapping type editor
this.mappingTypeEditor =
getDefaultComboBoxEditor("mappingTypeEditor");
+
+ Set<VisualLexicon> lexSet = vmm.getAllVisualLexicon();
+
+ for(final VisualLexicon lex: lexSet) {
+ this.buildDiscreteEditors(lex);
+ }
}
+
+
public AttributeComboBoxPropertyEditor getNodeEditor() {
return (AttributeComboBoxPropertyEditor)
attrComboBoxEditors.get(CyNode.class);
}
@@ -320,4 +334,38 @@
public PropertyEditor getMappingFunctionSelector() {
return mappingTypeEditor;
}
+
+
+ private void buildDiscreteEditors(final VisualLexicon lexicon) {
+
+ logger.debug("\n\n\nNew Engine Factory: Adding discrete value
editors------------------------");
+
+ Set<VisualProperty<?>> vps = lexicon.getAllVisualProperties();
+ for(final VisualProperty<?> vp: vps) {
+ Range<?> range = vp.getRange();
+
+ if(range instanceof DiscreteRange<?>) {
+
+ // Visual Property Editor.
+ logger.debug("Got new Discrete. Creating new
VP editor: " + vp.getDisplayName());
+ final Set<?> values = ((DiscreteRange<?>)
range).values();
+ VisualPropertyEditor<?> vpEditor = new
DiscreteValuePropertyEditor(range.getType(), values);
+ this.addVisualPropertyEditor(vpEditor, null);
+
+ if(this.getValueEditor(range.getType()) ==
null) {
+ ValueEditor<?> valEditor = new
DiscreteValueEditor(range.getType(), values);
+ this.addValueEditor(valEditor, null);
+ }
+
+ }
+ }
+ }
+ @Override
+ public void handleEvent(RenderingEngineFactoryAddedEvent e) {
+
+
+ final VisualLexicon lexicon =
e.getRenderingEngineFactory().getVisualLexicon();
+ buildDiscreteEditors(lexicon);
+
+ }
}
Modified:
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/propertyeditor/CyComboBoxPropertyEditor.java
===================================================================
---
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/propertyeditor/CyComboBoxPropertyEditor.java
2010-12-03 00:18:55 UTC (rev 23078)
+++
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/propertyeditor/CyComboBoxPropertyEditor.java
2010-12-03 00:42:00 UTC (rev 23079)
@@ -48,8 +48,7 @@
private static final Color BACKGROUND = Color.white;
private static final Color NOT_SELECTED = new Color(51, 51, 255, 150);
private static final Color SELECTED = Color.red;
- private static final Font SELECTED_FONT = new Font("SansSerif",
Font.BOLD,
- 12);
+ private static final Font SELECTED_FONT = new Font("SansSerif",
Font.BOLD, 12);
private Object oldValue;
private Icon[] icons;
Added:
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/propertyeditor/CyDiscreteValuePropertyEditor.java
===================================================================
---
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/propertyeditor/CyDiscreteValuePropertyEditor.java
(rev 0)
+++
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/propertyeditor/CyDiscreteValuePropertyEditor.java
2010-12-03 00:42:00 UTC (rev 23079)
@@ -0,0 +1,15 @@
+package org.cytoscape.view.vizmap.gui.internal.editor.propertyeditor;
+
+import com.l2fprod.common.beans.editor.AbstractPropertyEditor;
+
+public class CyDiscreteValuePropertyEditor extends AbstractPropertyEditor {
+
+
+ @Override public Object getValue() {
+ return null;
+ }
+
+ @Override public void setValue(Object value) {
+
+ }
+}
Deleted:
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/valueeditor/DiscreteValueChooser.java
===================================================================
---
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/valueeditor/DiscreteValueChooser.java
2010-12-03 00:18:55 UTC (rev 23078)
+++
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/valueeditor/DiscreteValueChooser.java
2010-12-03 00:42:00 UTC (rev 23079)
@@ -1,304 +0,0 @@
-/*
- Copyright (c) 2006, 2007, 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 org.cytoscape.view.vizmap.gui.internal.editor.valueeditor;
-
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.event.ActionEvent;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.swing.DefaultListModel;
-import javax.swing.GroupLayout;
-import javax.swing.Icon;
-import javax.swing.JDialog;
-import javax.swing.JLabel;
-import javax.swing.JList;
-import javax.swing.LayoutStyle;
-import javax.swing.ListCellRenderer;
-import javax.swing.ListSelectionModel;
-import javax.swing.SwingConstants;
-
-import org.cytoscape.view.model.VisualProperty;
-import org.jdesktop.swingx.border.DropShadowBorder;
-
-/**
- * Chooser for any discrete values. This includes:
- * <ul>
- * <li>node shape</li>
- * <li>arrow shape</li>
- * <li>line style</li>
- * <li>etc.</li>
- * </ul>
- *
- * @author kono
- */
-public class DiscreteValueChooser<T> extends JDialog {
- private final static long serialVersionUID = 1202339876950593L;
-
- private final VisualProperty<T> type;
-
- private Map<T, Icon> valueMap;
- private List<T> orderedKeyList;
- private T defaultValue;
- private boolean canceled = false;
-
- public DiscreteValueChooser(VisualProperty<T> vp) {
- this(vp, null, null);
- }
-
- /**
- * Creates a new DiscreteValueChooser object.
- *
- * If List of discrete values and
- *
- * @param vp
- * DOCUMENT ME!
- */
- public DiscreteValueChooser(VisualProperty<T> vp, Map<T, Icon> valueMap,
- T defaultValue) {
- super();
- this.setModal(true);
- this.type = vp;
- this.setTitle("Select " + type.getDisplayName());
-
- this.valueMap = valueMap;
- initComponents();
- setListItems();
-
- this.defaultValue = defaultValue;
- }
-
- /**
- * This should be a listener for OSGi service.
- */
-
- /**
- * Static method to show dialog and get a value from user.
- *
- * @param type
- * @param parent
- * @return
- */
- public T showDialog(Component parentComponent) {
- setLocationRelativeTo(parentComponent);
- setVisible(true);
-
- return getValue();
- }
-
- /**
- * This method is called from within the constructor to initialize the
form.
- * WARNING: Do NOT modify this code. The content of this method is
always
- * regenerated by the Form Editor.
- */
-
- // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
- private void initComponents() {
- mainPanel = new org.jdesktop.swingx.JXTitledPanel();
- iconListScrollPane = new javax.swing.JScrollPane();
- iconList = new javax.swing.JList();
- applyButton = new javax.swing.JButton();
- cancelButton = new javax.swing.JButton();
-
-
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- setTitle("Select New Value");
-
- // TODO: should change the design
- // mainPanel.setTitlePainter(new BasicGradientPainter(new
- // Point2D.Double(.2d, 0),
- // new Color(Color.gray.getRed(),
- // Color.gray.getGreen(),
- // Color.gray.getBlue(), 100),
- // new Point2D.Double(.8d, 0), Color.WHITE));
-
- mainPanel.setTitleFont(new java.awt.Font("SansSerif", 1, 14));
-
- iconList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- iconListScrollPane.setViewportView(iconList);
-
- applyButton.setText("Apply");
- applyButton.addActionListener(new
java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent
evt) {
- applyButtonActionPerformed(evt);
- }
- });
-
- cancelButton.setText("Cancel");
- cancelButton.addActionListener(new
java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent
evt) {
- cancelButtonActionPerformed(evt);
- }
- });
- // Currently not implemented
- cancelButton.setVisible(true);
-
- GroupLayout mainPanelLayout = new GroupLayout(mainPanel
- .getContentContainer());
- mainPanel.getContentContainer().setLayout(mainPanelLayout);
-
mainPanelLayout.setHorizontalGroup(mainPanelLayout.createParallelGroup(
- GroupLayout.Alignment.LEADING)
- .addGroup(
- GroupLayout.Alignment.TRAILING,
-
mainPanelLayout.createSequentialGroup()
-
.addContainerGap(128, Short.MAX_VALUE)
-
.addComponent(cancelButton).addPreferredGap(
-
LayoutStyle.ComponentPlacement.RELATED)
-
.addComponent(applyButton).addContainerGap())
- .addComponent(iconListScrollPane,
GroupLayout.DEFAULT_SIZE,
- 291, Short.MAX_VALUE));
-
mainPanelLayout.setVerticalGroup(mainPanelLayout.createParallelGroup(
- GroupLayout.Alignment.LEADING).addGroup(
- GroupLayout.Alignment.TRAILING,
-
mainPanelLayout.createSequentialGroup().addComponent(
- iconListScrollPane,
GroupLayout.DEFAULT_SIZE, 312,
-
Short.MAX_VALUE).addPreferredGap(
-
LayoutStyle.ComponentPlacement.RELATED).addGroup(
-
mainPanelLayout.createParallelGroup(
-
GroupLayout.Alignment.BASELINE).addComponent(
-
applyButton).addComponent(cancelButton))
- .addContainerGap()));
-
- GroupLayout layout = new GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(layout.createParallelGroup(
-
GroupLayout.Alignment.LEADING).addComponent(mainPanel,
- GroupLayout.DEFAULT_SIZE,
GroupLayout.DEFAULT_SIZE,
- Short.MAX_VALUE));
- layout.setVerticalGroup(layout.createParallelGroup(
-
GroupLayout.Alignment.LEADING).addComponent(mainPanel,
- GroupLayout.DEFAULT_SIZE,
GroupLayout.DEFAULT_SIZE,
- Short.MAX_VALUE));
- pack();
- } // </editor-fold>
-
- private void cancelButtonActionPerformed(ActionEvent evt) {
- dispose();
- canceled = true;
- }
-
- private void applyButtonActionPerformed(ActionEvent evt) {
- dispose();
- }
-
- // Variables declaration - do not modify
- private javax.swing.JButton applyButton;
- private javax.swing.JButton cancelButton;
- private javax.swing.JList iconList;
- private javax.swing.JScrollPane iconListScrollPane;
- private org.jdesktop.swingx.JXTitledPanel mainPanel;
- private DefaultListModel model;
-
- // End of variables declaration
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public T getValue() {
- if (canceled == true)
- return defaultValue;
-
- final int selectedIndex = iconList.getSelectedIndex();
-
- if ((0 <= selectedIndex) && (selectedIndex <
orderedKeyList.size()))
- return orderedKeyList.get(selectedIndex);
- else
-
- return defaultValue;
- }
-
- private void setListItems() {
- List<Icon> icons = new ArrayList<Icon>();
- orderedKeyList = new ArrayList<T>();
-
- model = new DefaultListModel();
- iconList.setModel(model);
-
- Icon icon;
-
- for (T key : valueMap.keySet()) {
- icon = valueMap.get(key);
-
- icons.add(icon);
- orderedKeyList.add(key);
- model.addElement(key);
- }
-
- iconList.setCellRenderer(new IconCellRenderer());
- iconList.repaint();
- }
-
- // TODO: tuning icon layout
- public class IconCellRenderer extends JLabel implements
ListCellRenderer {
- private final static long serialVersionUID = 1202339876940871L;
- private final Font SELECTED_FONT = new Font("SansSerif",
Font.ITALIC,
- 18);
- private final Font NORMAL_FONT = new Font("SansSerif",
Font.BOLD, 14);
- private final Color SELECTED_COLOR = new Color(30, 30, 80, 25);
- private final Color SELECTED_FONT_COLOR = new Color(0, 150,
255, 120);
-
- public IconCellRenderer() {
- setOpaque(true);
- }
-
- public Component getListCellRendererComponent(JList list,
Object value,
- int index, boolean isSelected, boolean
cellHasFocus) {
- // Get icon for the target value
- final Icon icon = valueMap.get(value);
-
- setText(value.toString());
- // icon.setLeftPadding(15);
- setIcon(icon);
- setFont(isSelected ? SELECTED_FONT : NORMAL_FONT);
-
- this.setVerticalTextPosition(SwingConstants.CENTER);
- this.setVerticalAlignment(SwingConstants.CENTER);
- this.setIconTextGap(35);
-
- setBackground(isSelected ? SELECTED_COLOR :
list.getBackground());
- setForeground(isSelected ? SELECTED_FONT_COLOR : list
- .getForeground());
- setPreferredSize(new Dimension(icon.getIconWidth(), icon
- .getIconHeight() + 20));
- this.setBorder(new DropShadowBorder());
-
- return this;
- }
- }
-}
Copied:
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/valueeditor/DiscreteValueEditor.java
(from rev 22416,
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/valueeditor/DiscreteValueChooser.java)
===================================================================
---
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/valueeditor/DiscreteValueEditor.java
(rev 0)
+++
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/valueeditor/DiscreteValueEditor.java
2010-12-03 00:42:00 UTC (rev 23079)
@@ -0,0 +1,291 @@
+/*
+ Copyright (c) 2006, 2007, 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 org.cytoscape.view.vizmap.gui.internal.editor.valueeditor;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.swing.DefaultListModel;
+import javax.swing.GroupLayout;
+import javax.swing.Icon;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.LayoutStyle;
+import javax.swing.ListCellRenderer;
+import javax.swing.ListSelectionModel;
+import javax.swing.SwingConstants;
+
+import org.cytoscape.view.model.VisualProperty;
+import org.cytoscape.view.vizmap.gui.editor.ValueEditor;
+import org.jdesktop.swingx.border.DropShadowBorder;
+
+/**
+ * Chooser for any discrete values. This includes:
+ * <ul>
+ * <li>node shape</li>
+ * <li>arrow shape</li>
+ * <li>line style</li>
+ * <li>etc.</li>
+ * </ul>
+ *
+ * @author kono
+ */
+public class DiscreteValueEditor<T> extends JDialog implements ValueEditor<T> {
+
+ private final static long serialVersionUID = 1202339876950593L;
+
+ private final Class<T> type;
+ private final Set<T> values;
+
+// private Map<T, Icon> valueMap;
+//
+// private List<T> orderedKeyList;
+// private T defaultValue;
+ private boolean canceled = false;
+
+ public DiscreteValueEditor(Class<T> type, Set<T> values) {
+ super();
+ this.values = values;
+ this.type = type;
+
+ this.setModal(true);
+ this.setTitle("Select a value");
+
+ initComponents();
+ setListItems();
+ }
+
+
+ /**
+ * This method is called from within the constructor to initialize the
form.
+ * WARNING: Do NOT modify this code. The content of this method is
always
+ * regenerated by the Form Editor.
+ */
+
+ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
+ private void initComponents() {
+ mainPanel = new org.jdesktop.swingx.JXTitledPanel();
+ iconListScrollPane = new javax.swing.JScrollPane();
+ iconList = new javax.swing.JList();
+ applyButton = new javax.swing.JButton();
+ cancelButton = new javax.swing.JButton();
+
+
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ setTitle("Select New Value");
+
+ mainPanel.setTitleFont(new java.awt.Font("SansSerif", 1, 14));
+
+ iconList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ iconListScrollPane.setViewportView(iconList);
+
+ applyButton.setText("Apply");
+ applyButton.addActionListener(new
java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent
evt) {
+ applyButtonActionPerformed(evt);
+ }
+ });
+
+ cancelButton.setText("Cancel");
+ cancelButton.addActionListener(new
java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent
evt) {
+ cancelButtonActionPerformed(evt);
+ }
+ });
+ // Currently not implemented
+ cancelButton.setVisible(true);
+
+ GroupLayout mainPanelLayout = new GroupLayout(mainPanel
+ .getContentContainer());
+ mainPanel.getContentContainer().setLayout(mainPanelLayout);
+
mainPanelLayout.setHorizontalGroup(mainPanelLayout.createParallelGroup(
+ GroupLayout.Alignment.LEADING)
+ .addGroup(
+ GroupLayout.Alignment.TRAILING,
+
mainPanelLayout.createSequentialGroup()
+
.addContainerGap(128, Short.MAX_VALUE)
+
.addComponent(cancelButton).addPreferredGap(
+
LayoutStyle.ComponentPlacement.RELATED)
+
.addComponent(applyButton).addContainerGap())
+ .addComponent(iconListScrollPane,
GroupLayout.DEFAULT_SIZE,
+ 291, Short.MAX_VALUE));
+
mainPanelLayout.setVerticalGroup(mainPanelLayout.createParallelGroup(
+ GroupLayout.Alignment.LEADING).addGroup(
+ GroupLayout.Alignment.TRAILING,
+
mainPanelLayout.createSequentialGroup().addComponent(
+ iconListScrollPane,
GroupLayout.DEFAULT_SIZE, 312,
+
Short.MAX_VALUE).addPreferredGap(
+
LayoutStyle.ComponentPlacement.RELATED).addGroup(
+
mainPanelLayout.createParallelGroup(
+
GroupLayout.Alignment.BASELINE).addComponent(
+
applyButton).addComponent(cancelButton))
+ .addContainerGap()));
+
+ GroupLayout layout = new GroupLayout(getContentPane());
+ getContentPane().setLayout(layout);
+ layout.setHorizontalGroup(layout.createParallelGroup(
+
GroupLayout.Alignment.LEADING).addComponent(mainPanel,
+ GroupLayout.DEFAULT_SIZE,
GroupLayout.DEFAULT_SIZE,
+ Short.MAX_VALUE));
+ layout.setVerticalGroup(layout.createParallelGroup(
+
GroupLayout.Alignment.LEADING).addComponent(mainPanel,
+ GroupLayout.DEFAULT_SIZE,
GroupLayout.DEFAULT_SIZE,
+ Short.MAX_VALUE));
+ pack();
+ } // </editor-fold>
+
+ private void cancelButtonActionPerformed(ActionEvent evt) {
+ dispose();
+ canceled = true;
+ }
+
+ private void applyButtonActionPerformed(ActionEvent evt) {
+ dispose();
+ }
+
+ // Variables declaration - do not modify
+ private javax.swing.JButton applyButton;
+ private javax.swing.JButton cancelButton;
+ private javax.swing.JList iconList;
+ private javax.swing.JScrollPane iconListScrollPane;
+ private org.jdesktop.swingx.JXTitledPanel mainPanel;
+ private DefaultListModel model;
+
+ // End of variables declaration
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public T getValue() {
+ if (canceled == true)
+ return null;
+
+ return (T) iconList.getSelectedValue();
+
+// final int selectedIndex = iconList.getSelectedIndex();
+//
+// if ((0 <= selectedIndex) && (selectedIndex <
orderedKeyList.size()))
+// return orderedKeyList.get(selectedIndex);
+// else
+//
+// return defaultValue;
+ }
+
+
+ private void setListItems() {
+ final List<Icon> icons = new ArrayList<Icon>();
+ //orderedKeyList = new ArrayList<T>();
+
+
+ model = new DefaultListModel();
+ iconList.setModel(model);
+
+ Icon icon;
+
+ for (final T key : values) {
+ //icon = valueMap.get(key);
+
+ //icons.add(icon);
+ //orderedKeyList.add(key);
+ model.addElement(key);
+ }
+
+ iconList.setCellRenderer(new IconCellRenderer());
+ iconList.repaint();
+ }
+
+ // TODO: tuning icon layout
+ public class IconCellRenderer extends JLabel implements
ListCellRenderer {
+ private final static long serialVersionUID = 1202339876940871L;
+ private final Font SELECTED_FONT = new Font("SansSerif",
Font.ITALIC,
+ 18);
+ private final Font NORMAL_FONT = new Font("SansSerif",
Font.BOLD, 14);
+ private final Color SELECTED_COLOR = new Color(30, 30, 80, 25);
+ private final Color SELECTED_FONT_COLOR = new Color(0, 150,
255, 120);
+
+ public IconCellRenderer() {
+ setOpaque(true);
+ }
+
+ public Component getListCellRendererComponent(JList list,
Object value,
+ int index, boolean isSelected, boolean
cellHasFocus) {
+ // Get icon for the target value
+
+ //TODO: fix icon
+ //final Icon icon = valueMap.get(value);
+
+ setText(value.toString());
+ // icon.setLeftPadding(15);
+ //setIcon(icon);
+ setFont(isSelected ? SELECTED_FONT : NORMAL_FONT);
+
+ this.setVerticalTextPosition(SwingConstants.CENTER);
+ this.setVerticalAlignment(SwingConstants.CENTER);
+ this.setIconTextGap(35);
+
+ setBackground(isSelected ? SELECTED_COLOR :
list.getBackground());
+ setForeground(isSelected ? SELECTED_FONT_COLOR : list
+ .getForeground());
+
+ this.setHorizontalTextPosition(CENTER);
+ setPreferredSize(new Dimension(100, 40));
+// setPreferredSize(new Dimension(icon.getIconWidth(), icon
+// .getIconHeight() + 20));
+ this.setBorder(new DropShadowBorder());
+
+ return this;
+ }
+ }
+
+ @Override
+ public <S extends T> T showEditor(Component parent, S initialValue) {
+ setLocationRelativeTo(parent);
+ setVisible(true);
+ return getValue();
+ }
+
+ @Override
+ public Class<T> getType() {
+ return type;
+ }
+}
Modified:
core3/vizmap-gui-impl/trunk/src/main/resources/META-INF/spring/bundle-context-vizmapper.xml
===================================================================
---
core3/vizmap-gui-impl/trunk/src/main/resources/META-INF/spring/bundle-context-vizmapper.xml
2010-12-03 00:18:55 UTC (rev 23078)
+++
core3/vizmap-gui-impl/trunk/src/main/resources/META-INF/spring/bundle-context-vizmapper.xml
2010-12-03 00:42:00 UTC (rev 23079)
@@ -65,6 +65,7 @@
<bean name="editorManager"
class="org.cytoscape.view.vizmap.gui.internal.editor.EditorManagerImpl">
<constructor-arg ref="attributeSetManager" />
+ <constructor-arg ref="vmmServiceRef" />
</bean>
--
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.