package net.miginfocom.layout;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public final class ConstraintParser {
   private ConstraintParser() {
   }

   public static LC parseLayoutConstraint(String var0) {
      LC var1 = new LC();
      if (var0.length() == 0) {
         return var1;
      } else {
         String[] var2 = toTrimmedTokens(var0, ',');

         int var5;
         for(int var3 = 0; var3 < var2.length; ++var3) {
            String var4 = var2[var3];
            if (var4 != null) {
               var5 = var4.length();
               if (var5 == 3 || var5 == 11) {
                  if (var4.equals("ltr") || var4.equals("rtl") || var4.equals("lefttoright") || var4.equals("righttoleft")) {
                     var1.setLeftToRight(var4.charAt(0) == 'l' ? Boolean.TRUE : Boolean.FALSE);
                     var2[var3] = null;
                  }

                  if (var4.equals("ttb") || var4.equals("btt") || var4.equals("toptobottom") || var4.equals("bottomtotop")) {
                     var1.setTopToBottom(var4.charAt(0) == 't');
                     var2[var3] = null;
                  }
               }
            }
         }

         String[] var12 = var2;
         int var13 = var2.length;

         for(var5 = 0; var5 < var13; ++var5) {
            String var6 = var12[var5];
            if (var6 != null && var6.length() != 0) {
               try {
                  boolean var7 = true;
                  char var8 = var6.charAt(0);
                  int var14;
                  String var16;
                  if (var8 == 'w' || var8 == 'h') {
                     label412: {
                        var14 = startsWithLenient(var6, "wrap", -1, true);
                        if (var14 > -1) {
                           var16 = var6.substring(var14).trim();
                           var1.setWrapAfter(var16.length() != 0 ? Integer.parseInt(var16) : 0);
                           continue;
                        }

                        boolean var9 = var8 == 'w';
                        String var10;
                        if (!var9 || !var6.startsWith("w ") && !var6.startsWith("width ")) {
                           if (var9 || !var6.startsWith("h ") && !var6.startsWith("height ")) {
                              if (var6.length() > 5) {
                                 var10 = var6.substring(5).trim();
                                 if (var6.startsWith("wmin ")) {
                                    var1.minWidth(var10);
                                    continue;
                                 }

                                 if (var6.startsWith("wmax ")) {
                                    var1.maxWidth(var10);
                                    continue;
                                 }

                                 if (var6.startsWith("hmin ")) {
                                    var1.minHeight(var10);
                                    continue;
                                 }

                                 if (var6.startsWith("hmax ")) {
                                    var1.maxHeight(var10);
                                    continue;
                                 }
                              }

                              if (var6.startsWith("hidemode ")) {
                                 var1.setHideMode(Integer.parseInt(var6.substring(9)));
                                 continue;
                              }
                              break label412;
                           }

                           var10 = var6.substring(var6.charAt(1) == ' ' ? 2 : 7).trim();
                           var1.setHeight(parseBoundSize(var10, false, false));
                           continue;
                        }

                        var10 = var6.substring(var6.charAt(1) == ' ' ? 2 : 6).trim();
                        var1.setWidth(parseBoundSize(var10, false, true));
                        continue;
                     }
                  }

                  String[] var17;
                  if (var8 == 'g') {
                     if (var6.startsWith("gapx ")) {
                        var1.setGridGapX(parseBoundSize(var6.substring(5).trim(), true, true));
                        continue;
                     }

                     if (var6.startsWith("gapy ")) {
                        var1.setGridGapY(parseBoundSize(var6.substring(5).trim(), true, false));
                        continue;
                     }

                     if (var6.startsWith("gap ")) {
                        var17 = toTrimmedTokens(var6.substring(4).trim(), ' ');
                        var1.setGridGapX(parseBoundSize(var17[0], true, true));
                        var1.setGridGapY(var17.length > 1 ? parseBoundSize(var17[1], true, false) : var1.getGridGapX());
                        continue;
                     }
                  }

                  if (var8 == 'd') {
                     var14 = startsWithLenient(var6, "debug", 5, true);
                     if (var14 > -1) {
                        var16 = var6.substring(var14).trim();
                        var1.setDebugMillis(var16.length() > 0 ? Integer.parseInt(var16) : 1000);
                        continue;
                     }
                  }

                  if (var8 == 'n') {
                     if (var6.equals("nogrid")) {
                        var1.setNoGrid(true);
                        continue;
                     }

                     if (var6.equals("nocache")) {
                        var1.setNoCache(true);
                        continue;
                     }

                     if (var6.equals("novisualpadding")) {
                        var1.setVisualPadding(false);
                        continue;
                     }
                  }

                  if (var8 == 'f') {
                     if (var6.equals("fill") || var6.equals("fillx") || var6.equals("filly")) {
                        var1.setFillX(var6.length() == 4 || var6.charAt(4) == 'x');
                        var1.setFillY(var6.length() == 4 || var6.charAt(4) == 'y');
                        continue;
                     }

                     if (var6.equals("flowy")) {
                        var1.setFlowX(false);
                        continue;
                     }

                     if (var6.equals("flowx")) {
                        var1.setFlowX(true);
                        continue;
                     }
                  }

                  if (var8 == 'i') {
                     var14 = startsWithLenient(var6, "insets", 3, true);
                     if (var14 > -1) {
                        var16 = var6.substring(var14).trim();
                        UnitValue[] var19 = parseInsets(var16, true);
                        LayoutUtil.putCCString(var19, var16);
                        var1.setInsets(var19);
                        continue;
                     }
                  }

                  UnitValue var15;
                  if (var8 == 'a') {
                     var14 = startsWithLenient(var6, new String[]{"aligny", "ay"}, new int[]{6, 2}, true);
                     if (var14 > -1) {
                        var15 = parseUnitValueOrAlign(var6.substring(var14).trim(), false, (UnitValue)null);
                        if (var15 == UnitValue.BASELINE_IDENTITY) {
                           throw new IllegalArgumentException("'baseline' can not be used to align the whole component group.");
                        }

                        var1.setAlignY(var15);
                        continue;
                     }

                     var14 = startsWithLenient(var6, new String[]{"alignx", "ax"}, new int[]{6, 2}, true);
                     if (var14 > -1) {
                        var1.setAlignX(parseUnitValueOrAlign(var6.substring(var14).trim(), true, (UnitValue)null));
                        continue;
                     }

                     var14 = startsWithLenient(var6, "align", 2, true);
                     if (var14 > -1) {
                        var17 = toTrimmedTokens(var6.substring(var14).trim(), ' ');
                        var1.setAlignX(parseUnitValueOrAlign(var17[0], true, (UnitValue)null));
                        if (var17.length > 1) {
                           var1.setAlignY(parseUnitValueOrAlign(var17[1], false, (UnitValue)null));
                        }
                        continue;
                     }
                  }

                  if (var8 == 'p') {
                     if (var6.startsWith("packalign ")) {
                        var17 = toTrimmedTokens(var6.substring(10).trim(), ' ');
                        var1.setPackWidthAlign(var17[0].length() > 0 ? Float.parseFloat(var17[0]) : 0.5F);
                        if (var17.length > 1) {
                           var1.setPackHeightAlign(Float.parseFloat(var17[1]));
                        }
                        continue;
                     }

                     if (var6.startsWith("pack ") || var6.equals("pack")) {
                        var16 = var6.substring(4).trim();
                        String[] var18 = toTrimmedTokens(var16.length() > 0 ? var16 : "pref pref", ' ');
                        var1.setPackWidth(parseBoundSize(var18[0], false, true));
                        if (var18.length > 1) {
                           var1.setPackHeight(parseBoundSize(var18[1], false, false));
                        }
                        continue;
                     }
                  }

                  if (var1.getAlignX() == null) {
                     var15 = parseAlignKeywords(var6, true);
                     if (var15 != null) {
                        var1.setAlignX(var15);
                        continue;
                     }
                  }

                  var15 = parseAlignKeywords(var6, false);
                  if (var15 == null) {
                     throw new IllegalArgumentException("Unknown Constraint: '" + var6 + "'\n");
                  }

                  var1.setAlignY(var15);
               } catch (Exception var11) {
                  throw new IllegalArgumentException("Illegal Constraint: '" + var6 + "'\n" + var11.getMessage());
               }
            }
         }

         return var1;
      }
   }

   public static AC parseRowConstraints(String var0) {
      return parseAxisConstraint(var0, false);
   }

   public static AC parseColumnConstraints(String var0) {
      return parseAxisConstraint(var0, true);
   }

   private static AC parseAxisConstraint(String var0, boolean var1) {
      var0 = var0.trim();
      if (var0.length() == 0) {
         return new AC();
      } else {
         var0 = var0.toLowerCase();
         ArrayList var2 = getRowColAndGapsTrimmed(var0);
         BoundSize[] var3 = new BoundSize[(var2.size() >> 1) + 1];
         int var4 = 0;
         int var5 = var2.size();

         int var6;
         for(var6 = 0; var4 < var5; ++var6) {
            var3[var6] = parseBoundSize((String)var2.get(var4), true, var1);
            var4 += 2;
         }

         DimConstraint[] var7 = new DimConstraint[var2.size() >> 1];
         var5 = 0;

         for(var6 = 0; var5 < var7.length; ++var6) {
            if (var6 >= var3.length - 1) {
               var6 = var3.length - 2;
            }

            var7[var5] = parseDimConstraint((String)var2.get((var5 << 1) + 1), var3[var6], var3[var6 + 1], var1);
            ++var5;
         }

         AC var8 = new AC();
         var8.setConstaints(var7);
         return var8;
      }
   }

   private static DimConstraint parseDimConstraint(String var0, BoundSize var1, BoundSize var2, boolean var3) {
      DimConstraint var4 = new DimConstraint();
      var4.setGapBefore(var1);
      var4.setGapAfter(var2);
      String[] var5 = toTrimmedTokens(var0, ',');

      for(int var6 = 0; var6 < var5.length; ++var6) {
         String var7 = var5[var6];

         try {
            if (var7.length() != 0) {
               if (var7.equals("fill")) {
                  var4.setFill(true);
               } else if (var7.equals("nogrid")) {
                  var4.setNoGrid(true);
               } else {
                  boolean var8 = true;
                  char var9 = var7.charAt(0);
                  int var12;
                  if (var9 == 's') {
                     var12 = startsWithLenient(var7, new String[]{"sizegroup", "sg"}, new int[]{5, 2}, true);
                     if (var12 > -1) {
                        var4.setSizeGroup(var7.substring(var12).trim());
                        continue;
                     }

                     var12 = startsWithLenient(var7, new String[]{"shrinkprio", "shp"}, new int[]{10, 3}, true);
                     if (var12 > -1) {
                        var4.setShrinkPriority(Integer.parseInt(var7.substring(var12).trim()));
                        continue;
                     }

                     var12 = startsWithLenient(var7, "shrink", 6, true);
                     if (var12 > -1) {
                        var4.setShrink(parseFloat(var7.substring(var12).trim(), ResizeConstraint.WEIGHT_100));
                        continue;
                     }
                  }

                  if (var9 == 'g') {
                     var12 = startsWithLenient(var7, new String[]{"growpriority", "gp"}, new int[]{5, 2}, true);
                     if (var12 > -1) {
                        var4.setGrowPriority(Integer.parseInt(var7.substring(var12).trim()));
                        continue;
                     }

                     var12 = startsWithLenient(var7, "grow", 4, true);
                     if (var12 > -1) {
                        var4.setGrow(parseFloat(var7.substring(var12).trim(), ResizeConstraint.WEIGHT_100));
                        continue;
                     }
                  }

                  if (var9 == 'a') {
                     var12 = startsWithLenient(var7, "align", 2, true);
                     if (var12 > -1) {
                        var4.setAlign(parseUnitValueOrAlign(var7.substring(var12).trim(), var3, (UnitValue)null));
                        continue;
                     }
                  }

                  UnitValue var10 = parseAlignKeywords(var7, var3);
                  if (var10 != null) {
                     var4.setAlign(var10);
                  } else {
                     var4.setSize(parseBoundSize(var7, false, var3));
                  }
               }
            }
         } catch (Exception var11) {
            throw new IllegalArgumentException("Illegal contraint: '" + var7 + "'\n" + var11.getMessage());
         }
      }

      return var4;
   }

   public static Map<ComponentWrapper, CC> parseComponentConstraints(Map<ComponentWrapper, String> var0) {
      HashMap var1 = new HashMap();
      Iterator var2 = var0.entrySet().iterator();

      while(var2.hasNext()) {
         Entry var3 = (Entry)var2.next();
         var1.put(var3.getKey(), parseComponentConstraint((String)var3.getValue()));
      }

      return var1;
   }

   public static CC parseComponentConstraint(String var0) {
      CC var1 = new CC();
      if (var0.length() == 0) {
         return var1;
      } else {
         String[] var2 = toTrimmedTokens(var0, ',');
         String[] var3 = var2;
         int var4 = var2.length;

         for(int var5 = 0; var5 < var4; ++var5) {
            String var6 = var3[var5];

            try {
               if (var6.length() != 0) {
                  boolean var7 = true;
                  char var8 = var6.charAt(0);
                  String var18;
                  if (var8 == 'n') {
                     if (var6.equals("north")) {
                        var1.setDockSide(0);
                        continue;
                     }

                     if (var6.equals("newline")) {
                        var1.setNewline(true);
                        continue;
                     }

                     if (var6.startsWith("newline ")) {
                        var18 = var6.substring(7).trim();
                        var1.setNewlineGapSize(parseBoundSize(var18, true, true));
                        continue;
                     }
                  }

                  if (var8 != 'f' || !var6.equals("flowy") && !var6.equals("flowx")) {
                     int var15;
                     char var21;
                     String[] var22;
                     if (var8 == 's') {
                        var15 = startsWithLenient(var6, "skip", 4, true);
                        if (var15 > -1) {
                           var18 = var6.substring(var15).trim();
                           var1.setSkip(var18.length() != 0 ? Integer.parseInt(var18) : 1);
                           continue;
                        }

                        var15 = startsWithLenient(var6, "split", 5, true);
                        if (var15 > -1) {
                           var18 = var6.substring(var15).trim();
                           var1.setSplit(var18.length() > 0 ? Integer.parseInt(var18) : 2097051);
                           continue;
                        }

                        if (var6.equals("south")) {
                           var1.setDockSide(2);
                           continue;
                        }

                        var15 = startsWithLenient(var6, new String[]{"spany", "sy"}, new int[]{5, 2}, true);
                        if (var15 > -1) {
                           var1.setSpanY(parseSpan(var6.substring(var15).trim()));
                           continue;
                        }

                        var15 = startsWithLenient(var6, new String[]{"spanx", "sx"}, new int[]{5, 2}, true);
                        if (var15 > -1) {
                           var1.setSpanX(parseSpan(var6.substring(var15).trim()));
                           continue;
                        }

                        var15 = startsWithLenient(var6, "span", 4, true);
                        if (var15 > -1) {
                           var22 = toTrimmedTokens(var6.substring(var15).trim(), ' ');
                           var1.setSpanX(var22[0].length() > 0 ? Integer.parseInt(var22[0]) : 2097051);
                           var1.setSpanY(var22.length > 1 ? Integer.parseInt(var22[1]) : 1);
                           continue;
                        }

                        var15 = startsWithLenient(var6, "shrinkx", 7, true);
                        if (var15 > -1) {
                           var1.getHorizontal().setShrink(parseFloat(var6.substring(var15).trim(), ResizeConstraint.WEIGHT_100));
                           continue;
                        }

                        var15 = startsWithLenient(var6, "shrinky", 7, true);
                        if (var15 > -1) {
                           var1.getVertical().setShrink(parseFloat(var6.substring(var15).trim(), ResizeConstraint.WEIGHT_100));
                           continue;
                        }

                        var15 = startsWithLenient(var6, "shrink", 6, false);
                        if (var15 > -1) {
                           var22 = toTrimmedTokens(var6.substring(var15).trim(), ' ');
                           var1.getHorizontal().setShrink(parseFloat(var6.substring(var15).trim(), ResizeConstraint.WEIGHT_100));
                           if (var22.length > 1) {
                              var1.getVertical().setShrink(parseFloat(var6.substring(var15).trim(), ResizeConstraint.WEIGHT_100));
                           }
                           continue;
                        }

                        var15 = startsWithLenient(var6, new String[]{"shrinkprio", "shp"}, new int[]{10, 3}, true);
                        if (var15 > -1) {
                           var18 = var6.substring(var15).trim();
                           if (!var18.startsWith("x") && !var18.startsWith("y")) {
                              String[] var31 = toTrimmedTokens(var18, ' ');
                              var1.getHorizontal().setShrinkPriority(Integer.parseInt(var31[0]));
                              if (var31.length > 1) {
                                 var1.getVertical().setShrinkPriority(Integer.parseInt(var31[1]));
                              }
                           } else {
                              (var18.startsWith("x") ? var1.getHorizontal() : var1.getVertical()).setShrinkPriority(Integer.parseInt(var18.substring(2)));
                           }
                           continue;
                        }

                        var15 = startsWithLenient(var6, new String[]{"sizegroupx", "sizegroupy", "sgx", "sgy"}, new int[]{9, 9, 2, 2}, true);
                        if (var15 > -1) {
                           var18 = var6.substring(var15).trim();
                           var21 = var6.charAt(var15 - 1);
                           if (var21 != 'y') {
                              var1.getHorizontal().setSizeGroup(var18);
                           }

                           if (var21 != 'x') {
                              var1.getVertical().setSizeGroup(var18);
                           }
                           continue;
                        }
                     }

                     if (var8 == 'g') {
                        var15 = startsWithLenient(var6, "growx", 5, true);
                        if (var15 > -1) {
                           var1.getHorizontal().setGrow(parseFloat(var6.substring(var15).trim(), ResizeConstraint.WEIGHT_100));
                           continue;
                        }

                        var15 = startsWithLenient(var6, "growy", 5, true);
                        if (var15 > -1) {
                           var1.getVertical().setGrow(parseFloat(var6.substring(var15).trim(), ResizeConstraint.WEIGHT_100));
                           continue;
                        }

                        var15 = startsWithLenient(var6, "grow", 4, false);
                        if (var15 > -1) {
                           var22 = toTrimmedTokens(var6.substring(var15).trim(), ' ');
                           var1.getHorizontal().setGrow(parseFloat(var22[0], ResizeConstraint.WEIGHT_100));
                           var1.getVertical().setGrow(parseFloat(var22.length > 1 ? var22[1] : "", ResizeConstraint.WEIGHT_100));
                           continue;
                        }

                        var15 = startsWithLenient(var6, new String[]{"growprio", "gp"}, new int[]{8, 2}, true);
                        if (var15 > -1) {
                           var18 = var6.substring(var15).trim();
                           var21 = var18.length() > 0 ? var18.charAt(0) : 32;
                           if (var21 != 'x' && var21 != 'y') {
                              String[] var29 = toTrimmedTokens(var18, ' ');
                              var1.getHorizontal().setGrowPriority(Integer.parseInt(var29[0]));
                              if (var29.length > 1) {
                                 var1.getVertical().setGrowPriority(Integer.parseInt(var29[1]));
                              }
                           } else {
                              (var21 == 'x' ? var1.getHorizontal() : var1.getVertical()).setGrowPriority(Integer.parseInt(var18.substring(2)));
                           }
                           continue;
                        }

                        if (var6.startsWith("gap")) {
                           BoundSize[] var30 = parseGaps(var6);
                           if (var30[0] != null) {
                              var1.getVertical().setGapBefore(var30[0]);
                           }

                           if (var30[1] != null) {
                              var1.getHorizontal().setGapBefore(var30[1]);
                           }

                           if (var30[2] != null) {
                              var1.getVertical().setGapAfter(var30[2]);
                           }

                           if (var30[3] != null) {
                              var1.getHorizontal().setGapAfter(var30[3]);
                           }
                           continue;
                        }
                     }

                     if (var8 == 'a') {
                        var15 = startsWithLenient(var6, new String[]{"aligny", "ay"}, new int[]{6, 2}, true);
                        if (var15 > -1) {
                           var1.getVertical().setAlign(parseUnitValueOrAlign(var6.substring(var15).trim(), false, (UnitValue)null));
                           continue;
                        }

                        var15 = startsWithLenient(var6, new String[]{"alignx", "ax"}, new int[]{6, 2}, true);
                        if (var15 > -1) {
                           var1.getHorizontal().setAlign(parseUnitValueOrAlign(var6.substring(var15).trim(), true, (UnitValue)null));
                           continue;
                        }

                        var15 = startsWithLenient(var6, "align", 2, true);
                        if (var15 > -1) {
                           var22 = toTrimmedTokens(var6.substring(var15).trim(), ' ');
                           var1.getHorizontal().setAlign(parseUnitValueOrAlign(var22[0], true, (UnitValue)null));
                           if (var22.length > 1) {
                              var1.getVertical().setAlign(parseUnitValueOrAlign(var22[1], false, (UnitValue)null));
                           }
                           continue;
                        }
                     }

                     if ((var8 == 'x' || var8 == 'y') && var6.length() > 2) {
                        char var9 = var6.charAt(1);
                        if (var9 == ' ' || var9 == '2' && var6.charAt(2) == ' ') {
                           if (var1.getPos() == null) {
                              var1.setPos(new UnitValue[4]);
                           } else if (!var1.isBoundsInGrid()) {
                              throw new IllegalArgumentException("Cannot combine 'position' with 'x/y/x2/y2' keywords.");
                           }

                           int var27 = (var8 == 'x' ? 0 : 1) + (var9 == '2' ? 2 : 0);
                           UnitValue[] var28 = var1.getPos();
                           var28[var27] = parseUnitValue(var6.substring(2).trim(), (UnitValue)null, var8 == 'x');
                           var1.setPos(var28);
                           var1.setBoundsInGrid(true);
                           continue;
                        }
                     }

                     if (var8 == 'c') {
                        var15 = startsWithLenient(var6, "cell", 4, true);
                        if (var15 > -1) {
                           var22 = toTrimmedTokens(var6.substring(var15).trim(), ' ');
                           if (var22.length < 2) {
                              throw new IllegalArgumentException("At least two integers must follow " + var6);
                           }

                           var1.setCellX(Integer.parseInt(var22[0]));
                           var1.setCellY(Integer.parseInt(var22[1]));
                           if (var22.length > 2) {
                              var1.setSpanX(Integer.parseInt(var22[2]));
                           }

                           if (var22.length > 3) {
                              var1.setSpanY(Integer.parseInt(var22[3]));
                           }
                           continue;
                        }
                     }

                     if (var8 == 'p') {
                        var15 = startsWithLenient(var6, "pos", 3, true);
                        if (var15 > -1) {
                           if (var1.getPos() != null && var1.isBoundsInGrid()) {
                              throw new IllegalArgumentException("Can not combine 'pos' with 'x/y/x2/y2' keywords.");
                           }

                           var22 = toTrimmedTokens(var6.substring(var15).trim(), ' ');
                           UnitValue[] var25 = new UnitValue[4];

                           for(int var26 = 0; var26 < var22.length; ++var26) {
                              var25[var26] = parseUnitValue(var22[var26], (UnitValue)null, var26 % 2 == 0);
                           }

                           if (var25[0] == null && var25[2] == null || var25[1] == null && var25[3] == null) {
                              throw new IllegalArgumentException("Both x and x2 or y and y2 can not be null!");
                           }

                           var1.setPos(var25);
                           var1.setBoundsInGrid(false);
                           continue;
                        }

                        var15 = startsWithLenient(var6, "pad", 3, true);
                        if (var15 > -1) {
                           UnitValue[] var23 = parseInsets(var6.substring(var15).trim(), false);
                           var1.setPadding(new UnitValue[]{var23[0], var23.length > 1 ? var23[1] : null, var23.length > 2 ? var23[2] : null, var23.length > 3 ? var23[3] : null});
                           continue;
                        }

                        var15 = startsWithLenient(var6, "pushx", 5, true);
                        if (var15 > -1) {
                           var1.setPushX(parseFloat(var6.substring(var15).trim(), ResizeConstraint.WEIGHT_100));
                           continue;
                        }

                        var15 = startsWithLenient(var6, "pushy", 5, true);
                        if (var15 > -1) {
                           var1.setPushY(parseFloat(var6.substring(var15).trim(), ResizeConstraint.WEIGHT_100));
                           continue;
                        }

                        var15 = startsWithLenient(var6, "push", 4, false);
                        if (var15 > -1) {
                           var22 = toTrimmedTokens(var6.substring(var15).trim(), ' ');
                           var1.setPushX(parseFloat(var22[0], ResizeConstraint.WEIGHT_100));
                           var1.setPushY(parseFloat(var22.length > 1 ? var22[1] : "", ResizeConstraint.WEIGHT_100));
                           continue;
                        }
                     }

                     if (var8 == 't') {
                        var15 = startsWithLenient(var6, "tag", 3, true);
                        if (var15 > -1) {
                           var1.setTag(var6.substring(var15).trim());
                           continue;
                        }
                     }

                     if (var8 == 'w' || var8 == 'h') {
                        if (var6.equals("wrap")) {
                           var1.setWrap(true);
                           continue;
                        }

                        if (var6.startsWith("wrap ")) {
                           var18 = var6.substring(5).trim();
                           var1.setWrapGapSize(parseBoundSize(var18, true, true));
                           continue;
                        }

                        boolean var16 = var8 == 'w';
                        String var10;
                        if (var16 && (var6.startsWith("w ") || var6.startsWith("width "))) {
                           var10 = var6.substring(var6.charAt(1) == ' ' ? 2 : 6).trim();
                           var1.getHorizontal().setSize(parseBoundSize(var10, false, true));
                           continue;
                        }

                        if (!var16 && (var6.startsWith("h ") || var6.startsWith("height "))) {
                           var10 = var6.substring(var6.charAt(1) == ' ' ? 2 : 7).trim();
                           var1.getVertical().setSize(parseBoundSize(var10, false, false));
                           continue;
                        }

                        if (var6.startsWith("wmin ") || var6.startsWith("wmax ") || var6.startsWith("hmin ") || var6.startsWith("hmax ")) {
                           var10 = var6.substring(5).trim();
                           if (var10.length() > 0) {
                              UnitValue var24 = parseUnitValue(var10, (UnitValue)null, var16);
                              boolean var12 = var6.charAt(3) == 'n';
                              DimConstraint var13 = var16 ? var1.getHorizontal() : var1.getVertical();
                              var13.setSize(new BoundSize(var12 ? var24 : var13.getSize().getMin(), var13.getSize().getPreferred(), var12 ? var13.getSize().getMax() : var24, var10));
                              continue;
                           }
                        }

                        if (var6.equals("west")) {
                           var1.setDockSide(1);
                           continue;
                        }

                        if (var6.startsWith("hidemode ")) {
                           var1.setHideMode(Integer.parseInt(var6.substring(9)));
                           continue;
                        }
                     }

                     if (var8 == 'i' && var6.startsWith("id ")) {
                        var1.setId(var6.substring(3).trim());
                        int var19 = var1.getId().indexOf(46);
                        if (var19 == 0 || var19 == var1.getId().length() - 1) {
                           throw new IllegalArgumentException("Dot must not be first or last!");
                        }
                     } else {
                        if (var8 == 'e') {
                           if (var6.equals("east")) {
                              var1.setDockSide(3);
                              continue;
                           }

                           if (var6.equals("external")) {
                              var1.setExternal(true);
                              continue;
                           }

                           var15 = startsWithLenient(var6, new String[]{"endgroupx", "endgroupy", "egx", "egy"}, new int[]{-1, -1, -1, -1}, true);
                           if (var15 > -1) {
                              var18 = var6.substring(var15).trim();
                              var21 = var6.charAt(var15 - 1);
                              DimConstraint var11 = var21 == 'x' ? var1.getHorizontal() : var1.getVertical();
                              var11.setEndGroup(var18);
                              continue;
                           }
                        }

                        if (var8 == 'd') {
                           if (var6.equals("dock north")) {
                              var1.setDockSide(0);
                              continue;
                           }

                           if (var6.equals("dock west")) {
                              var1.setDockSide(1);
                              continue;
                           }

                           if (var6.equals("dock south")) {
                              var1.setDockSide(2);
                              continue;
                           }

                           if (var6.equals("dock east")) {
                              var1.setDockSide(3);
                              continue;
                           }

                           if (var6.equals("dock center")) {
                              var1.getHorizontal().setGrow(100.0F);
                              var1.getVertical().setGrow(100.0F);
                              var1.setPushX(100.0F);
                              var1.setPushY(100.0F);
                              continue;
                           }
                        }

                        UnitValue var17 = parseAlignKeywords(var6, true);
                        if (var17 != null) {
                           var1.getHorizontal().setAlign(var17);
                        } else {
                           UnitValue var20 = parseAlignKeywords(var6, false);
                           if (var20 == null) {
                              throw new IllegalArgumentException("Unknown keyword.");
                           }

                           var1.getVertical().setAlign(var20);
                        }
                     }
                  } else {
                     var1.setFlowX(var6.charAt(4) == 'x' ? Boolean.TRUE : Boolean.FALSE);
                  }
               }
            } catch (Exception var14) {
               throw new IllegalArgumentException("Illegal Constraint: '" + var6 + "'\n" + var14.getMessage());
            }
         }

         return var1;
      }
   }

   public static UnitValue[] parseInsets(String var0, boolean var1) {
      UnitValue[] var3;
      int var4;
      if (var0.length() != 0 && !var0.equals("dialog") && !var0.equals("panel")) {
         String[] var6 = toTrimmedTokens(var0, ' ');
         var3 = new UnitValue[4];

         for(var4 = 0; var4 < 4; ++var4) {
            UnitValue var5 = parseUnitValue(var6[var4 < var6.length ? var4 : var6.length - 1], UnitValue.ZERO, var4 % 2 == 1);
            var3[var4] = var5 != null ? var5 : PlatformDefaults.getPanelInsets(var4);
         }

         return var3;
      } else if (!var1) {
         throw new IllegalAccessError("Insets now allowed: " + var0 + "\n");
      } else {
         boolean var2 = var0.startsWith("p");
         var3 = new UnitValue[4];

         for(var4 = 0; var4 < 4; ++var4) {
            var3[var4] = var2 ? PlatformDefaults.getPanelInsets(var4) : PlatformDefaults.getDialogInsets(var4);
         }

         return var3;
      }
   }

   private static BoundSize[] parseGaps(String var0) {
      BoundSize[] var1 = new BoundSize[4];
      int var2 = startsWithLenient(var0, "gaptop", -1, true);
      if (var2 > -1) {
         var0 = var0.substring(var2).trim();
         var1[0] = parseBoundSize(var0, true, false);
         return var1;
      } else {
         var2 = startsWithLenient(var0, "gapleft", -1, true);
         if (var2 > -1) {
            var0 = var0.substring(var2).trim();
            var1[1] = parseBoundSize(var0, true, true);
            return var1;
         } else {
            var2 = startsWithLenient(var0, "gapbottom", -1, true);
            if (var2 > -1) {
               var0 = var0.substring(var2).trim();
               var1[2] = parseBoundSize(var0, true, false);
               return var1;
            } else {
               var2 = startsWithLenient(var0, "gapright", -1, true);
               if (var2 > -1) {
                  var0 = var0.substring(var2).trim();
                  var1[3] = parseBoundSize(var0, true, true);
                  return var1;
               } else {
                  var2 = startsWithLenient(var0, "gapbefore", -1, true);
                  if (var2 > -1) {
                     var0 = var0.substring(var2).trim();
                     var1[1] = parseBoundSize(var0, true, true);
                     return var1;
                  } else {
                     var2 = startsWithLenient(var0, "gapafter", -1, true);
                     if (var2 > -1) {
                        var0 = var0.substring(var2).trim();
                        var1[3] = parseBoundSize(var0, true, true);
                        return var1;
                     } else {
                        var2 = startsWithLenient(var0, new String[]{"gapx", "gapy"}, (int[])null, true);
                        if (var2 > -1) {
                           boolean var5 = var0.charAt(3) == 'x';
                           String[] var4 = toTrimmedTokens(var0.substring(var2).trim(), ' ');
                           var1[var5 ? 1 : 0] = parseBoundSize(var4[0], true, var5);
                           if (var4.length > 1) {
                              var1[var5 ? 3 : 2] = parseBoundSize(var4[1], true, !var5);
                           }

                           return var1;
                        } else {
                           var2 = startsWithLenient(var0, "gap ", 1, true);
                           if (var2 > -1) {
                              String[] var3 = toTrimmedTokens(var0.substring(var2).trim(), ' ');
                              var1[1] = parseBoundSize(var3[0], true, true);
                              if (var3.length > 1) {
                                 var1[3] = parseBoundSize(var3[1], true, false);
                                 if (var3.length > 2) {
                                    var1[0] = parseBoundSize(var3[2], true, true);
                                    if (var3.length > 3) {
                                       var1[2] = parseBoundSize(var3[3], true, false);
                                    }
                                 }
                              }

                              return var1;
                           } else {
                              throw new IllegalArgumentException("Unknown Gap part: '" + var0 + "'");
                           }
                        }
                     }
                  }
               }
            }
         }
      }
   }

   private static int parseSpan(String var0) {
      return var0.length() > 0 ? Integer.parseInt(var0) : 2097051;
   }

   private static Float parseFloat(String var0, Float var1) {
      return var0.length() > 0 ? new Float(Float.parseFloat(var0)) : var1;
   }

   public static BoundSize parseBoundSize(String var0, boolean var1, boolean var2) {
      if (var0.length() != 0 && !var0.equals("null") && !var0.equals("n")) {
         String var3 = var0;
         boolean var4 = false;
         if (var0.endsWith("push")) {
            var4 = true;
            int var5 = var0.length();
            var0 = var0.substring(0, var5 - (var0.endsWith(":push") ? 5 : 4));
            if (var0.length() == 0) {
               return new BoundSize((UnitValue)null, (UnitValue)null, (UnitValue)null, true, var3);
            }
         }

         String[] var9 = toTrimmedTokens(var0, ':');
         String var6 = var9[0];
         if (var9.length == 1) {
            boolean var7 = var6.endsWith("!");
            if (var7) {
               var6 = var6.substring(0, var6.length() - 1);
            }

            UnitValue var8 = parseUnitValue(var6, (UnitValue)null, var2);
            return new BoundSize(!var1 && !var7 ? null : var8, var8, var7 ? var8 : null, var4, var3);
         } else if (var9.length == 2) {
            return new BoundSize(parseUnitValue(var6, (UnitValue)null, var2), parseUnitValue(var9[1], (UnitValue)null, var2), (UnitValue)null, var4, var3);
         } else if (var9.length == 3) {
            return new BoundSize(parseUnitValue(var6, (UnitValue)null, var2), parseUnitValue(var9[1], (UnitValue)null, var2), parseUnitValue(var9[2], (UnitValue)null, var2), var4, var3);
         } else {
            throw new IllegalArgumentException("Min:Preferred:Max size section must contain 0, 1 or 2 colons. '" + var3 + "'");
         }
      } else {
         return null;
      }
   }

   public static UnitValue parseUnitValueOrAlign(String var0, boolean var1, UnitValue var2) {
      if (var0.length() == 0) {
         return var2;
      } else {
         UnitValue var3 = parseAlignKeywords(var0, var1);
         return var3 != null ? var3 : parseUnitValue(var0, var2, var1);
      }
   }

   public static UnitValue parseUnitValue(String var0, boolean var1) {
      return parseUnitValue(var0, (UnitValue)null, var1);
   }

   private static UnitValue parseUnitValue(String var0, UnitValue var1, boolean var2) {
      if (var0 != null && var0.length() != 0) {
         String var3 = var0;
         char var4 = var0.charAt(0);
         if (var4 == '(' && var0.charAt(var0.length() - 1) == ')') {
            var0 = var0.substring(1, var0.length() - 1);
         }

         if (var4 == 'n' && (var0.equals("null") || var0.equals("n"))) {
            return null;
         } else if (var4 == 'i' && var0.equals("inf")) {
            return UnitValue.INF;
         } else {
            int var5 = getOper(var0);
            boolean var6 = var5 == 101 || var5 == 102 || var5 == 103 || var5 == 104;
            String[] var7;
            if (var5 != 100) {
               if (!var6) {
                  String var12 = var0.substring(4, var0.length() - 1).trim();
                  var7 = toTrimmedTokens(var12, ',');
                  if (var7.length == 1) {
                     return parseUnitValue(var12, (UnitValue)null, var2);
                  }
               } else {
                  char var13;
                  if (var5 == 101) {
                     var13 = '+';
                  } else if (var5 == 102) {
                     var13 = '-';
                  } else if (var5 == 103) {
                     var13 = '*';
                  } else {
                     var13 = '/';
                  }

                  var7 = toTrimmedTokens(var0, var13);
                  if (var7.length > 2) {
                     String var9 = var7[var7.length - 1];
                     String var10 = var0.substring(0, var0.length() - var9.length() - 1);
                     var7 = new String[]{var10, var9};
                  }
               }

               if (var7.length != 2) {
                  throw new IllegalArgumentException("Malformed UnitValue: '" + var0 + "'");
               } else {
                  UnitValue var15 = parseUnitValue(var7[0], (UnitValue)null, var2);
                  UnitValue var14 = parseUnitValue(var7[1], (UnitValue)null, var2);
                  if (var15 != null && var14 != null) {
                     return new UnitValue(var2, var5, var15, var14, var3);
                  } else {
                     throw new IllegalArgumentException("Malformed UnitValue. Must be two sub-values: '" + var0 + "'");
                  }
               }
            } else {
               try {
                  var7 = getNumTextParts(var0);
                  float var8 = var7[0].length() > 0 ? Float.parseFloat(var7[0]) : 1.0F;
                  return new UnitValue(var8, var7[1], var2, var5, var3);
               } catch (Exception var11) {
                  throw new IllegalArgumentException("Malformed UnitValue: '" + var0 + "'");
               }
            }
         }
      } else {
         return var1;
      }
   }

   static UnitValue parseAlignKeywords(String var0, boolean var1) {
      if (startsWithLenient(var0, "center", 1, false) != -1) {
         return UnitValue.CENTER;
      } else {
         if (var1) {
            if (startsWithLenient(var0, "left", 1, false) != -1) {
               return UnitValue.LEFT;
            }

            if (startsWithLenient(var0, "right", 1, false) != -1) {
               return UnitValue.RIGHT;
            }

            if (startsWithLenient(var0, "leading", 4, false) != -1) {
               return UnitValue.LEADING;
            }

            if (startsWithLenient(var0, "trailing", 5, false) != -1) {
               return UnitValue.TRAILING;
            }

            if (startsWithLenient(var0, "label", 5, false) != -1) {
               return UnitValue.LABEL;
            }
         } else {
            if (startsWithLenient(var0, "baseline", 4, false) != -1) {
               return UnitValue.BASELINE_IDENTITY;
            }

            if (startsWithLenient(var0, "top", 1, false) != -1) {
               return UnitValue.TOP;
            }

            if (startsWithLenient(var0, "bottom", 1, false) != -1) {
               return UnitValue.BOTTOM;
            }
         }

         return null;
      }
   }

   private static String[] getNumTextParts(String var0) {
      int var1 = 0;

      for(int var2 = var0.length(); var1 < var2; ++var1) {
         char var3 = var0.charAt(var1);
         if (var3 == ' ') {
            throw new IllegalArgumentException("Space in UnitValue: '" + var0 + "'");
         }

         if ((var3 < '0' || var3 > '9') && var3 != '.' && var3 != '-') {
            return new String[]{var0.substring(0, var1).trim(), var0.substring(var1).trim()};
         }
      }

      return new String[]{var0, ""};
   }

   private static int getOper(String var0) {
      int var1 = var0.length();
      if (var1 < 3) {
         return 100;
      } else {
         if (var1 > 5 && var0.charAt(3) == '(' && var0.charAt(var1 - 1) == ')') {
            if (var0.startsWith("min(")) {
               return 105;
            }

            if (var0.startsWith("max(")) {
               return 106;
            }

            if (var0.startsWith("mid(")) {
               return 107;
            }
         }

         for(int var2 = 0; var2 < 2; ++var2) {
            int var3 = var1 - 1;

            for(int var4 = 0; var3 > 0; --var3) {
               char var5 = var0.charAt(var3);
               if (var5 == ')') {
                  ++var4;
               } else if (var5 == '(') {
                  --var4;
               } else if (var4 == 0) {
                  if (var2 == 0) {
                     if (var5 == '+') {
                        return 101;
                     }

                     if (var5 == '-') {
                        return 102;
                     }
                  } else {
                     if (var5 == '*') {
                        return 103;
                     }

                     if (var5 == '/') {
                        return 104;
                     }
                  }
               }
            }
         }

         return 100;
      }
   }

   private static int startsWithLenient(String var0, String[] var1, int[] var2, boolean var3) {
      for(int var4 = 0; var4 < var1.length; ++var4) {
         int var5 = var2 != null ? var2[var4] : -1;
         int var6 = startsWithLenient(var0, var1[var4], var5, var3);
         if (var6 > -1) {
            return var6;
         }
      }

      return -1;
   }

   private static int startsWithLenient(String var0, String var1, int var2, boolean var3) {
      if (var0.charAt(0) != var1.charAt(0)) {
         return -1;
      } else {
         if (var2 == -1) {
            var2 = var1.length();
         }

         int var4 = var0.length();
         if (var4 < var2) {
            return -1;
         } else {
            int var5 = var1.length();
            int var6 = 0;

            for(int var7 = 0; var7 < var5; ++var7) {
               while(var6 < var4 && (var0.charAt(var6) == ' ' || var0.charAt(var6) == '_')) {
                  ++var6;
               }

               if (var6 >= var4 || var0.charAt(var6) != var1.charAt(var7)) {
                  return var7 < var2 || !var3 && var6 < var4 || var6 < var4 && var0.charAt(var6 - 1) != ' ' ? -1 : var6;
               }

               ++var6;
            }

            return var6 < var4 && !var3 && var0.charAt(var6) != ' ' ? -1 : var6;
         }
      }
   }

   private static String[] toTrimmedTokens(String var0, char var1) {
      int var2 = 0;
      int var3 = var0.length();
      boolean var4 = var1 == ' ';
      int var5 = 0;

      for(int var6 = 0; var6 < var3; ++var6) {
         char var7 = var0.charAt(var6);
         if (var7 == '(') {
            ++var5;
         } else if (var7 == ')') {
            --var5;
         } else if (var5 == 0 && var7 == var1) {
            ++var2;

            while(var4 && var6 < var3 - 1 && var0.charAt(var6 + 1) == ' ') {
               ++var6;
            }
         }

         if (var5 < 0) {
            throw new IllegalArgumentException("Unbalanced parentheses: '" + var0 + "'");
         }
      }

      if (var5 != 0) {
         throw new IllegalArgumentException("Unbalanced parentheses: '" + var0 + "'");
      } else if (var2 == 0) {
         return new String[]{var0.trim()};
      } else {
         String[] var11 = new String[var2 + 1];
         int var12 = 0;
         int var8 = 0;
         var5 = 0;

         for(int var9 = 0; var9 < var3; ++var9) {
            char var10 = var0.charAt(var9);
            if (var10 == '(') {
               ++var5;
            } else if (var10 == ')') {
               --var5;
            } else if (var5 == 0 && var10 == var1) {
               var11[var8++] = var0.substring(var12, var9).trim();

               for(var12 = var9 + 1; var4 && var9 < var3 - 1 && var0.charAt(var9 + 1) == ' '; ++var9) {
               }
            }
         }

         var11[var8++] = var0.substring(var12, var3).trim();
         return var11;
      }
   }

   private static ArrayList<String> getRowColAndGapsTrimmed(String var0) {
      if (var0.indexOf(124) != -1) {
         var0 = var0.replaceAll("\\|", "][");
      }

      ArrayList var1 = new ArrayList(Math.max(var0.length() >> 3, 3));
      int var2 = 0;
      int var3 = 0;
      int var4 = 0;
      int var5 = 0;

      for(int var6 = var0.length(); var5 < var6; ++var5) {
         char var7 = var0.charAt(var5);
         if (var7 == '[') {
            ++var2;
         } else {
            if (var7 != ']') {
               continue;
            }

            ++var3;
         }

         if (var2 != var3 && var2 - 1 != var3) {
            break;
         }

         var1.add(var0.substring(var4, var5).trim());
         var4 = var5 + 1;
      }

      if (var2 != var3) {
         throw new IllegalArgumentException("'[' and ']' mismatch in row/column format string: " + var0);
      } else {
         if (var2 == 0) {
            var1.add("");
            var1.add(var0);
            var1.add("");
         } else if (var1.size() % 2 == 0) {
            var1.add(var0.substring(var4, var0.length()));
         }

         return var1;
      }
   }

   public static String prepare(String var0) {
      return var0 != null ? var0.trim().toLowerCase() : "";
   }
}
