Example #1
0
  /**
   * Add a legend to the tree, in the currently selected RuleWrapper, after the currently selected
   * Legend (if any in both case). A RuleWrapper will be added in the case there is none.
   */
  private void addLegend() {
    LegendUIChooser legendPicker = new LegendUIChooser(simpleStyleEditor);

    if (UIFactory.showDialog(legendPicker)) {
      // Recover the panel that was selected when the user clicked OK.
      ILegendPanel ilp = legendPicker.getSelectedPanel();

      // Get the currently selected RuleWrapper, or the last one in this
      // style if none is currently selected.
      RuleWrapper currentrw = getSelectedRule();
      StyleWrapper sw = simpleStyleEditor.getStyleWrapper();
      if (currentrw == null) {
        if (sw.getSize() == 0) {
          addRule();
        }
        currentrw = sw.getRuleWrapper(sw.getSize() - 1);
      }

      // Set the Legend's name.
      Legend legend = ilp.getLegend();
      legend
          .getSymbolizer()
          .setName(getUniqueName(legend.getLegendTypeName(), currentrw.getRule(), 0));

      // Add the panel to the LegendTree.
      ((LegendTreeModel) tree.getModel()).addElement(currentrw, ilp, getSelectedLegend());

      // Automatically select the newly added legend in the tree.
      TreePath selectionPath = tree.getSelectionPath();
      TreePath parent;
      if (selectionPath.getLastPathComponent() instanceof RuleWrapper) {
        parent = selectionPath;
      } else {
        parent = selectionPath.getParentPath();
      }
      tree.setSelectionPath(parent.pathByAddingChild(ilp));

      // Notify the SimpleStyleEditor that a Legend has been added.
      simpleStyleEditor.legendAdded(ilp);
    }
  }
Example #2
0
 /**
  * Create the thumbnail image
  *
  * @return
  */
 public ImageIcon getThumbnail() {
   ILegendPanel legendPanel = (ILegendPanel) getSelected();
   String legendId = legendPanel.getLegend().getLegendTypeId();
   if (legendId.equals("org.orbisgis.legend.thematic.proportional.ProportionalPoint")) {
     return createImageIcon("thumbnail_proportionnal_point.png");
   } else if (legendId.equals("org.orbisgis.legend.thematic.proportional.ProportionalLine")) {
     return createImageIcon("thumbnail_proportionnal_line.png");
   } else if (legendId.equals("org.orbisgis.legend.thematic.constant.UniqueSymbolPoint")) {
     return createImageIcon("thumbnail_unique_point.png");
   } else if (legendId.equals("org.orbisgis.legend.thematic.constant.UniqueSymbolLine")) {
     return createImageIcon("thumbnail_unique_line.png");
   } else if (legendId.equals("org.orbisgis.legend.thematic.constant.UniqueSymbolArea")) {
     return createImageIcon("thumbnail_unique_area.png");
   } else if (legendId.equals("org.orbisgis.legend.thematic.recode.RecodedLine")) {
     return createImageIcon("thumbnail_recoded_line.png");
   } else if (legendId.equals("org.orbisgis.legend.thematic.recode.RecodedArea")) {
     return createImageIcon("thumbnail_recoded_area.png");
   } else if (legendId.equals("org.orbisgis.legend.thematic.recode.RecodedPoint")) {
     return createImageIcon("thumbnail_recoded_point.png");
   } else {
     return createImageIcon("thumbnail_not_found.png");
   }
 }
Example #3
0
 /**
  * Adds the symbol panel attached to the given {@link Symbolizer} and returns the panel.
  *
  * @param symb Symbolizer
  * @return The newly generated symbol panel
  */
 private ILegendPanel addSymbolPanel(Symbolizer symb) {
   // Get the legend corresponding to this symbolizer.
   Legend legend = LegendFactory.getLegend(symb);
   if (legend instanceof AbstractRecodedLegend) {
     String table = layer.getTableReference();
     AbstractRecodedLegend leg = (AbstractRecodedLegend) legend;
     try (Connection connection = layer.getDataManager().getDataSource().getConnection()) {
       String f = leg.getLookupFieldName();
       int type = MetaData.getFieldType(connection, table, f);
       leg.setComparator(AbstractRecodedLegend.getComparator(type));
     } catch (SQLException e) {
       LOGGER.warn("Can't retrieve an accurate Comparator for this classification");
     }
   }
   // Initialize a panel for this legend.
   ILegendPanel panel = ILegendPanelFactory.getILegendPanel(this, legend);
   // Give it a new id.
   panel.setId(createNewID());
   // Add the symbol panel to the container after putting it in a
   // new JScrollPane.
   dialogContainer.add(panel.getId(), getJScrollPane(panel));
   return panel;
 }
 /**
  * Adds the symbol panel attached to the given {@link Symbolizer} and returns the panel.
  *
  * @param symb Symbolizer
  * @return The newly generated symbol panel
  */
 private ILegendPanel addSymbolPanel(Symbolizer symb) {
   // Get the legend corresponding to this symbolizer.
   Legend legend = LegendFactory.getLegend(symb);
   if (legend instanceof AbstractRecodedLegend) {
     DataSource dataSource = layer.getDataSource();
     AbstractRecodedLegend leg = (AbstractRecodedLegend) legend;
     try {
       Metadata metadata = dataSource.getMetadata();
       String f = leg.getLookupFieldName();
       int in = metadata.getFieldIndex(f);
       leg.setComparator(AbstractRecodedLegend.getComparator(metadata.getFieldType(in)));
     } catch (DriverException e) {
       LOGGER.warn("Can't retrieve an accurate Comparator for this classification");
     }
   }
   // Initialize a panel for this legend.
   ILegendPanel panel = ILegendPanelFactory.getILegendPanel(this, legend);
   // Give it a new id.
   panel.setId(createNewID());
   // Add the symbol panel to the container after putting it in a
   // new JScrollPane.
   dialogContainer.add(panel.getId(), getJScrollPane(panel));
   return panel;
 }
Example #5
0
 private Component getComponent(ILegendPanel legend, JLabel lab) {
   lab.setText(legend.getLegend().getName());
   return lab;
 }