Esempio n. 1
0
 private void addRule() {
   // We must add it just after the currently selected Rule.
   // Let's find which one it is. If there is none, we add it at the
   // end of the list.
   MultiInputPanel mip = new MultiInputPanel(I18N.tr("Choose a name for your rule"));
   mip.addInput("RuleName", I18N.tr("Name of the Rule : "), new TextBoxType(10));
   mip.addValidation(
       new MIPValidation() {
         @Override
         public String validate(MultiInputPanel mid) {
           String ruleName = mid.getInput("RuleName");
           return ruleName.isEmpty() ? I18N.tr("Rule name cannot be null or empty.") : null;
         }
       });
   if (UIFactory.showDialog(mip)) {
     String s = mip.getInput("RuleName");
     LegendTreeModel tm = (LegendTreeModel) tree.getModel();
     // We need to link our new RuleWrapper with the layer we are editing.
     Rule temp = new Rule(simpleStyleEditor.getStyleWrapper().getStyle().getLayer());
     temp.setName(s);
     Legend leg =
         LegendFactory.getLegend(temp.getCompositeSymbolizer().getSymbolizerList().get(0));
     // Initialize a panel for this legend.
     ILegendPanel ilp = ILegendPanelFactory.getILegendPanel(simpleStyleEditor, leg);
     List<ILegendPanel> list = new ArrayList<ILegendPanel>();
     list.add(ilp);
     RuleWrapper nrw = new RuleWrapper(simpleStyleEditor, temp, list);
     tm.addElement(tm.getRoot(), nrw, getSelectedRule());
     simpleStyleEditor.legendAdded(nrw.getPanel());
   }
 }
Esempio n. 2
0
 /**
  * Adds the symbol panels for the legends (=symbols) attached to the given rule and returns a list
  * of the corresponding {@link ILegendPanel}s.
  *
  * @param rule Rule
  * @return A list of {@link ILegendPanel}s corresponding to the newly added symbol panels.
  */
 private List<ILegendPanel> addSymbolPanels(Rule rule) {
   List<ILegendPanel> symbolPanelList = new LinkedList<ILegendPanel>();
   // For each symbol in this rule, add its symbol panel to the list of
   // symbol panels.
   for (Symbolizer symb : rule.getCompositeSymbolizer().getSymbolizerList()) {
     symbolPanelList.add(addSymbolPanel(symb));
   }
   return symbolPanelList;
 }
Esempio n. 3
0
 /**
  * Get a name for a Symbolizer that is not already contained in the rule.
  *
  * @param n The base name
  * @param r the rule where we search
  * @param i An int we'll try to had to reach unicity
  * @return The unique name.
  */
 private String getUniqueName(String n, Rule r, int i) {
   int a = i < 0 ? 0 : i;
   String ret = n;
   if (a > 0) {
     ret = n + " " + a;
   }
   boolean contained = false;
   List<Symbolizer> symbolizerList = r.getCompositeSymbolizer().getSymbolizerList();
   for (int p = 0; p < symbolizerList.size() && !contained; p++) {
     Symbolizer s = symbolizerList.get(p);
     if (s.getName().equals(ret)) {
       contained = true;
     }
   }
   if (!contained) {
     return ret;
   } else {
     return getUniqueName(n, r, a + 1);
   }
 }