/** Updates the user message based on the current state of the application. */
  private void updateMessages() {
    browseStatusPanel.setBrowseStatus(browseStatus);

    if (!lifeCycleComplete) {
      messageLabel.setText(
          I18n.tr("LimeWire will start your search right after it finishes loading."));
      messagePanel.setVisible(true);
      browseFailedPanel.setVisible(false);
    } else if (!fullyConnected) {
      messageLabel.setText(
          I18n.tr("You might not receive many results until LimeWire finishes loading..."));
      messagePanel.setVisible(true);
      browseFailedPanel.setVisible(false);
    } else if (browseStatus != null && !browseStatus.getState().isOK()) {
      browseFailedPanel.update(
          browseStatus.getState(), browseStatus.getBrowseSearch(), browseStatus.getFailedFriends());
      browseFailedPanel.setVisible(true);
    } else {
      messagePanel.setVisible(false);
      browseFailedPanel.setVisible(false);
    }

    filterPanel.setVisible(!browseFailedPanel.isVisible());
    scrollPane.setVisible(!browseFailedPanel.isVisible());
  }
    public BlockHostsPanel() {
      super(I18n.tr("Block Hosts"));

      setLayout(new MigLayout("gapy 10", "[sg 1][sg 1][]", ""));

      addressTextField = new JTextField(26);
      addButton = new JButton(I18n.tr("Add Address"));
      filterTable = new FilteringTable();
      backListCheckBox = new JCheckBox();
      backListCheckBox.setOpaque(false);
      addButton.addActionListener(new AddAction(addressTextField, filterTable));

      add(
          new JLabel(
              "<html>"
                  + I18n.tr("Block contact with specific people by adding their IP address")
                  + "</html>"),
          "span, growx, wrap");
      add(addressTextField, "gapright 10");
      add(addButton, "wrap");
      add(new JScrollPane(filterTable), "growx, span 2, wrap");
      add(backListCheckBox, "span, split");
      add(
          new MultiLineLabel(description, ReallyAdvancedOptionPanel.MULTI_LINE_LABEL_WIDTH),
          "wrap");
    }
Example #3
0
 private void updateNoSaveLink(NoSave noSave) {
   noSaveState = noSave;
   nosaveLink.setText(
       "<html><u>"
           + (noSaveState == NoSave.ENABLED ? I18n.tr("On the Record") : I18n.tr("Off the Record"))
           + "</u></html>");
 }
 public String getDisplayText() {
   switch (navType) {
     case LIST:
       return sharedFileList.getCollectionName();
     case LIBRARY:
       return I18n.tr("Library");
     case PUBLIC_SHARED:
       return I18n.tr("Public Shared");
     default:
       throw new IllegalStateException("unknown type: " + navType);
   }
 }
  /** Constructs the connections detail table. */
  public ConnectionTable() {
    // Set attributes.
    setIntercellSpacing(new Dimension(1, 0));
    setColumnSelectionAllowed(false);
    setRowSelectionAllowed(true);
    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    setShowHorizontalLines(false);

    // Set up table header to display context menu to configure visible
    // columns.  As recommended in the API Javadoc for isPopupTrigger(),
    // we check both the mousePressed and mouseReleased events.
    getTableHeader().setToolTipText(I18n.tr("Right-click to select columns to display"));
    getTableHeader()
        .addMouseListener(
            new MouseAdapter() {
              @Override
              public void mousePressed(MouseEvent e) {
                if (e.isPopupTrigger()) {
                  showHeaderPopup(e);
                }
              }

              @Override
              public void mouseReleased(MouseEvent e) {
                if (e.isPopupTrigger()) {
                  showHeaderPopup(e);
                }
              }
            });
  }
  /** Creates a custom popup menu for the table header. */
  private JPopupMenu createHeaderPopup() {
    // Create popup menu.
    JPopupMenu popupMenu = new JPopupMenu();

    JMenuItem defaultItem = new JMenuItem();
    defaultItem.setAction(defaultConfigAction);
    popupMenu.add(defaultItem);

    JMenu optionsMenu = new JMenu(I18n.tr("More Options"));
    popupMenu.add(optionsMenu);
    popupMenu.addSeparator();

    JMenuItem autosortItem = new JCheckBoxMenuItem();
    autosortItem.setAction(autosortAction);
    optionsMenu.add(autosortItem);

    JMenuItem tooltipsItem = new JCheckBoxMenuItem();
    tooltipsItem.setAction(tooltipsAction);
    optionsMenu.add(tooltipsItem);

    // Get column headings in default order.
    int columnCount = tableFormat.getColumnCount();
    for (int i = 0; i < columnCount; i++) {
      // Create checkbox menu item for each column heading.
      String headerName = tableFormat.getColumnName(i);
      JMenuItem item = new JCheckBoxMenuItem(headerName, true);
      item.addActionListener(toggleColumnAction);
      popupMenu.add(item);
    }

    return popupMenu;
  }
    public AllowHostsPanel() {
      super(I18n.tr("Allow Hosts"));

      setLayout(new MigLayout("gapy 10", "[sg 1][sg 1][]", ""));

      addressTextField = new JTextField(26);
      addButton = new JButton(I18n.tr("Add Address"));
      filterTable = new FilteringTable();
      addButton.addActionListener(new AddAction(addressTextField, filterTable));

      add(
          new MultiLineLabel(description, ReallyAdvancedOptionPanel.MULTI_LINE_LABEL_WIDTH),
          "span, growx, wrap");
      add(addressTextField, "gapright 10");
      add(addButton, "wrap");
      add(new JScrollPane(filterTable), "growx, span 2");
    }
 @Inject
 public LogoutAction(
     EventBean<FriendConnectionEvent> friendConnectionEventBean,
     FriendAccountConfigurationManager accountManager) {
   super(I18n.tr("Sign out"));
   this.accountManager = accountManager;
   this.friendConnectionEventBean = friendConnectionEventBean;
 }
  /**
   * Download the file offer given a file ID.
   *
   * <p>package-private for testing
   *
   * @param fileId identifier to look up the file offer message
   */
  void downloadFileOffer(String fileId) {
    Map<String, MessageFileOffer> fileOffers = conversation.getFileOfferMessages();
    MessageFileOffer msgWithfileOffer = fileOffers.get(fileId);
    SearchResult file = null;

    try {
      file =
          remoteFileItemFactory.create(
              msgWithfileOffer.getPresence(), msgWithfileOffer.getFileOffer());
      DownloadItem dl = downloader.addDownload(null, Collections.singletonList(file));

      // Track download states by adding listeners to dl item
      addPropertyListener(dl, msgWithfileOffer);

    } catch (DownloadException e) {
      final SearchResult remoteFileItem = file;
      final MessageFileOffer messageFileOffer = msgWithfileOffer;
      downloadExceptionHandler
          .get()
          .handleDownloadException(
              new DownloadAction() {
                @Override
                public void download(File saveFile, boolean overwrite) throws DownloadException {
                  DownloadItem dl =
                      downloader.addDownload(
                          null, Collections.singletonList(remoteFileItem), saveFile, overwrite);
                  addPropertyListener(dl, messageFileOffer);
                }

                @Override
                public void downloadCanceled(DownloadException ignored) {
                  // nothing to do
                }
              },
              e,
              true);
    } catch (InvalidDataException ide) {
      // this means the FileMetaData we received isn't well-formed.
      LOG.error("Unable to access remote file", ide);
      FocusJOptionPane.showMessageDialog(
          null,
          I18n.tr("Unable to access remote file"),
          I18n.tr("Hyperlink"),
          JOptionPane.WARNING_MESSAGE);
    }
  }
  /**
   * Allows a soft localised refresh of the text within the panel based on the language selected in
   * the combo box.
   */
  private void setTextContents() {
    String heading = I18n.tr("Some Legal Stuff");
    String bodyText1 =
        I18n.tr(
            "<html><body>LimeWire Basic and LimeWire PRO are peer-to-peer programs for sharing authorized files only. Copyright laws may forbid obtaining or distributing certain copyrighted content. Learn more about <a href=\"{0}\">Copyright Information</a></body></html>",
            copyrightURL);
    String copyInfringementText = I18n.tr("Copyright Infringement");
    String privacyText = I18n.tr("Privacy Policy");
    String licenseText = I18n.tr("License");
    String agreementText =
        I18n.tr(
            "By clicking \"I Agree\", you agree that you have read, understand and assent to the terms of the License Agreement and Privacy Policy. You also agree that you will not use LimeWire for copyright infringement.");
    String languageText = I18n.tr("Choose your language");
    String policiesText = I18n.tr("Policies Governing Your Use:");

    Action exitAction =
        new AbstractAction(I18n.tr("Exit")) {
          @Override
          public void actionPerformed(ActionEvent e) {
            finish(false);
          }
        };

    Action agreeAction =
        new AbstractAction(I18n.tr("I Agree")) {
          @Override
          public void actionPerformed(ActionEvent e) {
            finish(true);
          }
        };

    headingLabel.setText(heading);
    bodyLabel.setText(bodyText1);
    copyrightLabel.setText(copyInfringementText);
    policiesLabel.setText(policiesText);
    licenseButton.setText(licenseText);
    privacyButton.setText(privacyText);
    agreeLabel.setText(agreementText);
    languageLabel.setText(languageText);
    exitButton.setAction(exitAction);
    agreeButton.setAction(agreeAction);
  }
