Exemplo n.º 1
0
 /* shamelessly copied from PlugInManager */
 private static Class toClass(ZipEntry entry, ClassLoader classLoader) {
   if (entry.isDirectory()) {
     return null;
   }
   if (!entry.getName().endsWith(".class")) {
     return null;
   }
   if (entry.getName().indexOf("$") != -1) {
     // I assume it's not necessary to load inner classes explicitly.
     // [Jon Aquino]
     return null;
   }
   String className = entry.getName();
   className = className.substring(0, className.length() - ".class".length());
   className = StringUtil.replaceAll(className, "/", ".");
   Class candidate;
   try {
     candidate = classLoader.loadClass(className);
   } catch (ClassNotFoundException e) {
     Assert.shouldNeverReachHere(
         "Class not found: " + className + ". Refine class name algorithm.");
     return null;
   } catch (Throwable t) {
     LOG.error("Throwable encountered loading " + className + ":");
     // e.g. java.lang.VerifyError: class
     // org.apache.xml.serialize.XML11Serializer
     // overrides final method [Jon Aquino]
     t.printStackTrace(System.out);
     return null;
   }
   return candidate;
 }
Exemplo n.º 2
0
  /**
   * Extract the coordinate arrays for a geometry into a List.
   *
   * @param g the Geometry to extract from
   * @param coordArrayList the List to add the coordinate arrays to
   * @param orientPolygons whether or not the arrays in the List should be oriented (clockwise for
   *     the shell, counterclockwise for the holes)
   */
  public static void addCoordinateArrays(Geometry g, boolean orientPolygons, List coordArrayList) {
    if (g.getDimension() <= 0) {
      return;
    } else if (g instanceof LineString) {
      LineString l = (LineString) g;
      coordArrayList.add(l.getCoordinates());
    } else if (g instanceof Polygon) {
      Polygon poly = (Polygon) g;
      Coordinate[] shell = poly.getExteriorRing().getCoordinates();

      if (orientPolygons) {
        shell = ensureOrientation(shell, CGAlgorithms.CLOCKWISE);
      }

      coordArrayList.add(shell);

      for (int i = 0; i < poly.getNumInteriorRing(); i++) {
        Coordinate[] hole = poly.getInteriorRingN(i).getCoordinates();

        if (orientPolygons) {
          hole = ensureOrientation(hole, CGAlgorithms.COUNTERCLOCKWISE);
        }

        coordArrayList.add(hole);
      }
    } else if (g instanceof GeometryCollection) {
      GeometryCollection gc = (GeometryCollection) g;

      for (int i = 0; i < gc.getNumGeometries(); i++) {
        addCoordinateArrays(gc.getGeometryN(i), orientPolygons, coordArrayList);
      }
    } else {
      Assert.shouldNeverReachHere("Geometry of type " + g.getClass().getName() + " not handled");
    }
  }
Exemplo n.º 3
0
 public TestCase(
     String name,
     String description,
     String wkta,
     String wktb,
     String expectedIM,
     String expectedConvexHull,
     String expectedIntersection,
     String expectedUnion,
     String expectedDifference,
     String expectedSymDifference,
     String expectedBoundary) {
   try {
     init(
         name,
         description,
         wkta,
         wktb,
         expectedIM,
         toNullOrGeometry(expectedConvexHull),
         toNullOrGeometry(expectedIntersection),
         toNullOrGeometry(expectedUnion),
         toNullOrGeometry(expectedDifference),
         toNullOrGeometry(expectedSymDifference),
         toNullOrGeometry(expectedBoundary));
   } catch (ParseException e) {
     Assert.shouldNeverReachHere();
   }
 }
Exemplo n.º 4
0
 public TestCase setExpectedBoundary(String wkt) {
   try {
     this.expectedBoundary = toNullOrGeometry(wkt);
   } catch (ParseException e) {
     Assert.shouldNeverReachHere();
   }
   return this;
 }
Exemplo n.º 5
0
 public static Object newInstance(Class c) {
   try {
     return c.newInstance();
   } catch (Exception e) {
     Assert.shouldNeverReachHere(e.toString());
     return null;
   }
 }
Exemplo n.º 6
0
 /**
  * Devuelve las extensiones que reconoce la clase ReaderWriter especificada (que no es mas que un
  * wrapper de 1 JumpReader y 1 JumpWriter)
  *
  * @param readerWriterDataSourceClass
  * @return extensiones que reconoce
  */
 public static String[] extensions(Class readerWriterDataSourceClass) {
   try {
     return ((StandardReaderWriterFileDataSource) readerWriterDataSourceClass.newInstance())
         .getExtensions();
   } catch (Exception e) {
     Assert.shouldNeverReachHere(e.toString());
     return null;
   }
 }
