/*
* Copyright 2017 Esri.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.esri.samples.symbology.symbol_dictionary;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class SymbolDictionarySample extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/fxml/symbol_dictionary.fxml"));
Scene scene = new Scene(root);
// set title, size, and add scene to stage
stage.setTitle("Symbol Dictionary Sample");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(scene);
stage.show();
}
/**
* Opens and runs application.
*
* @param args arguments passed to this application
*/
public static void main(String[] args) {
Application.launch(args);
}
}
Loading
Code
/*
* Copyright 2017 Esri.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.esri.samples.symbology.symbol_dictionary;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import javafx.scene.control.Pagination;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
import com.esri.arcgisruntime.concurrent.ListenableFuture;
import com.esri.arcgisruntime.symbology.DictionarySymbolStyle;
import com.esri.arcgisruntime.symbology.SymbolStyleSearchParameters;
import com.esri.arcgisruntime.symbology.SymbolStyleSearchResult;
public class SymbolDictionaryController {
@FXML private TextField nameField;
@FXML private TextField tagField;
@FXML private TextField symbolClassField;
@FXML private TextField categoryField;
@FXML private TextField keyField;
@FXML private Text searchResultsFound;
@FXML private Pagination resultPages;
private ObservableList<SymbolStyleSearchResult> results;
private DictionarySymbolStyle dictionarySymbol;
private static final int MAX_RESULTS_PER_PAGE = 20;
public void initialize() {
// loads a specification for the symbol dictionary
dictionarySymbol = new DictionarySymbolStyle("mil2525d");
dictionarySymbol.loadAsync();
// initialize result list
results = FXCollections.observableArrayList();
// add listener to update pagination control when results change
results.addListener((ListChangeListener<SymbolStyleSearchResult>) e -> {
int resultSize = results.size();
resultPages.setPageCount(resultSize / MAX_RESULTS_PER_PAGE + 1);
resultPages.setCurrentPageIndex(0);
resultPages.setPageFactory(pageIndex -> {
ListView<SymbolView> resultsList = new ListView<>();
int start = pageIndex * MAX_RESULTS_PER_PAGE;
List<SymbolView> resultViews = results.subList(start, Math.min(start + MAX_RESULTS_PER_PAGE, results.size()))
.stream()
.map(SymbolView::new)
.collect(Collectors.toList());
resultsList.getItems().addAll(resultViews);
return resultsList;
});
});
}
/**
* Searches through the symbol dictionary using the text from the search fields.
*/
@FXML
private void handleSearchAction() {
// get parameters from input fields
SymbolStyleSearchParameters searchParameters = new SymbolStyleSearchParameters();
searchParameters.getNames().add(nameField.getText());
searchParameters.getTags().add(tagField.getText());
searchParameters.getSymbolClasses().add(symbolClassField.getText());
searchParameters.getCategories().add(categoryField.getText());
searchParameters.getKeys().add(keyField.getText());
// search for any matching symbols
ListenableFuture<List<SymbolStyleSearchResult>> search = dictionarySymbol.searchSymbolsAsync(searchParameters);
search.addDoneListener(() -> {
try {
// update the result list (triggering the listener)
List<SymbolStyleSearchResult> searchResults = search.get();
searchResultsFound.setText(String.valueOf(searchResults.size()));
results.clear();
results.addAll(searchResults);
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
});
}
/**
* Clears search results and any text in the search fields.
*/
@FXML
private void handleClearAction() {
nameField.clear();
tagField.clear();
symbolClassField.clear();
categoryField.clear();
keyField.clear();
results.clear();
searchResultsFound.setText("");
}
}
/*
* Copyright 2016 Esri.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.esri.samples.symbology.symbol_dictionary;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.concurrent.ExecutionException;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import com.esri.arcgisruntime.concurrent.ListenableFuture;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.symbology.Symbol;
import com.esri.arcgisruntime.symbology.SymbolStyleSearchResult;
class SymbolView extends HBox implements Initializable {
@FXML private ImageView imageView;
@FXML private Label name;
@FXML private Label tags;
@FXML private Label symbolClass;
@FXML private Label category;
@FXML private Label key;
private final SymbolStyleSearchResult styleSymbolSearchResult;
/**
* Creates a view of a symbol with a picture and description.
*
* @param symbolResult symbol result from a symbol dictionary search
*/
SymbolView(SymbolStyleSearchResult symbolResult) {
styleSymbolSearchResult = symbolResult;
// Set the view of this component to the fxml file
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/symbol_dictionary_view.fxml"));
loader.setRoot(this);
loader.setController(this);
try {
loader.load();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void initialize(URL location, ResourceBundle resources) {
// initialize the component values
name.setText(styleSymbolSearchResult.getName());
tags.setText(styleSymbolSearchResult.getTags().toString());
symbolClass.setText(styleSymbolSearchResult.getSymbolClass());
category.setText(styleSymbolSearchResult.getCategory());
key.setText(styleSymbolSearchResult.getKey());
// set image for non-text symbols
if (!category.getText().startsWith("Text")) {
Symbol symbol = styleSymbolSearchResult.getSymbol();
ListenableFuture<Image> imageResult = symbol.createSwatchAsync(40, 40, 0x00FFFFFF, new Point(0, 0, 0));
imageResult.addDoneListener(() -> {
try {
imageView.setImage(imageResult.get());
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
});
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2017 Esri.
~
~ Licensed under the Apache License, Version 2.0 (the "License"); you may not
~ use this file except in compliance with the License. You may obtain a copy of
~ the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
~ License for the specific language governing permissions and limitations under
~ the License.
-->
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Pagination?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Text?>
<BorderPane fx:controller="com.esri.samples.symbology.symbol_dictionary.SymbolDictionaryController"
xmlns:fx="http://javafx.com/fxml" stylesheets="/css/style.css">
<padding>
<Insets bottom="10"/>
</padding>
<!-- Top Pane for Search Result -->
<top>
<GridPane hgap="10" vgap="10" prefHeight="200">
<padding><Insets top="25" bottom="25" left="25"/></padding>
<Label text="Name: " GridPane.columnIndex="0" GridPane.rowIndex="0"/>
<!-- Search Result Fields -->
<TextField fx:id="nameField" GridPane.columnIndex="1" GridPane.rowIndex="0"/>
<Label text="Tag: " GridPane.columnIndex="0" GridPane.rowIndex="1"/>
<TextField fx:id="tagField" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<Label text="Symbol Class: " GridPane.columnIndex="0" GridPane.rowIndex="2"/>
<TextField fx:id="symbolClassField" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
<Label text="Category: " GridPane.columnIndex="0" GridPane.rowIndex="3"/>
<TextField fx:id="categoryField" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<Label text="Key: " GridPane.columnIndex="0" GridPane.rowIndex="4"/>
<TextField fx:id="keyField" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
<!-- Button Actions-->
<Button text="Search for Symbols" onAction="#handleSearchAction"
GridPane.columnIndex="2" GridPane.rowIndex="5"/>
<HBox alignment="center_right" GridPane.columnIndex="1" GridPane.rowIndex="5">
<Button text="Clear" onAction="#handleClearAction" alignment="bottom_right"/>
</HBox>
<!-- Displaying Results-->
<Label text="Result(s) Found: " GridPane.columnIndex="0" GridPane.rowIndex="6"/>
<Text fx:id="searchResultsFound" GridPane.columnIndex="1" GridPane.rowIndex="6"/>
</GridPane>
</top>
<center>
<Pagination fx:id="resultPages" pageCount="1"/>
</center>
</BorderPane>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2017 Esri.
~
~ Licensed under the Apache License, Version 2.0 (the "License"); you may not
~ use this file except in compliance with the License. You may obtain a copy of
~ the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
~ License for the specific language governing permissions and limitations under
~ the License.
-->
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.GridPane?>
<fx:root type="javafx.scene.layout.HBox" xmlns:fx="http://javafx.com/fxml" spacing="10">
<ImageView fx:id="imageView" fitWidth="40"/>
<GridPane hgap="10" vgap="3">
<Label text="Name:" GridPane.rowIndex="0" GridPane.columnIndex="0"/>
<Label fx:id="name" GridPane.rowIndex="0" GridPane.columnIndex="1"/>
<Label text="Tags:" GridPane.rowIndex="1" GridPane.columnIndex="0"/>
<Label fx:id="tags" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
<Label text="Symbol Class:" GridPane.rowIndex="2" GridPane.columnIndex="0"/>
<Label fx:id="symbolClass" GridPane.rowIndex="2" GridPane.columnIndex="1"/>
<Label text="Category:" GridPane.rowIndex="3" GridPane.columnIndex="0"/>
<Label fx:id="category" GridPane.rowIndex="3" GridPane.columnIndex="1"/>
<Label text="Key:" GridPane.rowIndex="4" GridPane.columnIndex="0"/>
<Label fx:id="key" GridPane.rowIndex="4" GridPane.columnIndex="1"/>
</GridPane>
</fx:root>