package jas2.hist;
import jas2.plot.TextBlock;
import jas2.util.DoubleWithError;
import jas2.util.ScientificFormat;
import java.awt.Component;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.text.Format;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
/**
* The main class used to display and format statistics.
* When a user selects showStatistics from the plots popupmenu, a statistics text block
* is displayed showing each displayed plots' statistics (Vector stats) and name. The statistics block
* requires a number formatting method to be set (setFormat), the default method is
* implemented by jas2.util.ScientificFormat.
*/
public class StatisticsBlock extends TextBlock
{
public StatisticsBlock()
{
this(new ScientificFormat());
}
public StatisticsBlock(Format g)
{
super("Statistics");
//set default format types
initializeDefaultFormats(g);
setFormat(g);
}
/**
* Calculates and returns the total number of lines to be displayed in the statistics block,
* including a draw line seperator, plot title (if available) and formatted
* statistics for each data set displayed in the plot area.
*/
public int getNLines()
{
NothingToShow =false;
if (stats.isEmpty()) return 1;
int n = 0;
for (int i=0; i1 && s.length>0))
{
addline = new String[s.length+2];
addline[0] = "\n";
addline[1] = "addplottitle";
for(int i=0;i0)
{
addline = new String[s.length+1];
addline[0] = "\n";
for(int i=0;i0))
{
splitstringalign=a;
}else throw new IllegalArgumentException("Integer splitstringalign must be set to 1,2 or 3");
}
/**Sets the (int) showtitles to one of three values:SHOWTITLES_ALWAYS,
* SHOWTITLES_NEVER, SHOWTITLES_AUTOMATIC. The value controls when a plot title is
* displayed in the stat block. If showtitles = SHOWTITLES_AUTOMATIC then titles will
* be displayed if there is more than one plot displayed.
*/
public void setShowTitles(int settitles)
{
if((settitles<4) && (settitles >0))
{
showtitles = settitles;
}else throw new IllegalArgumentException("Integer showtitles must be set to 1,2 or 3");
}
/**Returns the (int) showtitles which has three values:SHOWTITLES_ALWAYS,
* SHOWTITLES_NEVER, SHOWTITLES_AUTOMATIC. The value controls when a plot title is
* displayed in the stat block. If showtitles = SHOWTITLES_AUTOMATIC then titles will
* be displayed if there is more than one plot displayed.
*/
public int getShowTitles()
{
return showtitles;
}
public void modifyPopupMenu(final JPopupMenu menu, final Component source)
{
if (menu.getComponentCount() > 0) menu.addSeparator();
statpropertiesitem = new JMenuItem(getPrefix()+" Properties...")
{
protected void fireActionPerformed( final ActionEvent e)
{
statwin = new StatsWindow(StatisticsBlock.this);
final Frame frame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, this);
statwin.showStatsWindow();
}
};
menu.add(statpropertiesitem);
super.modifyPopupMenu(menu,source);
}
private boolean NothingToShow;
private Format f;
private Hashtable formats = new Hashtable();
private StatsWindow statwin;
private Vector stats = new Vector();
private String[] selectedentries;
private String[] listnames;
private int showtitles = SHOWTITLES_AUTOMATIC;
private int splitstringalign=RIGHTALIGNSPLIT;
private String line;
private JMenuItem statpropertiesitem;
private boolean alwaysall=true;
final public static int SHOWTITLES_ALWAYS = 1;
final public static int SHOWTITLES_NEVER = 2;
final public static int SHOWTITLES_AUTOMATIC = 3;
final public static int LEFTALIGNSPLIT = 1;
final public static int RIGHTALIGNSPLIT = 2;
final public static int NOALIGNSPLIT = 3;
}
Ads help maintain this website.