< prev index next >

src/solaris/classes/sun/awt/X11/XListPeer.java

Print this page
rev 1571 : 8010297: Missing isLoggable() checks in logging code
Summary: Add isLoggable() checks
Reviewed-by: anthony, mchung, serb
Contributed-by: Laurent Bourges <bourges.laurent@gmail.com>


 568           case MouseEvent.MOUSE_PRESSED:
 569               mousePressed(e);
 570               break;
 571           case MouseEvent.MOUSE_RELEASED:
 572               mouseReleased(e);
 573               break;
 574           case MouseEvent.MOUSE_DRAGGED:
 575               mouseDragged(e);
 576               break;
 577         }
 578     }
 579 
 580     void handleJavaMouseWheelEvent(MouseWheelEvent e) {
 581         if (ListHelper.doWheelScroll(vsbVis ? vsb : null,
 582                                      hsbVis ? hsb : null, e)) {
 583             repaint();
 584         }
 585     }
 586 
 587     void mousePressed(MouseEvent mouseEvent) {
 588         if (log.isLoggable(Level.FINER)) log.finer(mouseEvent.toString() + ", hsb " + hsbVis + ", vsb " + vsbVis);


 589         if (isEnabled() && mouseEvent.getButton() == MouseEvent.BUTTON1) {
 590             if (inWindow(mouseEvent.getX(), mouseEvent.getY())) {
 591                 if (log.isLoggable(Level.FINE)) log.fine("Mouse press in items area");


 592                 active = WINDOW;
 593                 int i = y2index(mouseEvent.getY());
 594                 if (i >= 0) {
 595                     if (multipleSelections) {
 596                         if (isSelected(i)) {
 597                             // See 6243382 for more information
 598                             deselectItem(i);
 599                             eventIndex = i;
 600                             eventType = ItemEvent.DESELECTED;
 601                         }
 602                         else {
 603                             selectItem(i);
 604                             eventIndex = i;
 605                             eventType = ItemEvent.SELECTED;
 606                         }
 607                     }
 608                     // Backward-compatible bug: even if a single-select
 609                     // item is already selected, we send an ITEM_STATE_CHANGED/
 610                     // SELECTED event.  Engineer's Toolbox appears to rely on
 611                     // this.
 612                     //else if (!isSelected(i)) {
 613                     else {
 614                         selectItem(i);
 615                         eventIndex = i;
 616                         eventType = ItemEvent.SELECTED;
 617                     }
 618                     // Restoring Windows behaviour
 619                     // We should update focus index after "mouse pressed" event
 620                     setFocusIndex(i);
 621                     repaint(PAINT_FOCUS);
 622                 } else {
 623                     // 6426186: reset variable to prevent action event
 624                     // if user clicks on unoccupied area of list
 625                     currentIndex = -1;
 626                 }
 627             } else if (inVerticalScrollbar(mouseEvent.getX(), mouseEvent.getY())) {
 628                 if (log.isLoggable(Level.FINE)) log.fine("Mouse press in vertical scrollbar");


 629                 active = VERSCROLLBAR;
 630                 vsb.handleMouseEvent(mouseEvent.getID(),
 631                                      mouseEvent.getModifiers(),
 632                                      mouseEvent.getX() - (width - SCROLLBAR_WIDTH),
 633                                      mouseEvent.getY());
 634             } else if (inHorizontalScrollbar(mouseEvent.getX(), mouseEvent.getY())) {
 635                 if (log.isLoggable(Level.FINE)) log.fine("Mouse press in horizontal scrollbar");


 636                 active = HORSCROLLBAR;
 637                 hsb.handleMouseEvent(mouseEvent.getID(),
 638                                      mouseEvent.getModifiers(),
 639                                      mouseEvent.getX(),
 640                                      mouseEvent.getY() - (height - SCROLLBAR_WIDTH));
 641 
 642             }
 643             isMousePressed = true;
 644         }
 645     }
 646     void mouseReleased(MouseEvent mouseEvent) {
 647         if (isEnabled() && mouseEvent.getButton() == MouseEvent.BUTTON1) {
 648             //winReleaseCursorFocus();
 649             int clickCount = mouseEvent.getClickCount();
 650             if (active == VERSCROLLBAR) {
 651                 vsb.handleMouseEvent(mouseEvent.getID(),
 652                                      mouseEvent.getModifiers(),
 653                                      mouseEvent.getX()-(width-SCROLLBAR_WIDTH),
 654                                      mouseEvent.getY());
 655             } else if(active == HORSCROLLBAR) {


 798         }
 799 
 800         if (mouseDraggedOutHorizontally){
 801             mouseDraggedOutHorizontally = false;
 802             hsb.stopScrollingInstance();
 803         }
 804     }
 805 
 806     void handleJavaKeyEvent(KeyEvent e) {
 807         switch(e.getID()) {
 808           case KeyEvent.KEY_PRESSED:
 809               if (!isMousePressed){
 810                   keyPressed(e);
 811               }
 812               break;
 813         }
 814     }
 815 
 816     void keyPressed(KeyEvent e) {
 817         int keyCode = e.getKeyCode();
 818         if (log.isLoggable(Level.FINE)) log.fine(e.toString());


 819         switch(keyCode) {
 820           case KeyEvent.VK_UP:
 821           case KeyEvent.VK_KP_UP: // TODO: I assume we also want this, too
 822               if (getFocusIndex() > 0) {
 823                   setFocusIndex(getFocusIndex()-1);
 824                   repaint(PAINT_HIDEFOCUS);
 825                   // If single-select, select the item
 826                   if (!multipleSelections) {
 827                       selectItem(getFocusIndex());
 828                       postEvent(new ItemEvent((List)target,
 829                                               ItemEvent.ITEM_STATE_CHANGED,
 830                                               Integer.valueOf(getFocusIndex()),
 831                                               ItemEvent.SELECTED));
 832                   }
 833                   if (isItemHidden(getFocusIndex())) {
 834                       makeVisible(getFocusIndex());
 835                   }
 836                   else {
 837                       repaint(PAINT_FOCUS);
 838                   }


 983               // So for now in XAWT, I'm going to simply go by what the List docs
 984               // say: "AWT also generates an action event when the user presses
 985               // the return key while an item in the list is selected."
 986               if (selected.length > 0) {
 987                   postEvent(new ActionEvent((List)target,
 988                                             ActionEvent.ACTION_PERFORMED,
 989                                             (String)items.elementAt(getFocusIndex()),
 990                                             e.getWhen(),
 991                                             e.getModifiers()));  // ActionEvent doesn't have
 992                   // extended modifiers.
 993               }
 994               break;
 995         }
 996     }
 997 
 998     /**
 999      * return value from the scrollbar
1000      */
1001     public void notifyValue(XScrollbar obj, int type, int v, boolean isAdjusting) {
1002 
1003         if (log.isLoggable(Level.FINE)) log.fine("Notify value changed on " + obj + " to " + v);


1004         int value = obj.getValue();
1005         if (obj == vsb) {
1006             scrollVertical(v - value);
1007 
1008             // See 6243382 for more information
1009             int oldSel = eventIndex;
1010             int newSel = eventIndex+v-value;
1011             if (mouseDraggedOutVertically && !isSelected(newSel)){
1012                 selectItem(newSel);
1013                 eventIndex = newSel;
1014                 repaint(oldSel, eventIndex, PAINT_ITEMS);
1015                 // Scrolling select() should also set the focus index
1016                 // Otherwise, the updating of the 'focusIndex' variable will be incorrect
1017                 // if user drag mouse out of the area of the list
1018                 setFocusIndex(newSel);
1019                 repaint(PAINT_FOCUS);
1020             }
1021 
1022         } else if ((XHorizontalScrollbar)obj == hsb) {
1023             scrollHorizontal(v - value);


1066 
1067         // Why we set this variable to -1 in spite of the fact that selected[] is changed in other way?
1068         // It's not clear how to reproduce incorrect behaviour based on this assignment
1069         // since before using this variable (mouseReleased) we certainly update it to correct value
1070         // So we don't modify this behaviour now
1071         currentIndex = -1;
1072 
1073         if (i == -1) {
1074             items.addElement(item);
1075             i = 0;              // fix the math for the paintItems test
1076             addedIndex = items.size() - 1;
1077         } else {
1078             items.insertElementAt(item, i);
1079             addedIndex = i;
1080             for (int j = 0 ; j < selected.length ; j++) {
1081                 if (selected[j] >= i) {
1082                     selected[j] += 1;
1083                 }
1084             }
1085         }
1086         if (log.isLoggable(Level.FINER)) log.finer("Adding item '" + item + "' to " + addedIndex);


1087 
1088         // Update maxLength
1089         boolean repaintItems = !isItemHidden(addedIndex);
1090         maxLength = Math.max(maxLength, getItemWidth(addedIndex));
1091         layout();
1092 
1093         int options = 0;
1094         if (vsbVis != vsbWasVis || hsbVis != hsbWasVis) {
1095             // Scrollbars are being added or removed, so we must repaint all
1096             options = PAINT_ALL;
1097         }
1098         else {
1099             options = (repaintItems ? (PAINT_ITEMS):0)
1100                 | ((maxLength != oldMaxLength || (hsbWasVis ^ hsbVis))?(PAINT_HSCROLL):0)
1101                 | ((vsb.needsRepaint())?(PAINT_VSCROLL):0);
1102 
1103         }
1104         if (log.isLoggable(Level.FINEST)) log.finest("Last visible: " + getLastVisibleItem() +

1105                                                      ", hsb changed : " + (hsbWasVis ^ hsbVis) + ", items changed " + repaintItems);

1106         repaint(addedIndex, getLastVisibleItem(), options);
1107     }
1108 
1109     /**
1110      * delete items starting with s (start position) to e (end position) including s and e
1111      * if s < 0 then s = 0
1112      * if e >= items.size() then e = items.size() - 1
1113      */
1114     public void delItems(int s, int e) {
1115         // save the current state of the scrollbars
1116         boolean hsbWasVisible = hsbVis;
1117         boolean vsbWasVisible = vsbVis;
1118         int oldLastDisplayed = lastItemDisplayed();
1119 
1120         if (log.isLoggable(Level.FINE)) log.fine("Deleting from " + s + " to " + e);


1121 
1122         if (log.isLoggable(Level.FINEST)) log.finest("Last displayed item: " + oldLastDisplayed + ", items in window " + itemsInWindow() +

1123                                                      ", size " + items.size());

1124 
1125         if (items.size() == 0) {
1126             return;
1127         }
1128 
1129         // if user passed in flipped args, reverse them
1130         if (s > e) {
1131             int tmp = s;
1132             s = e;
1133             e = tmp;
1134         }
1135 
1136         // check for starting point less than zero
1137         if (s < 0) {
1138             s = 0;
1139         }
1140 
1141         // check for end point greater than the size of the list
1142         if (e >= items.size()) {
1143             e = items.size() - 1;


1170         for (int i = 0 ; i < selected.length ; i++) {
1171             if (selected[i] > e) {
1172                 selected[i] -= diff;
1173             }
1174         }
1175 
1176         int options = PAINT_VSCROLL;
1177         // focusedIndex updating according to native (Window, Motif) behaviour
1178         if (getFocusIndex() > e) {
1179             setFocusIndex(getFocusIndex() - (e - s + 1));
1180             options |= PAINT_FOCUS;
1181         } else if (getFocusIndex() >= s && getFocusIndex() <= e) {
1182             // Fixed 6299858: PIT. Focused border not shown on List if selected item is removed, XToolkit
1183             // We should set focus to new first item if the current first item was removed
1184             // except if the list is empty
1185             int focusBound = (items.size() > 0) ? 0 : -1;
1186             setFocusIndex(Math.max(s-1, focusBound));
1187             options |= PAINT_FOCUS;
1188         }
1189 
1190         if (log.isLoggable(Level.FINEST)) log.finest("Multiple selections: " + multipleSelections);


1191 
1192         // update vsb.val
1193         if (vsb.getValue() >= s) {
1194             if (vsb.getValue() <= e) {
1195                 vsb.setValue(e+1 - diff);
1196             } else {
1197                 vsb.setValue(vsb.getValue() - diff);
1198             }
1199         }
1200 
1201         int oldMaxLength = maxLength;
1202         maxLength = maxLength();
1203         if (maxLength != oldMaxLength) {
1204             // Width of the items changed affecting the range of
1205             // horizontal scrollbar
1206             options |= PAINT_HSCROLL;
1207         }
1208         layout();
1209         repaintNeeded |= (vsbWasVisible ^ vsbVis) || (hsbWasVisible ^ hsbVis); // If scrollbars visibility changed
1210         if (repaintNeeded) {


1423      * presence of vertical scrollbar)
1424      */
1425     int getListWidth() {
1426         return vsbVis ? width - SCROLLBAR_AREA : width;
1427     }
1428 
1429     /**
1430      * returns number of  items actually displayed in the List
1431      */
1432     int itemsDisplayed() {
1433 
1434         return (Math.min(items.size()-vsb.getValue(), itemsInWindow()));
1435 
1436     }
1437 
1438     /**
1439      * scrollVertical
1440      * y is the number of items to scroll
1441      */
1442     void scrollVertical(int y) {
1443         if (log.isLoggable(Level.FINE)) log.fine("Scrolling vertically by " + y);


1444         int itemsInWin = itemsInWindow();
1445         int h = getItemHeight();
1446         int pixelsToScroll = y * h;
1447 
1448         if (vsb.getValue() < -y) {
1449             y = -vsb.getValue();
1450         }
1451         vsb.setValue(vsb.getValue() + y);
1452 
1453         if (y > 0) {
1454             // Fixed 6308295: XAWTduplicate list item is displayed
1455             // Window resizing leads to the buffer flushing
1456             // That's why the repainting with the PAINT_HIDEFOCUS option is the repainting with PAINT_ALL option
1457             // So we should do only the repainting instead of the copy area
1458             if (y < itemsInWin && painter.isBuffer()) {
1459                 if (log.isLoggable(Level.FINEST)) {
1460                     log.finest("Copying " + "" + MARGIN + "," + ( MARGIN + pixelsToScroll)
1461                                + "," +  (width - SCROLLBAR_AREA) + "," +  (h * (itemsInWin - y)-1) +
1462                                "," + 0 + "," + (-pixelsToScroll));
1463                 }


1469         } else if (y < 0 && painter.isBuffer()) {
1470             if (y + itemsInWindow() > 0) {
1471                 if (log.isLoggable(Level.FINEST)) {
1472                     log.finest("Copying " + MARGIN + "," + MARGIN +"," +
1473                                (width - SCROLLBAR_AREA) + "," +
1474                                (h * (itemsInWin + y)) + "," + "0" +"," +(-pixelsToScroll));
1475                 }
1476                 repaint(PAINT_HIDEFOCUS);
1477                 painter.copyArea(MARGIN, MARGIN, width - SCROLLBAR_AREA, h * (itemsInWin + y), 0, -pixelsToScroll);
1478             }
1479             int e = Math.min(getLastVisibleItem(), vsb.getValue() + -y);
1480             repaint(vsb.getValue(), e, PAINT_ITEMS | PAINT_VSCROLL | PAINT_FOCUS);
1481         }
1482     }
1483 
1484     /**
1485      * scrollHorizontal
1486      * x is the number of pixels to scroll
1487      */
1488     void scrollHorizontal(int x) {
1489         if (log.isLoggable(Level.FINE)) log.fine("Scrolling horizontally by " + y);


1490         int w = getListWidth();
1491         w -= ((2 * SPACE) + (2 * MARGIN));
1492         int h = height - (SCROLLBAR_AREA + (2 * MARGIN));
1493         hsb.setValue(hsb.getValue() + x);
1494 
1495         if (x < 0 && painter.isBuffer()) {
1496             painter.copyArea(MARGIN + SPACE, MARGIN, w + x, h, -x, 0);
1497         } else if (x > 0 && painter.isBuffer()) {
1498             painter.copyArea(MARGIN + SPACE + x, MARGIN, w - x, h, -x, 0);
1499         }
1500         repaint(vsb.getValue(), lastItemDisplayed(), PAINT_ITEMS | PAINT_HSCROLL);
1501     }
1502 
1503     /**
1504      * return the index
1505      */
1506     int y2index(int y) {
1507         if (!validY(y)) {
1508             return -1;
1509         }


1704                 return SystemColor.text;
1705             }
1706         }
1707 
1708         private Color getDisabledColor() {
1709             Color backgroundColor = getListBackground();
1710             Color foregroundColor = getListForeground();
1711             return (backgroundColor.equals(Color.BLACK)) ? foregroundColor.darker() : backgroundColor.darker();
1712         }
1713 
1714         private boolean createBuffer() {
1715             VolatileImage localBuffer = null;
1716             XToolkit.awtLock();
1717             try {
1718                 localBuffer = buffer;
1719             } finally {
1720                 XToolkit.awtUnlock();
1721             }
1722 
1723             if (localBuffer == null) {
1724                 if (log.isLoggable(Level.FINE)) log.fine("Creating buffer " + width + "x" + height);


1725                 // use GraphicsConfig.cCVI() instead of Component.cVI(),
1726                 // because the latter may cause a deadlock with the tree lock
1727                 localBuffer =
1728                     graphicsConfig.createCompatibleVolatileImage(width+1,
1729                                                                  height+1);
1730             }
1731             XToolkit.awtLock();
1732             try {
1733                 if (buffer == null) {
1734                     buffer = localBuffer;
1735                     return true;
1736                 }
1737             } finally {
1738                 XToolkit.awtUnlock();
1739             }
1740             return false;
1741         }
1742 
1743         public void invalidate() {
1744             XToolkit.awtLock();
1745             try {
1746                 if (buffer != null) {
1747                     buffer.flush();
1748                 }
1749                 buffer = null;
1750             } finally {
1751                 XToolkit.awtUnlock();
1752             }
1753         }
1754 
1755         private void paint(Graphics listG, int firstItem, int lastItem, int options) {
1756             if (log.isLoggable(Level.FINER)) log.finer("Repaint from " + firstItem + " to " + lastItem + " options " + options);


1757             if (firstItem > lastItem) {
1758                 int t = lastItem;
1759                 lastItem = firstItem;
1760                 firstItem = t;
1761             }
1762             if (firstItem < 0) {
1763                 firstItem = 0;
1764             }
1765             colors = getGUIcolors();
1766             VolatileImage localBuffer = null;
1767             do {
1768                 XToolkit.awtLock();
1769                 try {
1770                     if (createBuffer()) {
1771                         // First time created buffer should be painted over at full.
1772                         options = PAINT_ALL;
1773                     }
1774                     localBuffer = buffer;
1775                 } finally {
1776                     XToolkit.awtUnlock();


1800                     }
1801                     if ((options & PAINT_VSCROLL) != 0 && vsbVis) {
1802                         g.setClip(getVScrollBarRec());
1803                         paintVerScrollbar(g, true);
1804                     }
1805                     if ((options & PAINT_HSCROLL) != 0 && hsbVis) {
1806                         g.setClip(getHScrollBarRec());
1807                         paintHorScrollbar(g, true);
1808                     }
1809                     if ((options & (PAINT_FOCUS|PAINT_HIDEFOCUS)) != 0) {
1810                         paintFocus(g, options);
1811                     }
1812                 } finally {
1813                     g.dispose();
1814                 }
1815             } while (localBuffer.contentsLost());
1816             listG.drawImage(localBuffer, 0, 0, null);
1817         }
1818 
1819         private void paintItems(Graphics g, int firstItem, int lastItem, int options) {
1820             if (log.isLoggable(Level.FINER)) log.finer("Painting items from " + firstItem + " to " + lastItem + ", focused " + focusIndex + ", first " + getFirstVisibleItem() + ", last " + getLastVisibleItem());




1821 
1822             firstItem = Math.max(getFirstVisibleItem(), firstItem);
1823             if (firstItem > lastItem) {
1824                 int t = lastItem;
1825                 lastItem = firstItem;
1826                 firstItem = t;
1827             }
1828             firstItem = Math.max(getFirstVisibleItem(), firstItem);
1829             lastItem = Math.min(lastItem, items.size()-1);
1830 
1831             if (log.isLoggable(Level.FINER)) log.finer("Actually painting items from " + firstItem + " to " + lastItem +

1832                                                        ", items in window " + itemsInWindow());

1833             for (int i = firstItem; i <= lastItem; i++) {
1834                 paintItem(g, i);
1835             }
1836         }
1837 
1838         private void paintItem(Graphics g, int index) {
1839             if (log.isLoggable(Level.FINEST)) log.finest("Painting item " + index);


1840             // 4895367 - only paint items which are visible
1841             if (!isItemHidden(index)) {
1842                 Shape clip = g.getClip();
1843                 int w = getItemWidth();
1844                 int h = getItemHeight();
1845                 int y = getItemY(index);
1846                 int x = getItemX();
1847                 if (log.isLoggable(Level.FINEST)) log.finest("Setting clip " + new Rectangle(x, y, w - (SPACE*2), h-(SPACE*2)));


1848                 g.setClip(x, y, w - (SPACE*2), h-(SPACE*2));
1849 
1850                 // Always paint the background so that focus is unpainted in
1851                 // multiselect mode
1852                 if (isSelected(index)) {
1853                     if (log.isLoggable(Level.FINEST)) log.finest("Painted item is selected");


1854                     g.setColor(getListForeground());
1855                 } else {
1856                     g.setColor(getListBackground());
1857                 }
1858                 if (log.isLoggable(Level.FINEST)) log.finest("Filling " + new Rectangle(x, y, w, h));


1859                 g.fillRect(x, y, w, h);
1860 
1861                 if (index <= getLastVisibleItem() && index < items.size()) {
1862                     if (!isEnabled()){
1863                         g.setColor(getDisabledColor());
1864                     } else if (isSelected(index)) {
1865                         g.setColor(getListBackground());
1866                     } else {
1867                         g.setColor(getListForeground());
1868                     }
1869                     String str = (String)items.elementAt(index);
1870                     g.drawString(str, x - hsb.getValue(), y + fontAscent);
1871                 } else {
1872                     // Clear the remaining area around the item - focus area and the rest of border
1873                     g.setClip(x, y, listWidth, h);
1874                     g.setColor(getListBackground());
1875                     g.fillRect(x, y, listWidth, h);
1876                 }
1877                 g.setClip(clip);
1878             }
1879         }
1880 
1881         void paintScrollBar(XScrollbar scr, Graphics g, int x, int y, int width, int height, boolean paintAll) {
1882             if (log.isLoggable(Level.FINEST)) log.finest("Painting scrollbar " + scr + " width " +

1883                                                          width + " height " + height + ", paintAll " + paintAll);

1884             g.translate(x, y);
1885             scr.paint(g, getSystemColors(), paintAll);
1886             g.translate(-x, -y);
1887         }
1888 
1889         /**
1890          * Paint the horizontal scrollbar to the screen
1891          *
1892          * @param g the graphics context to draw into
1893          * @param colors the colors used to draw the scrollbar
1894          * @param paintAll paint the whole scrollbar if true, just the thumb if false
1895          */
1896         void paintHorScrollbar(Graphics g, boolean paintAll) {
1897             int w = getListWidth();
1898             paintScrollBar(hsb, g, 0, height - (SCROLLBAR_WIDTH), w, SCROLLBAR_WIDTH, paintAll);
1899         }
1900 
1901         /**
1902          * Paint the vertical scrollbar to the screen
1903          *
1904          * @param g the graphics context to draw into
1905          * @param colors the colors used to draw the scrollbar
1906          * @param paintAll paint the whole scrollbar if true, just the thumb if false
1907          */
1908         void paintVerScrollbar(Graphics g, boolean paintAll) {
1909             int h = height - (hsbVis ? (SCROLLBAR_AREA-2) : 0);
1910             paintScrollBar(vsb, g, width - SCROLLBAR_WIDTH, 0, SCROLLBAR_WIDTH - 2, h, paintAll);
1911         }
1912 
1913 
1914         private Rectangle prevFocusRect;
1915         private void paintFocus(Graphics g, int options) {
1916             boolean paintFocus = (options & PAINT_FOCUS) != 0;
1917             if (paintFocus && !hasFocus()) {
1918                 paintFocus = false;
1919             }
1920             if (log.isLoggable(Level.FINE)) log.fine("Painting focus, focus index " + getFocusIndex() + ", focus is " +

1921                                                      (isItemHidden(getFocusIndex())?("invisible"):("visible")) + ", paint focus is " + paintFocus);

1922             Shape clip = g.getClip();
1923             g.setClip(0, 0, listWidth, listHeight);
1924             if (log.isLoggable(Level.FINEST)) log.finest("Setting focus clip " + new Rectangle(0, 0, listWidth, listHeight));


1925             Rectangle rect = getFocusRect();
1926             if (prevFocusRect != null) {
1927                 // Erase focus rect
1928                 if (log.isLoggable(Level.FINEST)) log.finest("Erasing previous focus rect " + prevFocusRect);


1929                 g.setColor(getListBackground());
1930                 g.drawRect(prevFocusRect.x, prevFocusRect.y, prevFocusRect.width, prevFocusRect.height);
1931                 prevFocusRect = null;
1932             }
1933             if (paintFocus) {
1934                 // Paint new
1935                 if (log.isLoggable(Level.FINEST)) log.finest("Painting focus rect " + rect);


1936                 g.setColor(getListForeground());  // Focus color is always black on Linux
1937                 g.drawRect(rect.x, rect.y, rect.width, rect.height);
1938                 prevFocusRect = rect;
1939             }
1940             g.setClip(clip);
1941         }
1942 
1943         public void copyArea(int x, int y, int width, int height, int dx, int dy) {
1944             if (log.isLoggable(Level.FINER)) log.finer("Copying area " + x + ", " + y + " " + width +

1945                                                        "x" + height + ", (" + dx + "," + dy + ")");

1946             VolatileImage localBuffer = null;
1947             do {
1948                 XToolkit.awtLock();
1949                 try {
1950                     if (createBuffer()) {
1951                         // Newly created buffer should be painted over at full
1952                         repaint(PAINT_ALL);
1953                         return;
1954                     }
1955                     localBuffer = buffer;
1956                 } finally {
1957                     XToolkit.awtUnlock();
1958                 }
1959                 switch (localBuffer.validate(getGraphicsConfiguration())) {
1960                   case VolatileImage.IMAGE_INCOMPATIBLE:
1961                       invalidate();
1962                   case VolatileImage.IMAGE_RESTORED:
1963                       // Since we've lost the content we can't just scroll - we should paint again
1964                       repaint(PAINT_ALL);
1965                       return;




 568           case MouseEvent.MOUSE_PRESSED:
 569               mousePressed(e);
 570               break;
 571           case MouseEvent.MOUSE_RELEASED:
 572               mouseReleased(e);
 573               break;
 574           case MouseEvent.MOUSE_DRAGGED:
 575               mouseDragged(e);
 576               break;
 577         }
 578     }
 579 
 580     void handleJavaMouseWheelEvent(MouseWheelEvent e) {
 581         if (ListHelper.doWheelScroll(vsbVis ? vsb : null,
 582                                      hsbVis ? hsb : null, e)) {
 583             repaint();
 584         }
 585     }
 586 
 587     void mousePressed(MouseEvent mouseEvent) {
 588         if (log.isLoggable(Level.FINER)) {
 589             log.finer(mouseEvent.toString() + ", hsb " + hsbVis + ", vsb " + vsbVis);
 590         }
 591         if (isEnabled() && mouseEvent.getButton() == MouseEvent.BUTTON1) {
 592             if (inWindow(mouseEvent.getX(), mouseEvent.getY())) {
 593                 if (log.isLoggable(Level.FINE)) {
 594                     log.fine("Mouse press in items area");
 595                 }
 596                 active = WINDOW;
 597                 int i = y2index(mouseEvent.getY());
 598                 if (i >= 0) {
 599                     if (multipleSelections) {
 600                         if (isSelected(i)) {
 601                             // See 6243382 for more information
 602                             deselectItem(i);
 603                             eventIndex = i;
 604                             eventType = ItemEvent.DESELECTED;
 605                         }
 606                         else {
 607                             selectItem(i);
 608                             eventIndex = i;
 609                             eventType = ItemEvent.SELECTED;
 610                         }
 611                     }
 612                     // Backward-compatible bug: even if a single-select
 613                     // item is already selected, we send an ITEM_STATE_CHANGED/
 614                     // SELECTED event.  Engineer's Toolbox appears to rely on
 615                     // this.
 616                     //else if (!isSelected(i)) {
 617                     else {
 618                         selectItem(i);
 619                         eventIndex = i;
 620                         eventType = ItemEvent.SELECTED;
 621                     }
 622                     // Restoring Windows behaviour
 623                     // We should update focus index after "mouse pressed" event
 624                     setFocusIndex(i);
 625                     repaint(PAINT_FOCUS);
 626                 } else {
 627                     // 6426186: reset variable to prevent action event
 628                     // if user clicks on unoccupied area of list
 629                     currentIndex = -1;
 630                 }
 631             } else if (inVerticalScrollbar(mouseEvent.getX(), mouseEvent.getY())) {
 632                 if (log.isLoggable(Level.FINE)) {
 633                     log.fine("Mouse press in vertical scrollbar");
 634                 }
 635                 active = VERSCROLLBAR;
 636                 vsb.handleMouseEvent(mouseEvent.getID(),
 637                                      mouseEvent.getModifiers(),
 638                                      mouseEvent.getX() - (width - SCROLLBAR_WIDTH),
 639                                      mouseEvent.getY());
 640             } else if (inHorizontalScrollbar(mouseEvent.getX(), mouseEvent.getY())) {
 641                 if (log.isLoggable(Level.FINE)) {
 642                     log.fine("Mouse press in horizontal scrollbar");
 643                 }
 644                 active = HORSCROLLBAR;
 645                 hsb.handleMouseEvent(mouseEvent.getID(),
 646                                      mouseEvent.getModifiers(),
 647                                      mouseEvent.getX(),
 648                                      mouseEvent.getY() - (height - SCROLLBAR_WIDTH));
 649 
 650             }
 651             isMousePressed = true;
 652         }
 653     }
 654     void mouseReleased(MouseEvent mouseEvent) {
 655         if (isEnabled() && mouseEvent.getButton() == MouseEvent.BUTTON1) {
 656             //winReleaseCursorFocus();
 657             int clickCount = mouseEvent.getClickCount();
 658             if (active == VERSCROLLBAR) {
 659                 vsb.handleMouseEvent(mouseEvent.getID(),
 660                                      mouseEvent.getModifiers(),
 661                                      mouseEvent.getX()-(width-SCROLLBAR_WIDTH),
 662                                      mouseEvent.getY());
 663             } else if(active == HORSCROLLBAR) {


 806         }
 807 
 808         if (mouseDraggedOutHorizontally){
 809             mouseDraggedOutHorizontally = false;
 810             hsb.stopScrollingInstance();
 811         }
 812     }
 813 
 814     void handleJavaKeyEvent(KeyEvent e) {
 815         switch(e.getID()) {
 816           case KeyEvent.KEY_PRESSED:
 817               if (!isMousePressed){
 818                   keyPressed(e);
 819               }
 820               break;
 821         }
 822     }
 823 
 824     void keyPressed(KeyEvent e) {
 825         int keyCode = e.getKeyCode();
 826         if (log.isLoggable(Level.FINE)) {
 827             log.fine(e.toString());
 828         }
 829         switch(keyCode) {
 830           case KeyEvent.VK_UP:
 831           case KeyEvent.VK_KP_UP: // TODO: I assume we also want this, too
 832               if (getFocusIndex() > 0) {
 833                   setFocusIndex(getFocusIndex()-1);
 834                   repaint(PAINT_HIDEFOCUS);
 835                   // If single-select, select the item
 836                   if (!multipleSelections) {
 837                       selectItem(getFocusIndex());
 838                       postEvent(new ItemEvent((List)target,
 839                                               ItemEvent.ITEM_STATE_CHANGED,
 840                                               Integer.valueOf(getFocusIndex()),
 841                                               ItemEvent.SELECTED));
 842                   }
 843                   if (isItemHidden(getFocusIndex())) {
 844                       makeVisible(getFocusIndex());
 845                   }
 846                   else {
 847                       repaint(PAINT_FOCUS);
 848                   }


 993               // So for now in XAWT, I'm going to simply go by what the List docs
 994               // say: "AWT also generates an action event when the user presses
 995               // the return key while an item in the list is selected."
 996               if (selected.length > 0) {
 997                   postEvent(new ActionEvent((List)target,
 998                                             ActionEvent.ACTION_PERFORMED,
 999                                             (String)items.elementAt(getFocusIndex()),
1000                                             e.getWhen(),
1001                                             e.getModifiers()));  // ActionEvent doesn't have
1002                   // extended modifiers.
1003               }
1004               break;
1005         }
1006     }
1007 
1008     /**
1009      * return value from the scrollbar
1010      */
1011     public void notifyValue(XScrollbar obj, int type, int v, boolean isAdjusting) {
1012 
1013         if (log.isLoggable(Level.FINE)) {
1014             log.fine("Notify value changed on " + obj + " to " + v);
1015         }
1016         int value = obj.getValue();
1017         if (obj == vsb) {
1018             scrollVertical(v - value);
1019 
1020             // See 6243382 for more information
1021             int oldSel = eventIndex;
1022             int newSel = eventIndex+v-value;
1023             if (mouseDraggedOutVertically && !isSelected(newSel)){
1024                 selectItem(newSel);
1025                 eventIndex = newSel;
1026                 repaint(oldSel, eventIndex, PAINT_ITEMS);
1027                 // Scrolling select() should also set the focus index
1028                 // Otherwise, the updating of the 'focusIndex' variable will be incorrect
1029                 // if user drag mouse out of the area of the list
1030                 setFocusIndex(newSel);
1031                 repaint(PAINT_FOCUS);
1032             }
1033 
1034         } else if ((XHorizontalScrollbar)obj == hsb) {
1035             scrollHorizontal(v - value);


1078 
1079         // Why we set this variable to -1 in spite of the fact that selected[] is changed in other way?
1080         // It's not clear how to reproduce incorrect behaviour based on this assignment
1081         // since before using this variable (mouseReleased) we certainly update it to correct value
1082         // So we don't modify this behaviour now
1083         currentIndex = -1;
1084 
1085         if (i == -1) {
1086             items.addElement(item);
1087             i = 0;              // fix the math for the paintItems test
1088             addedIndex = items.size() - 1;
1089         } else {
1090             items.insertElementAt(item, i);
1091             addedIndex = i;
1092             for (int j = 0 ; j < selected.length ; j++) {
1093                 if (selected[j] >= i) {
1094                     selected[j] += 1;
1095                 }
1096             }
1097         }
1098         if (log.isLoggable(Level.FINER)) {
1099             log.finer("Adding item '" + item + "' to " + addedIndex);
1100         }
1101 
1102         // Update maxLength
1103         boolean repaintItems = !isItemHidden(addedIndex);
1104         maxLength = Math.max(maxLength, getItemWidth(addedIndex));
1105         layout();
1106 
1107         int options = 0;
1108         if (vsbVis != vsbWasVis || hsbVis != hsbWasVis) {
1109             // Scrollbars are being added or removed, so we must repaint all
1110             options = PAINT_ALL;
1111         }
1112         else {
1113             options = (repaintItems ? (PAINT_ITEMS):0)
1114                 | ((maxLength != oldMaxLength || (hsbWasVis ^ hsbVis))?(PAINT_HSCROLL):0)
1115                 | ((vsb.needsRepaint())?(PAINT_VSCROLL):0);
1116 
1117         }
1118         if (log.isLoggable(Level.FINEST)) {
1119             log.finest("Last visible: " + getLastVisibleItem() +
1120                        ", hsb changed : " + (hsbWasVis ^ hsbVis) + ", items changed " + repaintItems);
1121         }
1122         repaint(addedIndex, getLastVisibleItem(), options);
1123     }
1124 
1125     /**
1126      * delete items starting with s (start position) to e (end position) including s and e
1127      * if s < 0 then s = 0
1128      * if e >= items.size() then e = items.size() - 1
1129      */
1130     public void delItems(int s, int e) {
1131         // save the current state of the scrollbars
1132         boolean hsbWasVisible = hsbVis;
1133         boolean vsbWasVisible = vsbVis;
1134         int oldLastDisplayed = lastItemDisplayed();
1135 
1136         if (log.isLoggable(Level.FINE)) {
1137             log.fine("Deleting from " + s + " to " + e);
1138         }
1139 
1140         if (log.isLoggable(Level.FINEST)) {
1141             log.finest("Last displayed item: " + oldLastDisplayed + ", items in window " + itemsInWindow() +
1142                        ", size " + items.size());
1143         }
1144 
1145         if (items.size() == 0) {
1146             return;
1147         }
1148 
1149         // if user passed in flipped args, reverse them
1150         if (s > e) {
1151             int tmp = s;
1152             s = e;
1153             e = tmp;
1154         }
1155 
1156         // check for starting point less than zero
1157         if (s < 0) {
1158             s = 0;
1159         }
1160 
1161         // check for end point greater than the size of the list
1162         if (e >= items.size()) {
1163             e = items.size() - 1;


1190         for (int i = 0 ; i < selected.length ; i++) {
1191             if (selected[i] > e) {
1192                 selected[i] -= diff;
1193             }
1194         }
1195 
1196         int options = PAINT_VSCROLL;
1197         // focusedIndex updating according to native (Window, Motif) behaviour
1198         if (getFocusIndex() > e) {
1199             setFocusIndex(getFocusIndex() - (e - s + 1));
1200             options |= PAINT_FOCUS;
1201         } else if (getFocusIndex() >= s && getFocusIndex() <= e) {
1202             // Fixed 6299858: PIT. Focused border not shown on List if selected item is removed, XToolkit
1203             // We should set focus to new first item if the current first item was removed
1204             // except if the list is empty
1205             int focusBound = (items.size() > 0) ? 0 : -1;
1206             setFocusIndex(Math.max(s-1, focusBound));
1207             options |= PAINT_FOCUS;
1208         }
1209 
1210         if (log.isLoggable(Level.FINEST)) {
1211             log.finest("Multiple selections: " + multipleSelections);
1212         }
1213 
1214         // update vsb.val
1215         if (vsb.getValue() >= s) {
1216             if (vsb.getValue() <= e) {
1217                 vsb.setValue(e+1 - diff);
1218             } else {
1219                 vsb.setValue(vsb.getValue() - diff);
1220             }
1221         }
1222 
1223         int oldMaxLength = maxLength;
1224         maxLength = maxLength();
1225         if (maxLength != oldMaxLength) {
1226             // Width of the items changed affecting the range of
1227             // horizontal scrollbar
1228             options |= PAINT_HSCROLL;
1229         }
1230         layout();
1231         repaintNeeded |= (vsbWasVisible ^ vsbVis) || (hsbWasVisible ^ hsbVis); // If scrollbars visibility changed
1232         if (repaintNeeded) {


1445      * presence of vertical scrollbar)
1446      */
1447     int getListWidth() {
1448         return vsbVis ? width - SCROLLBAR_AREA : width;
1449     }
1450 
1451     /**
1452      * returns number of  items actually displayed in the List
1453      */
1454     int itemsDisplayed() {
1455 
1456         return (Math.min(items.size()-vsb.getValue(), itemsInWindow()));
1457 
1458     }
1459 
1460     /**
1461      * scrollVertical
1462      * y is the number of items to scroll
1463      */
1464     void scrollVertical(int y) {
1465         if (log.isLoggable(Level.FINE)) {
1466             log.fine("Scrolling vertically by " + y);
1467         }
1468         int itemsInWin = itemsInWindow();
1469         int h = getItemHeight();
1470         int pixelsToScroll = y * h;
1471 
1472         if (vsb.getValue() < -y) {
1473             y = -vsb.getValue();
1474         }
1475         vsb.setValue(vsb.getValue() + y);
1476 
1477         if (y > 0) {
1478             // Fixed 6308295: XAWTduplicate list item is displayed
1479             // Window resizing leads to the buffer flushing
1480             // That's why the repainting with the PAINT_HIDEFOCUS option is the repainting with PAINT_ALL option
1481             // So we should do only the repainting instead of the copy area
1482             if (y < itemsInWin && painter.isBuffer()) {
1483                 if (log.isLoggable(Level.FINEST)) {
1484                     log.finest("Copying " + "" + MARGIN + "," + ( MARGIN + pixelsToScroll)
1485                                + "," +  (width - SCROLLBAR_AREA) + "," +  (h * (itemsInWin - y)-1) +
1486                                "," + 0 + "," + (-pixelsToScroll));
1487                 }


1493         } else if (y < 0 && painter.isBuffer()) {
1494             if (y + itemsInWindow() > 0) {
1495                 if (log.isLoggable(Level.FINEST)) {
1496                     log.finest("Copying " + MARGIN + "," + MARGIN +"," +
1497                                (width - SCROLLBAR_AREA) + "," +
1498                                (h * (itemsInWin + y)) + "," + "0" +"," +(-pixelsToScroll));
1499                 }
1500                 repaint(PAINT_HIDEFOCUS);
1501                 painter.copyArea(MARGIN, MARGIN, width - SCROLLBAR_AREA, h * (itemsInWin + y), 0, -pixelsToScroll);
1502             }
1503             int e = Math.min(getLastVisibleItem(), vsb.getValue() + -y);
1504             repaint(vsb.getValue(), e, PAINT_ITEMS | PAINT_VSCROLL | PAINT_FOCUS);
1505         }
1506     }
1507 
1508     /**
1509      * scrollHorizontal
1510      * x is the number of pixels to scroll
1511      */
1512     void scrollHorizontal(int x) {
1513         if (log.isLoggable(Level.FINE)) {
1514             log.fine("Scrolling horizontally by " + y);
1515         }
1516         int w = getListWidth();
1517         w -= ((2 * SPACE) + (2 * MARGIN));
1518         int h = height - (SCROLLBAR_AREA + (2 * MARGIN));
1519         hsb.setValue(hsb.getValue() + x);
1520 
1521         if (x < 0 && painter.isBuffer()) {
1522             painter.copyArea(MARGIN + SPACE, MARGIN, w + x, h, -x, 0);
1523         } else if (x > 0 && painter.isBuffer()) {
1524             painter.copyArea(MARGIN + SPACE + x, MARGIN, w - x, h, -x, 0);
1525         }
1526         repaint(vsb.getValue(), lastItemDisplayed(), PAINT_ITEMS | PAINT_HSCROLL);
1527     }
1528 
1529     /**
1530      * return the index
1531      */
1532     int y2index(int y) {
1533         if (!validY(y)) {
1534             return -1;
1535         }


1730                 return SystemColor.text;
1731             }
1732         }
1733 
1734         private Color getDisabledColor() {
1735             Color backgroundColor = getListBackground();
1736             Color foregroundColor = getListForeground();
1737             return (backgroundColor.equals(Color.BLACK)) ? foregroundColor.darker() : backgroundColor.darker();
1738         }
1739 
1740         private boolean createBuffer() {
1741             VolatileImage localBuffer = null;
1742             XToolkit.awtLock();
1743             try {
1744                 localBuffer = buffer;
1745             } finally {
1746                 XToolkit.awtUnlock();
1747             }
1748 
1749             if (localBuffer == null) {
1750                 if (log.isLoggable(Level.FINE)) {
1751                     log.fine("Creating buffer " + width + "x" + height);
1752                 }
1753                 // use GraphicsConfig.cCVI() instead of Component.cVI(),
1754                 // because the latter may cause a deadlock with the tree lock
1755                 localBuffer =
1756                     graphicsConfig.createCompatibleVolatileImage(width+1,
1757                                                                  height+1);
1758             }
1759             XToolkit.awtLock();
1760             try {
1761                 if (buffer == null) {
1762                     buffer = localBuffer;
1763                     return true;
1764                 }
1765             } finally {
1766                 XToolkit.awtUnlock();
1767             }
1768             return false;
1769         }
1770 
1771         public void invalidate() {
1772             XToolkit.awtLock();
1773             try {
1774                 if (buffer != null) {
1775                     buffer.flush();
1776                 }
1777                 buffer = null;
1778             } finally {
1779                 XToolkit.awtUnlock();
1780             }
1781         }
1782 
1783         private void paint(Graphics listG, int firstItem, int lastItem, int options) {
1784             if (log.isLoggable(Level.FINER)) {
1785                 log.finer("Repaint from " + firstItem + " to " + lastItem + " options " + options);
1786             }
1787             if (firstItem > lastItem) {
1788                 int t = lastItem;
1789                 lastItem = firstItem;
1790                 firstItem = t;
1791             }
1792             if (firstItem < 0) {
1793                 firstItem = 0;
1794             }
1795             colors = getGUIcolors();
1796             VolatileImage localBuffer = null;
1797             do {
1798                 XToolkit.awtLock();
1799                 try {
1800                     if (createBuffer()) {
1801                         // First time created buffer should be painted over at full.
1802                         options = PAINT_ALL;
1803                     }
1804                     localBuffer = buffer;
1805                 } finally {
1806                     XToolkit.awtUnlock();


1830                     }
1831                     if ((options & PAINT_VSCROLL) != 0 && vsbVis) {
1832                         g.setClip(getVScrollBarRec());
1833                         paintVerScrollbar(g, true);
1834                     }
1835                     if ((options & PAINT_HSCROLL) != 0 && hsbVis) {
1836                         g.setClip(getHScrollBarRec());
1837                         paintHorScrollbar(g, true);
1838                     }
1839                     if ((options & (PAINT_FOCUS|PAINT_HIDEFOCUS)) != 0) {
1840                         paintFocus(g, options);
1841                     }
1842                 } finally {
1843                     g.dispose();
1844                 }
1845             } while (localBuffer.contentsLost());
1846             listG.drawImage(localBuffer, 0, 0, null);
1847         }
1848 
1849         private void paintItems(Graphics g, int firstItem, int lastItem, int options) {
1850             if (log.isLoggable(Level.FINER)) {
1851                 log.finer("Painting items from " + firstItem + " to " + lastItem +
1852                           ", focused " + focusIndex + ", first " + getFirstVisibleItem() +
1853                           ", last " + getLastVisibleItem());
1854             }
1855 
1856             firstItem = Math.max(getFirstVisibleItem(), firstItem);
1857             if (firstItem > lastItem) {
1858                 int t = lastItem;
1859                 lastItem = firstItem;
1860                 firstItem = t;
1861             }
1862             firstItem = Math.max(getFirstVisibleItem(), firstItem);
1863             lastItem = Math.min(lastItem, items.size()-1);
1864 
1865             if (log.isLoggable(Level.FINER)) {
1866                 log.finer("Actually painting items from " + firstItem + " to " + lastItem +
1867                           ", items in window " + itemsInWindow());
1868             }
1869             for (int i = firstItem; i <= lastItem; i++) {
1870                 paintItem(g, i);
1871             }
1872         }
1873 
1874         private void paintItem(Graphics g, int index) {
1875             if (log.isLoggable(Level.FINEST)) {
1876                 log.finest("Painting item " + index);
1877             }
1878             // 4895367 - only paint items which are visible
1879             if (!isItemHidden(index)) {
1880                 Shape clip = g.getClip();
1881                 int w = getItemWidth();
1882                 int h = getItemHeight();
1883                 int y = getItemY(index);
1884                 int x = getItemX();
1885                 if (log.isLoggable(Level.FINEST)) {
1886                     log.finest("Setting clip " + new Rectangle(x, y, w - (SPACE*2), h-(SPACE*2)));
1887                 }
1888                 g.setClip(x, y, w - (SPACE*2), h-(SPACE*2));
1889 
1890                 // Always paint the background so that focus is unpainted in
1891                 // multiselect mode
1892                 if (isSelected(index)) {
1893                     if (log.isLoggable(Level.FINEST)) {
1894                         log.finest("Painted item is selected");
1895                     }
1896                     g.setColor(getListForeground());
1897                 } else {
1898                     g.setColor(getListBackground());
1899                 }
1900                 if (log.isLoggable(Level.FINEST)) {
1901                     log.finest("Filling " + new Rectangle(x, y, w, h));
1902                 }
1903                 g.fillRect(x, y, w, h);
1904 
1905                 if (index <= getLastVisibleItem() && index < items.size()) {
1906                     if (!isEnabled()){
1907                         g.setColor(getDisabledColor());
1908                     } else if (isSelected(index)) {
1909                         g.setColor(getListBackground());
1910                     } else {
1911                         g.setColor(getListForeground());
1912                     }
1913                     String str = (String)items.elementAt(index);
1914                     g.drawString(str, x - hsb.getValue(), y + fontAscent);
1915                 } else {
1916                     // Clear the remaining area around the item - focus area and the rest of border
1917                     g.setClip(x, y, listWidth, h);
1918                     g.setColor(getListBackground());
1919                     g.fillRect(x, y, listWidth, h);
1920                 }
1921                 g.setClip(clip);
1922             }
1923         }
1924 
1925         void paintScrollBar(XScrollbar scr, Graphics g, int x, int y, int width, int height, boolean paintAll) {
1926             if (log.isLoggable(Level.FINEST)) {
1927                 log.finest("Painting scrollbar " + scr + " width " +
1928                            width + " height " + height + ", paintAll " + paintAll);
1929             }
1930             g.translate(x, y);
1931             scr.paint(g, getSystemColors(), paintAll);
1932             g.translate(-x, -y);
1933         }
1934 
1935         /**
1936          * Paint the horizontal scrollbar to the screen
1937          *
1938          * @param g the graphics context to draw into
1939          * @param colors the colors used to draw the scrollbar
1940          * @param paintAll paint the whole scrollbar if true, just the thumb if false
1941          */
1942         void paintHorScrollbar(Graphics g, boolean paintAll) {
1943             int w = getListWidth();
1944             paintScrollBar(hsb, g, 0, height - (SCROLLBAR_WIDTH), w, SCROLLBAR_WIDTH, paintAll);
1945         }
1946 
1947         /**
1948          * Paint the vertical scrollbar to the screen
1949          *
1950          * @param g the graphics context to draw into
1951          * @param colors the colors used to draw the scrollbar
1952          * @param paintAll paint the whole scrollbar if true, just the thumb if false
1953          */
1954         void paintVerScrollbar(Graphics g, boolean paintAll) {
1955             int h = height - (hsbVis ? (SCROLLBAR_AREA-2) : 0);
1956             paintScrollBar(vsb, g, width - SCROLLBAR_WIDTH, 0, SCROLLBAR_WIDTH - 2, h, paintAll);
1957         }
1958 
1959 
1960         private Rectangle prevFocusRect;
1961         private void paintFocus(Graphics g, int options) {
1962             boolean paintFocus = (options & PAINT_FOCUS) != 0;
1963             if (paintFocus && !hasFocus()) {
1964                 paintFocus = false;
1965             }
1966             if (log.isLoggable(Level.FINE)) {
1967                 log.fine("Painting focus, focus index " + getFocusIndex() + ", focus is " +
1968                          (isItemHidden(getFocusIndex())?("invisible"):("visible")) + ", paint focus is " + paintFocus);
1969             }
1970             Shape clip = g.getClip();
1971             g.setClip(0, 0, listWidth, listHeight);
1972             if (log.isLoggable(Level.FINEST)) {
1973                 log.finest("Setting focus clip " + new Rectangle(0, 0, listWidth, listHeight));
1974             }
1975             Rectangle rect = getFocusRect();
1976             if (prevFocusRect != null) {
1977                 // Erase focus rect
1978                 if (log.isLoggable(Level.FINEST)) {
1979                     log.finest("Erasing previous focus rect " + prevFocusRect);
1980                 }
1981                 g.setColor(getListBackground());
1982                 g.drawRect(prevFocusRect.x, prevFocusRect.y, prevFocusRect.width, prevFocusRect.height);
1983                 prevFocusRect = null;
1984             }
1985             if (paintFocus) {
1986                 // Paint new
1987                 if (log.isLoggable(Level.FINEST)) {
1988                     log.finest("Painting focus rect " + rect);
1989                 }
1990                 g.setColor(getListForeground());  // Focus color is always black on Linux
1991                 g.drawRect(rect.x, rect.y, rect.width, rect.height);
1992                 prevFocusRect = rect;
1993             }
1994             g.setClip(clip);
1995         }
1996 
1997         public void copyArea(int x, int y, int width, int height, int dx, int dy) {
1998             if (log.isLoggable(Level.FINER)) {
1999                 log.finer("Copying area " + x + ", " + y + " " + width +
2000                           "x" + height + ", (" + dx + "," + dy + ")");
2001             }
2002             VolatileImage localBuffer = null;
2003             do {
2004                 XToolkit.awtLock();
2005                 try {
2006                     if (createBuffer()) {
2007                         // Newly created buffer should be painted over at full
2008                         repaint(PAINT_ALL);
2009                         return;
2010                     }
2011                     localBuffer = buffer;
2012                 } finally {
2013                     XToolkit.awtUnlock();
2014                 }
2015                 switch (localBuffer.validate(getGraphicsConfiguration())) {
2016                   case VolatileImage.IMAGE_INCOMPATIBLE:
2017                       invalidate();
2018                   case VolatileImage.IMAGE_RESTORED:
2019                       // Since we've lost the content we can't just scroll - we should paint again
2020                       repaint(PAINT_ALL);
2021                       return;


< prev index next >