Back to index

wims  3.65+svn20090927
Public Member Functions | Package Functions | Static Package Functions | Package Attributes | Private Member Functions | Private Attributes
SharpTools.TabPanel Class Reference

A class for one panel, which includes the image panel and all the control components. More...

Inheritance diagram for SharpTools.TabPanel:
Inheritance graph
[legend]
Collaboration diagram for SharpTools.TabPanel:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void update ()
 Update everything of the histogram.

Package Functions

 TabPanel (SharpTableModel tableModel, CellRange range, Histogram frame, JTabbedPane pane)
 Constructor.
void getOptions (boolean firstTime)
 Parameter configuration for this histogram.

Static Package Functions

static float[] getValueMinMax (SharpTableModel model, CellRange range)
 get the min and max values from the cell range

Package Attributes

Float endvalue
Float bucketvalue
Float xmin
Float xmax
Float ymin
Float ymax
Float xunit
Float yunit

Private Member Functions

void updateData ()
 Read values from textfields and update the histogram's data; Nothing else.

Private Attributes

Histogram owner
SharpTableModel model
JTabbedPane tab
HistoPanel histo
CellRange range
Float startvalue
boolean bypercentage = true

Detailed Description

A class for one panel, which includes the image panel and all the control components.

In short, this is everything for one chart.

Author:
Hua Zhong
Version:
Revision:
1.5

Definition at line 21 of file TabPanel.java.


Constructor & Destructor Documentation

SharpTools.TabPanel.TabPanel ( SharpTableModel  tableModel,
CellRange  range,
Histogram  frame,
JTabbedPane  pane 
) [inline, package]

Constructor.

Parameters:
tableModelthe SharpTableModel as backend data
rangethe selected cell range
framethe parent frame
panethe JTabbedPane object that this panel belongs to

Definition at line 41 of file TabPanel.java.

                                               {
       super();
       this.owner = frame;
       this.model = tableModel;
       this.tab = pane;
       this.range = range;
       
       // set layout - tedious..
       setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
       setLayout(new BorderLayout());

       // add the HistoPanel - our canvas
       histo = new HistoPanel();
       histo.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
       add(histo, BorderLayout.CENTER);   

       // buttons
       JPanel south = new JPanel();
       south.setBorder(BorderFactory.createEmptyBorder(10,0,0,0));
       south.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 0));

       // Remove button
       final ImageIcon noIcon=new ImageIcon(getClass().getResource("/images/no.gif"));
       JButton closeButton = new JButton(SharpTools.translation.getProperty("Remove"), noIcon);
//     JButton closeButton = new JButton("Remove", SharpTools.getImageIcon("no.gif"));
       closeButton.setMnemonic(KeyEvent.VK_R);
       closeButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  // remove the current tab
                  tab.remove(tab.getSelectedComponent());
                  
                  // if there is no tab left, close the window
                  if (tab.getTabCount() == 0) {
                     owner.hide();
                  }
              }
           });

       // Options button
       final ImageIcon optionsIcon=new ImageIcon(getClass().getResource("/images/options.gif"));
       JButton optionButton = new JButton(SharpTools.translation.getProperty("Options"), optionsIcon);   
       //JButton optionButton = new JButton("Options...", SharpTools.getImageIcon("options.gif"));       
       optionButton.setMnemonic(KeyEvent.VK_O);
       optionButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  getOptions(false);                 
              }
           });

       // Update button
       final ImageIcon refreshIcon=new ImageIcon(getClass().getResource("/images/refresh.gif"));
       JButton updateButton = new JButton (SharpTools.translation.getProperty("Update"), refreshIcon);
       //JButton updateButton = new JButton ("Update", SharpTools.getImageIcon("refresh.gif"));

       updateButton.setMnemonic(KeyEvent.VK_U);
       updateButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  updateData();
                  histo.paintImmediately(0, 0, histo.getWidth(),
                                      histo.getHeight());
              }
           });
       
       south.add(updateButton);
       south.add(optionButton);
       south.add(closeButton);
       
       add(south, BorderLayout.SOUTH);
    }    

Here is the call graph for this function:


Member Function Documentation

void SharpTools.TabPanel.getOptions ( boolean  firstTime) [inline, package]

Parameter configuration for this histogram.

Parameters:
firstTimewhether this is the first time to call the dialog

