Package net.coljac.pirates.gui

Source Code of net.coljac.pirates.gui.GenericPanel

package net.coljac.pirates.gui;

import net.coljac.pirates.CardDatabase;
import net.coljac.pirates.Crew;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;

/**
* By Colin Jacobs, colin@q9software.com
* Date: Apr 1, 2006
*/
public class GenericPanel extends JPanel implements ActionListener {

  private JButton captain, helmsman, explorer, shipwright, oarsman, musketeer, cannoneer;
  private FleetsPanel fleetPanel;
  Map<String, Crew> crew = new HashMap<String, Crew>();

  public GenericPanel(FleetsPanel fleetPanel) {
    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

//    this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    this.fleetPanel = fleetPanel;
    captain = new JButton("Captain");
    explorer = new JButton("Explorer");
    helmsman = new JButton("Helmsman");
    shipwright = new JButton("Shipwright");
    musketeer = new JButton("Musketeer");
    cannoneer = new JButton("Cannoneer");
    oarsman = new JButton("Oarsman");

    JLabel label = new JLabel("Add Generic Crew");


    shipwright.addActionListener(this);
    explorer.addActionListener(this);
    captain.addActionListener(this);
    musketeer.addActionListener(this);
    cannoneer.addActionListener(this);
    oarsman.addActionListener(this);
    helmsman.addActionListener(this);

    shipwright.setAlignmentX(Component.CENTER_ALIGNMENT);
    explorer.setAlignmentX(Component.CENTER_ALIGNMENT);
    captain.setAlignmentX(Component.CENTER_ALIGNMENT);
    musketeer.setAlignmentX(Component.CENTER_ALIGNMENT);
    cannoneer.setAlignmentX(Component.CENTER_ALIGNMENT);
    oarsman.setAlignmentX(Component.CENTER_ALIGNMENT);
    helmsman.setAlignmentX(Component.CENTER_ALIGNMENT);
    label.setAlignmentX(Component.CENTER_ALIGNMENT);
//    label.setBorder(BorderFactory.createLineBorder(Color.black, 2));
    label.setBorder(BorderFactory.createCompoundBorder(

        BorderFactory.createLineBorder(Color.black), BorderFactory.createEmptyBorder(5, 10, 5, 10)
    ));

    this.setBorder(BorderFactory.createLineBorder(Color.black));


    this.add(label);

    this.add(captain);
    this.add(helmsman);
    this.add(explorer);
    this.add(shipwright);
    this.add(musketeer);
    this.add(oarsman);
    this.add(cannoneer);

    initCrew();
  }


  private void initCrew() {
    CardDatabase db = ManagerMain.instance.db;
    for (Crew c : db.getCrew()) {
      if (c.isGeneric()) {
        crew.put(c.getName(), c);
      }
    }
  }

  public void actionPerformed(ActionEvent e) {
    if (fleetPanel.getCurrentFleet() == null) return;
    if (e.getSource() == captain) {
      fleetPanel.getCurrentFleet().addCrew(crew.get("Captain"));
    } else if (e.getSource() == oarsman) {
      fleetPanel.getCurrentFleet().addCrew(crew.get("Oarsman"));
    } else if (e.getSource() == shipwright) {
      fleetPanel.getCurrentFleet().addCrew(crew.get("Shipwright"));
    } else if (e.getSource() == helmsman) {
      fleetPanel.getCurrentFleet().addCrew(crew.get("Helmsman"));
    } else if (e.getSource() == musketeer) {
      fleetPanel.getCurrentFleet().addCrew(crew.get("Musketeer"));
    } else if (e.getSource() == cannoneer) {
      fleetPanel.getCurrentFleet().addCrew(crew.get("Cannoneer"));
    } else if (e.getSource() == explorer) {
      fleetPanel.getCurrentFleet().addCrew(crew.get("Explorer"));
    }
    fleetPanel.fleetChanged();
    ManagerMain.instance.tabPanel.repaint();
  }

}
TOP

Related Classes of net.coljac.pirates.gui.GenericPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.