Esempio n. 1
0
 public void savePreset(String name) {
   if (model != null) {
     PreviewModel previewModel = previewController.getModel();
     Map<String, Object> map = new HashMap<String, Object>();
     for (PreviewProperty p : previewModel.getProperties().getProperties()) {
       map.put(p.getName(), p.getValue());
     }
     PreviewPreset preset = new PreviewPreset(name, map);
     presetUtils.savePreset(preset);
     model.setCurrentPreset(preset);
   }
 }
  /**
   * Function that automatically saves a property using its PropertyName and the Value attached to
   * it. Only works if property has a known value type. Known types: <code>Integer</code>, <code>
   *  Float</code>, <code> String</code>,, <code> Color</code>, <code> LegendItem.Alignment</code>,
   * <code> LegendItem.Shape</code> and <code> LegendItem.Direction</code>
   *
   * @param writer the XMLStreamWriter to write to
   * @param property property to be saved
   * @param previewProperties Current workspace PreviewProperties
   * @throws XMLStreamException
   */
  protected void writeXMLFromSingleProperty(
      XMLStreamWriter writer, PreviewProperty property, PreviewProperties previewProperties)
      throws XMLStreamException {
    // Better read from previewProperties instead of just the property, because LegendMouseListener
    // puts origin x and y in previewProperties.
    Object propertyValue = previewProperties.getValue(property.getName());

    if (propertyValue != null) {
      String text = writeValueAsText(propertyValue);
      writer.writeStartElement(XML_PROPERTY);
      String name = LegendModel.getPropertyFromPreviewProperty(property);
      System.out.println("@Var: SAVING XML name: " + name + " , " + text);
      writer.writeAttribute(XML_NAME, name);
      writer.writeAttribute(XML_CLASS, propertyValue.getClass().getName());
      writer.writeCharacters(text);
      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;
  }