File Source: AddonInfoListCellRenderer.java

         /* 
    P/P   *  Method: com.dmdirc.addons.addonbrowser.AddonInfoListCellRenderer__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.addonbrowser;
    24  
    25  import com.dmdirc.addons.ui_swing.components.text.TextLabel;
    26  import java.awt.Color;
    27  import java.awt.Component;
    28  import java.awt.Font;
    29  import javax.swing.BorderFactory;
    30  import javax.swing.JButton;
    31  import javax.swing.JLabel;
    32  import javax.swing.JList;
    33  import javax.swing.JPanel;
    34  import javax.swing.JSeparator;
    35  import javax.swing.ListCellRenderer;
    36  import net.miginfocom.swing.MigLayout;
    37  
    38  /**
    39   *
    40   */
         /* 
    P/P   *  Method: void com.dmdirc.addons.addonbrowser.AddonInfoListCellRenderer()
          */
    41  public class AddonInfoListCellRenderer extends JPanel 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      /** {@inheritDoc} */
    51      @Override
    52      public Component getListCellRendererComponent(JList list, Object value,
    53              int index, boolean isSelected, boolean cellHasFocus) {
                 /* 
    P/P           *  Method: Component getListCellRendererComponent(JList, Object, int, bool, bool)
                  * 
                  *  Preconditions:
                  *    value != null
                  *    value.type != null
                  * 
                  *  Presumptions:
                  *    init'ed(java.awt.Color.BLACK)
                  *    init'ed(java.awt.Color.GRAY)
                  *    init'ed(java.awt.Color.WHITE)
                  *    java.awt.Font:deriveFont(...)@60 != null
                  *    javax.swing.JLabel:getFont(...)@60 != null
                  * 
                  *  Postconditions:
                  *    return_value == this
                  *    return_value != null
                  */
    54          final AddonInfo info = (AddonInfo) value;
    55          removeAll();
    56          setLayout(new MigLayout("fillx, ins 0"));
    57          setBackground(index % 2 == 1 ? new Color(0xEE, 0xEE, 0xFF) : Color.WHITE);
    58          
    59          JLabel title = new JLabel(info.getTitle());
    60          title.setFont(title.getFont().deriveFont(16f).deriveFont(Font.BOLD));
    61          add(title, "wmin 165, wmax 165, gaptop 5, gapleft 5");
    62          
    63          title = new JLabel(info.getScreenshot());
    64          title.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    65          add(title, "wmin 150, wmax 150, height 150::, wrap, spany 4, gaptop 5, gapright 5");
    66  
    67          title = new JLabel(info.getType().toString() + ", rated "
    68                  + info.getRating() + "/10");
    69          add(title, "gapleft 5, wrap");
    70          
    71          TextLabel label = new TextLabel(info.getDescription());
    72          add(label, "wmax 100%-170, hmax 150, growy, wrap, gapleft 5, gapbottom 5, pushy");
    73          
    74          final JButton button = new JButton("Install");
    75          button.addActionListener(new InstallListener(info));
    76          final boolean installed = info.isInstalled();
    77          
    78          if (installed || !info.isDownloadable()) {
    79              button.setEnabled(false);
    80          }
    81          
    82          add(button, "gapleft 5, split");
    83          
    84          if (installed || !info.isDownloadable()) {
    85              title = new JLabel(installed ? "Already installed" : "No download available");
    86              title.setForeground(Color.GRAY);
    87              add(title);
    88          }
    89          
    90          add(new JSeparator(), "newline, span, growx, pushx, gaptop 5");
    91          
    92          return this;
    93      }
    94  }








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