/** put all the needed things in the blackboards */
  private void commitToBlackboards(
      JGrassRegion jgR, CoordinateReferenceSystem crs, String windPath) {
    blackboard = getLayer().getMap().getBlackboard();

    style.north = (float) jgR.getNorth();
    style.south = (float) jgR.getSouth();
    style.east = (float) jgR.getEast();
    style.west = (float) jgR.getWest();
    style.rows = jgR.getRows();
    style.cols = jgR.getCols();

    style.windPath = windPath;

    try {

      try {
        Integer epsg = CRS.lookupEpsgCode(crs, true);
        style.crsString = "EPSG:" + epsg;
      } catch (Exception e) {
        // try non epsg
        style.crsString = CRS.lookupIdentifier(crs, true);
      }
    } catch (FactoryException e) {
      e.printStackTrace();
    }

    blackboard.put(ActiveregionStyleContent.ID, style);
    getLayer().setStatus(ILayer.DONE);
  }
  @Override
  protected void refresh() {
    System.out.println("refresh"); // $NON-NLS-1$ //TODO erase this line
    IBlackboard blackboard = getStyleBlackboard();
    LegendStyle style = (LegendStyle) blackboard.get(LegendStyleContent.ID);

    if (style == null) {
      style = LegendStyleContent.createDefault();
      blackboard.put(LegendStyleContent.ID, style);
      ((StyleBlackboard) blackboard).setSelected(new String[] {LegendStyleContent.ID});
    }
  }
  private void checkStyle() {
    IMap activeMap = ApplicationGIS.getActiveMap();

    IBlackboard styleBlackboard = activeMap.getBlackboard();
    if (style == null) {
      style = (RasterLegendStyle) styleBlackboard.get(RasterLegendStyleContent.ID);
    }
    if (style == null) {
      style = RasterLegendStyleContent.createDefault();
      styleBlackboard.put(RasterLegendStyleContent.ID, style);
      // styleBlackboard.setSelected(new String[]{RasterLegendStyleContent.ID});
    }
  }
  private void updateBlackboard() {
    IMap activeMap = ApplicationGIS.getActiveMap();
    IBlackboard styleBlackboard = activeMap.getBlackboard();
    style = (RasterLegendStyle) styleBlackboard.get(RasterLegendStyleContent.ID);

    if (style == null) {
      style = RasterLegendStyleContent.createDefault();
      styleBlackboard.put(RasterLegendStyleContent.ID, style);
      // styleBlackboard.setSelected(new String[]{RasterLegendStyleContent.ID});
    }

    RGB bg = backgroundColour.getColorValue();
    try {
      int bAlpha = Integer.parseInt(backgroundAlphaText.getText());
      style.backgroundColor = new Color(bg.red, bg.green, bg.blue, bAlpha);
    } catch (Exception e) {
      style.backgroundColor = new Color(bg.red, bg.green, bg.blue);
    }
    bg = foregroundColor.getColorValue();
    try {
      int fAlpha = Integer.parseInt(forgroundAlphaText.getText());
      style.foregroundColor = new Color(bg.red, bg.green, bg.blue, fAlpha);
    } catch (Exception e) {
      style.foregroundColor = new Color(bg.red, bg.green, bg.blue);
    }
    bg = fontColour.getColorValue();
    style.fontColor = new Color(bg.red, bg.green, bg.blue);

    style.titleString = titleText.getText();
    style.xPos = Integer.parseInt(xposText.getText());
    style.yPos = Integer.parseInt(yposText.getText());
    style.legendHeight = Integer.parseInt(legHeightText.getText());
    style.legendWidth = Integer.parseInt(legWidthText.getText());
    style.boxWidth = Integer.parseInt(boxWidthText.getText());
    style.isRoundedRectangle = isroundedButton.getSelection();

    styleBlackboard.put(RasterLegendStyleContent.ID, style);
  }
  private void updateBlackboard() {
    IBlackboard blackboard = getStyleBlackboard();
    LegendStyle style = (LegendStyle) blackboard.get(LegendStyleContent.ID);

    if (style == null) {
      style = LegendStyleContent.createDefault();
      blackboard.put(LegendStyleContent.ID, style);
      ((StyleBlackboard) blackboard).setSelected(new String[] {LegendStyleContent.ID});
    }

    RGB bg = backgroundColour.getColorValue();
    style.backgroundColour = new Color(bg.red, bg.green, bg.blue);

    RGB fg = fontColour.getColorValue();
    style.foregroundColour = new Color(fg.red, fg.green, fg.blue);

    style.horizontalMargin = Integer.parseInt(horizontalMargin.getText());
    style.horizontalSpacing = Integer.parseInt(horizontalSpacing.getText());
    style.indentSize = Integer.parseInt(indentSize.getText());
    style.verticalMargin = Integer.parseInt(verticalMargin.getText());
    style.verticalSpacing = Integer.parseInt(verticalSpacing.getText());
  }
  public void createControl(Composite parent) {
    IBlackboard blackboard = getStyleBlackboard();
    LegendStyle style = null;
    if (blackboard != null) {
      style = (LegendStyle) blackboard.get(LegendStyleContent.ID);
    }

    if (style == null) {
      style = LegendStyleContent.createDefault();
      if (blackboard != null) {
        blackboard.put(LegendStyleContent.ID, style);
        ((StyleBlackboard) blackboard).setSelected(new String[] {LegendStyleContent.ID});
      }
    }

    ScrolledComposite scrollComposite = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    Composite composite = new Composite(scrollComposite, SWT.BORDER);

    GridLayout layout = new GridLayout(2, true);
    composite.setLayout(layout);

    GridData layoutData = null;

    Label verticalMarginLabel = new Label(composite, SWT.NONE);
    verticalMarginLabel.setText(Messages.LegendGraphicStyleConfigurator_vertical_margin);
    verticalMarginLabel.setLayoutData(layoutData);
    verticalMargin = new Text(composite, SWT.BORDER);
    verticalMargin.setLayoutData(layoutData);

    Label horizontalMarginLabel = new Label(composite, SWT.NONE);
    horizontalMarginLabel.setLayoutData(layoutData);
    horizontalMarginLabel.setText(Messages.LegendGraphicStyleConfigurator_horizontal_margin);
    horizontalMargin = new Text(composite, SWT.BORDER);
    horizontalMargin.setLayoutData(layoutData);

    Label verticalSpacingLabel = new Label(composite, SWT.NONE);
    verticalSpacingLabel.setLayoutData(layoutData);
    verticalSpacingLabel.setText(Messages.LegendGraphicStyleConfigurator_vertical_spacing);
    verticalSpacing = new Text(composite, SWT.BORDER);
    verticalSpacing.setLayoutData(layoutData);

    Label horizontalSpacingLabel = new Label(composite, SWT.NONE);
    horizontalSpacingLabel.setLayoutData(layoutData);
    horizontalSpacingLabel.setText(Messages.LegendGraphicStyleConfigurator_horizontal_spacing);
    horizontalSpacing = new Text(composite, SWT.BORDER);
    horizontalSpacing.setLayoutData(layoutData);

    Label indentSizeLabel = new Label(composite, SWT.NONE);
    indentSizeLabel.setLayoutData(layoutData);
    indentSizeLabel.setText(Messages.LegendGraphicStyleConfigurator_indent_size);
    indentSize = new Text(composite, SWT.BORDER);
    indentSize.setLayoutData(layoutData);

    Label fontColourLabel = new Label(composite, SWT.NONE);
    fontColourLabel.setLayoutData(layoutData);
    fontColourLabel.setText(Messages.LegendGraphicStyleConfigurator_font_colour);
    fontColour = new ColorEditor(composite);

    Label backgroundColourLabel = new Label(composite, SWT.NONE);
    backgroundColourLabel.setLayoutData(layoutData);
    backgroundColourLabel.setText(Messages.LegendGraphicStyleConfigurator_background_colour);
    backgroundColour = new ColorEditor(composite);

    composite.layout();
    Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    composite.setSize(size);
    scrollComposite.setContent(composite);

    verticalMargin.setText(Integer.toString(style.verticalMargin));
    horizontalMargin.setText(Integer.toString(style.horizontalMargin));
    verticalSpacing.setText(Integer.toString(style.verticalSpacing));
    horizontalSpacing.setText(Integer.toString(style.horizontalSpacing));
    indentSize.setText(Integer.toString(style.indentSize));
    fontColour.setColorValue(
        new RGB(
            style.foregroundColour.getRed(),
            style.foregroundColour.getGreen(),
            style.foregroundColour.getBlue()));
    backgroundColour.setColorValue(
        new RGB(
            style.backgroundColour.getRed(),
            style.backgroundColour.getGreen(),
            style.backgroundColour.getBlue()));

    verticalMargin.addModifyListener(this);
    horizontalMargin.addModifyListener(this);
    verticalSpacing.addModifyListener(this);
    horizontalSpacing.addModifyListener(this);
    indentSize.addModifyListener(this);
    backgroundColour.addSelectionListener(this);
    fontColour.addSelectionListener(this);
  }
 private void dumpActiveRegionStyle(ActiveRegionStyle style) {
   blackboard.put(ActiveregionStyleContent.ID, style);
   // ((StyleBlackboard) blackboard).setSelected(new String[]{ActiveregionStyleContent.ID});
 }
  @Override
  protected void refresh() {
    try {
      IBlackboard blackboard = getLayer().getMap().getBlackboard();

      style = (ActiveRegionStyle) blackboard.get(ActiveregionStyleContent.ID);

      if (style == null) {
        style = ActiveregionStyleContent.createDefault();
        blackboard.put(ActiveregionStyleContent.ID, style);
        // ((StyleBlackboard) styleBlackboard).setSelected(new
        // String[]{ActiveregionStyleContent.ID});
      }

      // first time choose the mapset
      if (style.windPath == null) {
        CatalogJGrassMapsetTreeViewerDialog mapsetDialog =
            new CatalogJGrassMapsetTreeViewerDialog();
        mapsetDialog.open(parent.getShell());
        jGrassMapsetGeoResource = mapsetDialog.getSelectedLayers().get(0);

        JGrassRegion activeRegionWindow = jGrassMapsetGeoResource.getActiveRegionWindow();
        style.windPath = jGrassMapsetGeoResource.getActiveRegionWindowPath();
        style.north = (float) activeRegionWindow.getNorth();
        style.south = (float) activeRegionWindow.getSouth();
        style.west = (float) activeRegionWindow.getWest();
        style.east = (float) activeRegionWindow.getEast();
        style.rows = activeRegionWindow.getRows();
        style.cols = activeRegionWindow.getCols();

        CoordinateReferenceSystem jGrassCrs = jGrassMapsetGeoResource.getLocationCrs();
        try {
          Integer epsg = CRS.lookupEpsgCode(jGrassCrs, true);
          style.crsString = "EPSG:" + epsg;
        } catch (Exception e) {
          // try non epsg
          style.crsString = CRS.lookupIdentifier(jGrassCrs, true);
        }
      }
      windPathText.setText(style.windPath);

      JGrassRegion tmp =
          new JGrassRegion(
              style.west, style.east, style.south, style.north, style.rows, style.cols);
      // set initial values
      isWorking = true;
      northText.setText(String.valueOf(style.north));
      southText.setText(String.valueOf(style.south));
      westText.setText(String.valueOf(style.west));
      eastText.setText(String.valueOf(style.east));
      xresText.setText(String.valueOf(tmp.getWEResolution()));
      yresText.setText(String.valueOf(tmp.getNSResolution()));
      colsText.setText(String.valueOf(style.cols));
      rowsText.setText(String.valueOf(style.rows));
      isWorking = false;

      forgroundAlphaText.setText(Float.toString(style.fAlpha));
      backgroundAlphaText.setText(Float.toString(style.bAlpha));
      foregroundColor.setColorValue(
          new RGB(
              style.foregroundColor.getRed(),
              style.foregroundColor.getGreen(),
              style.foregroundColor.getBlue()));
      backgroundColour.setColorValue(
          new RGB(
              style.backgroundColor.getRed(),
              style.backgroundColor.getGreen(),
              style.backgroundColor.getBlue()));

      CoordinateReferenceSystem crs = CRS.decode(style.crsString);
      commitToBlackboards(tmp, crs, style.windPath);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }