Beispiel #1
0
  public JointPriorDialog(JFrame frame, BeautiOptions options) {
    this.frame = frame;

    this.options = options;

    priorSettingsPanel = new PriorSettingsPanel(frame);

    nameField.setColumns(30);

    parametersTableModel = new ParametersTableModel();
    //        TableSorter sorter = new TableSorter(traitsTableModel);
    //        traitsTable = new JTable(sorter);
    //        sorter.setTableHeader(traitsTable.getTableHeader());
    parametersTable = new JTable(parametersTableModel);

    parametersTable.getTableHeader().setReorderingAllowed(false);
    parametersTable.getTableHeader().setResizingAllowed(false);
    //        traitsTable.getTableHeader().setDefaultRenderer(
    //                new HeaderRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4)));

    parametersTable
        .getSelectionModel()
        .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    parametersTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent evt) {
                parametersSelectionChanged();
              }
            });
  }
  public void fixSelection(int rows[]) {
    if (rows.length == 0) return;

    table.getSelectionModel().setValueIsAdjusting(true);

    int rowcount = table.getModel().getRowCount();

    for (int x = 0; x < rows.length; x++) {
      if (rows[x] < rowcount) {
        table.getSelectionModel().addSelectionInterval(rows[x], rows[x]);
      }
    }

    table.getSelectionModel().setValueIsAdjusting(false);
  }
    public EventAdapter(JTextField tf, JTable tbl) {

      boolean autoIme = Project.getBoolean("autoIme", true);
      if (autoIme) {
        tf.addFocusListener(AutoKanjiListener.getInstance());
      } else {
        tf.addFocusListener(AutoRomanListener.getInstance());
      }
      tf.addActionListener(EventAdapter.this);

      tbl.getSelectionModel().addListSelectionListener(EventAdapter.this);
      tbl.addMouseListener(EventAdapter.this);
    }
 private void addListSelectionListener(final JTable table, final JButton deleteDOTItemButton) {
   final ListSelectionModel selectionModel = table.getSelectionModel();
   ListSelectionListener listSelectionListener =
       new ListSelectionListener() {
         public void valueChanged(ListSelectionEvent e) {
           final int selectedRow = table.getSelectedRow();
           if (selectedRow == -1) {
             deleteDOTItemButton.setEnabled(false);
           } else {
             deleteDOTItemButton.setEnabled(_dotDefinitionDialogFrame.isEditable());
           }
         }
       };
   selectionModel.addListSelectionListener(listSelectionListener);
 }
  private void rebuildPopup(
      @NotNull final UsageViewImpl usageView,
      @NotNull final List<Usage> usages,
      @NotNull List<UsageNode> nodes,
      @NotNull final JTable table,
      @NotNull final JBPopup popup,
      @NotNull final UsageViewPresentation presentation,
      @NotNull final RelativePoint popupPosition,
      boolean findUsagesInProgress) {
    ApplicationManager.getApplication().assertIsDispatchThread();

    boolean shouldShowMoreSeparator = usages.contains(MORE_USAGES_SEPARATOR);
    if (shouldShowMoreSeparator) {
      nodes.add(MORE_USAGES_SEPARATOR_NODE);
    }

    String title = presentation.getTabText();
    String fullTitle =
        getFullTitle(
            usages,
            title,
            shouldShowMoreSeparator,
            nodes.size() - (shouldShowMoreSeparator ? 1 : 0),
            findUsagesInProgress);

    ((AbstractPopup) popup).setCaption(fullTitle);

    List<UsageNode> data = collectData(usages, nodes, usageView, presentation);
    MyModel tableModel = setTableModel(table, usageView, data);
    List<UsageNode> existingData = tableModel.getItems();

    int row = table.getSelectedRow();

    int newSelection = updateModel(tableModel, existingData, data, row == -1 ? 0 : row);
    if (newSelection < 0 || newSelection >= tableModel.getRowCount()) {
      TableScrollingUtil.ensureSelectionExists(table);
      newSelection = table.getSelectedRow();
    } else {
      table.getSelectionModel().setSelectionInterval(newSelection, newSelection);
    }
    TableScrollingUtil.ensureIndexIsVisible(table, newSelection, 0);

    setSizeAndDimensions(table, popup, popupPosition, data);
  }
  /** Initial method to populate the insuranceCompaniesTable */
  public void loadTable() {

    Map<Integer, InsuranceCompany> data = model.getInsuranceCompanies();
    tableData = new InsuranceCompanyTableModel(data);
    insuranceCompaniesTable.setModel(tableData);
    insuranceCompaniesTable.getColumnModel().getColumn(0).setMaxWidth(50);
    insuranceCompaniesTable
        .getSelectionModel()
        .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    // Check if db is empty and proceed with selecting only if the table is populated
    if (insuranceCompaniesTable.getRowCount() > 0) {
      // Set selected company according to selected row on load
      selectRow();
      int selectedCompanyId =
          Integer.valueOf(
              (String)
                  insuranceCompaniesTable.getValueAt(insuranceCompaniesTable.getSelectedRow(), 0));
    }
  }
 private void maybeGrabSelection() {
   if (table.getSelectedRow() != -1) {
     // Grab selection
     ListSelectionModel rowSel = table.getSelectionModel();
     ListSelectionModel colSel = table.getColumnModel().getSelectionModel();
     if (!haveAnchor()) {
       //        System.err.println("Updating from table's selection");
       setSelection(
           rowSel.getAnchorSelectionIndex(), rowSel.getLeadSelectionIndex(),
           colSel.getAnchorSelectionIndex(), colSel.getLeadSelectionIndex());
     } else {
       //        System.err.println("Updating lead from table's selection");
       setSelection(
           getRowAnchor(), rowSel.getLeadSelectionIndex(),
           getColAnchor(), colSel.getLeadSelectionIndex());
     }
     //      printSelection();
   }
 }
