121 |
*/ |
*/ |
122 |
public void contentsChanged(ListDataEvent e) |
public void contentsChanged(ListDataEvent e) |
123 |
{ |
{ |
|
// System.err.println(this + ".contentsChanged(" + e + ")"); |
|
124 |
BasicListUI.this.damageLayout(); |
BasicListUI.this.damageLayout(); |
125 |
} |
} |
126 |
|
|
131 |
*/ |
*/ |
132 |
public void intervalAdded(ListDataEvent e) |
public void intervalAdded(ListDataEvent e) |
133 |
{ |
{ |
|
// System.err.println(this + ".intervalAdded(" + e + ")"); |
|
134 |
BasicListUI.this.damageLayout(); |
BasicListUI.this.damageLayout(); |
135 |
} |
} |
136 |
|
|
141 |
*/ |
*/ |
142 |
public void intervalRemoved(ListDataEvent e) |
public void intervalRemoved(ListDataEvent e) |
143 |
{ |
{ |
|
// System.err.println(this + ".intervalRemoved(" + e + ")"); |
|
144 |
BasicListUI.this.damageLayout(); |
BasicListUI.this.damageLayout(); |
145 |
} |
} |
146 |
} |
} |
158 |
*/ |
*/ |
159 |
public void valueChanged(ListSelectionEvent e) |
public void valueChanged(ListSelectionEvent e) |
160 |
{ |
{ |
|
// System.err.println(this + ".valueChanged(" + e + ")"); |
|
161 |
} |
} |
162 |
} |
} |
163 |
|
|
185 |
*/ |
*/ |
186 |
public void mousePressed(MouseEvent event) |
public void mousePressed(MouseEvent event) |
187 |
{ |
{ |
|
// System.err.println("got mouse click event " + event); |
|
188 |
int row = BasicListUI.this.convertYToRow(event.getY()); |
int row = BasicListUI.this.convertYToRow(event.getY()); |
189 |
if (row == -1) |
if (row == -1) |
190 |
return; |
return; |
191 |
|
|
|
// System.err.println("clicked on row " + row); |
|
192 |
BasicListUI.this.list.setSelectedIndex(row); |
BasicListUI.this.list.setSelectedIndex(row); |
193 |
} |
} |
194 |
|
|
256 |
*/ |
*/ |
257 |
public void propertyChange(PropertyChangeEvent e) |
public void propertyChange(PropertyChangeEvent e) |
258 |
{ |
{ |
|
// System.err.println(this + ".propertyChange(" + e + ")"); |
|
259 |
if (e.getSource() == BasicListUI.this.list) |
if (e.getSource() == BasicListUI.this.list) |
260 |
{ |
{ |
261 |
if (e.getOldValue() != null && e.getOldValue() instanceof ListModel) |
if (e.getOldValue() != null && e.getOldValue() instanceof ListModel) |
350 |
*/ |
*/ |
351 |
public Rectangle getCellBounds(JList l, int index1, int index2) |
public Rectangle getCellBounds(JList l, int index1, int index2) |
352 |
{ |
{ |
353 |
|
maybeUpdateLayoutState(); |
354 |
|
|
355 |
if (l != list || cellWidth == -1) |
if (l != list || cellWidth == -1) |
356 |
return null; |
return null; |
357 |
|
|
361 |
getRowHeight(lo)); |
getRowHeight(lo)); |
362 |
Rectangle hibounds = new Rectangle(0, convertRowToY(hi), cellWidth, |
Rectangle hibounds = new Rectangle(0, convertRowToY(hi), cellWidth, |
363 |
getRowHeight(hi)); |
getRowHeight(hi)); |
364 |
|
|
365 |
return lobounds.union(hibounds); |
return lobounds.union(hibounds); |
366 |
} |
} |
367 |
|
|
404 |
{ |
{ |
405 |
int h = getRowHeight(row); |
int h = getRowHeight(row); |
406 |
|
|
|
// System.err.println("convertYToRow(" + y0 + ") vs. " + h); |
|
407 |
if (y0 < h) |
if (y0 < h) |
408 |
return row; |
return row; |
409 |
y0 -= h; |
y0 -= h; |
463 |
*/ |
*/ |
464 |
void maybeUpdateLayoutState() |
void maybeUpdateLayoutState() |
465 |
{ |
{ |
|
// System.err.println(this + ".maybeUpdateLayoutState()"); |
|
466 |
if (updateLayoutStateNeeded != 0) |
if (updateLayoutStateNeeded != 0) |
467 |
{ |
{ |
468 |
updateLayoutState(); |
updateLayoutState(); |
570 |
installDefaults(); |
installDefaults(); |
571 |
installListeners(); |
installListeners(); |
572 |
installKeyboardActions(); |
installKeyboardActions(); |
|
// System.err.println(this + ".installUI()"); |
|
573 |
maybeUpdateLayoutState(); |
maybeUpdateLayoutState(); |
574 |
} |
} |
575 |
|
|
611 |
*/ |
*/ |
612 |
public Dimension getPreferredSize(JComponent c) |
public Dimension getPreferredSize(JComponent c) |
613 |
{ |
{ |
|
maybeUpdateLayoutState(); |
|
614 |
if (list.getModel().getSize() == 0) |
if (list.getModel().getSize() == 0) |
615 |
return new Dimension(0, 0); |
return new Dimension(0, 0); |
616 |
int nrows = Math.min(list.getVisibleRowCount(), list.getModel().getSize()); |
Rectangle bounds = getCellBounds(list, 0, list.getModel().getSize() - 1); |
|
Rectangle bounds = getCellBounds(list, 0, nrows - 1); |
|
617 |
return bounds.getSize(); |
return bounds.getSize(); |
618 |
} |
} |
619 |
|
|
669 |
*/ |
*/ |
670 |
public void paint(Graphics g, JComponent c) |
public void paint(Graphics g, JComponent c) |
671 |
{ |
{ |
672 |
int nrows = Math.min(list.getVisibleRowCount(), list.getModel().getSize()); |
int nrows = list.getModel().getSize(); |
673 |
if (nrows == 0) |
if (nrows == 0) |
674 |
return; |
return; |
675 |
|
|
678 |
ListModel model = list.getModel(); |
ListModel model = list.getModel(); |
679 |
ListSelectionModel sel = list.getSelectionModel(); |
ListSelectionModel sel = list.getSelectionModel(); |
680 |
int lead = sel.getLeadSelectionIndex(); |
int lead = sel.getLeadSelectionIndex(); |
681 |
|
Rectangle clip = g.getClipBounds(); |
682 |
paintBackground(g, list); |
paintBackground(g, list); |
683 |
|
|
684 |
for (int row = 0; row < nrows; ++row) |
for (int row = 0; row < nrows; ++row) |
685 |
{ |
{ |
686 |
Rectangle bounds = getCellBounds(list, row, row); |
Rectangle bounds = getCellBounds(list, row, row); |
687 |
|
if (bounds.intersects(clip)) |
688 |
paintCell(g, row, bounds, render, model, sel, lead); |
paintCell(g, row, bounds, render, model, sel, lead); |
689 |
} |
} |
690 |
} |
} |