Revision: 4460
          http://sourceforge.net/p/jump-pilot/code/4460
Author:   michaudm
Date:     2015-05-23 17:48:06 +0000 (Sat, 23 May 2015)
Log Message:
-----------
Right-click on the button now displays a rich text tooltip containing the 
button parameters.
Add a backgroundColor attribute for the buttons.

Modified Paths:
--------------
    
plug-ins/SetAttributesPlugin/trunk/resources/set_attributes/language/jump.properties
    
plug-ins/SetAttributesPlugin/trunk/resources/set_attributes/language/jump_fr.properties
    
plug-ins/SetAttributesPlugin/trunk/src/org/openjump/ext/setattributes/SetAttributesExtension.java
    
plug-ins/SetAttributesPlugin/trunk/src/org/openjump/ext/setattributes/SetAttributesToolbox.java
    
plug-ins/SetAttributesPlugin/trunk/src/org/openjump/ext/setattributes/SetOfAttributes.java

Modified: 
plug-ins/SetAttributesPlugin/trunk/resources/set_attributes/language/jump.properties
===================================================================
--- 
plug-ins/SetAttributesPlugin/trunk/resources/set_attributes/language/jump.properties
        2015-05-23 09:15:56 UTC (rev 4459)
+++ 
plug-ins/SetAttributesPlugin/trunk/resources/set_attributes/language/jump.properties
        2015-05-23 17:48:06 UTC (rev 4460)
@@ -1,4 +1,11 @@
 SetAttributesPlugIn = SetAttributes
 SetAttributesPlugIn.no-feature-found = No selected feature in an editable layer
 SetAttributesPlugIn.no-feature-found-in-layer = No selected feature in an 
editable layer matching mask ''{0}''
-SetAttributesPlugIn.not-consistent-with-schema = Set Attributes : 
inconsistency between attribute ''{0}'' and feature ''{1}'' #{2}
\ No newline at end of file
+SetAttributesPlugIn.not-consistent-with-schema = Set Attributes : 
inconsistency between attribute ''{0}'' and feature ''{1}'' #{2}
+SetAttributesPlugIn.layer = Layer
+SetAttributesPlugIn.transaction-mode = Transaction mode
+SetAttributesPlugIn.transaction-mode.normal = normal
+SetAttributesPlugIn.transaction-mode.atomic = atomic
+SetAttributesPlugIn.accepted-geometry-dimension = Accepted geometry dimension
+SetAttributesPlugIn.attributes-changed = Attributes changed
+SetAttributesPlugIn.attributes-changed.if = if

Modified: 
plug-ins/SetAttributesPlugin/trunk/resources/set_attributes/language/jump_fr.properties
===================================================================
--- 
plug-ins/SetAttributesPlugin/trunk/resources/set_attributes/language/jump_fr.properties
     2015-05-23 09:15:56 UTC (rev 4459)
+++ 
plug-ins/SetAttributesPlugin/trunk/resources/set_attributes/language/jump_fr.properties
     2015-05-23 17:48:06 UTC (rev 4460)
@@ -1,4 +1,11 @@
 SetAttributesPlugIn = Jeu d'attributs
 SetAttributesPlugIn.no-feature-found = Aucun objet s\xE9lectionn\xE9 dans une 
couche modifiable
 SetAttributesPlugIn.no-feature-found-in-layer = Aucun objet s\xE9lectionn\xE9 
dans une couche modifiable de la forme ''{0}''
-SetAttributesPlugIn.not-consistent-with-schema = Jeu d''attributs : 
incoh\xE9rence entre l''attribut ''{0}'' et l''objet ''{1}'' #{2}
\ No newline at end of file
+SetAttributesPlugIn.not-consistent-with-schema = Jeu d''attributs : 
incoh\xE9rence entre l''attribut ''{0}'' et l''objet ''{1}'' #{2}
+SetAttributesPlugIn.layer = Couche
+SetAttributesPlugIn.transaction-mode = Mode de transaction
+SetAttributesPlugIn.transaction-mode.normal = normal
+SetAttributesPlugIn.transaction-mode.atomic = atomic
+SetAttributesPlugIn.accepted-geometry-dimension = Dimension accept\xE9e
+SetAttributesPlugIn.attributes-changed = Attributs chang\xE9s
+SetAttributesPlugIn.attributes-changed.if = si
\ No newline at end of file

