tn5250j/src/org/tn5250j/tools Macronizer.java,1.16,1.17

"Kenneth J. Pouncey" <[email protected]> Fri, 08 Jul 2005 06:17:55 +0000
Newsgroups gmane.comp.java.tn5250j.cvs
Message-ID <[email protected]>
Update of /cvsroot/tn5250j/tn5250j/src/org/tn5250j/tools
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29775/src/org/tn5250j/tools

Modified Files:
	Macronizer.java 
Log Message:
Fix for Richard on duplicate macro names

Index: Macronizer.java
===================================================================
RCS file: /cvsroot/tn5250j/tn5250j/src/org/tn5250j/tools/Macronizer.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** Macronizer.java	14 Jun 2005 06:22:12 -0000	1.16
--- Macronizer.java	8 Jul 2005 06:17:53 -0000	1.17
***************
*** 39,43 ****
  public class Macronizer {
  
-    private static String macroName;
     private static Properties macros;
     private static boolean macrosExist;
--- 39,42 ----
***************
*** 137,147 ****
     }
  
     public final static void setMacro(String name, String keyStrokes) {
  
        int x = 0;
  
!       while (getMacroByNumber(++x) != null) {}
!       macros.put("macro" + x + "." + name,keyStrokes);
!       macrosExist = true;
        saveMacros();
  
--- 136,178 ----
     }
  
+    /**
+     * Add the macro keystrokes to the macros list.
+     * 
+     * This method is a destructive where if the macro already exists it will be
+     *   overwritten.
+     *   
+     * @param name
+     * @param keyStrokes
+     */
     public final static void setMacro(String name, String keyStrokes) {
  
        int x = 0;
  
!       // first let's go through all the macros and replace the macro entry if it
!       //   already exists.  
!       if (macrosExist && getMacroByName(name) != null) {
!          Set macroSet = macros.keySet();
!          Iterator macroIterator = macroSet.iterator();
!          String byName = null;
!          String prefix = null;
!          while (macroIterator.hasNext()) {
!             byName = (String)macroIterator.next();
!             if (byName.endsWith(name)) {
!                //  we need to obtain the prefix so that we can replace
!                //   the slot with the new keystrokes.  If not the keymapping
!                //   will not work correctly.
!                prefix = byName.substring(0,byName.indexOf(name));
!                macros.put(prefix + name,keyStrokes);
!             }
!          }
!       }
!       else {
!          // If it did not exist and get replaced then we need to find the next
!          //  available slot to place the macro in.
!          while (getMacroByNumber(++x) != null) {}
!          
!          macros.put("macro" + x + "." + name,keyStrokes);
!          macrosExist = true;
!       }
        saveMacros();
  



-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP, 
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar