Пример #1
0
  public Main() {
    try {

      this.configureDisplay();
      mapPane.setForeground(Color.BLUE);
      refreshBtn.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {

              JMapFrame.splitPane.resetToPreferredSizes();
              JMapFrame.leftSplitPane.resetToPreferredSizes();
              JMapFrame.leftSplitPane.setBottomComponent(null);
              getMapPane().removeAll();
            }
          });
      queryBtn.addActionListener(
          new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
              Thread t =
                  new Thread(
                      new Runnable() {
                        public void run() {
                          new QueryWindow(getMapContent(), getMapContent().layers().get(0))
                              .setVisible(true);
                        }
                      });
              if (getMapContent().layers().size() != 0) t.start();
              else JOptionPane.showMessageDialog(null, "No Layers are added !");
            }
          });
      printBtn.addActionListener(
          new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
              saveNewImage(getMapContent(), "TEST");
              saveImage(getMapContent(), "TEST", 1000);
            }
          });

    } catch (Exception ex) {
      ex.printStackTrace();
      JOptionPane.showMessageDialog(null, ex.getMessage());
    }
  }
Пример #2
0
  private static String getFieldForColour(SimpleFeatureSource source) throws Exception {

    String selectedField = new String();
    String[] fieldNames = new String[source.getSchema().getAttributeCount()];
    int k = 0;
    for (AttributeDescriptor desc : source.getSchema().getAttributeDescriptors()) {
      fieldNames[k++] = desc.getLocalName();
    }

    selectedField =
        JOptionPane.showInputDialog(
                null,
                "Choose an attribute for colouring",
                "Feature attribute",
                JOptionPane.PLAIN_MESSAGE,
                null,
                fieldNames,
                fieldNames[0])
            .toString();
    return selectedField;
  }
Пример #3
0
  public static void legendAction() {
    try {
      LegendColorTable.countTable = 0;
      Layer layer = content.layers().get(content.layers().size() - 1);
      SimpleFeatureSource featureSource = (SimpleFeatureSource) layer.getFeatureSource();
      String fieldName = getFieldForColour(featureSource);

      if (fieldName != null && fieldName.length() > 0) {

        Style style = createStyle(featureSource, fieldName);

        content.removeLayer(layer);
        Layer newLayer = new FeatureLayer(featureSource, style);
        content.addLayer(newLayer);

      } else throw new NullPointerException("Error occured during making legend");

    } catch (ArrayIndexOutOfBoundsException ex) {
      JOptionPane.showMessageDialog(null, "No layers are added !");
    } catch (Exception ex) {
      ex.printStackTrace();
      // JOptionPane.showMessageDialog(null, ex.getMessage());
    }
  }