package vu.ch.sirmackerberus.card;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import vu.ch.sirmackerberus.card.*;
/**
* Ermoeglicht das Verwalten verschiedenenr Cards.
*
* @author Sir MacKerberus
* @version 11.07.2004
*/
public abstract class CardManager extends JFrame implements ActionListener
{
public Vector interneVerwaltung = new Vector(); //interne Verwaltung der Cards
private JButton previous; //Die drei Buttons zur Steuerung des Stapels
private JButton next;
private JButton ok;
private JPanel CardWindow; //JPanel, das mit der jeweiligen Card gefüllt wird
private JPanel control; //Repräsentiert die drei Buttons zur Steuerung des Stapels
private int index = 0; //Beschreibt die Position der aktuellen Card im Stapel
private int card_size_x; //Enthält die Breite einer Karte
private int card_size_y; //Enthält die Höhe einer Karkte
/**
* Constructor for objects of class CardManager
*/
public CardManager(String title, int card_size_x, int card_size_y)
{
super(title);
this.getContentPane().setLayout(null);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setSize(card_size_x + 20, card_size_y + 100);
CardWindow = new JPanel();
CardWindow.setSize(card_size_x, card_size_y);
CardWindow.setLayout(null);
control = new JPanel();
control.setBorder(new TitledBorder("Control"));
control.setLayout(null);
previous = new JButton("Previous");
previous.addActionListener(this);
previous.setBounds(20, 20, 100, 20);
control.add(previous);
next = new JButton("Next");
next.addActionListener(this);
next.setBounds((card_size_x / 2) - 50, 20, 100, 20);
control.add(next);
ok = new JButton("Ok");
ok.addActionListener(this);
ok.setBounds(card_size_x - 120, 20, 100, 20);
control.add(ok);
CardWindow.setBounds(10, 10, card_size_x, card_size_y);
this.getContentPane().add(CardWindow);
control.setBounds(10, card_size_y + 20, card_size_x, 50);
this.getContentPane().add(control);
this.card_size_x = card_size_x;
this.card_size_y = card_size_y;
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source == previous)
{
previousCard();
}
if(source == next)
{
nextCard();
}
if(source == ok)
{
CardManagerEvent();
}
}
public void addCard(Card param_card)
{
interneVerwaltung.add(param_card);
}
private void showCard(int pointer)
{
Card card_pointer = (Card) interneVerwaltung.get(pointer);
previous.setEnabled(true);
next.setEnabled(true);
ok.setEnabled(true);
if(card_pointer == (Card) interneVerwaltung.firstElement())
{
previous.setEnabled(false);
}
if(card_pointer == (Card)interneVerwaltung.lastElement())
{
next.setEnabled(false);
}
if(card_pointer != (Card) interneVerwaltung.lastElement())
{
ok.setEnabled(false);
}
card_pointer.setBounds(0, 0, card_size_x, card_size_y);
CardWindow.add(card_pointer);
this.CardWindow.repaint();
}
public void load()
{
showCard(index);
}
private void previousCard()
{
index = index - 1;
this.load();
}
private void nextCard()
{
index = index + 1;
this.load();
}
public abstract void CardManagerEvent();
}