Changeset 976


Ignore:
Timestamp:
12/01/15 10:59:02 (8 years ago)
Author:
bln4
Message:

When deciding what action to run Actions.java now considers actions with the same parameter list by emphasising some parameter types over others. Integer -> Double -> Float -> String -> All others

Now doesn't try to map in a item if the item for some reason has a null bounding_rect. A error message is displayed if it finds a null.

Location:
trunk/src/org/expeditee
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Actions.java

    r975 r976  
    2424import java.lang.reflect.Modifier;
    2525import java.rmi.UnexpectedException;
     26import java.util.Arrays;
    2627import java.util.Collection;
    2728import java.util.Comparator;
     
    4243import org.expeditee.items.Item;
    4344import org.expeditee.items.ItemUtils;
    44 import org.expeditee.items.Text;
    4545import org.expeditee.reflection.PackageLoader;
    4646import org.expeditee.simple.SString;
     
    408408        public static Object PerformAction(final Frame source, final Item launcher,
    409409                        final String command) throws Exception {
    410                 System.err.println("Running action: " + command + " with floating: " + launcher);
    411410                final String actionName = getName(command);
    412411                final String parameters = command.substring(actionName.length()).trim();
     
    441440                        @Override
    442441                        public int compare(final Method m1, final Method m2) {
    443                                 return m2.getParameterCount() - m1.getParameterCount();
     442                                final int parameterCountDifference = m2.getParameterCount() - m1.getParameterCount();
     443                                if(parameterCountDifference == 0) {
     444                                        final Class<?>[] m1ParamTypes = m1.getParameterTypes();
     445                                        final Class<?>[] m2ParamTypes = m2.getParameterTypes();
     446                                        final List<Class<?>> typeOrder = Arrays.asList(Integer.TYPE, Double.TYPE, Float.TYPE, String.class);                                   
     447                                        for(int i = 0,o = 0; i < m1ParamTypes.length && o < m2ParamTypes.length; i++,o++) {
     448                                                final Class<?> m1ParamType = m1ParamTypes[i];
     449                                                final Class<?> m2ParamType = m2ParamTypes[o];
     450                                                final int m1ParamTypeIndex = typeOrder.indexOf(m1ParamType) != -1 ?
     451                                                                                typeOrder.indexOf(m1ParamType) : typeOrder.size();
     452                                                final int m2ParamTypeIndex = typeOrder.indexOf(m2ParamType) != -1 ?
     453                                                                                typeOrder.indexOf(m2ParamType) : typeOrder.size();
     454                                                final int paramMagnitude = m2ParamTypeIndex - m1ParamTypeIndex;
     455                                                if(paramMagnitude != 0) return paramMagnitude;
     456                                        }
     457                                }
     458                                return parameterCountDifference;
    444459                        }
    445460                });
  • trunk/src/org/expeditee/io/flowlayout/XGroupItem.java

    r975 r976  
    143143                        // overspill can occur (and is acceptable) when raw-text item spills
    144144                        // out of enclosing shape (such as a rectangle)
    145                         mapInItem(x_raw_item);
     145                        if(x_raw_item.bounding_rect == null) {
     146                                final StringBuilder errorMsg =
     147                                                new StringBuilder("Was about to try mapInItem(XRawItem) but found a null bounding_rect.  Item details: ");
     148                                final String nl = System.getProperty("line.separator");
     149                                errorMsg.append("\t Item parent: "                      + text_item.getParent() + nl);
     150                                errorMsg.append("\t Item position: "            + text_item.getPosition() + nl);
     151                                errorMsg.append("\t Item text content: "        + text_item.getText() + nl);
     152                                System.err.println(errorMsg.toString());
     153                        }
     154                        else mapInItem(x_raw_item);
    146155                }
    147156
Note: See TracChangeset for help on using the changeset viewer.