gt: 				if (value > max) {
context: /*
   *   This file is part of entropy-triangle-weka-package.
   *
   *   This program is free software: you can redistribute it
   *   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/>.
   */
  
  /*
   *    ColorBar.java (Modified version of the Weka source file ClassPanel.java)
   *    Copyright of the changes (C) 2015-2017 Antonio Pastor
   *
   *    ClassPanel.java
   *    Copyright (C) 2000-2012 University of Waikato, Hamilton, New Zealand
   *
   */
  
  package weka.etplugin;
  
  import java.awt.BorderLayout;
  import java.awt.Color;
  import java.awt.Component;
  import java.awt.Font;
  import java.awt.FontMetrics;
  import java.awt.Graphics;
  import java.awt.Graphics2D;
  import java.awt.LinearGradientPaint;
  import java.awt.MultipleGradientPaint;
  import java.awt.Paint;
  import java.awt.PaintContext;
  import java.awt.Rectangle;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.InputEvent;
  import java.awt.event.MouseAdapter;
  import java.awt.event.MouseEvent;
  import java.awt.geom.AffineTransform;
  import java.awt.geom.Point2D;
  import java.awt.image.ColorModel;
  import java.awt.image.DataBuffer;
  import java.util.ArrayList;
  
  import javax.swing.JColorChooser;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  
  import weka.core.Instances;
  import weka.core.Utils;
  
  /**
   * This panel displays colored labels for nominal or string attributes and a rainbow style gradient for numeric attributes.
   * <br><br>
   * This class is a modified version of the Weka's {@link weka.gui.visualize.ClassPanel} to fit the needs of the Entropy Triangle package.
   * It incorporates the {@link #getColor(double)} method to get the color of the gradient or labels for a given value.
   * 
   * As the original <code>ClassPanel</code> of Weka,
   * the ColorBar notifies to the objects on the repainters list and
   * to the registered ActionListeners when the class attribute is changed or the range of values is modified.
   * 
   * @author Mark Hall (mhall@cs.waikato.ac.nz)
   * @author Malcolm Ware (mfw4@cs.waikato.ac.nz)
   * @author Antonio Pastor
   * @see weka.gui.visualize.ClassPanel
   */
  public class ColorBar extends JPanel {
  
  	/** for serialization */
  	private static final long serialVersionUID = -7969401840501661430L;
  
  	private boolean wekaVersion_3_7_12_or_older = new weka.core.Version().isOlder("3.7.13");
  
  	private DataBuffer colorBuffer = null;
  
  	private float[] dist = {0f, 0.35f, 0.7f, 1f};
  	private Color[] colors = {Color.BLUE, Color.GREEN, Color.YELLOW, Color.RED};
  
  	private int bar_width = 0;
  
  	/** Default maximum precision for the display of numeric values */
  	protected static int MAX_PRECISION = 10;
  
  	/** True if the colouring attribute is numeric */
  	private boolean m_isNumeric = false;
  
  	/** The height of the spectrum for numeric class */
  	private final int m_spectrumHeight = 5;
  
  	/** The maximum value for the colouring attribute */
  	private double m_maxC;
  
  	/** The minimum value for the colouring attribute */
  	private double m_minC;
  
  	/** The size of the ticks */
  	private final int m_tickSize = 5;
  
  	/** Font metrics */
  	private FontMetrics m_labelMetrics = null;
  
  	/** The font used in labeling */
  	private Font m_labelFont = null;
  
  	/** The amount of space to leave either side of the legend */
  	private int m_HorizontalPad = 0;
  
  	/** The precision with which to display real values */
  	private int m_precisionC;
  
  	/** The old width. */
  	private int m_oldWidth = -9000;
  
  	/** Instances being plotted */
  	private Instances m_Instances = null;
  
  	/** the list of colours to use for colouring nominal attribute labels */
  	private ArrayList<Color> m_colorList;
  
  	/**
  	 * An optional list of Components that use the colour list maintained by this
  	 * class. If the user changes a colour using the colour chooser, then these
  	 * components need to be repainted in order to display the change
  	 */
  	private final ArrayList<Component> m_Repainters = new ArrayList<Component>();
  
  	/**
  	 * An optional list of listeners who want to know when a colour changes.
  	 * Listeners are notified via an ActionEvent
  	 */
  	private final ArrayList<ActionListener> m_ColourChangeListeners = new ArrayList<ActionListener>();
  
  	/** default colours for colouring discrete class */
  	protected Color[] m_DefaultColors = { Color.blue, Color.red, Color.green,
  			Color.cyan, Color.pink, new Color(255, 0, 255), Color.orange,
  			new Color(255, 0, 0), new Color(0, 255, 0), Color.white };
  
  	/**
  	 * if set, it allows this panel to steer away from setting up a color in the
  	 * color list that is equal to the background color
  	 */
  	protected Color m_backgroundColor = null;
  
  	/**
  	 * Inner Inner class used to create labels for nominal attributes so that
  	 * there color can be changed.
  	 */
  	private class NomLabel extends JLabel {
  
  		/** for serialization */
  		private static final long serialVersionUID = -4686613106474820655L;
  
  		private int m_index = 0;
  
  		/**
  		 * Creates a label with its name and class index value.
  		 * 
  		 * @param name The name of the nominal class value.
  		 * @param id The index value for that class value.
  		 */
  		public NomLabel(String name, int id) {
  			super(name);
  			m_index = id;
  			this.addMouseListener(new MouseAdapter() {
  				@Override
  				public void mouseClicked(MouseEvent e) {
  					if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) {
  						Color tmp = JColorChooser.showDialog(ColorBar.this,
  								"Select new Color", m_colorList.get(m_index));
  						if (tmp != null) {
  							m_colorList.set(m_index, tmp);
  							m_oldWidth = -9000;
  							ColorBar.this.repaint();
  							if (m_Repainters.size() > 0) {
  								for (int i = 0; i < m_Repainters.size(); i++) {
  									(m_Repainters.get(i)).repaint();
  								}
  							}
  							if (m_ColourChangeListeners.size() > 0) {
  								for (int i = 0; i < m_ColourChangeListeners.size(); i++) {
  									(m_ColourChangeListeners.get(i))
  									.actionPerformed(new ActionEvent(this, 0, ""));
  								}
  							}
  						}
  					}
  				}
  			});
  		}
  	}
  
  	/** Default constructor, with default background color. */
  	public ColorBar() {
  		this(null);
  	}
  
  	/**
  	 * Constructor specifying the background color. 
  	 * @param background the background color of the panel
  	 */
  	public ColorBar(Color background) {
  		m_backgroundColor = background;
  		/** Set up some default colours */
  		m_colorList = new ArrayList<Color>(10);
  		for (int noa = m_colorList.size(); noa < 10; noa++) {
  			Color pc = m_DefaultColors[noa % 10];
  			int ija = noa / 10;
  			ija *= 2;
  			for (int j = 0; j < ija; j++) {
  				pc = pc.darker();
  			}
  			m_colorList.add(pc);
  		}
  		this.setVisible(true);
  	}
  
  	/**
  	 * Adds a component that will need to be repainted if the user changes the
  	 * color of a label.
  	 * 
  	 * @param c the component to be repainted
  	 */
  	public void addRepaintNotify(Component c) {
  		m_Repainters.add(c);
  	}
  
  	/**
  	 * Add an action listener that will be notified if the user changes the color
  	 * of a label
  	 * 
  	 * @param a an <code>ActionListener</code> value
  	 */
  	public void addActionListener(ActionListener a) {
  		m_ColourChangeListeners.add(a);
  	}
  
  	/**
  	 * Set up fonts and font metrics
  	 * 
  	 * @param gx the graphics context
  	 */
  	private void setFonts(Graphics gx) {
  		if (m_labelMetrics == null) {
  			m_labelFont = new Font("Monospaced", Font.PLAIN, 12);
  			m_labelMetrics = gx.getFontMetrics(m_labelFont);
  			int hf = m_labelMetrics.getAscent();
  			if (this.getHeight() < (3 * hf)) {
  				m_labelFont = new Font("Monospaced", Font.PLAIN, 11);
  				m_labelMetrics = gx.getFontMetrics(m_labelFont);
  			}
  		}
  		gx.setFont(m_labelFont);
  	}
  
  	/**
  	 * Set the instances.
  	 * 
  	 * @param insts the instances
  	 */
  	public void setInstances(Instances insts) {
  		m_Instances = insts;
  		if(insts==null){
  			this.m_isNumeric=false;
  			this.m_oldWidth = -9000;
  		} else {
  			setCindex(insts.classIndex());
  		}
  	}
  
  	/**
  	 * Set the index of the attribute to display colored labels for
  	 * 
  	 * @param cIndex the index of the attribute to display colored labels for
  	 */
  	public void setCindex(int cIndex) {
  		if (m_Instances != null && m_Instances.numAttributes() > 0) {
  			if (m_Instances.classAttribute().isNumeric()) {
  				setNumeric();
  			} else {
  				if (m_Instances.classAttribute().numValues() > m_colorList.size()) {
  					extendColourMap();
  				}
  				setNominal();
  			}
  		}
  	}
  
  	/**
  	 * Extends the list of colors if a new attribute with more values than the
  	 * previous one is chosen
  	 */
  	private void extendColourMap() {
  		for (int i = m_colorList.size(); i < m_Instances.classAttribute()
  				.numValues(); i++) {
  			Color pc = m_DefaultColors[i % 10];
  			int ija = i / 10;
  			ija *= 2;
  			for (int j = 0; j < ija; j++) {
  				pc = pc.brighter();
  			}
  			if (m_backgroundColor != null) {
  				pc = ColorBar.checkAgainstBackground(pc, m_backgroundColor);
  			}
  
  			m_colorList.add(pc);
  		}
  	}
  
  	protected void setDefaultColourList(Color[] list) {
  		m_DefaultColors = list;
  	}
  
  	/**
  	 * Set a list of colours to use for colouring labels
  	 * 
  	 * @param cols a list containing java.awt.Colors
  	 */
  	public void setColours(ArrayList<Color> cols) {
  		m_colorList = cols;
  	}
  
  	/**
  	 * Sets the legend to be for a nominal variable
  	 */
  	protected void setNominal() {
  		m_isNumeric = false;
  		m_HorizontalPad = 0;
  		m_oldWidth = -9000;
  
  		this.repaint();
  	}
  
  	/**
  	 * Sets the legend to be for a numeric variable
  	 */
  	protected void setNumeric() {
  		m_isNumeric = true;
  		/*
  		 * m_maxC = mxC; m_minC = mnC;
  		 */
  
  		double min = Double.POSITIVE_INFINITY;
  		double max = Double.NEGATIVE_INFINITY;
  		double value;
  
  		int numInstances = 0;
  		if (m_Instances != null) {
  			numInstances = m_Instances.numInstances();
  		}
  		for (int i = 0; i < numInstances; i++) {
  			if (!m_Instances.instance(i).classIsMissing()) {
  				value = m_Instances.instance(i).classValue();
  				if (value < min) {
  					min = value;
  				}
  