Changeset 1296 for trunk


Ignore:
Timestamp:
04/08/19 15:59:17 (5 years ago)
Author:
bln4
Message:

Added placeholders as a thing for text items. You can now provide default text for a text item. Inject the property 'Placeholder: <text>' were <text> is the placeholder text. When the placeholder is being used, the font color alpha is reduced.

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

Legend:

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

    r1227 r1296  
    315315                        _Attrib.put("Mask",                             Text.class.getMethod("getMask"),
    316316                                                                                                Text.class.getMethod("setMask", pIntO));
     317                        _Attrib.put("Placeholder",                      Text.class.getMethod("getPlaceholder"),
     318                                                                                                Text.class.getMethod("setPlaceholder", pString));
    317319                       
    318320                        // Aliases for attribute setting
  • trunk/src/org/expeditee/io/DefaultFrameReader.java

    r1242 r1296  
    161161                        _ItemTags.put('O', Text.class.getMethod("setMask", pIntO));
    162162                       
     163                        _ItemTags.put('=', Text.class.getMethod("setPlaceholder", pString));
     164                       
    163165                        // Lines and constraints are created differently
    164166                        _ItemTags.put('L', Line.class.getMethod("setStartItem", pItem));
  • trunk/src/org/expeditee/io/DefaultFrameWriter.java

    r1274 r1296  
    149149                        _ItemTags.put('^', Item.class.getMethod("getMagnetizedItemTop"));
    150150                        _ItemTags.put('_', Item.class.getMethod("getMagnetizedItemBottom"));
     151                       
     152                        _ItemTags.put('=', Text.class.getMethod("getPlaceholder"));
    151153                } catch (Exception e) {
    152154                        e.printStackTrace();
  • trunk/src/org/expeditee/items/Text.java

    r1258 r1296  
    176176        // text is broken up into lines
    177177        protected StringBuffer _text = new StringBuffer();
     178       
     179        // place holder text to use if _text is empty.
     180        protected StringBuffer _placeholder = new StringBuffer();
    178181
    179182        private List<TextLayout> _textLayouts = new LinkedList<TextLayout>();
    180183        private List<TextLayout> _maskTextLayouts = new LinkedList<TextLayout>();
     184        private List<TextLayout> _placeholderTextLayouts = new LinkedList<TextLayout>();
    181185
    182186        // The font to display this text in
     
    17531757
    17541758                // if there is no text, there is nothing to do
    1755                 if (_text == null || _text.length() == 0) {
     1759                if ((_text == null || _text.length() == 0 ) && getPlaceholder() == null) {
    17561760                        // Frame parent = getParent();
    17571761                        // if(parent != null)
     
    17671771                if (_maskTextLayouts != null) {
    17681772                        _maskTextLayouts.clear();
     1773                }
     1774                EcosystemManager.getTextLayoutManager().releaseLayouts(_placeholderTextLayouts);
     1775                if (_placeholderTextLayouts != null) {
     1776                        _placeholderTextLayouts.clear();
    17691777                }
    17701778
     
    18071815                }
    18081816
    1809                 this._textLayouts =
    1810                         EcosystemManager.getTextLayoutManager().layoutString(
    1811                                 _text.toString(),
    1812                                 getPaintFont(),
    1813                                 new Point(getX(), getY()), lines != null ? lines.toArray(new org.expeditee.core.Line[1]) : null,
    1814                                 (int) width,
    1815                                 (int) getSpacing(),
    1816                                 true,
    1817                                 getJustification() == Justification.full
    1818                         );
    1819                 if (this.getMask() != null) {
    1820                         final Stream<Character> maskStream = _text.toString().chars().mapToObj(c -> (char) this.getMask().intValue());
    1821                         final StringBuilder sb = new StringBuilder();
    1822                         maskStream.forEach(c -> sb.append(c));
    1823                         this._maskTextLayouts =
    1824                                 EcosystemManager.getTextLayoutManager().layoutString(
    1825                                         sb.toString(),
    1826                                         getPaintFont(),
    1827                                         new Point(getX(), getY()), lines != null ? lines.toArray(new org.expeditee.core.Line[1]) : null,
    1828                                         (int) width,
    1829                                         (int) getSpacing(),
    1830                                         true,
    1831                                         getJustification() == Justification.full
    1832                                 );
    1833                 }
    1834 
     1817                Font paintFont = getPaintFont();
     1818                if (this._text != null && this._text.length() > 0) {
     1819                        this._textLayouts =
     1820                                        EcosystemManager.getTextLayoutManager().layoutString(
     1821                                                _text.toString(),
     1822                                                paintFont,
     1823                                                new Point(getX(), getY()), lines != null ? lines.toArray(new org.expeditee.core.Line[1]) : null,
     1824                                                (int) width,
     1825                                                (int) getSpacing(),
     1826                                                true,
     1827                                                getJustification() == Justification.full
     1828                                        );
     1829                       
     1830                        if (this.getMask() != null) {
     1831                                final Stream<Character> maskStream = _text.toString().chars().mapToObj(c -> (char) this.getMask().intValue());
     1832                                final StringBuilder sb = new StringBuilder();
     1833                                maskStream.forEach(c -> sb.append(c));
     1834                                this._maskTextLayouts =
     1835                                        EcosystemManager.getTextLayoutManager().layoutString(
     1836                                                sb.toString(),
     1837                                                paintFont,
     1838                                                new Point(getX(), getY()), lines != null ? lines.toArray(new org.expeditee.core.Line[1]) : null,
     1839                                                (int) width,
     1840                                                (int) getSpacing(),
     1841                                                true,
     1842                                                getJustification() == Justification.full
     1843                                        );
     1844                        }
     1845                }
     1846                if (this.getPlaceholder() != null) {
     1847                        this._placeholderTextLayouts =
     1848                                        EcosystemManager.getTextLayoutManager().layoutString(
     1849                                                getPlaceholder(),
     1850                                                paintFont,
     1851                                                new Point(getX(), getY()), lines != null ? lines.toArray(new org.expeditee.core.Line[1]) : null,
     1852                                                (int) width,
     1853                                                (int) getSpacing(),
     1854                                                true,
     1855                                                getJustification() == Justification.full
     1856                                        );
     1857                }
    18351858                invalidateBounds();
    18361859        }
     
    19411964                        return;
    19421965                }
    1943 
    1944                 // if there is no text to paint, do nothing.
    1945                 if (_text == null) {
    1946                         return;
    1947                 }
     1966               
     1967                boolean hasContent = !(_text == null || (_text.length() == 0 && getMinWidth() == null));
     1968                boolean hasPlaceholderContent = getPlaceholder() != null;
     1969
    19481970
    19491971                // if the text to paint is empty string and there is no min width, do nothing.
    1950                 if ((_text.length() == 0 && getMinWidth() == null)) {
     1972                if (!hasContent && !hasPlaceholderContent) {
    19511973                        return;
    19521974                }
     
    20252047                        paintColour = new Colour(paintColour);
    20262048                        paintColour.setAlpha(Colour.FromComponent255(_alpha));
    2027 
     2049                }
     2050                if (getTextLayouts() == _placeholderTextLayouts) {
     2051                        paintColour = paintColour.clone();
     2052                        paintColour.setAlpha(Colour.FromComponent255(60));
    20282053                }
    20292054
     
    31083133                _mask = c;
    31093134        }
     3135       
     3136        public String getPlaceholder() {
     3137                if (_placeholder == null || _placeholder.length() == 0) {
     3138                        return null;
     3139                }
     3140                return _placeholder.toString();
     3141        }
     3142
     3143        public void setPlaceholder(String _placeholder) {
     3144                this._placeholder = new StringBuffer(_placeholder);
     3145        }
    31103146
    31113147        protected List<TextLayout> getTextLayouts() {
    3112                 if (this.getMask() != null) {
     3148                if (this.getPlaceholder() != null && (this._text == null || this._text.length() == 0)) {
     3149                        return _placeholderTextLayouts;
     3150                } else if (this.getMask() != null) {
    31133151                        return _maskTextLayouts;
    31143152                } else {
Note: See TracChangeset for help on using the changeset viewer.