Exemplo n.º 7
0
 /* shamelessly copied from PlugInManager */
 private static URL[] toURLs(File[] files) {
   URL[] urls = new URL[files.length];
   for (int i = 0; i < files.length; i++) {
     try {
       System.out.println("path: " + files[i].getPath());
       urls[i] = new URL("jar:file:" + files[i].getPath() + "!/");
     } catch (MalformedURLException e) {
       Assert.shouldNeverReachHere(e.toString());
     }
   }
   return urls;
 }
Exemplo n.º 8
0
 public String getTestXML(Testable testable) {
   if (testable instanceof TestCase) {
     return getTestXML((TestCase) testable);
   }
   if (testable instanceof TestCaseEdit) {
     return getTestXML(((TestCaseEdit) testable).getTestable());
   }
   if (testable instanceof TestRunnerTestCaseAdapter) {
     return getTestXML((TestRunnerTestCaseAdapter) testable);
   }
   Assert.shouldNeverReachHere();
   return null;
 }
 private int row(Object attributeValue) {
   for (int i = 0; i < stylePanel.tableModel().getRowCount(); i++) {
     Object otherAttributeValue =
         stylePanel.tableModel().getValueAt(i, ColorThemingTableModel.ATTRIBUTE_COLUMN);
     if (attributeValue == null && otherAttributeValue == null) {
       return i;
     }
     if (attributeValue != null && attributeValue.equals(otherAttributeValue)) {
       return i;
     }
   }
   Assert.shouldNeverReachHere();
   return -1;
 }
Exemplo n.º 10
0
 public ConstraintsOptionsPanel(WorkbenchContext workbenchContext) {
   this.workbenchContext = workbenchContext;
   try {
     this.jbInit();
     this.init();
   } catch (Exception e) {
     Assert.shouldNeverReachHere(e.toString());
   }
   relativeAngleRadioButton.addItemListener(
       new ItemListener() {
         @Override
         public void itemStateChanged(ItemEvent e) {
           if (start) {
             SettingOptionsDialog.page.fireButtonEvent(
                 ButtonEvent.ENABLE_BUTTON, ButtonNames.APPLY);
           }
         }
       });
   lengthCheckBox.addItemListener(
       new ItemListener() {
         @Override
         public void itemStateChanged(ItemEvent e) {
           updateEnabled();
         }
       });
   constrainIncrementalAngleCheckBox.addItemListener(
       new ItemListener() {
         public void itemStateChanged(ItemEvent e) {
           updateEnabled();
         }
       });
   constrainAngleCheckBox.addItemListener(
       new ItemListener() {
         public void itemStateChanged(ItemEvent e) {
           updateEnabled();
         }
       });
   numPartsTextField.addFocusListener(
       new myFocusListener() {
         public void focusLost(FocusEvent e) {
           double newAngle = 360.0 / Double.parseDouble(numPartsTextField.getText());
           // constrainIncrementalAngleCheckBox.setText("Constrain angle to " + newAngle + " degree
           // increments");
           // [sstein: 16.10.2005]
           constrainIncrementalAngleCheckBox.setText(
               constrainAngleByStepsOf + " " + newAngle + " " + degree);
         }
       });
 }
Exemplo n.º 11
0
 private void query(Object searchBounds, AbstractNode node, ItemVisitor visitor) {
   List childBoundables = node.getChildBoundables();
   for (int i = 0; i < childBoundables.size(); i++) {
     Boundable childBoundable = (Boundable) childBoundables.get(i);
     if (!getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds)) {
       continue;
     }
     if (childBoundable instanceof AbstractNode) {
       query(searchBounds, (AbstractNode) childBoundable, visitor);
     } else if (childBoundable instanceof ItemBoundable) {
       visitor.visitItem(((ItemBoundable) childBoundable).getItem());
     } else {
       Assert.shouldNeverReachHere();
     }
   }
 }
Exemplo n.º 12
0
 private List itemsTree(AbstractNode node) {
   List valuesTreeForNode = new ArrayList();
   for (Iterator i = node.getChildBoundables().iterator(); i.hasNext(); ) {
     Boundable childBoundable = (Boundable) i.next();
     if (childBoundable instanceof AbstractNode) {
       List valuesTreeForChild = itemsTree((AbstractNode) childBoundable);
       // only add if not null (which indicates an item somewhere in this tree
       if (valuesTreeForChild != null) valuesTreeForNode.add(valuesTreeForChild);
     } else if (childBoundable instanceof ItemBoundable) {
       valuesTreeForNode.add(((ItemBoundable) childBoundable).getItem());
     } else {
       Assert.shouldNeverReachHere();
     }
   }
   if (valuesTreeForNode.size() <= 0) return null;
   return valuesTreeForNode;
 }
