private void readEvents() { frame .getGlassPane() .setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); // run event reader runEventReader(currentEventFile); // initialize map viewer if (this.jMapViewer == null) loadMapView(); // get data from eventhandler (if not null) if (eventHandler != null) { eventHandler.setColorationMode(this.colorationMode); eventHandler.setTransparency(this.cellTransparency); eventHandler.setK(k); // get data EventData data = eventHandler.getData(); // update data in both the map viewer and the graphs jMapViewer.updateEventData(data); graphPanel.updateData(data); keyPanel.updateData(data); } frame .getGlassPane() .setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); }
/** save, open and (re)calculate events */ @Override public void actionPerformed(ActionEvent e) { /** Save heatmap shape and graphs */ if (e.getActionCommand() == "Save") { if (eventHandler != null) { jMapViewer.disableForSaving(true); jMapViewer.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(currentDirectory)); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setFileFilter( new FileFilter() { @Override public String getDescription() { return "choose directory for the TIFF export"; } @Override public boolean accept(File f) { if (f.isDirectory()) return true; else return false; } }); int returnVal = fc.showSaveDialog(this.frame); if (returnVal == JFileChooser.APPROVE_OPTION) { // open file File directory = fc.getSelectedFile(); currentDirectory = directory.toString(); Rect boundingBox = eventHandler.getData().getBoundingBox(); double gridSize = eventHandler.getData().getCellSize(); Coord minValues = this.ctInverse.transform( new CoordImpl(boundingBox.minX - gridSize / 2, boundingBox.minY - gridSize / 2)); Coord maxValues = this.ctInverse.transform( new CoordImpl(boundingBox.maxX + gridSize / 2, boundingBox.maxY + gridSize / 2)); double westmost = minValues.getX(); double soutmost = minValues.getY(); double eastmost = maxValues.getX(); double northmost = maxValues.getY(); Envelope2D env = new Envelope2D( DefaultGeographicCRS.WGS84, westmost, soutmost, eastmost - westmost, northmost - soutmost); BufferedImage imgEvacuation = jMapViewer.getGridAsImage(Mode.EVACUATION, exportSize, exportSize); BufferedImage imgClearing = jMapViewer.getGridAsImage(Mode.CLEARING, exportSize, exportSize); BufferedImage imgUtilization = jMapViewer.getGridAsImage(Mode.UTILIZATION, exportSize, exportSize); String filePrefix = directory.toString() + "/" + currentEventFile.getName() + "_2_"; try { TiffExporter.writeGEOTiff(env, filePrefix + Mode.EVACUATION + ".tiff", imgEvacuation); TiffExporter.writeGEOTiff(env, filePrefix + Mode.CLEARING + ".tiff", imgClearing); TiffExporter.writeGEOTiff(env, filePrefix + Mode.UTILIZATION + ".tiff", imgUtilization); } catch (IOException e1) { e1.printStackTrace(); } finally { jMapViewer.disableForSaving(false); jMapViewer.setCursor(Cursor.getDefaultCursor()); } } jMapViewer.disableForSaving(false); jMapViewer.setCursor(Cursor.getDefaultCursor()); } } /** Open MATSim config file. */ if (e.getActionCommand() == "Open") { final JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(currentDirectory)); fc.setFileFilter( new FileFilter() { @Override public String getDescription() { return "MATSim config file"; } @Override public boolean accept(File f) { if (f.isDirectory()) { return true; } if (f.getName().endsWith("xml")) { return true; } return false; } }); int returnVal = fc.showOpenDialog(this.frame); if (returnVal == JFileChooser.APPROVE_OPTION) { // open file File file = fc.getSelectedFile(); log.info("Opening: " + file.getAbsolutePath() + "."); this.configFile = file.getAbsolutePath(); file.getParent(); Config c = ConfigUtils.loadConfig(this.configFile); this.sc = ScenarioUtils.loadScenario(c); String shp = this.sc.getConfig().getModule("grips").getValue("evacuationAreaFile"); // read the shape file readShapeFile(shp); // get events file, check if there is at least the very first // iteration this.itersOutputDir = this.sc.getConfig().getModule("controler").getValue("outputDirectory"); // get all available events eventFiles = getAvailableEventFiles(this.itersOutputDir); // check if empty if (eventFiles.isEmpty()) { JOptionPane.showMessageDialog( this.frame, "Could not find any event files", "Event files unavailable", JOptionPane.ERROR_MESSAGE); return; } currentEventFile = eventFiles.get(0); iterationsList.removeAllItems(); for (File eventFile : eventFiles) { String shortenedFileName = eventFile.getName(); iterationsList.addItem(shortenedFileName); } // read events readEvents(); // update buttons this.openBtn.setEnabled(false); this.saveButton.setEnabled(true); this.calcButton.setEnabled(true); this.ctInverse = new GeotoolsTransformation( this.getScenario().getConfig().global().getCoordinateSystem(), "EPSG:4326"); this.firstLoad = false; } else { log.info("Open command cancelled by user."); } } if (e.getActionCommand() == "calculate") { runCalculation(); } if ((e.getActionCommand() == "changeIteration") && (!firstLoad)) { System.out.println("(looking for \"" + iterationsList.getSelectedItem() + "\")"); File newFile = getEventPathFromName("" + iterationsList.getSelectedItem()); if (newFile != null) { currentEventFile = newFile; System.out.println("current event file: " + newFile.getAbsoluteFile()); } if (!useCalculateButton) runCalculation(); } if (e.getActionCommand() == "changeMode") { setMode((Mode) modeList.getSelectedItem()); } }