/** * Function that reads the legend properties, specific item properties, dynamic properties and * data and converts it to an Item using the specified reader. * * @param reader the XML reader to read the data from * @param newItemIndex used to create the Item * @return * @throws XMLStreamException */ public Item readXMLToItem(XMLStreamReader reader, Integer newItemIndex) throws XMLStreamException { Item item = createNewLegendItem(null); item.setData(LegendItem.ITEM_INDEX, newItemIndex); // opening renderer reader.nextTag(); readXMLToRenderer(reader, item); // opening legend properties reader.nextTag(); ArrayList<PreviewProperty> legendProperties = readXMLToLegendProperties(reader, item); // opening own properties reader.nextTag(); ArrayList<PreviewProperty> ownProperties = readXMLToOwnProperties(reader, item); // opening dynamic properties reader.nextTag(); ArrayList<PreviewProperty> dynamicProperties = readXMLToDynamicProperties(reader, item); // closing dynamic properties // data reader.nextTag(); readXMLToData(reader, item); // finish reading reader.next(); PreviewProperty[] legendPropertiesArray = legendProperties.toArray(new PreviewProperty[legendProperties.size()]); PreviewProperty[] ownPropertiesArray = ownProperties.toArray(new PreviewProperty[ownProperties.size()]); PreviewProperty[] dynamicPropertiesArray = dynamicProperties.toArray(new PreviewProperty[dynamicProperties.size()]); // setting data item.setData(LegendItem.ITEM_INDEX, newItemIndex); item.setData(LegendItem.OWN_PROPERTIES, ownPropertiesArray); item.setData(LegendItem.PROPERTIES, legendPropertiesArray); item.setData(LegendItem.HAS_DYNAMIC_PROPERTIES, hasDynamicProperties()); item.setData(LegendItem.DYNAMIC_PROPERTIES, dynamicPropertiesArray); item.setData(LegendItem.IS_SELECTED, Boolean.FALSE); item.setData(LegendItem.IS_BEING_TRANSFORMED, Boolean.FALSE); item.setData(LegendItem.CURRENT_TRANSFORMATION, ""); return item; }
private void createDefaultProperties(Integer newItemIndex, Item item) { item.setData(LegendItem.ITEM_INDEX, newItemIndex); item.setData(LegendItem.PROPERTIES, createLegendProperties(item)); item.setData(LegendItem.OWN_PROPERTIES, createLegendOwnProperties(item)); item.setData(LegendItem.NUMBER_OF_DYNAMIC_PROPERTIES, 0); item.setData(LegendItem.HAS_DYNAMIC_PROPERTIES, hasDynamicProperties()); item.setData(LegendItem.DYNAMIC_PROPERTIES, new PreviewProperty[0]); item.setData(LegendItem.IS_SELECTED, Boolean.FALSE); item.setData(LegendItem.IS_BEING_TRANSFORMED, Boolean.FALSE); item.setData(LegendItem.CURRENT_TRANSFORMATION, ""); }
public void readXMLToRenderer(XMLStreamReader reader, Item item) throws XMLStreamException { if (reader.getLocalName().equals(XML_RENDERER)) { String valueString = reader.getElementText(); System.out.println("@Var: renderer.... " + valueString); LegendItemRenderer availableRenderer = LegendController.getInstance().getRenderers().get(valueString); System.out.println("@Var: renderer.... " + availableRenderer); if (availableRenderer != null) { item.setData(LegendItem.RENDERER, availableRenderer); } } }
private PreviewProperty[] createLegendProperties(Item item) { if (setDefaultValues()) { updateDefaultValues(); } int[] properties = LegendProperty.LIST_OF_PROPERTIES; PreviewProperty[] previewProperties = new PreviewProperty[defaultValuesArrayList.size()]; // creating label Integer itemIndex = item.getData(LegendItem.ITEM_INDEX); previewProperties[0] = createLegendProperty( item, LegendProperty.LABEL, defaultLabel + itemIndex + " [" + item.getType() + "]"); for (int i = 1; i < previewProperties.length; i++) { previewProperties[i] = createLegendProperty(item, properties[i], defaultValuesArrayList.get(i)); } return previewProperties; }
/** * Function that takes an item and saves its data, legend properties, specific item properties, * dynamic properties and data using the specified writer. * * @param writer the XMLStreamWriter to write to * @param item the item to be saved * @param previewProperties Current workspace PreviewProperties * @throws XMLStreamException */ public void writeXMLFromItem( XMLStreamWriter writer, Item item, PreviewProperties previewProperties) throws XMLStreamException { // legend type writer.writeStartElement(XML_LEGEND_TYPE); writer.writeCharacters(item.getType()); writer.writeEndElement(); // renderer writer.writeStartElement(XML_RENDERER); System.out.println("" + item.getData(LegendItem.RENDERER).getClass().getName()); writer.writeCharacters(item.getData(LegendItem.RENDERER).getClass().getName()); writer.writeEndElement(); // legend properties writer.writeStartElement(XML_LEGEND_PROPERTY); PreviewProperty[] legendProperties = item.getData(LegendItem.PROPERTIES); for (PreviewProperty property : legendProperties) { writeXMLFromSingleProperty(writer, property, previewProperties); } writer.writeEndElement(); // own properties writer.writeStartElement(XML_OWN_PROPERTY); writeXMLFromItemOwnProperties(writer, item, previewProperties); writer.writeEndElement(); // dynamic properties writer.writeStartElement(XML_DYNAMIC_PROPERTY); writeXMLFromDynamicProperties(writer, item, previewProperties); writer.writeEndElement(); // data writer.writeStartElement(XML_DATA); writeXMLFromData(writer, item, previewProperties); writer.writeEndElement(); }
private PreviewProperty createLegendProperty(Item item, int property, Object value) { PreviewProperty previewProperty = null; Integer itemIndex = item.getData(LegendItem.ITEM_INDEX); String propertyString = LegendModel.getProperty(LegendProperty.LEGEND_PROPERTIES, itemIndex, property); switch (property) { case LegendProperty.LABEL: { previewProperty = PreviewProperty.createProperty( this, propertyString, String.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.label.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.label.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.IS_DISPLAYING: { previewProperty = PreviewProperty.createProperty( this, propertyString, Boolean.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.isDisplaying.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.isDisplaying.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.USER_ORIGIN_X: { previewProperty = PreviewProperty.createProperty( this, propertyString, Float.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.originX.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.originX.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.USER_ORIGIN_Y: { previewProperty = PreviewProperty.createProperty( this, propertyString, Float.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.originY.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.originY.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.WIDTH: { previewProperty = PreviewProperty.createProperty( this, propertyString, Float.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.width.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.width.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.HEIGHT: { previewProperty = PreviewProperty.createProperty( this, propertyString, Float.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.height.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.height.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.BACKGROUND_IS_DISPLAYING: { previewProperty = PreviewProperty.createProperty( this, propertyString, Boolean.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.background.isDisplaying.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.background.isDisplaying.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.BACKGROUND_COLOR: { previewProperty = PreviewProperty.createProperty( this, propertyString, Color.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.background.color.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.background.color.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.BORDER_IS_DISPLAYING: { previewProperty = PreviewProperty.createProperty( this, propertyString, Boolean.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.border.isDisplaying.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.border.isDisplaying.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.BORDER_COLOR: { previewProperty = PreviewProperty.createProperty( this, propertyString, Color.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.border.color.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.border.color.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.BORDER_LINE_THICK: { previewProperty = PreviewProperty.createProperty( this, propertyString, Integer.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.border.lineThick.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.border.lineThick.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.TITLE_IS_DISPLAYING: { previewProperty = PreviewProperty.createProperty( this, propertyString, Boolean.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.title.isDisplaying.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.title.isDisplaying.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.TITLE: { previewProperty = PreviewProperty.createProperty( this, propertyString, String.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.title.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.title.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.TITLE_FONT: { previewProperty = PreviewProperty.createProperty( this, propertyString, Font.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.title.font.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.title.font.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.TITLE_FONT_COLOR: { previewProperty = PreviewProperty.createProperty( this, propertyString, Color.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.title.font.color.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.title.font.color.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.TITLE_ALIGNMENT: { previewProperty = PreviewProperty.createProperty( this, propertyString, Alignment.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.title.alignment.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.title.alignment.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.DESCRIPTION_IS_DISPLAYING: { previewProperty = PreviewProperty.createProperty( this, propertyString, Boolean.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.description.isDisplaying.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.description.isDisplaying.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.DESCRIPTION: { previewProperty = PreviewProperty.createProperty( this, propertyString, String.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.description.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.description.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.DESCRIPTION_FONT: { previewProperty = PreviewProperty.createProperty( this, propertyString, Font.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.description.font.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.description.font.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.DESCRIPTION_FONT_COLOR: { previewProperty = PreviewProperty.createProperty( this, propertyString, Color.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.description.font.color.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.description.font.color.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); break; } case LegendProperty.DESCRIPTION_ALIGNMENT: { previewProperty = PreviewProperty.createProperty( this, propertyString, Alignment.class, NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.description.alignment.displayName"), NbBundle.getMessage( AbstractLegendItemBuilder.class, "LegendItem.property.description.alignment.description"), PreviewProperty.CATEGORY_LEGEND_PROPERTY) .setValue(value); } } return previewProperty; }