private void selectPolicyInformationInTable(PolicyInformation policyInfo) {
   for (int i = 0; i < jtPolicyInformation.getRowCount(); i++) {
     if (policyInfo.equals(jtPolicyInformation.getValueAt(i, 0))) {
       jtPolicyInformation.changeSelection(i, 0, false, false);
       return;
     }
   }
 }
  private void removeSelectedPolicyInformation() {
    int selectedRow = jtPolicyInformation.getSelectedRow();

    if (selectedRow != -1) {
      PolicyInformation policyInfo =
          (PolicyInformation) jtPolicyInformation.getValueAt(selectedRow, 0);

      policyInformation.remove(policyInfo);

      reloadPolicyInformationTable();
      selectFirstPolicyInformationInTable();
      updateButtonControls();
    }
  }
  private void editSelectedPolicyInformation() {
    int selectedRow = jtPolicyInformation.getSelectedRow();

    if (selectedRow != -1) {
      PolicyInformation policyInfo =
          (PolicyInformation) jtPolicyInformation.getValueAt(selectedRow, 0);

      Container container = getTopLevelAncestor();

      try {
        DPolicyInformationChooser dPolicyNameChooser = null;

        if (container instanceof JDialog) {
          dPolicyNameChooser =
              new DPolicyInformationChooser((JDialog) container, title, policyInfo);
          dPolicyNameChooser.setLocationRelativeTo(container);
          dPolicyNameChooser.setVisible(true);
        } else if (container instanceof JFrame) {
          dPolicyNameChooser = new DPolicyInformationChooser((JFrame) container, title, policyInfo);
          dPolicyNameChooser.setLocationRelativeTo(container);
          dPolicyNameChooser.setVisible(true);
        }

        PolicyInformation newPolicyInfo = dPolicyNameChooser.getPolicyInformation();

        if (newPolicyInfo == null) {
          return;
        }

        policyInformation.remove(policyInfo);
        policyInformation.add(newPolicyInfo);

        populate();
        selectPolicyInformationInTable(newPolicyInfo);
      } catch (IOException ex) {
        DError dError = null;

        if (container instanceof JDialog) {
          dError = new DError((JDialog) container, ex);
        } else {
          dError = new DError((JFrame) container, ex);
        }

        dError.setLocationRelativeTo(container);
        dError.setVisible(true);
      }
    }
  }
  private void maybeEditPolicyInformation(MouseEvent evt) {
    if (evt.getClickCount() > 1) {
      Point point = new Point(evt.getX(), evt.getY());
      int row = jtPolicyInformation.rowAtPoint(point);

      if (row != -1) {
        try {
          CursorUtil.setCursorBusy(JPolicyInformation.this);
          jtPolicyInformation.setRowSelectionInterval(row, row);
          editSelectedPolicyInformation();
        } finally {
          CursorUtil.setCursorFree(JPolicyInformation.this);
        }
      }
    }
  }
  private void updateButtonControls() {
    if (!enabled) {
      jbAdd.setEnabled(false);
      jbEdit.setEnabled(false);
      jbRemove.setEnabled(false);
    } else {
      jbAdd.setEnabled(true);

      int selectedRow = jtPolicyInformation.getSelectedRow();

      if (selectedRow == -1) {
        jbEdit.setEnabled(false);
        jbRemove.setEnabled(false);
      } else {
        jbEdit.setEnabled(true);
        jbRemove.setEnabled(true);
      }
    }
  }
  private void initComponents() {
    jbAdd =
        new JButton(
            new ImageIcon(
                Toolkit.getDefaultToolkit()
                    .createImage(
                        getClass().getResource(res.getString("JPolicyInformation.jbAdd.image")))));
    jbAdd.setMargin(new Insets(2, 2, 0, 0));
    jbAdd.setToolTipText(res.getString("JPolicyInformation.jbAdd.tooltip"));
    jbAdd.setMnemonic(res.getString("JPolicyInformation.jbAdd.mnemonic").charAt(0));

    jbAdd.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            try {
              CursorUtil.setCursorBusy(JPolicyInformation.this);
              addPressed();
            } finally {
              CursorUtil.setCursorFree(JPolicyInformation.this);
            }
          }
        });

    jbEdit =
        new JButton(
            new ImageIcon(
                Toolkit.getDefaultToolkit()
                    .createImage(
                        getClass().getResource(res.getString("JPolicyInformation.jbEdit.image")))));
    jbEdit.setMargin(new Insets(2, 2, 0, 0));
    jbEdit.setToolTipText(res.getString("JPolicyInformation.jbEdit.tooltip"));
    jbEdit.setMnemonic(res.getString("JPolicyInformation.jbEdit.mnemonic").charAt(0));

    jbEdit.setEnabled(false);

    jbEdit.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            try {
              CursorUtil.setCursorBusy(JPolicyInformation.this);
              editPressed();
            } finally {
              CursorUtil.setCursorFree(JPolicyInformation.this);
            }
          }
        });

    jbRemove =
        new JButton(
            new ImageIcon(
                Toolkit.getDefaultToolkit()
                    .createImage(
                        getClass()
                            .getResource(res.getString("JPolicyInformation.jbRemove.image")))));
    jbRemove.setMargin(new Insets(2, 2, 0, 0));
    jbRemove.setToolTipText(res.getString("JPolicyInformation.jbRemove.tooltip"));
    jbRemove.setMnemonic(res.getString("JPolicyInformation.jbRemove.mnemonic").charAt(0));

    jbRemove.setEnabled(false);

    jbRemove.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            try {
              CursorUtil.setCursorBusy(JPolicyInformation.this);
              removePressed();
            } finally {
              CursorUtil.setCursorFree(JPolicyInformation.this);
            }
          }
        });

    jpPolicyInformationButtons = new JPanel();
    jpPolicyInformationButtons.setLayout(
        new BoxLayout(jpPolicyInformationButtons, BoxLayout.Y_AXIS));
    jpPolicyInformationButtons.add(Box.createVerticalGlue());
    jpPolicyInformationButtons.add(jbAdd);
    jpPolicyInformationButtons.add(Box.createVerticalStrut(3));
    jpPolicyInformationButtons.add(jbEdit);
    jpPolicyInformationButtons.add(Box.createVerticalStrut(3));
    jpPolicyInformationButtons.add(jbRemove);
    jpPolicyInformationButtons.add(Box.createVerticalGlue());

    PolicyInformationTableModel policyInformationTableModel = new PolicyInformationTableModel();
    jtPolicyInformation = new JKseTable(policyInformationTableModel);

    TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(policyInformationTableModel);
    sorter.setComparator(0, new PolicyInformationTableModel.PolicyInformationComparator());
    jtPolicyInformation.setRowSorter(sorter);

    jtPolicyInformation.setShowGrid(false);
    jtPolicyInformation.setRowMargin(0);
    jtPolicyInformation.getColumnModel().setColumnMargin(0);
    jtPolicyInformation.getTableHeader().setReorderingAllowed(false);
    jtPolicyInformation.setAutoResizeMode(JKseTable.AUTO_RESIZE_ALL_COLUMNS);
    jtPolicyInformation.setRowHeight(Math.max(18, jtPolicyInformation.getRowHeight()));

    for (int i = 0; i < jtPolicyInformation.getColumnCount(); i++) {
      TableColumn column = jtPolicyInformation.getColumnModel().getColumn(i);
      column.setHeaderRenderer(
          new PolicyInformationTableHeadRend(
              jtPolicyInformation.getTableHeader().getDefaultRenderer()));
      column.setCellRenderer(new PolicyInformationTableCellRend());
    }

    ListSelectionModel selectionModel = jtPolicyInformation.getSelectionModel();
    selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    selectionModel.addListSelectionListener(
        new ListSelectionListener() {
          @Override
          public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
              updateButtonControls();
            }
          }
        });

    jtPolicyInformation.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent evt) {
            maybeEditPolicyInformation(evt);
          }
        });

    jtPolicyInformation.addKeyListener(
        new KeyAdapter() {
          boolean deleteLastPressed = false;

          @Override
          public void keyPressed(KeyEvent evt) {
            // Record delete pressed on non-Macs
            if (!OperatingSystem.isMacOs()) {
              deleteLastPressed = evt.getKeyCode() == KeyEvent.VK_DELETE;
            }
          }

          @Override
          public void keyReleased(KeyEvent evt) {
            // Delete on non-Mac if delete was pressed and is now released
            if (!OperatingSystem.isMacOs()
                && deleteLastPressed
                && evt.getKeyCode() == KeyEvent.VK_DELETE) {
              try {
                CursorUtil.setCursorBusy(JPolicyInformation.this);
                deleteLastPressed = false;
                removeSelectedPolicyInformation();
              } finally {
                CursorUtil.setCursorFree(JPolicyInformation.this);
              }
            }
          }

          @Override
          public void keyTyped(KeyEvent evt) {
            // Delete on Mac if back space typed
            if (OperatingSystem.isMacOs() && evt.getKeyChar() == 0x08) {
              try {
                CursorUtil.setCursorBusy(JPolicyInformation.this);
                removeSelectedPolicyInformation();
              } finally {
                CursorUtil.setCursorFree(JPolicyInformation.this);
              }
            }
          }
        });

    jspPolicyInformation =
        PlatformUtil.createScrollPane(
            jtPolicyInformation,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    jspPolicyInformation.getViewport().setBackground(jtPolicyInformation.getBackground());

    this.setLayout(new BorderLayout(5, 5));
    setPreferredSize(new Dimension(250, 150));
    add(jspPolicyInformation, BorderLayout.CENTER);
    add(jpPolicyInformationButtons, BorderLayout.EAST);

    populate();
  }
 private PolicyInformationTableModel getPolicyInformationTableModel() {
   return (PolicyInformationTableModel) jtPolicyInformation.getModel();
 }
 private void selectFirstPolicyInformationInTable() {
   if (getPolicyInformationTableModel().getRowCount() > 0) {
     jtPolicyInformation.changeSelection(0, 0, false, false);
   }
 }
 /**
  * Set component's tooltip text.
  *
  * @param toolTipText Tooltip text
  */
 @Override
 public void setToolTipText(String toolTipText) {
   super.setToolTipText(toolTipText);
   jspPolicyInformation.setToolTipText(toolTipText);
   jtPolicyInformation.setToolTipText(toolTipText);
 }