
weka.gui.visualize.LegendPanel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of weka-stable Show documentation
Show all versions of weka-stable Show documentation
The Waikato Environment for Knowledge Analysis (WEKA), a machine
learning workbench. This is the stable version. Apart from bugfixes, this version
does not receive any other updates.
/*
* 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 2 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, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* LegendPanel.java
* Copyright (C) 2000 University of Waikato, Hamilton, New Zealand
*
*/
package weka.gui.visualize;
import weka.core.FastVector;
import weka.core.Instances;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JColorChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
/**
* This panel displays legends for a list of plots. If a given plot
* has a custom colour defined then this panel allows the colour to
* be changed.
*
* @author Mark Hall ([email protected])
* @version $Revision: 7059 $
*/
public class LegendPanel
extends JScrollPane {
/** for serialization */
private static final long serialVersionUID = -1262384440543001505L;
/** the list of plot elements */
protected FastVector m_plots;
/** the panel that contains the legend entries */
protected JPanel m_span=null;
/** a list of components that need to be repainted when a colour is
changed */
protected FastVector m_Repainters = new FastVector();
/**
* Inner class for handling legend entries
*/
protected class LegendEntry
extends JPanel {
/** for serialization */
private static final long serialVersionUID = 3879990289042935670L;
/** the data for this legend entry */
private PlotData2D m_plotData=null;
/** the index (in the list of plots) of the data for this legend---
used to draw the correct shape for this data */
private int m_dataIndex;
/** the text part of this legend */
private JLabel m_legendText;
/** displays the point shape associated with this legend entry */
private JPanel m_pointShape;
public LegendEntry(PlotData2D data, int dataIndex) {
javax.swing.ToolTipManager.sharedInstance().setDismissDelay(5000);
m_plotData = data;
m_dataIndex = dataIndex;
// this.setBackground(Color.black);
/* this.setPreferredSize(new Dimension(0, 20));
this.setMinimumSize(new Dimension(0, 20)); */
if (m_plotData.m_useCustomColour) {
this.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if ((e.getModifiers() & e.BUTTON1_MASK) == e.BUTTON1_MASK) {
Color tmp = JColorChooser.showDialog
(LegendPanel.this, Messages.getInstance().getString("LegendPanel_Main_JColorChooserShowDialog_Text"),
m_plotData.m_customColour);
if (tmp != null) {
m_plotData.m_customColour = tmp;
m_legendText.setForeground(tmp);
if (m_Repainters.size() > 0) {
for (int i=0;i").length;
for (int i=0;i 0) {
constraints.gridheight = (numLines + 2);
} */
m_span.add(tmp, constraints);
}
}
/**
* Main method for testing this class
* @param args a list of arff files
*/
public static void main(String [] args) {
try {
if (args.length < 1) {
System.err.println(Messages.getInstance().getString("LegendPanel_Main_Error_Text_First"));
System.exit(1);
}
final javax.swing.JFrame jf =
new javax.swing.JFrame(Messages.getInstance().getString("LegendPanel_Main_JFrame_Text"));
jf.setSize(100,100);
jf.getContentPane().setLayout(new BorderLayout());
final LegendPanel p2 = new LegendPanel();
jf.getContentPane().add(p2, BorderLayout.CENTER);
jf.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
jf.dispose();
System.exit(0);
}
});
FastVector plotList = new FastVector();
for (int j=0;j
© 2015 - 2025 Weber Informatics LLC | Privacy Policy