/* * UFO Saved Game Editor * Copyright (C) 2010 Christopher Davoren * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.rubikscomplex.ufosge.gui; import net.rubikscomplex.ufosge.gui.table.BaseListTableModel; import java.awt.Component; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import net.rubikscomplex.ufosge.data.SavedGame; import net.rubikscomplex.ufosge.util.Util; /** * * @author Chris Davoren */ public class BaseListPanel extends JPanel implements ActionListener, MouseListener { protected SavedGame game; protected BaseListTableModel tableModel; protected JTable baseListTable; public BaseListPanel(SavedGame game) { super(); this.game = game; tableModel = new BaseListTableModel(game, true); JButton editButton = new JButton("Edit..."); editButton.setMnemonic(KeyEvent.VK_E); editButton.addActionListener(this); Util.setButtonSize(editButton, 100, 25); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS)); buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); buttonPanel.setAlignmentY(Component.TOP_ALIGNMENT); buttonPanel.add(editButton); baseListTable = new JTable(); baseListTable.setModel(tableModel); baseListTable.addMouseListener(this); baseListTable.setFillsViewportHeight(true); JScrollPane tableScrollPane = new JScrollPane(baseListTable); tableScrollPane.setPreferredSize(new Dimension(400, 100)); tableScrollPane.setMinimumSize(tableScrollPane.getPreferredSize()); tableScrollPane.setAlignmentY(Component.TOP_ALIGNMENT); setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); add(tableScrollPane); add(buttonPanel); } protected void editSelectedBase() { int selectedRow = baseListTable.getSelectedRow(); if (selectedRow == -1) { return; } int modelRow = baseListTable.convertRowIndexToModel(selectedRow); BaseEditDialog bed = new BaseEditDialog(null, game, tableModel.getBaseAt(modelRow)); bed.setVisible(true); tableModel.updateList(true); } public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("Edit...")) { editSelectedBase(); } } public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { editSelectedBase(); } } public void mouseExited(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } public void mousePressed(MouseEvent e) { } }