Ignore:
Timestamp:
01/26/21 09:45:54 (3 years ago)
Author:
bnemhaus
Message:

With a Item under your cursor, pressing left and right mouse buttons at the same time, extracts the properties of that item. (No change)
However, if an Item is attached to the users cursor when doing this, nothing happens. Now, instead of nothing happening, all attached Items are checked to see if they are in the format of "Property:". If they are then those specified properties are extracted.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/AttributeUtils.java

    r1513 r1548  
    2222import java.lang.reflect.InvocationTargetException;
    2323import java.lang.reflect.Method;
     24import java.util.Collection;
    2425import java.util.HashMap;
    2526import java.util.LinkedList;
     
    427428                        throw new IncorrectTypeException("toExtract", "Item | Frame");
    428429                }
    429 
     430               
     431                // If there are Items attached to cursor, extract only those properties being asked for
     432                if (FreeItems.hasItemsAttachedToCursor()) {
     433                        extractSpecifiedAttributes(toExtract, attribSet);
     434                        return null;
     435                }
     436               
    430437                // StringBuffer to store all the extracted Attribute:Value pairs
    431438                StringBuffer attributes = new StringBuffer();
     
    468475        }
    469476
     477        /**
     478         * Extracts only the attributes specified by the FreeItems. 
     479         * Designed to be called exclusively from AttributeUtils::extractAttributes
     480         * @param toExtract The Item or Frame to extract attributes from
     481         * @param attributes The set of attributes to consult
     482         */
     483        private static void extractSpecifiedAttributes(Object toExtract, AttributeSet attributes) {
     484                Collection<Text> textItemsOnCursor = FreeItems.getTextItems();
     485                List<String> keys = attributes.keys;
     486               
     487                for (Text canditate: textItemsOnCursor) {
     488                        String canditateContent = canditate.getText().trim();
     489                        if (canditateContent.charAt(canditateContent.length() - 1) == ':') {
     490                                String attributeName = canditateContent.substring(0, canditateContent.length() - 1);
     491                                String attributeNameLower = attributeName.toLowerCase();
     492                                if (keys.contains(attributeNameLower)) {
     493                                        Attribute a = attributes.get(attributeNameLower);
     494                                        // Make sure the classes of the methods match the item
     495                                        if (a != null && a.getter != null && a.getter.getDeclaringClass().isAssignableFrom(toExtract.getClass())) {     
     496                                                String value = getValue(attributeNameLower, a, toExtract, true);
     497                                                if (value == null) {
     498                                                        continue;
     499                                                }
     500                                                canditate.setText(attributeName + ": " + value);
     501                                        }
     502                                }
     503                        }
     504                }
     505        }
     506               
    470507        /**
    471508         * Gets a string form of the value for a given item get method.
Note: See TracChangeset for help on using the changeset viewer.