ScrollList.java
     1: //========================================================================================
     2: //  ScrollList.java
     3: //    en:Scroll list -- It is a modified JScrollPage that has a JList as the view.
     4: //    ja:スクロールリスト -- JListをビューに持つJScrollPaneです。
     5: //  Copyright (C) 2003-2023 Makoto Kamada
     6: //
     7: //  This file is part of the XEiJ (X68000 Emulator in Java).
     8: //  You can use, modify and redistribute the XEiJ if the conditions are met.
     9: //  Read the XEiJ License for more details.
    10: //  https://stdkmd.net/xeij/
    11: //========================================================================================
    12: 
    13: package xeij;
    14: 
    15: import java.awt.*;  //BasicStroke,BorderLayout,BoxLayout,Color,Component,Container,Cursor,Desktop,Dimension,Font,Frame,Graphics,Graphics2D,GraphicsDevice,GraphicsEnvironment,GridLayout,Image,Insets,Paint,Point,Rectangle,RenderingHints,Robot,Shape,Stroke,TexturePaint,Toolkit
    16: import javax.swing.*;  //AbstractSpinnerModel,Box,ButtonGroup,DefaultListModel,ImageIcon,JApplet,JButton,JCheckBox,JCheckBoxMenuItem,JDialog,JFileChooser,JFrame,JLabel,JList,JMenu,JMenuBar,JMenuItem,JPanel,JRadioButton,JScrollPane,JSpinner,JTextArea,JTextField,JTextPane,JViewport,ScrollPaneConstants,SpinnerListModel,SpinnerNumberModel,SwingConstants,SwingUtilities,UIManager,UIDefaults,UnsupportedLookAndFeelException
    17: import javax.swing.event.*;  //CaretListener,ChangeEvent,ChangeListener,DocumentEvent,DocumentListener,ListSelectionListener
    18: 
    19: public class ScrollList extends JScrollPane {
    20: 
    21:   private DefaultListModel<String> listModel;
    22:   private JList<String> list;
    23: 
    24:   @SuppressWarnings ("this-escape") public ScrollList (DefaultListModel<String> listModel) {
    25:     super ();
    26:     this.listModel = listModel;
    27:     list = new JList<String> (listModel);
    28:     setViewportView (list);  //[this-escape]
    29:   }
    30: 
    31:   public Color getBackground () {
    32:     return list == null ? null : list.getBackground ();
    33:   }
    34:   public void setBackground (Color background) {
    35:     super.setBackground (background);
    36:     if (list != null) {
    37:       list.setBackground (background);
    38:     }
    39:   }
    40: 
    41:   public Color getForeground () {
    42:     return list == null ? null : list.getForeground ();
    43:   }
    44:   public void setForeground (Color foreground) {
    45:     super.setForeground (foreground);
    46:     if (list != null) {
    47:       list.setForeground (foreground);
    48:     }
    49:   }
    50: 
    51:   public Font getFont () {
    52:     return list == null ? null : list.getFont ();
    53:   }
    54:   public void setFont (Font font) {
    55:     super.setFont (font);
    56:     if (list != null) {
    57:       list.setFont (font);
    58:     }
    59:   }
    60: 
    61:   public int getVisibleRowCount () {
    62:     return list == null ? 8 : list.getVisibleRowCount ();
    63:   }
    64:   public void setVisibleRowCount (int visibleRowCount) {
    65:     if (list != null) {
    66:       list.setVisibleRowCount (visibleRowCount);
    67:     }
    68:   }
    69: 
    70:   public int getSelectedIndex () {
    71:     return list == null ? -1 : list.getSelectedIndex ();
    72:   }
    73:   public void setSelectedIndex (int selectedIndex) {
    74:     if (list != null) {
    75:       list.setSelectedIndex (selectedIndex);
    76:     }
    77:   }
    78: 
    79:   public int[] getSelectedIndices () {
    80:     return list == null ? new int[0] : list.getSelectedIndices ();
    81:   }
    82:   public void setSelectedIndices (int selectedIndices[]) {
    83:     if (list != null) {
    84:       list.setSelectedIndices (selectedIndices);
    85:     }
    86:   }
    87: 
    88:   public int getSelectionMode () {
    89:     return list == null ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : list.getSelectionMode ();
    90:   }
    91:   public void setSelectionMode (int selectionMode) {
    92:     if (list != null) {
    93:       list.setSelectionMode (selectionMode);
    94:     }
    95:   }
    96: 
    97:   public void addListSelectionListener (ListSelectionListener listener) {
    98:     list.addListSelectionListener (listener);
    99:   }
   100:   public ListSelectionListener[] getListSelectionListeners () {
   101:     return list.getListSelectionListeners ();
   102:   }
   103:   public void removeListSelectionListener (ListSelectionListener listener) {
   104:     list.removeListSelectionListener (listener);
   105:   }
   106: 
   107:   public void setTexts (String[] texts) {
   108:     listModel.clear ();
   109:     for (String text : texts) {
   110:       listModel.addElement (text);
   111:     }
   112:   }
   113:   public void addElement (String element) {
   114:     listModel.addElement (element);
   115:   }
   116:   public void clear () {
   117:     listModel.clear ();
   118:   }
   119: 
   120: }  //class ScrollList
   121: 
   122: 
   123: