private void refresh() {
    guiCount.setText(String.valueOf(analyze.getCount()));
    guiSum.setText(FORMAT.format(analyze.getSum()));
    guiMinimum.setText(FORMAT.format(analyze.getMinimum()));
    guiMaximum.setText(FORMAT.format(analyze.getMaximum()));
    guiMean.setText(FORMAT.format(analyze.getMean()));
    guiMedian.setText(FORMAT.format(analyze.getMedian()));

    guiChart.removeAll();
    guiChart.add(new ChartPanel(getChart((Integer) guiDivision.getModel().getValue())));

    double[] values = analyze.getValues();
    Double[][] vals = new Double[values.length][1];

    for (int i = 0; i < values.length; i++) {
      vals[i][0] = values[i];
    }

    guiTable.setTableHeader(null);
    guiTable.setModel(
        new DefaultTableModel(vals, new String[] {""}) {

          @Override
          public Class<?> getColumnClass(int columnIndex) {
            return Double.class;
          }
        });
    guiTable.setShowGrid(false, false);
    guiTable.setHighlighters(
        new Highlighter[] {
          HighlighterFactory.createAlternateStriping(Color.white, HighlighterFactory.QUICKSILVER, 1)
        });
    guiTable.revalidate();
    guiTable.repaint();

    guiTable.setEditable(analyze.getMethod() == METHOD.MANUAL);

    guiTable
        .getModel()
        .addTableModelListener(
            new TableModelListener() {

              @Override
              public void tableChanged(TableModelEvent e) {
                double[] values = new double[guiTable.getModel().getRowCount()];
                for (int i = 0; i < values.length; i++) {
                  values[i] = Double.valueOf(guiTable.getModel().getValueAt(i, 0).toString());
                }

                analyze.setValues(values);
              }
            });

    guiMethod.setSelectedItem(analyze.getMethod());
  }
