//==================================================================================================
// G r a p h i c                                                                               Java
// I n t e g e r I n d i c a t o r
//                                                                                By Bruno Bachelet
//==================================================================================================
// Copyright (c) 1999-2016
// Bruno Bachelet - bruno@nawouak.net - http://www.nawouak.net
//
// This file is part of the B++ Library. This library is free software; you can redistribute it
// and/or modify it under the terms of the GNU Library General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This library 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 Library General Public License for more details (http://www.gnu.org).

/*DESCRIPTION*/
/* This module provides a class to create an indicator component that displays an integer value. */

// Package //---------------------------------------------------------------------------------------
package bpp.graphic;

// Importation //-----------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;

// I n t e g e r I n d i c a t o r  Class //--------------------------------------------------------
/*CLASS IntegerIndicator */
/* Represents a component that displays an integer value. */
public class IntegerIndicator extends Panel {
 //---------------------------------------------------------------------------------------Attributes
 protected TextField atLabel;   // Component displaying the integer value.
 protected int       atMaximum; // Maximum value to be displayed.
 protected Label     atTitle;   // Component displaying the title.
 protected int       atValue;   // Value to be displayed.
 //--------------------------------------------------------------------------------------Constructor
 /*METHOD IntegerIndicator */
 /* Builds an indicator for a given value. The maximum value that can be reached must be provided,
    <I>0</I> means there is no limit. */
 public IntegerIndicator(int agValue,int agMaximum) {
  super();

  atMaximum=agMaximum;
  atValue=agValue;

  setLayout(new BorderLayout(0,0));
  atLabel=new TextField(valueString(),15);
  atLabel.setEditable(false);
  add(atLabel,BorderLayout.CENTER);
 }
 //--------------------------------------------------------------------------------------Constructor
 /*METHOD IntegerIndicator */
 /* Builds an indicator with a title for a given value. The maximum value that can be reached must
    be provided, <I>0</I> means there is no limit. */
 public IntegerIndicator(int agValue,int agMaximum,String agTitle) {
  super();

  atMaximum=agMaximum;
  atValue=agValue;

  setLayout(new BorderLayout(0,0));
  atLabel=new TextField(valueString(),15);
  atLabel.setEditable(false);
  atTitle=new Label(agTitle,Label.CENTER);
  add(atTitle,BorderLayout.NORTH);
  add(atLabel,BorderLayout.CENTER);
 }
 //------------------------------------------------------------------------------------------Maximum
 /*METHOD IntegerIndicator */ /* Returns the maximum value of the indicator. */
 public int maximum() { return (atMaximum); }
 //--------------------------------------------------------------------------------------------Value
 /*METHOD IntegerIndicator */ /* Returns the value of the indicator. */
 public int value() { return (atValue); }
 //---------------------------------------------------------------------------------------SetMaximum
 /*METHOD IntegerIndicator */ /* Sets the maximum value of the indicator. */
 public void setMaximum(int agMaximum) {
  atMaximum=agMaximum;
  atLabel.setText(valueString());
 }
 //-----------------------------------------------------------------------------------------SetValue
 /*METHOD IntegerIndicator */ /* Sets the value of the indicator. */
 public void setValue(int agValue) {
  atValue=agValue;
  atLabel.setText(valueString());
 }
 //--------------------------------------------------------------------------------------ValueString
 protected String valueString()
 { return (value()+(maximum()==0 ? "" : " / "+maximum())); }
}

// End //-------------------------------------------------------------------------------------------