package net.miginfocom.layout;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.ObjectStreamException;
import java.util.ArrayList;

public final class CC implements Externalizable {
   private static final BoundSize DEF_GAP;
   static final String[] DOCK_SIDES;
   private int dock = -1;
   private UnitValue[] pos = null;
   private UnitValue[] padding = null;
   private Boolean flowX = null;
   private int skip = 0;
   private int split = 1;
   private int spanX = 1;
   private int spanY = 1;
   private int cellX = -1;
   private int cellY = 0;
   private String tag = null;
   private String id = null;
   private int hideMode = -1;
   private DimConstraint hor = new DimConstraint();
   private DimConstraint ver = new DimConstraint();
   private BoundSize newline = null;
   private BoundSize wrap = null;
   private boolean boundsInGrid = true;
   private boolean external = false;
   private Float pushX = null;
   private Float pushY = null;
   private static final String[] EMPTY_ARR;
   private transient String[] linkTargets = null;

   String[] getLinkTargets() {
      if (this.linkTargets == null) {
         ArrayList var1 = new ArrayList(2);
         if (this.pos != null) {
            for(int var2 = 0; var2 < this.pos.length; ++var2) {
               this.addLinkTargetIDs(var1, this.pos[var2]);
            }
         }

         this.linkTargets = var1.size() == 0 ? EMPTY_ARR : (String[])var1.toArray(new String[var1.size()]);
      }

      return this.linkTargets;
   }

   private void addLinkTargetIDs(ArrayList<String> var1, UnitValue var2) {
      if (var2 != null) {
         String var3 = var2.getLinkTargetId();
         if (var3 != null) {
            var1.add(var3);
         } else {
            for(int var4 = var2.getSubUnitCount() - 1; var4 >= 0; --var4) {
               UnitValue var5 = var2.getSubUnitValue(var4);
               if (var5.isLinkedDeep()) {
                  this.addLinkTargetIDs(var1, var5);
               }
            }
         }
      }

   }

   public final CC endGroupX(String var1) {
      this.hor.setEndGroup(var1);
      return this;
   }

   public final CC sizeGroupX(String var1) {
      this.hor.setSizeGroup(var1);
      return this;
   }

   public final CC minWidth(String var1) {
      this.hor.setSize(LayoutUtil.derive(this.hor.getSize(), ConstraintParser.parseUnitValue(var1, true), (UnitValue)null, (UnitValue)null));
      return this;
   }

   public final CC width(String var1) {
      this.hor.setSize(ConstraintParser.parseBoundSize(var1, false, true));
      return this;
   }

   public final CC maxWidth(String var1) {
      this.hor.setSize(LayoutUtil.derive(this.hor.getSize(), (UnitValue)null, (UnitValue)null, ConstraintParser.parseUnitValue(var1, true)));
      return this;
   }

   public final CC gapX(String var1, String var2) {
      if (var1 != null) {
         this.hor.setGapBefore(ConstraintParser.parseBoundSize(var1, true, true));
      }

      if (var2 != null) {
         this.hor.setGapAfter(ConstraintParser.parseBoundSize(var2, true, true));
      }

      return this;
   }

   public final CC alignX(String var1) {
      this.hor.setAlign(ConstraintParser.parseUnitValueOrAlign(var1, true, (UnitValue)null));
      return this;
   }

   public final CC growPrioX(int var1) {
      this.hor.setGrowPriority(var1);
      return this;
   }

   public final CC growPrio(int... var1) {
      switch(var1.length) {
      case 2:
         this.growPrioY(var1[1]);
      case 1:
         this.growPrioX(var1[0]);
         return this;
      default:
         throw new IllegalArgumentException("Illegal argument count: " + var1.length);
      }
   }

   public final CC growX() {
      this.hor.setGrow(ResizeConstraint.WEIGHT_100);
      return this;
   }

   public final CC growX(float var1) {
      this.hor.setGrow(new Float(var1));
      return this;
   }