Beispiel #2
0
 @PostConstruct
 protected void build() {
   setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
   setHorizontalScrollEnabled(true);
   setAutoCreateColumnsFromModel(false);
   setAutoCreateRowSorter(false);
   setEditable(false);
   addHighlighter(HighlighterFactory.createAlternateStriping(Color.white, Colors.tableRowColor));
   addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW, null, Color.blue));
   addHighlighter(NegativeNumberHighlighter.instance);
   setComponentPopupMenu(new FindPopupMenu(resourceManager, getActionMap().get("find")));
   setFillsViewportHeight(true);
 }
  private void initPropertiesTable() {
    propertiesTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    DefaultTableModel model =
        new DefaultTableModel(
            new Object[][] {},
            new String[] {PROPERTY_NAME_COLUMN_NAME, PROPERTY_VALUE_COLUMN_NAME}) {
          public boolean isCellEditable(int rowIndex, int columnIndex) {
            return true;
          }

          @Override
          public void setValueAt(Object value, int row, int column) {
            if (!value.equals(getValueAt(row, column))) {
              parent.setSaveEnabled(true);
            }

            super.setValueAt(value, row, column);
          }
        };

    propertiesTable.setSortable(false);
    propertiesTable.getTableHeader().setReorderingAllowed(false);
    propertiesTable.setModel(model);

    propertiesTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent evt) {
                deletePropertyButton.setEnabled(propertiesTable.getSelectedRow() != -1);
              }
            });

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
      propertiesTable.setHighlighters(
          HighlighterFactory.createAlternateStriping(
              UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    deletePropertyButton.setEnabled(false);
  }
Beispiel #4
0
  public void initComponent(ODatabaseDocumentTx db) {
    //		amountFormat = NumberFormat.getNumberInstance();
    //
    //        percentFormat = NumberFormat.getNumberInstance();
    //        percentFormat.setMinimumFractionDigits(2);

    listModel = new DefaultListModel();
    custList = new JXList(listModel);
    custList.setHighlighters(HighlighterFactory.createAlternateStriping());
    popup = new JPopupMenu();
    popup.add(new JScrollPane(custList), BorderLayout.CENTER);

    code = new TextField();
    tgl = new DatePicker();
    tgl.setFormats(App.dateFormat);
    pelanggan = new TextField();
    jml = new FormattedTextField(App.paymentFormat);
    harga = new FormattedTextField(App.paymentFormat);
    harga.setEditable(false);
    harga.setBackground(App.whiteSmoke);
    total1 = new FormattedTextField(App.paymentFormat);
    total1.setEditable(false);
    total1.setBackground(App.whiteSmoke);
    diskon = new FormattedTextField(App.paymentFormat);
    diskonp = new FormattedTextField(App.paymentFormat2);
    total = new FormattedTextField(App.paymentFormat);
    total.setEditable(false);
    total.setBackground(App.whiteSmoke);
    bayar = new TextField();
    k = new FormattedTextField(App.paymentFormat);
    k.setEditable(false);
    k.setBackground(App.whiteSmoke);
    kembali = new FormattedTextField(App.paymentFormat);
    kembali.setEditable(false);
    kembali.setBackground(App.whiteSmoke);

    Font f = UIManager.getFont("TextField.font");
    f2 = f.deriveFont((float) 24.0);
    total1.setFont(f2);
    total.setFont(f2);
    kembali.setFont(f2);
    harga.setFont(f2);
    bayar.setFont(f2);
    jml.setFont(f2);
    k.setFont(f2);

    harga.setHorizontalAlignment(SwingConstants.RIGHT);
    total1.setHorizontalAlignment(SwingConstants.RIGHT);
    total.setHorizontalAlignment(SwingConstants.RIGHT);
    diskon.setHorizontalAlignment(SwingConstants.RIGHT);
    bayar.setHorizontalAlignment(SwingConstants.RIGHT);
    k.setHorizontalAlignment(SwingConstants.RIGHT);
    kembali.setHorizontalAlignment(SwingConstants.RIGHT);

    setFocusEnter(code, tgl.getEditor());
    setFocusEnter(tgl.getEditor(), pelanggan);
    setFocusEnter(jml, diskon);
    setFocusEnter(diskon, diskonp);
    setFocusEnter(diskonp, bayar);
    setFocusEnter(bayar, kembali);

    kembali.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            save.requestFocus();
          }
        });

    pelanggan.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            // bila pelanggan null maka menampilkan popup
            // bila tidak null berarti tidak menampilkan popup
            // karena dianggap sudah benar, sehingga bila inggin mengganti
            // menggani harus menghapus terlebih dahulu
            if (cust == null) {

              // hapus semua elemaent yang terdapat pada list
              listModel.removeAllElements();

              ODatabaseDocumentTx db = App.getDbd();
              ODatabaseRecordThreadLocal.INSTANCE.set(db);

              // ambil dari database dengan batasan 0-10
              List<ODocument> ps = null;
              try {
                ps =
                    App.getPelangganDao()
                        .getAllByColumnLike(
                            db, PelangganDao.name, pelanggan.getText() + "%", 0, 50);
              } catch (Exception e2) {
              }

              // cek apakah ps null atau hasilnya kosong
              // bila kosong maka mengambil 10 default
              if (ps == null || ps.size() == 0) {
                ps = App.getPelangganDao().getAll(db, 0, 50);
              }

              // masukkan list ps kedalam model
              // untuk split menggunakan ":    "
              for (ODocument pelanggan : ps) {
                listModel.addElement(
                    pelanggan.field(PelangganDao.code) + ", " + pelanggan.field(PelangganDao.name));
              }

              // pengaturan preferred size pada jlist
              // - 19 digunakan untuk scrol
              custList.setPreferredSize(
                  new Dimension(pelanggan.getSize().width - 4, custList.getPreferredSize().height));

              // +8 digunakan untuk meletakkan di bawah persis pd
              // jtextfiled
              popup.show(pelanggan, 0, 18);

              // pengaturan default
              custList.requestFocus();
              custList.setSelectedIndex(0);
            }
          }
        });

    custList.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == 10) {
              popup.setVisible(false);
              if (custList.getSelectedIndex() != -1) {
                String tmp = (String) listModel.getElementAt(custList.getSelectedIndex());
                if (tmp != null) {

                  pelanggan.setText(tmp);
                  jml.requestFocus();
                }
              }

              listModel.removeAllElements();
            }
          }
        });

    pelanggan.addFocusListener(
        new FocusListener() {

          @Override
          public void focusLost(FocusEvent e) {
            String value = pelanggan.getText();
            String[] split = ((String) value).split(", ");
            ODatabaseDocumentTx db = App.getDbd();
            ODatabaseRecordThreadLocal.INSTANCE.set(db);
            try {
              String id = split[0];
              cust = App.getPelangganDao().getOne(db, PelangganDao.code, id);
            } catch (Exception ex) {
              cust = null;
            } finally {
              db.close();
            }
            if (cust == null) {
              pelanggan.setText("");
            }
          }

          @Override
          public void focusGained(FocusEvent e) {
            harga.setValue(DataUser.getProduct().field(ProductDao.harga));
          }
        });

    jml.addFocusListener(
        new FocusListener() {

          @Override
          public void focusLost(FocusEvent e) {
            ODatabaseDocumentTx db = App.getDbd();
            ODatabaseRecordThreadLocal.INSTANCE.set(db);
            if (jml.getText().equalsIgnoreCase("")) {
              App.showErrorFieldEmpty(db, "Jumlah");
              jml.setText("1");
              jml.requestFocus();
              jml.selectAll();
            } else {
              try {
                int tmp = Integer.parseInt(jml.getText());
                if (tmp == 0) {
                  App.showErrorFieldEmpty(db, "Jumlah");
                  jml.setText("1");
                  jml.requestFocus();
                  jml.selectAll();
                }

              } catch (Exception e2) {
                App.showErrorFieldEmpty(db, "Jumlah");
                jml.setText("1");
                jml.requestFocus();
                jml.selectAll();
              }
              autoHarga();
            }
          }

          @Override
          public void focusGained(FocusEvent e) {}
        });

    diskon.addFocusListener(
        new FocusListener() {

          @Override
          public void focusLost(FocusEvent e) {
            autoHarga();
          }

          @Override
          public void focusGained(FocusEvent e) {
            diskon.selectAll();
          }
        });
    diskonp.addFocusListener(
        new FocusListener() {

          @Override
          public void focusLost(FocusEvent e) {
            autoHarga();
          }

          @Override
          public void focusGained(FocusEvent e) {
            diskonp.selectAll();
          }
        });
    bayar.addFocusListener(
        new FocusListener() {

          @Override
          public void focusLost(FocusEvent e) {
            autoKembali();
          }

          @Override
          public void focusGained(FocusEvent e) {
            bayar.selectAll();
          }
        });

    bayar.addKeyListener(
        new KeyListener() {

          @Override
          public void keyTyped(KeyEvent e) {}

          @Override
          public void keyReleased(KeyEvent e) {
            String tmp = bayar.getText();
            try {
              if (tmp != null && !tmp.equalsIgnoreCase("")) {
                double tmp2 = Double.parseDouble(tmp.replaceAll("\\,", ""));
                bayar.setText(App.paymentFormat.format(tmp2));
              }
            } catch (Exception e2) {
              App.printErr(e2);
              bayar.setText("");
            }
          }

          @Override
          public void keyPressed(KeyEvent e) {}
        });

    save = new JButton(App.getT(db, "Save"));
    save.addActionListener(
        new ActionListener() {

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

    reset = new JButton(App.getT(db, "Reset"));
    reset.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            aksiReset();
          }
        });
  }
