You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ss...@apache.org on 2013/02/19 18:04:22 UTC
[43/51] [abbrv] libraries/ compiling
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4c3a7698/launchers/lmf-splash/src/main/java/net/miginfocom/layout/LayoutUtil.java
----------------------------------------------------------------------
diff --git a/launchers/lmf-splash/src/main/java/net/miginfocom/layout/LayoutUtil.java b/launchers/lmf-splash/src/main/java/net/miginfocom/layout/LayoutUtil.java
deleted file mode 100644
index d3f5e9c..0000000
--- a/launchers/lmf-splash/src/main/java/net/miginfocom/layout/LayoutUtil.java
+++ /dev/null
@@ -1,566 +0,0 @@
-package net.miginfocom.layout;
-
-import java.beans.*;
-import java.io.*;
-import java.util.IdentityHashMap;
-import java.util.TreeSet;
-import java.util.WeakHashMap;
-/*
- * License (BSD):
- * ==============
- *
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this list
- * of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice, this
- * list of conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * @version 1.0
- * @author Mikael Grev, MiG InfoCom AB
- * Date: 2006-sep-08
- */
-
-/** A utility class that has only static helper methods.
- */
-public final class LayoutUtil
-{
- /** A substitute value for aa really large value. Integer.MAX_VALUE is not used since that means a lot of defensive code
- * for potential overflow must exist in many places. This value is large enough for being unreasonable yet it is hard to
- * overflow.
- */
- public static final int INF = (Integer.MAX_VALUE >> 10) - 100; // To reduce likelihood of overflow errors when calculating.
-
- /** Tag int for a value that in considered "not set". Used as "null" element in int arrays.
- */
- static final int NOT_SET = Integer.MIN_VALUE + 12346; // Magic value...
-
- // Index for the different sizes
- public static final int MIN = 0;
- public static final int PREF = 1;
- public static final int MAX = 2;
-
- private static volatile WeakHashMap<Object, String> CR_MAP = null;
- private static volatile WeakHashMap<Object, Boolean> DT_MAP = null; // The Containers that have design time. Value not used.
- private static int eSz = 0;
- private static int globalDebugMillis = 0;
- public static final boolean HAS_BEANS = hasBeans();
-
- private static boolean hasBeans()
- {
- try {
- LayoutUtil.class.getClassLoader().loadClass("java.beans.Beans");
- return true;
- } catch (ClassNotFoundException e) {
- return false;
- }
- }
-
- private LayoutUtil()
- {
- }
-
- /** Returns the current version of MiG Layout.
- * @return The current version of MiG Layout. E.g. "3.6.3" or "4.0"
- */
- public static String getVersion()
- {
- return "4.0";
- }
-
- /** If global debug should be on or off. If > 0 then debug is turned on for all MigLayout
- * instances.
- * @return The current debug milliseconds.
- * @see LC#setDebugMillis(int)
- */
- public static int getGlobalDebugMillis()
- {
- return globalDebugMillis;
- }
-
- /** If global debug should be on or off. If > 0 then debug is turned on for all MigLayout
- * instances.
- * <p>
- * Note! This is a passive value and will be read by panels when the needed, which is normally
- * when they repaint/layout.
- * @param millis The new debug milliseconds. 0 turns of global debug and leaves debug up to every
- * individual panel.
- * @see LC#setDebugMillis(int)
- */
- public static void setGlobalDebugMillis(int millis)
- {
- globalDebugMillis = millis;
- }
-
- /** Sets if design time is turned on for a Container in {@link ContainerWrapper}.
- * @param cw The container to set design time for. <code>null</code> is legal and can be used as
- * a key to turn on/off design time "in general". Note though that design time "in general" is
- * always on as long as there is at least one ContainerWrapper with design time.
- * <p>
- * <strong>If this method has not ever been called it will default to what
- * <code>Beans.isDesignTime()</code> returns.</strong> This means that if you call
- * this method you indicate that you will take responsibility for the design time value.
- * @param b <code>true</code> means design time on.
- */
- public static void setDesignTime(ContainerWrapper cw, boolean b)
- {
- if (DT_MAP == null)
- DT_MAP = new WeakHashMap<Object, Boolean>();
-
- DT_MAP.put((cw != null ? cw.getComponent() : null), b);
- }
-
- /** Returns if design time is turned on for a Container in {@link ContainerWrapper}.
- * @param cw The container to set design time for. <code>null</code> is legal will return <code>true</code>
- * if there is at least one <code>ContainerWrapper</code> (or <code>null</code>) that have design time
- * turned on.
- * @return If design time is set for <code>cw</code>.
- */
- public static boolean isDesignTime(ContainerWrapper cw)
- {
- if (DT_MAP == null)
- return HAS_BEANS && Beans.isDesignTime();
-
- if (cw != null && DT_MAP.containsKey(cw.getComponent()) == false)
- cw = null;
-
- Boolean b = DT_MAP.get(cw != null ? cw.getComponent() : null);
- return b != null && b;
- }
-
- /** The size of an empty row or columns in a grid during design time.
- * @return The number of pixels. Default is 15.
- */
- public static int getDesignTimeEmptySize()
- {
- return eSz;
- }
-
- /** The size of an empty row or columns in a grid during design time.
- * @param pixels The number of pixels. Default is 0 (it was 15 prior to v3.7.2, but since that meant different behaviour
- * under design time by default it was changed to be 0, same as non-design time). IDE vendors can still set it to 15 to
- * get the old behaviour.
- */
- public static void setDesignTimeEmptySize(int pixels)
- {
- eSz = pixels;
- }
-
- /** Associates <code>con</code> with the creation string <code>s</code>. The <code>con</code> object should
- * probably have an equals method that compares identities or <code>con</code> objects that .equals() will only
- * be able to have <b>one</b> creation string.
- * <p>
- * If {@link LayoutUtil#isDesignTime(ContainerWrapper)} returns <code>false</code> the method does nothing.
- * @param con The object. if <code>null</code> the method does nothing.
- * @param s The creation string. if <code>null</code> the method does nothing.
- */
- static void putCCString(Object con, String s)
- {
- if (s != null && con != null && isDesignTime(null)) {
- if (CR_MAP == null)
- CR_MAP = new WeakHashMap<Object, String>(64);
-
- CR_MAP.put(con, s);
- }
- }
-
- /** Sets/add the persistence delegates to be used for a class.
- * @param c The class to set the registered deligate for.
- * @param del The new delegate or <code>null</code> to erase to old one.
- */
- static synchronized void setDelegate(Class c, PersistenceDelegate del)
- {
- try {
- Introspector.getBeanInfo(c, Introspector.IGNORE_ALL_BEANINFO).getBeanDescriptor().setValue("persistenceDelegate", del);
- } catch (Exception ignored) {
- }
- }
-
- /** Returns strings set with {@link #putCCString(Object, String)} or <code>null</code> if nothing is associated or
- * {@link LayoutUtil#isDesignTime(ContainerWrapper)} returns <code>false</code>.
- * @param con The constrain object.
- * @return The creation string or <code>null</code> if nothing is registered with the <code>con</code> object.
- */
- static String getCCString(Object con)
- {
- return CR_MAP != null ? CR_MAP.get(con) : null;
- }
-
- static void throwCC()
- {
- throw new IllegalStateException("setStoreConstraintData(true) must be set for strings to be saved.");
- }
-
- /** Takes a number on min/preferred/max sizes and resize constraints and returns the calculated sizes which sum should add up to <code>bounds</code>. Whether the sum
- * will actually equal <code>bounds</code> is dependent om the pref/max sizes and resize constraints.
- * @param sizes [ix],[MIN][PREF][MAX]. Grid.CompWrap.NOT_SET will be treated as N/A or 0. A "[MIN][PREF][MAX]" array with null elements will be interpreted as very flexible (no bounds)
- * but if the array itself is null it will not get any size.
- * @param resConstr Elements can be <code>null</code> and the whole array can be <code>null</code>. <code>null</code> means that the size will not be flexible at all.
- * Can have length less than <code>sizes</code> in which case the last element should be used for the elements missing.
- * @param defPushWeights If there is no grow weight for a resConstr the corresponding value of this array is used.
- * These forced resConstr will be grown last though and only if needed to fill to the bounds.
- * @param startSizeType The initial size to use. E.g. {@link net.miginfocom.layout.LayoutUtil#MIN}.
- * @param bounds To use for relative sizes.
- * @return The sizes. Array length will match <code>sizes</code>.
- */
- static int[] calculateSerial(int[][] sizes, ResizeConstraint[] resConstr, Float[] defPushWeights, int startSizeType, int bounds)
- {
- float[] lengths = new float[sizes.length]; // heights/widths that are set
- float usedLength = 0.0f;
-
- // Give all preferred size to start with
- for (int i = 0; i < sizes.length; i++) {
- if (sizes[i] != null) {
- float len = sizes[i][startSizeType] != NOT_SET ? sizes[i][startSizeType] : 0;
- int newSizeBounded = getBrokenBoundary(len, sizes[i][MIN], sizes[i][MAX]);
- if (newSizeBounded != NOT_SET)
- len = newSizeBounded;
-
- usedLength += len;
- lengths[i] = len;
- }
- }
-
- int useLengthI = Math.round(usedLength);
- if (useLengthI != bounds && resConstr != null) {
- boolean isGrow = useLengthI < bounds;
-
- // Create a Set with the available priorities
- TreeSet<Integer> prioList = new TreeSet<Integer>();
- for (int i = 0; i < sizes.length; i++) {
- ResizeConstraint resC = (ResizeConstraint) getIndexSafe(resConstr, i);
- if (resC != null)
- prioList.add(isGrow ? resC.growPrio : resC.shrinkPrio);
- }
- Integer[] prioIntegers = prioList.toArray(new Integer[prioList.size()]);
-
- for (int force = 0; force <= ((isGrow && defPushWeights != null) ? 1 : 0); force++) { // Run twice if defGrow and the need for growing.
- for (int pr = prioIntegers.length - 1; pr >= 0; pr--) {
- int curPrio = prioIntegers[pr];
-
- float totWeight = 0f;
- Float[] resizeWeight = new Float[sizes.length];
- for (int i = 0; i < sizes.length; i++) {
- if (sizes[i] == null) // if no min/pref/max size at all do not grow or shrink.
- continue;
-
- ResizeConstraint resC = (ResizeConstraint) getIndexSafe(resConstr, i);
- if (resC != null) {
- int prio = isGrow ? resC.growPrio : resC.shrinkPrio;
-
- if (curPrio == prio) {
- if (isGrow) {
- resizeWeight[i] = (force == 0 || resC.grow != null) ? resC.grow : (defPushWeights[i < defPushWeights.length ? i : defPushWeights.length - 1]);
- } else {
- resizeWeight[i] = resC.shrink;
- }
- if (resizeWeight[i] != null)
- totWeight += resizeWeight[i];
- }
- }
- }
-
- if (totWeight > 0f) {
- boolean hit;
- do {
- float toChange = bounds - usedLength;
- hit = false;
- float changedWeight = 0f;
- for (int i = 0; i < sizes.length && totWeight > 0.0001f; i++) {
-
- Float weight = resizeWeight[i];
- if (weight != null) {
- float sizeDelta = toChange * weight / totWeight;
- float newSize = lengths[i] + sizeDelta;
-
- if (sizes[i] != null) {
- int newSizeBounded = getBrokenBoundary(newSize, sizes[i][MIN], sizes[i][MAX]);
- if (newSizeBounded != NOT_SET) {
- resizeWeight[i] = null;
- hit = true;
- changedWeight += weight;
- newSize = newSizeBounded;
- sizeDelta = newSize - lengths[i];
- }
- }
-
- lengths[i] = newSize;
- usedLength += sizeDelta;
- }
- }
- totWeight -= changedWeight;
- } while (hit);
- }
- }
- }
- }
- return roundSizes(lengths);
- }
-
- static Object getIndexSafe(Object[] arr, int ix)
- {
- return arr != null ? arr[ix < arr.length ? ix : arr.length - 1] : null;
- }
-
- /** Returns the broken boundary if <code>sz</code> is outside the boundaries <code>lower</code> or <code>upper</code>. If both boundaries
- * are broken, the lower one is returned. If <code>sz</code> is < 0 then <code>new Float(0f)</code> is returned so that no sizes can be
- * negative.
- * @param sz The size to check
- * @param lower The lower boundary (or <code>null</code> fo no boundary).
- * @param upper The upper boundary (or <code>null</code> fo no boundary).
- * @return The broken boundary.
- */
- private static int getBrokenBoundary(float sz, int lower, int upper)
- {
- if (lower != NOT_SET) {
- if (sz < lower)
- return lower;
- } else if (sz < 0f) {
- return 0;
- }
-
- if (upper != NOT_SET && sz > upper)
- return upper;
-
- return NOT_SET;
- }
-
-
- static int sum(int[] terms, int start, int len)
- {
- int s = 0;
- for (int i = start, iSz = start + len; i < iSz; i++)
- s += terms[i];
- return s;
- }
-
- static int sum(int[] terms)
- {
- return sum(terms, 0, terms.length);
- }
-
- public static int getSizeSafe(int[] sizes, int sizeType)
- {
- if (sizes == null || sizes[sizeType] == NOT_SET)
- return sizeType == MAX ? LayoutUtil.INF : 0;
- return sizes[sizeType];
- }
-
- static BoundSize derive(BoundSize bs, UnitValue min, UnitValue pref, UnitValue max)
- {
- if (bs == null || bs.isUnset())
- return new BoundSize(min, pref, max, null);
-
- return new BoundSize(
- min != null ? min : bs.getMin(),
- pref != null ? pref : bs.getPreferred(),
- max != null ? max : bs.getMax(),
- bs.getGapPush(),
- null);
- }
-
- /** Returns if left-to-right orientation is used. If not set explicitly in the layout constraints the Locale
- * of the <code>parent</code> is used.
- * @param lc The constraint if there is one. Can be <code>null</code>.
- * @param container The parent that may be used to get the left-to-right if ffc does not specify this.
- * @return If left-to-right orientation is currently used.
- */
- public static boolean isLeftToRight(LC lc, ContainerWrapper container)
- {
- if (lc != null && lc.getLeftToRight() != null)
- return lc.getLeftToRight();
-
- return container == null || container.isLeftToRight();
- }
-
- /** Round a number of float sizes into int sizes so that the total length match up
- * @param sizes The sizes to round
- * @return An array of equal length as <code>sizes</code>.
- */
- static int[] roundSizes(float[] sizes)
- {
- int[] retInts = new int[sizes.length];
- float posD = 0;
-
- for (int i = 0; i < retInts.length; i++) {
- int posI = (int) (posD + 0.5f);
-
- posD += sizes[i];
-
- retInts[i] = (int) (posD + 0.5f) - posI;
- }
-
- return retInts;
- }
-
- /** Safe equals. null == null, but null never equals anything else.
- * @param o1 The first object. May be <code>null</code>.
- * @param o2 The second object. May be <code>null</code>.
- * @return Returns <code>true</code> if <code>o1</code> and <code>o2</code> are equal (using .equals()) or both are <code>null</code>.
- */
- static boolean equals(Object o1, Object o2)
- {
- return o1 == o2 || (o1 != null && o2 != null && o1.equals(o2));
- }
-
-// static int getBaselineCorrect(Component comp)
-// {
-// Dimension pSize = comp.getPreferredSize();
-// int baseline = comp.getBaseline(pSize.width, pSize.height);
-// int nextBaseline = comp.getBaseline(pSize.width, pSize.height + 1);
-//
-// // Amount to add to height when calculating where baseline
-// // lands for a particular height:
-// int padding = 0;
-//
-// // Where the baseline is relative to the mid point
-// int baselineOffset = baseline - pSize.height / 2;
-// if (pSize.height % 2 == 0 && baseline != nextBaseline) {
-// padding = 1;
-// } else if (pSize.height % 2 == 1 && baseline == nextBaseline) {
-// baselineOffset--;
-// padding = 1;
-// }
-//
-// // The following calculates where the baseline lands for
-// // the height z:
-// return (pSize.height + padding) / 2 + baselineOffset;
-// }
-
-
- /** Returns the inset for the side.
- * @param side top == 0, left == 1, bottom = 2, right = 3.
- * @param getDefault If <code>true</code> the default insets will get retrieved if <code>lc</code> has none set.
- * @return The inset for the side. Never <code>null</code>.
- */
- static UnitValue getInsets(LC lc, int side, boolean getDefault)
- {
- UnitValue[] i = lc.getInsets();
- return (i != null && i[side] != null) ? i[side] : (getDefault ? PlatformDefaults.getPanelInsets(side) : UnitValue.ZERO);
- }
-
- /** Writes the objet and CLOSES the stream. Uses the persistence delegate registered in this class.
- * @param os The stream to write to. Will be closed.
- * @param o The object to be serialized.
- * @param listener The listener to recieve the exeptions if there are any. If <code>null</code> not used.
- */
- static void writeXMLObject(OutputStream os, Object o, ExceptionListener listener)
- {
- ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(LayoutUtil.class.getClassLoader());
-
- XMLEncoder encoder = new XMLEncoder(os);
-
- if (listener != null)
- encoder.setExceptionListener(listener);
-
- encoder.writeObject(o);
- encoder.close(); // Must be closed to write.
-
- Thread.currentThread().setContextClassLoader(oldClassLoader);
- }
-
- private static ByteArrayOutputStream writeOutputStream = null;
- /** Writes an object to XML.
- * @param out The boject out to write to. Will not be closed.
- * @param o The object to write.
- */
- public static synchronized void writeAsXML(ObjectOutput out, Object o) throws IOException
- {
- if (writeOutputStream == null)
- writeOutputStream = new ByteArrayOutputStream(16384);
-
- writeOutputStream.reset();
-
- writeXMLObject(writeOutputStream, o, new ExceptionListener() {
- public void exceptionThrown(Exception e) {
- e.printStackTrace();
- }});
-
- byte[] buf = writeOutputStream.toByteArray();
-
- out.writeInt(buf.length);
- out.write(buf);
- }
-
- private static byte[] readBuf = null;
- /** Reads an object from <code>in</code> using the
- * @param in The object input to read from.
- * @return The object. Never <code>null</code>.
- * @throws IOException If there was a problem saving as XML
- */
- public static synchronized Object readAsXML(ObjectInput in) throws IOException
- {
- if (readBuf == null)
- readBuf = new byte[16384];
-
- Thread cThread = Thread.currentThread();
- ClassLoader oldCL = null;
-
- try {
- oldCL = cThread.getContextClassLoader();
- cThread.setContextClassLoader(LayoutUtil.class.getClassLoader());
- } catch(SecurityException ignored) {
- }
-
- Object o = null;
- try {
- int length = in.readInt();
- if (length > readBuf.length)
- readBuf = new byte[length];
-
- in.readFully(readBuf, 0, length);
-
- o = new XMLDecoder(new ByteArrayInputStream(readBuf, 0, length)).readObject();
-
- } catch(EOFException ignored) {
- }
-
- if (oldCL != null)
- cThread.setContextClassLoader(oldCL);
-
- return o;
- }
-
- private static final IdentityHashMap<Object, Object> SER_MAP = new IdentityHashMap<Object, Object>(2);
-
- /** Sets the serialized object and associates it with <code>caller</code>.
- * @param caller The object created <code>o</code>
- * @param o The just serialized object.
- */
- public static void setSerializedObject(Object caller, Object o)
- {
- synchronized(SER_MAP) {
- SER_MAP.put(caller, o);
- }
- }
-
- /** Returns the serialized object that are associated with <code>caller</code>. It also removes it from the list.
- * @param caller The original creator of the object.
- * @return The object.
- */
- public static Object getSerializedObject(Object caller)
- {
- synchronized(SER_MAP) {
- return SER_MAP.remove(caller);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4c3a7698/launchers/lmf-splash/src/main/java/net/miginfocom/layout/LinkHandler.java
----------------------------------------------------------------------
diff --git a/launchers/lmf-splash/src/main/java/net/miginfocom/layout/LinkHandler.java b/launchers/lmf-splash/src/main/java/net/miginfocom/layout/LinkHandler.java
deleted file mode 100644
index 45ad266..0000000
--- a/launchers/lmf-splash/src/main/java/net/miginfocom/layout/LinkHandler.java
+++ /dev/null
@@ -1,200 +0,0 @@
-package net.miginfocom.layout;
-
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.HashMap;
-/*
- * License (BSD):
- * ==============
- *
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this list
- * of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice, this
- * list of conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * @version 1.0
- * @author Mikael Grev, MiG InfoCom AB
- * Date: 2006-sep-08
- */
-
-/**
- */
-public final class LinkHandler
-{
- public static final int X = 0;
- public static final int Y = 1;
- public static final int WIDTH = 2;
- public static final int HEIGHT = 3;
- public static final int X2 = 4;
- public static final int Y2 = 5;
-
- private static final ArrayList<WeakReference<Object>> LAYOUTS = new ArrayList<WeakReference<Object>>(4);
- private static final ArrayList<HashMap<String, int[]>> VALUES = new ArrayList<HashMap<String, int[]>>(4);
- private static final ArrayList<HashMap<String, int[]>> VALUES_TEMP = new ArrayList<HashMap<String, int[]>>(4);
-
- private LinkHandler()
- {
- }
-
- public synchronized static Integer getValue(Object layout, String key, int type)
- {
- Integer ret = null;
- boolean cont = true;
-
- for (int i = LAYOUTS.size() - 1; i >= 0; i--) {
- Object l = LAYOUTS.get(i).get();
- if (ret == null && l == layout) {
- int[] rect = VALUES_TEMP.get(i).get(key);
- if (cont && rect != null && rect[type] != LayoutUtil.NOT_SET) {
- ret = rect[type];
- } else {
- rect = VALUES.get(i).get(key);
- ret = (rect != null && rect[type] != LayoutUtil.NOT_SET) ? rect[type] : null;
- }
- cont = false;
- }
-
- if (l == null) {
- LAYOUTS.remove(i);
- VALUES.remove(i);
- VALUES_TEMP.remove(i);
- }
- }
- return ret;
- }
-
- /** Sets a key that can be linked to from any component.
- * @param layout The MigLayout instance
- * @param key The key to link to. This is the same as the ID in a component constraint.
- * @param x x
- * @param y y
- * @param width Width
- * @param height Height
- * @return If the value was changed
- */
- public synchronized static boolean setBounds(Object layout, String key, int x, int y, int width, int height)
- {
- return setBounds(layout, key, x, y, width, height, false, false);
- }
-
- synchronized static boolean setBounds(Object layout, String key, int x, int y, int width, int height, boolean temporary, boolean incCur)
- {
- for (int i = LAYOUTS.size() - 1; i >= 0; i--) {
- Object l = LAYOUTS.get(i).get();
- if (l == layout) {
- HashMap<String, int[]> map = (temporary ? VALUES_TEMP : VALUES).get(i);
- int[] old = map.get(key);
-
- if (old == null || old[X] != x || old[Y] != y || old[WIDTH] != width || old[HEIGHT] != height) {
- if (old == null || incCur == false) {
- map.put(key, new int[] {x, y, width, height, x + width, y + height});
- return true;
- } else {
- boolean changed = false;
-
- if (x != LayoutUtil.NOT_SET) {
- if (old[X] == LayoutUtil.NOT_SET || x < old[X]) {
- old[X] = x;
- old[WIDTH] = old[X2] - x;
- changed = true;
- }
-
- if (width != LayoutUtil.NOT_SET) {
- int x2 = x + width;
- if (old[X2] == LayoutUtil.NOT_SET || x2 > old[X2]) {
- old[X2] = x2;
- old[WIDTH] = x2 - old[X];
- changed = true;
- }
- }
- }
-
- if (y != LayoutUtil.NOT_SET) {
- if (old[Y] == LayoutUtil.NOT_SET || y < old[Y]) {
- old[Y] = y;
- old[HEIGHT] = old[Y2] - y;
- changed = true;
- }
-
- if (height != LayoutUtil.NOT_SET) {
- int y2 = y + height;
- if (old[Y2] == LayoutUtil.NOT_SET || y2 > old[Y2]) {
- old[Y2] = y2;
- old[HEIGHT] = y2 - old[Y];
- changed = true;
- }
- }
- }
- return changed;
- }
- }
- return false;
- }
- }
-
- LAYOUTS.add(new WeakReference<Object>(layout));
- int[] bounds = new int[] {x, y, width, height, x + width, y + height};
-
- HashMap<String, int[]> values = new HashMap<String, int[]>(4);
- if (temporary)
- values.put(key, bounds);
- VALUES_TEMP.add(values);
-
- values = new HashMap<String, int[]>(4);
- if (temporary == false)
- values.put(key, bounds);
- VALUES.add(values);
-
- return true;
- }
-
- /** This method clear any weak references right away instead of waiting for the GC. This might be advantageous
- * if lots of layout are created and disposed of quickly to keep memory consumption down.
- * @since 3.7.4
- */
- public synchronized static void clearWeakReferencesNow()
- {
- LAYOUTS.clear();
- }
-
- public synchronized static boolean clearBounds(Object layout, String key)
- {
- for (int i = LAYOUTS.size() - 1; i >= 0; i--) {
- Object l = LAYOUTS.get(i).get();
- if (l == layout)
- return VALUES.get(i).remove(key) != null;
- }
- return false;
- }
-
- synchronized static void clearTemporaryBounds(Object layout)
- {
- for (int i = LAYOUTS.size() - 1; i >= 0; i--) {
- Object l = LAYOUTS.get(i).get();
- if (l == layout) {
- VALUES_TEMP.get(i).clear();
- return;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4c3a7698/launchers/lmf-splash/src/main/java/net/miginfocom/layout/PlatformDefaults.java
----------------------------------------------------------------------
diff --git a/launchers/lmf-splash/src/main/java/net/miginfocom/layout/PlatformDefaults.java b/launchers/lmf-splash/src/main/java/net/miginfocom/layout/PlatformDefaults.java
deleted file mode 100644
index 1a6e158..0000000
--- a/launchers/lmf-splash/src/main/java/net/miginfocom/layout/PlatformDefaults.java
+++ /dev/null
@@ -1,772 +0,0 @@
-package net.miginfocom.layout;
-
-import javax.swing.*;
-import java.util.HashMap;
-/*
- * License (BSD):
- * ==============
- *
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this list
- * of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice, this
- * list of conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * @version 1.0
- * @author Mikael Grev, MiG InfoCom AB
- * Date: 2006-sep-08
- * @author Xxxx Xxxx, Xxxx - Gnome support
- * Date: 2008-jan-16
- */
-
-/** Currently handles Windows, Mac OS X, and GNOME spacing.
- */
-public final class PlatformDefaults
-{
- private static int DEF_H_UNIT = UnitValue.LPX;
- private static int DEF_V_UNIT = UnitValue.LPY;
-
- private static InCellGapProvider GAP_PROVIDER = null;
-
- private static volatile int MOD_COUNT = 0;
-
- private static final UnitValue LPX4 = new UnitValue(4, UnitValue.LPX, null);
- private static final UnitValue LPX6 = new UnitValue(6, UnitValue.LPX, null);
- private static final UnitValue LPX7 = new UnitValue(7, UnitValue.LPX, null);
-// private static final UnitValue LPX8 = new UnitValue(8, UnitValue.LPX, null);
- private static final UnitValue LPX9 = new UnitValue(9, UnitValue.LPX, null);
- private static final UnitValue LPX10 = new UnitValue(10, UnitValue.LPX, null);
- private static final UnitValue LPX11 = new UnitValue(11, UnitValue.LPX, null);
- private static final UnitValue LPX12 = new UnitValue(12, UnitValue.LPX, null);
- private static final UnitValue LPX14 = new UnitValue(14, UnitValue.LPX, null);
- private static final UnitValue LPX16 = new UnitValue(16, UnitValue.LPX, null);
- private static final UnitValue LPX18 = new UnitValue(18, UnitValue.LPX, null);
- private static final UnitValue LPX20 = new UnitValue(20, UnitValue.LPX, null);
-
- private static final UnitValue LPY4 = new UnitValue(4, UnitValue.LPY, null);
- private static final UnitValue LPY6 = new UnitValue(6, UnitValue.LPY, null);
- private static final UnitValue LPY7 = new UnitValue(7, UnitValue.LPY, null);
-// private static final UnitValue LPY8 = new UnitValue(8, UnitValue.LPY, null);
- private static final UnitValue LPY9 = new UnitValue(9, UnitValue.LPY, null);
- private static final UnitValue LPY10 = new UnitValue(10, UnitValue.LPY, null);
- private static final UnitValue LPY11 = new UnitValue(11, UnitValue.LPY, null);
- private static final UnitValue LPY12 = new UnitValue(12, UnitValue.LPY, null);
- private static final UnitValue LPY14 = new UnitValue(14, UnitValue.LPY, null);
- private static final UnitValue LPY16 = new UnitValue(16, UnitValue.LPY, null);
- private static final UnitValue LPY18 = new UnitValue(18, UnitValue.LPY, null);
- private static final UnitValue LPY20 = new UnitValue(20, UnitValue.LPY, null);
-
- public static final int WINDOWS_XP = 0;
- public static final int MAC_OSX = 1;
- public static final int GNOME = 2;
-// private static final int KDE = 3;
-
- private static int CUR_PLAF = WINDOWS_XP;
-
- // Used for holding values.
- private final static UnitValue[] PANEL_INS = new UnitValue[4];
- private final static UnitValue[] DIALOG_INS = new UnitValue[4];
-
- private static String BUTTON_FORMAT = null;
-
- private static final HashMap<String, UnitValue> HOR_DEFS = new HashMap<String, UnitValue>(32);
- private static final HashMap<String, UnitValue> VER_DEFS = new HashMap<String, UnitValue>(32);
- private static BoundSize DEF_VGAP = null, DEF_HGAP = null;
- static BoundSize RELATED_X = null, RELATED_Y = null, UNRELATED_X = null, UNRELATED_Y = null;
- private static UnitValue BUTT_WIDTH = null;
-
- private static Float horScale = null, verScale = null;
-
- /** I value indicating that the size of the font for the container of the component
- * will be used as a base for calculating the logical pixel size. This is much as how
- * Windows calculated DLU (dialog units).
- * @see net.miginfocom.layout.UnitValue#LPX
- * @see net.miginfocom.layout.UnitValue#LPY
- * @see #setLogicalPixelBase(int)
- */
- public static final int BASE_FONT_SIZE = 100;
-
- /** I value indicating that the screen DPI will be used as a base for calculating the
- * logical pixel size.
- * <p>
- * This is the default value.
- * @see net.miginfocom.layout.UnitValue#LPX
- * @see net.miginfocom.layout.UnitValue#LPY
- * @see #setLogicalPixelBase(int)
- * @see #setVerticalScaleFactor(Float)
- * @see #setHorizontalScaleFactor(Float)
- */
- public static final int BASE_SCALE_FACTOR = 101;
-
- /** I value indicating that the size of a logical pixel should always be a real pixel
- * and thus no compensation will be made.
- * @see net.miginfocom.layout.UnitValue#LPX
- * @see net.miginfocom.layout.UnitValue#LPY
- * @see #setLogicalPixelBase(int)
- */
- public static final int BASE_REAL_PIXEL = 102;
-
- private static int LP_BASE = BASE_SCALE_FACTOR;
-
- private static Integer BASE_DPI_FORCED = null;
- private static int BASE_DPI = 96;
-
- private static boolean dra = true;
-
- static {
- setPlatform(getCurrentPlatform());
- MOD_COUNT = 0;
- }
-
- /** Returns the platform that the JRE is running on currently.
- * @return The platform that the JRE is running on currently. E.g. {@link #MAC_OSX}, {@link #WINDOWS_XP}, or {@link #GNOME}.
- */
- public static int getCurrentPlatform()
- {
- final String os = System.getProperty("os.name");
- if (os.startsWith("Mac OS")) {
- return MAC_OSX;
- } else if (os.startsWith("Linux")) {
- return GNOME;
- } else {
- return WINDOWS_XP;
- }
- }
-
- private PlatformDefaults()
- {
- }
-
- /** Set the defaults to the default for the platform
- * @param plaf The platform. <code>PlatformDefaults.WINDOWS_XP</code>,
- * <code>PlatformDefaults.MAC_OSX</code>, or
- * <code>PlatformDefaults.GNOME</code>.
- */
- public static void setPlatform(int plaf)
- {
- switch (plaf) {
- case WINDOWS_XP:
- setRelatedGap(LPX4, LPY4);
- setUnrelatedGap(LPX7, LPY9);
- setParagraphGap(LPX14, LPY14);
- setIndentGap(LPX9, LPY9);
- setGridCellGap(LPX4, LPY4);
-
- setMinimumButtonWidth(new UnitValue(75, UnitValue.LPX, null));
- setButtonOrder("L_E+U+YNBXOCAH_R");
- setDialogInsets(LPY11, LPX11, LPY11, LPX11);
- setPanelInsets(LPY7, LPX7, LPY7, LPX7);
- break;
- case MAC_OSX:
- setRelatedGap(LPX4, LPY4);
- setUnrelatedGap(LPX7, LPY9);
- setParagraphGap(LPX14, LPY14);
- setIndentGap(LPX10, LPY10);
- setGridCellGap(LPX4, LPY4);
-
- setMinimumButtonWidth(new UnitValue(68, UnitValue.LPX, null));
- setButtonOrder("L_HE+U+NYBXCOA_R");
- setDialogInsets(LPY14, LPX20, LPY20, LPX20);
- setPanelInsets(LPY16, LPX16, LPY16, LPX16);
-
-// setRelatedGap(LPX8, LPY8);
-// setUnrelatedGap(LPX12, LPY12);
-// setParagraphGap(LPX16, LPY16);
-// setIndentGap(LPX10, LPY10);
-// setGridCellGap(LPX8, LPY8);
-//
-// setMinimumButtonWidth(new UnitValue(68, UnitValue.LPX, null));
-// setButtonOrder("L_HE+U+NYBXCOA_R");
-// setDialogInsets(LPY14, LPX20, LPY20, LPX20);
-// setPanelInsets(LPY16, LPX16, LPY16, LPX16);
- break;
- case GNOME:
- setRelatedGap(LPX6, LPY6); // GNOME HIG 8.2.3
- setUnrelatedGap(LPX12, LPY12); // GNOME HIG 8.2.3
- setParagraphGap(LPX18, LPY18); // GNOME HIG 8.2.3
- setIndentGap(LPX12, LPY12); // GNOME HIG 8.2.3
- setGridCellGap(LPX6, LPY6); // GNOME HIG 8.2.3
-
- // GtkButtonBox, child-min-width property default value
- setMinimumButtonWidth(new UnitValue(85, UnitValue.LPX, null));
- setButtonOrder("L_HE+UNYACBXIO_R"); // GNOME HIG 3.4.2, 3.7.1
- setDialogInsets(LPY12, LPX12, LPY12, LPX12); // GNOME HIG 3.4.3
- setPanelInsets(LPY6, LPX6, LPY6, LPX6); // ???
- break;
- default:
- throw new IllegalArgumentException("Unknown platform: " + plaf);
- }
- CUR_PLAF = plaf;
- BASE_DPI = BASE_DPI_FORCED != null ? BASE_DPI_FORCED : getPlatformDPI(plaf);
- }
-
- private static int getPlatformDPI(int plaf)
- {
- switch (plaf) {
- case WINDOWS_XP:
- case GNOME:
- return 96;
- case MAC_OSX:
- try {
- return System.getProperty("java.version").compareTo("1.6") < 0 ? 72 : 96; // Default DPI was 72 prior to JSE 1.6
- } catch (Throwable t) {
- return 72;
- }
- default:
- throw new IllegalArgumentException("Unknown platform: " + plaf);
- }
- }
-
- /** Returns the current platform
- * @return <code>PlatformDefaults.WINDOWS</code> or <code>PlatformDefaults.MAC_OSX</code>
- */
- public static int getPlatform()
- {
- return CUR_PLAF;
- }
-
- public static int getDefaultDPI()
- {
- return BASE_DPI;
- }
-
- /** Sets the default platform DPI. Normally this is set in the {@link #setPlatform(int)} for the different platforms
- * but it can be tweaked here. For instance SWT on Mac does this.
- * <p>
- * Note that this is not the actual current DPI, but the base DPI for the toolkit.
- * @param dpi The base DPI. If null the default DPI is reset to the platform base DPI.
- */
- public static void setDefaultDPI(Integer dpi)
- {
- BASE_DPI = dpi != null ? dpi : getPlatformDPI(CUR_PLAF);
- BASE_DPI_FORCED = dpi;
- }
-
- /** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
- * with. If <code>null</code> this will default to a scale that will scale the current screen to the default screen resolution
- * (72 DPI for Mac and 92 DPI for Windows).
- * @return The forced scale or <code>null</code> for default scaling.
- * @see #getHorizontalScaleFactor()
- * @see ComponentWrapper#getHorizontalScreenDPI()
- */
- public static Float getHorizontalScaleFactor()
- {
- return horScale;
- }
-
- /** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
- * with. If <code>null</code> this will default to a scale that will scale the current screen to the default screen resolution
- * (72 DPI for Mac and 92 DPI for Windows).
- * @param f The forced scale or <code>null</code> for default scaling.
- * @see #getHorizontalScaleFactor()
- * @see ComponentWrapper#getHorizontalScreenDPI()
- */
- public static void setHorizontalScaleFactor(Float f)
- {
- if (LayoutUtil.equals(horScale, f) == false) {
- horScale = f;
- MOD_COUNT++;
- }
- }
-
- /** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
- * with. If <code>null</code> this will default to a scale that will scale the current screen to the default screen resolution
- * (72 DPI for Mac and 92 DPI for Windows).
- * @return The forced scale or <code>null</code> for default scaling.
- * @see #getHorizontalScaleFactor()
- * @see ComponentWrapper#getVerticalScreenDPI()
- */
- public static Float getVerticalScaleFactor()
- {
- return verScale;
- }
-
- /** The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied
- * with. If <code>null</code> this will default to a scale that will scale the current screen to the default screen resolution
- * (72 DPI for Mac and 92 DPI for Windows).
- * @param f The forced scale or <code>null</code> for default scaling.
- * @see #getHorizontalScaleFactor()
- * @see ComponentWrapper#getVerticalScreenDPI()
- */
- public static void setVerticalScaleFactor(Float f)
- {
- if (LayoutUtil.equals(verScale, f) == false) {
- verScale = f;
- MOD_COUNT++;
- }
- }
-
- /** What base value should be used to calculate logical pixel sizes.
- * @return The current base. Default is {@link #BASE_SCALE_FACTOR}
- * @see #BASE_FONT_SIZE
- * @see #BASE_SCALE_FACTOR
- * @see #BASE_REAL_PIXEL
-*/
- public static int getLogicalPixelBase()
- {
- return LP_BASE;
- }
-
- /** What base value should be used to calculate logical pixel sizes.
- * @param base The new base. Default is {@link #BASE_SCALE_FACTOR}
- * @see #BASE_FONT_SIZE
- * @see #BASE_SCALE_FACTOR
- * @see #BASE_REAL_PIXEL
- */
- public static void setLogicalPixelBase(int base)
- {
- if (LP_BASE != base) {
- if (base < BASE_FONT_SIZE || base > BASE_SCALE_FACTOR)
- throw new IllegalArgumentException("Unrecognized base: " + base);
-
- LP_BASE = base;
- MOD_COUNT++;
- }
- }
-
- /** Sets gap value for components that are "related".
- * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
- * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
- */
- public static void setRelatedGap(UnitValue x, UnitValue y)
- {
- setUnitValue(new String[] {"r", "rel", "related"}, x, y);
-
- RELATED_X = new BoundSize(x, x, null, "rel:rel");
- RELATED_Y = new BoundSize(y, y, null, "rel:rel");
- }
-
- /** Sets gap value for components that are "unrelated".
- * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
- * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
- */
- public static void setUnrelatedGap(UnitValue x, UnitValue y)
- {
- setUnitValue(new String[] {"u", "unrel", "unrelated"}, x, y);
-
- UNRELATED_X = new BoundSize(x, x, null, "unrel:unrel");
- UNRELATED_Y = new BoundSize(y, y, null, "unrel:unrel");
- }
-
- /** Sets paragraph gap value for components.
- * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
- * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
- */
- public static void setParagraphGap(UnitValue x, UnitValue y)
- {
- setUnitValue(new String[] {"p", "para", "paragraph"}, x, y);
- }
-
- /** Sets gap value for components that are "intended".
- * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
- * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
- */
- public static void setIndentGap(UnitValue x, UnitValue y)
- {
- setUnitValue(new String[] {"i", "ind", "indent"}, x, y);
- }
-
- /** Sets gap between two cells in the grid. Note that this is not a gap between component IN a cell, that has to be set
- * on the component constraints. The value will be the min and preferred size of the gap.
- * @param x The value that will be transformed to pixels. If <code>null</code> the current value will not change.
- * @param y The value that will be transformed to pixels. If <code>null</code> the current value will not change.
- */
- public static void setGridCellGap(UnitValue x, UnitValue y)
- {
- if (x != null)
- DEF_HGAP = new BoundSize(x, x, null, null);
-
- if (y != null)
- DEF_VGAP = new BoundSize(y, y, null, null);
-
- MOD_COUNT++;
- }
-
- /** Sets the recommended minimum button width.
- * @param width The recommended minimum button width.
- */
- public static void setMinimumButtonWidth(UnitValue width)
- {
- BUTT_WIDTH = width;
- MOD_COUNT++;
- }
-
- /** Returns the recommended minimum button width depending on the current set platform.
- * @return The recommended minimum button width depending on the current set platform.
- */
- public static UnitValue getMinimumButtonWidth()
- {
- return BUTT_WIDTH;
- }
-
- /** Returns the unit value associated with the unit. (E.i. "related" or "indent"). Must be lower case.
- * @param unit The unit string.
- * @return The unit value associated with the unit. <code>null</code> for unrecognized units.
- */
- public static UnitValue getUnitValueX(String unit)
- {
- return HOR_DEFS.get(unit);
- }
-
- /** Returns the unit value associated with the unit. (E.i. "related" or "indent"). Must be lower case.
- * @param unit The unit string.
- * @return The unit value associated with the unit. <code>null</code> for unrecognized units.
- */
- public static UnitValue getUnitValueY(String unit)
- {
- return VER_DEFS.get(unit);
- }
-
- /** Sets the unit value associated with a unit string. This may be used to store values for new unit strings
- * or modify old. Note that if a built in unit (such as "related") is modified all versions of it must be
- * set (I.e. "r", "rel" and "related"). The build in values will be reset to the default ones if the platform
- * is re-set.
- * @param unitStrings The unit strings. E.g. "mu", "myunit". Will be converted to lower case and trimmed. Not <code>null</code>.
- * @param x The value for the horizontal dimension. If <code>null</code> the value is not changed.
- * @param y The value for the vertical dimension. Might be same object as for <code>x</code>. If <code>null</code> the value is not changed.
- */
- public static final void setUnitValue(String[] unitStrings, UnitValue x, UnitValue y)
- {
- for (String unitString : unitStrings) {
- String s = unitString.toLowerCase().trim();
- if (x != null)
- HOR_DEFS.put(s, x);
- if (y != null)
- VER_DEFS.put(s, y);
- }
- MOD_COUNT++;
- }
-
- /** Understands ("r", "rel", "related") OR ("u", "unrel", "unrelated") OR ("i", "ind", "indent") OR ("p", "para", "paragraph").
- */
- static int convertToPixels(float value, String unit, boolean isHor, float ref, ContainerWrapper parent, ComponentWrapper comp)
- {
- UnitValue uv = (isHor ? HOR_DEFS : VER_DEFS).get(unit);
- return uv != null ? Math.round(value * uv.getPixels(ref, parent, comp)) : UnitConverter.UNABLE;
- }
-
- /** Returns the order for the typical buttons in a standard button bar. It is one letter per button type.
- * @return The button order.
- * @see #setButtonOrder(String)
- */
- public static String getButtonOrder()
- {
- return BUTTON_FORMAT;
- }
-
- /** Sets the order for the typical buttons in a standard button bar. It is one letter per button type.
- * <p>
- * Letter in upper case will get the minimum button width that the {@link #getMinimumButtonWidth()} specifies
- * and letters in lower case will get the width the current look&feel specifies.
- * <p>
- * Gaps will never be added to before the first component or after the last component. However, '+' (push) will be
- * applied before and after as well, but with a minimum size of 0 if first/last so there will not be a gap
- * before or after.
- * <p>
- * If gaps are explicitly set on buttons they will never be reduced, but they may be increased.
- * <p>
- * These are the characters that can be used:
- * <ul>
- * <li><code>'L'</code> - Buttons with this style tag will staticall end up on the left end of the bar.
- * <li><code>'R'</code> - Buttons with this style tag will staticall end up on the right end of the bar.
- * <li><code>'H'</code> - A tag for the "help" button that normally is supposed to be on the right.
- * <li><code>'E'</code> - A tag for the "help2" button that normally is supposed to be on the left.
- * <li><code>'Y'</code> - A tag for the "yes" button.
- * <li><code>'N'</code> - A tag for the "no" button.
- * <li><code>'X'</code> - A tag for the "next >" or "forward >" button.
- * <li><code>'B'</code> - A tag for the "< back>" or "< previous" button.
- * <li><code>'I'</code> - A tag for the "finish".
- * <li><code>'A'</code> - A tag for the "apply" button.
- * <li><code>'C'</code> - A tag for the "cancel" or "close" button.
- * <li><code>'O'</code> - A tag for the "ok" or "done" button.
- * <li><code>'U'</code> - All Uncategorized, Other, or "Unknown" buttons. Tag will be "other".
- * <li><code>'+'</code> - A glue push gap that will take as much space as it can and at least an "unrelated" gap. (Platform dependant)
- * <li><code>'_'</code> - (underscore) An "unrelated" gap. (Platform dependant)
- * </ul>
- * <p>
- * Even though the style tags are normally applied to buttons this works with all components.
- * <p>
- * The normal style for MAC OS X is <code>"L_HE+U+FBI_NYCOA_R"</code>,
- * for Windows is <code>"L_E+U+FBI_YNOCAH_R"</code>, and for GNOME is
- * <code>"L_HE+UNYACBXIO_R"</code>.
- *
- * @param order The new button order for the current platform.
- */
- public static void setButtonOrder(String order)
- {
- BUTTON_FORMAT = order;
- MOD_COUNT++;
- }
-
- /** Returns the tag (used in the {@link CC}) for a char. The char is same as used in {@link #getButtonOrder()}.
- * @param c The char. Must be lower case!
- * @return The tag that corresponds to the char or <code>null</code> if the char is unrecognized.
- */
- static String getTagForChar(char c)
- {
- switch (c) {
- case 'o':
- return "ok";
- case 'c':
- return "cancel";
- case 'h':
- return "help";
- case 'e':
- return "help2";
- case 'y':
- return "yes";
- case 'n':
- return "no";
- case 'a':
- return "apply";
- case 'x':
- return "next"; // a.k.a forward
- case 'b':
- return "back"; // a.k.a. previous
- case 'i':
- return "finish";
- case 'l':
- return "left";
- case 'r':
- return "right";
- case 'u':
- return "other";
- default:
- return null;
- }
- }
-
- /** Returns the platform recommended inter-cell gap in the horizontal (x) dimension..
- * @return The platform recommended inter-cell gap in the horizontal (x) dimension..
- */
- public static BoundSize getGridGapX()
- {
- return DEF_HGAP;
- }
-
- /** Returns the platform recommended inter-cell gap in the vertical (x) dimension..
- * @return The platform recommended inter-cell gap in the vertical (x) dimension..
- */
- public static BoundSize getGridGapY()
- {
- return DEF_VGAP;
- }
-
- /** Returns the default dialog inset depending of the current platform.
- * @param side top == 0, left == 1, bottom = 2, right = 3.
- * @return The inset. Never <code>null</code>.
- */
- public static UnitValue getDialogInsets(int side)
- {
- return DIALOG_INS[side];
- }
-
- /** Sets the default insets for a dialog. Values that are null will not be changed.
- * @param top The top inset. May be <code>null</code>.
- * @param left The left inset. May be <code>null</code>.
- * @param bottom The bottom inset. May be <code>null</code>.
- * @param right The right inset. May be <code>null</code>.
- */
- public static void setDialogInsets(UnitValue top, UnitValue left, UnitValue bottom, UnitValue right)
- {
- if (top != null)
- DIALOG_INS[0] = top;
-
- if (left != null)
- DIALOG_INS[1] = left;
-
- if (bottom != null)
- DIALOG_INS[2] = bottom;
-
- if (right != null)
- DIALOG_INS[3] = right;
-
- MOD_COUNT++;
- }
-
- /** Returns the default panel inset depending of the current platform.
- * @param side top == 0, left == 1, bottom = 2, right = 3.
- * @return The inset. Never <code>null</code>.
- */
- public static UnitValue getPanelInsets(int side)
- {
- return PANEL_INS[side];
- }
-
- /** Sets the default insets for a dialog. Values that are null will not be changed.
- * @param top The top inset. May be <code>null</code>.
- * @param left The left inset. May be <code>null</code>.
- * @param bottom The bottom inset. May be <code>null</code>.
- * @param right The right inset. May be <code>null</code>.
- */
- public static void setPanelInsets(UnitValue top, UnitValue left, UnitValue bottom, UnitValue right)
- {
- if (top != null)
- PANEL_INS[0] = top;
-
- if (left != null)
- PANEL_INS[1] = left;
-
- if (bottom != null)
- PANEL_INS[2] = bottom;
-
- if (right != null)
- PANEL_INS[3] = right;
-
- MOD_COUNT++;
- }
-
- /** Returns the percentage used for alignment for labels (0 is left, 50 is center and 100 is right).
- * @return The percentage used for alignment for labels
- */
- public static float getLabelAlignPercentage()
- {
- return CUR_PLAF == MAC_OSX ? 1f : 0f;
- }
-
- /** Returns the default gap between two components that <b>are in the same cell</b>.
- * @param comp The component that the gap is for. Never <code>null</code>.
- * @param adjacentComp The adjacent component if any. May be <code>null</code>.
- * @param adjacentSide What side the <code>adjacentComp</code> is on. {@link javax.swing.SwingUtilities#TOP} or
- * {@link javax.swing.SwingUtilities#LEFT} or {@link javax.swing.SwingUtilities#BOTTOM} or {@link javax.swing.SwingUtilities#RIGHT}.
- * @param tag The tag string that the component might be tagged with in the component constraints. May be <code>null</code>.
- * @param isLTR If it is left-to-right.
- * @return The default gap between two components or <code>null</code> if there should be no gap.
- */
- static BoundSize getDefaultComponentGap(ComponentWrapper comp, ComponentWrapper adjacentComp, int adjacentSide, String tag, boolean isLTR)
- {
- if (GAP_PROVIDER != null)
- return GAP_PROVIDER.getDefaultGap(comp, adjacentComp, adjacentSide, tag, isLTR);
-
- if (adjacentComp == null)
- return null;
-
-// if (adjacentComp == null || adjacentSide == SwingConstants.LEFT || adjacentSide == SwingConstants.TOP)
-// return null;
-
- return (adjacentSide == SwingConstants.LEFT || adjacentSide == SwingConstants.RIGHT) ? RELATED_X : RELATED_Y;
- }
-
- /** Returns the current gap provider or <code>null</code> if none is set and "related" should always be used.
- * @return The current gap provider or <code>null</code> if none is set and "related" should always be used.
- */
- public static InCellGapProvider getGapProvider()
- {
- return GAP_PROVIDER;
- }
-
- /** Sets the current gap provider or <code>null</code> if none is set and "related" should always be used.
- * @param provider The current gap provider or <code>null</code> if none is set and "related" should always be used.
- */
- public static void setGapProvider(InCellGapProvider provider)
- {
- GAP_PROVIDER = provider;
- }
-
- /** Returns how many times the defaults has been changed. This can be used as a light weight check to
- * see if layout caches needs to be refreshed.
- * @return How many times the defaults has been changed.
- */
- public static int getModCount()
- {
- return MOD_COUNT;
- }
-
- /** Tells all layout manager instances to revalidate and recalculated everything.
- */
- public void invalidate()
- {
- MOD_COUNT++;
- }
-
- /** Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
- * @return The current default unit.
- * @see UnitValue#PIXEL
- * @see UnitValue#LPX
- */
- public static int getDefaultHorizontalUnit()
- {
- return DEF_H_UNIT;
- }
-
- /** Sets the default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
- * @param unit The new default unit.
- * @see UnitValue#PIXEL
- * @see UnitValue#LPX
- */
- public static void setDefaultHorizontalUnit(int unit)
- {
- if (unit < UnitValue.PIXEL || unit > UnitValue.LABEL_ALIGN)
- throw new IllegalArgumentException("Illegal Unit: " + unit);
-
- if (DEF_H_UNIT != unit) {
- DEF_H_UNIT = unit;
- MOD_COUNT++;
- }
- }
-
- /** Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
- * @return The current default unit.
- * @see UnitValue#PIXEL
- * @see UnitValue#LPY
- */
- public static int getDefaultVerticalUnit()
- {
- return DEF_V_UNIT;
- }
-
- /** Sets the default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
- * @param unit The new default unit.
- * @see UnitValue#PIXEL
- * @see UnitValue#LPY
- */
- public static void setDefaultVerticalUnit(int unit)
- {
- if (unit < UnitValue.PIXEL || unit > UnitValue.LABEL_ALIGN)
- throw new IllegalArgumentException("Illegal Unit: " + unit);
-
- if (DEF_V_UNIT != unit) {
- DEF_V_UNIT = unit;
- MOD_COUNT++;
- }
- }
-
- /** The default alignment for rows. Pre v3.5 this was <code>false</code> but now it is
- * <code>true</code>.
- * @return The current value. Default is <code>true</code>.
- * @since 3.5
- */
- public static boolean getDefaultRowAlignmentBaseline()
- {
- return dra;
- }
-
- /** The default alignment for rows. Pre v3.5 this was <code>false</code> but now it is
- * <code>true</code>.
- * @param b The new value. Default is <code>true</code> from v3.5.
- * @since 3.5
- */
- public static void setDefaultRowAlignmentBaseline(boolean b)
- {
- dra = b;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4c3a7698/launchers/lmf-splash/src/main/java/net/miginfocom/layout/ResizeConstraint.java
----------------------------------------------------------------------
diff --git a/launchers/lmf-splash/src/main/java/net/miginfocom/layout/ResizeConstraint.java b/launchers/lmf-splash/src/main/java/net/miginfocom/layout/ResizeConstraint.java
deleted file mode 100644
index 75a4c37..0000000
--- a/launchers/lmf-splash/src/main/java/net/miginfocom/layout/ResizeConstraint.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package net.miginfocom.layout;
-
-import java.io.*;
-/*
- * License (BSD):
- * ==============
- *
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this list
- * of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice, this
- * list of conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * @version 1.0
- * @author Mikael Grev, MiG InfoCom AB
- * Date: 2006-sep-08
- */
-
-/** A parsed constraint that specifies how an entity (normally column/row or component) can shrink or
- * grow compared to other entities.
- */
-final class ResizeConstraint implements Externalizable
-{
- static final Float WEIGHT_100 = new Float(100);
-
- /** How flexilble the entity should be, relative to other entities, when it comes to growing. <code>null</code> or
- * zero mean it will never grow. An entity that has twise the growWeight compared to another entity will get twice
- * as much of available space.
- * <p>
- * "grow" are only compared within the same "growPrio".
- */
- Float grow = null;
-
- /** The relative priority used for determining which entities gets the extra space first.
- */
- int growPrio = 100;
-
- Float shrink = WEIGHT_100;
-
- int shrinkPrio = 100;
-
- public ResizeConstraint() // For Externalizable
- {
- }
-
- ResizeConstraint(int shrinkPrio, Float shrinkWeight, int growPrio, Float growWeight)
- {
- this.shrinkPrio = shrinkPrio;
- this.shrink = shrinkWeight;
- this.growPrio = growPrio;
- this.grow = growWeight;
- }
-
- // ************************************************
- // Persistence Delegate and Serializable combined.
- // ************************************************
-
- private Object readResolve() throws ObjectStreamException
- {
- return LayoutUtil.getSerializedObject(this);
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- {
- LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
- }
-
- public void writeExternal(ObjectOutput out) throws IOException
- {
- if (getClass() == ResizeConstraint.class)
- LayoutUtil.writeAsXML(out, this);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4c3a7698/launchers/lmf-splash/src/main/java/net/miginfocom/layout/UnitConverter.java
----------------------------------------------------------------------
diff --git a/launchers/lmf-splash/src/main/java/net/miginfocom/layout/UnitConverter.java b/launchers/lmf-splash/src/main/java/net/miginfocom/layout/UnitConverter.java
deleted file mode 100644
index e94e82b..0000000
--- a/launchers/lmf-splash/src/main/java/net/miginfocom/layout/UnitConverter.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package net.miginfocom.layout;
-/*
- * License (BSD):
- * ==============
- *
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this list
- * of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice, this
- * list of conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * @version 1.0
- * @author Mikael Grev, MiG InfoCom AB
- * Date: 2006-sep-08
- */
-
-/**
- */
-public abstract class UnitConverter
-{
- /** Value to return if this converter can not handle the <code>unit</code> sent in as an argument
- * to the convert method.
- */
- public static final int UNABLE = -87654312;
-
- /** Converts <code>value</code> to pixels.
- * @param value The value to be converted.
- * @param unit The unit of <code>value</code>. Never <code>null</code> and at least one character.
- * @param refValue Some reference value that may of may not be used. If the unit is percent for instance this value
- * is the value to take the percent from. Usually the size of the parent component in the appropriate dimension.
- * @param isHor If the value is horizontal (<code>true</code>) or vertical (<code>false</code>).
- * @param parent The parent of the target component that <code>value</code> is to be applied to.
- * Might for instance be needed to get the screen that the component is on in a multi screen environment.
- * <p>
- * May be <code>null</code> in which case a "best guess" value should be returned.
- * @param comp The component, if applicable, or <code>null</code> if none.
- * @return The number of pixels if <code>unit</code> is handled by this converter, <code>UnitConverter.UNABLE</code> if not.
- */
- public abstract int convertToPixels(float value, String unit, boolean isHor, float refValue, ContainerWrapper parent, ComponentWrapper comp);
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/4c3a7698/launchers/lmf-splash/src/main/java/net/miginfocom/layout/UnitValue.java
----------------------------------------------------------------------
diff --git a/launchers/lmf-splash/src/main/java/net/miginfocom/layout/UnitValue.java b/launchers/lmf-splash/src/main/java/net/miginfocom/layout/UnitValue.java
deleted file mode 100644
index 82cd752..0000000
--- a/launchers/lmf-splash/src/main/java/net/miginfocom/layout/UnitValue.java
+++ /dev/null
@@ -1,637 +0,0 @@
-package net.miginfocom.layout;
-/*
- * License (BSD):
- * ==============
- *
- * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this list
- * of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice, this
- * list of conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
- * used to endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * @version 1.0
- * @author Mikael Grev, MiG InfoCom AB
- * Date: 2006-sep-08
- */
-
-import java.beans.Encoder;
-import java.beans.Expression;
-import java.beans.PersistenceDelegate;
-import java.io.*;
-import java.util.ArrayList;
-import java.util.HashMap;
-
-public final class UnitValue implements Serializable
-{
- private static final HashMap<String, Integer> UNIT_MAP = new HashMap<String, Integer>(32);
-
- private static final ArrayList<UnitConverter> CONVERTERS = new ArrayList<UnitConverter>();
-
- /** An operation indicating a static value.
- */
- public static final int STATIC = 100;
-
- /** An operation indicating a addition of two sub units.
- */
- public static final int ADD = 101; // Must have "sub-unit values"
-
- /** An operation indicating a subtraction of two sub units
- */
- public static final int SUB = 102; // Must have "sub-unit values"
-
- /** An operation indicating a multiplication of two sub units.
- */
- public static final int MUL = 103; // Must have "sub-unit values"
-
- /** An operation indicating a division of two sub units.
- */
- public static final int DIV = 104; // Must have "sub-unit values"
-
- /** An operation indicating the minimum of two sub units
- */
- public static final int MIN = 105; // Must have "sub-unit values"
-
- /** An operation indicating the maximum of two sub units
- */
- public static final int MAX = 106; // Must have "sub-unit values"
-
- /** An operation indicating the middle value of two sub units
- */
- public static final int MID = 107; // Must have "sub-unit values"
-
-
-
-
- /** A unit indicating pixels.
- */
- public static final int PIXEL = 0;
-
- /** A unit indicating logical horizontal pixels.
- */
- public static final int LPX = 1;
-
- /** A unit indicating logical vertical pixels.
- */
- public static final int LPY = 2;
-
- /** A unit indicating millimeters.
- */
- public static final int MM = 3;
-
- /** A unit indicating centimeters.
- */
- public static final int CM = 4;
-
- /** A unit indicating inches.
- */
- public static final int INCH = 5;
-
- /** A unit indicating percent.
- */
- public static final int PERCENT = 6;
-
- /** A unit indicating points.
- */
- public static final int PT = 7;
-
- /** A unit indicating screen percentage width.
- */
- public static final int SPX = 8;
-
- /** A unit indicating screen percentage height.
- */
- public static final int SPY = 9;
-
- /** A unit indicating alignment.
- */
- public static final int ALIGN = 12;
-
- /** A unit indicating minimum size.
- */
- public static final int MIN_SIZE = 13;
-
- /** A unit indicating preferred size.
- */
- public static final int PREF_SIZE = 14;
-
- /** A unit indicating maximum size.
- */
- public static final int MAX_SIZE = 15;
-
- /** A unit indicating botton size.
- */
- public static final int BUTTON = 16;
-
- /** A unit indicating linking to x.
- */
- public static final int LINK_X = 18; // First link
-
- /** A unit indicating linking to y.
- */
- public static final int LINK_Y = 19;
-
- /** A unit indicating linking to width.
- */
- public static final int LINK_W = 20;
-
- /** A unit indicating linking to height.
- */
- public static final int LINK_H = 21;
-
- /** A unit indicating linking to x2.
- */
- public static final int LINK_X2 = 22;
-
- /** A unit indicating linking to y2.
- */
- public static final int LINK_Y2 = 23;
-
- /** A unit indicating linking to x position on screen.
- */
- public static final int LINK_XPOS = 24;
-
- /** A unit indicating linking to y position on screen.
- */
- public static final int LINK_YPOS = 25; // Last link
-
- /** A unit indicating a lookup.
- */
- public static final int LOOKUP = 26;
-
- /** A unit indicating label alignment.
- */
- public static final int LABEL_ALIGN = 27;
-
- private static final int IDENTITY = -1;
-
- static {
- UNIT_MAP.put("px", PIXEL);
- UNIT_MAP.put("lpx", LPX);
- UNIT_MAP.put("lpy", LPY);
- UNIT_MAP.put("%", PERCENT);
- UNIT_MAP.put("cm", CM);
- UNIT_MAP.put("in", INCH);
- UNIT_MAP.put("spx", SPX);
- UNIT_MAP.put("spy", SPY);
- UNIT_MAP.put("al", ALIGN);
- UNIT_MAP.put("mm", MM);
- UNIT_MAP.put("pt", PT);
- UNIT_MAP.put("min", MIN_SIZE);
- UNIT_MAP.put("minimum", MIN_SIZE);
- UNIT_MAP.put("p", PREF_SIZE);
- UNIT_MAP.put("pref", PREF_SIZE);
- UNIT_MAP.put("max", MAX_SIZE);
- UNIT_MAP.put("maximum", MAX_SIZE);
- UNIT_MAP.put("button", BUTTON);
- UNIT_MAP.put("label", LABEL_ALIGN);
- }
-
- static final UnitValue ZERO = new UnitValue(0, null, PIXEL, true, STATIC, null, null, "0px");
- static final UnitValue TOP = new UnitValue(0, null, PERCENT, false, STATIC, null, null, "top");
- static final UnitValue LEADING = new UnitValue(0, null, PERCENT, true, STATIC, null, null, "leading");
- static final UnitValue LEFT = new UnitValue(0, null, PERCENT, true, STATIC, null, null, "left");
- static final UnitValue CENTER = new UnitValue(50, null, PERCENT, true, STATIC, null, null, "center");
- static final UnitValue TRAILING = new UnitValue(100, null, PERCENT, true, STATIC, null, null, "trailing");
- static final UnitValue RIGHT = new UnitValue(100, null, PERCENT, true, STATIC, null, null, "right");
- static final UnitValue BOTTOM = new UnitValue(100, null, PERCENT, false, STATIC, null, null, "bottom");
- static final UnitValue LABEL = new UnitValue(0, null, LABEL_ALIGN, false, STATIC, null, null, "label");
-
- static final UnitValue INF = new UnitValue(LayoutUtil.INF, null, PIXEL, true, STATIC, null, null, "inf");
-
- static final UnitValue BASELINE_IDENTITY = new UnitValue(0, null, IDENTITY, false, STATIC, null, null, "baseline");
-
- private final transient float value;
- private final transient int unit;
- private final transient int oper;
- private final transient String unitStr;
- private transient String linkId = null; // Should be final, but initializes in a sub method.
- private final transient boolean isHor;
- private final transient UnitValue[] subUnits;
-
- // Pixel
- public UnitValue(float value) // If hor/ver does not matter.
- {
- this(value, null, PIXEL, true, STATIC, null, null, value + "px");
- }
-
- public UnitValue(float value, int unit, String createString) // If hor/ver does not matter.
- {
- this(value, null, unit, true, STATIC, null, null, createString);
- }
-
- UnitValue(float value, String unitStr, boolean isHor, int oper, String createString)
- {
- this(value, unitStr, -1, isHor, oper, null, null, createString);
- }
-
- UnitValue(boolean isHor, int oper, UnitValue sub1, UnitValue sub2, String createString)
- {
- this(0, "", -1, isHor, oper, sub1, sub2, createString);
- if (sub1 == null || sub2 == null)
- throw new IllegalArgumentException("Sub units is null!");
- }
-
- private UnitValue(float value, String unitStr, int unit, boolean isHor, int oper, UnitValue sub1, UnitValue sub2, String createString)
- {
- if (oper < STATIC || oper > MID)
- throw new IllegalArgumentException("Unknown Operation: " + oper);
-
- if (oper >= ADD && oper <= MID && (sub1 == null || sub2 == null))
- throw new IllegalArgumentException(oper + " Operation may not have null sub-UnitValues.");
-
- this.value = value;
- this.oper = oper;
- this.isHor = isHor;
- this.unitStr = unitStr;
- this.unit = unitStr != null ? parseUnitString() : unit;
- this.subUnits = sub1 != null && sub2 != null ? new UnitValue[] {sub1, sub2} : null;
-
- LayoutUtil.putCCString(this, createString); // "this" escapes!! Safe though.
- }
-
- /** Returns the size in pixels rounded.
- * @param refValue The reference value. Normally the size of the parent. For unit {@link #ALIGN} the current size of the component should be sent in.
- * @param parent The parent. May be <code>null</code> for testing the validity of the value, but should normally not and are not
- * required to return any usable value if <code>null</code>.
- * @param comp The component, if any, that the value is for. Might be <code>null</code> if the value is not
- * connected to any component.
- * @return The size in pixels.
- */
- public final int getPixels(float refValue, ContainerWrapper parent, ComponentWrapper comp)
- {
- return Math.round(getPixelsExact(refValue, parent, comp));
- }
-
- private static final float[] SCALE = new float[] {25.4f, 2.54f, 1f, 0f, 72f};
- /** Returns the size in pixels.
- * @param refValue The reference value. Normally the size of the parent. For unit {@link #ALIGN} the current size of the component should be sent in.
- * @param parent The parent. May be <code>null</code> for testing the validity of the value, but should normally not and are not
- * required to return any usable value if <code>null</code>.
- * @param comp The component, if any, that the value is for. Might be <code>null</code> if the value is not
- * connected to any component.
- * @return The size in pixels.
- */
- public final float getPixelsExact(float refValue, ContainerWrapper parent, ComponentWrapper comp)
- {
- if (parent == null)
- return 1;
-
- if (oper == STATIC) {
- switch (unit) {
- case PIXEL:
- return value;
-
- case LPX:
- case LPY:
- return parent.getPixelUnitFactor(unit == LPX) * value;
-
- case MM:
- case CM:
- case INCH:
- case PT:
- float f = SCALE[unit - MM];
- Float s = isHor ? PlatformDefaults.getHorizontalScaleFactor() : PlatformDefaults.getVerticalScaleFactor();
- if (s != null)
- f *= s;
- return (isHor ? parent.getHorizontalScreenDPI() : parent.getVerticalScreenDPI()) * value / f;
-
- case PERCENT:
- return value * refValue * 0.01f;
-
- case SPX:
- case SPY:
- return (unit == SPX ? parent.getScreenWidth() : parent.getScreenHeight()) * value * 0.01f;
-
- case ALIGN:
- Integer st = LinkHandler.getValue(parent.getLayout(), "visual", isHor ? LinkHandler.X : LinkHandler.Y);
- Integer sz = LinkHandler.getValue(parent.getLayout(), "visual", isHor ? LinkHandler.WIDTH : LinkHandler.HEIGHT);
- if (st == null || sz == null)
- return 0;
- return value * (Math.max(0, sz.intValue()) - refValue) + st;
-
- case MIN_SIZE:
- if (comp == null)
- return 0;
- return isHor ? comp.getMinimumWidth(comp.getHeight()) : comp.getMinimumHeight(comp.getWidth());
-
- case PREF_SIZE:
- if (comp == null)
- return 0;
- return isHor ? comp.getPreferredWidth(comp.getHeight()) : comp.getPreferredHeight(comp.getWidth());
-
- case MAX_SIZE:
- if (comp == null)
- return 0;
- return isHor ? comp.getMaximumWidth(comp.getHeight()) : comp.getMaximumHeight(comp.getWidth());
-
- case BUTTON:
- return PlatformDefaults.getMinimumButtonWidth().getPixels(refValue, parent, comp);
-
- case LINK_X:
- case LINK_Y:
- case LINK_W:
- case LINK_H:
- case LINK_X2:
- case LINK_Y2:
- case LINK_XPOS:
- case LINK_YPOS:
- Integer v = LinkHandler.getValue(parent.getLayout(), getLinkTargetId(), unit - (unit >= LINK_XPOS ? LINK_XPOS : LINK_X));
- if (v == null)
- return 0;
-
- if (unit == LINK_XPOS)
- return parent.getScreenLocationX() + v;
- if (unit == LINK_YPOS)
- return parent.getScreenLocationY() + v;
-
- return v;
-
- case LOOKUP:
- float res = lookup(refValue, parent, comp);
- if (res != UnitConverter.UNABLE)
- return res;
-
- case LABEL_ALIGN:
- return PlatformDefaults.getLabelAlignPercentage() * refValue;
-
- case IDENTITY:
- }
- throw new IllegalArgumentException("Unknown/illegal unit: " + unit + ", unitStr: " + unitStr);
- }
-
- if (subUnits != null && subUnits.length == 2) {
- float r1 = subUnits[0].getPixelsExact(refValue, parent, comp);
- float r2 = subUnits[1].getPixelsExact(refValue, parent, comp);
- switch (oper) {
- case ADD:
- return r1 + r2;
- case SUB:
- return r1 - r2;
- case MUL:
- return r1 * r2;
- case DIV:
- return r1 / r2;
- case MIN:
- return r1 < r2 ? r1 : r2;
- case MAX:
- return r1 > r2 ? r1 : r2;
- case MID:
- return (r1 + r2) * 0.5f;
- }
- }
-
- throw new IllegalArgumentException("Internal: Unknown Oper: " + oper);
- }
-
- private float lookup(float refValue, ContainerWrapper parent, ComponentWrapper comp)
- {
- float res = UnitConverter.UNABLE;
- for (int i = CONVERTERS.size() - 1; i >= 0; i--) {
- res = CONVERTERS.get(i).convertToPixels(value, unitStr, isHor, refValue, parent, comp);
- if (res != UnitConverter.UNABLE)
- return res;
- }
- return PlatformDefaults.convertToPixels(value, unitStr, isHor, refValue, parent, comp);
- }
-
- private int parseUnitString()
- {
- int len = unitStr.length();
- if (len == 0)
- return isHor ? PlatformDefaults.getDefaultHorizontalUnit() : PlatformDefaults.getDefaultVerticalUnit();
-
- Integer u = UNIT_MAP.get(unitStr);
- if (u != null)
- return u;
-
- if (unitStr.equals("lp"))
- return isHor ? LPX : LPY;
-
- if (unitStr.equals("sp"))
- return isHor ? SPX : SPY;
-
- if (lookup(0, null, null) != UnitConverter.UNABLE) // To test so we can fail fast
- return LOOKUP;
-
- // Only link left. E.g. "otherID.width"
-
- int pIx = unitStr.indexOf('.');
- if (pIx != -1) {
- linkId = unitStr.substring(0, pIx);
- String e = unitStr.substring(pIx + 1);
-
- if (e.equals("x"))
- return LINK_X;
- if (e.equals("y"))
- return LINK_Y;
- if (e.equals("w") || e.equals("width"))
- return LINK_W;
- if (e.equals("h") || e.equals("height"))
- return LINK_H;
- if (e.equals("x2"))
- return LINK_X2;
- if (e.equals("y2"))
- return LINK_Y2;
- if (e.equals("xpos"))
- return LINK_XPOS;
- if (e.equals("ypos"))
- return LINK_YPOS;
- }
-
- throw new IllegalArgumentException("Unknown keyword: " + unitStr);
- }
-
- final boolean isLinked()
- {
- return linkId != null;
- }
-
- final boolean isLinkedDeep()
- {
- if (subUnits == null)
- return linkId != null;
-
- for (UnitValue subUnit : subUnits) {
- if (subUnit.isLinkedDeep())
- return true;
- }
-
- return false;
- }
-
- final String getLinkTargetId()
- {
- return linkId;
- }
-
- final UnitValue getSubUnitValue(int i)
- {
- return subUnits[i];
- }
-
- final int getSubUnitCount()
- {
- return subUnits != null ? subUnits.length : 0;
- }
-
- public final UnitValue[] getSubUnits()
- {
- return subUnits != null ? subUnits.clone() : null;
- }
-
- public final int getUnit()
- {
- return unit;
- }
-
- public final String getUnitString()
- {
- return unitStr;
- }
-
- public final int getOperation()
- {
- return oper;
- }
-
- public final float getValue()
- {
- return value;
- }
-
- public final boolean isHorizontal()
- {
- return isHor;
- }
-
- final public String toString()
- {
- return getClass().getName() + ". Value=" + value + ", unit=" + unit + ", unitString: " + unitStr + ", oper=" + oper + ", isHor: " + isHor;
- }
-
- /** Returns the creation string for this object. Note that {@link LayoutUtil#setDesignTime(ContainerWrapper, boolean)} must be
- * set to <code>true</code> for the creation strings to be stored.
- * @return The constraint string or <code>null</code> if none is registered.
- */
- public final String getConstraintString()
- {
- return LayoutUtil.getCCString(this);
- }
-
- public final int hashCode()
- {
- return (int) (value * 12345) + (oper >>> 5) + unit >>> 17;
- }
-
- /** Adds a global unit converter that can convert from some <code>unit</code> to pixels.
- * <p>
- * This converter will be asked before the platform converter so the values for it (e.g. "related" and "unrelated")
- * can be overridden. It is however not possible to override the built in ones (e.g. "mm", "pixel" or "lp").
- * @param conv The converter. Not <code>null</code>.
- */
- public synchronized static void addGlobalUnitConverter(UnitConverter conv)
- {
- if (conv == null)
- throw new NullPointerException();
- CONVERTERS.add(conv);
- }
-
- /** Removed the converter.
- * @param unit The converter.
- * @return If there was a converter found and thus removed.
- */
- public synchronized static boolean removeGlobalUnitConverter(UnitConverter unit)
- {
- return CONVERTERS.remove(unit);
- }
-
- /** Returns the global converters currently registered. The platform converter will not be in this list.
- * @return The converters. Never <code>null</code>.
- */
- public synchronized static UnitConverter[] getGlobalUnitConverters()
- {
- return CONVERTERS.toArray(new UnitConverter[CONVERTERS.size()]);
- }
-
- /** Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
- * @return The current default unit.
- * @see #PIXEL
- * @see #LPX
- * @deprecated Use {@link PlatformDefaults#getDefaultHorizontalUnit()} and {@link PlatformDefaults#getDefaultVerticalUnit()} instead.
- */
- public static int getDefaultUnit()
- {
- return PlatformDefaults.getDefaultHorizontalUnit();
- }
-
- /** Sets the default unit. The default unit is the unit used if no unit is set. E.g. "width 10".
- * @param unit The new default unit.
- * @see #PIXEL
- * @see #LPX
- * @deprecated Use {@link PlatformDefaults#setDefaultHorizontalUnit(int)} and {@link PlatformDefaults#setDefaultVerticalUnit(int)} instead.
- */
- public static void setDefaultUnit(int unit)
- {
- PlatformDefaults.setDefaultHorizontalUnit(unit);
- PlatformDefaults.setDefaultVerticalUnit(unit);
- }
-
- static {
- if(LayoutUtil.HAS_BEANS){
- LayoutUtil.setDelegate(UnitValue.class, new PersistenceDelegate() {
- protected Expression instantiate(Object oldInstance, Encoder out)
- {
- UnitValue uv = (UnitValue) oldInstance;
- String cs = uv.getConstraintString();
- if (cs == null)
- throw new IllegalStateException("Design time must be on to use XML persistence. See LayoutUtil.");
-
- return new Expression(oldInstance, ConstraintParser.class, "parseUnitValueOrAlign", new Object[] {
- uv.getConstraintString(), (uv.isHorizontal() ? Boolean.TRUE : Boolean.FALSE), null
- });
- }
- });
- }
- }
-
- // ************************************************
- // Persistence Delegate and Serializable combined.
- // ************************************************
-
- private static final long serialVersionUID = 1L;
-
- private Object readResolve() throws ObjectStreamException
- {
- return LayoutUtil.getSerializedObject(this);
- }
-
- private void writeObject(ObjectOutputStream out) throws IOException
- {
- if (getClass() == UnitValue.class)
- LayoutUtil.writeAsXML(out, this);
- }
-
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
- {
- LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
- }
-}