Modified: 
plug-ins/SetAttributesPlugin/trunk/src/org/openjump/ext/setattributes/SetAttributesExtension.java
===================================================================
--- 
plug-ins/SetAttributesPlugin/trunk/src/org/openjump/ext/setattributes/SetAttributesExtension.java
   2015-05-23 09:15:56 UTC (rev 4459)
+++ 
plug-ins/SetAttributesPlugin/trunk/src/org/openjump/ext/setattributes/SetAttributesExtension.java
   2015-05-23 17:48:06 UTC (rev 4460)
@@ -15,7 +15,7 @@
     }
 
     public String getVersion() {
-        return "0.5.1 (2015-05-12)";
+        return "0.6 (2015-05-23)";
     }
 
     public void configure(PlugInContext context) throws Exception {

Modified: 
plug-ins/SetAttributesPlugin/trunk/src/org/openjump/ext/setattributes/SetAttributesToolbox.java
===================================================================
--- 
plug-ins/SetAttributesPlugin/trunk/src/org/openjump/ext/setattributes/SetAttributesToolbox.java
     2015-05-23 09:15:56 UTC (rev 4459)
+++ 
plug-ins/SetAttributesPlugin/trunk/src/org/openjump/ext/setattributes/SetAttributesToolbox.java
     2015-05-23 17:48:06 UTC (rev 4460)
@@ -16,9 +16,10 @@
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
+import java.awt.event.*;
 import java.io.File;
+import java.text.CharacterIterator;
+import java.text.StringCharacterIterator;
 import java.util.*;
 import java.util.List;
 import java.util.regex.Pattern;
@@ -65,11 +66,19 @@
         final PlugInContext pluginContext = context.createPlugInContext();
         for (final SetOfAttributes setOfAttributes : buttons) {
             ImageIcon icon = new 
ImageIcon(dir.getPath()+"/"+setOfAttributes.icon);
-            final JButton button = icon.getImageLoadStatus() == 
MediaTracker.COMPLETE ?
-                    new JButton(icon) :
-                    new JButton(setOfAttributes.text);
-            button.setMargin(new Insets(0,0,0,0));
-            button.setPreferredSize(new Dimension(iconWidth,iconHeight));
+            final JButton button;
+            if (icon.getImageLoadStatus() == MediaTracker.COMPLETE) {
+                button = new JButton(icon);
+            } else {
+                button = new JButton(setOfAttributes.text);
+                if (setOfAttributes.getBackgroundColor()!=null) {
+                    button.setBackground(setOfAttributes.getBackgroundColor());
+                    //button.setContentAreaFilled(false);
+                    button.setOpaque(true);
+                }
+            }
+            button.setMargin(new Insets(0, 0, 0, 0));
+            button.setPreferredSize(new Dimension(iconWidth, iconHeight));
             button.setToolTipText(setOfAttributes.getTooltip());
             button.addActionListener(new ActionListener() {
                 @Override
@@ -91,26 +100,28 @@
                                 }
                                 // and finally, try to read layer name as a 
regex if it starts and ends with a /
                                 if (setOfAttributes.getLayer().startsWith("/") 
&& setOfAttributes.getLayer().endsWith("/")) {
-                                    layerPattern = 
Pattern.compile(setOfAttributes.getLayer().substring(1,setOfAttributes.getLayer().length()-1));
+                                    layerPattern = 
Pattern.compile(setOfAttributes.getLayer().substring(1, 
setOfAttributes.getLayer().length() - 1));
                                 }
-                            } catch(PatternSyntaxException pse) 
{pse.printStackTrace();}
+                            } catch (PatternSyntaxException pse) {
+                                pse.printStackTrace();
+                            }
                         }
