package net.miginfocom.layout;

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

public final class DimConstraint implements Externalizable {
   final ResizeConstraint resize = new ResizeConstraint();
   private String sizeGroup = null;
   private BoundSize size;
   private BoundSize gapBefore;
   private BoundSize gapAfter;
   private UnitValue align;
   private String endGroup;
   private boolean fill;
   private boolean noGrid;

   public DimConstraint() {
      this.size = BoundSize.NULL_SIZE;
      this.gapBefore = null;
      this.gapAfter = null;
      this.align = null;
      this.endGroup = null;
      this.fill = false;
      this.noGrid = false;
   }

   public int getGrowPriority() {
      return this.resize.growPrio;
   }

   public void setGrowPriority(int var1) {
      this.resize.growPrio = var1;
   }

   public Float getGrow() {
      return this.resize.grow;
   }

   public void setGrow(Float var1) {
      this.resize.grow = var1;
   }

   public int getShrinkPriority() {
      return this.resize.shrinkPrio;
   }

   public void setShrinkPriority(int var1) {
      this.resize.shrinkPrio = var1;
   }

   public Float getShrink() {
      return this.resize.shrink;
   }

   public void setShrink(Float var1) {
      this.resize.shrink = var1;
   }

   public UnitValue getAlignOrDefault(boolean var1) {
      if (this.align != null) {
         return this.align;
      } else if (var1) {
         return UnitValue.LEADING;
      } else {
         return !this.fill && PlatformDefaults.getDefaultRowAlignmentBaseline() ? UnitValue.BASELINE_IDENTITY : UnitValue.CENTER;
      }
   }

   public UnitValue getAlign() {
      return this.align;
   }

   public void setAlign(UnitValue var1) {
      this.align = var1;
   }

   public BoundSize getGapAfter() {
      return this.gapAfter;
   }

   public void setGapAfter(BoundSize var1) {
      this.gapAfter = var1;
   }

   boolean hasGapAfter() {
      return this.gapAfter != null && !this.gapAfter.isUnset();
   }

   boolean isGapAfterPush() {
      return this.gapAfter != null && this.gapAfter.getGapPush();
   }

   public BoundSize getGapBefore() {
      return this.gapBefore;
   }

   public void setGapBefore(BoundSize var1) {
      this.gapBefore = var1;
   }

   boolean hasGapBefore() {
      return this.gapBefore != null && !this.gapBefore.isUnset();
   }

   boolean isGapBeforePush() {
      return this.gapBefore != null && this.gapBefore.getGapPush();
   }

   public BoundSize getSize() {
      return this.size;
   }

   public void setSize(BoundSize var1) {
      if (var1 != null) {
         var1.checkNotLinked();
      }

      this.size = var1;
   }

   public String getSizeGroup() {
      return this.sizeGroup;
   }

   public void setSizeGroup(String var1) {
      this.sizeGroup = var1;
   }

   public String getEndGroup() {
      return this.endGroup;
   }

   public void setEndGroup(String var1) {
      this.endGroup = var1;
   }

   public boolean isFill() {
      return this.fill;
   }

   public void setFill(boolean var1) {
      this.fill = var1;
   }

   public boolean isNoGrid() {
      return this.noGrid;
   }

   public void setNoGrid(boolean var1) {
      this.noGrid = var1;
   }

   int[] getRowGaps(ContainerWrapper var1, BoundSize var2, int var3, boolean var4) {
      BoundSize var5 = var4 ? this.gapBefore : this.gapAfter;
      if (var5 == null || var5.isUnset()) {
         var5 = var2;
      }

      if (var5 != null && !var5.isUnset()) {
         int[] var6 = new int[3];

         for(int var7 = 0; var7 <= 2; ++var7) {
            UnitValue var8 = var5.getSize(var7);
            var6[var7] = var8 != null ? var8.getPixels((float)var3, var1, (ComponentWrapper)null) : -2147471302;
         }

         return var6;
      } else {
         return null;
      }
   }

   int[] getComponentGaps(ContainerWrapper var1, ComponentWrapper var2, BoundSize var3, ComponentWrapper var4, String var5, int var6, int var7, boolean var8) {
      BoundSize var9 = var7 < 2 ? this.gapBefore : this.gapAfter;
      boolean var10 = var9 != null && var9.getGapPush();
      if ((var9 == null || var9.isUnset()) && (var3 == null || var3.isUnset()) && var2 != null) {
         var9 = PlatformDefaults.getDefaultComponentGap(var2, var4, var7 + 1, var5, var8);
      }

      if (var9 == null) {
         return var10 ? new int[]{0, 0, -2147471302} : null;
      } else {
         int[] var11 = new int[3];

         for(int var12 = 0; var12 <= 2; ++var12) {
            UnitValue var13 = var9.getSize(var12);
            var11[var12] = var13 != null ? var13.getPixels((float)var6, var1, (ComponentWrapper)null) : -2147471302;
         }

         return var11;
      }
   }

   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() == DimConstraint.class) {
         LayoutUtil.writeAsXML(var1, this);
      }

   }
}
