Revision: 5105
          http://sourceforge.net/p/jump-pilot/code/5105
Author:   michaudm
Date:     2016-10-25 22:06:36 +0000 (Tue, 25 Oct 2016)
Log Message:
-----------
Generify AbstractMultiInputDialog

Modified Paths:
--------------
    core/trunk/src/com/vividsolutions/jump/workbench/model/LayerManager.java
    
core/trunk/src/com/vividsolutions/jump/workbench/ui/AbstractMultiInputDialog.java
    
core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/analysis/CalculateAreasAndLengthsPlugIn.java
    core/trunk/src/de/latlon/deejump/plugin/style/DeeChangeStylesPlugIn.java
    
core/trunk/src/org/openjump/core/ui/plugin/layer/pirolraster/ChangeRasterImagePropertiesPlugIn.java
    
core/trunk/src/org/openjump/core/ui/plugin/tools/AutoAssignAttributePlugIn.java
    core/trunk/src/org/openjump/core/ui/plugin/wms/WMSStylePlugIn.java

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/model/LayerManager.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/model/LayerManager.java    
2016-10-25 21:29:10 UTC (rev 5104)
+++ core/trunk/src/com/vividsolutions/jump/workbench/model/LayerManager.java    
2016-10-25 22:06:36 UTC (rev 5105)
@@ -726,7 +726,7 @@
         return null;
     }
 
