Package ui.tabs.search

Source Code of ui.tabs.search.SearchSubTab$CloseListener

package ui.tabs.search;


import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collection;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;

import main.ClientMain;

import common.files.MultiNamedFile;

import search.SearchRequest;
import ui.misc.CloseButton;


public class SearchSubTab extends JPanel
{
  private static final long serialVersionUID = 6190826908973125184L;

  private Label label;
  private DownloadableFileJTable resultsTable;

  private SearchRequest request;

  public SearchSubTab(String searchText)
  {
    super();
    setLayout(new BorderLayout());

    label = new Label(searchText);

    resultsTable = new DownloadableFileJTable();
    add(resultsTable.getTableHeader(), BorderLayout.PAGE_START);
    add(new JScrollPane(resultsTable), BorderLayout.CENTER);
  }

  private class Label extends JPanel
  {
    private static final long serialVersionUID = 8663196657673691056L;

    public Label(String title)
    {
      setOpaque(false);

      BorderLayout layout = new BorderLayout();
      layout.setHgap(4);
      setLayout(layout);

      JLabel titleLabel = new JLabel(title);
      add(titleLabel, BorderLayout.CENTER);

      CloseButton closeButton = new CloseButton(new CloseListener());
      add(closeButton, BorderLayout.EAST);
    }

  }

  private class CloseListener implements ActionListener
  {
    public void actionPerformed(ActionEvent event)
    {
      ClientMain.getSearchManager().removeRequest(request);
    }

  }

  public void setRequest(SearchRequest request)
  {
    this.request = request;
  }

  public void addToPane(JTabbedPane pane)
  {
    synchronized (pane)
    {
      pane.addTab(null, null, this);

      int tabIndex = pane.indexOfComponent(this);
      pane.setTabComponentAt(tabIndex, label);
    }
  }

  public void addResults(Collection<MultiNamedFile> results)
  {
    for (MultiNamedFile entry : results)
    {
      resultsTable.getModel().add(entry);
    }
  }

}
TOP

Related Classes of ui.tabs.search.SearchSubTab$CloseListener

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.