home *** CD-ROM | disk | FTP | other *** search
- package javax.swing.plaf.basic;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.LayoutManager;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.event.FocusListener;
- import java.beans.PropertyChangeListener;
- import javax.swing.CellRendererPane;
- import javax.swing.JComponent;
- import javax.swing.JList;
- import javax.swing.KeyStroke;
- import javax.swing.ListCellRenderer;
- import javax.swing.ListModel;
- import javax.swing.ListSelectionModel;
- import javax.swing.LookAndFeel;
- import javax.swing.UIManager;
- import javax.swing.event.ListDataListener;
- import javax.swing.event.ListSelectionListener;
- import javax.swing.event.MouseInputListener;
- import javax.swing.plaf.ComponentUI;
- import javax.swing.plaf.ListUI;
- import javax.swing.plaf.UIResource;
-
- public class BasicListUI extends ListUI {
- protected JList list = null;
- protected CellRendererPane rendererPane;
- protected FocusListener focusListener;
- protected MouseInputListener mouseInputListener;
- protected ListSelectionListener listSelectionListener;
- protected ListDataListener listDataListener;
- protected PropertyChangeListener propertyChangeListener;
- protected int[] cellHeights = null;
- protected int cellHeight = -1;
- protected int cellWidth = -1;
- protected int updateLayoutStateNeeded = 1;
- protected static final int modelChanged = 1;
- protected static final int selectionModelChanged = 2;
- protected static final int fontChanged = 4;
- protected static final int fixedCellWidthChanged = 8;
- protected static final int fixedCellHeightChanged = 16;
- protected static final int prototypeCellValueChanged = 32;
- protected static final int cellRendererChanged = 64;
- private static final int CHANGE_LEAD = 0;
- private static final int CHANGE_SELECTION = 1;
- private static final int EXTEND_SELECTION = 2;
-
- // $FF: synthetic method
- static void access$0(BasicListUI var0) {
- var0.redrawList();
- }
-
- protected int convertRowToY(int var1) {
- int var2 = this.list.getModel().getSize();
- Insets var3 = this.list.getInsets();
- if (var1 >= 0 && var1 < var2) {
- if (this.cellHeights == null) {
- return var3.top + this.cellHeight * var1;
- } else if (var1 >= this.cellHeights.length) {
- return -1;
- } else {
- int var4 = var3.top;
-
- for(int var5 = 0; var5 < var1; ++var5) {
- var4 += this.cellHeights[var5];
- }
-
- return var4;
- }
- } else {
- return -1;
- }
- }
-
- protected int convertYToRow(int var1) {
- int var2 = this.list.getModel().getSize();
- Insets var3 = this.list.getInsets();
- if (this.cellHeights == null) {
- int var7 = this.cellHeight == 0 ? 0 : (var1 - var3.top) / this.cellHeight;
- return var7 >= 0 && var7 < var2 ? var7 : -1;
- } else if (var2 > this.cellHeights.length) {
- return -1;
- } else {
- int var4 = var3.top;
- int var5 = 0;
-
- for(int var6 = 0; var6 < var2; ++var6) {
- if (var1 >= var4 && var1 < var4 + this.cellHeights[var6]) {
- return var5;
- }
-
- var4 += this.cellHeights[var6];
- ++var5;
- }
-
- return -1;
- }
- }
-
- protected FocusListener createFocusListener() {
- return new FocusHandler(this);
- }
-
- protected ListDataListener createListDataListener() {
- return new ListDataHandler(this);
- }
-
- protected ListSelectionListener createListSelectionListener() {
- return new ListSelectionHandler(this);
- }
-
- protected MouseInputListener createMouseInputListener() {
- return new MouseInputHandler(this);
- }
-
- protected PropertyChangeListener createPropertyChangeListener() {
- return new PropertyChangeHandler(this);
- }
-
- public static ComponentUI createUI(JComponent var0) {
- return new BasicListUI();
- }
-
- public Rectangle getCellBounds(JList var1, int var2, int var3) {
- this.maybeUpdateLayoutState();
- int var4 = Math.min(var2, var3);
- int var5 = Math.max(var2, var3);
- int var6 = this.convertRowToY(var4);
- int var7 = this.convertRowToY(var5);
- if (var6 != -1 && var7 != -1) {
- Insets var8 = ((JComponent)var1).getInsets();
- int var9 = var8.left;
- int var11 = ((JComponent)var1).getWidth() - (var8.left + var8.right);
- int var12 = var7 + this.getRowHeight(var5) - var6;
- return new Rectangle(var9, var6, var11, var12);
- } else {
- return null;
- }
- }
-
- public Dimension getMaximumSize(JComponent var1) {
- return this.getPreferredSize(var1);
- }
-
- public Dimension getMinimumSize(JComponent var1) {
- return this.getPreferredSize(var1);
- }
-
- public Dimension getPreferredSize(JComponent var1) {
- this.maybeUpdateLayoutState();
- int var2 = this.list.getModel().getSize() - 1;
- if (var2 < 0) {
- return new Dimension(0, 0);
- } else {
- Insets var3 = this.list.getInsets();
- int var4 = this.cellWidth + var3.left + var3.right;
- int var5 = this.convertRowToY(var2) + this.getRowHeight(var2) + var3.bottom;
- return new Dimension(var4, var5);
- }
- }
-
- protected int getRowHeight(int var1) {
- if (var1 >= 0 && var1 < this.list.getModel().getSize()) {
- return this.cellHeights == null ? this.cellHeight : (var1 < this.cellHeights.length ? this.cellHeights[var1] : -1);
- } else {
- return -1;
- }
- }
-
- public Point indexToLocation(JList var1, int var2) {
- this.maybeUpdateLayoutState();
- return new Point(0, this.convertRowToY(var2));
- }
-
- protected void installDefaults() {
- this.list.setLayout((LayoutManager)null);
- LookAndFeel.installBorder(this.list, "List.border");
- LookAndFeel.installColorsAndFont(this.list, "List.background", "List.foreground", "List.font");
- if (this.list.getCellRenderer() == null) {
- this.list.setCellRenderer((ListCellRenderer)UIManager.get("List.cellRenderer"));
- }
-
- Color var1 = this.list.getSelectionBackground();
- if (var1 == null || var1 instanceof UIResource) {
- this.list.setSelectionBackground(UIManager.getColor("List.selectionBackground"));
- }
-
- Color var2 = this.list.getSelectionForeground();
- if (var2 == null || var2 instanceof UIResource) {
- this.list.setSelectionForeground(UIManager.getColor("List.selectionForeground"));
- }
-
- }
-
- protected void installKeyboardActions() {
- this.list.registerKeyboardAction(new IncrementLeadSelectionAction(this, "SelectPreviousRow", 1, -1), KeyStroke.getKeyStroke(38, 0), 0);
- this.list.registerKeyboardAction(new IncrementLeadSelectionAction(this, "ExtendSelectPreviousRow", 2, -1), KeyStroke.getKeyStroke(38, 1), 0);
- this.list.registerKeyboardAction(new IncrementLeadSelectionAction(this, "SelectNextRow", 1, 1), KeyStroke.getKeyStroke(40, 0), 0);
- this.list.registerKeyboardAction(new IncrementLeadSelectionAction(this, "ExtendSelectPreviousRow", 2, 1), KeyStroke.getKeyStroke(40, 1), 0);
- this.list.registerKeyboardAction(new HomeAction(this, "SelectHome", 1), KeyStroke.getKeyStroke(36, 0), 0);
- this.list.registerKeyboardAction(new HomeAction(this, "ExtendSelectHome", 2), KeyStroke.getKeyStroke(36, 1), 0);
- this.list.registerKeyboardAction(new EndAction(this, "SelectEnd", 1), KeyStroke.getKeyStroke(35, 0), 0);
- this.list.registerKeyboardAction(new EndAction(this, "ExtendSelectEnd", 2), KeyStroke.getKeyStroke(35, 1), 0);
- this.list.registerKeyboardAction(new PageUpAction(this, "SelectPageUp", 1), KeyStroke.getKeyStroke(33, 0), 0);
- this.list.registerKeyboardAction(new PageUpAction(this, "ExtendSelectPageUp", 2), KeyStroke.getKeyStroke(33, 1), 0);
- this.list.registerKeyboardAction(new PageDownAction(this, "SelectPageDown", 1), KeyStroke.getKeyStroke(34, 0), 0);
- this.list.registerKeyboardAction(new PageDownAction(this, "ExtendSelectPageDown", 2), KeyStroke.getKeyStroke(34, 1), 0);
- SelectAllAction var1 = new SelectAllAction(this, (1)null, "SelectAll");
- this.list.registerKeyboardAction(var1, KeyStroke.getKeyStroke(65, 2), 0);
- this.list.registerKeyboardAction(var1, KeyStroke.getKeyStroke(47, 2), 0);
- this.list.registerKeyboardAction(new ClearSelectionAction(this, (1)null, "ClearSelection"), KeyStroke.getKeyStroke(92, 2), 0);
- }
-
- protected void installListeners() {
- this.focusListener = this.createFocusListener();
- this.mouseInputListener = this.createMouseInputListener();
- this.propertyChangeListener = this.createPropertyChangeListener();
- this.listSelectionListener = this.createListSelectionListener();
- this.listDataListener = this.createListDataListener();
- this.list.addFocusListener(this.focusListener);
- this.list.addMouseListener(this.mouseInputListener);
- this.list.addMouseMotionListener(this.mouseInputListener);
- this.list.addPropertyChangeListener(this.propertyChangeListener);
- ListModel var1 = this.list.getModel();
- if (var1 != null) {
- var1.addListDataListener(this.listDataListener);
- }
-
- ListSelectionModel var2 = this.list.getSelectionModel();
- if (var2 != null) {
- var2.addListSelectionListener(this.listSelectionListener);
- }
-
- }
-
- public void installUI(JComponent var1) {
- this.list = (JList)var1;
- this.rendererPane = new CellRendererPane();
- this.list.add(this.rendererPane);
- this.installDefaults();
- this.installListeners();
- this.installKeyboardActions();
- }
-
- public int locationToIndex(JList var1, Point var2) {
- this.maybeUpdateLayoutState();
- return this.convertYToRow(var2.y);
- }
-
- protected void maybeUpdateLayoutState() {
- if (this.updateLayoutStateNeeded != 0) {
- this.updateLayoutState();
- this.updateLayoutStateNeeded = 0;
- }
-
- }
-
- public void paint(Graphics var1, JComponent var2) {
- this.maybeUpdateLayoutState();
- ListCellRenderer var3 = this.list.getCellRenderer();
- ListModel var4 = this.list.getModel();
- ListSelectionModel var5 = this.list.getSelectionModel();
- if (var3 != null && var4.getSize() != 0) {
- Rectangle var6 = var1.getClipBounds();
- int var7 = this.convertYToRow(var6.y);
- int var8 = this.convertYToRow(var6.y + var6.height - 1);
- if (var7 == -1) {
- var7 = 0;
- }
-
- if (var8 == -1) {
- var8 = var4.getSize() - 1;
- }
-
- Rectangle var9 = this.getCellBounds(this.list, var7, var7);
- if (var9 != null) {
- int var10 = this.list.getLeadSelectionIndex();
-
- for(int var11 = var7; var11 <= var8; ++var11) {
- var9.height = this.getRowHeight(var11);
- var1.setClip(var9.x, var9.y, var9.width, var9.height);
- var1.clipRect(var6.x, var6.y, var6.width, var6.height);
- this.paintCell(var1, var11, var9, var3, var4, var5, var10);
- var9.y += var9.height;
- }
-
- }
- }
- }
-
- protected void paintCell(Graphics var1, int var2, Rectangle var3, ListCellRenderer var4, ListModel var5, ListSelectionModel var6, int var7) {
- Object var8 = var5.getElementAt(var2);
- boolean var9 = this.list.hasFocus() && var2 == var7;
- boolean var10 = var6.isSelectedIndex(var2);
- Component var11 = var4.getListCellRendererComponent(this.list, var8, var2, var10, var9);
- int var12 = var3.x;
- int var13 = var3.y;
- int var14 = var3.width;
- int var15 = var3.height;
- this.rendererPane.paintComponent(var1, var11, this.list, var12, var13, var14, var15, true);
- }
-
- private void redrawList() {
- this.list.revalidate();
- this.list.repaint();
- }
-
- protected void selectNextIndex() {
- int var1 = this.list.getSelectedIndex();
- if (var1 + 1 < this.list.getModel().getSize()) {
- ++var1;
- this.list.setSelectedIndex(var1);
- this.list.ensureIndexIsVisible(var1);
- }
-
- }
-
- protected void selectPreviousIndex() {
- int var1 = this.list.getSelectedIndex();
- if (var1 > 0) {
- --var1;
- this.list.setSelectedIndex(var1);
- this.list.ensureIndexIsVisible(var1);
- }
-
- }
-
- protected void uninstallDefaults() {
- if (this.list.getCellRenderer() instanceof UIResource) {
- this.list.setCellRenderer((ListCellRenderer)null);
- }
-
- }
-
- protected void uninstallKeyboardActions() {
- this.list.unregisterKeyboardAction(KeyStroke.getKeyStroke(38, 0));
- this.list.unregisterKeyboardAction(KeyStroke.getKeyStroke(38, 1));
- this.list.unregisterKeyboardAction(KeyStroke.getKeyStroke(40, 0));
- this.list.unregisterKeyboardAction(KeyStroke.getKeyStroke(40, 1));
- this.list.unregisterKeyboardAction(KeyStroke.getKeyStroke(36, 0));
- this.list.unregisterKeyboardAction(KeyStroke.getKeyStroke(36, 1));
- this.list.unregisterKeyboardAction(KeyStroke.getKeyStroke(35, 0));
- this.list.unregisterKeyboardAction(KeyStroke.getKeyStroke(35, 1));
- this.list.unregisterKeyboardAction(KeyStroke.getKeyStroke(33, 0));
- this.list.unregisterKeyboardAction(KeyStroke.getKeyStroke(33, 1));
- this.list.unregisterKeyboardAction(KeyStroke.getKeyStroke(34, 0));
- this.list.unregisterKeyboardAction(KeyStroke.getKeyStroke(34, 1));
- this.list.unregisterKeyboardAction(KeyStroke.getKeyStroke(65, 2));
- this.list.unregisterKeyboardAction(KeyStroke.getKeyStroke(47, 2));
- this.list.unregisterKeyboardAction(KeyStroke.getKeyStroke(92, 2));
- }
-
- protected void uninstallListeners() {
- this.list.removeFocusListener(this.focusListener);
- this.list.removeMouseListener(this.mouseInputListener);
- this.list.removeMouseMotionListener(this.mouseInputListener);
- this.list.removePropertyChangeListener(this.propertyChangeListener);
- ListModel var1 = this.list.getModel();
- if (var1 != null) {
- var1.removeListDataListener(this.listDataListener);
- }
-
- ListSelectionModel var2 = this.list.getSelectionModel();
- if (var2 != null) {
- var2.removeListSelectionListener(this.listSelectionListener);
- }
-
- this.focusListener = null;
- this.mouseInputListener = null;
- this.listSelectionListener = null;
- this.listDataListener = null;
- this.propertyChangeListener = null;
- }
-
- public void uninstallUI(JComponent var1) {
- this.uninstallDefaults();
- this.uninstallListeners();
- this.uninstallKeyboardActions();
- this.cellWidth = this.cellHeight = -1;
- this.cellHeights = null;
- this.list.remove(this.rendererPane);
- this.rendererPane = null;
- this.list = null;
- }
-
- protected void updateLayoutState() {
- int var1 = this.list.getFixedCellHeight();
- int var2 = this.list.getFixedCellWidth();
- this.cellWidth = var2 != -1 ? var2 : -1;
- if (var1 != -1) {
- this.cellHeight = var1;
- this.cellHeights = null;
- } else {
- this.cellHeight = -1;
- this.cellHeights = new int[this.list.getModel().getSize()];
- }
-
- if (var2 == -1 || var1 == -1) {
- ListModel var3 = this.list.getModel();
- int var4 = var3.getSize();
- ListCellRenderer var5 = this.list.getCellRenderer();
- if (var5 != null) {
- for(int var6 = 0; var6 < var4; ++var6) {
- Object var7 = var3.getElementAt(var6);
- Component var8 = var5.getListCellRendererComponent(this.list, var7, var6, false, false);
- this.rendererPane.add(var8);
- Dimension var9 = var8.getPreferredSize();
- if (var2 == -1) {
- this.cellWidth = Math.max(var9.width, this.cellWidth);
- }
-
- if (var1 == -1) {
- this.cellHeights[var6] = var9.height;
- }
- }
- } else {
- if (this.cellWidth == -1) {
- this.cellWidth = 0;
- }
-
- for(int var10 = 0; var10 < var4; ++var10) {
- this.cellHeights[var10] = 0;
- }
- }
- }
-
- this.list.invalidate();
- }
- }
-