-                        final Map<Layer,Map<Feature,Feature>> mapSource = new 
HashMap<Layer,Map<Feature,Feature>>();
-                        final Map<Layer,Map<Feature,Feature>> mapTarget = new 
HashMap<Layer,Map<Feature,Feature>>();
+                        final Map<Layer, Map<Feature, Feature>> mapSource = 
new HashMap<Layer, Map<Feature, Feature>>();
+                        final Map<Layer, Map<Feature, Feature>> mapTarget = 
new HashMap<Layer, Map<Feature, Feature>>();
                         for (Layer lyr : 
selectionManager.getLayersWithSelectedItems()) {
                             if (!lyr.isEditable()) continue;
                             if (layerPattern != null && 
!layerPattern.matcher(lyr.getName()).matches()) continue;
                             editableLayers++;
-                            Map<Feature,Feature> srcLayerMap = new 
HashMap<Feature,Feature>();
-                            Map<Feature,Feature> tgtLayerMap = new 
HashMap<Feature,Feature>();
+                            Map<Feature, Feature> srcLayerMap = new 
HashMap<Feature, Feature>();
+                            Map<Feature, Feature> tgtLayerMap = new 
HashMap<Feature, Feature>();
                             Collection<Feature> features = 
selectionManager.getFeaturesWithSelectedItems(lyr);
                             editableFeatures += features.size();
                             for (Feature feature : features) {
                                 srcLayerMap.put(feature, feature.clone(false));
                             }
                             
tgtLayerMap.putAll(setOfAttributes.setAttributes(selectionManager.getFeaturesWithSelectedItems(lyr),
 lyr.getName()));
-                            mapSource.put(lyr,srcLayerMap);
-                            mapTarget.put(lyr,tgtLayerMap);
+                            mapSource.put(lyr, srcLayerMap);
+                            mapTarget.put(lyr, tgtLayerMap);
                         }
                         if (unselect) {
                             for (Layer lyr : 
selectionManager.getLayersWithSelectedItems()) {
@@ -136,7 +147,7 @@
                                     new 
UndoableCommand(I18N.get(SetAttributesPlugIn.class.getName())) {
                                         public void execute() {
                                             for (Layer lyr : 
mapTarget.keySet()) {
-                                                Map<Feature,Feature> map = 
mapTarget.get(lyr);
+                                                Map<Feature, Feature> map = 
mapTarget.get(lyr);
                                                 for (Feature feature : 
map.keySet()) {
                                                     Feature newFeature = 
map.get(feature);
                                                     FeatureSchema schema = 
feature.getSchema();
@@ -148,14 +159,14 @@
                                                     }
                                                 }
                                                 
//pluginContext.getLayerManager().fireFeaturesAttChanged(map.keySet(), 
FeatureEventType.ATTRIBUTES_MODIFIED, lyr, map.keySet());
-                                                
pluginContext.getLayerManager().fireFeaturesChanged(map.keySet(),FeatureEventType.ATTRIBUTES_MODIFIED,
 lyr);
+                                                
pluginContext.getLayerManager().fireFeaturesChanged(map.keySet(), 
FeatureEventType.ATTRIBUTES_MODIFIED, lyr);
                                             }
                                             
pluginContext.getLayerViewPanel().repaint();
                                         }
 
                                         public void unexecute() {
                                             for (Layer lyr : 
mapSource.keySet()) {
-                                                Map<Feature,Feature> map = 
mapSource.get(lyr);
+                                                Map<Feature, Feature> map = 
mapSource.get(lyr);
                                                 for (Feature feature : 
map.keySet()) {
                                                     Feature newFeature = 
map.get(feature);
                                                     FeatureSchema schema = 
feature.getSchema();
@@ -166,7 +177,7 @@
                                                         }
                                                     }
                                                     
//pluginContext.getLayerManager().fireFeaturesAttChanged(map.keySet(), 
FeatureEventType.ATTRIBUTES_MODIFIED, lyr, map.keySet());
-                                                    
pluginContext.getLayerManager().fireFeaturesChanged(map.keySet(),FeatureEventType.ATTRIBUTES_MODIFIED,
 lyr);
+                                                    
pluginContext.getLayerManager().fireFeaturesChanged(map.keySet(), 
FeatureEventType.ATTRIBUTES_MODIFIED, lyr);
                                                 }
                                             }
                                             
