Back to index

wims  3.65+svn20090927
Histogram.java
Go to the documentation of this file.
00001 /*
00002  * @(#)Histogram.java
00003  * 
00004  * $Id: Histogram.java,v 1.35 2001/05/27 22:29:29 huaz Exp $
00005  * 
00006  * Created Novenmber 21, 2000, 11:27 PM
00007 */
00008 package SharpTools; 
00009 import java.awt.*;
00010 import java.awt.event.*;
00011 import javax.swing.*;
00012 import java.util.*;
00013 
00023 public class Histogram extends JFrame implements ActionListener {
00024     private SharpTools sharp;
00025     private JTable table;
00026     private SharpTableModel model;
00027     private JTabbedPane tab;
00028     private int width;
00029     private int height;
00030     private String title;
00031     private Point location;
00032     private Dimension dim;
00033     final ImageIcon histogramIcon=new ImageIcon(getClass().getResource("/images/chart.gif"));
00034     //final private ImageIcon histogramIcon = SharpTools.getImageIcon("chart.gif");
00035     
00036     //    private int selected = -1;    
00037     
00046     Histogram(SharpTools sharp, String title, int width, int height) {
00047        super(title);
00048        setSize(width, height);
00049        //     setIconImage(histogramIcon.getImage());
00050 
00051        this.sharp = sharp;
00052        this.table = sharp.getTable();
00053        this.model = sharp.getTableModel();
00054        this.title = title;
00055        this.width = width;
00056        this.height = height;
00057 
00058        tab = new JTabbedPane();
00059 
00060        // register toggle key
00061        table.registerKeyboardAction
00062            (this, SharpTools.translation.getProperty("Show"),
00063             KeyStroke.getKeyStroke(KeyEvent.VK_F8,0, false),
00064             JComponent.WHEN_FOCUSED);
00065 
00066        // register add histogram key
00067        table.registerKeyboardAction
00068            (this, SharpTools.translation.getProperty("Add"),
00069             KeyStroke.getKeyStroke(KeyEvent.VK_H, ActionEvent.CTRL_MASK, false),
00070             JComponent.WHEN_FOCUSED);
00071        
00072        
00073        Container container = getContentPane();
00074        container.setLayout(new BorderLayout());
00075 
00076        container.add(tab, BorderLayout.CENTER);
00077        /*
00078        if (selected >= 0) {
00079            selected = Math.min(selected, tab.getTabCount()-1);
00080            tab.setSelectedIndex(selected);
00081        }
00082        */
00083        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
00084     }
00085 
00086     // bring the dialog to the front; restore if minimized
00087     private void bringToFront() {
00088        if (getState() == Frame.ICONIFIED)
00089            setState(Frame.NORMAL);
00090        
00091        toFront();
00092     }
00093     
00097     public void show() {
00098        super.show();
00099        sharp.checkShowHistogramState();
00100     }
00101 
00105     public void hide() {
00106        super.hide();
00107        sharp.checkShowHistogramState();
00108     }
00109 
00116     public void add(String title, CellRange range) {
00117 
00118        bringToFront();
00119 
00120        if (!isVisible())
00121            show();
00122 
00123        TabPanel newTab = new TabPanel(model, range, this, tab);
00124        
00125        tab.addTab(title, null, newTab, range.toString());
00126        
00127        tab.setSelectedIndex(tab.getTabCount()-1);
00128        newTab.getOptions(true); // first time
00129     }
00130 
00134     public void toggle() {
00135        if (isVisible())
00136            hide();
00137        else if (hasChart()) {
00138            //     setSize(width, height);
00139            bringToFront();
00140            show();
00141        }
00142     }
00143 
00147     public void addHistogram() {
00148        //checks if anything is selected   
00149        if (table.getSelectedRowCount() != 0) { 
00150            CellRange range = new CellRange
00151               (table.getSelectedRows(), table.getSelectedColumns());
00152 
00153            String title = SharpTools.translation.getProperty("Chart")+" "+(tab.getTabCount()+1);
00154            add(title, range);
00155            
00156            sharp.checkShowHistogramState();
00157            
00158        } else {
00159             sharp.noCellsSelected(SharpTools.translation.getProperty("Histogram"));
00160         }
00161     }        
00162         
00168     public boolean hasChart() {
00169        return tab.getTabCount()>0;
00170     }
00171 
00180     public void actionPerformed(ActionEvent e) {
00181 
00182        if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Show"))==0) {
00183            toggle();
00184        }
00185        else if (e.getActionCommand().compareTo(SharpTools.translation.getProperty("Add"))==0) {
00186            addHistogram();
00187        }
00188     }
00189 
00190 }
00191