Package fmg.fmg8.graphVis.fensterDialoge

Source Code of fmg.fmg8.graphVis.fensterDialoge.Ankreuzdialog

/*
* Datei: Ankreuzdialog.java
* Autor(en):        Lukas K�nig
* Java-Version:     6.0
* Erstellt:         13.02.2009
*
* (c) Lukas K�nig, die Datei unterliegt der LGPL
* -> http://www.gnu.de/lgpl-ger.html
*/

package fmg.fmg8.graphVis.fensterDialoge;

import fmg.fmg8.graphVis.MultiLineLabel;
import fmg.fmg8.umgebung2D.Vektor2D;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Dialog;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Checkbox;
import java.util.ArrayList;
import java.util.Iterator;


/**
* Implementierung eines allgemeinen Dialogs.
*
* @author Lukas K�nig
*/
public class Ankreuzdialog extends Dialog implements ActionListener {
   
    /**
     * Die Serial-Version-ID vom 28. April 2007
     */
    private static final long serialVersionUID = 2504188077455833733L;

    /**
     * Das gew�hlte Element.
     */
    private String result;

    /**
     * Die Auswahlelemente.
     */
    private Checkbox[] choices;
   
    /**
     * Enth�lt die ausgew�hlten Elemente.
     */
    private ArrayList<String> auswahl;
   
    /**
     * Der Konstruktor.
     *
     * @param owner     Das Vaterfenster.
     * @param msg       Anzuzeigende Nachricht.
     * @param titel     Der Titel des Fensters.
     * @param buttons   Liste von Strings, die von den anzuzeigenden
     *                  Buttons dargestellt werden.
     * @param elemente  Liste der ankreuzbaren Elemente.
     * @param aktiv     Welche Elemente angekreuzt sind.
     */
    public Ankreuzdialog(final Frame              owner,
                         final String             msg,
                         final String             titel,
                         final ArrayList<String>  buttons,
                         final ArrayList<String>  elemente,
                         final ArrayList<Boolean> aktiv) {
        super(owner, titel, true);

        final int locationX = 200;
        final int locationY = 200;
        final int borderX = 4;
        final int borderY = 4;
        final int lrMargin = 20;
        final int tbMargin = 10;
        Iterator<String> it;
        Button butt;
        int i;
       
        this.choices = new Checkbox[elemente.size()];

        this.setAlwaysOnTop(true);
       
        //Fenster
        this.setLayout(new BorderLayout(borderX, borderY));
        this.setResizable(false);
        this.setLocation(locationX, locationY);

        //Message
        MultiLineLabel lab = new MultiLineLabel(msg);
        lab.setLeftRightMargin(lrMargin);
        lab.setTopBottomMargin(tbMargin);
        this.add(lab, BorderLayout.NORTH);

        //Buttons
        Panel panel = new Panel();
        panel.setLayout(new FlowLayout(FlowLayout.CENTER));

        it = buttons.iterator();
        while (it.hasNext()) {
            butt = new Button(it.next());
            butt.addActionListener(this);
            panel.add(butt);
        }

        Panel panelChoice = new Panel();
        panelChoice.setLayout(new GridLayout(elemente.size(), 1));

        i = 0;
        it = elemente.iterator();
        while (it.hasNext()) {
            this.choices[i] = new Checkbox(it.next());
            this.choices[i].setState(aktiv.get(i));
           
            panelChoice.add(this.choices[i]);
            i++;
        }

        this.add(new Panel(), BorderLayout.WEST);
        this.add(panelChoice, BorderLayout.CENTER);
        this.add(panel, BorderLayout.SOUTH);

        this.pack();
    }

    /**
     * F�ngt das Klicken auf einen Button ab.
     *
     * @param event  Das ausgel�ste Ereignis.
     */
    public void actionPerformed(final ActionEvent event) {
        this.result = event.getActionCommand();
        this.auswahl = new ArrayList<String>();
       
        for (int i = 0; i < this.choices.length; i++) {
            if (this.choices[i].getState()) {
                this.auswahl.add((this.choices[i].getLabel()));
            }
        }

        this.setVisible(false);
        this.dispose();
    }

    /**
     * Gibt die Wahl des Benutzers zur�ck.
     *
     * @return  Das Ergebnis des Benutzers.
     */
    public String getResult() {
        return this.result;
    }
   
    /**
     * Sets the position of the window.
     *
     * @param pos  Position vector.
     */
    public void setPosition(final Vektor2D pos) {
        this.setBounds((int) pos.x, (int) pos.y,
                       this.getWidth(), this.getHeight());
    }
   
    /**
     * Sets the size of the window.
     *
     * @param size  Size vector.
     */
    public void setSize(final Vektor2D size) {
        this.setBounds(this.getX(), this.getY(),
                       (int) size.x, (int) size.y);
    }

    /**
     * @return Returns the auswahl.
     */
    public ArrayList<String> getAuswahl() {
        return this.auswahl;
    }
}
TOP

Related Classes of fmg.fmg8.graphVis.fensterDialoge.Ankreuzdialog

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.