-    public List getLayers() {
+    public List<Layer> getLayers() {
         return getLayerables(Layer.class);
     }
 

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/ui/AbstractMultiInputDialog.java
===================================================================
--- 
core/trunk/src/com/vividsolutions/jump/workbench/ui/AbstractMultiInputDialog.java
   2016-10-25 21:29:10 UTC (rev 5104)
+++ 
core/trunk/src/com/vividsolutions/jump/workbench/ui/AbstractMultiInputDialog.java
   2016-10-25 22:06:36 UTC (rev 5105)
@@ -43,9 +43,7 @@
 import com.vividsolutions.jts.util.Assert;
 
 import com.vividsolutions.jump.I18N;
-import com.vividsolutions.jump.feature.AttributeType;
 import com.vividsolutions.jump.feature.FeatureSchema;
-import com.vividsolutions.jump.workbench.ui.LayerNameRenderer;
 import com.vividsolutions.jump.workbench.model.Layer;
 import com.vividsolutions.jump.workbench.model.LayerManager;
 import com.vividsolutions.jump.workbench.model.Layerable;
@@ -180,7 +178,7 @@
     protected HashMap<String,JComponent> fieldNameToComponentMap = new 
HashMap<String,JComponent>();
     
     // Map containing associations between field names and their label
-    protected HashMap fieldNameToLabelMap = new HashMap();
+    protected HashMap<String,JComponent> fieldNameToLabelMap = new HashMap<>();
     
     // Map containing associations between field names and ButtonGroup
     protected Map buttonGroupMap = new HashMap();
@@ -189,7 +187,7 @@
     protected CollectionMap fieldNameToEnableCheckListMap = new 
CollectionMap();
 
     private JComponent getComponent(String fieldName) {
-        return (JComponent) fieldNameToComponentMap.get(fieldName);
+        return fieldNameToComponentMap.get(fieldName);
     }
     
     
@@ -203,7 +201,7 @@
      * Gets JLabel matching this fieldName.
      */
     public JComponent getLabel(String fieldName) {
-        return (JComponent) fieldNameToLabelMap.get(fieldName);
+        return fieldNameToLabelMap.get(fieldName);
     }
     
     /**
@@ -239,7 +237,7 @@
      * Gets the string value of a control
      * @param fieldName control to read
      * @return the string value of the control
-     * @return null if the control is not in a valid state (e.g. not selected)
+     *         null if the control is not in a valid state (e.g. not selected)
      */
     public String getText(String fieldName) {
         Component component = fieldNameToComponentMap.get(fieldName);
@@ -339,9 +337,13 @@
      * @param fieldName fieldName of the control
      * @param enableChecks EnableCheck array to validate this control input
      */
-    public void addEnableChecks(String fieldName, Collection enableChecks) {
+    public void addEnableChecks(String fieldName, Collection<? extends 
EnableCheck> enableChecks) {
         fieldNameToEnableCheckListMap.addItems(fieldName, enableChecks);
     }
+
+    public void addEnableChecks(String fieldName, EnableCheck...enableChecks) {
+        fieldNameToEnableCheckListMap.addItems(fieldName, 
Arrays.asList(enableChecks));
+    }
     
     
     
////////////////////////////////////////////////////////////////////////////
@@ -381,11 +383,11 @@
      * @param toolTipText tool tip to help the user
      * @return the JComboBox control added to this dialog
      */
-    public JComboBox addComboBox(String fieldName,
+    public <T> JComboBox<T> addComboBox(String fieldName,
                                  Object selectedItem,
-                                 Collection items,
+                                 Collection<T> items,
                                  String toolTipText) {
-        final JComboBox comboBox = new JComboBox(new Vector(items));
+        final JComboBox<T> comboBox = new JComboBox<>(new Vector<>(items));
         comboBox.setSelectedItem(selectedItem);
         addRow(fieldName, new JLabel(fieldName), comboBox, null, toolTipText, 
LEFT_LABEL, NONE);
         return comboBox;
@@ -425,7 +427,7 @@
      * Action associated to this JButton must be defined.
      * @param fieldName will be used for the label text on the left of the 
button 
      * @param text text to display in the JButton
-     * @param toolTipText
+     * @param toolTipText tooltip text associated to the JButton
      * @return the JButton added to this dialog
      */
     public JButton addButton(String fieldName, String text, String 
toolTipText) {
@@ -661,17 +663,18 @@
      * @param layers layers to be proposed in the combo box
      * @return the JComboBox
      */
-    public JComboBox addLayerComboBox(String fieldName,
+    public JComboBox<Layer> addLayerComboBox(String fieldName,
                                       Layer initialValue,
                                       String toolTipText,
-                                      Collection layers) {
-        JComboBox comboBox = addComboBox(fieldName, initialValue, layers, 
toolTipText);
+                                      Collection<Layer> layers) {
+        JComboBox<Layer> comboBox = addComboBox(fieldName, initialValue, 
layers, toolTipText);
         LayerNameRenderer layerListCellRenderer = new LayerNameRenderer();
         layerListCellRenderer.setCheckBoxVisible(false);
         layerListCellRenderer.setProgressIconLabelVisible(false);
         comboBox.setRenderer(layerListCellRenderer);
         comboBox.invalidate();
-        return getComboBox(fieldName);
+        //return getComboBox(fieldName);
+        return comboBox;
     }
     
     
@@ -738,8 +741,8 @@
                                       String toolTipText,
                                       LayerManager layerManager,
                                       AttributeTypeFilter filter) {
-        List<Layer> layerList = new ArrayList<Layer>();
-        for (Layer layer : (List<Layer>)layerManager.getLayers()) {
+        List<Layer> layerList = new ArrayList<>();
+        for (Layer layer : layerManager.getLayers()) {
             FeatureSchema schema = 
layer.getFeatureCollectionWrapper().getFeatureSchema();
             if (filter.filter(schema).size() > 0) layerList.add(layer);
         }
@@ -753,19 +756,20 @@
      * @param fieldName field name for the attribute
      * @param layerFieldName field name of the ComboBox used to choose the 
layer
      * @param filter filter valid attributes from their type
-     * @param toolTipText
+     * @param toolTipText a toolTip for this JComboBox
      * @return the JComboBox
      */
-    public JComboBox addAttributeComboBox(final String fieldName,
+    public JComboBox<String> addAttributeComboBox(final String fieldName,
                                           final String layerFieldName,
                                           final AttributeTypeFilter filter,
                                           final String toolTipText) {
         
         final JComboBox layerComboBox = getComboBox(layerFieldName);
         
-        final JComboBox attributeComboBox = addComboBox(fieldName, null, new 
ArrayList(), toolTipText);
+        final JComboBox<String> attributeComboBox =
+                addComboBox(fieldName, null, new ArrayList<String>(), 
toolTipText);
         
-        final ComboBoxModel DEFAULT = new DefaultComboBoxModel(new String[]{
+        final ComboBoxModel<String> DEFAULT = new DefaultComboBoxModel<>(new 
String[]{
             NO_VALID_ATTRIBUTE
         });
         
@@ -774,7 +778,7 @@
             FeatureSchema schema = 
layer.getFeatureCollectionWrapper().getFeatureSchema();
             List<String> attributes = filter.filter(schema);
             if (attributes.size() > 0) {
-                attributeComboBox.setModel(new DefaultComboBoxModel(
+                attributeComboBox.setModel(new DefaultComboBoxModel<>(
                     attributes.toArray(new String[attributes.size()])));
             }
             else attributeComboBox.setModel(DEFAULT);
@@ -788,7 +792,7 @@
                 List<String> attributes = filter.filter(schema);
                 if (attributes.size() > 0) {
                     String oldAttr = 
(String)attributeComboBox.getSelectedItem();
-                    attributeComboBox.setModel(new DefaultComboBoxModel(
+                    attributeComboBox.setModel(new DefaultComboBoxModel<>(
                         attributes.toArray(new String[attributes.size()])));
                     if (attributes.contains(oldAttr)) {
                         attributeComboBox.setSelectedItem(oldAttr);

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/analysis/CalculateAreasAndLengthsPlugIn.java
===================================================================
--- 
core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/analysis/CalculateAreasAndLengthsPlugIn.java
     2016-10-25 21:29:10 UTC (rev 5104)
+++ 
core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/analysis/CalculateAreasAndLengthsPlugIn.java
     2016-10-25 22:06:36 UTC (rev 5105)
@@ -188,23 +188,18 @@
         return getClass().getName() + " - ";
     }
     private void initEnableChecks(final MultiInputDialog dialog) {
-        dialog
-            .addEnableChecks(
-                LENGTH_COMBO_BOX,
-                Arrays
-                    .asList(
-                        new Object[] {
-                            new EnableCheck() {
-                                public String check(JComponent component) {
-                                return dialog.getBoolean(AREA_CHECK_BOX)
-                                    && dialog.getBoolean(LENGTH_CHECK_BOX)
-                                    && dialog.getText(AREA_COMBO_BOX).equals(
-                                        dialog.getText(LENGTH_COMBO_BOX))
+        dialog.addEnableChecks(
+                LENGTH_COMBO_BOX, new EnableCheck() {
+                    public String check(JComponent component) {
+                        return dialog.getBoolean(AREA_CHECK_BOX)
+                                && dialog.getBoolean(LENGTH_CHECK_BOX)
+                                && dialog.getText(AREA_COMBO_BOX).equals(
+                                    dialog.getText(LENGTH_COMBO_BOX))
                                         ? 
I18N.get("ui.plugin.analysis.CalculateAreasAndLengthsPlugIn.area-and-length-attribute-names-must-be-different")
                                         : null;
                 }
             }
-        }));
+        );
     }
     private String attributeName(List attributeNames, int preferredIndex) {
         return (String) attributeNames.get(
@@ -248,19 +243,15 @@
         dialog
             .addEnableChecks(
                 comboBoxFieldName,
-                Arrays
-                    .asList(
-                        new Object[] {
-                            new EnableCheck() {
-                                public String check(JComponent component) {
-                                return dialog.getBoolean(checkBoxFieldName)
-                                    && 
dialog.getComboBox(comboBoxFieldName).getItemCount()
-                                        == 0
+                    new EnableCheck() {
+                        public String check(JComponent component) {
+                            return dialog.getBoolean(checkBoxFieldName)
+                                    && 
dialog.getComboBox(comboBoxFieldName).getItemCount() == 0
                                         ? "Layer has no string, integer, or 
double attributes"
                                         : null;
                 }
             }
-        }));
+        );
         dialog.indentLabel(comboBoxFieldName);
     }
     private Layer candidateLayer(PlugInContext context) {

Modified: 
core/trunk/src/de/latlon/deejump/plugin/style/DeeChangeStylesPlugIn.java
===================================================================
--- core/trunk/src/de/latlon/deejump/plugin/style/DeeChangeStylesPlugIn.java    
2016-10-25 21:29:10 UTC (rev 5104)
+++ core/trunk/src/de/latlon/deejump/plugin/style/DeeChangeStylesPlugIn.java    
2016-10-25 22:06:36 UTC (rev 5105)
@@ -146,11 +146,11 @@
 
         for (final StylePanel stylePanel : stylePanels) {
             tabbedPane.add((Component) stylePanel, stylePanel.getTitle());
-            dialog.addEnableChecks(stylePanel.getTitle(), Arrays.asList(new 
EnableCheck() {
+            dialog.addEnableChecks(stylePanel.getTitle(), new EnableCheck() {
                 public String check(JComponent component) {
                     return stylePanel.validateInput();
                 }
-            }));
+            });
         }
 
         dialog.addRow(tabbedPane);

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/layer/pirolraster/ChangeRasterImagePropertiesPlugIn.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/layer/pirolraster/ChangeRasterImagePropertiesPlugIn.java
 2016-10-25 21:29:10 UTC (rev 5104)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/layer/pirolraster/ChangeRasterImagePropertiesPlugIn.java
 2016-10-25 22:06:36 UTC (rev 5105)
@@ -127,11 +127,11 @@
                         ((StylePanel) tabbedPane.getSelectedComponent())
                                 .getTitle());
         dialog.addEnableChecks(rasterScalepanel.getTitle(),
-                Arrays.asList(new EnableCheck() {
+                new EnableCheck() {
                     public String check(JComponent component) {
                         return rasterScalepanel.validateInput();
                     }
-                }));
+                });
   /*      dialog.addOKCancelApplyPanelActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 if (dialog.wasApplyPressed()) {

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/tools/AutoAssignAttributePlugIn.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/tools/AutoAssignAttributePlugIn.java 
    2016-10-25 21:29:10 UTC (rev 5104)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/tools/AutoAssignAttributePlugIn.java 
    2016-10-25 22:06:36 UTC (rev 5105)
@@ -268,7 +268,7 @@
     
     private void initEnableChecks(final MultiInputDialog dialog) {
         dialog.addEnableChecks(SOURCE_COMBO_BOX,
-            Arrays.asList(new Object[] {new EnableCheck() {
+            Arrays.asList(new EnableCheck[] {new EnableCheck() {
                 public String check(JComponent component) {
                     return assignFromSource && 
                            dialog.getText(TARGET_ATTRIBUTE_COMBO_BOX)

Modified: core/trunk/src/org/openjump/core/ui/plugin/wms/WMSStylePlugIn.java
===================================================================
--- core/trunk/src/org/openjump/core/ui/plugin/wms/WMSStylePlugIn.java  
2016-10-25 21:29:10 UTC (rev 5104)
+++ core/trunk/src/org/openjump/core/ui/plugin/wms/WMSStylePlugIn.java  
2016-10-25 22:06:36 UTC (rev 5105)
@@ -96,11 +96,11 @@
         dialog.setApplyVisible(true);
 
         dialog.addEnableChecks(panel.getTitle(),
-                Arrays.asList(new EnableCheck() {
+                new EnableCheck() {
                     public String check(JComponent component) {
                         return panel.validateInput();
                     }
-                }));
+                });
 
         dialog.addOKCancelApplyPanelActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {


------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive. 
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to