   public final CC grow(float... var1) {
      switch(var1.length) {
      case 2:
         this.growY(var1[1]);
      case 1:
         this.growX(var1[0]);
         return this;
      default:
         throw new IllegalArgumentException("Illegal argument count: " + var1.length);
      }
   }

   public final CC shrinkPrioX(int var1) {
      this.hor.setShrinkPriority(var1);
      return this;
   }

   public final CC shrinkPrio(int... var1) {
      switch(var1.length) {
      case 2:
         this.shrinkPrioY(var1[1]);
      case 1:
         this.shrinkPrioX(var1[0]);
         return this;
      default:
         throw new IllegalArgumentException("Illegal argument count: " + var1.length);
      }
   }

   public final CC shrinkX(float var1) {
      this.hor.setShrink(new Float(var1));
      return this;
   }

   public final CC shrink(float... var1) {
      switch(var1.length) {
      case 2:
         this.shrinkY(var1[1]);
      case 1:
         this.shrinkX(var1[0]);
         return this;
      default:
         throw new IllegalArgumentException("Illegal argument count: " + var1.length);
      }
   }

   public final CC endGroupY(String var1) {
      this.ver.setEndGroup(var1);
      return this;
   }

   public final CC endGroup(String... var1) {
      switch(var1.length) {
      case 2:
         this.endGroupY(var1[1]);
      case 1:
         this.endGroupX(var1[0]);
         return this;
      default:
         throw new IllegalArgumentException("Illegal argument count: " + var1.length);
      }
   }

   public final CC sizeGroupY(String var1) {
      this.ver.setSizeGroup(var1);
      return this;
   }

   public final CC sizeGroup(String... var1) {
      switch(var1.length) {
      case 2:
         this.sizeGroupY(var1[1]);
      case 1:
         this.sizeGroupX(var1[0]);
         return this;
      default:
         throw new IllegalArgumentException("Illegal argument count: " + var1.length);
      }
   }

   public final CC minHeight(String var1) {
      this.ver.setSize(LayoutUtil.derive(this.ver.getSize(), ConstraintParser.parseUnitValue(var1, false), (UnitValue)null, (UnitValue)null));
      return this;
   }

   public final CC height(String var1) {
      this.ver.setSize(ConstraintParser.parseBoundSize(var1, false, false));
      return this;
   }

   public final CC maxHeight(String var1) {
      this.ver.setSize(LayoutUtil.derive(this.ver.getSize(), (UnitValue)null, (UnitValue)null, ConstraintParser.parseUnitValue(var1, false)));
      return this;
   }

   public final CC gapY(String var1, String var2) {
      if (var1 != null) {
         this.ver.setGapBefore(ConstraintParser.parseBoundSize(var1, true, false));
      }

      if (var2 != null) {
         this.ver.setGapAfter(ConstraintParser.parseBoundSize(var2, true, false));
      }

      return this;
   }

   public final CC alignY(String var1) {
      this.ver.setAlign(ConstraintParser.parseUnitValueOrAlign(var1, false, (UnitValue)null));
      return this;
   }

   public final CC growPrioY(int var1) {
      this.ver.setGrowPriority(var1);
      return this;
   }

   public final CC growY() {
      this.ver.setGrow(ResizeConstraint.WEIGHT_100);
      return this;
   }

   public final CC growY(Float var1) {
      this.ver.setGrow(var1);
      return this;
   }

   public final CC shrinkPrioY(int var1) {
      this.ver.setShrinkPriority(var1);
      return this;
   }

   public final CC shrinkY(float var1) {
      this.ver.setShrink(new Float(var1));
      return this;
   }

   public final CC hideMode(int var1) {
      this.setHideMode(var1);
      return this;
   }

   public final CC id(String var1) {
      this.setId(var1);
      return this;
   }

   public final CC tag(String var1) {
      this.setTag(var1);
      return this;
   }