Example #11
0
  @Inject
  public StoreMenu(Application application, Navigator navigator, StoreMediator storeMediator) {

    super(I18n.tr("&Store"));

    this.application = application;
    this.navigator = navigator;
    this.storeMediator = storeMediator;

    navigator.createNavItem(NavCategory.LIMEWIRE, StoreMediator.NAME, storeMediator);
  }
  public FilterFileExtensionsOptionPanel(SpamManager spamManager, Action okAction) {
    this.spamManager = spamManager;
    setLayout(new MigLayout("gapy 10"));

    keywordTextField = new JTextField(30);
    addKeywordButton = new JButton(I18n.tr("Add Extension"));

    filterTable =
        new FilterTable(
            GlazedListsSwingFactory.eventTableModel(
                eventList, new FilterTableFormat(I18n.tr("Extensions"))));
    okButton = new JButton(okAction);
    addKeywordButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String text = keywordTextField.getText();
            if (text == null || text.trim().length() == 0) return;
            if (!eventList.contains(text)) {
              if (text.charAt(0) != '.') text = "." + text;
              eventList.add(text);
            }
            keywordTextField.setText("");
          }
        });

    defaultButton = new JButton(new DefaultAction());

    add(
        new MultiLineLabel(
            I18n.tr(
                "LimeWire will not show files with the following extensions in your search results"),
            300),
        "span, wrap");
    add(keywordTextField, "gapright 10");
    add(addKeywordButton, "wrap");
    add(new JScrollPane(filterTable), "span 2, grow, wrap");

    add(defaultButton, "alignx left");
    add(okButton, "alignx right");
  }
  private class AllowHostsPanel extends OptionPanel {

    private JTextField addressTextField;
    private JButton addButton;
    private FilteringTable filterTable;

    private final String description =
        I18n.tr("Override the block list and allow specific people by adding their IP address");

    public AllowHostsPanel() {
      super(I18n.tr("Allow Hosts"));

      setLayout(new MigLayout("gapy 10", "[sg 1][sg 1][]", ""));

      addressTextField = new JTextField(26);
      addButton = new JButton(I18n.tr("Add Address"));
      filterTable = new FilteringTable();
      addButton.addActionListener(new AddAction(addressTextField, filterTable));

      add(
          new MultiLineLabel(description, ReallyAdvancedOptionPanel.MULTI_LINE_LABEL_WIDTH),
          "span, growx, wrap");
      add(addressTextField, "gapright 10");
      add(addButton, "wrap");
      add(new JScrollPane(filterTable), "growx, span 2");
    }

    @Override
    boolean applyOptions() {
      List<String> list = filterTable.getFilterModel().getModel();

      FilterSettings.WHITE_LISTED_IP_ADDRESSES.set(list.toArray(new String[list.size()]));
      spamManager.reloadIPFilter();
      return false;
    }

    @Override
    boolean hasChanged() {
      List model = Arrays.asList(FilterSettings.WHITE_LISTED_IP_ADDRESSES.get());
      return !model.equals(filterTable.getFilterModel().getModel());
    }

    @Override
    public void initOptions() {
      String[] allowedIps = FilterSettings.WHITE_LISTED_IP_ADDRESSES.get();
      FilterModel model = new FilterModel(new ArrayList<String>(Arrays.asList(allowedIps)));
      filterTable.setModel(model);
    }
  }
    public FriendShareCheckBox(LocalFileList friendFileList, LocalFileItem localFileItem) {
      super(I18n.tr("Share"));
      this.friendFileList = friendFileList;
      this.localFile = localFileItem;
      setSelected(friendFileList.contains(localFileItem.getFile()));

      addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              if (isSelected()) {
                FriendShareCheckBox.this.friendFileList.addFile(localFile.getFile());
              } else {
                FriendShareCheckBox.this.friendFileList.removeFile(localFile.getFile());
              }
            }
          });
    }
    public RemoveButtonRenderer(final FilteringTable table) {
      // lower case since hyperlink
      super(I18n.tr("remove"));

      setBorder(BorderFactory.createEmptyBorder());
      setContentAreaFilled(false);
      FontUtils.underline(this);
      setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

      addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              table.getFilterModel().removeIP(table.getSelectedRow());
              cancelCellEditing();
              table.repaint();
            }
          });
    }