Definition at line 117 of file TabPanel.java.

                                       {

       HistoDialog option = new HistoDialog(owner);
       option.pack();
       option.setLocationRelativeTo(owner);

       // title textfield
       option.setTitleField(tab.getTitleAt(tab.getSelectedIndex()));
       
       if (firstTime) {
           // set initial values
           option.setCellRange(range);

           float[] minmax = TabPanel.getValueMinMax(model, range);
           int min = (int)minmax[0];
           int max = (int)minmax[1];

           startvalue = new Float(min);       
           endvalue = new Float(max);         

           // estimate a reasonable bucket size
           int power = 0;
           if (max>min)
              power = (int)((Math.log(max-min)/Math.log(10)));
           if (power<0)
              power--;
           
           bucketvalue = new Float(Math.pow(10, power));
           xunit = bucketvalue;

           xmin = new Float(min);
           xmax = new Float(max);
           
           ymin = new Float(0);
           ymax = new Float(100);
           yunit = new Float(10);

       }

       // initialize all the fields
       option.setCellRange(range);
       option.setStartValue(startvalue);
       option.setEndValue(endvalue);
       option.setBucket(bucketvalue);
       option.setXMin(xmin);
       option.setXMax(xmax);
       option.setXUnit(xunit);
       option.setYMin(ymin);
       option.setYMax(ymax);
       option.setYUnit(yunit);
       option.setByPercentage(bypercentage);

       // show the dialog
       option.setVisible(true);

       if (!option.isCancelled()) {

           // save data
           tab.setTitleAt(tab.getSelectedIndex(),
                        option.getTitleField());
           range = option.getCellRange();
           startvalue = option.getStartValue();
           endvalue = option.getEndValue();
           bucketvalue = option.getBucket();
           xmin = option.getXMin();
           xmax = option.getXMax();
           ymin = option.getYMin();
           ymax = option.getYMax();
           xunit = option.getXUnit();
           yunit = option.getYUnit();
           bypercentage = option.getByPercentage();

           // do an update to repaint the chart
           update();
       }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static float [] SharpTools.TabPanel.getValueMinMax ( SharpTableModel  model,
CellRange  range 
) [inline, static, package]

get the min and max values from the cell range

Parameters:
modelthe backend table data source
rangethe range of cells
Returns:
two float numbers, first is min and second is max

Definition at line 201 of file TabPanel.java.

                                                                          {
       // value[0] is min, value[1] is max
       float[] values = { Float.MAX_VALUE, Float.MIN_VALUE };
       float v;
       for (int i = range.getStartRow(); i <= range.getEndRow(); i++)
           for (int j = range.getStartCol(); j <= range.getEndCol(); j++) {
              try {
                  v = model.getNumericValueAt(i, j).floatValue();
              }
              catch (ParserException e) {
                  v= 0;
              }

              values[0] = Math.min(values[0], v);
              values[1] = Math.max(values[1], v);
           }

       return values;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.TabPanel.update ( ) [inline]

Update everything of the histogram.

This is called after we change options by the Option dialog.

Definition at line 226 of file TabPanel.java.

                         {

       float start = startvalue.floatValue();
       float end = endvalue.floatValue();
       float bucket = bucketvalue.floatValue();
       float nb = (end-start)/bucket;
       int nbars = (int)nb;
       if (nbars > (int)nbars)
           nbars++;

       // values below and above
       nbars += 2;

       float[] data = new float[nbars];
       histo.setData(data);

       updateData();
       
       histo.setStartEndPoints(start, end, bucket);
       histo.setXYAxis(xmin.floatValue(),
                     xmax.floatValue(),
                     xunit.floatValue(),
                     ymin.floatValue(),
                     ymax.floatValue(),
                     yunit.floatValue());

       histo.setByPercentage(bypercentage);
       histo.paintImmediately(0, 0, histo.getWidth(), histo.getHeight());
       
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void SharpTools.TabPanel.updateData ( ) [inline, private]

Read values from textfields and update the histogram's data; Nothing else.

This is called from the "Update" button.

Definition at line 263 of file TabPanel.java.

                              {

       float start = startvalue.floatValue();
       float end = endvalue.floatValue();
       float bucket = bucketvalue.floatValue();
       float[] data = histo.getData();
       
       for (int k = 0; k < data.length; k++)
           data[k] = 0;
       
       // two more buckets below start or above end
       //     float scale = end-start+2;

       for (int i = range.getStartRow(); i <= range.getEndRow(); i++) {
            for (int j = range.getStartCol(); j <= range.getEndCol(); j++) {
              
              float value = 0;

              try {
                  value = model.getNumericValueAt(i, j).floatValue();
              }
              catch (Exception e) {
              }
              
              if (value < start)
                  data[0]++;
              else if (value > end)
                  data[data.length-1]++;
              else {
                  int index = (int)((value-start)/bucket)+1;
                  data[index]++;
              }
           }
       }

       if (bypercentage) {
           int nums = range.getWidth()*range.getHeight();
           for (int k = 0; k < data.length; k++)
              data[k] = data[k]*100/nums;
       }
       // histo.setData(data); - dont need it since we've modified in-place
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 29 of file TabPanel.java.

Definition at line 31 of file TabPanel.java.

Definition at line 29 of file TabPanel.java.

Definition at line 26 of file TabPanel.java.

Definition at line 24 of file TabPanel.java.

Definition at line 23 of file TabPanel.java.

Definition at line 28 of file TabPanel.java.

Definition at line 29 of file TabPanel.java.

JTabbedPane SharpTools.TabPanel.tab [private]

Definition at line 25 of file TabPanel.java.

Float SharpTools.TabPanel.xmax [package]

Definition at line 29 of file TabPanel.java.

Float SharpTools.TabPanel.xmin [package]

Definition at line 29 of file TabPanel.java.

Float SharpTools.TabPanel.xunit [package]

Definition at line 29 of file TabPanel.java.

Float SharpTools.TabPanel.ymax [package]

Definition at line 29 of file TabPanel.java.

Float SharpTools.TabPanel.ymin [package]

Definition at line 29 of file TabPanel.java.

Float SharpTools.TabPanel.yunit [package]

Definition at line 29 of file TabPanel.java.


The documentation for this class was generated from the following file: