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; } } } } } }
@Override protected void performAction(Node[] nodes) { if (nodes.length == 0) return; JasperDesign jd = nodes[0].getLookup().lookup(JasperDesign.class); if (jd == null) return; List<JRDesignElement> elements = getSelectedElements(nodes); boolean aggregate = false; for (JRDesignElement element : elements) { Rectangle oldBounds = getElementBounds(element); // 1. Find the parent... Rectangle rect = ModelUtils.getParentBounds(jd, element); int oldY = element.getY(); element.setY((rect.height / 2) - (element.getHeight() / 2)); aggregate = addTransformationUndo(element, oldBounds, aggregate); } }
public Map<JRElement, Rectangle> layout(JRElement[] elements, Dimension c) { Map<JRElement, Rectangle> map = new HashMap<JRElement, Rectangle>(); int x = 0; int y = 0; int w = c.width; int h = (int) Math.floor((float) c.height / elements.length); int rest = c.height - h * elements.length; for (JRElement el : elements) { JRDesignElement del = (JRDesignElement) el; map.put(el, new Rectangle(el.getX(), el.getY(), el.getWidth(), el.getHeight())); del.setX(x); del.setY(y); del.setWidth(w); del.setHeight(h + rest); // if last grab free pixels y += h + rest; if (rest > 0) rest = 0; LayoutManager.layout(map, el); } return map; }