Example #16
0
  @Inject
  public FileMenu(
      RecentDownloadsMenu recentDownloadsMenu,
      Provider<OpenFileAction> openFileActionProvider,
      Provider<OpenLinkAction> openLinkActionProvider,
      Provider<AddFileAction> addFileActionProvider,
      Provider<FixStalledDownloadsAction> fixStalledDownloadsActionProvider,
      Provider<ExitAfterTransferAction> exitAfterTransferActionProvider,
      Provider<ExitAction> exitActionProvider) {

    super(I18n.tr("&File"));

    this.recentDownloadsMenu = recentDownloadsMenu;
    this.openFileActionProvider = openFileActionProvider;
    this.openLinkActionProvider = openLinkActionProvider;
    this.addFileActionProvider = addFileActionProvider;
    this.fixStalledDownloadsActionProvider = fixStalledDownloadsActionProvider;
    this.exitAfterTransferActionProvider = exitAfterTransferActionProvider;
    this.exitActionProvider = exitActionProvider;
  }
Example #17
0
  @Inject
  public HelpMenu(
      Application application,
      final IconManager iconManager,
      final TrayNotifier trayNotifier,
      final Navigator navigator,
      final StorePanel storePanel) {
    super(I18n.tr("&Help"));

    add(
        new AbstractAction(I18n.tr("&Using LimeWire")) {
          @Override
          public void actionPerformed(ActionEvent e) {
            NativeLaunchUtils.openURL("http://www.limewire.com/client_redirect/?page=support");
          }
        });

    add(
        new AbstractAction(I18n.tr("&FAQ")) {
          @Override
          public void actionPerformed(ActionEvent e) {
            NativeLaunchUtils.openURL("http://www.limewire.com/client_redirect/?page=faq");
          }
        });

    if (!application.isProVersion()) {
      addSeparator();
      add(
          new AbstractAction(I18n.tr("Get personalized &tech support")) {
            @Override
            public void actionPerformed(ActionEvent e) {
              NativeLaunchUtils.openURL("http://www.limewire.com/client_redirect/?page=gopro");
            }
          });
    }

    if (!OSUtils.isMacOSX()) {
      addSeparator();
      add(
          new AbstractAction(I18n.tr("&About LimeWire...")) {
            @Override
            public void actionPerformed(ActionEvent e) {
              new AboutDisplayEvent().publish();
            }
          });
    }

    if (application.isTestingVersion()) {
      addSeparator();
      add(
          new AbstractAction("Error Test") {
            @Override
            public void actionPerformed(ActionEvent e) {
              throw new RuntimeException("Test Error");
            }
          });

      add(
          new AbstractAction("Tray Test") {
            @Override
            public void actionPerformed(ActionEvent e) {
              if (new Random().nextBoolean()) {
                Notification notification =
                    new Notification(
                        "This is a not tooo long message title",
                        "This is a super looooooooooooooooooooooooooooooooong message.",
                        this);
                trayNotifier.showMessage(notification);
              } else if (new Random().nextBoolean()) {
                Notification notification =
                    new Notification(
                        "Long super loooooooooooooong loooon loooong message title",
                        "This is a another very loooong  loooong loooong loooong loooong loooong loooong loooong loooong message.",
                        this);
                trayNotifier.showMessage(notification);
              } else {
                Notification notification = new Notification("Short Title", "Short message.", this);
                trayNotifier.showMessage(notification);
              }
            }
          });
    }
  }
  /**
   * Updates the title icon and text in the container. For search results, the title includes the
   * category name, search title, and result counts.
   */
  private void updateTitle() {
    // Get result counts.
    int total = searchResultsModel.getUnfilteredList().size();
    int actual = searchResultsModel.getFilteredList().size();

    if (browseTitle != null) {
      // Set browse title.
      searchTitleLabel.setText(
          (actual == total)
              ?
              // {0}: browse title, {1}: total count
              I18n.tr("Browse {0} ({1})", browseTitle, total)
              :
              // {0}: browse title, {1}: actual count, {2}: total count
              I18n.tr("Browse {0} - Showing {1} of {2}", browseTitle, actual, total));

    } else {
      // Get search category and title.
      SearchCategory displayCategory = searchResultsModel.getSelectedCategory();
      String title = searchResultsModel.getSearchTitle();

      // Set title icon based on category.
      Icon icon =
          (displayCategory == SearchCategory.ALL)
              ? null
              : categoryIconManager.getIcon(displayCategory.getCategory());
      searchTitleLabel.setIcon(icon);

      // Set title text.
      switch (displayCategory) {
        case ALL:
          searchTitleLabel.setText(
              (actual == total)
                  ?
                  // {0}: search title, {1}: total count
                  I18n.tr("All results for {0} ({1})", title, total)
                  :
                  // {0}: search title, {1}: actual count, {2}: total count
                  I18n.tr("All results for {0} - Showing {1} of {2}", title, actual, total));
          break;
        case AUDIO:
          searchTitleLabel.setText(
              (actual == total)
                  ?
                  // {0}: search title, {1}: total count
                  I18n.tr("Audio results for {0} ({1})", title, total)
                  :
                  // {0}: search title, {1}: actual count, {2}: total count
                  I18n.tr("Audio results for {0} - Showing {1} of {2}", title, actual, total));
          break;
        case VIDEO:
          searchTitleLabel.setText(
              (actual == total)
                  ?
                  // {0}: search title, {1}: total count
                  I18n.tr("Video results for {0} ({1})", title, total)
                  :
                  // {0}: search title, {1}: actual count, {2}: total count
                  I18n.tr("Video results for {0} - Showing {1} of {2}", title, actual, total));
          break;
        case IMAGE:
          searchTitleLabel.setText(
              (actual == total)
                  ?
                  // {0}: search title, {1}: total count
                  I18n.tr("Image results for {0} ({1})", title, total)
                  :
                  // {0}: search title, {1}: actual count, {2}: total count
                  I18n.tr("Image results for {0} - Showing {1} of {2}", title, actual, total));
          break;
        case DOCUMENT:
          searchTitleLabel.setText(
              (actual == total)
                  ?
                  // {0}: search title, {1}: total count
                  I18n.tr("Document results for {0} ({1})", title, total)
                  :
                  // {0}: search title, {1}: actual count, {2}: total count
                  I18n.tr("Document results for {0} - Showing {1} of {2}", title, actual, total));
          break;
        case PROGRAM:
          searchTitleLabel.setText(
              (actual == total)
                  ?
                  // {0}: search title, {1}: total count
                  I18n.tr("Program results for {0} ({1})", title, total)
                  :
                  // {0}: search title, {1}: actual count, {2}: total count
                  I18n.tr("Program results for {0} - Showing {1} of {2}", title, actual, total));
          break;
        case OTHER:
          searchTitleLabel.setText(
              (actual == total)
                  ?
                  // {0}: search title, {1}: total count
                  I18n.tr("Other results for {0} ({1})", title, total)
                  :
                  // {0}: search title, {1}: actual count, {2}: total count
                  I18n.tr("Other results for {0} - Showing {1} of {2}", title, actual, total));
          break;
        default:
          throw new IllegalStateException("Invalid search category " + displayCategory);
      }
    }
  }
  private void initialize() {
    boolean singleFile = fileItems.size() == 1;
    boolean multiFile = fileItems.size() > 1;

    LocalFileItem firstItem = fileItems.get(0);

    boolean playActionEnabled = singleFile;
    boolean launchActionEnabled = singleFile;
    boolean locateActionEnabled = singleFile && !firstItem.isIncomplete();
    boolean viewFileInfoEnabled = singleFile;
    boolean shareActionEnabled = false;
    boolean removeActionEnabled = false;
    boolean deleteActionEnabled = false;

    for (LocalFileItem localFileItem : fileItems) {
      if (localFileItem.isShareable()) {
        shareActionEnabled = true;
        break;
      }
    }

    for (LocalFileItem localFileItem : fileItems) {
      if (!localFileItem.isIncomplete()) {
        removeActionEnabled = true;
        deleteActionEnabled = true;
        break;
      }
    }

    removeAll();
    switch (category) {
      case AUDIO:
      case VIDEO:
        add(new PlayAction(libraryNavigator, new Catalog(category), firstItem))
            .setEnabled(playActionEnabled);
        break;
      case IMAGE:
      case DOCUMENT:
        add(new LaunchFileAction(I18n.tr("View"), firstItem)).setEnabled(launchActionEnabled);
        break;
      case PROGRAM:
      case OTHER:
        add(new LocateFileAction(firstItem)).setEnabled(locateActionEnabled);
    }

    if (multiFile) {
      add(new FriendShareAction(friendFileList, createFileItemArray()))
          .setEnabled(shareActionEnabled);
      add(new FriendUnshareAction(friendFileList, createFileItemArray()))
          .setEnabled(shareActionEnabled);
    } else {
      add(new FriendShareCheckBox(friendFileList, firstItem)).setEnabled(shareActionEnabled);
    }

    addSeparator();
    if (category != Category.PROGRAM && category != Category.OTHER) {
      add(new LocateFileAction(firstItem)).setEnabled(locateActionEnabled);
    }

    add(new RemoveAction(createFileItemArray(), libraryManager)).setEnabled(removeActionEnabled);
    add(new DeleteAction(createFileItemArray(), libraryManager)).setEnabled(deleteActionEnabled);

    addSeparator();
    add(new ViewFileInfoAction(firstItem, propertiesFactory)).setEnabled(viewFileInfoEnabled);
  }
 public FriendUnshareAction(LocalFileList friendFileList, LocalFileItem[] localFileItems) {
   super(I18n.tr("Unshare"));
   this.friendFileList = friendFileList;
   this.localFileItems = localFileItems;
 }
