Package eas.startSetup.marbBuilder

Source Code of eas.startSetup.marbBuilder.SensorenDarstellung

/*
* Datei:          SensorenDarstellung.java
* Autor(en):      Lukas König
* Java-Version:   1.4
* Erstellt (vor): 18.08.2007
*
* (c) This file and the EAS (Easy Agent Simulation) framework containing it
* is protected by Creative Commons by-nc-sa license. Any altered or
* further developed versions of this file have to meet the agreements
* stated by the license conditions.
*
* In a nutshell
* -------------
* You are free:
* - to Share -- to copy, distribute and transmit the work
* - to Remix -- to adapt the work
*
* Under the following conditions:
* - Attribution -- You must attribute the work in the manner specified by the
*   author or licensor (but not in any way that suggests that they endorse
*   you or your use of the work).
* - Noncommercial -- You may not use this work for commercial purposes.
* - Share Alike -- If you alter, transform, or build upon this work, you may
*   distribute the resulting work only under the same or a similar license to
*   this one.
*
* + Detailed license conditions (Germany):
*   http://creativecommons.org/licenses/by-nc-sa/3.0/de/
* + Detailed license conditions (unported):
*   http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en
*
* This header must be placed in the beginning of any version of this file.
*/

package eas.startSetup.marbBuilder;


import eas.miscellaneous.system.windowFrames.WindClosAdaptNormal;
import eas.simulation.agent.GenericSensor;
import eas.simulation.spatial.sim2D.marbSimulation.RobEA;

import java.awt.Color;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.util.LinkedList;


/**
* Implementiert ein Fenster, in dem eine Reihe von Werten angezeigt werden.
* Diese werden im Zusammenhang mit der Simulation als Sensorwerte
* interpretiert.
*
* @author Lukas König
*/
public class SensorenDarstellung extends Frame {

    /**
     * Generiert am 18.08.07.
     */
    private static final long serialVersionUID = -340261808019118079L;

    /**
     * Ein Array von Labels.
     */
    private Label[] labels;

    /**
     * Ein Array von Textfeldern.
     */
    private TextField[] textfelder;

    /**
     * Konstruktor.
     *
     * @param sensAnzahl   Die Anzahl der anzuzeigenden Sensoren.
     * @param berSensoren  Die Anzahl der berechneten Sensoren.
     * @param rob          Der Roboter, dessen Sensoren dargestellt werden.
     *
     * @throws HeadlessException
     */
    public SensorenDarstellung(
            final int sensAnzahl,
            final int berSensoren,
            final RobEA rob) {

        super("Sensor values");

        LinkedList<GenericSensor<?, ?, ?>> genSens = rob.getGenSensListOrdered();
        Panel p1 = new Panel();
        Panel p2 = new Panel();
//        p1.setLayout(new GridLayout(berSensoren, 0));
//        p2.setLayout(new GridLayout(sensAnzahl - berSensoren, 0));
        this.setLayout(new GridLayout(2, 0));
        boolean b = false;

        this.labels = new Label[sensAnzahl + genSens.size()];
        this.textfelder = new TextField[sensAnzahl];

        // Setze berechnete Sensoren-Felder.
        for (int i = 0; i < berSensoren; i++) {
            this.labels[i] = new Label("Sensor" + (i + 1));
            this.textfelder[i] = new TextField("0", 3);
            p1.add(this.labels[i]);
            p1.add(this.textfelder[i]);
        }

        // Setze generische Sensoren-Felder.
        for (int i = 0; i < genSens.size(); i++) {
            if (genSens.get(i) != null) {
                this.labels[i] = new Label(genSens.get(i).id());
                this.textfelder[i] = new TextField("0", 3);
                p2.add(this.labels[i]);
                p2.add(this.textfelder[i]);
                b = true;
            } else if (b) {
                break;
            }
        }
//        labels[Konstanten.BEAMER - 1].setText("Beamer");
        p1.setForeground(Color.BLUE);

        this.add(p1);
        this.add(p2);
        this.addWindowListener(new WindClosAdaptNormal());
    }

    /**
     * Setzt einen Sensor in der Bildschirmdarstellung auf einen Wert.
     *
     * @param sensor  Der Sensor, dessen Wert gesetzt wird.
     * @param wert    Der Wert, auf den der Sensor gesetzt wird.
     */
    public void setSensor(final int sensor,  final int wert) {
        this.textfelder[sensor].setText("" + wert);
    }
   
    /**
     * Setzt einen generischen Sensor auf einen Wert.
     *
     * @param sensID  Die ID des Sensors.
     *
     * @param wert  Der zu setzende Wert.
     */
    public void setGenSensor(final String sensID, final String wert) {
        for (int i = 0; i < this.labels.length; i++) {
            if (this.labels[i] != null
                    && this.labels[i].getText().equals(sensID)) {
                this.textfelder[i].setText(wert);
            }
        }
    }
}
TOP

Related Classes of eas.startSetup.marbBuilder.SensorenDarstellung

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.