Exemplo n.º 13
0
 private URL[] toURLs(Collection<File> files) {
   URL[] urls = new URL[files.size()];
   int i = 0;
   for (File file : files) {
     try {
       // TODO: if "jar:file:" not explicitely defined VertexSymbols Extensions die with
       //       "java.lang.SecurityException: sealing violation: can't seal package <>: already
       // loaded"
       // [ede 05.2012]
       urls[i++] =
           file.isFile() ? new URL("jar:file:" + file.getPath() + "!/") : file.toURI().toURL();
     } catch (MalformedURLException e) {
       Assert.shouldNeverReachHere(e.toString());
     }
   }
   return urls;
 }
Exemplo n.º 14
0
  public SnapOptionsPanel(Blackboard blackboard) {
    this.blackboard = blackboard;

    try {
      jbInit();
    } catch (Exception e) {
      Assert.shouldNeverReachHere(e.toString());
    }

    buttonGroup.add(showGridDotsRadioButton);
    buttonGroup.add(showGridLinesRadioButton);
    snapToFeaturesCheckBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            updateEnabled();
          }
        });
  }
Exemplo n.º 15
0
  /**
   * Build an appropriate <code>Geometry</code>, <code>MultiGeometry</code>, or <code>
   * GeometryCollection</code> to contain the <code>Geometry</code>s in it. For example:<br>
   *
   * <ul>
   *   <li>If <code>geomList</code> contains a single <code>Polygon</code>, the <code>Polygon</code>
   *       is returned.
   *   <li>If <code>geomList</code> contains several <code>Polygon</code>s, a <code>MultiPolygon
   *       </code> is returned.
   *   <li>If <code>geomList</code> contains some <code>Polygon</code>s and some <code>LineString
   *       </code>s, a <code>GeometryCollection</code> is returned.
   *   <li>If <code>geomList</code> is empty, an empty <code>GeometryCollection</code> is returned
   * </ul>
   *
   * Note that this method does not "flatten" Geometries in the input, and hence if any
   * MultiGeometries are contained in the input a GeometryCollection containing them will be
   * returned.
   *
   * @param geomList the <code>Geometry</code>s to combine
   * @return a <code>Geometry</code> of the "smallest", "most type-specific" class that can contain
   *     the elements of <code>geomList</code> .
   */
  public Geometry buildGeometry(Collection geomList) {

    /** Determine some facts about the geometries in the list */
    Class geomClass = null;
    boolean isHeterogeneous = false;
    boolean hasGeometryCollection = false;
    for (Iterator i = geomList.iterator(); i.hasNext(); ) {
      Geometry geom = (Geometry) i.next();
      Class partClass = geom.getClass();
      if (geomClass == null) {
        geomClass = partClass;
      }
      if (partClass != geomClass) {
        isHeterogeneous = true;
      }
      if (geom instanceof GeometryCollection) hasGeometryCollection = true;
    }

    /** Now construct an appropriate geometry to return */
    // for the empty geometry, return an empty GeometryCollection
    if (geomClass == null) {
      return createGeometryCollection(null);
    }
    if (isHeterogeneous || hasGeometryCollection) {
      return createGeometryCollection(toGeometryArray(geomList));
    }
    // at this point we know the collection is hetereogenous.
    // Determine the type of the result from the first Geometry in the list
    // this should always return a geometry, since otherwise an empty collection would have already
    // been returned
    Geometry geom0 = (Geometry) geomList.iterator().next();
    boolean isCollection = geomList.size() > 1;
    if (isCollection) {
      if (geom0 instanceof Polygon) {
        return createMultiPolygon(toPolygonArray(geomList));
      } else if (geom0 instanceof LineString) {
        return createMultiLineString(toLineStringArray(geomList));
      } else if (geom0 instanceof Point) {
        return createMultiPoint(toPointArray(geomList));
      }
      Assert.shouldNeverReachHere("Unhandled class: " + geom0.getClass().getName());
    }
    return geom0;
  }
Exemplo n.º 16
0
 private Class toClass(ZipEntry entry, ClassLoader classLoader) {
   String className = entry.getName();
   className = className.substring(0, className.length() - ".class".length());
   className = StringUtil.replaceAll(className, "/", ".");
   Class candidate;
   try {
     candidate = classLoader.loadClass(className);
   } catch (ClassNotFoundException e) {
     Assert.shouldNeverReachHere(
         "Class not found: " + className + ". Refine class name algorithm.");
     return null;
   } catch (Throwable t) {
     LOG.error(LOADING_ERROR + " " + className + ":");
     // e.g. java.lang.VerifyError: class
     // org.apache.xml.serialize.XML11Serializer
     // overrides final method [Jon Aquino]
     t.printStackTrace(System.out);
     return null;
   }
   return candidate;
 }