Example #21
0
  @Override
  public void createMenuItems() {
    add(
        new AbstractAction(I18n.tr("&Home")) {
          @Override
          public void actionPerformed(ActionEvent e) {
            storeVisited++;
            navigator.getNavItem(NavCategory.LIMEWIRE, StoreMediator.NAME).select();
            storeMediator.getComponent().loadDefaultUrl();
          }
        });

    add(
        new StoreUrlAction(
            I18n.tr("&Log In"),
            "https://www.store.limewire.com/store/app/pages/account/LogIn/noDest/1/"));
    add(
        new StoreUrlAction(
            I18n.tr("&Sign Up"),
            "https://www.store.limewire.com/store/app/pages/register/RegisterSelection/"));

    JMenu genres = new MnemonicMenu(I18n.tr("&Genres"));
    genres.add(
        new StoreUrlAction(
            I18n.tr("&Alternative"),
            "http://www.store.limewire.com/store/app/pages/genre/GenreHome/genreId/31/"));
    genres.add(
        new StoreUrlAction(
            I18n.tr("&Country"),
            "http://www.store.limewire.com/store/app/pages/genre/GenreHome/genreId/14/"));
    genres.add(
        new StoreUrlAction(
            I18n.tr("&Electronica"),
            "http://www.store.limewire.com/store/app/pages/genre/GenreHome/genreId/20/"));
    genres.add(
        new StoreUrlAction(
            I18n.tr("&Folk"),
            "http://www.store.limewire.com/store/app/pages/genre/GenreHome/genreId/3/"));
    genres.add(
        new StoreUrlAction(
            I18n.tr("&Jazz"),
            "http://www.store.limewire.com/store/app/pages/genre/GenreHome/genreId/6/"));
    genres.add(
        new StoreUrlAction(
            I18n.tr("&Pop"),
            "http://www.store.limewire.com/store/app/pages/genre/GenreHome/genreId/27/"));
    genres.add(
        new StoreUrlAction(
            I18n.tr("&Rap"),
            "http://www.store.limewire.com/store/app/pages/genre/GenreHome/genreId/8/"));
    genres.add(
        new StoreUrlAction(
            I18n.tr("&Rhythm and Blues"),
            "http://www.store.limewire.com/store/app/pages/genre/GenreHome/genreId/26/"));
    genres.add(
        new StoreUrlAction(
            I18n.tr("&Rock"),
            "http://www.store.limewire.com/store/app/pages/genre/GenreHome/genreId/1/"));
    genres.add(
        new StoreUrlAction(
            I18n.tr("&World"),
            "http://www.store.limewire.com/store/app/pages/genre/GenreHome/genreId/2/"));
    add(genres);

    //        add(new StoreUrlAction(I18n.tr("&Free Songs"), "http://www.store.limewire.com/free"));
    add(
        new StoreUrlAction(
            I18n.tr("LimeWire Store Hel&p"),
            "http://www.store.limewire.com/store/app/pages/help/Help/"));

    // The history menu is not working on Mac OS X. Calls to retrieve it go into native code and
    // never return.
    if (!OSUtils.isMacOSX()) {
      final JMenu history = new MnemonicMenu(I18n.tr("His&tory"));
      history.addMenuListener(
          new MenuListener() {
            @Override
            public void menuCanceled(MenuEvent e) {
              history.removeAll();
            }

            @Override
            public void menuDeselected(MenuEvent e) {
              history.removeAll();
            }

            @Override
            public void menuSelected(MenuEvent e) {
              AtomicReference<Integer> currentPosition = new AtomicReference<Integer>();
              for (HistoryEntry entry : storeMediator.getComponent().getHistory(currentPosition)) {
                JMenuItem item = history.add(new HistoryAction(entry));
                if (entry.getIndex() == currentPosition.get()) {
                  FontUtils.bold(item);
                }
              }
            }
          });
      add(history);
    }
  }
 @Override
 public String getHeaderText() {
   return I18n.tr("Size");
 }
