public void mouseClicked(MouseEvent e) {
setStatusText("");
if (modTable.isEnabled()) {
int row = modTable.getSelectedRow();
int col = modTable.getSelectedColumn();
AbstractTableModel model = (AbstractTableModel) modTable.getModel();
Mod mod = (Mod) model.getValueAt(row, col);
if (col == 0 && mod != null && mod.okToApply()) {
MCPatcher.modList.selectMod(mod, !mod.isEnabled());
}
model.fireTableRowsUpdated(0, model.getRowCount());
if (e.getClickCount() == 2 && mod instanceof ExternalMod) {
ExternalMod extMod = (ExternalMod) mod;
addModDialog = new AddModDialog(mainPanel, extMod);
addModDialog.setLocationRelativeTo(frame);
addModDialog.setVisible(true);
if (addModDialog.getMod() == extMod) {
modTable.addRowSelectionInterval(row, row);
ModTextRenderer renderer = (ModTextRenderer) modTable.getColumnModel().getColumn(1).getCellRenderer();
renderer.resetRowHeights();
model.fireTableDataChanged();
}
}
}
super.mouseClicked(e);
}
});
upButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int row = modTable.getSelectedRow();
if (row >= 0) {
int newRow = MCPatcher.modList.moveUp(row, shift);
modTable.clearSelection();
AbstractTableModel model = (AbstractTableModel) modTable.getModel();
model.fireTableRowsUpdated(Math.min(row, newRow), Math.max(row, newRow));
ModTextRenderer renderer = (ModTextRenderer) modTable.getColumnModel().getColumn(1).getCellRenderer();
renderer.resetRowHeights();
modTable.addRowSelectionInterval(newRow, newRow);
}
}
});
downButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int row = modTable.getSelectedRow();
if (row >= 0) {
int newRow = MCPatcher.modList.moveDown(row, shift);
modTable.clearSelection();
AbstractTableModel model = (AbstractTableModel) modTable.getModel();
model.fireTableRowsUpdated(Math.min(row, newRow), Math.max(row, newRow));
ModTextRenderer renderer = (ModTextRenderer) modTable.getColumnModel().getColumn(1).getCellRenderer();
renderer.resetRowHeights();
modTable.addRowSelectionInterval(newRow, newRow);
}
}
});
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
addModDialog = new AddModDialog(mainPanel);
if (!addModDialog.showBrowseDialog(mainPanel)) {
return;
}
addModDialog.setLocationRelativeTo(frame);
addModDialog.setVisible(true);
Mod mod = addModDialog.getMod();
if (mod != null) {
int row = MCPatcher.modList.addFirst(mod);
mod.setEnabled(true);
modTable.clearSelection();
AbstractTableModel model = (AbstractTableModel) modTable.getModel();
model.fireTableRowsInserted(row, row);
ModTextRenderer renderer = (ModTextRenderer) modTable.getColumnModel().getColumn(1).getCellRenderer();
renderer.resetRowHeights();
}
} catch (Throwable e1) {
Logger.log(e1);
} finally {
hideDialog();
updateControls();
}
}
private void hideDialog() {
if (addModDialog != null) {
addModDialog.setVisible(false);
addModDialog.dispose();
addModDialog = null;
}
}
});
removeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int row = modTable.getSelectedRow();
Mod mod = (Mod) modTable.getModel().getValueAt(row, 0);
if (mod instanceof ExternalMod) {
MCPatcher.modList.remove(mod);
modTable.clearSelection();
AbstractTableModel model = (AbstractTableModel) modTable.getModel();
model.fireTableRowsDeleted(row, row);
if (row >= model.getRowCount()) {
row--;
}
modTable.addRowSelectionInterval(row, row);
ModTextRenderer renderer = (ModTextRenderer) modTable.getColumnModel().getColumn(1).getCellRenderer();
renderer.resetRowHeights();