Author: kono
Date: 2012-07-09 18:50:42 -0700 (Mon, 09 Jul 2012)
New Revision: 29818

Modified:
   
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/mappingeditor/C2CEditor.java
   
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/mappingeditor/C2CMappingEditorPanel.java
   
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/mappingeditor/ContinuousMappingEditorPanel.java
   
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/event/CellEditorEventHandler.java
Log:
refs #1244 Add more type checkers.

Modified: 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/mappingeditor/C2CEditor.java
===================================================================
--- 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/mappingeditor/C2CEditor.java
   2012-07-09 23:33:16 UTC (rev 29817)
+++ 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/mappingeditor/C2CEditor.java
   2012-07-10 01:50:42 UTC (rev 29818)
@@ -9,7 +9,7 @@
 import org.cytoscape.view.vizmap.gui.editor.EditorManager;
 import org.cytoscape.view.vizmap.mappings.ContinuousMapping;
 
-public class C2CEditor extends AbstractContinuousMappingEditor<Number, Number> 
{
+public class C2CEditor<K extends Number, V extends Number> extends 
AbstractContinuousMappingEditor<K, V> {
 
        public C2CEditor(final CyNetworkTableManager manager, final 
CyApplicationManager appManager,
                        final EditorManager editorManager, final 
VisualMappingManager vmm) {
@@ -20,18 +20,16 @@
        public void setValue(Object value) {
                if (value instanceof ContinuousMapping == false)
                        throw new IllegalArgumentException("Value should be 
ContinuousMapping: this is " + value);
+               
                final CyNetwork currentNetwork = appManager.getCurrentNetwork();
                if (currentNetwork == null)
                        return;
 
-               ContinuousMapping<?, ?> mTest = (ContinuousMapping<?, ?>) value;
-
-               // TODO: error chekcing
-               mapping = (ContinuousMapping<Number, Number>) value;
+               mapping = (ContinuousMapping<K, V>) value;
                @SuppressWarnings("unchecked")
                Class<? extends CyIdentifiable> type = (Class<? extends 
CyIdentifiable>) mapping.getVisualProperty()
                                .getTargetDataType();
                final CyTable attr = 
manager.getTable(appManager.getCurrentNetwork(), type, CyNetwork.DEFAULT_ATTRS);
-               this.editorPanel = new 
C2CMappingEditorPanel(vmm.getCurrentVisualStyle(), mapping, attr, appManager, 
vmm);
+               this.editorPanel = new C2CMappingEditorPanel<K, 
V>(vmm.getCurrentVisualStyle(), mapping, attr, appManager, vmm);
        }
 }
\ No newline at end of file

Modified: 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/mappingeditor/C2CMappingEditorPanel.java
===================================================================
--- 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/mappingeditor/C2CMappingEditorPanel.java
       2012-07-09 23:33:16 UTC (rev 29817)
+++ 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/mappingeditor/C2CMappingEditorPanel.java
       2012-07-10 01:50:42 UTC (rev 29818)
@@ -54,26 +54,32 @@
 /**
  * Continuous-Continuous mapping editor.<br>
  * 
+ * This editor will be used for Number-to-Number mapping.
+ * 
  * <p>
  * This is a editor for continuous values, i.e., numbers.
  * </p>
  * 
  */
-public class C2CMappingEditorPanel<V extends Number> extends 
ContinuousMappingEditorPanel<Double, V> {
+public class C2CMappingEditorPanel<K extends Number, V extends Number> extends 
ContinuousMappingEditorPanel<K, V> {
 
        private final static long serialVersionUID = 1213748836613718L;
 
        // Default value for below and above.
-       private final V DEF_BELOW_AND_ABOVE = (V) new Double(1f);
-       private final V FIVE = (V) new Double(5f);
+       private static final Number DEF_BELOW_AND_ABOVE = 1d;
+       private static final Number FIRST_LOCATION = 10d;
+       private static final Number SECOND_LOCATION = 30d;
 
-       private final V FIRST_LOCATION = (V) new Double(10f);
-       private final V SECOND_LOCATION = (V) new Double(30f);
-       
+       private final Class<K> columnType;
+       private final Class<V> vpValueType;
 
-       public C2CMappingEditorPanel(final VisualStyle style, final 
ContinuousMapping<Double, V> mapping, final CyTable attr,
+       public C2CMappingEditorPanel(final VisualStyle style, final 
ContinuousMapping<K, V> mapping, final CyTable attr,
                        final CyApplicationManager appManager, final 
VisualMappingManager vmm) {
                super(style, mapping, attr, appManager, vmm);
+               
+               columnType = mapping.getMappingColumnType();
+               vpValueType = mapping.getVisualProperty().getRange().getType();
+               
                abovePanel.setVisible(false);
                belowPanel.setVisible(false);
 
@@ -87,42 +93,78 @@
 
                setPropertySpinner();
        }
+       
+       private V convertToValue(final Number value) {
+               return convert(vpValueType, value);
+       }
+       
+       private K convertToColumnValue(final Number value) {
+               return convert(columnType, value);
+       }
+       
+       private <T> T convert(final Class<T> type, Number value) {
+               T converted = null;
+               if(type == Double.class) {
+                       Double doubleValue = value.doubleValue();
+                       converted = (T) doubleValue;
+               } else if(type == Integer.class) {
+                       Integer intValue = value.intValue();
+                       converted = (T) intValue;
+               } else if(type == Float.class) {
+                       Float floatValue = value.floatValue();
+                       converted = (T) floatValue;
+               } else if(type == Byte.class) {
+                       Byte byteValue = value.byteValue();
+                       converted = (T) byteValue;
+               } else if(type == Long.class){
+                       Long longValue = value.longValue();
+                       converted = (T) longValue;
+               } else if(type == Short.class) {
+                       Short shortValue = value.shortValue();
+                       converted = (T) shortValue;
+               } else {
+                       throw new IllegalStateException("Could not covert 
Number.");
+               }
+               
+               return converted;
+       }
 
        public ImageIcon getIcon(final int iconWidth, final int iconHeight) {
-
                final TrackRenderer rend = slider.getTrackRenderer();
 
                if (rend instanceof ContinuousTrackRenderer) {
                        rend.getRendererComponent(slider);
 
-                       return ((ContinuousTrackRenderer<Double, V>) 
rend).getTrackGraphicIcon(iconWidth, iconHeight);
+                       return ((ContinuousTrackRenderer) 
rend).getTrackGraphicIcon(iconWidth, iconHeight);
                } else {
                        return null;
                }
        }
 
        public ImageIcon getLegend(final int width, final int height) {
-
-               final ContinuousTrackRenderer<Double, V> rend = 
(ContinuousTrackRenderer<Double, V>) slider.getTrackRenderer();
+               final ContinuousTrackRenderer<K, V> rend = 
(ContinuousTrackRenderer) slider.getTrackRenderer();
                rend.getRendererComponent(slider);
 
                return rend.getLegend(width, height);
        }
 
-       // FIXME
-       // // Add slider to the editor.
-       private void addSlider(Double position, V value) {
-
-               final Double maxValue = tracer.getMax(type);
-
+       
+       /**
+        * Add New Slider to editor
+        * 
+        * @param position
+        * @param value
+        */
+       private void addSlider(Number position, Number value) {
+               final K maxValue = convertToColumnValue(tracer.getMax(type));
                BoundaryRangeValues<V> newRange;
 
                if (mapping.getPointCount() == 0) {
-                       slider.getModel().addThumb(position.floatValue(), 
value);
+                       slider.getModel().addThumb(position.floatValue(), 
convertToValue(value));
 
-                       V five = (V) new Double(5);
-                       newRange = new BoundaryRangeValues<V>(below, five, 
above);
-                       final Double newKey = (maxValue / 2);
+                       newRange = new BoundaryRangeValues<V>(below, 
convertToValue(5d), above);
+                       final K newKey = 
convertToColumnValue((maxValue.doubleValue() / 2));
+                       
                        mapping.addPoint(newKey, newRange);
 
                        slider.repaint();
@@ -132,18 +174,14 @@
                }
 
                // Add a new white thumb in the min.
-               slider.getModel().addThumb(position.floatValue(), value);
+               slider.getModel().addThumb(position.floatValue(), 
convertToValue(value));
 
-               // Update continuous mapping
-               final Double newVal = maxValue;
-
                // Pick Up first point.
-               final ContinuousMappingPoint<Double, V> previousPoint = 
mapping.getPoint(mapping.getPointCount() - 1);
-
+               final ContinuousMappingPoint<K, V> previousPoint = 
mapping.getPoint(mapping.getPointCount() - 1);
                final BoundaryRangeValues<V> previousRange = 
previousPoint.getRange();
 
                V lesserVal = 
slider.getModel().getSortedThumbs().get(slider.getModel().getThumbCount() - 
1).getObject();
-               V equalVal = FIVE;
+               V equalVal = convertToValue(5d);
                V greaterVal = previousRange.greaterValue;
 
                newRange = new BoundaryRangeValues<V>(lesserVal, equalVal, 
greaterVal);
@@ -160,7 +198,7 @@
 
        @Override
        protected void addButtonActionPerformed(ActionEvent evt) {
-               addSlider(100d, FIVE);
+               addSlider(100d, convertToValue(5d));
        }
 
        @Override
@@ -184,19 +222,19 @@
 
                slider.updateUI();
 
-               final double minValue = tracer.getMin(type);
-               double actualRange = tracer.getRange(type);
+               final Number minValue = tracer.getMin(type);
+               Number actualRange = tracer.getRange(type);
 
                BoundaryRangeValues<V> bound;
-               Double fraction;
+               Number fraction;
 
                if (allPoints == null)
                        return;
 
-               for (ContinuousMappingPoint<Double, V> point : allPoints) {
+               for (ContinuousMappingPoint<K, V> point : allPoints) {
                        bound = point.getRange();
 
-                       fraction = ((Number) ((point.getValue() - minValue) / 
actualRange)).floatValue() * 100d;
+                       fraction = ((Number) ((point.getValue().doubleValue() - 
minValue.doubleValue()) / actualRange.doubleValue())).floatValue() * 100d;
                        slider.getModel().addThumb(fraction.floatValue(), 
bound.equalValue);
                }
 
@@ -204,8 +242,8 @@
                        below = allPoints.get(0).getRange().lesserValue;
                        above = allPoints.get(allPoints.size() - 
1).getRange().greaterValue;
                } else {
-                       below = DEF_BELOW_AND_ABOVE;
-                       above = DEF_BELOW_AND_ABOVE;
+                       below = convertToValue(DEF_BELOW_AND_ABOVE);
+                       above = convertToValue(DEF_BELOW_AND_ABOVE);
                }
 
                /*
@@ -213,7 +251,7 @@
                 */
                TriangleThumbRenderer thumbRend = new TriangleThumbRenderer();
 
-               ContinuousTrackRenderer<Double, V> cRend = new 
ContinuousTrackRenderer<Double, V>(style, mapping, below, above,
+               ContinuousTrackRenderer<K, V> cRend = new 
ContinuousTrackRenderer<K, V>(style, mapping, below, above,
                                tracer, appManager);
                cRend.addPropertyChangeListener(this);
 
@@ -224,9 +262,9 @@
 
        public void propertyChange(PropertyChangeEvent evt) {
                if 
(evt.getPropertyName().equals(ContinuousMappingEditorPanel.BELOW_VALUE_CHANGED))
 {
-                       below = (V) evt.getNewValue();
+                       below = convertToValue((Number)evt.getNewValue());
                } else if 
(evt.getPropertyName().equals(ContinuousMappingEditorPanel.ABOVE_VALUE_CHANGED))
 {
-                       above = (V) evt.getNewValue();
+                       above = convertToValue((Number)evt.getNewValue());
                }
        }
 
@@ -237,7 +275,7 @@
                if (rend instanceof ContinuousTrackRenderer) {
                        rend.getRendererComponent(slider);
 
-                       return ((ContinuousTrackRenderer<Double, V>) 
rend).getTrackGraphicIcon(iconWidth, iconHeight);
+                       return ((ContinuousTrackRenderer) 
rend).getTrackGraphicIcon(iconWidth, iconHeight);
                } else {
                        return null;
                }
@@ -261,10 +299,10 @@
 
                public void stateChanged(ChangeEvent e) {
                        
-                       final Double newVal = 
spinnerModel.getNumber().doubleValue();
+                       final Number newVal = 
spinnerModel.getNumber().doubleValue();
                        final int selectedIndex = slider.getSelectedIndex();
 
-                       
slider.getModel().getThumbAt(selectedIndex).setObject((V) newVal);
+                       
slider.getModel().getThumbAt(selectedIndex).setObject(convertToValue(newVal));
 
                        updateMap();
                        style.apply(appManager.getCurrentNetworkView());

Modified: 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/mappingeditor/ContinuousMappingEditorPanel.java
===================================================================
--- 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/mappingeditor/ContinuousMappingEditorPanel.java
        2012-07-09 23:33:16 UTC (rev 29817)
+++ 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/mappingeditor/ContinuousMappingEditorPanel.java
        2012-07-10 01:50:42 UTC (rev 29818)
@@ -78,9 +78,6 @@
  * Abstract class for all Continuous Mapping Editors. This is the mapping from
  * Number to visual property value.
  * 
- * @param T
- *            type of the value associated with the thumb.
- * 
  */
 public abstract class ContinuousMappingEditorPanel<K extends Number, V> 
extends JPanel implements
                PropertyChangeListener {
@@ -102,7 +99,6 @@
        protected final ContinuousMapping<K, V> mapping;
        protected final VisualProperty<V> type;
        private final CyTable dataTable;
-       private final Class<K> dataType;
 
        protected List<ContinuousMappingPoint<K, V>> allPoints;
        private SpinnerNumberModel spinnerModel;
@@ -161,8 +157,6 @@
                        throw new IllegalArgumentException("Cannot support 
attribute data type.  Numerical values only: "
                                        + attrType);
                
-               this.dataType = (Class<K>) attrType;
-               
                initComponents();
                initRangeValues();
                setSpinner();

Modified: 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/event/CellEditorEventHandler.java
===================================================================
--- 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/event/CellEditorEventHandler.java
     2012-07-09 23:33:16 UTC (rev 29817)
+++ 
core3/impl/trunk/vizmap-gui-impl/src/main/java/org/cytoscape/view/vizmap/gui/internal/event/CellEditorEventHandler.java
     2012-07-10 01:50:42 UTC (rev 29818)
@@ -252,17 +252,17 @@
                // Remove old property
                propertySheetPanel.removeProperty(prop);
 
-               // Create new one.
-               logger.debug("Creating new prop sheet objects for " + 
newMapping.getMappingColumnName() + ", "
-                               + vp.getDisplayName());
-
+               
+               
+               
+               
+               // Create new Property.
                final VisualProperty<Visualizable> category = 
util.getCategory((Class<? extends CyIdentifiable>) vp
                                .getTargetDataType());
                VizMapperProperty<VisualProperty<V>, String, ?> newRootProp = 
vizMapPropertySheetBuilder.getPropertyBuilder()
                                .buildProperty(newMapping, 
category.getDisplayName(), propertySheetPanel, factory);
 
                vizMapPropertySheetBuilder.removeProperty(prop, currentStyle);
-
                final List<Property> propList = 
vizMapPropertySheetBuilder.getPropertyList(currentStyle);
                propList.add(newRootProp);
 

-- 
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.

Reply via email to