/**
 * The table that displays the connections details. ConnectionTable installs a header popup menu to
 * allow the user to configure the visible columns.
 */
public class ConnectionTable extends MouseableTable {

  /** List of connections. */
  private TransformedList<ConnectionItem, ConnectionItem> connectionList;

  /** Table format for connections details. */
  private ConnectionTableFormat tableFormat;

  /** Disabled menu item. */
  private JMenuItem disabledMenuItem;

  /** Context menu for table header. */
  private JPopupMenu headerPopup;

  /** Text array for connection tooltip. */
  private String[] tipArray;

  private Action defaultConfigAction = new DefaultConfigAction(I18n.tr("Revert To Default"));
  private Action autosortAction = new AutosortAction(I18n.tr("Sort Automatically"));
  private Action tooltipsAction = new TooltipsAction(I18n.tr("Extended Tooltips"));
  private Action toggleColumnAction = new ToggleColumnAction();

  /** Constructs the connections detail table. */
  public ConnectionTable() {
    // Set attributes.
    setIntercellSpacing(new Dimension(1, 0));
    setColumnSelectionAllowed(false);
    setRowSelectionAllowed(true);
    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    setShowHorizontalLines(false);

    // Set up table header to display context menu to configure visible
    // columns.  As recommended in the API Javadoc for isPopupTrigger(),
    // we check both the mousePressed and mouseReleased events.
    getTableHeader().setToolTipText(I18n.tr("Right-click to select columns to display"));
    getTableHeader()
        .addMouseListener(
            new MouseAdapter() {
              @Override
              public void mousePressed(MouseEvent e) {
                if (e.isPopupTrigger()) {
                  showHeaderPopup(e);
                }
              }

              @Override
              public void mouseReleased(MouseEvent e) {
                if (e.isPopupTrigger()) {
                  showHeaderPopup(e);
                }
              }
            });
  }

  @Override
  protected void setTableHeaderRenderer() {
    // use default table headers
  }

  /** Creates the default cell renderers. */
  @Override
  protected void createDefaultRenderers() {
    super.createDefaultRenderers();

    // Install custom renderer for Object values.
    setDefaultRenderer(Object.class, new ObjectCellRenderer());
  }

  /**
   * Creates the tooltip component. This method is called by the tooltip manager whenever a new
   * tooltip is needed.
   */
  @Override
  public JToolTip createToolTip() {
    // Create tooltip component.
    MultiLineToolTip toolTip = new MultiLineToolTip();
    toolTip.setComponent(this);

    // Set text array.
    toolTip.setToolTipArray(tipArray);

    return toolTip;
  }

  /** Returns the tooltip text at the location of the specified mouse event. */
  @Override
  public String getToolTipText(MouseEvent e) {
    Point p = e.getPoint();
    int row = rowAtPoint(p);
    int col = columnAtPoint(p);

    // Get tooltip text if action is enabled.
    if (Boolean.TRUE.equals(tooltipsAction.getValue(Action.SELECTED_KEY)) && (row >= 0)) {
      // Get connection item and tooltip text array.
      ConnectionItem item = connectionList.get(convertRowIndexToModel(row));
      tipArray = tableFormat.getToolTipArray(item);

      // Return row/col text so tooltip manager will create new tooltip
      // for each table cell.
      return (row + "," + col);
    }

    // Reset tooltip array and return null.
    tipArray = new String[0];
    return null;
  }

  /** Returns true if the table should be sorted in response to the specified table model event. */
  @Override
  protected boolean shouldSortOnChange(TableModelEvent e) {
    if ((autosortAction == null)
        || (Boolean.TRUE.equals(autosortAction.getValue(Action.SELECTED_KEY)))) {
      return super.shouldSortOnChange(e);
    } else {
      return false;
    }
  }

