?? spring.java
字號:
* Returns the maximum value of this Spring. * * @return the maximum value. */ public int getMaximumValue() { return max; } /** * Returns the minimum value of this Spring. * * @return the minimum value. */ public int getMinimumValue() { return min; } /** * Returns the preferred value of this Spring. * * @return the preferred value. */ public int getPreferredValue() { return pref; } /** * Return the actual current value of this Spring. * * @return the current value. */ public int getValue() { if (value == Spring.UNSET) return pref; return value; } /** * Sets the current value. * * @param val the value to be set. */ public void setValue(int val) { value = val; } } /** * A Spring, that is the sum of two other Springs. * * @author Roman Kennke (roman@ontographics.com) */ private static final class AddSpring extends Spring { /** The springs, that are the 'operands' of this Spring. */ private final Spring s1; private final Spring s2; /** The current value for this Spring. */ private int value; public String toString() { return "AddSpring of " + s1 + " and " + s2; } /** * Creates a new AddSpring object. * * @param s1 the first operand. * @param s2 the second operand. */ protected AddSpring(Spring s1, Spring s2) { super(); this.s1 = s1; this.s2 = s2; value = Spring.UNSET; } /** * Returns the maximum value of this Spring. * * @return the maximum value. */ public int getMaximumValue() { int max1 = s1.getMaximumValue(); int max2 = s2.getMaximumValue(); return max1 + max2; } /** * Return the minimum value of this Spring. * * @return the minimum value. */ public int getMinimumValue() { int min1 = s1.getMinimumValue(); int min2 = s2.getMinimumValue(); return min1 + min2; } /** * Returns the preferred value of this Spring. * * @return the preferred value. */ public int getPreferredValue() { int pref1 = s1.getPreferredValue(); int pref2 = s2.getPreferredValue(); return pref1 + pref2; } /** * Returns the actual current value of this Spring. * * @return the current value of this Spring. */ public int getValue() { if (value == Spring.UNSET) { int val1 = s1.getValue(); int val2 = s2.getValue(); value = val1 + val2; } return value; } /** * Sets the current value. * * @param val the value to be set. */ public void setValue(int val) { if (val == Spring.UNSET) { if (value != Spring.UNSET) { s1.setValue(Spring.UNSET); s2.setValue(Spring.UNSET); } value = Spring.UNSET; return; } value = val; //Spead the value over the two components double fStrain = getStrain(); s1.setStrain(fStrain); int remainder = val - s1.getValue(); s2.setValue(remainder); } } /** * A Spring that is calculated as the negation of another Spring. * * @author Roman Kennke (roman@ontographics.com) */ private static final class MinusSpring extends Spring { /** The Spring from which to calculate the negation. */ private final Spring s; public String toString() { return "MinusSpring of " + s; } /** * Creates a new MinusSpring object. * @param s the Spring from which to calculate the negation. */ protected MinusSpring(Spring s) { super(); this.s = s; } /** Returns the maximum value of this Spring. * * @return the maximum value. */ public int getMaximumValue() { return -s.getMinimumValue(); } /** * Returns the minimum value of this Spring. * * @return the minimum value. */ public int getMinimumValue() { return -s.getMaximumValue(); } /** * Returns the preferred value of this Spring. * * @return the preferred value. */ public int getPreferredValue() { return -s.getPreferredValue(); } /** * Returns the current value of this Spring. * * @return the current value. */ public int getValue() { return -s.getValue(); } /** * Sets the current value. * * @param val the value to be set. */ public void setValue(int val) { if (val == Spring.UNSET) s.setValue(Spring.UNSET); else s.setValue(-val); } } /** * A Spring, that is calculated as the maximum of two Springs. * * @author Roman Kennke (roman@ontographics.com) */ private static final class MaxSpring extends Spring { /** The two other Springs from which to calculate the maximum. */ private final Spring s1; private final Spring s2; public String toString() { return "MaxSpring of " + s1 + " and " + s2; } /** The current value of this Spring. */ private int value; /** * Creates a new MaxSpring object. * * @param s1 the 1st operand. * @param s2 the 2nd operand. */ protected MaxSpring(Spring s1, Spring s2) { super(); this.s1 = s1; this.s2 = s2; value = Spring.UNSET; } /** * Returns the maximum value of this Spring. * * @return the maximum value. */ public int getMaximumValue() { int max1 = s1.getMaximumValue(); int max2 = s2.getMaximumValue(); return Math.max(max1, max2); } /** * Returns the minimum value of this Spring. * * @return the minimum value. */ public int getMinimumValue() { int min1 = s1.getMinimumValue(); int min2 = s2.getMinimumValue(); return Math.max(min1, min2); } /** * Returns the preferred value of this Spring. * * @return the preferred value. */ public int getPreferredValue() { int pref1 = s1.getPreferredValue(); int pref2 = s2.getPreferredValue(); return Math.max(pref1, pref2); } /** * Returns the actual value of this Spring. * * @return the current value. */ public int getValue() { if (value == Spring.UNSET) { int val1 = s1.getValue(); int val2 = s2.getValue(); value = Math.max(val1, val2); } return value; } /** * Sets the current value. * * @param val the value to be set. */ public void setValue(int val) { if (val == Spring.UNSET) { if (value != Spring.UNSET) { s1.setValue(Spring.UNSET); s2.setValue(Spring.UNSET); } value = Spring.UNSET; return; } value = val; int p1 = s1.getPreferredValue(); int p2 = s2.getPreferredValue(); if (p1 < p2) { s1.setValue(Math.min(val, p1)); s2.setValue(val); } else { s1.setValue(val); s2.setValue(Math.min(val, p2)); } } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -