package jas2.swingstudio;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import jas2.hep.*;
import jas2.hist.*;
import jas2.util.*;
import jas2.util.layout.PercentLayout;
import jas2.plot.PrintHelper;
import jas2.util.encoder.GifEncoder;
import jas2.job.PageAccess;
import jas2.job.PlotAccess;
public class JASPage extends JPanel implements HasCommandProcessor, ChangableContainer,
jas2.plot.HasPopupItems, Closable
{
/**
* Builds a JASPage from a PageAccess object. The PageAccess object
* is a proxy for a hep.analysis.Page object.
*/
public JASPage(PageAccess page)
{
setBackground(Color.white);
int n = page.getNPlots();
if (n > 0)
{
boolean constained = page.getPlot(0).isConstrained();
if (constained) setLayout(new PercentLayout());
else setLayout(n);
m_plots = new Vector(n);
for (int i=0; i 0) menu.addSeparator();
menu.add(new JASMenuItem("Remove Plot", 'R'));
menu.add(new JASMenuItem("Print Page...", 'P'));
//menu.add(new JASMenuItem("Full Screen",'F')); // Not ready for prime time.
}
public static void calculateTitlesAndLabels(JASHist plot)
{
if (plot.getNumberOfDataSources() == 0) return;
String[][] titles = new String[plot.getNumberOfDataSources()][];
Enumeration e = plot.getDataSources();
int n = 0;
int minLength = Integer.MAX_VALUE;
for (; n < titles.length; n++)
{
JASHistData data = (JASHistData) e.nextElement();
if (data.getDataSource() instanceof TreeData)
{
titles[n] = ((TreeData) data.getDataSource()).getItem().path;
}
else titles[n] = new String[]{ data.getTitle() };
minLength = Math.min(minLength,titles[n].length);
}
/// Figure out which elements of the titles are in common, we build an array that
/// contains indeces of the title elements that are in common.
boolean[] indeces = new boolean[minLength];
for (int j=0; j 0) title.append(" - ");
title.append(titles[0][j]);
}
}
plot.setTitle(title.toString());
// Now build the individual key entries
e = plot.getDataSources();
for (int k=0; e.hasMoreElements(); k++)
{
JASHistData data = (JASHistData) e.nextElement();
StringBuffer legend = new StringBuffer();
for (int j=0; j= minLength || !indeces[j])
{
if (legend.length() > 0) legend.append(" - ");
legend.append(titles[k][j]);
}
}
data.setLegendText(legend.toString());
}
}
private boolean isPrinting = false;
private boolean isPainting = false;
private Vector m_plots;
private Border border = new PageBorder();
private JASHist currentPlot;
private PageCommandProcessor commandProcessor = new PageCommandProcessor();
private static JavaAnalysisStudio jas = JavaAnalysisStudio.getApp();
private MouseListener ml = new MouseAdapter()
{
public void mousePressed(final MouseEvent e)
{
JASHist newPlot = (JASHist) e.getSource() ;
if (currentPlot != newPlot)
{
currentPlot.deselected();
currentPlot.repaint();
currentPlot = newPlot;
currentPlotChanged();
currentPlot.repaint();
}
}
};
private class PageBorder extends AbstractBorder
{
public void paintBorder(Component c,Graphics g,int x,int y,int width,int height)
{
// We dont want the border if we are printing, or if we are copy/pasting
// or if only the object itself (not the Page) is being painted
if (!isPrinting && isPainting && !PrintHelper.isPrinting())
{
g.setColor(c==currentPlot ? Color.blue : getBackground());
g.drawRect(x, y, width-1, height-1);
}
}
public boolean isBorderOpaque()
{
return true;
}
public Insets getBorderInsets(Component c)
{
return new Insets(1, 1, 1, 1);
}
}
private class PageCommandProcessor extends JASCommandProcessor
{
public void onPrint() throws Exception
{
PrintHelper ph = PrintHelper.instance();
ph.printTarget(JASPage.this);
}
public void onPrintPage() throws Exception
{
PrintHelper ph = PrintHelper.instance();
ph.printTarget(JASPage.this);
}
public void onProperties()
{
currentPlot.showProperties();
}
public void enableProperties(final JASState state)
{
state.setEnabled(currentPlot.supportsProperties());
}
public void onSaveAs() throws IOException
{
SaveAsDialog dlg = new SaveAsDialog(JASPage.this);
// dlg.pack();
// dlg.doModal();
}
public void onCopy()
{
VectorGraphicsTransferable t = new VectorGraphicsTransferable(JASPage.this);
getToolkit().getSystemClipboard().setContents(t,t);
}
public void onRemovePlot()
{
removePlot();
setChanged();
}
public void enableRemovePlot(final JASState state)
{
state.setEnabled(m_plots.size()>1);
}
// convert setChanged() to public
public void setChanged()
{
super.setChanged();
}
}
}
Ads help maintain this website.