  /** Sets the visibility of the column with the specified name. */
  public void setColumnVisible(String name, boolean visible) {
    // Get column and set visibility.
    TableColumnExt column = getColumnExt(name);
    column.setVisible(visible);

    // Get column title.
    String columnTitle = column.getTitle();

    // Find checkbox menu item with matching title.
    JCheckBoxMenuItem matchingItem = null;
    int itemCount = headerPopup.getComponentCount();
    for (int i = 0; i < itemCount; i++) {
      Component menuComponent = headerPopup.getComponent(i);
      if (menuComponent instanceof JCheckBoxMenuItem) {
        JCheckBoxMenuItem item = (JCheckBoxMenuItem) menuComponent;
        String itemTitle = item.getText();
        if (itemTitle.equals(columnTitle)) {
          matchingItem = item;
          break;
        }
      }
    }

    // Select matching menu item.
    if (matchingItem != null) {
      matchingItem.setSelected(visible);
    }
  }

  /** Sets the width of the column with the specified name. */
  public void setColumnWidth(String name, int width) {
    getColumnExt(name).setPreferredWidth(width);
  }

  /** Initializes the data model using the specified connection list and table format. */
  public void setEventList(
      TransformedList<ConnectionItem, ConnectionItem> connectionList,
      ConnectionTableFormat tableFormat) {

    if (tableFormat == null) {
      throw new IllegalArgumentException("tableFormat cannot be null");
    }

    this.connectionList = connectionList;
    this.tableFormat = tableFormat;

    // Set table model using event list and table format.
    setModel(new DefaultEventTableModel<ConnectionItem>(connectionList, tableFormat));

    // Create header popup menu.
    headerPopup = createHeaderPopup();

    // Initialize column visibility.
    resetTableColumns();
  }

  /** Clears the data model and releases resources used by the event list. */
  public void clearEventList() {
    // Get table model and dispose resources.
    TableModel tableModel = getModel();
    if (tableModel instanceof DefaultEventTableModel) {
      ((DefaultEventTableModel) tableModel).dispose();
    }

    // Set default model to remove old reference.
    setModel(new DefaultTableModel());

    // Dispose connection list.
    connectionList.dispose();
    connectionList = null;
  }

  /** Returns an array of the selected connections. */
  public ConnectionItem[] getSelectedConnections() {
    // Get selected rows.
    int[] rows = getSelectedRows();

    // Create result array.
    ConnectionItem[] items = new ConnectionItem[rows.length];
    for (int i = 0; i < rows.length; i++) {
      items[i] = connectionList.get(convertRowIndexToModel(rows[i]));
    }

    // Return result array.
    return items;
  }

  /** Updates the table by firing a table model event. */
  public void refresh() {
    TableModel model = getModel();
    if (model instanceof AbstractTableModel) {
      ((AbstractTableModel) model).fireTableRowsUpdated(0, getRowCount() - 1);
    }
  }

  /** Resets the table columns and attributes to their default configuration. */
  public void resetTableColumns() {
    // Reset column widths and visibility.
    for (int col = 0; col < tableFormat.getColumnCount(); col++) {
      ConnectionColumn column = tableFormat.getColumn(col);
      setColumnWidth(column.getName(), column.getWidth());
      setColumnVisible(column.getName(), column.isVisible());
    }

    // Reset attributes.
    autosortAction.putValue(Action.SELECTED_KEY, Boolean.TRUE);
    tooltipsAction.putValue(Action.SELECTED_KEY, Boolean.FALSE);
  }

  /** Creates a custom popup menu for the table header. */
  private JPopupMenu createHeaderPopup() {
    // Create popup menu.
    JPopupMenu popupMenu = new JPopupMenu();

    JMenuItem defaultItem = new JMenuItem();
    defaultItem.setAction(defaultConfigAction);
    popupMenu.add(defaultItem);

    JMenu optionsMenu = new JMenu(I18n.tr("More Options"));
    popupMenu.add(optionsMenu);
    popupMenu.addSeparator();

    JMenuItem autosortItem = new JCheckBoxMenuItem();
    autosortItem.setAction(autosortAction);
    optionsMenu.add(autosortItem);

    JMenuItem tooltipsItem = new JCheckBoxMenuItem();
    tooltipsItem.setAction(tooltipsAction);
    optionsMenu.add(tooltipsItem);

    // Get column headings in default order.
    int columnCount = tableFormat.getColumnCount();
    for (int i = 0; i < columnCount; i++) {
      // Create checkbox menu item for each column heading.
      String headerName = tableFormat.getColumnName(i);
      JMenuItem item = new JCheckBoxMenuItem(headerName, true);
      item.addActionListener(toggleColumnAction);
      popupMenu.add(item);
    }

    return popupMenu;
  }

  /** Displays the header popup menu at the location of the specified mouse event. */
  private void showHeaderPopup(MouseEvent e) {
    if (headerPopup != null) {
      headerPopup.show((Component) e.getSource(), e.getX(), e.getY());
    }
  }

  /**
   * Updates the header popup menu by enabling/disabling menu items based on the number of visible
   * columns.
   */
  private void updateHeaderPopup() {
    // Get number of visible columns.
    int visibleColumnCount = getColumnCount(false);

    // If only one visible column, then disable its menu item.
    if (visibleColumnCount == 1) {
      // Find the only visible column.
      int allColumnCount = getColumnCount(true);
      TableColumnExt column = null;
      for (int i = 0; i < allColumnCount; i++) {
        column = getColumnExt(i);
        if (column.isVisible()) {
          break;
        }
      }

      // Get menu item name from column title.
      assert column != null;
      String headerName = column.getTitle();

      // Find matching menu item, and disable so user cannot hide column.
      Component[] components = headerPopup.getComponents();
      for (Component component : components) {
        if (component instanceof JMenuItem) {
          JMenuItem item = (JMenuItem) component;
          // Disable matching menu item.
          if (item.getText().equals(headerName)) {
            item.setEnabled(false);
            disabledMenuItem = item;
            break;
          }
        }
      }

    } else if (disabledMenuItem != null) {
      // Re-enable previously disabled menu item because more than one
      // column is visible.
      disabledMenuItem.setEnabled(true);
    }
  }

  /** Action to reset table to default configuration. */
  private class DefaultConfigAction extends AbstractAction {

    public DefaultConfigAction(String name) {
      super(name);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
      resetTableColumns();
    }
  }