   public final CC cell(int... var1) {
      switch(var1.length) {
      case 4:
         this.setSpanY(var1[3]);
      case 3:
         this.setSpanX(var1[2]);
      case 2:
         this.setCellY(var1[1]);
      case 1:
         this.setCellX(var1[0]);
         return this;
      default:
         throw new IllegalArgumentException("Illegal argument count: " + var1.length);
      }
   }

   public final CC span(int... var1) {
      if (var1 != null && var1.length != 0) {
         if (var1.length == 1) {
            this.setSpanX(var1[0]);
            this.setSpanY(1);
         } else {
            this.setSpanX(var1[0]);
            this.setSpanY(var1[1]);
         }
      } else {
         this.setSpanX(2097051);
         this.setSpanY(1);
      }

      return this;
   }

   public final CC gap(String... var1) {
      switch(var1.length) {
      case 4:
         this.gapBottom(var1[3]);
      case 3:
         this.gapTop(var1[2]);
      case 2:
         this.gapRight(var1[1]);
      case 1:
         this.gapLeft(var1[0]);
         return this;
      default:
         throw new IllegalArgumentException("Illegal argument count: " + var1.length);
      }
   }

   public final CC gapBefore(String var1) {
      this.hor.setGapBefore(ConstraintParser.parseBoundSize(var1, true, true));
      return this;
   }

   public final CC gapAfter(String var1) {
      this.hor.setGapAfter(ConstraintParser.parseBoundSize(var1, true, true));
      return this;
   }

   public final CC gapTop(String var1) {
      this.ver.setGapBefore(ConstraintParser.parseBoundSize(var1, true, false));
      return this;
   }

   public final CC gapLeft(String var1) {
      this.hor.setGapBefore(ConstraintParser.parseBoundSize(var1, true, true));
      return this;
   }

   public final CC gapBottom(String var1) {
      this.ver.setGapAfter(ConstraintParser.parseBoundSize(var1, true, false));
      return this;
   }

   public final CC gapRight(String var1) {
      this.hor.setGapAfter(ConstraintParser.parseBoundSize(var1, true, true));
      return this;
   }

   public final CC spanY() {
      return this.spanY(2097051);
   }

   public final CC spanY(int var1) {
      this.setSpanY(var1);
      return this;
   }

   public final CC spanX() {
      return this.spanX(2097051);
   }

   public final CC spanX(int var1) {
      this.setSpanX(var1);
      return this;
   }

   public final CC push() {
      return this.pushX().pushY();
   }

   public final CC push(Float var1, Float var2) {
      return this.pushX(var1).pushY(var2);
   }

   public final CC pushY() {
      return this.pushY(ResizeConstraint.WEIGHT_100);
   }

   public final CC pushY(Float var1) {
      this.setPushY(var1);
      return this;
   }

   public final CC pushX() {
      return this.pushX(ResizeConstraint.WEIGHT_100);
   }

   public final CC pushX(Float var1) {
      this.setPushX(var1);
      return this;
   }

   public final CC split(int var1) {
      this.setSplit(var1);
      return this;
   }

   public final CC split() {
      this.setSplit(2097051);
      return this;
   }

   public final CC skip(int var1) {
      this.setSkip(var1);
      return this;
   }

   public final CC skip() {
      this.setSkip(1);
      return this;
   }

   public final CC external() {
      this.setExternal(true);
      return this;
   }

   public final CC flowX() {
      this.setFlowX(Boolean.TRUE);
      return this;
   }

   public final CC flowY() {
      this.setFlowX(Boolean.FALSE);
      return this;
   }

   public final CC grow() {
      this.growX();
      this.growY();
      return this;
   }

   public final CC newline() {
      this.setNewline(true);
      return this;
   }

   public final CC newline(String var1) {
      BoundSize var2 = ConstraintParser.parseBoundSize(var1, true, this.flowX != null && !this.flowX);
      if (var2 != null) {
         this.setNewlineGapSize(var2);
      } else {
         this.setNewline(true);
      }

      return this;
   }

