Skip to content

Commit 508054f

Browse files
committed
updated sample class name, removed unused imports
1 parent 9f9c9ba commit 508054f

File tree

1 file changed

+118
-126
lines changed

1 file changed

+118
-126
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,118 @@
1-
/*
2-
* Copyright 2016 Esri.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5-
* use this file except in compliance with the License. You may obtain a copy of
6-
* the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13-
* License for the specific language governing permissions and limitations under
14-
* the License.
15-
*/
16-
17-
package com.esri.samples.mapview.take_screen_shot;
18-
19-
import java.awt.image.BufferedImage;
20-
import java.io.File;
21-
import java.util.Optional;
22-
23-
import javax.imageio.ImageIO;
24-
25-
import javafx.application.Application;
26-
import javafx.embed.swing.SwingFXUtils;
27-
import javafx.geometry.Pos;
28-
import javafx.scene.Scene;
29-
import javafx.scene.control.Alert;
30-
import javafx.scene.control.Alert.AlertType;
31-
import javafx.scene.control.Button;
32-
import javafx.scene.control.ButtonBar.ButtonData;
33-
import javafx.scene.control.ButtonType;
34-
import javafx.scene.image.Image;
35-
import javafx.scene.image.ImageView;
36-
import javafx.scene.layout.BorderPane;
37-
import javafx.stage.FileChooser;
38-
import javafx.stage.Stage;
39-
40-
import com.esri.arcgisruntime.concurrent.ListenableFuture;
41-
import com.esri.arcgisruntime.mapping.ArcGISMap;
42-
import com.esri.arcgisruntime.mapping.Basemap;
43-
import com.esri.arcgisruntime.mapping.view.MapView;
44-
45-
public class TakeScreenShot extends Application {
46-
47-
private MapView mapView;
48-
49-
@Override
50-
public void start(Stage stage) throws Exception {
51-
52-
try {
53-
// create stack pane and application scene
54-
BorderPane borderPane = new BorderPane();
55-
Scene scene = new Scene(borderPane);
56-
57-
// set title, size, and add scene to stage
58-
stage.setTitle("Take Screen Shot Sample");
59-
stage.setWidth(800);
60-
stage.setHeight(700);
61-
stage.setScene(scene);
62-
stage.show();
63-
64-
// create map and set to map view
65-
ArcGISMap map = new ArcGISMap(Basemap.createStreets());
66-
mapView = new MapView();
67-
mapView.setMap(map);
68-
69-
// create a file chooser for saving image
70-
final FileChooser fileChooser = new FileChooser();
71-
fileChooser.setInitialFileName("map-screenshot");
72-
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("PNG file (*.png)", "*.png"));
73-
74-
// create button to take screen shot
75-
Button screenShotButton = new Button("Take Screenshot");
76-
screenShotButton.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
77-
screenShotButton.setOnAction(e -> {
78-
// export image from map view
79-
ListenableFuture<Image> mapImage = mapView.exportImageAsync();
80-
mapImage.addDoneListener(() -> {
81-
try {
82-
// get image
83-
Image image = mapImage.get();
84-
// choose a location to save the file
85-
File file = fileChooser.showSaveDialog(stage);
86-
if (file != null) {
87-
// write the image to the save location
88-
ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
89-
}
90-
} catch (Exception ex) {
91-
ex.printStackTrace();
92-
}
93-
});
94-
});
95-
96-
// add the map view to stack pane
97-
borderPane.setCenter(mapView);
98-
borderPane.setBottom(screenShotButton);
99-
} catch (Exception e) {
100-
// on any error, display the stack trace.
101-
e.printStackTrace();
102-
}
103-
}
104-
105-
/**
106-
* Stops and releases all resources used in application.
107-
*/
108-
@Override
109-
public void stop() throws Exception {
110-
111-
if (mapView != null) {
112-
mapView.dispose();
113-
}
114-
}
115-
116-
/**
117-
* Opens and runs application.
118-
*
119-
* @param args arguments passed to this application
120-
*/
121-
public static void main(String[] args) {
122-
123-
Application.launch(args);
124-
}
125-
126-
}
1+
/*
2+
* Copyright 2016 Esri.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package com.esri.samples.mapview.take_screen_shot;
18+
19+
import java.io.File;
20+
21+
import javax.imageio.ImageIO;
22+
23+
import com.esri.arcgisruntime.concurrent.ListenableFuture;
24+
import com.esri.arcgisruntime.mapping.ArcGISMap;
25+
import com.esri.arcgisruntime.mapping.Basemap;
26+
import com.esri.arcgisruntime.mapping.view.MapView;
27+
28+
import javafx.application.Application;
29+
import javafx.embed.swing.SwingFXUtils;
30+
import javafx.scene.Scene;
31+
import javafx.scene.control.Button;
32+
import javafx.scene.image.Image;
33+
import javafx.scene.layout.BorderPane;
34+
import javafx.stage.FileChooser;
35+
import javafx.stage.Stage;
36+
37+
public class TakeScreenShotSample extends Application {
38+
39+
private MapView mapView;
40+
41+
@Override
42+
public void start(Stage stage) throws Exception {
43+
44+
try {
45+
// create stack pane and application scene
46+
BorderPane borderPane = new BorderPane();
47+
Scene scene = new Scene(borderPane);
48+
49+
// set title, size, and add scene to stage
50+
stage.setTitle("Take Screen Shot Sample");
51+
stage.setWidth(800);
52+
stage.setHeight(700);
53+
stage.setScene(scene);
54+
stage.show();
55+
56+
// create map and set to map view
57+
ArcGISMap map = new ArcGISMap(Basemap.createStreets());
58+
mapView = new MapView();
59+
mapView.setMap(map);
60+
61+
// create a file chooser for saving image
62+
final FileChooser fileChooser = new FileChooser();
63+
fileChooser.setInitialFileName("map-screenshot");
64+
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("PNG file (*.png)", "*.png"));
65+
66+
// create button to take screen shot
67+
Button screenShotButton = new Button("Take Screenshot");
68+
screenShotButton.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
69+
screenShotButton.setOnAction(e -> {
70+
// export image from map view
71+
ListenableFuture<Image> mapImage = mapView.exportImageAsync();
72+
mapImage.addDoneListener(() -> {
73+
try {
74+
// get image
75+
Image image = mapImage.get();
76+
// choose a location to save the file
77+
File file = fileChooser.showSaveDialog(stage);
78+
if (file != null) {
79+
// write the image to the save location
80+
ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
81+
}
82+
} catch (Exception ex) {
83+
ex.printStackTrace();
84+
}
85+
});
86+
});
87+
88+
// add the map view to stack pane
89+
borderPane.setCenter(mapView);
90+
borderPane.setBottom(screenShotButton);
91+
} catch (Exception e) {
92+
// on any error, display the stack trace.
93+
e.printStackTrace();
94+
}
95+
}
96+
97+
/**
98+
* Stops and releases all resources used in application.
99+
*/
100+
@Override
101+
public void stop() throws Exception {
102+
103+
if (mapView != null) {
104+
mapView.dispose();
105+
}
106+
}
107+
108+
/**
109+
* Opens and runs application.
110+
*
111+
* @param args arguments passed to this application
112+
*/
113+
public static void main(String[] args) {
114+
115+
Application.launch(args);
116+
}
117+
118+
}

0 commit comments

Comments
 (0)