  /** Action to toggle option to automatically sort by column. */
  private class AutosortAction extends AbstractAction {

    public AutosortAction(String name) {
      super(name);
      putValue(SELECTED_KEY, Boolean.TRUE);
    }

    @Override
    public void actionPerformed(ActionEvent e) {}
  }

  /** Action to toggle option to display tooltips. */
  private class TooltipsAction extends AbstractAction {

    public TooltipsAction(String name) {
      super(name);
      putValue(SELECTED_KEY, Boolean.FALSE);
    }

    @Override
    public void actionPerformed(ActionEvent e) {}
  }

  /** Action that toggles the visibility of the selected table column. */
  private class ToggleColumnAction extends AbstractAction {

    @Override
    public void actionPerformed(ActionEvent e) {
      // Get table column.
      String name = e.getActionCommand();
      TableColumnExt selectedColumn = getColumnExt(name);

      // Toggle column visibility.
      boolean visible = selectedColumn.isVisible();
      selectedColumn.setVisible(!visible);

      // Update popup menu.
      updateHeaderPopup();

      // Resize table columns to fit.
      packAll();
    }
  }

  /** Cell renderer for Object values. */
  private static class ObjectCellRenderer extends DefaultTableRenderer {

    @Override
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

      // Retrieve renderer component.
      Component renderer =
          super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

      // Set renderer attributes.  The border is set so that the focused
      // cell border is never seen.
      if (renderer instanceof JLabel) {
        ((JLabel) renderer).setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
      }

      return renderer;
    }
  }

  /** Tooltip component that displays multiple lines using a text array. */
  private static class MultiLineToolTip extends JToolTip {
    private static final int LINE_LEN = 72;

    private String[] tipArray;

    /**
     * Returns the tooltip text generated using the text array. The result is an HTML string. This
     * overrides the superclass method to ignore the tip text set by the tooltip manager.
     *
     * <p>Note that when the mouse moves to a new table cell, <code>getToolTipText(MouseEvent)
     * </code> returns a different value, causing the tooltip manager to create a new tooltip and
     * set its tip text. This method allows the table to control the tooltip, which may not change
     * when the mouse moves between cells in the same row.
     */
    @Override
    public String getTipText() {
      if ((tipArray != null) && (tipArray.length > 0)) {
        // Create buffer to build string.
        StringBuilder buf = new StringBuilder("<html>");
        boolean firstLine = true;

        // Add each text line with breaks between lines.  Long lines
        // are wrapped onto multiple lines.
        for (String text : tipArray) {
          while (text.length() > LINE_LEN) {
            buf.append(firstLine ? "" : "<br/>");
            buf.append(text.substring(0, LINE_LEN));
            firstLine = false;
            text = text.substring(LINE_LEN);
          }
          buf.append(firstLine ? "" : "<br/>");
          buf.append(text);
          firstLine = false;
        }

        // Return result string.
        buf.append("</html>");
        return buf.toString();

      } else {
        return null;
      }
    }

    /** Returns the array of text lines in the tooltip. */
    public String[] getToolTipArray() {
      return tipArray;
    }

    /** Sets the array of text lines in the tooltips. */
    public void setToolTipArray(String[] tipArray) {
      this.tipArray = tipArray;
    }
  }
}
 public DefaultAction() {
   putValue(Action.NAME, I18n.tr("Use Default"));
   putValue(Action.SHORT_DESCRIPTION, I18n.tr("Revert to default settings"));
 }
 @Inject
 public AudioTableFormat() {
   super(
       ACTION_INDEX,
       "LIBRARY_AUDIO_TABLE",
       ARTIST_INDEX,
       true,
       new ColumnStateInfo[] {
         new ColumnStateInfo(PLAY_INDEX, "LIBRARY_AUDIO_PLAY", "", 16, 16, true, false),
         new ColumnStateInfo(TITLE_INDEX, "LIBRARY_AUDIO_TITLE", I18n.tr("Name"), 274, true, true),
         new ColumnStateInfo(
             ARTIST_INDEX, "LIBRARY_AUDIO_ARTIST", I18n.tr("Artist"), 182, true, true),
         new ColumnStateInfo(
             ALBUM_INDEX, "LIBRARY_AUDIO_ALBUM", I18n.tr("Album"), 163, true, true),
         new ColumnStateInfo(
             LENGTH_INDEX, "LIBRARY_AUDIO_LENGTH", I18n.tr("Length"), 59, true, true),
         new ColumnStateInfo(
             GENRE_INDEX, "LIBRARY_AUDIO_GENRE", I18n.tr("Genre"), 60, false, true),
         new ColumnStateInfo(
             BITRATE_INDEX, "LIBRARY_AUDIO_BITRATE", I18n.tr("Bitrate"), 50, false, true),
         new ColumnStateInfo(SIZE_INDEX, "LIBRARY_AUDIO_SIZE", I18n.tr("Size"), 50, false, true),
         new ColumnStateInfo(
             FILENAME_INDEX, "LIBRARY_AUDIO_FILENAME", I18n.tr("Filename"), 100, false, true),
         new ColumnStateInfo(
             TRACK_INDEX, "LIBRARY_AUDIO_TRACK", I18n.tr("Track"), 50, false, true),
         new ColumnStateInfo(YEAR_INDEX, "LIBRARY_AUDIO_YEAR", I18n.tr("Year"), 50, false, true),
         new ColumnStateInfo(
             DESCRIPTION_INDEX,
             "LIBRARY_AUDIO_DESCRIPTION",
             I18n.tr("Description"),
             100,
             false,
             false),
         new ColumnStateInfo(HIT_INDEX, "LIBRARY_AUDIO_HITS", I18n.tr("Hits"), 100, false, true),
         new ColumnStateInfo(
             UPLOADS_INDEX, "LIBRARY_AUDIO_UPLOADS", I18n.tr("Uploads"), 100, false, true),
         new ColumnStateInfo(
             UPLOAD_ATTEMPTS_INDEX,
             "LIBRARY_AUDIO_UPLOAD_ATTEMPTS",
             I18n.tr("Upload attempts"),
             200,
             false,
             true),
         new ColumnStateInfo(
             PATH_INDEX, "LIBRARY_AUDIO_PATH", I18n.tr("Location"), 200, false, true),
         new ColumnStateInfo(
             ACTION_INDEX, "LIBRARY_AUDIO_ACTION", I18n.tr(" "), 22, 22, true, false)
       });
 }
