Package ch.bfh.ti.kybernetik.gui.swing

Source Code of ch.bfh.ti.kybernetik.gui.swing.EditLightBulbFrame

/**
* Copyright (C) BFH www.bfh.ch 2011
* Code written by: Patrick Dobler, Marc Folly
*
* 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 ch.bfh.ti.kybernetik.gui.swing;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import net.miginfocom.swing.MigLayout;
import ch.bfh.ti.kybernetik.engine.model.LightBulb;
import ch.bfh.ti.kybernetik.gui.slick.components.LightBulbComponent;

/**
* A {@link JFrame} which renders a input mask to edit a selected
* {@link LightBulb}
*
*/
class EditLightBulbFrame extends JFrame {

  /**
   *
   */
  private static final long serialVersionUID = 1L;

  private final LightBulbComponent lightBulbComponent;

  private JSlider lightBulbMaxIntensity;

  private JSlider lightBulbMaxRadius;

  EditLightBulbFrame(LightBulbComponent lightBulbComponent) {
    super();
    setTitle("Edit LightBulb");
    setSize(300, 300);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    this.lightBulbComponent = lightBulbComponent;
    this.init();
  }

  private void init() {
    JPanel panel = new JPanel(new MigLayout());
    getContentPane().add(panel);

    panel.add(new JLabel("LightBulb ID:"));
    panel.add(new JLabel("" + lightBulbComponent.hashCode()), "wrap");
    panel.add(new JLabel("Max LightBulb Intensity"));
    panel.add(getLightBulbMaxIntensity(), "wrap");
    panel.add(new JLabel("Max LightBulb Radius"));
    panel.add(getLightBulbMaxRadius(), "wrap");
  }

  private JSlider getLightBulbMaxIntensity() {
    if (lightBulbMaxIntensity == null) {
      final LightBulb lightBulb = lightBulbComponent.getModelObject();
      lightBulbMaxIntensity = new JSlider(JSlider.HORIZONTAL, 0, 1000, (int) lightBulb.getMaxIntensity());
      lightBulbMaxIntensity.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
          JSlider source = (JSlider) e.getSource();
          int value = source.getValue();
          lightBulb.setMaxIntensity(value);
        }
      });
    }
    return lightBulbMaxIntensity;
  }

  private JSlider getLightBulbMaxRadius() {
    if (lightBulbMaxRadius == null) {
      final LightBulb lightBulb = lightBulbComponent.getModelObject();
      lightBulbMaxRadius = new JSlider(JSlider.HORIZONTAL, 0, 1000, (int) lightBulb.getMaxRadius());
      lightBulbMaxRadius.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
          JSlider source = (JSlider) e.getSource();
          int value = source.getValue();
          lightBulb.setMaxRadius(value);
        }
      });
    }
    return lightBulbMaxRadius;
  }
}
TOP

Related Classes of ch.bfh.ti.kybernetik.gui.swing.EditLightBulbFrame

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.