1 7 8 package javax.swing.plaf.synth; 9 10 import javax.swing.*; 11 import javax.swing.border.*; 12 import javax.swing.event.*; 13 import javax.swing.plaf.*; 14 import javax.swing.plaf.basic.*; 15 import javax.swing.text.Position ; 16 17 import java.awt.*; 18 import java.awt.event.*; 19 import java.awt.datatransfer.Transferable ; 20 import java.awt.dnd.*; 21 22 import java.util.ArrayList ; 23 import java.util.TooManyListenersException ; 24 25 import java.beans.PropertyChangeListener ; 26 import java.beans.PropertyChangeEvent ; 27 import sun.swing.plaf.synth.SynthUI; 28 29 35 class SynthListUI extends BasicListUI implements PropertyChangeListener , 36 SynthUI { 37 private SynthStyle style; 38 private boolean useListColors; 39 private boolean useUIBorder; 40 41 public static ComponentUI createUI(JComponent list) { 42 return new SynthListUI (); 43 } 44 45 public void update(Graphics g, JComponent c) { 46 SynthContext context = getContext(c); 47 48 SynthLookAndFeel.update(context, g); 49 context.getPainter().paintListBackground(context, 50 g, 0, 0, c.getWidth(), c.getHeight()); 51 context.dispose(); 52 paint(g, c); 53 } 54 55 public void paintBorder(SynthContext context, Graphics g, int x, 56 int y, int w, int h) { 57 context.getPainter().paintListBorder(context, g, x, y, w, h); 58 } 59 60 protected void installListeners() { 61 super.installListeners(); 62 list.addPropertyChangeListener(this); 63 } 64 65 public void propertyChange(PropertyChangeEvent e) { 66 if (SynthLookAndFeel.shouldUpdateStyle(e)) { 67 updateStyle((JList)e.getSource()); 68 } 69 } 70 71 protected void uninstallListeners() { 72 super.uninstallListeners(); 73 list.removePropertyChangeListener(this); 74 } 75 76 protected void installDefaults() { 77 if (list.getCellRenderer() == null || 78 (list.getCellRenderer() instanceof UIResource)) { 79 list.setCellRenderer(new SynthListCellRenderer()); 80 } 81 updateStyle(list); 82 } 83 84 private void updateStyle(JComponent c) { 85 SynthContext context = getContext(list, ENABLED); 86 SynthStyle oldStyle = style; 87 88 style = SynthLookAndFeel.updateStyle(context, this); 89 90 if (style != oldStyle) { 91 context.setComponentState(SELECTED); 92 Color sbg = list.getSelectionBackground(); 93 if (sbg == null || sbg instanceof UIResource) { 94 list.setSelectionBackground(style.getColor( 95 context, ColorType.TEXT_BACKGROUND)); 96 } 97 98 Color sfg = list.getSelectionForeground(); 99 if (sfg == null || sfg instanceof UIResource) { 100 list.setSelectionForeground(style.getColor( 101 context, ColorType.TEXT_FOREGROUND)); 102 } 103 104 useListColors = style.getBoolean(context, 105 "List.rendererUseListColors", true); 106 useUIBorder = style.getBoolean(context, 107 "List.rendererUseUIBorder", true); 108 109 int height = style.getInt(context, "List.cellHeight", -1); 110 if (height != -1) { 111 list.setFixedCellHeight(height); 112 } 113 if (oldStyle != null) { 114 uninstallKeyboardActions(); 115 installKeyboardActions(); 116 } 117 } 118 context.dispose(); 119 } 120 121 protected void uninstallDefaults() { 122 super.uninstallDefaults(); 123 124 SynthContext context = getContext(list, ENABLED); 125 126 style.uninstallDefaults(context); 127 context.dispose(); 128 style = null; 129 } 130 131 public SynthContext getContext(JComponent c) { 132 return getContext(c, getComponentState(c)); 133 } 134 135 private SynthContext getContext(JComponent c, int state) { 136 return SynthContext.getContext(SynthContext .class, c, 137 SynthLookAndFeel.getRegion(c), style, state); 138 } 139 140 private Region getRegion(JComponent c) { 141 return SynthLookAndFeel.getRegion(c); 142 } 143 144 private int getComponentState(JComponent c) { 145 return SynthLookAndFeel.getComponentState(c); 146 } 147 148 149 private class SynthListCellRenderer extends DefaultListCellRenderer.UIResource { 150 public String getName() { 151 return "List.cellRenderer"; 152 } 153 154 public void setBorder(Border b) { 155 if (useUIBorder || b instanceof SynthBorder ) { 156 super.setBorder(b); 157 } 158 } 159 160 public Component getListCellRendererComponent(JList list, Object value, 161 int index, boolean isSelected, boolean cellHasFocus) { 162 if (!useListColors && (isSelected || cellHasFocus)) { 163 SynthLookAndFeel.setSelectedUI((SynthLabelUI )SynthLookAndFeel. 164 getUIOfType(getUI(), SynthLabelUI .class), 165 isSelected, cellHasFocus, list.isEnabled()); 166 } 167 else { 168 SynthLookAndFeel.resetSelectedUI(); 169 } 170 171 super.getListCellRendererComponent(list, value, index, 172 isSelected, cellHasFocus); 173 return this; 174 } 175 176 public void paint(Graphics g) { 177 super.paint(g); 178 SynthLookAndFeel.resetSelectedUI(); 179 } 180 } 181 } 182 | Popular Tags |