   public final CC wrap() {
      this.setWrap(true);
      return this;
   }

   public final CC wrap(String var1) {
      BoundSize var2 = ConstraintParser.parseBoundSize(var1, true, this.flowX != null && !this.flowX);
      if (var2 != null) {
         this.setWrapGapSize(var2);
      } else {
         this.setWrap(true);
      }

      return this;
   }

   public final CC dockNorth() {
      this.setDockSide(0);
      return this;
   }

   public final CC dockWest() {
      this.setDockSide(1);
      return this;
   }

   public final CC dockSouth() {
      this.setDockSide(2);
      return this;
   }

   public final CC dockEast() {
      this.setDockSide(3);
      return this;
   }

   public final CC x(String var1) {
      return this.corrPos(var1, 0);
   }

   public final CC y(String var1) {
      return this.corrPos(var1, 1);
   }

   public final CC x2(String var1) {
      return this.corrPos(var1, 2);
   }

   public final CC y2(String var1) {
      return this.corrPos(var1, 3);
   }

   private final CC corrPos(String var1, int var2) {
      UnitValue[] var3 = this.getPos();
      if (var3 == null) {
         var3 = new UnitValue[4];
      }

      var3[var2] = ConstraintParser.parseUnitValue(var1, var2 % 2 == 0);
      this.setPos(var3);
      this.setBoundsInGrid(true);
      return this;
   }

   public final CC pos(String var1, String var2) {
      UnitValue[] var3 = this.getPos();
      if (var3 == null) {
         var3 = new UnitValue[4];
      }

      var3[0] = ConstraintParser.parseUnitValue(var1, true);
      var3[1] = ConstraintParser.parseUnitValue(var2, false);
      this.setPos(var3);
      this.setBoundsInGrid(false);
      return this;
   }

   public final CC pos(String var1, String var2, String var3, String var4) {
      this.setPos(new UnitValue[]{ConstraintParser.parseUnitValue(var1, true), ConstraintParser.parseUnitValue(var2, false), ConstraintParser.parseUnitValue(var3, true), ConstraintParser.parseUnitValue(var4, false)});
      this.setBoundsInGrid(false);
      return this;
   }

   public final CC pad(int var1, int var2, int var3, int var4) {
      this.setPadding(new UnitValue[]{new UnitValue((float)var1), new UnitValue((float)var2), new UnitValue((float)var3), new UnitValue((float)var4)});
      return this;
   }

   public final CC pad(String var1) {
      this.setPadding(var1 != null ? ConstraintParser.parseInsets(var1, false) : null);
      return this;
   }

   public DimConstraint getHorizontal() {
      return this.hor;
   }

   public void setHorizontal(DimConstraint var1) {
      this.hor = var1 != null ? var1 : new DimConstraint();
   }

   public DimConstraint getVertical() {
      return this.ver;
   }

   public void setVertical(DimConstraint var1) {
      this.ver = var1 != null ? var1 : new DimConstraint();
   }

   public DimConstraint getDimConstraint(boolean var1) {
      return var1 ? this.hor : this.ver;
   }

   public UnitValue[] getPos() {
      return this.pos != null ? new UnitValue[]{this.pos[0], this.pos[1], this.pos[2], this.pos[3]} : null;
   }

   public void setPos(UnitValue[] var1) {
      this.pos = var1 != null ? new UnitValue[]{var1[0], var1[1], var1[2], var1[3]} : null;
      this.linkTargets = null;
   }

   public boolean isBoundsInGrid() {
      return this.boundsInGrid;
   }

   void setBoundsInGrid(boolean var1) {
      this.boundsInGrid = var1;
   }

   public int getCellX() {
      return this.cellX;
   }

   public void setCellX(int var1) {
      this.cellX = var1;
   }

   public int getCellY() {
      return this.cellX < 0 ? -1 : this.cellY;
   }