Beispiel #8
0
  public void setContent(String cat) {
    cat = cat.trim();
    selectAllCB.setVisible(false);
    selectAllCB.setSelected(false);
    deleteBut.setVisible(false);
    restoreBut.setVisible(false);
    refreshBut.setVisible(true);
    Object columns[] = null;
    int count = 0;
    switch (cat) {
      case "Inbox":
        columns = new Object[] {"", "From", "Date", "Subject", "Content"};
        count = Database.getCount("Inbox");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='inbox' ORDER BY msg_id desc");
        ;
        break;
      case "SentMail":
        columns = new Object[] {"", "To", "Date", "Subject", "Content"};
        count = Database.getCount("Sentmail");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='sentmail' ORDER BY msg_id desc");
        break;
      case "Draft":
        columns = new Object[] {"", "To", "Date", "Subject", "Content"};
        count = Database.getCount("Draft");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='draft' ORDER BY msg_id desc");
        break;
      case "Outbox":
        columns = new Object[] {"", "To", "Date", "Subject", "Content"};
        count = Database.getCount("Outbox");
        workingSet = db.getData("SELECT * FROM messages WHERE tag='outbox' ORDER BY msg_id desc");
        break;
      case "Trash":
        //                restoreBut.setVisible(true);
        columns = new Object[] {"", "To/From", "Date", "Subject", "Content"};
        count = Database.getCount("Trash");
        workingSet =
            db.getData(
                "SELECT * FROM messages,trash WHERE messages.tag='trash' and messages.msg_id=trash.msg_id ORDER BY deleted_at desc");
        break;
      default:
        System.out.println("in default case");
    }
    if (count > 0) {
      selectAllCB.setVisible(true);
      rows = new Object[count][];
      msgID = new int[count];
      try {
        workingSet.beforeFirst();
        for (int i = 0; i < count && workingSet.next(); i++) {
          msgID[i] = workingSet.getInt(1);
          rows[i] =
              new Object[] {
                false,
                workingSet.getString(2),
                workingSet.getDate(3),
                workingSet.getString(4),
                workingSet.getString(5)
              };
        }
      } catch (SQLException sqlExc) {
        JOptionPane.showMessageDialog(null, sqlExc, "EXCEPTION", JOptionPane.ERROR_MESSAGE);
        sqlExc.printStackTrace();
      }

      tableModel = new MyDefaultTableModel(rows, columns);
      table = new JTable(tableModel);
      table.getSelectionModel().addListSelectionListener(this);
      table.addMouseListener(this);
      table.getTableHeader().setOpaque(true);
      table.getTableHeader().setReorderingAllowed(false);
      //            table.getTableHeader().setBackground(Color.blue);
      table.getTableHeader().setForeground(Color.blue);
      //        table.setRowSelectionAllowed(false);
      //            table.setColumnSelectionAllowed(false);
      table.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 14));
      table.setRowHeight(20);
      table.setFillsViewportHeight(true);

      TableColumn column = null;
      for (int i = 0; i < 5; i++) {
        column = table.getColumnModel().getColumn(i);
        if (i == 0) {
          column.setPreferredWidth(6);
        } else if (i == 3) {
          column.setPreferredWidth(250);
        } else if (i == 4) {
          column.setPreferredWidth(450);
        } else {
          column.setPreferredWidth(40);
        }
      }
      table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);

      remove(contentPan);
      contentPan = new JScrollPane(table);
      contentPan.setBackground(Color.orange);
      contentPan.setOpaque(true);
      contentPan.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
      add(contentPan, "Center");
      Home.home.homeFrame.setVisible(true);
    } else {
      JPanel centPan = new JPanel(new GridBagLayout());
      centPan.setBackground(new Color(52, 86, 70));
      JLabel label = new JLabel("No Messages In This Category");
      label.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 22));
      label.setForeground(Color.orange);
      centPan.add(label);
      remove(contentPan);
      contentPan = new JScrollPane(centPan);
      contentPan.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
      add(contentPan, "Center");
      contentPan.repaint();
    }
  }
Beispiel #9
0
  /**
   * Create a new, empty, not-visible TaxRef window. Really just activates the setup frame and setup
   * memory monitor components, then starts things off.
   */
  public MainFrame() {
    setupMemoryMonitor();

    // Set up the main frame.
    mainFrame = new JFrame(basicTitle);
    mainFrame.setJMenuBar(setupMenuBar());
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Set up the JTable.
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setSelectionBackground(COLOR_SELECTION_BACKGROUND);
    table.setShowGrid(true);

    // Add a blank table model so that the component renders properly on
    // startup.
    table.setModel(blankDataModel);

    // Add a list selection listener so we can tell the matchInfoPanel
    // that a new name was selected.
    table
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                if (currentCSV == null) return;

                int row = table.getSelectedRow();
                int column = table.getSelectedColumn();

                columnInfoPanel.columnChanged(column);

                Object o = table.getModel().getValueAt(row, column);
                if (Name.class.isAssignableFrom(o.getClass())) {
                  matchInfoPanel.nameSelected(currentCSV.getRowIndex(), (Name) o, row, column);
                } else {
                  matchInfoPanel.nameSelected(currentCSV.getRowIndex(), null, -1, -1);
                }
              }
            });

    // Set up the left panel (table + matchInfoPanel)
    JPanel leftPanel = new JPanel();

    matchInfoPanel = new MatchInformationPanel(this);
    leftPanel.setLayout(new BorderLayout());
    leftPanel.add(matchInfoPanel, BorderLayout.SOUTH);
    leftPanel.add(new JScrollPane(table));

    // Set up the right panel (columnInfoPanel)
    JPanel rightPanel = new JPanel();

    columnInfoPanel = new ColumnInformationPanel(this);

    progressBar.setStringPainted(true);

    rightPanel.setLayout(new BorderLayout());
    rightPanel.add(columnInfoPanel);
    rightPanel.add(progressBar, BorderLayout.SOUTH);

    // Set up a JSplitPane to split the panels up.
    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, leftPanel, rightPanel);
    split.setResizeWeight(1);
    mainFrame.add(split);
    mainFrame.pack();

    // Set up a drop target so we can pick up files
    mainFrame.setDropTarget(
        new DropTarget(
            mainFrame,
            new DropTargetAdapter() {
              @Override
              public void dragEnter(DropTargetDragEvent dtde) {
                // Accept any drags.
                dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
              }

              @Override
              public void dragOver(DropTargetDragEvent dtde) {}

              @Override
              public void dropActionChanged(DropTargetDragEvent dtde) {}

              @Override
              public void dragExit(DropTargetEvent dte) {}

              @Override
              public void drop(DropTargetDropEvent dtde) {
                // Accept a drop as long as its File List.

                if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                  dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

                  Transferable t = dtde.getTransferable();

                  try {
                    java.util.List<File> files =
                        (java.util.List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);

                    // If we're given multiple files, pick up only the last file and load that.
                    File f = files.get(files.size() - 1);
                    loadFile(f, DarwinCSV.FILE_CSV_DELIMITED);

                  } catch (UnsupportedFlavorException ex) {
                    dtde.dropComplete(false);

                  } catch (IOException ex) {
                    dtde.dropComplete(false);
                  }
                }
              }
            }));
  }
 public void removeSelectionListener(ListSelectionListener listener) {
   logItemTable.getSelectionModel().removeListSelectionListener(listener);
 }
 public void addSelectionListener(ListSelectionListener listener) {
   logItemTable.getSelectionModel().addListSelectionListener(listener);
 }
 /** Constructor (create and layout page) */
 public SOAPMonitorPage(String host_name) {
   host = host_name;
   // Set up default filter (show all messages)
   filter = new SOAPMonitorFilter();
   // Use borders to help improve appearance
   etched_border = new EtchedBorder();
   // Build top portion of split (list panel)
   model = new SOAPMonitorTableModel();
   table = new JTable(model);
   table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   table.setRowSelectionInterval(0, 0);
   table.setPreferredScrollableViewportSize(new Dimension(600, 96));
   table.getSelectionModel().addListSelectionListener(this);
   scroll = new JScrollPane(table);
   remove_button = new JButton("Remove");
   remove_button.addActionListener(this);
   remove_button.setEnabled(false);
   remove_all_button = new JButton("Remove All");
   remove_all_button.addActionListener(this);
   filter_button = new JButton("Filter ...");
   filter_button.addActionListener(this);
   list_buttons = new JPanel();
   list_buttons.setLayout(new FlowLayout());
   list_buttons.add(remove_button);
   list_buttons.add(remove_all_button);
   list_buttons.add(filter_button);
   list_panel = new JPanel();
   list_panel.setLayout(new BorderLayout());
   list_panel.add(scroll, BorderLayout.CENTER);
   list_panel.add(list_buttons, BorderLayout.SOUTH);
   list_panel.setBorder(empty_border);
   // Build bottom portion of split (message details)
   details_time = new JLabel("Time: ", SwingConstants.RIGHT);
   details_target = new JLabel("Target Service: ", SwingConstants.RIGHT);
   details_status = new JLabel("Status: ", SwingConstants.RIGHT);
   details_time_value = new JLabel();
   details_target_value = new JLabel();
   details_status_value = new JLabel();
   Dimension preferred_size = details_time.getPreferredSize();
   preferred_size.width = 1;
   details_time.setPreferredSize(preferred_size);
   details_target.setPreferredSize(preferred_size);
   details_status.setPreferredSize(preferred_size);
   details_time_value.setPreferredSize(preferred_size);
   details_target_value.setPreferredSize(preferred_size);
   details_status_value.setPreferredSize(preferred_size);
   details_header = new JPanel();
   details_header_layout = new GridBagLayout();
   details_header.setLayout(details_header_layout);
   details_header_constraints = new GridBagConstraints();
   details_header_constraints.fill = GridBagConstraints.BOTH;
   details_header_constraints.weightx = 0.5;
   details_header_layout.setConstraints(details_time, details_header_constraints);
   details_header.add(details_time);
   details_header_layout.setConstraints(details_time_value, details_header_constraints);
   details_header.add(details_time_value);
   details_header_layout.setConstraints(details_target, details_header_constraints);
   details_header.add(details_target);
   details_header_constraints.weightx = 1.0;
   details_header_layout.setConstraints(details_target_value, details_header_constraints);
   details_header.add(details_target_value);
   details_header_constraints.weightx = .5;
   details_header_layout.setConstraints(details_status, details_header_constraints);
   details_header.add(details_status);
   details_header_layout.setConstraints(details_status_value, details_header_constraints);
   details_header.add(details_status_value);
   details_header.setBorder(etched_border);
   request_label = new JLabel("SOAP Request", SwingConstants.CENTER);
   request_text = new SOAPMonitorTextArea();
   request_text.setEditable(false);
   request_scroll = new JScrollPane(request_text);
   request_panel = new JPanel();
   request_panel.setLayout(new BorderLayout());
   request_panel.add(request_label, BorderLayout.NORTH);
   request_panel.add(request_scroll, BorderLayout.CENTER);
   response_label = new JLabel("SOAP Response", SwingConstants.CENTER);
   response_text = new SOAPMonitorTextArea();
   response_text.setEditable(false);
   response_scroll = new JScrollPane(response_text);
   response_panel = new JPanel();
   response_panel.setLayout(new BorderLayout());
   response_panel.add(response_label, BorderLayout.NORTH);
   response_panel.add(response_scroll, BorderLayout.CENTER);
   details_soap = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
   details_soap.setTopComponent(request_panel);
   details_soap.setRightComponent(response_panel);
   details_soap.setResizeWeight(.5);
   details_panel = new JPanel();
   layout_button = new JButton("Switch Layout");
   layout_button.addActionListener(this);
   reflow_xml = new JCheckBox("Reflow XML text");
   reflow_xml.addActionListener(this);
   details_buttons = new JPanel();
   details_buttons.setLayout(new FlowLayout());
   details_buttons.add(reflow_xml);
   details_buttons.add(layout_button);
   details_panel.setLayout(new BorderLayout());
   details_panel.add(details_header, BorderLayout.NORTH);
   details_panel.add(details_soap, BorderLayout.CENTER);
   details_panel.add(details_buttons, BorderLayout.SOUTH);
   details_panel.setBorder(empty_border);
   // Add the two parts to the age split pane
   split = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
   split.setTopComponent(list_panel);
   split.setRightComponent(details_panel);
   // Build status area
   start_button = new JButton("Start");
   start_button.addActionListener(this);
   stop_button = new JButton("Stop");
   stop_button.addActionListener(this);
   status_buttons = new JPanel();
   status_buttons.setLayout(new FlowLayout());
   status_buttons.add(start_button);
   status_buttons.add(stop_button);
   status_text = new JLabel();
   status_text.setBorder(new BevelBorder(BevelBorder.LOWERED));
   status_text_panel = new JPanel();
   status_text_panel.setLayout(new BorderLayout());
   status_text_panel.add(status_text, BorderLayout.CENTER);
   status_text_panel.setBorder(empty_border);
   status_area = new JPanel();
   status_area.setLayout(new BorderLayout());
   status_area.add(status_buttons, BorderLayout.WEST);
   status_area.add(status_text_panel, BorderLayout.CENTER);
   status_area.setBorder(etched_border);
   // Add the split and status area to page
   setLayout(new BorderLayout());
   add(split, BorderLayout.CENTER);
   add(status_area, BorderLayout.SOUTH);
 }
  /** Creates the view's listeners */
  public void createListeners() {

    // If the table selection changes, set the currentInsuranceCompany accordingly (Listens to
    // keyboard and mouse)
    insuranceCompaniesTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent e) {
                if ((e.getValueIsAdjusting() == false)
                    && (insuranceCompaniesTable.getSelectedRow() != -1)) {
                  int selectedCompanyId =
                      Integer.valueOf(
                          (String)
                              insuranceCompaniesTable.getValueAt(
                                  insuranceCompaniesTable.getSelectedRow(), 0));
                  controller.selectInsuranceCompany(selectedCompanyId);
                }
              }
            });

    // Add a new InsuranceCompany
    addInsuranceCompanyButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            controller.addInsuranceCompany();
          }
        });

    // Save an InsuranceCompany
    saveInsuranceCompanyButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Check if a row is selected
            if (insuranceCompaniesTable.getSelectedRow() != -1) {
              int selectedCompanyId =
                  Integer.parseInt(
                      (String)
                          insuranceCompaniesTable.getValueAt(
                              insuranceCompaniesTable.getSelectedRow(), 0));
              String[] newData = {
                companyNameTextField.getText(),
                telephoneTextField.getText(),
                urlTextField.getText(),
                insuranceTypesTextField.getText(),
                percentageTextField.getText(),
                generalDescriptionTextField.getText()
              };

              // Input validation
              boolean checkInput = true;
              for (String input : newData) {
                if ((input.equals("")) || (input.equals(":"))) {
                  checkInput = false;
                }
              }
              // Use regex pattern to check double values
              if (!percentageTextField.getText().matches("(-|\\+)?[0-9]+(\\.[0-9]+)?")) {
                checkInput = false;
              }

              if (checkInput) {
                recordEdited = insuranceCompaniesTable.getSelectedRow();
                controller.updateInsuranceCompany(selectedCompanyId, newData);
              } else {
                showErrorMsg(
                    "Error Saving Insurance Company",
                    "Please enter proper values:\n(Fields cannot be blank or contain \":\")");
              }

            } else {
              showErrorMsg("Error Saving Insurance Company", "Please select a valid table row.");
            }
          }
        });

    // Delete an InsuranceCompany
    deleteInsuranceCompanyButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Check if a row is selected
            if (insuranceCompaniesTable.getSelectedRow() != -1) {
              int i =
                  JOptionPane.showConfirmDialog(
                      null,
                      "<html>Are you sure you want to delete following Insurance Company:<br><br><b>ID: "
                          + (String)
                              insuranceCompaniesTable.getValueAt(
                                  insuranceCompaniesTable.getSelectedRow(), 0)
                          + " - "
                          + (String)
                              insuranceCompaniesTable.getValueAt(
                                  insuranceCompaniesTable.getSelectedRow(), 1)
                          + "</b></html>",
                      "Delete Insurance Company",
                      JOptionPane.YES_NO_OPTION);

              if (i == JOptionPane.YES_OPTION) {
                int selectedCompanyId =
                    Integer.parseInt(
                        (String)
                            insuranceCompaniesTable.getValueAt(
                                insuranceCompaniesTable.getSelectedRow(), 0));
                controller.deleteInsuranceCompany(selectedCompanyId);
                searchTextField.setText("");
              }
            } else {
              showErrorMsg("Error Deleting Insurance Company", "Please select a valid table row.");
            }
          }
        });

    // Enable dynamic searching, by just typing into the searchTextField
    searchTextField
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              public void changedUpdate(DocumentEvent e) {}

              public void removeUpdate(DocumentEvent e) {
                searchInsuranceCompany();
              }

              public void insertUpdate(DocumentEvent e) {
                searchInsuranceCompany();
              }
            });

    // Clear the searchTextField
    clearSearchButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            searchTextField.setText("");
          }
        });

    // Enable sorting
    sortComboBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String sortStrategy = (String) sortComboBox.getSelectedItem();

            if (sortStrategy.equals("ID")) {
              model.setSortingStrategy(null);
            } else if (sortStrategy.equals("Company Name")) {
              model.setSortingStrategy(new InsuranceCompanyNameComparator());
            } else {
              model.setSortingStrategy(new InsuranceCompanyPercentageComparator());
            }

            updateTable();
          }
        });
  }
  public DownloadGUI() {

    setTitle("Rav's Download Manager");

    setSize(640, 480);

    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            actionExit();
          }
        });

    JPanel addPanel = new JPanel();
    pauseButton = new JButton("", new ImageIcon("icons/pause.gif"));
    pauseButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            actionPause();
          }
        });
    pauseButton.setEnabled(false);
    addPanel.add(pauseButton);
    resumeButton = new JButton("", new ImageIcon("icons/resume.gif"));
    resumeButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            actionResume();
          }
        });
    resumeButton.setEnabled(false);
    addPanel.add(resumeButton);
    cancelButton = new JButton("", new ImageIcon("icons/cancel.gif"));
    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            actionCancel();
          }
        });
    cancelButton.setEnabled(false);
    addPanel.add(cancelButton);
    clearButton = new JButton("", new ImageIcon("icons/clear.gif"));
    clearButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            actionClear();
          }
        });
    clearButton.setEnabled(false);
    addPanel.add(clearButton);

    JPanel addPane2 = new JPanel();
    addTextField = new JTextField(30);
    addPane2.add(addTextField);
    JButton addButton = new JButton("", new ImageIcon("icons/add.gif"));
    addButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            actionAdd();
          }
        });
    addPane2.add(addButton);

    tableModel = new DownloadList();
    table = new JTable(tableModel);
    table
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent e) {
                tableSelectionChanged();
              }
            });

    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    ProgressBar renderer = new ProgressBar(0, 100);
    renderer.setStringPainted(true);
    table.setDefaultRenderer(JProgressBar.class, renderer);

    table.setRowHeight((int) renderer.getPreferredSize().getHeight());

    JPanel downloadsPanel = new JPanel();
    downloadsPanel.setBorder(BorderFactory.createTitledBorder("Downloads"));
    downloadsPanel.setLayout(new BorderLayout());
    downloadsPanel.add(new JScrollPane(table), BorderLayout.CENTER);

    getContentPane().setLayout(new GridLayout(3, 1));
    getContentPane().add(addPane2);
    getContentPane().add(addPanel);
    getContentPane().add(downloadsPanel);
  }
 private void setLeadFromTable() {
   setLead(
       table.getSelectionModel().getAnchorSelectionIndex(),
       table.getColumnModel().getSelectionModel().getAnchorSelectionIndex());
 }