arcgissamples\soe\pp\PropertyPageUI.java
/* Copyright 2015 ESRI * * All rights reserved under the copyright laws of the United States * and applicable international laws, treaties, and conventions. * * You may freely redistribute and use this sample code, with or * without modification, provided you include the original copyright * notice and use restrictions. * * See the use restrictions at <your ArcGIS install location>/DeveloperKit10.4/userestrictions.txt. * */ package arcgissamples.soe.pp; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.Insets; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Enumeration; import javax.swing.AbstractButton; import javax.swing.ButtonGroup; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; import javax.swing.event.CaretEvent; import javax.swing.event.CaretListener; public class PropertyPageUI extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; private JPanel theRootPanel = null; private JPanel radioButtonPanel = null; private ButtonGroup radioButtonGrp = null; private JCheckBox isEditableCheckBox = null; private JComboBox returnFormatComboBox = null; private JTextField numFeaturesTextField = null; private JavaSimpleRESTSOEWithPropertiesPropPage propertyPage = null; public PropertyPageUI() { super(); } public PropertyPageUI(JavaSimpleRESTSOEWithPropertiesPropPage pp) { super(); this.propertyPage = pp; initialize(); } /** * Creates a user interface with the following structure * * JFrame | ContentPane | JPanel | Label : JPanel [Radio Button 1, Radio * Button 2, Radio Button 3] Label : ComboBox Label : CheckBox Label : * TextBox * * @return */ private void initialize() { this.setSize(300, 300); this.setContentPane(getJContentPane()); } /** * Initializes the User interface with default initial values. * * @param soeName * @param streetName * @param distance * @param poiTypes */ public void initPage(String soeName, String layerType, String returnFormat, String numFeatures, boolean isEditable) { /* Set layer type */ if (layerType != null && !layerType.equals("")) { Enumeration<AbstractButton> buttons = radioButtonGrp.getElements(); while (buttons.hasMoreElements()) { JRadioButton theButton = (JRadioButton) buttons.nextElement(); if (theButton.getText().equalsIgnoreCase(layerType)) theButton.setSelected(true); } } /* Set return format */ if (returnFormat != null && !returnFormat.equals("")) { returnFormatComboBox.setSelectedItem(returnFormat.toUpperCase()); } /* Set num Features */ if (Integer.valueOf(numFeatures) > 0) numFeaturesTextField.setText(numFeatures); /* Set is editable */ if (isEditable) isEditableCheckBox.setSelected(true); /* Attach listeners for Radio buttons */ Enumeration<AbstractButton> buttons = radioButtonGrp.getElements(); while (buttons.hasMoreElements()) buttons.nextElement().addActionListener(this); /* Attach listener for combox box */ returnFormatComboBox.addActionListener(this); /* Attach listener for check box */ isEditableCheckBox.addActionListener(this); /* Attach listener for the text field */ numFeaturesTextField.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent arg0) { propertyPage.firePageChanged(); } }); } /** * This method creates and returns the root panel that contains the rest of * the UI * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (theRootPanel == null) { theRootPanel = new JPanel(); theRootPanel.setLayout(new GridBagLayout()); /* Layer type [Radio buttons] */ GridBagConstraints constraints = new GridBagConstraints(); constraints.weightx = 1; constraints.fill = GridBagConstraints.HORIZONTAL; constraints.insets = new Insets(5, 5, 5, 5); constraints.gridx = 0; constraints.gridy = 0; JLabel layerTypeNameLabel = new JLabel(); layerTypeNameLabel.setText("Layer Type :"); theRootPanel.add(layerTypeNameLabel, constraints); constraints.gridx = 1; constraints.gridy = 0; theRootPanel.add(getRadioButtonPanel(), constraints); /* Return format [ComboBox] */ constraints.gridx = 0; constraints.gridy = 1; JLabel returnFormatLabel = new JLabel(); returnFormatLabel.setText("Return Format :"); theRootPanel.add(returnFormatLabel, constraints); constraints.gridx = 1; constraints.gridy = 1; theRootPanel.add(getReturnFormatComboxBox(), constraints); /* Service editable [CheckBox] */ constraints.gridx = 0; constraints.gridy = 2; JLabel editableLabel = new JLabel(); editableLabel.setText("Is service editable? :"); theRootPanel.add(editableLabel, constraints); constraints.gridx = 1; constraints.gridy = 2; isEditableCheckBox = new JCheckBox(); theRootPanel.add(isEditableCheckBox, constraints); /* Number of features [TextBox] */ constraints.gridx = 0; constraints.gridy = 3; JLabel numFeaturesLabel = new JLabel(); numFeaturesLabel.setText("Number of Features :"); theRootPanel.add(numFeaturesLabel, constraints); constraints.gridx = 1; constraints.gridy = 3; numFeaturesTextField = new JTextField(); numFeaturesTextField.setPreferredSize(new Dimension(40, 20)); numFeaturesTextField.setBounds(new Rectangle(176, 60, 128, 33)); numFeaturesTextField .setText(JavaSimpleRESTSOEWithPropertiesPropPage.DEFAULT_COUNT); theRootPanel.add(numFeaturesTextField, constraints); } return theRootPanel; } /** * Creates a radio button group and adds three buttons to it, each * corresponding to a supported layer type * * @return a panel with three radio buttons */ private JPanel getRadioButtonPanel() { JRadioButton featureRadioButton = new JRadioButton("Feature"); featureRadioButton.setActionCommand("Feature"); JRadioButton rasterRadioButton = new JRadioButton("Raster"); rasterRadioButton.setActionCommand("Raster"); JRadioButton allRadioButton = new JRadioButton("All"); allRadioButton.setActionCommand("All"); featureRadioButton.setSelected(true); /* Group the radio buttons. */ radioButtonGrp = new ButtonGroup(); radioButtonGrp.add(featureRadioButton); radioButtonGrp.add(rasterRadioButton); radioButtonGrp.add(allRadioButton); radioButtonPanel = new JPanel(new GridLayout(0, 1)); radioButtonPanel.add(featureRadioButton); radioButtonPanel.add(rasterRadioButton); radioButtonPanel.add(allRadioButton); return radioButtonPanel; } /** * Returns a combo box containing value for the three return type formats * that are supported by the SOE. * * @return */ private JComboBox getReturnFormatComboxBox() { String[] formats = new String[] { "JSON", "HTML", "TEXT" }; returnFormatComboBox = new JComboBox(formats); returnFormatComboBox.setSelectedItem("JSON"); return returnFormatComboBox; } /** * Returns the value of the layer type */ public String getLayerType() { return radioButtonGrp.getSelection().getActionCommand(); } /** * Returns the return format * * @return */ public String getReturnFormat() { return (String) returnFormatComboBox.getSelectedItem(); } /** * * @return */ public String getIsEditable() { return new Boolean(isEditableCheckBox.isSelected()).toString(); } /** * * @return */ public String getMaxFeatures() { return numFeaturesTextField.getText(); } /** * Notifies ArcCatalog that properties were changed on this UI. */ public void actionPerformed(ActionEvent arg0) { propertyPage.firePageChanged(); } }