예제 #1
0
  public Object clone() {
    JRDesignTextElement clone = (JRDesignTextElement) super.clone();

    clone.lineBox = (JRLineBox) lineBox.clone(clone);

    return clone;
  }
    public void animatorFinished(AnimatorEvent arg0) {
      animations--;
      if (animations == 0) {
        for (Iterator iter = getNewSizes().keySet().iterator(); iter.hasNext(); ) {
          JRDesignElement element = (JRDesignElement) iter.next();
          Rectangle rectangle = getNewSizes().get(element);
          element.setX(rectangle.x);
          element.setY(rectangle.y);
          element.setWidth(rectangle.width);
          element.setHeight(rectangle.height);

          // Calculate the best font height...
          if (element instanceof JRDesignTextElement) {
            JRStyledTextParser styledTextParser = JRStyledTextParser.getInstance();
            JRDesignTextElement dte = (JRDesignTextElement) element;
            dte.setFontSize(null);
            for (int i = dte.getFontSize() - 1; i > 1; --i) {
              String text = "test";

              // Convert the element in a print element...
              Map<Attribute, Object> attributes =
                  JRFontUtil.getAttributes(new HashMap(), dte, Locale.getDefault());

              JRStyledText styledText =
                  styledTextParser.getStyledText(
                      attributes,
                      text,
                      JRCommonText.MARKUP_STYLED_TEXT.equals(
                          dte
                              .getMarkup()), // FIXMEMARKUP only static styled text appears on
                                             // preview. no other markup
                      Locale.getDefault());

              JasperReportsContext context = IRLocalJasperReportsContext.getInstance();

              JRTextMeasurerUtil measurerUtil = JRTextMeasurerUtil.getInstance(context);
              JRTextMeasurer measurer = measurerUtil.createTextMeasurer(dte);
              JRMeasuredText measuredText = measurer.measure(styledText, 0, dte.getHeight(), true);

              if (measuredText.getTextHeight() > dte.getHeight()) {
                if (i > 1) {
                  dte.setFontSize(i);
                } else {
                  break;
                }
              } else {
                break;
              }
            }
          }
        }
      }
    }
  public JRDesignElementWidget(AbstractReportObjectScene scene, JRDesignElement element) {
    super(scene);
    this.element = element;
    setBorder(new SimpleLineBorder(this));
    updateBounds();

    try {
      if (crosstabImage == null)
        crosstabImage =
            new javax.swing.ImageIcon(
                getClass()
                    .getResource("/com/jaspersoft/ireport/designer/resources/crosstab-32.png"));
      if (subreportImage == null)
        subreportImage =
            new javax.swing.ImageIcon(
                getClass()
                    .getResource("/com/jaspersoft/ireport/designer/resources/subreport-32.png"));
      if (multiaxisImage == null)
        multiaxisImage =
            new javax.swing.ImageIcon(
                getClass()
                    .getResource("/com/jaspersoft/ireport/designer/resources/chartaxis-32.png"));
      if (genericElementImage == null)
        genericElementImage =
            new javax.swing.ImageIcon(
                getClass()
                    .getResource(
                        "/com/jaspersoft/ireport/designer/resources/genericelement-48.png"));
    } catch (Exception ex) {
    }

    selectionWidget = new SelectionWidget(scene, this);
    notifyStateChanged(null, ObjectState.createNormal());
    selectionWidget.addDependency(
        new Dependency() {

          public void revalidateDependency() {
            // setPreferredLocation(selectionWidget.getPreferredLocation() );
            // setPreferredBounds(selectionWidget.getPreferredBounds());
            // System.out.println("Revaludated");
          }
        });

    element.getEventSupport().addPropertyChangeListener(this);

    if (element instanceof JRDesignGraphicElement) {
      JRDesignGraphicElement gele = (JRDesignGraphicElement) element;
      ((JRBasePen) gele.getLinePen()).getEventSupport().addPropertyChangeListener(this);
    }

    if (element instanceof JRBoxContainer) {
      JRBoxContainer boxcontainer = (JRBoxContainer) element;
      JRBaseLineBox baseBox = (JRBaseLineBox) boxcontainer.getLineBox();
      baseBox.getEventSupport().addPropertyChangeListener(this);
      ((JRBasePen) baseBox.getPen()).getEventSupport().addPropertyChangeListener(this);
      ((JRBasePen) baseBox.getTopPen()).getEventSupport().addPropertyChangeListener(this);
      ((JRBasePen) baseBox.getBottomPen()).getEventSupport().addPropertyChangeListener(this);
      ((JRBasePen) baseBox.getLeftPen()).getEventSupport().addPropertyChangeListener(this);
      ((JRBasePen) baseBox.getRightPen()).getEventSupport().addPropertyChangeListener(this);
    }

    if (element instanceof JRDesignTextElement) {
      ((JRBaseParagraph) ((JRDesignTextElement) element).getParagraph())
          .getEventSupport()
          .addPropertyChangeListener(this);
    }
  }