Changeset 10207 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2016-05-13T21:32:58+02:00 (9 years ago)
Author:
Don-vip
Message:

remove MultiSplitLayout parsing features (code previously used only by RoadSigns plugin)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/widgets/MultiSplitLayout.java

    r10043 r10207  
    2929import java.beans.PropertyChangeListener;
    3030import java.beans.PropertyChangeSupport;
    31 import java.io.Reader;
    32 import java.io.StreamTokenizer;
    33 import java.io.StringReader;
    3431import java.util.ArrayList;
    3532import java.util.Collections;
     
    3835import java.util.List;
    3936import java.util.ListIterator;
    40 import java.util.Locale;
    4137import java.util.Map;
    4238
    4339import javax.swing.UIManager;
    4440
    45 import org.openstreetmap.josm.Main;
    4641import org.openstreetmap.josm.tools.CheckParameterUtil;
    47 import org.openstreetmap.josm.tools.Utils;
    4842
    4943/**
     
    10498    }
    10599
     100    /**
     101     * Add property change listener.
     102     * @param listener listener to add
     103     */
    106104    public void addPropertyChangeListener(PropertyChangeListener listener) {
    107105        if (listener != null) {
     
    110108    }
    111109
     110    /**
     111     * Remove property change listener.
     112     * @param listener listener to remove
     113     */
    112114    public void removePropertyChangeListener(PropertyChangeListener listener) {
    113115        if (listener != null) {
     
    116118    }
    117119
     120    /**
     121     * Replies list of property change listeners.
     122     * @return list of property change listeners
     123     */
    118124    public PropertyChangeListener[] getPropertyChangeListeners() {
    119125        return pcs.getPropertyChangeListeners();
     
    652658                        splitChildren.hasNext() ? (Divider) splitChildren.next() : null;
    653659
    654                         double childHeight = 0.0;
     660                        double childHeight;
    655661                        if (getFloatingDividers()) {
    656662                            childHeight = preferredNodeSize(splitChild).getHeight();
     
    714720    }
    715721
    716     private void checkLayout(Node root) {
     722    private static void checkLayout(Node root) {
    717723        if (root instanceof Split) {
    718724            Split split = (Split) root;
     
    792798    }
    793799
    794     private List<Divider> dividersThatOverlap(Node root, Rectangle r) {
     800    private static List<Divider> dividersThatOverlap(Node root, Rectangle r) {
    795801        if (nodeOverlapsRectangle(root, r) && (root instanceof Split)) {
    796802            List<Divider> dividers = new ArrayList<>();
     
    11381144        }
    11391145    }
    1140 
    1141     private static void throwParseException(StreamTokenizer st, String msg) throws Exception {
    1142         throw new Exception("MultiSplitLayout.parseModel Error: " + msg);
    1143     }
    1144 
    1145     private static void parseAttribute(String name, StreamTokenizer st, Node node) throws Exception {
    1146         if (st.nextToken() != '=') {
    1147             throwParseException(st, "expected '=' after " + name);
    1148         }
    1149         if ("WEIGHT".equalsIgnoreCase(name)) {
    1150             if (st.nextToken() == StreamTokenizer.TT_NUMBER) {
    1151                 node.setWeight(st.nval);
    1152             } else {
    1153                 throwParseException(st, "invalid weight");
    1154             }
    1155         } else if ("NAME".equalsIgnoreCase(name)) {
    1156             if (st.nextToken() == StreamTokenizer.TT_WORD) {
    1157                 if (node instanceof Leaf) {
    1158                     ((Leaf) node).setName(st.sval);
    1159                 } else {
    1160                     throwParseException(st, "can't specify name for " + node);
    1161                 }
    1162             } else {
    1163                 throwParseException(st, "invalid name");
    1164             }
    1165         } else {
    1166             throwParseException(st, "unrecognized attribute \"" + name + '\"');
    1167         }
    1168     }
    1169 
    1170     private static void addSplitChild(Split parent, Node child) {
    1171         List<Node> children = new ArrayList<>(parent.getChildren());
    1172         if (children.isEmpty()) {
    1173             children.add(child);
    1174         } else {
    1175             children.add(new Divider());
    1176             children.add(child);
    1177         }
    1178         parent.setChildren(children);
    1179     }
    1180 
    1181     private static void parseLeaf(StreamTokenizer st, Split parent) throws Exception {
    1182         Leaf leaf = new Leaf();
    1183         int token;
    1184         while ((token = st.nextToken()) != StreamTokenizer.TT_EOF) {
    1185             if (token == ')') {
    1186                 break;
    1187             }
    1188             if (token == StreamTokenizer.TT_WORD) {
    1189                 parseAttribute(st.sval, st, leaf);
    1190             } else {
    1191                 throwParseException(st, "Bad Leaf: " + leaf);
    1192             }
    1193         }
    1194         addSplitChild(parent, leaf);
    1195     }
    1196 
    1197     private static void parseSplit(StreamTokenizer st, Split parent) throws Exception {
    1198         int token;
    1199         while ((token = st.nextToken()) != StreamTokenizer.TT_EOF) {
    1200             if (token == ')') {
    1201                 break;
    1202             } else if (token == StreamTokenizer.TT_WORD) {
    1203                 if ("WEIGHT".equalsIgnoreCase(st.sval)) {
    1204                     parseAttribute(st.sval, st, parent);
    1205                 } else {
    1206                     addSplitChild(parent, new Leaf(st.sval));
    1207                 }
    1208             } else if (token == '(') {
    1209                 if ((token = st.nextToken()) != StreamTokenizer.TT_WORD) {
    1210                     throwParseException(st, "invalid node type");
    1211                 }
    1212                 String nodeType = st.sval.toUpperCase(Locale.ENGLISH);
    1213                 if ("LEAF".equals(nodeType)) {
    1214                     parseLeaf(st, parent);
    1215                 } else if ("ROW".equals(nodeType) || "COLUMN".equals(nodeType)) {
    1216                     Split split = new Split();
    1217                     split.setRowLayout("ROW".equals(nodeType));
    1218                     addSplitChild(parent, split);
    1219                     parseSplit(st, split);
    1220                 } else {
    1221                     throwParseException(st, "unrecognized node type '" + nodeType + '\'');
    1222                 }
    1223             }
    1224         }
    1225     }
    1226 
    1227     private static Node parseModel(Reader r) {
    1228         StreamTokenizer st = new StreamTokenizer(r);
    1229         try {
    1230             Split root = new Split();
    1231             parseSplit(st, root);
    1232             return root.getChildren().get(0);
    1233         } catch (Exception e) {
    1234             Main.error(e);
    1235         } finally {
    1236             Utils.close(r);
    1237         }
    1238         return null;
    1239     }
    1240 
    1241     /**
    1242      * A convenience method that converts a string to a MultiSplitLayout model (a tree of Nodes) using a
    1243      * a simple syntax.  Nodes are represented by parenthetical expressions whose first token
    1244      * is one of ROW/COLUMN/LEAF.  ROW and COLUMN specify horizontal and vertical Split nodes respectively,
    1245      * LEAF specifies a Leaf node.  A Leaf's name and weight can be specified with attributes,
    1246      * name=<i>myLeafName</i> weight=<i>myLeafWeight</i>.
    1247      * Similarly, a Split's weight can be specified with weight=<i>mySplitWeight</i>.
    1248      *
    1249      * <p> For example, the following expression generates a horizontal Split node with three children:
    1250      * the Leafs named left and right, and a Divider in between:
    1251      * <pre>
    1252      * (ROW (LEAF name=left) (LEAF name=right weight=1.0))
    1253      * </pre>
    1254      *
    1255      * <p> Dividers should not be included in the string, they're added automatcially as needed.  Because
    1256      * Leaf nodes often only need to specify a name, one can specify a Leaf by just providing the name.
    1257      * The previous example can be written like this:
    1258      * <pre>
    1259      * (ROW left (LEAF name=right weight=1.0))
    1260      * </pre>
    1261      *
    1262      * <p>Here's a more complex example.  One row with three elements, the first and last of which are columns
    1263      * with two leaves each:
    1264      * <pre>
    1265      * (ROW (COLUMN weight=0.5 left.top left.bottom)
    1266      *      (LEAF name=middle)
    1267      *      (COLUMN weight=0.5 right.top right.bottom))
    1268      * </pre>
    1269      *
    1270      * <p> This syntax is not intended for archiving or configuration files .  It's just a convenience for
    1271      * examples and tests.
    1272      * @param s model as string
    1273      *
    1274      * @return the Node root of a tree based on s.
    1275      */
    1276     public static Node parseModel(String s) {
    1277         return parseModel(new StringReader(s));
    1278     }
    12791146}
Note: See TracChangeset for help on using the changeset viewer.