File Source: ReorderableJListCellRenderer.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.components.renderers.ReorderableJListCellRenderer__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
     3   *
     4   * Permission is hereby granted, free of charge, to any person obtaining a copy
     5   * of this software and associated documentation files (the "Software"), to deal
     6   * in the Software without restriction, including without limitation the rights
     7   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     8   * copies of the Software, and to permit persons to whom the Software is
     9   * furnished to do so, subject to the following conditions:
    10   *
    11   * The above copyright notice and this permission notice shall be included in
    12   * all copies or substantial portions of the Software.
    13   *
    14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    20   * SOFTWARE.
    21   */
    22  
    23  package com.dmdirc.addons.ui_swing.components.renderers;
    24  
    25  import com.dmdirc.addons.ui_swing.components.reorderablelist.ReorderableJList;
    26  
    27  import java.awt.Component;
    28  
    29  import javax.swing.JLabel;
    30  import javax.swing.JList;
    31  import javax.swing.JPanel;
    32  import javax.swing.JSeparator;
    33  import javax.swing.ListCellRenderer;
    34  import javax.swing.UIManager;
    35  
    36  import net.miginfocom.swing.MigLayout;
    37  
    38  /**
    39   * Renderer for the reorderable JList, procides visual clues to DnD.
    40   */
    41  public class ReorderableJListCellRenderer implements ListCellRenderer {
    42      
    43      /**
    44       * A version number for this class. It should be changed whenever the class
    45       * structure is changed (or anything else that would prevent serialized
    46       * objects being unserialized with the new class).
    47       */
    48      private static final long serialVersionUID = 1;
    49      
    50      /** Parent list. */
    51      private final ReorderableJList parent;
    52      
    53      /**
    54       * Instantiates a new ReorderableJListCellRenderer.
    55       *
    56       * @param parent Parent list
    57       */
    58      public ReorderableJListCellRenderer(final ReorderableJList parent) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.components.renderers.ReorderableJListCellRenderer(ReorderableJList)
                  * 
                  *  Postconditions:
                  *    this.parent == parent
                  *    init'ed(this.parent)
                  */
    59          super();
    60          
    61          this.parent = parent;
    62      }
    63      
    64      /** {@inheritDoc} */
    65      @Override
    66      public Component getListCellRendererComponent(final JList list,
    67              final Object value, final int index, final boolean isSelected,
    68              final boolean cellHasFocus) {
                 /* 
    P/P           *  Method: Component getListCellRendererComponent(JList, Object, int, bool, bool)
                  * 
                  *  Preconditions:
                  *    this.parent != null
                  *    init'ed(this.parent.dropTargetCell)
                  *    value != null
                  *    (soft) init'ed(this.parent.belowTarget)
                  * 
                  *  Postconditions:
                  *    return_value == &new JPanel(getListCellRendererComponent#1)
                  *    new JPanel(getListCellRendererComponent#1) num objects == 1
                  * 
                  *  Test Vectors:
                  *    isSelected: {1}, {0}
                  *    this.parent.belowTarget: {0}, {1}
                  *    this.parent.dropTargetCell: Addr_Set{null}, Inverse{null}
                  *    value == this.parent.dropTargetCell: {0}, {1}
                  */
    69          final JPanel panel = new JPanel();
    70          panel.setLayout(new MigLayout("fill, ins 0"));
    71          final boolean isTargetCell = value == parent.getTargetCell();
    72          
    73          final boolean showSelected = isSelected & (parent.getTargetCell() == null);
    74          
    75          panel.add(new JLabel(value.toString()), "dock center");
    76          
    77          if (showSelected) {
    78              panel.setForeground(UIManager.getColor("List.selectionForeground"));
    79              panel.setBackground(UIManager.getColor("List.selectionBackground"));
    80          } else {
    81              if (isSelected) {
    82                  panel.setForeground(UIManager.getColor("List.selectionForeground"));
    83                  panel.setBackground(UIManager.getColor("List.selectionBackground"));
    84              } else {
    85                  panel.setForeground(UIManager.getColor("List.foreground"));
    86                  panel.setBackground(UIManager.getColor("List.background"));
    87              }
    88          }
    89          
    90          
    91          if (isTargetCell) {
    92              if (parent.getBelowTarget()) {
    93                  panel.add(new JSeparator(), "dock south");
    94              } else {
    95                  panel.add(new JSeparator(), "dock north");
    96              }
    97          }
    98          
    99          return panel;
   100      }
   101  }








SofCheck Inspector Build Version : 2.17854
ReorderableJListCellRenderer.java 2009-Jun-25 01:54:24
ReorderableJListCellRenderer.class 2009-Sep-02 17:04:15