/** Invoked when an action occurs. */ public void actionPerformed(final ActionEvent e) { final Object o = comboBox.getSelectedItem(); if (o != null && o instanceof String == false) { return; } final String font = (String) o; final ReportRenderContext activeContext = getActiveContext(); if (activeContext == null) { return; } final ReportSelectionModel selectionModel1 = getSelectionModel(); if (selectionModel1 == null) { return; } final Element[] visualElements = selectionModel1.getSelectedVisualElements(); final ArrayList<UndoEntry> undos = new ArrayList<UndoEntry>(); for (int i = 0; i < visualElements.length; i++) { final Element visualElement = visualElements[i]; undos.add(StyleEditUndoEntry.createConditional(visualElement, TextStyleKeys.FONT, font)); visualElement.getStyle().setStyleProperty(TextStyleKeys.FONT, font); visualElement.notifyNodePropertiesChanged(); } getActiveContext() .getUndo() .addChange( ActionMessages.getString("ApplyFontFamilyAction.UndoName"), new CompoundUndoEntry(undos.toArray(new UndoEntry[undos.size()]))); }
@Test public void testCanvasWithPrePostPad() throws Exception { final MasterReport report = new MasterReport(); report.setDataFactory(new TableDataFactory("query", new DefaultTableModel(10, 1))); report.setQuery("query"); final Band table = TableTestUtil.createTable(1, 1, 6, new CustomProducer()); table.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, 200f); table.getStyle().setStyleProperty(ElementStyleKeys.POS_X, 100f); table.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, 10f); table.setName("table"); report.getReportHeader().addElement(TableTestUtil.createDataItem("Pre-Padding", 100, 10)); report.getReportHeader().addElement(table); Element postPaddingItem = TableTestUtil.createDataItem("Post-Padding", 100, 10); postPaddingItem.getStyle().setStyleProperty(ElementStyleKeys.POS_X, 300f); report.getReportHeader().addElement(postPaddingItem); report.getReportHeader().setLayout("canvas"); PdfReportUtil.createPDF(report, "test-output/PRD-3857-output-canvas.pdf"); List<LogicalPageBox> pages = DebugReportRunner.layoutPages(report, 0, 1, 2); assertPageValid(pages, 0, StrictGeomUtility.toInternalValue(10)); assertPageValid(pages, 1); assertPageValid(pages, 2); }
public void resizeProportional() { final float originalPageWidth = originalPageDefinition.getWidth(); final float currentPageWidth = currentPageDefinition.getWidth(); final float scaleFactor = currentPageWidth / originalPageWidth; for (int i = 0; i < visualElements.length; i++) { // Resize the element. final CachedLayoutData cachedLayoutData = ModelUtility.getCachedLayoutData(visualElements[i]); final double elementWidth = StrictGeomUtility.toExternalValue(cachedLayoutData.getWidth()); final Element theElement = visualElements[i]; final ElementStyleSheet styleSheet = theElement.getStyle(); styleSheet.setStyleProperty( ElementStyleKeys.MIN_WIDTH, new Float(elementWidth * scaleFactor)); // Reposition the element. final double origin = StrictGeomUtility.toExternalValue(cachedLayoutData.getX()); final double destination = scaleFactor * origin; final int theShift = (int) (destination - origin); final Element[] theElements = new Element[1]; theElements[0] = theElement; align(theShift, theElements); } registerChanges(); }
/** * Creates a new drawable field element based on the defined properties. * * @return the generated elements * @throws IllegalStateException if the field name is not set. * @see ElementFactory#createElement() */ public Element createElement() { final Element element = new Element(); applyElementName(element); applyStyle(element.getStyle()); element.setElementType(new ContentType()); if (content != null) { element.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, content); } if (baseURL != null) { element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.CONTENT_BASE, baseURL); } return element; }
/** * Creates a new instance of the element. Override this method to return a concrete subclass of * the element. * * @return the newly generated instance of the element. */ public Element createElement() { final Element element = new Element(); applyElementName(element); applyStyle(element.getStyle()); element.setElementType(new LineSparklineType()); if (getContent() != null) { element.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, getContent()); } if (getFieldname() != null) { element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FIELD, getFieldname()); } if (getFormula() != null) { final FormulaExpression formulaExpression = new FormulaExpression(); formulaExpression.setFormula(getFormula()); element.setAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, formulaExpression); } if (spacing != null) { element.setAttribute( SparklineAttributeNames.NAMESPACE, SparklineAttributeNames.SPACING, spacing); } return element; }
/** * Triggers the visible state of the specified itemband element. If the named element was visible * at the last call, it gets now invisible and vice versa. This creates the effect, that an * element is printed every other line. * * @param event the current report event. */ private void triggerVisibleStateCrosstab(final ReportEvent event) { if ((count % numberOfElements) == 0) { trigger = (!trigger); } count += 1; final CrosstabCellBody cellBody = event.getReport().getCrosstabCellBody(); if (cellBody == null) { return; } if (element == null) { final int elementCount = cellBody.getElementCount(); for (int i = 1; i < elementCount; i += 1) { final Element cell = cellBody.getElement(i); if (trigger) { cell.getStyle().setStyleProperty(ElementStyleKeys.BACKGROUND_COLOR, visibleBackground); } else { cell.getStyle().setStyleProperty(ElementStyleKeys.BACKGROUND_COLOR, invisibleBackground); } } } else { final Element[] e = FunctionUtilities.findAllElements(cellBody, getElement()); if (e.length > 0) { for (int i = 0; i < e.length; i++) { if (trigger) { e[i].getStyle().setStyleProperty(ElementStyleKeys.BACKGROUND_COLOR, visibleBackground); } else { e[i].getStyle() .setStyleProperty(ElementStyleKeys.BACKGROUND_COLOR, invisibleBackground); } } } else { if (warned == false) { RowBandingFunction.logger.warn( "The cell-body does not contain an element named " + getElement()); warned = true; } } } }
protected void updateSelection() { super.updateSelection(); final ReportSelectionModel selectionModel = getSelectionModel(); if (selectionModel == null) { return; } final Element[] visualElements = selectionModel.getSelectedVisualElements(); boolean selected; if (visualElements.length == 0) { selected = false; } else { selected = true; for (int i = 0; i < visualElements.length; i++) { final Element visualElement = visualElements[i]; selected &= visualElement.getStyle().getBooleanStyleProperty(TextStyleKeys.ITALIC); } } setSelected(selected); }
private Expression extractSecondaryDatasource(final Element element) { final Expression originalSecondaryDataSourceExpression; final Object secondaryDataSource = element.getAttribute( LegacyChartElementModule.NAMESPACE, LegacyChartElementModule.SECONDARY_DATA_COLLECTOR_FUNCTION_ATTRIBUTE); if (secondaryDataSource instanceof Expression) { originalSecondaryDataSourceExpression = (Expression) secondaryDataSource; } else { originalSecondaryDataSourceExpression = null; } return originalSecondaryDataSourceExpression; }
private Expression extractPrimaryDatasource(final Element element) { final Expression originalPrimaryDataSourceExpression; final Object primaryDataSourceRaw = element.getAttribute( LegacyChartElementModule.NAMESPACE, LegacyChartElementModule.PRIMARY_DATA_COLLECTOR_FUNCTION_ATTRIBUTE); if (primaryDataSourceRaw instanceof Expression) { originalPrimaryDataSourceExpression = (Expression) primaryDataSourceRaw; } else { originalPrimaryDataSourceExpression = null; } return originalPrimaryDataSourceExpression; }
private Element process(final javax.swing.text.Element textElement) throws BadLocationException { if (textElement.isLeaf()) { final int endOffset = textElement.getEndOffset(); final int startOffset = textElement.getStartOffset(); final String text = textElement.getDocument().getText(startOffset, endOffset - startOffset); final Element result = new Element(); result.setElementType(LabelType.INSTANCE); result.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, text); configureStyle(textElement.getAttributes(), result); return result; } final Band band = new Band(); configureStyle(textElement.getAttributes(), band); configureBand(textElement, band); final int size = textElement.getElementCount(); for (int i = 0; i < size; i++) { final Element element = process(textElement.getElement(i)); band.addElement(element); } return band; }
public void testResourceLabelAfterSerialization() throws Exception { final File url = GoldTestBase.locateGoldenSampleReport("Prd-3514.prpt"); assertNotNull(url); final ResourceManager resourceManager = new ResourceManager(); resourceManager.registerDefaults(); final Resource directly = resourceManager.createDirectly(url, MasterReport.class); final MasterReport org = (MasterReport) directly.getResource(); final MasterReport report = postProcess(org); RelationalGroup relationalGroup = report.getRelationalGroup(0); GroupHeader header = relationalGroup.getHeader(); Band band = (Band) header.getElement(0); Element element = band.getElement(1); assertTrue(element.getElementType() instanceof ResourceMessageType); element.setName("DateTitleField"); // LogicalPageBox logicalPageBox = DebugReportRunner.layoutPage(report, 1); LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand(report, header, false, false); RenderNode dateTitleField = MatchFactory.findElementByName(logicalPageBox, "DateTitleField"); assertNotNull(dateTitleField); // ModelPrinter.INSTANCE.print(logicalPageBox); }
public void setStyleProperty(final StyleKey key, final Object value) { final long l = getChangeTracker(); final Object oldValue; if (super.isLocalKey(key)) { oldValue = super.getStyleProperty(key); } else { oldValue = null; } super.setStyleProperty(key, value); if (l != getChangeTracker()) { element.notifyNodePropertiesChanged(new StyleChange(key, oldValue, value)); } }
public void testLoadSaveFromDisk() throws Exception { final ResourceKey key = createImageKey(); final Element element = new Element(); element.setElementType(new ContentType()); element.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, key); // .. save it. final MasterReport report = new MasterReport(); report.getReportHeader().addElement(element); saveReport(report, new File("bin/test-tmp/prd-3319-load-save-disk-1.prpt")); // load it to establish the context in all resource-keys .. final ResourceManager mgr = new ResourceManager(); mgr.registerDefaults(); final Resource resource = mgr.createDirectly( new File("bin/test-tmp/prd-3319-load-save-disk-1.prpt"), MasterReport.class); // save it once, that changes the bundle ... final MasterReport report2 = (MasterReport) resource.getResource(); saveReport(report2, new File("bin/test-tmp/prd-3319-load-save-disk-2.prpt")); // save it twice, that triggers the crash... saveReport(report2, new File("bin/test-tmp/prd-3319-load-save-disk-2.prpt")); final ProcessingContext processingContext = new DefaultProcessingContext(); final DebugExpressionRuntime runtime = new DebugExpressionRuntime(new DefaultTableModel(), 0, processingContext); final Element reportElement = report2.getReportHeader().getElement(0); Object attribute = reportElement.getAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE); assertTrue(attribute instanceof ResourceKey); ResourceKey atKey = (ResourceKey) attribute; assertEquals("http://127.0.0.1:65535/image.jpg", atKey.getIdentifierAsString()); }
/** Invoked when an action occurs. */ public void actionPerformed(final ActionEvent e) { final ReportSelectionModel selectionModel = getSelectionModel(); if (selectionModel == null) { return; } final Element[] visualElements = selectionModel.getSelectedVisualElements(); if (visualElements.length == 0) { return; } final ReportRenderContext activeContext = getActiveContext(); if (activeContext == null) { return; } Boolean value = Boolean.FALSE; final ArrayList<UndoEntry> undos = new ArrayList<UndoEntry>(); for (int i = 0; i < visualElements.length; i++) { final Element element = visualElements[i]; final ElementStyleSheet styleSheet = element.getStyle(); if (i == 0) { if (styleSheet.getBooleanStyleProperty(TextStyleKeys.ITALIC)) { value = Boolean.FALSE; } else { value = Boolean.TRUE; } } undos.add(StyleEditUndoEntry.createConditional(element, TextStyleKeys.ITALIC, value)); styleSheet.setStyleProperty(TextStyleKeys.ITALIC, value); element.notifyNodePropertiesChanged(); } getActiveContext() .getUndo() .addChange( ActionMessages.getString("ItalicsAction.UndoName"), new CompoundUndoEntry(undos.toArray(new UndoEntry[undos.size()]))); }
public void testRichText() throws ReportProcessingException, ContentProcessingException { final Element e = new Element(); e.setElementType(LabelType.INSTANCE); e.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.RICH_TEXT_TYPE, "text/html"); e.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "Hi I am trying to use the <b>rich text type = text/html</b> in PRD version - 3.7."); e.getStyle().setStyleProperty(TextStyleKeys.FONTSIZE, 12); e.getStyle().setStyleProperty(TextStyleKeys.FONT, "Arial"); e.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, 285f); e.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, 20f); final MasterReport report = new MasterReport(); report.getReportHeader().addElement(e); final LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand(report, report.getReportHeader(), false, false); logicalPageBox.getRepeatFooterArea().setY(logicalPageBox.getContentArea().getHeight()); logicalPageBox.getFooterArea().setY(logicalPageBox.getContentArea().getHeight()); // ModelPrinter.INSTANCE.print(logicalPageBox); final RenderNode[] elementsByNodeType = MatchFactory.findElementsByNodeType(logicalPageBox, LayoutNodeTypes.TYPE_NODE_TEXT); assertEquals( 17, elementsByNodeType.length); // quick and easy way to see that all elements are there. // debugPrintText(elementsByNodeType); final LocalFontRegistry registry = new LocalFontRegistry(); registry.initialize(); final GraphicsOutputProcessorMetaData metaData = new GraphicsOutputProcessorMetaData(new DefaultFontStorage(registry)); metaData.initialize(report.getConfiguration()); final LogicalPageDrawable drawable = new LogicalPageDrawable(); drawable.init(logicalPageBox, metaData, report.getResourceManager()); final TracingGraphics g2 = new TracingGraphics(); drawable.draw(g2, new Rectangle2D.Double(0, 0, 500, 500)); /* for (int i = 0; i < g2.records.size(); i++) { final TextTraceRecord record = g2.records.get(i); System.out.println ("goldenSamples.add(new TextTraceRecord(" + record.x + ", " + record.y + ", \"" + record.text +"\"));"); } */ assertEquals(getSamples(), g2.records); }
/** * Creates the text field element. * * @return the generated text field element * @see org.pentaho.reporting.engine.classic.core.elementfactory.ElementFactory#createElement() */ public Element createElement() { final Element element = new Element(); applyElementName(element); applyStyle(element.getStyle()); element.setElementType(new TextFieldType()); if (getFieldname() != null) { element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.FIELD, getFieldname()); } if (getFormula() != null) { final FormulaExpression formulaExpression = new FormulaExpression(); formulaExpression.setFormula(getFormula()); element.setAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, formulaExpression); } element.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.NULL_VALUE, getNullString()); return element; }
public static void testBorder() throws IOException, ReportWriterException { Object[] columnNames = new Object[] {"Customer", "City", "Number"}; DefaultTableModel reportTableModel = new DefaultTableModel( new Object[][] { {"Customer_ASDFSDFSDFSDFSaasdasdasdasweruzweurzwiezrwieuzriweuzriweu", "Bern", "123"}, {"Hugo", "Z?rich", "2234"}, }, columnNames); MasterReport report = new MasterReport(); report.setName("BorderTest"); report .getItemBand() .addElement( LabelElementFactory.createLabelElement( "CustomerLabel", new Rectangle2D.Double(0, 0, 200, 100), Color.RED, ElementAlignment.LEFT, new FontDefinition("Arial", 12), "CustomerLabel")); Element element = TextFieldElementFactory.createStringElement( "CustomerField", new Rectangle2D.Double(210, 0, 150, 30), Color.black, ElementAlignment.LEFT, ElementAlignment.TOP, null, // font "-", // null string "Customer"); element.getStyle().setStyleProperty(ElementStyleKeys.BORDER_TOP_COLOR, Color.RED); element.getStyle().setStyleProperty(ElementStyleKeys.BORDER_TOP_WIDTH, new Float(1)); element.getStyle().setStyleProperty(ElementStyleKeys.BORDER_TOP_STYLE, BorderStyle.SOLID); element.getStyle().setStyleProperty(ElementStyleKeys.BORDER_LEFT_COLOR, Color.GREEN); element.getStyle().setStyleProperty(ElementStyleKeys.BORDER_LEFT_WIDTH, new Float(1)); element.getStyle().setStyleProperty(ElementStyleKeys.BORDER_LEFT_STYLE, BorderStyle.SOLID); element.getStyle().setStyleProperty(ElementStyleKeys.BORDER_RIGHT_COLOR, Color.YELLOW); element.getStyle().setStyleProperty(ElementStyleKeys.BORDER_RIGHT_WIDTH, new Float(5)); element.getStyle().setStyleProperty(ElementStyleKeys.BORDER_RIGHT_STYLE, BorderStyle.SOLID); element.getStyle().setStyleProperty(ElementStyleKeys.BORDER_BOTTOM_COLOR, Color.CYAN); element.getStyle().setStyleProperty(ElementStyleKeys.BORDER_BOTTOM_WIDTH, new Float(5)); element.getStyle().setStyleProperty(ElementStyleKeys.BORDER_BOTTOM_STYLE, BorderStyle.SOLID); element .getStyle() .setStyleProperty(ElementStyleKeys.BACKGROUND_COLOR, new Color(255, 127, 127, 120)); element.getStyle().setStyleProperty(ElementStyleKeys.PADDING_LEFT, new Float(5)); element.getStyle().setStyleProperty(ElementStyleKeys.PADDING_TOP, new Float(5)); element.getStyle().setStyleProperty(ElementStyleKeys.OVERFLOW_X, Boolean.TRUE); report.getItemBand().addElement(element); report.setQuery("default"); report.setDataFactory(new TableDataFactory("default", reportTableModel)); DebugReportRunner.execGraphics2D(report); }
private void configureStyle(final AttributeSet attributes, final Element element) { final Object alignment = attributes.getAttribute(StyleConstants.Alignment); if (alignment instanceof Integer) { final int alignmentValue = (Integer) alignment; if (StyleConstants.ALIGN_CENTER == alignmentValue) { element.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT, ElementAlignment.CENTER); } else if (StyleConstants.ALIGN_RIGHT == alignmentValue) { element.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT, ElementAlignment.RIGHT); } else if (StyleConstants.ALIGN_JUSTIFIED == alignmentValue) { element.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT, ElementAlignment.JUSTIFY); } else { element.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT, ElementAlignment.LEFT); } } final Object background = attributes.getAttribute(StyleConstants.Background); if (background instanceof Color) { element.getStyle().setStyleProperty(ElementStyleKeys.BACKGROUND_COLOR, background); } // Not handled: attributes.getAttribute(StyleConstants.BidiLevel); // Not handled: attributes.getAttribute(StyleConstants.ComponentAttribute); // Not handled: attributes.getAttribute(StyleConstants.ComposedTextAttribute); final Object bold = attributes.getAttribute(StyleConstants.Bold); if (bold instanceof Boolean) { element.getStyle().setStyleProperty(TextStyleKeys.BOLD, bold); } final Object firstLineIndent = attributes.getAttribute(StyleConstants.FirstLineIndent); if (firstLineIndent instanceof Float) { element.getStyle().setStyleProperty(TextStyleKeys.FIRST_LINE_INDENT, firstLineIndent); } final Object family = attributes.getAttribute(StyleConstants.FontFamily); if (family instanceof String) { element.getStyle().setStyleProperty(TextStyleKeys.FONT, family); } final Object fontSize = attributes.getAttribute(StyleConstants.FontSize); if (fontSize instanceof Integer) { element.getStyle().setStyleProperty(TextStyleKeys.FONTSIZE, fontSize); } final Object foreground = attributes.getAttribute(StyleConstants.Foreground); if (foreground instanceof Color) { element.getStyle().setStyleProperty(ElementStyleKeys.PAINT, foreground); } final Object iconAttribute = attributes.getAttribute(StyleConstants.IconAttribute); if (iconAttribute instanceof Icon) { // not handled yet } final Object italic = attributes.getAttribute(StyleConstants.Italic); if (italic instanceof Boolean) { element.getStyle().setStyleProperty(TextStyleKeys.ITALIC, italic); } final Object leftIndent = attributes.getAttribute(StyleConstants.LeftIndent); if (leftIndent instanceof Float) { element.getStyle().setStyleProperty(TextStyleKeys.TEXT_INDENT, leftIndent); } final Object lineSpacing = attributes.getAttribute(StyleConstants.LineSpacing); if (lineSpacing instanceof Float) { element.getStyle().setStyleProperty(TextStyleKeys.LINEHEIGHT, lineSpacing); } final Object modelAttribute = attributes.getAttribute(StyleConstants.ModelAttribute); if (modelAttribute instanceof Float) { // not handled yet } final Object nameAttribute = attributes.getAttribute(StyleConstants.NameAttribute); if (nameAttribute instanceof Float) { // not handled yet } final Object orientation = attributes.getAttribute(StyleConstants.Orientation); if (orientation instanceof Float) { // not used, also seems to be unused by Swing itself } final Object resolveAttribute = attributes.getAttribute(StyleConstants.ResolveAttribute); if (resolveAttribute instanceof Float) { // not handled yet, maybe never needed to be handled at all. } final Object rightIndent = attributes.getAttribute(StyleConstants.RightIndent); if (rightIndent instanceof Float) { // not handled yet } final Object spaceAbove = attributes.getAttribute(StyleConstants.SpaceAbove); if (spaceAbove instanceof Float) { element.getStyle().setStyleProperty(ElementStyleKeys.PADDING_TOP, spaceAbove); } final Object spaceBelow = attributes.getAttribute(StyleConstants.SpaceBelow); if (spaceBelow instanceof Float) { element.getStyle().setStyleProperty(ElementStyleKeys.PADDING_BOTTOM, spaceBelow); } final Object strikeThrough = attributes.getAttribute(StyleConstants.StrikeThrough); if (strikeThrough instanceof Boolean) { element.getStyle().setStyleProperty(TextStyleKeys.STRIKETHROUGH, strikeThrough); } final Object subscript = attributes.getAttribute(StyleConstants.Subscript); if (subscript instanceof Boolean) { // not handled yet } final Object superScript = attributes.getAttribute(StyleConstants.Superscript); if (superScript instanceof Boolean) { // not handled yet } final Object tabSet = attributes.getAttribute(StyleConstants.TabSet); if (tabSet instanceof Float) { // not handled yet } final Object underline = attributes.getAttribute(StyleConstants.Underline); if (underline instanceof Boolean) { element.getStyle().setStyleProperty(TextStyleKeys.UNDERLINED, underline); } element.getStyle().setStyleProperty(ElementStyleKeys.DYNAMIC_HEIGHT, Boolean.TRUE); }
public void testCanvasBug() throws Exception { final MasterReport report = new MasterReport(); final ReportHeader header = report.getReportHeader(); header.getStyle().setStyleProperty(TextStyleKeys.FONT, "Monospaced"); header.getStyle().setStyleProperty(TextStyleKeys.FONTSIZE, new Integer(6)); header.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, new Float(50)); header.getStyle().setStyleProperty(ElementStyleKeys.VALIGNMENT, ElementAlignment.MIDDLE); final Element label1 = new Element(); label1.setElementType(LabelType.INSTANCE); label1.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "COST"); label1.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.NAME, "COST"); label1.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT, ElementAlignment.LEFT); label1.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, new Float(12)); label1.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(100)); label1.getStyle().setStyleProperty(ElementStyleKeys.PADDING_LEFT, new Float(2)); label1.getStyle().setStyleProperty(ElementStyleKeys.PADDING_RIGHT, new Float(2)); label1.getStyle().setStyleProperty(ElementStyleKeys.PADDING_TOP, new Float(2)); label1.getStyle().setStyleProperty(ElementStyleKeys.PADDING_BOTTOM, new Float(2)); label1.getStyle().setStyleProperty(ElementStyleKeys.POS_X, new Float(0)); label1.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, new Float(0)); header.addElement(label1); final Element label2 = new Element(); label2.setElementType(LabelType.INSTANCE); label2.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "DROPPED"); label2.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.NAME, "DROPPED"); label2.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT, ElementAlignment.LEFT); label2.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, new Float(12)); label2.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(100)); label2.getStyle().setStyleProperty(ElementStyleKeys.PADDING_LEFT, new Float(2)); label2.getStyle().setStyleProperty(ElementStyleKeys.PADDING_RIGHT, new Float(2)); label2.getStyle().setStyleProperty(ElementStyleKeys.PADDING_TOP, new Float(2)); label2.getStyle().setStyleProperty(ElementStyleKeys.PADDING_BOTTOM, new Float(2)); label2.getStyle().setStyleProperty(ElementStyleKeys.POS_X, new Float(100)); label2.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, new Float(0)); header.addElement(label2); final Element label3 = new Element(); label3.setElementType(LabelType.INSTANCE); label3.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "DROPPED"); label3.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.NAME, "DROPPED"); label3.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT, ElementAlignment.LEFT); label3.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, new Float(12)); label3.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(100)); label3.getStyle().setStyleProperty(ElementStyleKeys.PADDING_LEFT, new Float(2)); label3.getStyle().setStyleProperty(ElementStyleKeys.PADDING_RIGHT, new Float(2)); label3.getStyle().setStyleProperty(ElementStyleKeys.PADDING_TOP, new Float(2)); label3.getStyle().setStyleProperty(ElementStyleKeys.PADDING_BOTTOM, new Float(2)); label3.getStyle().setStyleProperty(ElementStyleKeys.POS_X, new Float(200)); label3.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, new Float(0)); header.addElement(label3); final Element labelA1 = new Element(); labelA1.setElementType(LabelType.INSTANCE); labelA1.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "COST"); labelA1.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.NAME, "COST"); labelA1.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT, ElementAlignment.LEFT); labelA1.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, new Float(12)); labelA1.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(100)); labelA1.getStyle().setStyleProperty(ElementStyleKeys.PADDING_LEFT, new Float(2)); labelA1.getStyle().setStyleProperty(ElementStyleKeys.PADDING_RIGHT, new Float(2)); labelA1.getStyle().setStyleProperty(ElementStyleKeys.PADDING_TOP, new Float(2)); labelA1.getStyle().setStyleProperty(ElementStyleKeys.PADDING_BOTTOM, new Float(2)); labelA1.getStyle().setStyleProperty(ElementStyleKeys.POS_X, new Float(0)); labelA1.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, new Float(12)); header.addElement(labelA1); final Element labelA2 = new Element(); labelA2.setElementType(LabelType.INSTANCE); labelA2.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "DROPPED"); labelA2.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.NAME, "DROPPED"); labelA2.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT, ElementAlignment.LEFT); labelA2.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, new Float(12)); labelA2.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(100)); labelA2.getStyle().setStyleProperty(ElementStyleKeys.PADDING_LEFT, new Float(2)); labelA2.getStyle().setStyleProperty(ElementStyleKeys.PADDING_RIGHT, new Float(2)); labelA2.getStyle().setStyleProperty(ElementStyleKeys.PADDING_TOP, new Float(2)); labelA2.getStyle().setStyleProperty(ElementStyleKeys.PADDING_BOTTOM, new Float(2)); labelA2.getStyle().setStyleProperty(ElementStyleKeys.POS_X, new Float(100)); labelA2.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, new Float(12)); header.addElement(labelA2); final Element labelA3 = new Element(); labelA3.setElementType(LabelType.INSTANCE); labelA3.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "DROPPED"); labelA3.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.NAME, "DROPPED"); labelA3.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT, ElementAlignment.LEFT); labelA3.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, new Float(12)); labelA3.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(100)); labelA3.getStyle().setStyleProperty(ElementStyleKeys.PADDING_LEFT, new Float(2)); labelA3.getStyle().setStyleProperty(ElementStyleKeys.PADDING_RIGHT, new Float(2)); labelA3.getStyle().setStyleProperty(ElementStyleKeys.PADDING_TOP, new Float(2)); labelA3.getStyle().setStyleProperty(ElementStyleKeys.PADDING_BOTTOM, new Float(2)); labelA3.getStyle().setStyleProperty(ElementStyleKeys.POS_X, new Float(200)); labelA3.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, new Float(12)); header.addElement(labelA3); final Element labelB1 = new Element(); labelB1.setElementType(LabelType.INSTANCE); labelB1.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "COST"); labelB1.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.NAME, "COST"); labelB1.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT, ElementAlignment.LEFT); labelB1.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, new Float(12)); labelB1.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(100)); labelB1.getStyle().setStyleProperty(ElementStyleKeys.PADDING_LEFT, new Float(2)); labelB1.getStyle().setStyleProperty(ElementStyleKeys.PADDING_RIGHT, new Float(2)); labelB1.getStyle().setStyleProperty(ElementStyleKeys.PADDING_TOP, new Float(2)); labelB1.getStyle().setStyleProperty(ElementStyleKeys.PADDING_BOTTOM, new Float(2)); labelB1.getStyle().setStyleProperty(ElementStyleKeys.POS_X, new Float(0)); labelB1.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, new Float(24)); header.addElement(labelB1); final Element labelB2 = new Element(); labelB2.setElementType(LabelType.INSTANCE); labelB2.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "DROPPED"); labelB2.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.NAME, "DROPPED"); labelB2.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT, ElementAlignment.LEFT); labelB2.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, new Float(12)); labelB2.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(100)); labelB2.getStyle().setStyleProperty(ElementStyleKeys.PADDING_LEFT, new Float(2)); labelB2.getStyle().setStyleProperty(ElementStyleKeys.PADDING_RIGHT, new Float(2)); labelB2.getStyle().setStyleProperty(ElementStyleKeys.PADDING_TOP, new Float(2)); labelB2.getStyle().setStyleProperty(ElementStyleKeys.PADDING_BOTTOM, new Float(2)); labelB2.getStyle().setStyleProperty(ElementStyleKeys.POS_X, new Float(100)); labelB2.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, new Float(24)); header.addElement(labelB2); final Element labelB3 = new Element(); labelB3.setElementType(LabelType.INSTANCE); labelB3.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "DROPPED"); labelB3.setAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.NAME, "DROPPED"); labelB3.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT, ElementAlignment.LEFT); labelB3.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, new Float(12)); labelB3.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(100)); labelB3.getStyle().setStyleProperty(ElementStyleKeys.PADDING_LEFT, new Float(2)); labelB3.getStyle().setStyleProperty(ElementStyleKeys.PADDING_RIGHT, new Float(2)); labelB3.getStyle().setStyleProperty(ElementStyleKeys.PADDING_TOP, new Float(2)); labelB3.getStyle().setStyleProperty(ElementStyleKeys.PADDING_BOTTOM, new Float(2)); labelB3.getStyle().setStyleProperty(ElementStyleKeys.POS_X, new Float(200)); labelB3.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, new Float(24)); header.addElement(labelB3); DebugReportRunner.createStreamHTML(report); }
public void testWeirdTocLayout() throws ReportProcessingException, ContentProcessingException { Element textField = new Element(); textField.setName("textField"); textField.getStyle().setStyleProperty(TextStyleKeys.FONT, "Arial"); textField.getStyle().setStyleProperty(TextStyleKeys.FONTSIZE, 14); textField.getStyle().setStyleProperty(TextStyleKeys.TEXT_WRAP, TextWrap.NONE); textField.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, 97f); textField.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, 20f); textField.getStyle().setStyleProperty(ElementStyleKeys.POS_X, 0f); textField.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, 0f); textField.setElementType(LabelType.INSTANCE); textField.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, "Classic Cars"); Element dotField = new Element(); dotField.setName("dotField"); dotField.getStyle().setStyleProperty(TextStyleKeys.FONT, "Arial"); dotField.getStyle().setStyleProperty(TextStyleKeys.FONTSIZE, 14); dotField.getStyle().setStyleProperty(ElementStyleKeys.ALIGNMENT, ElementAlignment.RIGHT); dotField.getStyle().setStyleProperty(ElementStyleKeys.VALIGNMENT, ElementAlignment.TOP); dotField.getStyle().setStyleProperty(ElementStyleKeys.POS_X, 97f); dotField.getStyle().setStyleProperty(ElementStyleKeys.POS_Y, 0f); dotField.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, 628.463f); dotField.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, 20f); dotField.getStyle().setStyleProperty(ElementStyleKeys.WIDTH, 100f); dotField.getStyle().setStyleProperty(ElementStyleKeys.MAX_WIDTH, 100f); dotField.setElementType(LabelType.INSTANCE); dotField.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " + ". . . . . . . . . . . . . . . . . ."); Band band = new Band(); band.setName("outer-box"); band.setLayout("inline"); band.getStyle().setStyleProperty(ElementStyleKeys.BOX_SIZING, BoxSizing.CONTENT_BOX); band.getStyle().setStyleProperty(ElementStyleKeys.OVERFLOW_X, false); band.getStyle().setStyleProperty(ElementStyleKeys.OVERFLOW_Y, false); band.getStyle().setStyleProperty(TextStyleKeys.LINEHEIGHT, 1f); band.getStyle() .setStyleProperty(TextStyleKeys.WHITE_SPACE_COLLAPSE, WhitespaceCollapse.PRESERVE_BREAKS); band.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, 708f); band.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, 12f); band.getStyle().setStyleProperty(ElementStyleKeys.MAX_HEIGHT, 20f); band.addElement(textField); band.addElement(dotField); final MasterReport report = new MasterReport(); report.getReportHeader().addElement(band); LogicalPageBox logicalPageBox = DebugReportRunner.layoutSingleBand(report, report.getReportHeader(), false, false); // ModelPrinter.INSTANCE.print(logicalPageBox); RenderBox outerBox = (RenderBox) MatchFactory.findElementByName(logicalPageBox, "outer-box"); RenderNode dotFieldBox = MatchFactory.findElementByName(logicalPageBox, "dotField"); RenderNode textFieldBox = MatchFactory.findElementByName(logicalPageBox, "textField"); assertNotNull(outerBox); assertNotNull(dotFieldBox); assertNotNull(textFieldBox); assertEquals(0, outerBox.getY()); assertEquals(0, dotFieldBox.getY()); assertEquals(0, textFieldBox.getY()); // box only contains one line, and min-size is set to 8, max size = 20, so the line-height of // 14.024 is used. assertEquals(StrictGeomUtility.toInternalValue(14.024), outerBox.getHeight()); assertEquals(StrictGeomUtility.toInternalValue(14.024), outerBox.getFirstChild().getHeight()); assertEquals(StrictGeomUtility.toInternalValue(14), dotFieldBox.getHeight()); assertEquals(StrictGeomUtility.toInternalValue(14), textFieldBox.getHeight()); }
public ChartEditingResult performEdit( final Element element, final ReportDesignerContext reportDesignerContext) throws CloneNotSupportedException { if (element == null) { throw new NullPointerException(); } if (reportDesignerContext == null) { throw new NullPointerException(); } if (LegacyChartsUtil.isLegacyChartElement(element) == false) { return null; } try { chartTable.setReportDesignerContext(reportDesignerContext); primaryDataSourceTable.setReportDesignerContext(reportDesignerContext); secondaryDataSourceTable.setReportDesignerContext(reportDesignerContext); chartPropertiesTableModel.setActiveContext(reportDesignerContext.getActiveContext()); primaryDataSourcePropertiesTableModel.setActiveContext( reportDesignerContext.getActiveContext()); secondaryDataSourcePropertiesTableModel.setActiveContext( reportDesignerContext.getActiveContext()); final Element editableElement = element.derive(); final Expression chartExpression = editableElement.getAttributeExpression( AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE); final Expression originalPrimaryDataSourceExpression; final Expression originalSecondaryDataSourceExpression; if (chartExpression != null) { originalPrimaryDataSourceExpression = extractPrimaryDatasource(element); originalSecondaryDataSourceExpression = extractSecondaryDatasource(element); editModel.setChartExpression(chartExpression.getInstance()); if (originalPrimaryDataSourceExpression != null) { editModel.setPrimaryDataSource(originalPrimaryDataSourceExpression.getInstance()); } else { editModel.setPrimaryDataSource(null); } if (originalSecondaryDataSourceExpression != null) { editModel.setSecondaryDataSource(originalSecondaryDataSourceExpression.getInstance()); } else { editModel.setSecondaryDataSource(null); } } else { editModel.setChartExpression(null); editModel.setPrimaryDataSource(null); editModel.setSecondaryDataSource(null); originalPrimaryDataSourceExpression = null; originalSecondaryDataSourceExpression = null; } if (editModel.getCurrentChartType() != null) { final ChartType chartType = editModel.getCurrentChartType(); if (editModel.getPrimaryDataSource() == null) { final Class dataSourceImplementation = chartType.getPreferredPrimaryDataSourceImplementation(); final ExpressionMetaData data = ExpressionRegistry.getInstance() .getExpressionMetaData(dataSourceImplementation.getName()); editModel.getPrimaryDataSourcesModel().setSelectedItem(data); } if (editModel.getSecondaryDataSource() == null) { final Class dataSourceImplementation = chartType.getPreferredSecondaryDataSourceImplementation(); if (dataSourceImplementation != null) { final ExpressionMetaData data = ExpressionRegistry.getInstance() .getExpressionMetaData(dataSourceImplementation.getName()); editModel.getSecondaryDataSourcesModel().setSelectedItem(data); } } } if (performEdit() == false) { return null; } secondaryDataSourceTable.stopEditing(); primaryDataSourceTable.stopEditing(); chartTable.stopEditing(); return new ChartEditingResult( chartExpression, originalPrimaryDataSourceExpression, originalSecondaryDataSourceExpression, editModel.getChartExpression(), editModel.getPrimaryDataSource(), editModel.getSecondaryDataSource()); } finally { chartTable.setReportDesignerContext(null); primaryDataSourceTable.setReportDesignerContext(null); secondaryDataSourceTable.setReportDesignerContext(null); chartPropertiesTableModel.setActiveContext(null); primaryDataSourcePropertiesTableModel.setActiveContext(null); secondaryDataSourcePropertiesTableModel.setActiveContext(null); } }
public void update(final Point2D normalizedPoint, final double zoomFactor) { final SnapPositionsModel horizontalSnapModel = getHorizontalSnapModel(); final Element[] selectedVisualElements = getSelectedVisualElements(); final long originPointX = getOriginPointX(); final long[] elementWidth = getElementWidth(); final long px = StrictGeomUtility.toInternalValue(normalizedPoint.getX()); final long dx = px - originPointX; for (int i = 0; i < selectedVisualElements.length; i++) { final Element element = selectedVisualElements[i]; if (element instanceof RootLevelBand) { continue; } final ElementStyleSheet styleSheet = element.getStyle(); final double elementMinWidth = styleSheet.getDoubleStyleProperty(ElementStyleKeys.MIN_WIDTH, 0); // this is where I want the element on a global scale... final long targetWidth = elementWidth[i] + dx; final CachedLayoutData data = ModelUtility.getCachedLayoutData(element); final long elementX = data.getX(); final long targetX2 = elementX + targetWidth; if (elementMinWidth >= 0) { // absolute position; resolving is easy here final long snapPosition = horizontalSnapModel.getNearestSnapPosition(targetX2, element.getObjectID()); if (Math.abs(snapPosition - targetX2) > snapThreshold) { final long localWidth = Math.max(0, targetX2 - elementX); final float position = (float) StrictGeomUtility.toExternalValue(localWidth); styleSheet.setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(position)); } else { final long localWidth = Math.max(0, snapPosition - elementX); final float position = (float) StrictGeomUtility.toExternalValue(localWidth); styleSheet.setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(position)); } } else { final Element parent = element.getParentSection(); final CachedLayoutData parentData = ModelUtility.getCachedLayoutData(parent); final long parentBase = parentData.getWidth(); if (parentBase > 0) { // relative position; resolve the percentage against the height of the parent. final long snapPosition = horizontalSnapModel.getNearestSnapPosition(targetX2, element.getObjectID()); if (Math.abs(snapPosition - targetX2) > snapThreshold) { final long localWidth = Math.max(0, targetX2 - elementX); // strict geometry: all values are multiplied by 1000 // percentages in the engine are represented by floats betwen 0 and 100. final long percentage = StrictGeomUtility.toInternalValue(localWidth * 100 / parentBase); styleSheet.setStyleProperty( ElementStyleKeys.MIN_WIDTH, new Float(StrictGeomUtility.toExternalValue(-percentage))); } else { final long localWidth = Math.max(0, snapPosition - elementX); // strict geometry: all values are multiplied by 1000 // percentages in the engine are represented by floats betwen 0 and 100. final long percentage = StrictGeomUtility.toInternalValue(localWidth * 100 / parentBase); styleSheet.setStyleProperty( ElementStyleKeys.MIN_WIDTH, new Float(StrictGeomUtility.toExternalValue(-percentage))); } } } element.notifyNodePropertiesChanged(); } }
/** * Creates a deep copy of this element and regenerates all instance-ids. * * @param preserveElementInstanceIds defines whether this call generates new instance-ids for the * derived elements. Instance-IDs are used by the report processor to recognize reoccurring * elements and must not changed within the report run. Outside of the report processors new * instance ids should be generated at all times to separate instances and to make them * uniquely identifiable. * @return the copy of the element. */ public Element derive(final boolean preserveElementInstanceIds) { try { final Element e = (Element) super.clone(); e.elementContext = null; if (preserveElementInstanceIds == false) { e.treeLock = new InstanceID(); } e.style = (InternalElementStyleSheet) style.derive(preserveElementInstanceIds); e.datasource = datasource.clone(); e.parent = null; e.style.updateElementReference(e); e.attributes = attributes.clone(); e.copyOnWrite = false; final ElementMetaData metaData = e.getMetaData(); final String[] namespaces = e.attributes.getNameSpaces(); for (int i = 0; i < namespaces.length; i++) { final String namespace = namespaces[i]; final Map attrsNs = attributes.getAttributes(namespace); final Iterator it = attrsNs.entrySet().iterator(); while (it.hasNext()) { final Map.Entry entry = (Map.Entry) it.next(); final Object value = entry.getValue(); final String name = (String) entry.getKey(); final AttributeMetaData data = metaData.getAttributeDescription(namespace, name); if (data == null) { if (logger.isDebugEnabled()) { logger.debug( getElementTypeName() + ": Attribute " + namespace + "|" + name + " is not listed in the metadata."); } } if (value instanceof Cloneable) { e.attributes.setAttribute(namespace, name, ObjectUtilities.clone(value)); } else if (data == null || data.isComputed() == false || data.isDesignTimeValue()) { e.attributes.setAttribute(namespace, name, value); } else { e.attributes.setAttribute(namespace, name, null); } } } if (e.cachedAttributes != null && e.attributes.getChangeTracker() != e.cachedAttributes.getChangeTracker()) { e.cachedAttributes = null; } if (attributeExpressions != null) { e.attributeExpressions = attributeExpressions.clone(); final String[] attrExprNamespaces = e.attributeExpressions.getNameSpaces(); for (int i = 0; i < attrExprNamespaces.length; i++) { final String namespace = attrExprNamespaces[i]; final Map attrsNs = attributeExpressions.getAttributes(namespace); final Iterator it = attrsNs.entrySet().iterator(); while (it.hasNext()) { final Map.Entry entry = (Map.Entry) it.next(); final Expression exp = (Expression) entry.getValue(); e.attributeExpressions.setAttribute( namespace, (String) entry.getKey(), exp.getInstance()); } } } if (styleExpressions != null) { //noinspection unchecked e.styleExpressions = (HashMap<StyleKey, Expression>) styleExpressions.clone(); final Iterator<Map.Entry<StyleKey, Expression>> styleExpressionsIt = e.styleExpressions.entrySet().iterator(); while (styleExpressionsIt.hasNext()) { final Map.Entry<StyleKey, Expression> entry = styleExpressionsIt.next(); final Expression exp = entry.getValue(); entry.setValue(exp.getInstance()); } } return e; } catch (CloneNotSupportedException cne) { throw new IllegalStateException(cne); } }
/** * Clones this Element, the datasource and the private stylesheet of this Element. The clone does * no longer have a parent, as the old parent would not recognize that new object anymore. * * @return a clone of this Element. */ public Element clone() { try { final Element e = (Element) super.clone(); e.style = (InternalElementStyleSheet) style.clone(); e.datasource = datasource.clone(); e.parent = null; e.style.updateElementReference(e); e.elementContext = null; if (attributeExpressions != null) { e.attributes = attributes.clone(); e.attributeExpressions = attributeExpressions.clone(); final String[] namespaces = e.attributeExpressions.getNameSpaces(); for (int i = 0; i < namespaces.length; i++) { final String namespace = namespaces[i]; final Map<String, Expression> attrsNs = attributeExpressions.getAttributes(namespace); for (final Map.Entry<String, Expression> entry : attrsNs.entrySet()) { final Expression exp = entry.getValue(); e.attributeExpressions.setAttribute( namespace, entry.getKey(), (Expression) exp.clone()); } } } else { if (e.cachedAttributes != null) { e.attributes = attributes; e.copyOnWrite = true; copyOnWrite = true; } else { e.copyOnWrite = false; e.attributes = attributes.clone(); } } if (styleExpressions != null) { e.styleExpressions = (HashMap<StyleKey, Expression>) styleExpressions.clone(); for (final Map.Entry<StyleKey, Expression> entry : e.styleExpressions.entrySet()) { final Expression exp = entry.getValue(); entry.setValue((Expression) exp.clone()); } } return e; } catch (CloneNotSupportedException cne) { throw new IllegalStateException(cne); } }
public void copyInto(final Element target) { final ElementMetaData metaData = getMetaData(); final String[] attributeNamespaces = getAttributeNamespaces(); for (int i = 0; i < attributeNamespaces.length; i++) { final String namespace = attributeNamespaces[i]; final String[] attributeNames = getAttributeNames(namespace); for (int j = 0; j < attributeNames.length; j++) { final String name = attributeNames[j]; final AttributeMetaData attributeDescription = metaData.getAttributeDescription(namespace, name); if (attributeDescription == null) { continue; } if (attributeDescription.isTransient()) { continue; } if (attributeDescription.isComputed()) { continue; } if (AttributeNames.Core.ELEMENT_TYPE.equals(name) && AttributeNames.Core.NAMESPACE.equals(namespace)) { continue; } target.setAttribute(namespace, name, getAttribute(namespace, name), false); } } final String[] attrExprNamespaces = getAttributeExpressionNamespaces(); for (int i = 0; i < attrExprNamespaces.length; i++) { final String namespace = attrExprNamespaces[i]; final String[] attributeNames = getAttributeExpressionNames(namespace); for (int j = 0; j < attributeNames.length; j++) { final String name = attributeNames[j]; final AttributeMetaData attributeDescription = metaData.getAttributeDescription(namespace, name); if (attributeDescription == null) { continue; } if (attributeDescription.isTransient()) { continue; } target.setAttributeExpression(namespace, name, getAttributeExpression(namespace, name)); } } final ElementStyleSheet styleSheet = getStyle(); final StyleKey[] styleKeys = styleSheet.getDefinedPropertyNamesArray(); for (int i = 0; i < styleKeys.length; i++) { final StyleKey styleKey = styleKeys[i]; if (styleKey != null) { target.getStyle().setStyleProperty(styleKey, styleSheet.getStyleProperty(styleKey)); } } final Set<Map.Entry<StyleKey, Expression>> styleExpressionEntries = getStyleExpressions().entrySet(); for (final Map.Entry<StyleKey, Expression> entry : styleExpressionEntries) { target.setStyleExpression(entry.getKey(), entry.getValue()); } }