   public void setCellY(int var1) {
      if (var1 < 0) {
         this.cellX = -1;
      }

      this.cellY = var1 < 0 ? 0 : var1;
   }

   public int getDockSide() {
      return this.dock;
   }

   public void setDockSide(int var1) {
      if (var1 >= -1 && var1 <= 3) {
         this.dock = var1;
      } else {
         throw new IllegalArgumentException("Illegal dock side: " + var1);
      }
   }

   public boolean isExternal() {
      return this.external;
   }

   public void setExternal(boolean var1) {
      this.external = var1;
   }

   public Boolean getFlowX() {
      return this.flowX;
   }

   public void setFlowX(Boolean var1) {
      this.flowX = var1;
   }

   public int getHideMode() {
      return this.hideMode;
   }

   public void setHideMode(int var1) {
      if (var1 >= -1 && var1 <= 3) {
         this.hideMode = var1;
      } else {
         throw new IllegalArgumentException("Wrong hideMode: " + var1);
      }
   }

   public String getId() {
      return this.id;
   }

   public void setId(String var1) {
      this.id = var1;
   }

   public UnitValue[] getPadding() {
      return this.padding != null ? new UnitValue[]{this.padding[0], this.padding[1], this.padding[2], this.padding[3]} : null;
   }

   public void setPadding(UnitValue[] var1) {
      this.padding = var1 != null ? new UnitValue[]{var1[0], var1[1], var1[2], var1[3]} : null;
   }

   public int getSkip() {
      return this.skip;
   }

   public void setSkip(int var1) {
      this.skip = var1;
   }

   public int getSpanX() {
      return this.spanX;
   }

   public void setSpanX(int var1) {
      this.spanX = var1;
   }

   public int getSpanY() {
      return this.spanY;
   }

   public void setSpanY(int var1) {
      this.spanY = var1;
   }

   public Float getPushX() {
      return this.pushX;
   }

   public void setPushX(Float var1) {
      this.pushX = var1;
   }

   public Float getPushY() {
      return this.pushY;
   }

   public void setPushY(Float var1) {
      this.pushY = var1;
   }

   public int getSplit() {
      return this.split;
   }

   public void setSplit(int var1) {
      this.split = var1;
   }

   public String getTag() {
      return this.tag;
   }

   public void setTag(String var1) {
      this.tag = var1;
   }

   public boolean isWrap() {
      return this.wrap != null;
   }

   public void setWrap(boolean var1) {
      this.wrap = var1 ? (this.wrap == null ? DEF_GAP : this.wrap) : null;
   }

   public BoundSize getWrapGapSize() {
      return this.wrap == DEF_GAP ? null : this.wrap;
   }

   public void setWrapGapSize(BoundSize var1) {
      this.wrap = var1 == null ? (this.wrap != null ? DEF_GAP : null) : var1;
   }

   public boolean isNewline() {
      return this.newline != null;
   }

   public void setNewline(boolean var1) {
      this.newline = var1 ? (this.newline == null ? DEF_GAP : this.newline) : null;
   }

   public BoundSize getNewlineGapSize() {
      return this.newline == DEF_GAP ? null : this.newline;
   }

   public void setNewlineGapSize(BoundSize var1) {
      this.newline = var1 == null ? (this.newline != null ? DEF_GAP : null) : var1;
   }

   private Object readResolve() throws ObjectStreamException {
      return LayoutUtil.getSerializedObject(this);
   }

   public void readExternal(ObjectInput var1) throws IOException, ClassNotFoundException {
      LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(var1));
   }

   public void writeExternal(ObjectOutput var1) throws IOException {
      if (this.getClass() == CC.class) {
         LayoutUtil.writeAsXML(var1, this);
      }

   }

   static {
      DEF_GAP = BoundSize.NULL_SIZE;
      DOCK_SIDES = new String[]{"north", "west", "south", "east"};
      EMPTY_ARR = new String[0];
   }
}
