32 import java.awt.event.*; |
32 import java.awt.event.*; |
33 import java.awt.peer.*; |
33 import java.awt.peer.*; |
34 import java.util.Vector; |
34 import java.util.Vector; |
35 import java.awt.geom.*; |
35 import java.awt.geom.*; |
36 import java.awt.image.*; |
36 import java.awt.image.*; |
37 import java.util.logging.*; |
37 import sun.util.logging.PlatformLogger; |
38 |
38 |
39 // TODO: some input actions should do nothing if Shift or Control are down |
39 // TODO: some input actions should do nothing if Shift or Control are down |
40 |
40 |
41 class XListPeer extends XComponentPeer implements ListPeer, XScrollbarClient { |
41 class XListPeer extends XComponentPeer implements ListPeer, XScrollbarClient { |
42 |
42 |
43 private static final Logger log = Logger.getLogger("sun.awt.X11.XListPeer"); |
43 private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XListPeer"); |
44 |
44 |
45 public final static int MARGIN = 2; |
45 public final static int MARGIN = 2; |
46 public final static int SPACE = 1; |
46 public final static int SPACE = 1; |
47 public final static int SCROLLBAR_AREA = 17; // Area reserved for the |
47 public final static int SCROLLBAR_AREA = 17; // Area reserved for the |
48 // scrollbar |
48 // scrollbar |
616 // 6426186: reset variable to prevent action event |
616 // 6426186: reset variable to prevent action event |
617 // if user clicks on unoccupied area of list |
617 // if user clicks on unoccupied area of list |
618 currentIndex = -1; |
618 currentIndex = -1; |
619 } |
619 } |
620 } else if (inVerticalScrollbar(mouseEvent.getX(), mouseEvent.getY())) { |
620 } else if (inVerticalScrollbar(mouseEvent.getX(), mouseEvent.getY())) { |
621 if (log.isLoggable(Level.FINE)) log.fine("Mouse press in vertical scrollbar"); |
621 if (log.isLoggable(PlatformLogger.FINE)) log.fine("Mouse press in vertical scrollbar"); |
622 active = VERSCROLLBAR; |
622 active = VERSCROLLBAR; |
623 vsb.handleMouseEvent(mouseEvent.getID(), |
623 vsb.handleMouseEvent(mouseEvent.getID(), |
624 mouseEvent.getModifiers(), |
624 mouseEvent.getModifiers(), |
625 mouseEvent.getX() - (width - SCROLLBAR_WIDTH), |
625 mouseEvent.getX() - (width - SCROLLBAR_WIDTH), |
626 mouseEvent.getY()); |
626 mouseEvent.getY()); |
627 } else if (inHorizontalScrollbar(mouseEvent.getX(), mouseEvent.getY())) { |
627 } else if (inHorizontalScrollbar(mouseEvent.getX(), mouseEvent.getY())) { |
628 if (log.isLoggable(Level.FINE)) log.fine("Mouse press in horizontal scrollbar"); |
628 if (log.isLoggable(PlatformLogger.FINE)) log.fine("Mouse press in horizontal scrollbar"); |
629 active = HORSCROLLBAR; |
629 active = HORSCROLLBAR; |
630 hsb.handleMouseEvent(mouseEvent.getID(), |
630 hsb.handleMouseEvent(mouseEvent.getID(), |
631 mouseEvent.getModifiers(), |
631 mouseEvent.getModifiers(), |
632 mouseEvent.getX(), |
632 mouseEvent.getX(), |
633 mouseEvent.getY() - (height - SCROLLBAR_WIDTH)); |
633 mouseEvent.getY() - (height - SCROLLBAR_WIDTH)); |
1741 paint(listG, firstItem, lastItem, options, null, null); |
1741 paint(listG, firstItem, lastItem, options, null, null); |
1742 } |
1742 } |
1743 |
1743 |
1744 private void paint(Graphics listG, int firstItem, int lastItem, int options, |
1744 private void paint(Graphics listG, int firstItem, int lastItem, int options, |
1745 Rectangle source, Point distance) { |
1745 Rectangle source, Point distance) { |
1746 if (log.isLoggable(Level.FINER)) log.finer("Repaint from " + firstItem + " to " + lastItem + " options " + options); |
1746 if (log.isLoggable(PlatformLogger.FINER)) log.finer("Repaint from " + firstItem + " to " + lastItem + " options " + options); |
1747 if (firstItem > lastItem) { |
1747 if (firstItem > lastItem) { |
1748 int t = lastItem; |
1748 int t = lastItem; |
1749 lastItem = firstItem; |
1749 lastItem = firstItem; |
1750 firstItem = t; |
1750 firstItem = t; |
1751 } |
1751 } |
1830 g.fillRect(0, 0, listWidth, listHeight); |
1830 g.fillRect(0, 0, listWidth, listHeight); |
1831 draw3DRect(g, getSystemColors(), 0, 0, listWidth - 1, listHeight - 1, false); |
1831 draw3DRect(g, getSystemColors(), 0, 0, listWidth - 1, listHeight - 1, false); |
1832 } |
1832 } |
1833 |
1833 |
1834 private void paintItems(Graphics g, int firstItem, int lastItem, int options) { |
1834 private void paintItems(Graphics g, int firstItem, int lastItem, int options) { |
1835 if (log.isLoggable(Level.FINER)) log.finer("Painting items from " + firstItem + " to " + lastItem + ", focused " + focusIndex + ", first " + getFirstVisibleItem() + ", last " + getLastVisibleItem()); |
1835 if (log.isLoggable(PlatformLogger.FINER)) log.finer("Painting items from " + firstItem + " to " + lastItem + ", focused " + focusIndex + ", first " + getFirstVisibleItem() + ", last " + getLastVisibleItem()); |
1836 |
1836 |
1837 firstItem = Math.max(getFirstVisibleItem(), firstItem); |
1837 firstItem = Math.max(getFirstVisibleItem(), firstItem); |
1838 if (firstItem > lastItem) { |
1838 if (firstItem > lastItem) { |
1839 int t = lastItem; |
1839 int t = lastItem; |
1840 lastItem = firstItem; |
1840 lastItem = firstItem; |
1841 firstItem = t; |
1841 firstItem = t; |
1842 } |
1842 } |
1843 firstItem = Math.max(getFirstVisibleItem(), firstItem); |
1843 firstItem = Math.max(getFirstVisibleItem(), firstItem); |
1844 lastItem = Math.min(lastItem, items.size()-1); |
1844 lastItem = Math.min(lastItem, items.size()-1); |
1845 |
1845 |
1846 if (log.isLoggable(Level.FINER)) log.finer("Actually painting items from " + firstItem + " to " + lastItem + |
1846 if (log.isLoggable(PlatformLogger.FINER)) log.finer("Actually painting items from " + firstItem + " to " + lastItem + |
1847 ", items in window " + itemsInWindow()); |
1847 ", items in window " + itemsInWindow()); |
1848 for (int i = firstItem; i <= lastItem; i++) { |
1848 for (int i = firstItem; i <= lastItem; i++) { |
1849 paintItem(g, i); |
1849 paintItem(g, i); |
1850 } |
1850 } |
1851 } |
1851 } |
1852 |
1852 |
1853 private void paintItem(Graphics g, int index) { |
1853 private void paintItem(Graphics g, int index) { |
1854 if (log.isLoggable(Level.FINEST)) log.finest("Painting item " + index); |
1854 if (log.isLoggable(PlatformLogger.FINEST)) log.finest("Painting item " + index); |
1855 // 4895367 - only paint items which are visible |
1855 // 4895367 - only paint items which are visible |
1856 if (!isItemHidden(index)) { |
1856 if (!isItemHidden(index)) { |
1857 Shape clip = g.getClip(); |
1857 Shape clip = g.getClip(); |
1858 int w = getItemWidth(); |
1858 int w = getItemWidth(); |
1859 int h = getItemHeight(); |
1859 int h = getItemHeight(); |
1860 int y = getItemY(index); |
1860 int y = getItemY(index); |
1861 int x = getItemX(); |
1861 int x = getItemX(); |
1862 if (log.isLoggable(Level.FINEST)) log.finest("Setting clip " + new Rectangle(x, y, w - (SPACE*2), h-(SPACE*2))); |
1862 if (log.isLoggable(PlatformLogger.FINEST)) log.finest("Setting clip " + new Rectangle(x, y, w - (SPACE*2), h-(SPACE*2))); |
1863 g.setClip(x, y, w - (SPACE*2), h-(SPACE*2)); |
1863 g.setClip(x, y, w - (SPACE*2), h-(SPACE*2)); |
1864 |
1864 |
1865 // Always paint the background so that focus is unpainted in |
1865 // Always paint the background so that focus is unpainted in |
1866 // multiselect mode |
1866 // multiselect mode |
1867 if (isSelected(index)) { |
1867 if (isSelected(index)) { |
1868 if (log.isLoggable(Level.FINEST)) log.finest("Painted item is selected"); |
1868 if (log.isLoggable(PlatformLogger.FINEST)) log.finest("Painted item is selected"); |
1869 g.setColor(getListForeground()); |
1869 g.setColor(getListForeground()); |
1870 } else { |
1870 } else { |
1871 g.setColor(getListBackground()); |
1871 g.setColor(getListBackground()); |
1872 } |
1872 } |
1873 if (log.isLoggable(Level.FINEST)) log.finest("Filling " + new Rectangle(x, y, w, h)); |
1873 if (log.isLoggable(PlatformLogger.FINEST)) log.finest("Filling " + new Rectangle(x, y, w, h)); |
1874 g.fillRect(x, y, w, h); |
1874 g.fillRect(x, y, w, h); |
1875 |
1875 |
1876 if (index <= getLastVisibleItem() && index < items.size()) { |
1876 if (index <= getLastVisibleItem() && index < items.size()) { |
1877 if (!isEnabled()){ |
1877 if (!isEnabled()){ |
1878 g.setColor(getDisabledColor()); |
1878 g.setColor(getDisabledColor()); |
1892 g.setClip(clip); |
1892 g.setClip(clip); |
1893 } |
1893 } |
1894 } |
1894 } |
1895 |
1895 |
1896 void paintScrollBar(XScrollbar scr, Graphics g, int x, int y, int width, int height, boolean paintAll) { |
1896 void paintScrollBar(XScrollbar scr, Graphics g, int x, int y, int width, int height, boolean paintAll) { |
1897 if (log.isLoggable(Level.FINEST)) log.finest("Painting scrollbar " + scr + " width " + |
1897 if (log.isLoggable(PlatformLogger.FINEST)) log.finest("Painting scrollbar " + scr + " width " + |
1898 width + " height " + height + ", paintAll " + paintAll); |
1898 width + " height " + height + ", paintAll " + paintAll); |
1899 g.translate(x, y); |
1899 g.translate(x, y); |
1900 scr.paint(g, getSystemColors(), paintAll); |
1900 scr.paint(g, getSystemColors(), paintAll); |
1901 g.translate(-x, -y); |
1901 g.translate(-x, -y); |
1902 } |
1902 } |
1930 private void paintFocus(Graphics g, int options) { |
1930 private void paintFocus(Graphics g, int options) { |
1931 boolean paintFocus = (options & PAINT_FOCUS) != 0; |
1931 boolean paintFocus = (options & PAINT_FOCUS) != 0; |
1932 if (paintFocus && !hasFocus()) { |
1932 if (paintFocus && !hasFocus()) { |
1933 paintFocus = false; |
1933 paintFocus = false; |
1934 } |
1934 } |
1935 if (log.isLoggable(Level.FINE)) log.fine("Painting focus, focus index " + getFocusIndex() + ", focus is " + |
1935 if (log.isLoggable(PlatformLogger.FINE)) log.fine("Painting focus, focus index " + getFocusIndex() + ", focus is " + |
1936 (isItemHidden(getFocusIndex())?("invisible"):("visible")) + ", paint focus is " + paintFocus); |
1936 (isItemHidden(getFocusIndex())?("invisible"):("visible")) + ", paint focus is " + paintFocus); |
1937 Shape clip = g.getClip(); |
1937 Shape clip = g.getClip(); |
1938 g.setClip(0, 0, listWidth, listHeight); |
1938 g.setClip(0, 0, listWidth, listHeight); |
1939 if (log.isLoggable(Level.FINEST)) log.finest("Setting focus clip " + new Rectangle(0, 0, listWidth, listHeight)); |
1939 if (log.isLoggable(PlatformLogger.FINEST)) log.finest("Setting focus clip " + new Rectangle(0, 0, listWidth, listHeight)); |
1940 Rectangle rect = getFocusRect(); |
1940 Rectangle rect = getFocusRect(); |
1941 if (prevFocusRect != null) { |
1941 if (prevFocusRect != null) { |
1942 // Erase focus rect |
1942 // Erase focus rect |
1943 if (log.isLoggable(Level.FINEST)) log.finest("Erasing previous focus rect " + prevFocusRect); |
1943 if (log.isLoggable(PlatformLogger.FINEST)) log.finest("Erasing previous focus rect " + prevFocusRect); |
1944 g.setColor(getListBackground()); |
1944 g.setColor(getListBackground()); |
1945 g.drawRect(prevFocusRect.x, prevFocusRect.y, prevFocusRect.width, prevFocusRect.height); |
1945 g.drawRect(prevFocusRect.x, prevFocusRect.y, prevFocusRect.width, prevFocusRect.height); |
1946 prevFocusRect = null; |
1946 prevFocusRect = null; |
1947 } |
1947 } |
1948 if (paintFocus) { |
1948 if (paintFocus) { |
1949 // Paint new |
1949 // Paint new |
1950 if (log.isLoggable(Level.FINEST)) log.finest("Painting focus rect " + rect); |
1950 if (log.isLoggable(PlatformLogger.FINEST)) log.finest("Painting focus rect " + rect); |
1951 g.setColor(getListForeground()); // Focus color is always black on Linux |
1951 g.setColor(getListForeground()); // Focus color is always black on Linux |
1952 g.drawRect(rect.x, rect.y, rect.width, rect.height); |
1952 g.drawRect(rect.x, rect.y, rect.width, rect.height); |
1953 prevFocusRect = rect; |
1953 prevFocusRect = rect; |
1954 } |
1954 } |
1955 g.setClip(clip); |
1955 g.setClip(clip); |