public void preApply() { // collect new info for the active region double n = Double.parseDouble(northText.getText()); double s = Double.parseDouble(southText.getText()); double w = Double.parseDouble(westText.getText()); double e = Double.parseDouble(eastText.getText()); double xr = Double.parseDouble(xresText.getText()); double yr = Double.parseDouble(yresText.getText()); // write the region to file JGrassRegion newRegion = new JGrassRegion(w, e, s, n, xr, yr); try { File mapsetFile = new File(style.windPath).getParentFile(); File locationFile = mapsetFile.getParentFile(); JGrassRegion.writeWINDToMapset(mapsetFile.getAbsolutePath(), newRegion); CoordinateReferenceSystem locationCrs = JGrassCatalogUtilities.getLocationCrs(locationFile.getAbsolutePath()); style.fAlpha = Float.parseFloat(forgroundAlphaText.getText()); style.bAlpha = Float.parseFloat(backgroundAlphaText.getText()); RGB bg = backgroundColour.getColorValue(); style.backgroundColor = new Color(bg.red, bg.green, bg.blue); bg = foregroundColor.getColorValue(); style.foregroundColor = new Color(bg.red, bg.green, bg.blue); style.doGrid = gridButton.getSelection(); commitToBlackboards(newRegion, locationCrs, style.windPath); super.preApply(); } catch (IOException e1) { e1.printStackTrace(); } }
/** 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); }
private void updateBlackboard() { ActiveRegionStyle style = getActiveRegionStyle(); 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 bAlpha = Integer.parseInt(forgroundAlphaText.getText()); style.foregroundColor = new Color(bg.red, bg.green, bg.blue, bAlpha); } catch (Exception e) { style.foregroundColor = new Color(bg.red, bg.green, bg.blue); } dumpActiveRegionStyle(style); }
@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(); } }