Ignore:
Timestamp:
05/23/19 12:20:07 (5 years ago)
Author:
bln4
Message:

MaxWidth on text items is now a thing. Use this on text boxes in authentication frameset.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/items/Text.java

    r1296 r1369  
    136136         * the user. Initially set to be as wide as possible.
    137137         */
     138        private Integer _width = -Integer.MAX_VALUE;
     139
     140        private Integer _minWidth = -Integer.MAX_VALUE;
     141       
    138142        private Integer _maxWidth = -Integer.MAX_VALUE;
    139 
    140         private Integer _minWidth = -Integer.MAX_VALUE;
    141143
    142144        private Justification _justification = Justification.left;
     
    186188        // The font to display this text in
    187189        private Font _font;
     190        private Font _substituteFont;
     191        private boolean _useSubstituteFont = false;
    188192
    189193        // The optional mask character to us in place of the text's content.
     
    395399                }
    396400
    397                 _maxWidth = width;
     401                _width = width;
    398402                rebuild(true);
    399403                invalidateAll();
     
    414418                invalidateAll();
    415419        }
     420       
     421        public void setMaxWidth(Integer width) {
     422                invalidateAll();
     423
     424                if (width == null) {
     425                        setJustification(Justification.left);
     426                        setRightMargin(DisplayController.getFramePaintAreaWidth(), false);
     427                        return;
     428                }
     429               
     430                _maxWidth = width;
     431                rebuild(true);
     432                invalidateAll();
     433        }
     434       
    416435
    417436        /**
     
    428447        @Override
    429448        public Integer getWidth() {
    430                 if (_maxWidth == null || _maxWidth <= 0) {
     449                if (_width == null || _width <= 0) {
    431450                        return null;
    432451                }
    433452
    434                 return _maxWidth;
     453                return _width;
    435454        }
    436455
    437456        public Integer getAbsoluteWidth() {
    438                 if (_maxWidth == null) {
     457                if (_width == null) {
    439458                        return Integer.MAX_VALUE;
    440459                }
    441460
    442                 return Math.abs(_maxWidth);
     461                return Math.abs(_width);
    443462        }
    444463
     
    449468                return _minWidth;
    450469        }
     470       
     471        public Integer getMaxWidth() {
     472                if (_maxWidth == null || _maxWidth <= 0) {
     473                        return null;
     474                }
     475                return _maxWidth;
     476        }
    451477
    452478        public Integer getAbsoluteMinWidth() {
     
    456482                return Math.abs(_minWidth);
    457483        }
    458 
     484       
     485        public Integer getAbsoluteMaxWidth() {
     486                if (_maxWidth == null) {
     487                        return Integer.MIN_VALUE;
     488                }
     489                return Math.abs(_maxWidth);
     490        }
     491       
    459492        @Override
    460493        public Colour getHighlightColor() {
     
    13001333         */
    13011334        public Font getPaintFont() {
    1302                 final Font f = getFont();
     1335                Font f = getFont();
    13031336                if (f == null) {
    13041337                        _font = EcosystemManager.getFontManager().getDefaultFont().clone();
    1305                         return _font;
     1338                        f = _font;
     1339                       
     1340                        if (_useSubstituteFont) {
     1341                                f = _substituteFont;
     1342                        }
    13061343                }
    13071344                return f;
     
    16931730
    16941731                        int minWidth = getAbsoluteMinWidth();
     1732                        int maxWidth = getAbsoluteMaxWidth();
    16951733
    16961734                        minX = Math.min(minX, bounds.getMinX());
    16971735                        maxX = minWidth < Integer.MAX_VALUE ? Math.max(minX + minWidth, bounds.getMaxX())
    16981736                                        : Math.max(maxX, bounds.getMaxX());
     1737                        if ((maxWidth - minX) < maxX) {
     1738                                this._useSubstituteFont = true;
     1739                                this._substituteFont.setSize(this._substituteFont.getSize() - 1);
     1740                        } else {
     1741                                this._useSubstituteFont = false;
     1742                                this._substituteFont = this._font;
     1743                        }
    16991744                        minY = Math.min(minY, (int) (bounds.getMinY() + y));
    17001745                        maxY = Math.max(maxY, (int) (bounds.getMaxY() + y));
     
    18081853                float width = Float.MAX_VALUE;
    18091854                if (limitWidth) {
    1810                         if (_maxWidth == null) {
     1855                        if (_width == null) {
    18111856                                width = DisplayController.getFramePaintAreaWidth() - getX();
    18121857                        } else {
     
    18891934
    18901935        private boolean hasFixedWidth() {
    1891                 assert (_maxWidth != null);
    1892                 if (_maxWidth == null) {
     1936                assert (_width != null);
     1937                if (_width == null) {
    18931938                        justify(false);
    18941939                }
    1895                 return _maxWidth > 0;
     1940                return _width > 0;
    18961941        }
    18971942
Note: See TracChangeset for help on using the changeset viewer.