Logo Search packages:      
Sourcecode: josm-plugins version File versions  Download package

Test.java

package org.openstreetmap.josm.plugins.validator;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.swing.JCheckBox;
import javax.swing.JPanel;

import org.openstreetmap.josm.command.Command;
import org.openstreetmap.josm.data.osm.*;
import org.openstreetmap.josm.data.osm.visitor.Visitor;
import org.openstreetmap.josm.tools.GBC;

/**
 * Parent class for all validation tests.
 * <p>
 * A test is a primitive visitor, so that it can access to all data to be
 * validated. These primitives are always visited in the same order: nodes
 * first, then ways.
 * 
 * @author frsantos
 */
00026 public class Test implements Visitor
{
      /** Name of the test */
00029       protected String name;
      
      /** Description of the test */
00032       protected String description;
      
    /** Whether this test is enabled. Enabled by default */
00035     protected boolean enabled = true;

    /** The preferences check for validation */
00038     protected JCheckBox checkEnabled;

    /** The preferences check for validation on upload */
00041     protected JCheckBox checkBeforeUpload;
    
    /** Whether this test must check before upload. Enabled by default */
00044     protected boolean testBeforeUpload = true;

    /** Whether this test is performing just before an upload */
00047     protected boolean isBeforeUpload;

      /** The list of errors */
00050       protected List<TestError> errors = new ArrayList<TestError>(30);

      /** Whether the test is run on a partial selection data */
00053       protected boolean partialSelection;

      /**
       * Constructor
       * @param name Name of the test
       * @param description Description of the test
       */
00060       public Test(String name, String description)
      {
            this.name = name;
            this.description = description;
      }
      
      /**
       * Constructor
       * @param name Name of the test
       */
00070       public Test(String name)
      {
            this.name = name;
      }
      
      /**
       * Initializes any global data used this tester.
       * @param plugin The plugin
       * @throws Exception When cannot initialize the test
       */ 
00080       public static void initialize(@SuppressWarnings("unused") OSMValidatorPlugin plugin) throws Exception {}
      
      /**
       * Notification of the start of the test. The tester can initialize the
       * structures it may need for this test
       */ 
00086       public void startTest() 
      {
            errors = new ArrayList<TestError>(30);
      }

      /**
       * Flag notifying that this test is run over a partial data selection
       * @param partialSelection Whether the test is on a partial selection data
       */ 
00095       public void setPartialSelection(boolean partialSelection) 
      {
            this.partialSelection = partialSelection;
      }
      
      /**
       * Gets the validation errors accumulated until this moment.
       * @return The list of errors 
       */
00104       public List<TestError> getErrors() 
      {
            return errors;
      }
      
      /**
       * Notification of the end of the test. The tester may perform additional
       * actions and destroy the used structures 
       */
00113       public void endTest() {}

    /**
     * Visits all primitives to be tested. These primitives are always visited
     * in the same order: nodes first, then ways.
     * 
     * @param selection The primitives to be tested
     */
00121     public void visit(Collection<OsmPrimitive> selection) 
    {
        for (OsmPrimitive p : selection)
        {
            if( !p.deleted || !p.incomplete )
                  p.visit(this);
        }
    }

    public void visit(Node n) {}

      public void visit(Way w) {}

      public void visit(Relation r) {}

      /**
       * Allow the tester to manage its own preferences 
       * @param testPanel The panel to add any preferences component
       */
00140       public void addGui(@SuppressWarnings("unused") JPanel testPanel) 
      {
            checkEnabled = new JCheckBox(name, enabled);
            checkEnabled.setToolTipText(description);
            testPanel.add(checkEnabled, GBC.std().insets(20,0,0,0));
            
        checkBeforeUpload = new JCheckBox();
        checkBeforeUpload.setSelected(testBeforeUpload);
        testPanel.add(checkBeforeUpload, GBC.eop().insets(20,0,0,0));
      }

      /**
       * Called when the used submits the preferences
       */
00154       public void ok() 
      {
            enabled = checkEnabled.isSelected();
            testBeforeUpload = checkBeforeUpload.isSelected();
      }
      
      /**
       * Fixes the error with the appropiate command
       * 
       * @param testError
       * @return The command to fix the error
       */
00166       public Command fixError(@SuppressWarnings("unused") TestError testError)
      {
            return null;
      }
      
      /**
       * Returns true if the given error can be fixed automatically
       * 
       * @param testError The error to check if can be fixed
       * @return true if the error can be fixed
       */
00177       public boolean isFixable(@SuppressWarnings("unused") TestError testError)
      {
            return false;
      }

    /**
     * Returns true if this plugin must check the uploaded data before uploading
     * @return true if this plugin must check the uploaded data before uploading
     */
00186     public boolean testBeforeUpload()
    {
        return testBeforeUpload;
    }

    /**
     * Sets the flag that marks an upload check
     * @param isUpload if true, the test is before upload
     */
00195     public void setBeforeUpload(boolean isUpload)
    {
        this.isBeforeUpload = isUpload;
    }
}

Generated by  Doxygen 1.6.0   Back to index