Changeset 209


Ignore:
Timestamp:
08/11/08 10:49:38 (16 years ago)
Author:
bjn8
Message:

Tidied width and height restrictions ... now can set after construction

File:
1 edited

Legend:

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

    r208 r209  
    376376         * @param source
    377377         *            Must not be null. Neither must it's parent
     378         *           
    378379         * @param component
    379          *            Must not be null
     380         *            Must not be null.
     381         *           
     382         * @param minWidth
     383         *                      The min width restriction for the widget.
     384         *                      If negative, then there is no restriction.
     385         *
     386         * @param maxWidth
     387         *                      The max width restriction for the widget.
     388         *                      If negative, then there is no restriction.
     389         *
     390         * @param minHeight
     391         *                      The min height restriction for the widget.
     392         *                      If negative, then there is no restriction.
     393         *
     394         * @param maxHeight
     395         *                      The max height restriction for the widget.
     396         *                      If negative, then there is no restriction.
     397         *           
     398         * @throws NullPointerException
     399         *                      If source, component if null.
     400         *           
     401         * @throws IllegalArgumentException
     402         *                      If source's parent is null.
     403         *                      If maxWidth smaller than minWidth and maxWidth larger or equal to zero
     404         *                      or if maxHeight smaller than minHeight && maxHeight is larger or equal to zero
     405         *                     
    380406         */
    381407        protected InteractiveWidget(Text source, JComponent component,
     
    393419                _textRepresentation = source;
    394420               
    395                 _minWidth = minWidth;
    396 
    397                 if (maxWidth < _minWidth && maxWidth >= 0)
    398                         throw new IllegalArgumentException(
    399                                         "maxWidth smaller than the min Width");
    400                 _maxWidth = maxWidth;
    401 
    402                 _minHeight = minHeight;
    403                 if (maxHeight < _minHeight && maxHeight >= 0)
    404                         throw new IllegalArgumentException(
    405                                         "maxHeight smaller than the min Height");
    406                 _maxHeight = maxHeight;
     421                setSizeRestrictions(minWidth, maxWidth, minHeight, maxHeight); // throws IllegalArgumentException's
    407422
    408423                int x = source.getX();
     
    449464       
    450465        /**
     466         * Sets the restrictions - checks values.
     467         *
     468         * @param minWidth
     469         *                      The min width restriction for the widget.
     470         *                      If negative, then there is no restriction.
     471         *
     472         * @param maxWidth
     473         *                      The max width restriction for the widget.
     474         *                      If negative, then there is no restriction.
     475         *
     476         * @param minHeight
     477         *                      The min height restriction for the widget.
     478         *                      If negative, then there is no restriction.
     479         *
     480         * @param maxHeight
     481         *                      The max height restriction for the widget.
     482         *                      If negative, then there is no restriction.
     483         *
     484         * @throws IllegalArgumentException
     485         *                      If maxWidth smaller than minWidth and maxWidth larger or equal to zero
     486         *                      or if maxHeight smaller than minHeight && maxHeight is larger or equal to zero
     487         *
     488         */
     489        private void setSizeRestrictions(int minWidth, int maxWidth, int minHeight, int maxHeight) {
     490
     491                _minWidth = minWidth;
     492
     493                if (maxWidth < _minWidth && maxWidth >= 0)
     494                        throw new IllegalArgumentException(
     495                                        "maxWidth smaller than the min Width");
     496                _maxWidth = maxWidth;
     497
     498                _minHeight = minHeight;
     499                if (maxHeight < _minHeight && maxHeight >= 0)
     500                        throw new IllegalArgumentException(
     501                                        "maxHeight smaller than the min Height");
     502                _maxHeight = maxHeight;
     503        }
     504       
     505        /**
    451506         * This can be overrided for creating custom copies. The default implementation
    452507         * creates a new widget based on the current state of the widget (via getArgs).
     
    551606
    552607        /**
     608         * Sets both the new size as well as the new min/max widdet/height restricitons.
     609         *
     610         * @param minWidth
     611         *                      The min width restriction for the widget.
     612         *                      If negative, then there is no restriction.
     613         *
     614         * @param maxWidth
     615         *                      The max width restriction for the widget.
     616         *                      If negative, then there is no restriction.
     617         *
     618         * @param minHeight
     619         *                      The min height restriction for the widget.
     620         *                      If negative, then there is no restriction.
     621         *
     622         * @param maxHeight
     623         *                      The max height restriction for the widget.
     624         *                      If negative, then there is no restriction.
     625         *
     626         * @param newWidth
     627         *                      Clamped to new restrictions.
     628         *
     629         * @param newHeight
     630         *                      Clamped to new restrictions.
     631         *
     632         * @throws IllegalArgumentException
     633         *                      If maxWidth smaller than minWidth and maxWidth larger or equal to zero
     634         *                      or if maxHeight smaller than minHeight && maxHeight is larger or equal to zero
     635         *
     636         * @see #setSize(float, float)
     637         *
     638         */
     639        protected void setSize(int minWidth, int maxWidth, int minHeight, int maxHeight,
     640                        float newWidth, float newHeight) {
     641
     642                setSizeRestrictions(minWidth, maxWidth, minHeight, maxHeight); // throws IllegalArgumentException's
     643                setSize(newWidth, newHeight);
     644        }
     645       
     646        /**
    553647         * Clamped to current min/max width/height.
    554648         *
    555649         * @param width
     650         *                      Clamped to current restrictions.
    556651         * @param height
     652         *                      Clamped to current restrictions.
     653         *
     654         * @see #setSize(int, int, int, int, float, float)
    557655         */
    558656        public void setSize(float width, float height) {
Note: See TracChangeset for help on using the changeset viewer.