Changeset 283


Ignore:
Timestamp:
08/27/08 14:13:27 (16 years ago)
Author:
bjn8
Message:

Popups can change border size and color

Location:
trunk/src/org/expeditee/gui
Files:
2 edited

Legend:

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

    r215 r283  
    22
    33import java.awt.BasicStroke;
     4import java.awt.Color;
    45import java.awt.Component;
    56import java.awt.Container;
     
    1112import javax.swing.JPanel;
    1213
     14import org.expeditee.items.ItemUtils;
     15
    1316/**
    1417 *
     
    2932        private static final BasicStroke DEFAULT_STROKE = new BasicStroke(2.0f);
    3033       
    31         private BasicStroke _lineStroke = DEFAULT_STROKE;
     34        private BasicStroke _borderStroke = DEFAULT_STROKE;
     35        private Color _borderColor = Color.BLACK;
    3236       
    3337        private boolean _isReadyToPaint = false;
     
    5963                super.paint(g);
    6064               
    61                 if (_lineStroke != null) {
    62                         // Draw iwidget-like border for consistancy
    63                         ((Graphics2D)g).setStroke(_lineStroke);
     65                // Draw border - if not transparent
     66                if (_borderStroke != null && _borderColor != null) {
     67                        g.setColor(_borderColor);
     68                        ((Graphics2D)g).setStroke(_borderStroke);
    6469                        g.drawRect(0, 0, getWidth(), getHeight());
    6570                }
     
    149154       
    150155        /**
     156         * Invalidates self.
    151157         *
    152158         * @param thickness
     
    156162                assert(thickness >= 0);
    157163               
    158                 if (thickness == 0) _lineStroke = null;
    159                 else _lineStroke = new BasicStroke(thickness);
     164                if (_borderStroke != null && _borderStroke.getLineWidth() == thickness)
     165                        return;
     166               
     167                boolean posInvalidate = true;
     168               
     169                if (thickness < _borderStroke.getLineWidth()) {
     170                        invalidateAppearance();
     171                        posInvalidate = false;
     172                }
     173               
     174                if (thickness == 0) _borderStroke = null;
     175                else _borderStroke = new BasicStroke(thickness);
     176               
     177                if (posInvalidate) invalidateAppearance();
    160178
    161179        }
     
    166184         */
    167185        public float getBorderThickness() {
    168                 if (_lineStroke == null) return 0.0f;
    169                 return _lineStroke.getLineWidth();
    170         }
    171        
     186                if (_borderStroke == null) return 0.0f;
     187                return _borderStroke.getLineWidth();
     188
     189        }
     190       
     191        /**
     192         * Sets the border color around the popup.
     193         * Invalidates self.
     194         *
     195         * @param c
     196         *              The new color. Null for transparent.
     197         */
     198        public void setBorderColor(Color c) {
     199               
     200                if (c == null && _borderColor != null)
     201                        invalidateAppearance();
     202               
     203                if (c != _borderColor) {
     204                        _borderColor = c;
     205                        invalidateAppearance();
     206                }
     207        }
     208       
     209        /**
     210         *
     211         * @return
     212         *              The border color for the popup. NUll if transparent
     213         */
     214        public Color getBorderColor() {
     215                return _borderColor;
     216        }
     217       
     218        /**
     219         * Invalidates the whole popup so that it must be fully repainted.
     220         */
     221        public void invalidateAppearance() {
     222               
     223                if (_borderColor != null && _borderStroke != null && _borderStroke.getLineWidth() > 0) { // border
     224                        FrameGraphics.invalidateArea(ItemUtils.expandRectangle(getBounds(),
     225                                        (int)Math.ceil(getBorderThickness()) + 1));
     226                } else { // no border
     227                        FrameGraphics.invalidateArea(getBounds());
     228                }
     229
     230        }
     231       
     232
    172233       
    173234}
  • trunk/src/org/expeditee/gui/PopupManager.java

    r277 r283  
    1717import javax.swing.SwingUtilities;
    1818
    19 import org.expeditee.items.ItemUtils;
    20 
    2119/**
    2220 * A centralized container for all custom popups in expeditee.
     
    173171                                invokersToClear.add(_popups.get(p));
    174172                               
    175                                 invalidatePopup(p);
     173                                p.invalidateAppearance();
    176174                                p.setVisible(false);
    177175                                Browser._theBrowser.getLayeredPane().remove(p);
     
    243241                }
    244242
    245                 invalidatePopup(p);
     243                p.invalidateAppearance();
    246244                p.setVisible(false);
    247245                Browser._theBrowser.getLayeredPane().remove(p);
     
    331329                // Invalidate the popup border
    332330                if (p.getBorderThickness() > 0.0f) {
    333                         invalidatePopup(p);
     331                        p.invalidateAppearance();
    334332                }
    335333        }
     
    480478                       
    481479                }
    482         }
    483        
    484        
    485         private void invalidatePopup(Popup p) {
    486                 FrameGraphics.invalidateArea(ItemUtils.expandRectangle(p.getBounds(),
    487                                 (int)Math.ceil(p.getBorderThickness())));
    488480        }
    489481       
     
    621613                                                // Invalidate the popup border
    622614                                                if (ap.popup.getBorderThickness() > 0.0f) {
    623                                                         invalidatePopup(ap.popup);
     615                                                        ap.popup.invalidateAppearance();
    624616                                                }
    625617                                        }
Note: See TracChangeset for help on using the changeset viewer.