コード例 #1
0
  /** Tests the hash code computation. */
  @Test
  public void testHashCode() {
    final CitationImpl citation = new CitationImpl();
    final PropertyAccessor accessor = createPropertyAccessor(citation);
    int hashCode = accessor.hashCode(citation);
    assertEquals("Empty metadata.", 0, hashCode);

    final String ISBN = "Dummy ISBN";
    citation.setISBN(ISBN);
    hashCode = accessor.hashCode(citation);
    assertEquals("Metadata with a single String value.", ISBN.hashCode(), hashCode);

    final Set<Object> set = new HashSet<Object>();
    assertEquals("By Set.hashCode() contract.", 0, set.hashCode());
    assertTrue(set.add(ISBN));
    assertEquals("Expected Metadata.hashCode() == Set.hashCode().", set.hashCode(), hashCode);

    final InternationalString title = new SimpleInternationalString("Dummy title");
    citation.setTitle(title);
    hashCode = accessor.hashCode(citation);
    assertEquals("Metadata with two values.", ISBN.hashCode() + title.hashCode(), hashCode);
    assertTrue(set.add(title));
    assertEquals("Expected Metadata.hashCode() == Set.hashCode().", set.hashCode(), hashCode);
    assertEquals("CitationsImpl.hashCode() should delegate.", hashCode, citation.hashCode());

    final Collection<Object> values = citation.asMap().values();
    assertEquals(hashCode, new HashSet<Object>(values).hashCode());
    assertTrue(values.containsAll(set));
    assertTrue(set.containsAll(values));
  }
コード例 #2
0
 private String toString(InternationalString str) {
   if (str == null) {
     return "";
   } else {
     return str.toString();
   }
 }
コード例 #3
0
 private static SimpleScalarAxis createSimpleScalarAxis(
     final Name productName, final InternationalString productDescription) {
   return new SimpleScalarAxis(
       new NameImpl(new StringBuilder("axis:").append(productName.toString()).toString()),
       new SimpleInternationalString(
           new StringBuilder("axis for product:")
               .append(productDescription.toString())
               .toString()));
 }
コード例 #4
0
 /**
  * Returns {@code true} if this factory is available. The default implementation returns {@code
  * false} if no backing store were setup and {@link DeferredAuthorityFactory#createBackingStore}
  * throws an exception.
  */
 @Override
 synchronized boolean isAvailable() {
   try {
     return getBackingStore().isAvailable();
   } catch (FactoryNotFoundException exception) {
     /*
      * The factory is not available. This is error may be normal; it happens
      * for example if no gt2-epsg-hsql.jar (or similar JAR) are found in the
      * classpath, which is the case for example in GeoServer 1.3. Do not log
      * any stack trace,  since stack traces suggest more serious errors than
      * what we really have here.
      */
   } catch (FactoryException exception) {
     /*
      * The factory creation failed for an other reason, which may be more
      * serious. Now it is time to log a warning with a stack trace.
      */
     final Citation citation = getAuthority();
     final Collection titles = citation.getAlternateTitles();
     InternationalString title = citation.getTitle();
     if (titles != null) {
       for (final Iterator it = titles.iterator(); it.hasNext(); ) {
         /*
          * Uses the longuest title instead of the main one. In Geotools
          * implementation, the alternate title may contains usefull informations
          * like the EPSG database version number and the database engine.
          */
         final InternationalString candidate = (InternationalString) it.next();
         if (candidate.length() > title.length()) {
           title = candidate;
         }
       }
     }
     final LogRecord record =
         Loggings.format(Level.WARNING, LoggingKeys.UNAVAILABLE_AUTHORITY_FACTORY_$1, title);
     record.setSourceClassName(getClass().getName());
     record.setSourceMethodName("isAvailable");
     record.setThrown(exception);
     record.setLoggerName(LOGGER.getName());
     LOGGER.log(record);
   }
   return false;
 }