Beispiel #5
0
  public void setValues(ArrayList<String> values) {
    Object[][] tableData = new Object[values.size()][1];

    valuesTable = new MirthTable();

    for (int i = 0; i < values.size(); i++) {
      tableData[i][VALUE_COLUMN] = values.get(i);
    }

    valuesTable.setModel(
        new javax.swing.table.DefaultTableModel(tableData, new String[] {VALUE_COLUMN_NAME}) {

          boolean[] canEdit = new boolean[] {true};

          public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit[columnIndex];
          }
        });

    valuesTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {

              public void valueChanged(ListSelectionEvent evt) {
                if (getSelectedRow() != -1) {
                  lastIndex = getSelectedRow();
                  deleteButton.setEnabled(true);
                } else {
                  deleteButton.setEnabled(false);
                }

                rulePlugin.updateName();
              }
            });

    class RegExTableCellEditor extends TextFieldCellEditor {

      public boolean stopCellEditing() {
        parent.modified = true;
        deleteButton.setEnabled(true);
        boolean result = super.stopCellEditing();

        /*
         * HACK: Cannot move this logic into valueChanged. We need to
         * update the name after stopping cell editing, because the
         * swingx update caused the ListSelectionListener to stop being
         * called when there was only one row and it was edited.
         */
        rulePlugin.updateName();

        return result;
      }

      @Override
      public boolean isCellEditable(EventObject evt) {
        boolean editable = super.isCellEditable(evt);

        if (editable) {
          deleteButton.setEnabled(false);
        }

        return editable;
      }

      @Override
      protected boolean valueChanged(String value) {
        return true;
      }
    }

    // Set the custom cell editor for the Destination Name column.
    valuesTable
        .getColumnModel()
        .getColumn(valuesTable.getColumnModel().getColumnIndex(VALUE_COLUMN_NAME))
        .setCellEditor(new RegExTableCellEditor());
    valuesTable.setCustomEditorControls(true);

    valuesTable.setSelectionMode(0);
    valuesTable.setRowSelectionAllowed(true);
    valuesTable.setRowHeight(UIConstants.ROW_HEIGHT);
    valuesTable.setDragEnabled(false);
    valuesTable.setOpaque(true);
    valuesTable.setSortable(false);
    valuesTable.getTableHeader().setReorderingAllowed(false);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
      Highlighter highlighter =
          HighlighterFactory.createAlternateStriping(
              UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR);
      valuesTable.setHighlighters(highlighter);
    }

    valuesScrollPane.setViewportView(valuesTable);
  }
