Changeset 400


Ignore:
Timestamp:
11/18/08 13:34:54 (16 years ago)
Author:
ra33
Message:

Changed the way justification works so that...
Width field has a positive value if explicitly set and under the hood stores a negative value if it has not been set explicitly.

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

Legend:

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

    r376 r400  
    141141                        Class[] pString = { String.class };
    142142                        Class[] pInt = { int.class };
     143                        Class[] pIntO = { Integer.class };
    143144                        Class[] pFloat = { float.class };
    144145                        Class[] pFloatO = { Float.class };
     
    267268                        _SetMethods.put("j", Text.class.getMethod("setJustification",
    268269                                        pJustification));
    269                         _SetMethods.put("width", Text.class.getMethod("setWidth", pInt));
    270                         _SetMethods.put("w", Text.class.getMethod("setWidth", pInt));
     270                        _SetMethods.put("width", Text.class.getMethod("setWidth", pIntO));
     271                        _SetMethods.put("w", Text.class.getMethod("setWidth", pIntO));
    271272
    272273                        _SetMethods.put("size", Item.class.getMethod("setSize", pFloat));
  • trunk/src/org/expeditee/gui/DisplayIO.java

    r390 r400  
    2323import org.expeditee.items.Item;
    2424import org.expeditee.items.ItemParentStateChangedEvent;
    25 import org.expeditee.items.Permission;
    2625import org.expeditee.items.Picture;
    2726import org.expeditee.items.Text;
     
    7271         * The title to display in the Title bar.
    7372         */
    74         public static final String TITLE = "Exp31Oct2008A";
     73        public static String TITLE = "ExpDev";
    7574
    7675        private DisplayIO() {
  • trunk/src/org/expeditee/gui/FrameCreator.java

    r328 r400  
    195195                        toAdd.setOffset(0, 0);
    196196                        toAdd.setID(_current.getNextItemID());
    197                         toAdd.setRightMargin(FrameGraphics.getMaxFrameSize().width);
     197                        toAdd.setRightMargin(FrameGraphics.getMaxFrameSize().width, true);
    198198
    199199                        _current.addItem(toAdd);
  • trunk/src/org/expeditee/gui/FrameIO.java

    r376 r400  
    680680               
    681681                // Assign a width to the title.
    682                 titleItem.setRightMargin(template.getNameItem().getX());
     682                titleItem.setRightMargin(template.getNameItem().getX(), true);
    683683               
    684684                return template;
  • trunk/src/org/expeditee/gui/FrameKeyboardActions.java

    r376 r400  
    163163                        // DisplayIO.UpdateTitle();
    164164                        text = createText(ch);
    165                         justify(text);
     165                        text.justify(false);
    166166
    167167                        FrameUtils.setLastEdited(text);
     
    193193                 */
    194194                if (oldY < newMouse.y) {
    195                         //float diff = newMouse.y - oldY;
     195                        // float diff = newMouse.y - oldY;
    196196                        // System.out.print("c");
    197197                        Rectangle rect = text.getPolygon().getBounds();
    198                        
    199                         //Text lastEdited = FrameUtils.getLastEdited();
    200                         //FrameUtils.setLastEdited(null);
    201                        
     198
     199                        // Text lastEdited = FrameUtils.getLastEdited();
     200                        // FrameUtils.setLastEdited(null);
     201
    202202                        Item justBelow = FrameUtils.onItem(DisplayIO.getCurrentFrame(),
    203203                                        text.getX() + 10, rect.y + rect.height + 1, false);
    204                        
    205                         //FrameUtils.setLastEdited(lastEdited);
    206                        
    207                         //Dont drop unless
    208                         if (justBelow != null && justBelow instanceof Text && justBelow != on) {
     204
     205                        // FrameUtils.setLastEdited(lastEdited);
     206
     207                        // Dont drop unless
     208                        if (justBelow != null && justBelow instanceof Text
     209                                        && justBelow != on) {
    209210                                // Drop all the items below it down!
    210211                                // Get the list of items that must be dropped
     
    237238                                // DisplayIO.getCurrentFrame().removeItem(text);
    238239                                DisplayIO.setCursor(Item.DEFAULT_CURSOR);
    239                         }
    240                 }
    241         }
    242 
    243         /**
    244          * @param text
    245          */
    246         private static void justify(Text text) {
    247                 // Check if that text item is inside an enclosing rectangle...
    248                 // Set its max width accordingly
    249                 Polygon enclosure = FrameUtils.getEnlosingPolygon();
    250                 if (enclosure != null) {
    251                         Rectangle bounds = enclosure.getBounds();
    252                         text.setRightMargin(bounds.x + bounds.width);
    253                 } else {
    254                         text.setRightMargin(FrameGraphics.getMaxFrameSize().width);
    255 
    256                         // Check for the annotation that restricts the width of text items
    257                         // on the frame
    258                         String widthString;
    259                         if ((widthString = text.getParentOrCurrentFrame()
    260                                         .getAnnotationValue("maxwidth")) != null) {
    261                                 try {
    262                                         int width = text.getWidth();
    263                                         int maxWidth = Integer.parseInt(widthString);
    264                                         if (maxWidth < width)
    265                                                 text.setWidth(maxWidth);
    266                                 } catch (NumberFormatException nfe) {
    267                                 }
    268240                        }
    269241                }
     
    630602                        }
    631603                        textItem.setX(FrameMouseActions.getX());
    632                         justify(textItem);
     604                        textItem.justify(false);
    633605                        DisplayIO.getCurrentFrame().addItem(textItem);
    634606                        return textItem;
     
    969941                        if (text == null) {
    970942                                for (Text t : currentFrame.getBodyTextItems(false)) {
    971                                         justify(t);
     943                                        t.justify(true);
    972944                                }
    973945
     
    978950                        // text.setWidth(text.getBoundsWidth() - Item.MARGIN_RIGHT
    979951                        // - UserSettings.Gravity);
    980                         justify(text);
     952                        text.justify(true);
    981953                        break;
    982954                case KeyEvent.VK_S:
     
    14351407                                        || FreeItems.itemsAttachedToCursor()) {
    14361408                                dummyItem.getParentOrCurrentFrame().removeItem(dummyItem);
    1437                                 dummyItem.setRightMargin(FrameGraphics.getMaxFrameSize().width);
     1409                                dummyItem.setRightMargin(FrameGraphics.getMaxFrameSize().width,
     1410                                                false);
    14381411                        } else {
    14391412                                dummyItem.setWidth(toDropFrom.getWidth());
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r390 r400  
    10911091                                MessageBay.warningMessage("Exception occured when loading "
    10921092                                                + i.getClass().getSimpleName() + "(ID: " + i.getID()
    1093                                                 + ") " + e.getMessage());
     1093                                                + ") " + e.getMessage() != null ? e.getMessage() : "");
    10941094                        }
    10951095                }
  • trunk/src/org/expeditee/gui/UserSettings.java

    r355 r400  
    7272        static {
    7373                String jarPath = getJarLocation();
    74                 if (jarPath != null)
     74                if (jarPath != null){
    7575                        FrameIO.changeParentFolder(jarPath);
     76                }
    7677                else
    7778                        FrameIO.changeParentFolder("." + File.separator + "expeditee"
     
    117118
    118119                        int lastFileSeparator = jarName.lastIndexOf(File.separator);
     120                       
     121                        DisplayIO.TITLE = jarName.substring(lastFileSeparator + 1, jarName.length() - 4);
     122                       
    119123                        return jarName.substring(0, lastFileSeparator + 1);
    120124                }
  • trunk/src/org/expeditee/io/Conversion.java

    r390 r400  
    400400                        return Float.parseFloat(value);
    401401                }
     402               
     403                if (type.equals(Integer.class)) {
     404                        if (orig instanceof Integer
     405                                        && (value.startsWith("+") || value.startsWith("-"))) {
     406                                value = value.replace("+", "");
     407
     408                                return ((Integer) orig) + Integer.parseInt(value);
     409                        }
     410
     411                        if (value.length() == 0 || value.equals("null"))
     412                                return null;
     413
     414                        return Integer.parseInt(value);
     415                }
    402416
    403417                if (type.equals(double.class)) {
     
    583597
    584598                // integers can also be returned immediately
    585                 if (output instanceof Integer && (Integer) output >= 0)
     599                if (output instanceof Integer)
    586600                        return "" + output;
    587601
  • trunk/src/org/expeditee/io/DefaultFrameWriter.java

    r376 r400  
    113113                        _ItemTags
    114114                                        .put("m", Text.class.getMethod("getInitialSpacing", param));
    115                         _ItemTags.put("w", Text.class.getMethod("getWidth", param));
     115                        _ItemTags.put("w", Text.class.getMethod("getWidthToSave", param));
    116116                        _ItemTags.put("k", Text.class.getMethod("getJustification", param));
    117117
  • trunk/src/org/expeditee/io/FrameReader.java

    r362 r400  
    2828        protected static Class[] pString = { String.class };
    2929        protected static Class[] pInt = { int.class };
     30        protected static Class[] pIntO = { Integer.class };
    3031        protected static Class[] pFloat = { float.class };
    3132        protected static Class[] pFloatO = { Float.class };
     
    115116                        _ItemTags.put('b', Text.class.getMethod("setLetterSpacing", pInt));
    116117                        _ItemTags.put('m', Text.class.getMethod("setInitialSpacing", pInt));
    117                         _ItemTags.put('w', Text.class.getMethod("setWidth", pInt));
     118                        _ItemTags.put('w', Text.class.getMethod("setWidth", pIntO));
    118119                        _ItemTags.put('k', Text.class.getMethod("setJustification", pJustification));
    119120
  • trunk/src/org/expeditee/io/KMSReader.java

    r390 r400  
    106106                        _ItemTags.put("b", Text.class.getMethod("setLetterSpacing", pInt));
    107107                        _ItemTags.put("m", Text.class.getMethod("setInitialSpacing", pInt));
    108                         _ItemTags.put("w", Text.class.getMethod("setWidth", pInt));
     108                        _ItemTags.put("w", Text.class.getMethod("setWidth", pIntO));
    109109                        _ItemTags.put("k", Text.class.getMethod("setJustification", pJustification));
    110110
  • trunk/src/org/expeditee/items/Item.java

    r390 r400  
    191191                 * the user uses backspace to delete a text line end
    192192                 */
    193                 dest._anchorBottom = source._anchorBottom;
    194                 dest._anchorRight = source._anchorRight;
     193                //dest._anchorBottom = source._anchorBottom;
     194                //dest._anchorRight = source._anchorRight;
    195195
    196196                dest.setFormula(source.getFormula());
     
    946946        }
    947947
    948         public int getWidth() {
    949                 return 0;
     948        public Integer getWidthToSave() {
     949                return getWidth();
     950        }
     951       
     952        public Integer getWidth() {
     953                return null;
    950954        }
    951955
     
    18621866        }
    18631867
    1864         public void setWidth(int width) throws UnsupportedOperationException {
     1868        public void setWidth(Integer width) throws UnsupportedOperationException {
    18651869                throw new UnsupportedOperationException(
    18661870                                "Item type does not support width attribute!");
    18671871        }
    18681872
    1869         public void setRightMargin(int i) {
    1870                 setWidth(i - getX() - Item.MARGIN_LEFT);
     1873        public void setRightMargin(int i, boolean fixWidth) {
     1874                int newWidth = i - getX() - Item.MARGIN_LEFT;
     1875                if(!fixWidth){
     1876                        newWidth *= -1;
     1877                }
     1878               
     1879                setWidth(newWidth);
    18711880        }
    18721881
     
    28092818                return _locks.contains(item);
    28102819        }*/
     2820       
     2821       
    28112822}
  • trunk/src/org/expeditee/items/Picture.java

    r376 r400  
    273273
    274274        @Override
    275         public void setWidth(int width) {
     275        public void setWidth(Integer width) {
    276276                _scale = width * 1F / (_end.x - _start.x);
    277277        }
     
    289289         */
    290290        @Override
    291         public int getWidth() {
     291        public Integer getWidth() {
    292292                return Math.round((_end.x - _start.x) * _scale);
    293293        }
  • trunk/src/org/expeditee/items/Text.java

    r390 r400  
    4747 */
    4848public class Text extends Item {
     49        private static final int ADJUST_WIDTH_THRESHOLD = 200;
     50
    4951        public static String LINE_SEPARATOR = System.getProperty("line.separator");
    5052
     
    98100        public static final int PAGE_UP = 8;
    99101
    100         private int _maxWidth = -1;
     102        private Integer _maxWidth = null;
    101103
    102104        private Justification _justification = Justification.left;
     
    181183         */
    182184        @Override
    183         public void setWidth(int width) {
    184                 invalidateAll();
    185                 // 0 is the default
    186                 if (width <= 0) {
    187                         width = -1;
     185        public void setWidth(Integer width) {
     186                invalidateAll();
     187
     188                if (width == null) {
    188189                        setJustification(Justification.left);
     190                        setRightMargin(FrameGraphics.getMaxFrameSize().width, false);
     191                        return;
    189192                }
    190193
     
    194197        }
    195198
     199        public Integer getWidthToSave() {
     200                return _maxWidth;
     201        }
     202       
    196203        /**
    197204         * Returns the maximum width of this Text item when justifcation is used.
    198          * Note the returned value may be -1, which indicates that there is no
    199          * maximum size set
     205         * If the width is negative, it means no explicit width has been set
    200206         *
    201207         * @return The maximum width of this Text item when justification is used
    202208         */
    203209        @Override
    204         public int getWidth() {
     210        public Integer getWidth() {
     211                if (_maxWidth == null || _maxWidth <= 0)
     212                        return null;
    205213                return _maxWidth;
     214        }
     215
     216        public Integer getAbsoluteWidth() {
     217                if (_maxWidth == null) {
     218                        return Integer.MAX_VALUE;
     219                }
     220
     221                return Math.abs(_maxWidth);
    206222        }
    207223
     
    224240
    225241                // Only justification left works with 0 width
    226                 if (just != Justification.left && getWidth() <= 0) {
    227                         // TODO Tighten this up so it subtracts the margin widths
    228                         setWidth(getBoundsWidth());
    229                 }
     242                // if (just != null && just != Justification.left && !hasWidth()) {
     243                // // TODO Tighten this up so it subtracts the margin widths
     244                // setWidth(getBoundsWidth());
     245                // }
    230246
    231247                _justification = just;
     
    247263
    248264        private int getJustOffset(TextLayout layout) {
    249                 if (getWidth() < 0)
    250                         return 0;
    251 
    252265                if (getJustification() == Justification.center)
    253                         return (int) ((getWidth() - layout.getAdvance()) / 2);
     266                        return (int) ((getAbsoluteWidth() - layout.getAdvance()) / 2);
    254267                else if (getJustification() == Justification.right)
    255                         return (int) (getWidth() - layout.getAdvance());
     268                        return (int) (getAbsoluteWidth() - layout.getAdvance());
    256269
    257270                return 0;
     
    269282                setText(text, false);
    270283        }
    271        
     284
    272285        public void setText(String text, Boolean clearCache) {
    273286                // if (_text != null && text.length() < _text.length())
     
    279292                 * mode
    280293                 */
    281                 if(clearCache){
     294                if (clearCache) {
    282295                        clearCache();
    283                 }               
    284                        
     296                }
     297
    285298                rebuild(true);
    286299                invalidateAll();
     
    13141327                // If its justification right or center then DONT limit the width
    13151328                if (getJustification() != null) {
    1316                         maxX = Item.MARGIN_RIGHT + getWidth();
     1329                        maxX = Item.MARGIN_RIGHT + getAbsoluteWidth();
    13171330                }
    13181331
     
    13681381
    13691382                if (limitWidth) {
    1370                         if (getWidth() > 0)
    1371                                 width = getWidth();
     1383                        width = getAbsoluteWidth();
    13721384                        // else if (getMaxWidth() > 0)
    13731385                        // width = Math.max(50, getMaxWidth() - getX()
     
    14001412                        _lineOffsets.add(_lineBreaker.getPosition());
    14011413
    1402                         if (getWidth() > 0 && getJustification() == Justification.full
     1414                        if (/* hasWidth() && */getJustification() == Justification.full
    14031415                                        && _lineBreaker.getPosition() < _text.length())
    14041416                                layout = layout.getJustifiedLayout(width);
     
    14091421                updatePolygon();
    14101422
     1423        }
     1424
     1425        private boolean hasFixedWidth() {
     1426                assert (_maxWidth != null);
     1427                if(_maxWidth == null){
     1428                        justify(false);
     1429                }
     1430                return _maxWidth > 0;
    14111431        }
    14121432
     
    16581678                copy.setSpacing(getSpacing());
    16591679                copy.setInitialSpacing(getInitialSpacing());
     1680
     1681                copy.setWidth(getWidth());
    16601682                copy.setJustification(getJustification());
    16611683                copy.setLetterSpacing(getLetterSpacing());
     
    16691691                }
    16701692                copy.setHidden(!isVisible());
    1671                 // copy.setWidth(getWidth());
    16721693                return copy;
    16731694        }
     
    18561877                setPosition(MARGIN_LEFT, MARGIN_LEFT + getBoundsHeight());
    18571878                Frame modelFrame = getParentOrCurrentFrame();
    1858                 if (modelFrame != null) {
    1859                         setRightMargin(modelFrame.getNameItem().getX()
    1860                                         - MARGIN_LEFT);
     1879                if (modelFrame != null) {
     1880                        setRightMargin(modelFrame.getNameItem().getX() - MARGIN_LEFT, true);
    18611881                } else {
    1862                         System.out.print("Error: text.resetTitlePosition, getParent or currentFrame returned null");
    1863                         setRightMargin(MARGIN_LEFT);
     1882                        System.out
     1883                                        .print("Error: text.resetTitlePosition, getParent or currentFrame returned null");
     1884                        setRightMargin(MARGIN_LEFT, true);
    18641885                }
    18651886        }
     
    19431964                if (isLineEnd())
    19441965                        DisplayIO.setCursor(Item.DEFAULT_CURSOR);
     1966
     1967                if (!hasFixedWidth()) {
     1968                        int frameWidth = FrameGraphics.getMaxFrameSize().width;
     1969                        /*
     1970                         * Only change width if it is more than 150 pixels from the right of
     1971                         * the screen
     1972                         */
     1973                        if (frameWidth - getX() > ADJUST_WIDTH_THRESHOLD) {
     1974                                justify(false);
     1975                                //setRightMargin(frameWidth, false);
     1976                        }
     1977                }
     1978        }
     1979       
     1980        public void justify(boolean fixWidth) {
     1981                Integer width = FrameGraphics.getMaxFrameSize().width;
     1982
     1983                // Check if that text item is inside an enclosing rectangle...
     1984                // Set its max width accordingly
     1985                Polygon enclosure = FrameUtils.getEnlosingPolygon();
     1986                if (enclosure != null) {
     1987                        Rectangle bounds = enclosure.getBounds();
     1988                        if(bounds.width > 200 && getX() < bounds.width / 3 + bounds.x){
     1989                                width = bounds.x + bounds.width;
     1990                        }
     1991                }
     1992
     1993                if (getWidth() == null)
     1994                        setRightMargin(width, fixWidth);
     1995
     1996                // Check for the annotation that restricts the width of text items
     1997                // on the frame
     1998                String widthString;
     1999                if ((widthString = getParentOrCurrentFrame().getAnnotationValue(
     2000                                "maxwidth")) != null) {
     2001                        try {
     2002                                int oldWidth = getWidth();
     2003                                int maxWidth = Integer.parseInt(widthString);
     2004                                if (maxWidth < oldWidth)
     2005                                        setWidth(maxWidth);
     2006                        } catch (NumberFormatException nfe) {
     2007                        }
     2008
     2009                }
    19452010        }
    19462011
     
    22102275        public void scale(Float scale, int originX, int originY) {
    22112276                setSize(getSize() * scale);
     2277
    22122278                setWidth(Math.round(getWidth() * scale));
    22132279                super.scale(scale, originX, originY);
  • trunk/src/org/expeditee/items/widgets/InteractiveWidget.java

    r374 r400  
    183183
    184184                String classname = tokens[0];
    185                 if (classname.charAt(0) == '$')
    186                         classname = Actions.getClassName(classname.substring(1));
     185                if (classname.charAt(0) == '$'){
     186                        String shortClassname = classname.substring(1);
     187                        classname = Actions.getClassName(shortClassname);
     188                       
     189                        if (classname == null) // ensure it exists
     190                                throw new InteractiveWidgetNotAvailableException(shortClassname
     191                                                + " does not exist or is not an InteractiveWidget");
     192                }
    187193                // Attempt to locate the class using reflection
    188194                Class<?> iwclass = findIWidgetClass(classname);
     
    234240         */
    235241        private static Class findIWidgetClass(String classname) {
     242                if(classname == null)
     243                        return null;
     244               
    236245                try {
    237246                        Class c = Class.forName(classname); // attempt to find the class
Note: See TracChangeset for help on using the changeset viewer.