Example #26
0
  public HelpAction(Application application) {
    this.application = application;

    putValue(Action.NAME, I18n.tr("Help"));
    putValue(Action.SHORT_DESCRIPTION, I18n.tr("Learn more..."));
  }
Example #27
0
 public DownloadFromFriendLibraryAction() {
   super("<html><u>" + I18n.tr("Browse Files") + "</u></html>");
 }
  private class BlockHostsPanel extends OptionPanel {

    private JTextField addressTextField;
    private JButton addButton;
    private FilteringTable filterTable;
    private JCheckBox backListCheckBox;
    private String description =
        I18n.tr("Use LimeWire's blacklist to protect you from harmful people");

    public BlockHostsPanel() {
      super(I18n.tr("Block Hosts"));

      setLayout(new MigLayout("gapy 10", "[sg 1][sg 1][]", ""));

      addressTextField = new JTextField(26);
      addButton = new JButton(I18n.tr("Add Address"));
      filterTable = new FilteringTable();
      backListCheckBox = new JCheckBox();
      backListCheckBox.setOpaque(false);
      addButton.addActionListener(new AddAction(addressTextField, filterTable));

      add(
          new JLabel(
              "<html>"
                  + I18n.tr("Block contact with specific people by adding their IP address")
                  + "</html>"),
          "span, growx, wrap");
      add(addressTextField, "gapright 10");
      add(addButton, "wrap");
      add(new JScrollPane(filterTable), "growx, span 2, wrap");
      add(backListCheckBox, "span, split");
      add(
          new MultiLineLabel(description, ReallyAdvancedOptionPanel.MULTI_LINE_LABEL_WIDTH),
          "wrap");
    }

    @Override
    boolean applyOptions() {
      List<String> list = filterTable.getFilterModel().getModel();

      FilterSettings.USE_NETWORK_FILTER.setValue(backListCheckBox.isSelected());
      FilterSettings.BLACK_LISTED_IP_ADDRESSES.set(list.toArray(new String[list.size()]));
      spamManager.reloadIPFilter();
      return false;
    }

    @Override
    boolean hasChanged() {
      List model = Arrays.asList(FilterSettings.BLACK_LISTED_IP_ADDRESSES.get());
      return backListCheckBox.isSelected() != FilterSettings.USE_NETWORK_FILTER.getValue()
          || !model.equals(filterTable.getFilterModel().getModel());
    }

    @Override
    public void initOptions() {
      String[] bannedIps = FilterSettings.BLACK_LISTED_IP_ADDRESSES.get();
      FilterModel model = new FilterModel(new ArrayList<String>(Arrays.asList(bannedIps)));
      filterTable.setModel(model);

      backListCheckBox.setSelected(FilterSettings.USE_NETWORK_FILTER.getValue());
    }
  }
 /** Constructs a PlaylistTableFormat. */
 public PlaylistTableFormat() {
   super(
       -1,
       "LIBRARY_PLAYLIST_TABLE",
       ARTIST_INDEX,
       true,
       new ColumnStateInfo[] {
         new ColumnStateInfo(PLAY_INDEX, "LIBRARY_PLAYLIST_PLAY", "", 25, true, false),
         new ColumnStateInfo(
             NUMBER_INDEX, "LIBRARY_PLAYLIST_NUMBER", I18n.tr("#"), 50, true, true),
         new ColumnStateInfo(
             TITLE_INDEX, "LIBRARY_PLAYLIST_TITLE", I18n.tr("Name"), 278, true, true),
         new ColumnStateInfo(
             ARTIST_INDEX, "LIBRARY_PLAYLIST_ARTIST", I18n.tr("Artist"), 120, true, true),
         new ColumnStateInfo(
             ALBUM_INDEX, "LIBRARY_PLAYLIST_ALBUM", I18n.tr("Album"), 180, true, true),
         new ColumnStateInfo(
             LENGTH_INDEX, "LIBRARY_PLAYLIST_LENGTH", I18n.tr("Length"), 60, true, true),
         new ColumnStateInfo(
             GENRE_INDEX, "LIBRARY_PLAYLIST_GENRE", I18n.tr("Genre"), 60, false, true),
         new ColumnStateInfo(
             BITRATE_INDEX, "LIBRARY_PLAYLIST_BITRATE", I18n.tr("Bitrate"), 50, false, true),
         new ColumnStateInfo(
             SIZE_INDEX, "LIBRARY_PLAYLIST_SIZE", I18n.tr("Size"), 50, false, true),
         new ColumnStateInfo(
             FILENAME_INDEX, "LIBRARY_PLAYLIST_FILENAME", I18n.tr("Filename"), 100, false, true),
         new ColumnStateInfo(
             TRACK_INDEX, "LIBRARY_PLAYLIST_TRACK", I18n.tr("Track"), 50, false, true),
         new ColumnStateInfo(
             YEAR_INDEX, "LIBRARY_PLAYLIST_YEAR", I18n.tr("Year"), 50, false, true),
         new ColumnStateInfo(
             QUALITY_INDEX, "LIBRARY_PLAYLIST_QUALITY", I18n.tr("Quality"), 60, false, true),
         new ColumnStateInfo(
             DESCRIPTION_INDEX,
             "LIBRARY_PLAYLIST_DESCRIPTION",
             I18n.tr("Description"),
             100,
             false,
             true),
         new ColumnStateInfo(
             HIT_INDEX, "LIBRARY_PLAYLIST_HITS", I18n.tr("Hits"), 100, false, true),
         new ColumnStateInfo(
             UPLOADS_INDEX, "LIBRARY_PLAYLIST_UPLOADS", I18n.tr("Uploads"), 100, false, true),
         new ColumnStateInfo(
             UPLOAD_ATTEMPTS_INDEX,
             "LIBRARY_PLAYLIST_UPLOAD_ATTEMPTS",
             I18n.tr("Upload attempts"),
             200,
             false,
             true),
         new ColumnStateInfo(
             PATH_INDEX, "LIBRARY_PLAYLIST_PATH", I18n.tr("Location"), 200, false, true)
       });
 }