コード例 #1
0
ファイル: InfoLayer.java プロジェクト: av4n/Weasis
  public String ajustLengthDisplay(double scaleLength, Unit[] unit) {
    double ajustScaleLength = scaleLength;

    Unit ajustUnit = unit[0];

    if (scaleLength < 1.0) {
      Unit down = ajustUnit;
      while ((down = down.getDownUnit()) != null) {
        double length = scaleLength * down.getConversionRatio(unit[0].getConvFactor());
        if (length > 1) {
          ajustUnit = down;
          ajustScaleLength = length;
          break;
        }
      }
    } else if (scaleLength > 10.0) {
      Unit up = ajustUnit;
      while ((up = up.getUpUnit()) != null) {
        double length = scaleLength * up.getConversionRatio(unit[0].getConvFactor());
        if (length < 1) {
          break;
        }
        ajustUnit = up;
        ajustScaleLength = length;
      }
    }
    // Trick to keep the value as a return parameter
    unit[0] = ajustUnit;
    if (ajustScaleLength < 1.0) {
      return ajustScaleLength < 0.001
          ? DecFormater.scientificFormat(ajustScaleLength)
          : DecFormater.fourDecimal(ajustScaleLength);
    }
    return ajustScaleLength > 50000.0
        ? DecFormater.scientificFormat(ajustScaleLength)
        : DecFormater.twoDecimal(ajustScaleLength);
  }
コード例 #2
0
ファイル: InfoLayer.java プロジェクト: av4n/Weasis
  @Override
  public void paint(Graphics2D g2) {
    ImageElement image = view2DPane.getImage();
    if (!visible || image == null) {
      return;
    }

    final Rectangle bound = view2DPane.getBounds();
    float midx = bound.width / 2f;
    float midy = bound.height / 2f;

    g2.setPaint(color);

    final float fontHeight = FontTools.getAccurateFontHeight(g2);
    final float midfontHeight = fontHeight * FontTools.getMidFontHeightFactor();
    float drawY = bound.height - border - 1.5f; // -1.5 for outline

    if (!image.isReadable()) {
      String message = Messages.getString("InfoLayer.error_msg"); // $NON-NLS-1$
      float y = midy;
      GraphicLabel.paintColorFontOutline(
          g2, message, midx - g2.getFontMetrics().stringWidth(message) / 2, y, Color.RED);
      String[] desc = image.getMediaReader().getReaderDescription();
      if (desc != null) {
        for (String str : desc) {
          if (str != null) {
            y += fontHeight;
            GraphicLabel.paintColorFontOutline(
                g2, str, midx - g2.getFontMetrics().stringWidth(str) / 2, y, Color.RED);
          }
        }
      }
    }
    if (image.isReadable() && getDisplayPreferences(SCALE)) {
      drawScale(g2, bound, fontHeight);
    }
    if (image.isReadable() && getDisplayPreferences(LUT)) {
      drawLUT(g2, bound, midfontHeight);
    }

    if (getDisplayPreferences(PIXEL)) {
      String str =
          Messages.getString("InfoLayer.pix") + ": " + pixelInfo; // $NON-NLS-1$ //$NON-NLS-2$
      GraphicLabel.paintFontOutline(g2, str, border, drawY - 1);
      drawY -= fontHeight + 2;
      pixelInfoBound.setBounds(
          border - 2,
          (int) drawY + 3,
          g2.getFontMetrics().stringWidth(str) + 4,
          (int) fontHeight + 2);
      // g2.draw(pixelInfoBound);
    }
    if (getDisplayPreferences(WINDOW_LEVEL)) {
      GraphicLabel.paintFontOutline(
          g2,
          Messages.getString("InfoLayer.win")
              + ": "
              + view2DPane.getActionValue(ActionW.WINDOW.cmd()) // $NON-NLS-1$ //$NON-NLS-2$
              + " "
              + Messages.getString("InfoLayer.level")
              + ": "
              + view2DPane.getActionValue(ActionW.LEVEL.cmd()),
          border,
          drawY); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      drawY -= fontHeight;
    }
    if (getDisplayPreferences(ZOOM)) {
      GraphicLabel.paintFontOutline(
          g2,
          Messages.getString("InfoLayer.zoom")
              + ": "
              + DecFormater.twoDecimal(view2DPane.getViewModel().getViewScale() * 100)
              + " "
              + Messages.getString("InfoLayer.percent"),
          border, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
          drawY);
      drawY -= fontHeight;
    }
    if (getDisplayPreferences(ROTATION)) {
      GraphicLabel.paintFontOutline(
          g2,
          Messages.getString("InfoLayer.angle")
              + ": "
              + view2DPane.getActionValue(ActionW.ROTATION.cmd())
              + " "
              + Messages.getString("InfoLayer.angle_symb"),
          border,
          drawY); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
      drawY -= fontHeight;
    }

    if (getDisplayPreferences(FRAME)) {
      GraphicLabel.paintFontOutline(
          g2,
          Messages.getString("InfoLayer.frame") // $NON-NLS-1$
              + ": " //$NON-NLS-1$
              + (view2DPane.getFrameIndex() + 1)
              + " / " //$NON-NLS-1$
              + view2DPane
                  .getSeries()
                  .size(
                      (Filter<ImageElement>)
                          view2DPane.getActionValue(ActionW.FILTERED_SERIES.cmd())),
          border,
          drawY);
      drawY -= fontHeight;
    }

    // if (getDisplayPreferences(ANNOTATIONS)) {
    // MediaSeries<ImageElement> series = view2DPane.getSeries();
    //
    // Boolean synchLink = (Boolean) view2DPane.getActionValue(ActionW.SYNCH_LINK.cmd());
    // String str = synchLink != null && synchLink ? "linked" : "unlinked";
    // paintFontOutline(g2, str, bound.width - g2.getFontMetrics().stringWidth(str) - border,
    // drawY);
    //
    // }

  }