Beispiel #6
0
  /**
   * constructor
   *
   * @param variableServerConnection the variable server to which to send value changes
   */
  public VariableTable(VariableServerConnection variableServerConnection) {

    this.variableServerConnection = variableServerConnection;

    // Set the model.
    model = new VariableTableModel();
    setModel(model);

    // Enable column controls.
    setColumnControlVisible(true);

    // Hightlight invalid refernces in red.
    setHighlighters(
        HighlighterFactory.createSimpleStriping(),
        new ColorHighlighter(
            new PatternPredicate("<Invalid Reference>", getColumnModel().getColumnIndex("Value")),
            null,
            Color.red,
            null,
            Color.red));

    // Add keyboard support.
    getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "VariableTable.delete");

    // Add drag and drop support.
    setFillsViewportHeight(true);
    setDragEnabled(true);
    setDropMode(DropMode.INSERT);
    setTransferHandler(
        new TransferHandler() {

          DataFlavor variableDataFlavor =
              new DataFlavor(Variable.class, "Variable<? extends TrickViewFluent>");

          @Override
          public int getSourceActions(JComponent component) {
            return COPY_OR_MOVE;
          }

          @Override
          protected Transferable createTransferable(JComponent component) {
            return new VariableSelection(getSelectedRows());
          }

          @Override
          public boolean canImport(TransferSupport transferSupport) {
            return transferSupport.isDrop()
                && transferSupport.isDataFlavorSupported(variableDataFlavor)
                && ((JXTable.DropLocation) transferSupport.getDropLocation()).isInsertRow();
          }

          @Override
          public boolean importData(TransferSupport transferSupport) {

            if (!canImport(transferSupport)) {
              return false;
            }

            try {
              int[] indices =
                  (int[]) transferSupport.getTransferable().getTransferData(variableDataFlavor);

              // Convert from view to model indices.
              for (int i = 0; i < indices.length; i++) {
                indices[i] = convertRowIndexToModel(indices[i]);
              }
              Arrays.sort(indices);

              // If dropping after the end of the table, the drop index will be equal to
              // the row count, which is not a legally convertable index.
              int dropIndex = ((JXTable.DropLocation) transferSupport.getDropLocation()).getRow();
              if (dropIndex < model.getRowCount()) {
                dropIndex = convertRowIndexToModel(dropIndex);
              }

              ArrayList<Variable<? extends TrickViewFluent>> movingVariables =
                  new ArrayList<Variable<? extends TrickViewFluent>>();

              // Remove in reverse order to avoid index corruption.
              for (int i = indices.length - 1; i >= 0; --i) {
                movingVariables.add(variables.remove(indices[i]));
              }

              // The removed variables have reduced the table's row count. The index at which
              // we will begin re-inserting them must be decremented for each removed variable
              // that was positioned above the drop index.
              int index = dropIndex;
              for (int i : indices) {
                if (i < dropIndex) {
                  --index;
                } else {
                  break;
                }
              }

              // The variables were removed in reverse order, so re-insert them
              // with a constant index.
              for (Variable<? extends TrickViewFluent> variable : movingVariables) {
                variables.add(index, variable);
              }

              // Update all affected rows.
              model.fireTableRowsUpdated(
                  Math.min(dropIndex, indices[0]),
                  Math.max(
                      Math.min(dropIndex, model.getRowCount() - 1), indices[indices.length - 1]));

              // Revert to unsorted mode.
              getRowSorter().setSortKeys(null);

              // Select the re-inserted variables.
              setRowSelectionInterval(
                  convertRowIndexToView(index), convertRowIndexToView(index + indices.length - 1));
            } catch (Exception exception) {
              exception.printStackTrace();
            }

            return true;
          }

          /** provides for dragging of rows */
          class VariableSelection implements Transferable {

            /** indices of the selected rows */
            int[] indices;

            /** textual representation of the selected rows */
            String string = "";

            /**
             * constructor
             *
             * @param indices indices of the selected rows
             */
            public VariableSelection(int[] indices) {
              this.indices = indices;
              for (int row : indices) {
                for (int column = 0; column < getColumnCount(); ++column) {
                  string += getStringAt(row, column) + "\t";
                }
                string = string.trim() + "\n";
              }
            }

            @Override
            public Object getTransferData(DataFlavor dataFlavor) throws UnsupportedFlavorException {
              if (!isDataFlavorSupported(dataFlavor)) {
                throw new UnsupportedFlavorException(dataFlavor);
              }

              if (dataFlavor == variableDataFlavor) {
                return indices;
              }
              return string;
            }

            @Override
            public DataFlavor[] getTransferDataFlavors() {
              return new DataFlavor[] {variableDataFlavor, DataFlavor.stringFlavor};
            }

            @Override
            public boolean isDataFlavorSupported(DataFlavor dataFlavor) {
              return dataFlavor == variableDataFlavor || dataFlavor == DataFlavor.stringFlavor;
            }
          }
        });
  }
  /** Creates new form AttackSourcePanel */
  RetimerSourcePanel() {
    initComponents();
    jVillageTable.setModel(new RETSourceTableModel());
    jVillageTable.setDefaultRenderer(UnitHolder.class, new UnitCellRenderer());
    jVillageTable.setDefaultRenderer(Boolean.class, new FakeCellRenderer());
    jXCollapsiblePane1.setLayout(new BorderLayout());
    jXCollapsiblePane1.add(jInfoScrollPane, BorderLayout.CENTER);
    villageSelectionPanel =
        new VillageSelectionPanel(
            new VillageSelectionPanel.VillageSelectionPanelListener() {

              @Override
              public void fireVillageSelectionEvent(Village[] pSelection) {
                addVillages(pSelection);
              }
            });

    jVillageTable.setHighlighters(
        HighlighterFactory.createAlternateStriping(Constants.DS_ROW_A, Constants.DS_ROW_B));
    jVillageTable.getTableHeader().setDefaultRenderer(new DefaultTableHeaderRenderer());

    villageSelectionPanel.enableSelectionElement(
        VillageSelectionPanel.SELECTION_ELEMENT.ALLY, false);
    villageSelectionPanel.enableSelectionElement(
        VillageSelectionPanel.SELECTION_ELEMENT.TRIBE, false);
    villageSelectionPanel.setUnitSelectionEnabled(false);
    villageSelectionPanel.setFakeSelectionEnabled(false);
    jPanel1.add(villageSelectionPanel, BorderLayout.CENTER);
    jideSplitPane1.setOrientation(JideSplitPane.VERTICAL_SPLIT);
    jideSplitPane1.setProportionalLayout(true);
    jideSplitPane1.setDividerSize(5);
    jideSplitPane1.setShowGripper(true);
    jideSplitPane1.setOneTouchExpandable(true);
    jideSplitPane1.setDividerStepSize(10);
    jideSplitPane1.setInitiallyEven(true);
    jideSplitPane1.add(jDataPanel, JideBoxLayout.FLEXIBLE);
    jideSplitPane1.add(jVillageTablePanel, JideBoxLayout.VARY);
    jideSplitPane1
        .getDividerAt(0)
        .addMouseListener(
            new MouseAdapter() {

              @Override
              public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                  jideSplitPane1.setProportions(new double[] {0.5});
                }
              }
            });

    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK, false);
    KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false);
    ActionListener panelListener =
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals("Paste")) {
              pasteFromClipboard();
            } else if (e.getActionCommand().equals("Delete")) {
              deleteSelection();
            }
          }
        };
    jVillageTable.registerKeyboardAction(
        panelListener, "Paste", paste, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jVillageTable.registerKeyboardAction(
        panelListener, "Delete", delete, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    capabilityInfoPanel1.addActionListener(panelListener);

    jVillageTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {

              @Override
              public void valueChanged(ListSelectionEvent e) {
                int selectedRows = jVillageTable.getSelectedRowCount();
                if (selectedRows != 0) {
                  jStatusLabel.setText(selectedRows + " Dorf/Dörfer gewählt");
                }
              }
            });

    jInfoTextPane.setText(GENERAL_INFO);
    overviewPanel = new VillageOverviewMapPanel();
    jPanel2.add(overviewPanel, BorderLayout.CENTER);
  }
  public AttachmentsView(@Service ApplicationContext context, @Uses AttachmentsModel model) {
    setLayout(new BorderLayout());

    final ActionMap am = context.getActionMap(this);

    this.attachmentsModel = model;
    TableFormat tableFormat = new AttachmentsTableFormatter();
    tableModel = new EventJXTableModel<AttachmentDTO>(attachmentsModel.getEventList(), tableFormat);

    attachments = new JXTable(tableModel);

    attachments.setFocusTraversalKeys(
        KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
        KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
    attachments.setFocusTraversalKeys(
        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
        KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));

    attachments.getColumn(0).setPreferredWidth(20);
    attachments.getColumn(0).setMaxWidth(20);
    attachments.getColumn(0).setResizable(false);
    attachments.getColumn(2).setPreferredWidth(100);
    attachments.getColumn(2).setMaxWidth(100);
    attachments.getColumn(3).setPreferredWidth(100);
    attachments.getColumn(3).setMaxWidth(100);

    attachments.setAutoCreateColumnsFromModel(false);

    attachments.addHighlighter(HighlighterFactory.createAlternateStriping());

    attachments.setModel(tableModel);
    attachments.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JPanel toolbar = new JPanel();
    StreamflowButton addButton = new StreamflowButton(am.get("add"));
    toolbar.add(addButton);
    StreamflowButton removeButton = new StreamflowButton(am.get("remove"));
    toolbar.add(removeButton);
    final StreamflowButton openButton = new StreamflowButton(am.get("open"));
    toolbar.add(openButton);
    attachments
        .getSelectionModel()
        .addListSelectionListener(new SelectionActionEnabler(am.get("open")));
    attachments
        .getSelectionModel()
        .addListSelectionListener(
            new SelectionActionEnabler(am.get("remove")) {

              @Override
              public boolean isSelectedValueValid(javax.swing.Action action) {
                return !attachments
                    .getValueAt(attachments.convertRowIndexToModel(attachments.getSelectedRow()), 0)
                    .equals(Icons.formSubmitted);
              }
            });

    attachmentsModel.addObserver(
        new RefreshComponents().visibleOn("createattachment", addButton, removeButton));

    attachments.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "open");
    attachments.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "remove");
    attachments.setActionMap(am);

    attachments.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent me) {
            int obj = attachments.getSelectedRow();
            if (obj == -1) return;
            if (me.getClickCount() == 2) {
              am.get("open")
                  .actionPerformed(
                      new ActionEvent(openButton, ActionEvent.ACTION_PERFORMED, "open"));
              me.consume();
            }
          }
        });

    attachments
        .getColumn(0)
        .setCellRenderer(
            new DefaultTableCellRenderer() {
              @Override
              public Component getTableCellRendererComponent(
                  JTable table,
                  Object value,
                  boolean isSelected,
                  boolean hasFocus,
                  int row,
                  int column) {

                JLabel iconLabel = new JLabel(" ");
                switch ((Icons) value) {
                  case attachments:
                    iconLabel = new JLabel(i18n.icon((Icons) value, 11));
                    break;

                  case conversations:
                    iconLabel = new JLabel(i18n.icon((Icons) value, 11));
                    break;

                  case formSubmitted:
                    iconLabel = new JLabel(i18n.icon((Icons) value, 11));
                    break;
                }

                iconLabel.setOpaque(true);

                if (isSelected) iconLabel.setBackground(attachments.getSelectionBackground());
                return iconLabel;
              }
            });

    JScrollPane attachmentsScrollPane = new JScrollPane(attachments);

    add(attachmentsScrollPane, BorderLayout.CENTER);
    add(toolbar, BorderLayout.SOUTH);

    new RefreshWhenShowing(this, attachmentsModel);
  }