gt:     File getFile(int row) {
context: /*
   * Created by Angel Leon (@gubatron), Alden Torres (aldenml)
   * Copyright (c) 2011-2014, FrostWire(R). All rights reserved.
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
  
  package com.frostwire.gui.library;
  
  import java.awt.Point;
  import java.awt.event.ActionEvent;
  import java.awt.event.KeyAdapter;
  import java.awt.event.KeyEvent;
  import java.awt.event.MouseEvent;
  import java.awt.event.MouseMotionAdapter;
  import java.io.File;
  import java.util.ArrayList;
  import java.util.List;
  
  import javax.swing.Action;
  import javax.swing.DropMode;
  import javax.swing.JComponent;
  import javax.swing.JMenu;
  import javax.swing.JOptionPane;
  import javax.swing.JPopupMenu;
  import javax.swing.JTable;
  import javax.swing.ListSelectionModel;
  import javax.swing.event.MouseInputListener;
  import javax.swing.table.TableCellEditor;
  import javax.swing.table.TableColumn;
  import javax.swing.table.TableColumnModel;
  
  import org.limewire.util.OSUtils;
  import org.limewire.util.StringUtils;
  
  import com.frostwire.alexandria.InternetRadioStation;
  import com.frostwire.alexandria.Playlist;
  import com.frostwire.gui.player.InternetRadioAudioSource;
  import com.frostwire.gui.player.MediaPlayer;
  import com.frostwire.gui.player.MediaSource;
  import com.frostwire.gui.theme.SkinMenu;
  import com.frostwire.gui.theme.SkinMenuItem;
  import com.frostwire.gui.theme.SkinPopupMenu;
  import com.frostwire.gui.theme.ThemeMediator;
  import com.frostwire.uxstats.UXAction;
  import com.frostwire.uxstats.UXStats;
  import com.limegroup.gnutella.MediaType;
  import com.limegroup.gnutella.gui.ButtonRow;
  import com.limegroup.gnutella.gui.GUIMediator;
  import com.limegroup.gnutella.gui.DialogOption;
  import com.limegroup.gnutella.gui.I18n;
  import com.limegroup.gnutella.gui.PaddedPanel;
  import com.limegroup.gnutella.gui.actions.AbstractAction;
  import com.limegroup.gnutella.gui.actions.LimeAction;
  import com.limegroup.gnutella.gui.actions.SearchAction;
  import com.limegroup.gnutella.gui.search.GenericCellEditor;
  import com.limegroup.gnutella.gui.tables.ActionIconAndNameEditor;
  import com.limegroup.gnutella.gui.tables.LimeJTable;
  import com.limegroup.gnutella.gui.tables.LimeTableColumn;
  import com.limegroup.gnutella.gui.util.GUILauncher;
  import com.limegroup.gnutella.gui.util.GUILauncher.LaunchableProvider;
  import com.limegroup.gnutella.settings.TablesHandlerSettings;
  import com.limegroup.gnutella.util.QueryUtils;
  
  /**
   * This class wraps the JTable that displays files in the library,
   * controlling access to the table and the various table properties.
   * It is the Mediator to the Table part of the Library display.
   * 
   * @author gubatron
   * @author aldenml
   * 
   */
  final class LibraryInternetRadioTableMediator extends AbstractLibraryTableMediator<LibraryInternetRadioTableModel, LibraryInternetRadioTableDataLine, InternetRadioStation> {
  
      private static final InternetRadioBookmarkRenderer INTERNET_RADIO_BOOKMARK_RENDERER = new InternetRadioBookmarkRenderer();
      private Action importRadioStationAction;
      private Action copyStreamUrlAction;
      private Action LAUNCH_ACTION;
      private Action DELETE_ACTION;
  
      /**
       * instance, for singelton access
       */
      private static LibraryInternetRadioTableMediator INSTANCE;
  
      public static LibraryInternetRadioTableMediator instance() {
          if (INSTANCE == null) {
              INSTANCE = new LibraryInternetRadioTableMediator();
          }
          return INSTANCE;
      }
  
      /**
       * Build some extra listeners
       */
      protected void buildListeners() {
          super.buildListeners();
  
          importRadioStationAction = new AddRadioStationAction();
          copyStreamUrlAction = new CopyStreamUrlAction();
          LAUNCH_ACTION = new LaunchAction();
          DELETE_ACTION = new RemoveFromStationsAction();
      }
  
      /**
       * Set up the constants
       */
      protected void setupConstants() {
          super.setupConstants();
          MAIN_PANEL = new PaddedPanel();
          DATA_MODEL = new LibraryInternetRadioTableModel();
          TABLE = new LimeJTable(DATA_MODEL);
          Action[] aa = new Action[] { LAUNCH_ACTION, DELETE_ACTION, importRadioStationAction, OPTIONS_ACTION };
          BUTTON_ROW = new ButtonRow(aa, ButtonRow.X_AXIS, ButtonRow.NO_GLUE);
      }
  
      // inherit doc comment
      protected JPopupMenu createPopupMenu() {
          if (TABLE.getSelectionModel().isSelectionEmpty())
              return null;
  
          JPopupMenu menu = new SkinPopupMenu();
  
          menu.add(new SkinMenuItem(LAUNCH_ACTION));
          menu.add(new SkinMenuItem(importRadioStationAction));
          menu.add(new SkinMenuItem(copyStreamUrlAction));
          menu.add(new SkinMenuItem(DELETE_ACTION));
  
          int[] rows = TABLE.getSelectedRows();
  
          DELETE_ACTION.setEnabled(true);
  
          menu.addSeparator();
          LibraryInternetRadioTableDataLine line = DATA_MODEL.get(rows[0]);
          menu.add(createSearchSubMenu(line));
  
          return menu;
      }
  
      @Override
      protected void addListeners() {
          super.addListeners();
  
          TABLE.addKeyListener(new KeyAdapter() {
              @Override
              public void keyReleased(KeyEvent e) {
                  if (LibraryUtils.isRefreshKeyEvent(e)) {
                      //LibraryMediator.instance().getLibraryPlaylists().refreshSelection();
                  }
              }
          });
      }
  
      private JMenu createSearchSubMenu(LibraryInternetRadioTableDataLine dl) {
          JMenu menu = new SkinMenu(I18n.tr("Search"));
  
          if (dl != null) {
              String keywords = QueryUtils.createQueryString(dl.getInitializeObject().getName());
              if (keywords.length() > 0)
                  menu.add(new SkinMenuItem(new SearchAction(keywords)));
          }
  
          if (menu.getItemCount() == 0)
              menu.setEnabled(false);
  
          return menu;
      }
  
      /**
       * Upgrade getScrolledTablePane to public access.
       */
      public JComponent getScrolledTablePane() {
          return super.getScrolledTablePane();
      }
  
      /* Don't display anything for this.  The LibraryMediator will do it. */
      protected void updateSplashScreen() {
      }
  
      /**
       * Note: This is set up for this to work.
       * Polling is not needed though, because updates
       * already generate update events.
       */
      private LibraryInternetRadioTableMediator() {
          super("LIBRARY_INTERNET_RADIO_TABLE");
          setMediaType(MediaType.getAudioMediaType());
  
          LimeTableColumn genreColumn = LibraryInternetRadioTableDataLine.GENRE_COLUMN;
  
          if (genreColumn != null && TablesHandlerSettings.getVisibility(genreColumn.getId(), genreColumn.getDefaultVisibility()).getValue()) {
              DATA_MODEL.sort(LibraryInternetRadioTableDataLine.GENRE_IDX); //ascending
          }
      }
  
      /**
       * Sets up drag & drop for the table.
       */
      protected void setupDragAndDrop() {
          TABLE.setDragEnabled(true);
          TABLE.setDropMode(DropMode.INSERT_ROWS);
          // TABLE.setTransferHandler(new LibraryPlaylistsTableTransferHandler(this));
      }
  
      @Override
      protected void setDefaultRenderers() {
          super.setDefaultRenderers();
          TABLE.setDefaultRenderer(PlayableCell.class, new PlayableCellRenderer());
          TABLE.setDefaultRenderer(InternetRadioBookmark.class, INTERNET_RADIO_BOOKMARK_RENDERER);
      }
  
      /**
       * Sets the default editors.
       */
      protected void setDefaultEditors() {
          TableColumnModel model = TABLE.getColumnModel();
          TableColumn tc;
          tc = model.getColumn(LibraryInternetRadioTableDataLine.WEBSITE_IDX);
          tc.setCellEditor(new ActionIconAndNameEditor());
  
          //Hey Gosling, nice inconsistency here...
          //Why not TABLE.setDefaultCellEditor(Clazz, EditorObj)???
  
          tc = model.getColumn(LibraryInternetRadioTableDataLine.BOOKMARKED_IDX);
          tc.setCellEditor(new InternetRadioBookmarkEditor(new InternetRadioBookmarkRenderer()));
  
          TABLE.addMouseMotionListener(new MouseMotionAdapter() {
              int currentCellColumn = -1;
              int currentCellRow = -1;
  
              @Override
              public void mouseMoved(MouseEvent e) {
                  Point hit = e.getPoint();
                  int hitColumn = TABLE.columnAtPoint(hit);
                  int hitRow = TABLE.rowAtPoint(hit);
                  if (currentCellRow != hitRow || currentCellColumn != hitColumn) {
                      if (TABLE.getCellRenderer(hitRow, hitColumn) instanceof InternetRadioBookmarkRenderer) {
                          TABLE.editCellAt(hitRow, hitColumn);
                      }
                      currentCellColumn = hitColumn;
                      currentCellRow = hitRow;
                  }
              }
          });
          
          tc = model.getColumn(LibraryInternetRadioTableDataLine.ACTIONS_IDX);
          tc.setCellEditor(new GenericCellEditor(new LibraryActionsRenderer()));
      }
  
      /**
       * Cancels all editing of fields in the tree and table.
       */
      void cancelEditing() {
          if (TABLE.isEditing()) {
              TableCellEditor editor = TABLE.getCellEditor();
              editor.cancelCellEditing();
          }
      }
  
      /**
       * Adds the mouse listeners to the wrapped <tt>JTable</tt>.
       *
       * @param listener the <tt>MouseInputListener</tt> that handles mouse events
       *                 for the library
       */
      void addMouseInputListener(final MouseInputListener listener) {
          TABLE.addMouseListener(listener);
          TABLE.addMouseMotionListener(listener);
      }
  
      /**
       * Updates the Table based on the selection of the given table.
       * Perform lookups to remove any store files from the shared folder
       * view and to only display store files in the store view
       */
      void updateTableItems(List<InternetRadioStation> items) {
          if (items == null) {
              return;
          }
  
          clearTable();
          for (final InternetRadioStation item : items) {
              GUIMediator.safeInvokeLater(new Runnable() {
                  public void run() {
                      addUnsorted(item);
                  }
              });
          }
  
          forceResort();
      }
  
      /**
       * Returns the <tt>File</tt> stored at the specified row in the list.
       *
       * @param row the row of the desired <tt>File</tt> instance in the
       *            list
       *
       * @return a <tt>File</tt> instance associated with the specified row
       *         in the table
       */
  