pluginContext.getLayerViewPanel().repaint();
@@ -176,7 +187,7 @@
                             command.execute();
                             
pluginContext.getLayerManager().getUndoableEditReceiver().receive(command.toUndoableEdit());
                         }
-                    } catch(Exception exc) {
+                    } catch (Exception exc) {
                         LOG.warn(null, exc);
                         
pluginContext.getWorkbenchFrame().warnUser(exc.getMessage());
                     } finally {
@@ -184,6 +195,39 @@
                     }
                 }
             });
+
+            button.addMouseListener(new MouseAdapter() {
+
+                final int defaultDismissTimeout = 
ToolTipManager.sharedInstance().getDismissDelay();
+
+                @Override
+                public void mousePressed(MouseEvent e) {
+                    int defaultDismissTimeout = 
ToolTipManager.sharedInstance().getDismissDelay();
+
+                    if (SwingUtilities.isRightMouseButton(e)) {
+                        ToolTipManager.sharedInstance().setDismissDelay(10000);
+                        button.setToolTipText(getHtmlToolTip(setOfAttributes));
+                        MouseEvent phantom = new MouseEvent(
+                                button,
+                                MouseEvent.MOUSE_PRESSED,
+                                System.currentTimeMillis(),
+                                0,
+                                0,
+                                0,
+                                0,
+                                false);
+                        ToolTipManager.sharedInstance().mouseMoved(phantom);
+                    }
+                }
+
+                @Override
+                public void mouseReleased(MouseEvent e) {
+                    if (SwingUtilities.isRightMouseButton(e)) {
+                        button.setToolTipText(setOfAttributes.getTooltip());
+                        
ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
+                    }
+                }
+            });
             dialog.getContentPane().add(button, constraints);
             constraints.gridx += 1;
             if (constraints.gridx >= maxCol) {
@@ -207,4 +251,219 @@
         return buttons;
     }
 