コード例 #5
0
  /**
   * Receives a list of <code>BufferedImages</code> and produces a new one which holds all the
   * images in <code>imageStack</code> one above the other, handling labels.
   *
   * @param imageStack the list of BufferedImages, one for each applicable Rule
   * @param rules The applicable rules, one for each image in the stack (if not null it's used to
   *     compute labels)
   * @param request The request.
   * @param forceLabelsOn true for force labels on also with a single image.
   * @param forceLabelsOff true for force labels off also with more than one rule.
   * @return the stack image with all the images on the argument list.
   * @throws IllegalArgumentException if the list is empty
   */
  private BufferedImage mergeLegends(
      List<RenderedImage> imageStack,
      Rule[] rules,
      GetLegendGraphicRequest req,
      boolean forceLabelsOn,
      boolean forceLabelsOff) {

    Font labelFont = LegendUtils.getLabelFont(req);
    boolean useAA = LegendUtils.isFontAntiAliasing(req);

    if (imageStack.size() == 0) {
      return null;
    }

    final BufferedImage finalLegend;

    if (imageStack.size() == 1 && (!forceLabelsOn || rules == null)) {
      finalLegend = (BufferedImage) imageStack.get(0);
    } else {
      final int imgCount = imageStack.size();
      final String[] labels = new String[imgCount];

      BufferedImage img = ((BufferedImage) imageStack.get(0));

      int totalHeight = 0;
      int totalWidth = 0;
      int[] rowHeights = new int[imgCount];
      BufferedImage labelsGraphics[] = new BufferedImage[imgCount];
      for (int i = 0; i < imgCount; i++) {
        img = (BufferedImage) imageStack.get(i);

        if (forceLabelsOff || rules == null) {
          totalWidth = (int) Math.ceil(Math.max(img.getWidth(), totalWidth));
          rowHeights[i] = img.getHeight();
          totalHeight += img.getHeight();
        } else {

          Rule rule = rules[i];

          // What's the label on this rule? We prefer to use
          // the 'title' if it's available, but fall-back to 'name'
          final Description description = rule.getDescription();
          Locale locale = req.getLocale();

          if (description != null && description.getTitle() != null) {
            final InternationalString title = description.getTitle();
            if (locale != null) {
              labels[i] = title.toString(locale);
            } else {
              labels[i] = title.toString();
            }
          } else if (rule.getName() != null) {
            labels[i] = rule.getName();
          } else {
            labels[i] = "";
          }

          if (labels[i] != null && labels[i].length() > 0) {
            final BufferedImage renderedLabel = getRenderedLabel(img, labels[i], req);
            labelsGraphics[i] = renderedLabel;
            final Rectangle2D bounds =
                new Rectangle2D.Double(0, 0, renderedLabel.getWidth(), renderedLabel.getHeight());

            totalWidth = (int) Math.ceil(Math.max(img.getWidth() + bounds.getWidth(), totalWidth));
            rowHeights[i] = (int) Math.ceil(Math.max(img.getHeight(), bounds.getHeight()));
          } else {
            totalWidth = (int) Math.ceil(Math.max(img.getWidth(), totalWidth));
            rowHeights[i] = (int) Math.ceil(img.getHeight());
            labelsGraphics[i] = null;
          }

          totalHeight += rowHeights[i];
        }
      }

      // buffer the width a bit
      totalWidth += 2;

      final boolean transparent = req.isTransparent();
      final Color backgroundColor = LegendUtils.getBackgroundColor(req);
      final Map<RenderingHints.Key, Object> hintsMap = new HashMap<RenderingHints.Key, Object>();
      // create the final image
      finalLegend =
          ImageUtils.createImage(totalWidth, totalHeight, (IndexColorModel) null, transparent);
      Graphics2D finalGraphics =
          ImageUtils.prepareTransparency(transparent, backgroundColor, finalLegend, hintsMap);

      int topOfRow = 0;

      for (int i = 0; i < imgCount; i++) {
        img = (BufferedImage) imageStack.get(i);

        // draw the image
        int y = topOfRow;

        if (img.getHeight() < rowHeights[i]) {
          // move the image to the center of the row
          y += (int) ((rowHeights[i] - img.getHeight()) / 2d);
        }

        finalGraphics.drawImage(img, 0, y, null);
        if (forceLabelsOff || rules == null) {
          topOfRow += rowHeights[i];
          continue;
        }

        finalGraphics.setFont(labelFont);

        if (useAA) {
          finalGraphics.setRenderingHint(
              RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        } else {
          finalGraphics.setRenderingHint(
              RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
        }

        // draw the label
        if (labels[i] != null && labels[i].length() > 0) {
          // first create the actual overall label image.
          final BufferedImage renderedLabel = labelsGraphics[i];

          y = topOfRow;

          if (renderedLabel.getHeight() < rowHeights[i]) {
            y += (int) ((rowHeights[i] - renderedLabel.getHeight()) / 2d);
          }

          finalGraphics.drawImage(renderedLabel, img.getWidth(), y, null);
          // cleanup
          renderedLabel.flush();
          labelsGraphics[i] = null;
        }

        topOfRow += rowHeights[i];
      }

      finalGraphics.dispose();
    }
    return finalLegend;
  }
コード例 #6
0
 public String getDescription() {
   return task == null ? null : task.toString();
 }
コード例 #7
0
 public void setTask(InternationalString task) {
   setDescription(task.toString());
 }