package net.miginfocom.layout;

import java.beans.Encoder;
import java.beans.Expression;
import java.beans.PersistenceDelegate;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamException;
import java.io.Serializable;

public class BoundSize implements Serializable {
   public static final BoundSize NULL_SIZE = new BoundSize((UnitValue)null, (String)null);
   public static final BoundSize ZERO_PIXEL;
   private final transient UnitValue min;
   private final transient UnitValue pref;
   private final transient UnitValue max;
   private final transient boolean gapPush;
   private static final long serialVersionUID = 1L;

   public BoundSize(UnitValue var1, String var2) {
      this(var1, var1, var1, var2);
   }

   public BoundSize(UnitValue var1, UnitValue var2, UnitValue var3, String var4) {
      this(var1, var2, var3, false, var4);
   }

   public BoundSize(UnitValue var1, UnitValue var2, UnitValue var3, boolean var4, String var5) {
      this.min = var1;
      this.pref = var2;
      this.max = var3;
      this.gapPush = var4;
      LayoutUtil.putCCString(this, var5);
   }

   public final UnitValue getMin() {
      return this.min;
   }

   public final UnitValue getPreferred() {
      return this.pref;
   }

   public final UnitValue getMax() {
      return this.max;
   }

   public boolean getGapPush() {
      return this.gapPush;
   }

   public boolean isUnset() {
      return this == ZERO_PIXEL || this.pref == null && this.min == null && this.max == null && !this.gapPush;
   }

   public int constrain(int var1, float var2, ContainerWrapper var3) {
      if (this.max != null) {
         var1 = Math.min(var1, this.max.getPixels(var2, var3, var3));
      }

      if (this.min != null) {
         var1 = Math.max(var1, this.min.getPixels(var2, var3, var3));
      }

      return var1;
   }

   final UnitValue getSize(int var1) {
      switch(var1) {
      case 0:
         return this.min;
      case 1:
         return this.pref;
      case 2:
         return this.max;
      default:
         throw new IllegalArgumentException("Unknown size: " + var1);
      }
   }

   final int[] getPixelSizes(float var1, ContainerWrapper var2, ComponentWrapper var3) {
      return new int[]{this.min != null ? this.min.getPixels(var1, var2, var3) : 0, this.pref != null ? this.pref.getPixels(var1, var2, var3) : 0, this.max != null ? this.max.getPixels(var1, var2, var3) : 2097051};
   }

   String getConstraintString() {
      String var1 = LayoutUtil.getCCString(this);
      if (var1 != null) {
         return var1;
      } else if (this.min == this.pref && this.pref == this.max) {
         return this.min != null ? this.min.getConstraintString() + "!" : "null";
      } else {
         StringBuilder var2 = new StringBuilder(16);
         if (this.min != null) {
            var2.append(this.min.getConstraintString()).append(':');
         }

         if (this.pref != null) {
            if (this.min == null && this.max != null) {
               var2.append(":");
            }

            var2.append(this.pref.getConstraintString());
         } else if (this.min != null) {
            var2.append('n');
         }

         if (this.max != null) {
            var2.append(var2.length() == 0 ? "::" : ":").append(this.max.getConstraintString());
         }

         if (this.gapPush) {
            if (var2.length() > 0) {
               var2.append(':');
            }

            var2.append("push");
         }

         return var2.toString();
      }
   }

   void checkNotLinked() {
      if (this.min != null && this.min.isLinkedDeep() || this.pref != null && this.pref.isLinkedDeep() || this.max != null && this.max.isLinkedDeep()) {
         throw new IllegalArgumentException("Size may not contain links");
      }
   }

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

   private void writeObject(ObjectOutputStream var1) throws IOException {
      if (this.getClass() == BoundSize.class) {
         LayoutUtil.writeAsXML(var1, this);
      }

   }

   private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
      LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(var1));
   }

   static {
      ZERO_PIXEL = new BoundSize(UnitValue.ZERO, "0px");
      if (LayoutUtil.HAS_BEANS) {
         LayoutUtil.setDelegate(BoundSize.class, new PersistenceDelegate() {
            protected Expression instantiate(Object var1, Encoder var2) {
               BoundSize var3 = (BoundSize)var1;
               return new Expression(var1, BoundSize.class, "new", new Object[]{var3.getMin(), var3.getPreferred(), var3.getMax(), var3.getGapPush(), var3.getConstraintString()});
            }
         });
      }

   }
}