+    public String getHtmlToolTip(SetOfAttributes button) {
+        StringBuilder text = new StringBuilder("<html>");
+        text.append("<b>");
+        text.append(I18N_.getText("set_attributes", 
"SetAttributesPlugIn.layer"));
+        text.append("</b> : ");
+        text.append(forHTML(button.getLayer()));
+
+        text.append("<br><b>");
+        text.append(I18N_.getText("set_attributes", 
"SetAttributesPlugIn.transaction-mode"));
+        text.append("</b> : ");
+        text.append(button.isAtomic() ?
+                I18N_.getText("set_attributes", 
"SetAttributesPlugIn.transaction-mode.atomic") :
+                I18N_.getText("set_attributes", 
"SetAttributesPlugIn.transaction-mode.normal"));
+
+        if (button.getDimension() > -1) {
+            text.append("<br><b>");
+            text.append(I18N_.getText("set_attributes", 
"SetAttributesPlugIn.accepted-geometry-dimension"));
+            text.append("</b> : ");
+            text.append(button.getDimension());
+        }
+
+        text.append("<br><b>");
+        text.append(I18N_.getText("set_attributes", 
"SetAttributesPlugIn.attributes-changed"));
+        text.append("</b> :");
+        text.append("<ul>");
+        for (SetAttribute att : button.getAttributes()) {
+            text.append("<li><b>").append(att.getName()).append("</b> : 
").append(att.getValue());
+            if (att.getPrerequisite() != null && 
att.getPrerequisite().length() > 0) {
+                text.append("<i>[");
+                text.append(I18N_.getText("set_attributes", 
"SetAttributesPlugIn.attributes-changed.if"));
+                text.append(" ");
+                text.append(forHTML(att.getPrerequisite()));
+                text.append("]</i>");
+            }
+            text.append("</li>");
+        }
+        text.append("</ul></html>");
+        return text.toString();
+    }
+
+    /**
+     Escape characters for text appearing in HTML markup.
+
+     <P>This method exists as a defence against Cross Site Scripting (XSS) 
hacks.
+     The idea is to neutralize control characters commonly used by scripts, 
such that
+     they will not be executed by the browser. This is done by replacing the 
control
+     characters with their escaped equivalents.
+
+     <P>The following characters are replaced with corresponding
+     HTML character entities :
+     <table border='1' cellpadding='3' cellspacing='0'>
+     <tr><th> Character </th><th>Replacement</th></tr>
+     <tr><td> < </td><td> &lt; </td></tr>
+     <tr><td> > </td><td> &gt; </td></tr>
+     <tr><td> & </td><td> &amp; </td></tr>
+     <tr><td> " </td><td> &quot;</td></tr>
+     <tr><td> \t </td><td> &#009;</td></tr>
+     <tr><td> ! </td><td> &#033;</td></tr>
+     <tr><td> # </td><td> &#035;</td></tr>
+     <tr><td> $ </td><td> &#036;</td></tr>
+     <tr><td> % </td><td> &#037;</td></tr>
+     <tr><td> ' </td><td> &#039;</td></tr>
+     <tr><td> ( </td><td> &#040;</td></tr>
+     <tr><td> ) </td><td> &#041;</td></tr>
+     <tr><td> * </td><td> &#042;</td></tr>
+     <tr><td> + </td><td> &#043; </td></tr>
+     <tr><td> , </td><td> &#044; </td></tr>
+     <tr><td> - </td><td> &#045; </td></tr>
+     <tr><td> . </td><td> &#046; </td></tr>
+     <tr><td> / </td><td> &#047; </td></tr>
+     <tr><td> : </td><td> &#058;</td></tr>
+     <tr><td> ; </td><td> &#059;</td></tr>
+     <tr><td> = </td><td> &#061;</td></tr>
+     <tr><td> ? </td><td> &#063;</td></tr>
+     <tr><td> @ </td><td> &#064;</td></tr>
+     <tr><td> [ </td><td> &#091;</td></tr>
+     <tr><td> \ </td><td> &#092;</td></tr>
+     <tr><td> ] </td><td> &#093;</td></tr>
+     <tr><td> ^ </td><td> &#094;</td></tr>
+     <tr><td> _ </td><td> &#095;</td></tr>
+     <tr><td> ` </td><td> &#096;</td></tr>
+     <tr><td> { </td><td> &#123;</td></tr>
+     <tr><td> | </td><td> &#124;</td></tr>
+     <tr><td> } </td><td> &#125;</td></tr>
+     <tr><td> ~ </td><td> &#126;</td></tr>
+     </table>
+     */
+    public static String forHTML(String aText){
+        final StringBuilder result = new StringBuilder();
+        final StringCharacterIterator iterator = new 
StringCharacterIterator(aText);
+        char character =  iterator.current();
+        while (character != CharacterIterator.DONE ){
+            if (character == '<') {
+                result.append("&lt;");
+            }
+            else if (character == '>') {
+                result.append("&gt;");
+            }
+            else if (character == '&') {
+                result.append("&amp;");
+            }
+            else if (character == '\"') {
+                result.append("&quot;");
+            }
+            else if (character == '\t') {
+                addCharEntity(9, result);
+            }
+            else if (character == '!') {
+                addCharEntity(33, result);
+            }
+            else if (character == '#') {
+                addCharEntity(35, result);
+            }
+            else if (character == '$') {
+                addCharEntity(36, result);
+            }
+            else if (character == '%') {
+                addCharEntity(37, result);
+            }
+            else if (character == '\'') {
+                addCharEntity(39, result);
+            }
+            else if (character == '(') {
+                addCharEntity(40, result);
+            }
+            else if (character == ')') {
+                addCharEntity(41, result);
+            }
+            else if (character == '*') {
+                addCharEntity(42, result);
+            }
+            else if (character == '+') {
+                addCharEntity(43, result);
+            }
+            else if (character == ',') {
+                addCharEntity(44, result);
+            }
+            else if (character == '-') {
+                addCharEntity(45, result);
+            }
+            else if (character == '.') {
+                addCharEntity(46, result);
+            }
+            else if (character == '/') {
+                addCharEntity(47, result);
+            }
+            else if (character == ':') {
+                addCharEntity(58, result);
+            }
+            else if (character == ';') {
+                addCharEntity(59, result);
+            }
+            else if (character == '=') {
+                addCharEntity(61, result);
+            }
+            else if (character == '?') {
+                addCharEntity(63, result);
+            }
+            else if (character == '@') {
+                addCharEntity(64, result);
+            }
+            else if (character == '[') {
+                addCharEntity(91, result);
+            }
+            else if (character == '\\') {
+                addCharEntity(92, result);
+            }
+            else if (character == ']') {
+                addCharEntity(93, result);
+            }
+            else if (character == '^') {
+                addCharEntity(94, result);
+            }
+            else if (character == '_') {
+                addCharEntity(95, result);
+            }
+            else if (character == '`') {
+                addCharEntity(96, result);
+            }
+            else if (character == '{') {
+                addCharEntity(123, result);
+            }
+            else if (character == '|') {
+                addCharEntity(124, result);
+            }
+            else if (character == '}') {
+                addCharEntity(125, result);
+            }
+            else if (character == '~') {
+                addCharEntity(126, result);
+            }
+            else {
+                //the char is not a special one
+                //add it to the result as is
+                result.append(character);
+            }
+            character = iterator.next();
+        }
+        return result.toString();
+    }
+
+    private static void addCharEntity(Integer aIdx, StringBuilder aBuilder){
+        String padding = "";
+        if( aIdx <= 9 ){
+            padding = "00";
+        }
+        else if( aIdx <= 99 ){
+            padding = "0";
+        }
+        else {
+            //no prefix
+        }
+        String number = padding + aIdx.toString();
+        aBuilder.append("&#" + number + ";");
+    }
 }

Modified: 
plug-ins/SetAttributesPlugin/trunk/src/org/openjump/ext/setattributes/SetOfAttributes.java
===================================================================
--- 
plug-ins/SetAttributesPlugin/trunk/src/org/openjump/ext/setattributes/SetOfAttributes.java
  2015-05-23 09:15:56 UTC (rev 4459)
+++ 
plug-ins/SetAttributesPlugin/trunk/src/org/openjump/ext/setattributes/SetOfAttributes.java
  2015-05-23 17:48:06 UTC (rev 4460)
@@ -12,6 +12,7 @@
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
+import java.awt.*;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
@@ -36,6 +37,9 @@
     String text;
 
     @XmlAttribute
+    String backgroundColor;
+
+    @XmlAttribute
     String tooltip;
 
     @XmlAttribute
@@ -54,6 +58,15 @@
         return icon;
     }
 
+    public Color getBackgroundColor() {
+        Color c = null;
+        if (backgroundColor == null) return null;
+        try {
+            c = Color.decode(backgroundColor);
+        } catch(NumberFormatException e) {}
+        return c;
+    }
+
     public String getTooltip() {
         return tooltip;
     }


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to