~ubuntu-branches/ubuntu/wily/weka/wily

« back to all changes in this revision

Viewing changes to src/main/java/weka/gui/visualize/MatrixPanel.java

  • Committer: Bazaar Package Importer
  • Author(s): tony mancill
  • Date: 2011-08-05 22:40:50 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110805224050-a01vkwst9epdi4sw
Tags: 3.6.5-1
* Team upload.
* New upstream version (Closes: #632082, #598400)
* Bump Standards-Version to 3.9.2 (no changes required).
* Freshen jar.patch; remove java_cup.patch (incorporated upstream)
* Add README.source to document process of obtaining .png resources.
* Add myself to Uploaders.

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
 * high). Datapoints missing a class value are displayed in black.
76
76
 * 
77
77
 * @author Ashraf M. Kibriya (amk14@cs.waikato.ac.nz)
78
 
 * @version $Revision: 1.18 $
 
78
 * @version $Revision: 7059 $
79
79
 */
80
80
public class MatrixPanel
81
81
  extends JPanel{
97
97
  protected JSplitPane jp;
98
98
  /** The button that updates the display to reflect the changes made by the user. 
99
99
      E.g. changed attribute set for the matrix    */
100
 
  protected JButton m_updateBt = new JButton("Update");
 
100
  protected JButton m_updateBt = new JButton(Messages.getInstance().getString("MatrixPanel_UpdateBt_JButton_Text"));
101
101
 
102
102
  /** The button to display a window to select attributes */
103
 
  protected JButton m_selAttrib = new JButton("Select Attributes");
 
103
  protected JButton m_selAttrib = new JButton(Messages.getInstance().getString("MatrixPanel_SelAttrib_JButton_Text"));
104
104
 
105
105
  /** The dataset for which this panel will display the plot matrix for  */
106
106
  protected Instances m_data=null;
136
136
  protected JTextField m_resamplePercent = new JTextField(5);
137
137
 
138
138
  /** The label for resample percentage */
139
 
  protected JButton m_resampleBt =  new JButton("SubSample % :");
 
139
  protected JButton m_resampleBt =  new JButton(Messages.getInstance().getString("MatrixPanel_ResampleBt_JButton_Text"));
140
140
 
141
141
  /** Random seed for random subsample */
142
142
  protected JTextField m_rseed = new JTextField(5);
143
143
 
144
144
  /** Displays the current size beside the slider bar for cell size */
145
 
  private final JLabel m_plotSizeLb = new JLabel("PlotSize: [100]");
 
145
  private final JLabel m_plotSizeLb = new JLabel(Messages.getInstance().getString("MatrixPanel_PlotSizeLb_JLabel_Text"));
146
146
 
147
147
  /** Displays the current size beside the slider bar for point size */
148
 
  private final JLabel m_pointSizeLb = new JLabel("PointSize: [10]");
 
148
  private final JLabel m_pointSizeLb = new JLabel(Messages.getInstance().getString("MatrixPanel_PointSizeLb_JLabel_Text"));
149
149
 
150
150
  /** This array contains the indices of the attributes currently selected  */
151
151
  private int [] m_selectedAttribs;
214
214
    m_selAttrib.addActionListener( new ActionListener() {
215
215
        public void actionPerformed(ActionEvent ae) {
216
216
          final JDialog jd = new JDialog((JFrame) MatrixPanel.this.getTopLevelAncestor(), 
217
 
                                         "Attribute Selection Panel",
 
217
                          Messages.getInstance().getString("MatrixPanel_Jd_JDialog_Text"),
218
218
                                         true);
219
219
 
220
220
          JPanel jp = new JPanel();
221
221
          JScrollPane js = new JScrollPane(m_attribList);
222
 
          JButton okBt = new JButton("OK");
223
 
          JButton cancelBt = new JButton("Cancel");
 
222
          JButton okBt = new JButton(Messages.getInstance().getString("MatrixPanel_OkBt_JButton_Text"));
 
223
          JButton cancelBt = new JButton(Messages.getInstance().getString("MatrixPanel_CancelBt_JButton_Text"));
224
224
          final int [] savedSelection = m_attribList.getSelectedIndices();
225
225
                                        
226
226
          okBt.addActionListener( new ActionListener() {        
283
283
      
284
284
    m_plotSize.addChangeListener( new ChangeListener() {
285
285
        public void stateChanged(ChangeEvent ce) {
286
 
          m_plotSizeLb.setText("PlotSize: ["+m_plotSize.getValue()+"]");
 
286
          m_plotSizeLb.setText(Messages.getInstance().getString("MatrixPanel_StateChanged_PlotSizeLb_Text_First") + m_plotSize.getValue() + Messages.getInstance().getString("MatrixPanel_StateChanged_PlotSizeLb_Text_Second"));
287
287
          m_plotSizeLb.setPreferredSize( m_plotLBSizeD );
288
288
          m_jitter.setMaximum( m_plotSize.getValue()/5 ); //20% of cell Size
289
289
        }
291
291
 
292
292
    m_pointSize.addChangeListener( new ChangeListener() {
293
293
        public void stateChanged(ChangeEvent ce) {
294
 
          m_pointSizeLb.setText("PointSize: ["+m_pointSize.getValue()+"]");
 
294
          m_pointSizeLb.setText(Messages.getInstance().getString("MatrixPanel_StateChanged_PointSizeLb_Text_First") + m_pointSize.getValue() + Messages.getInstance().getString("MatrixPanel_StateChanged_PointSizeLb_Text_Second"));
295
295
          m_pointSizeLb.setPreferredSize( m_pointLBSizeD );
296
296
          datapointSize = m_pointSize.getValue();
297
297
        }
299
299
 
300
300
    m_resampleBt.addActionListener( new ActionListener() { 
301
301
        public void actionPerformed(ActionEvent e) {
302
 
          JLabel rseedLb = new JLabel("Random Seed: ");
 
302
          JLabel rseedLb = new JLabel(Messages.getInstance().getString("MatrixPanel_ActionPerformed_RseedLb_JLabel_Text"));
303
303
          JTextField rseedTxt = m_rseed;
304
 
          JLabel percentLb = new JLabel("Subsample as");
305
 
          JLabel percent2Lb = new JLabel("% of input: ");
 
304
          JLabel percentLb = new JLabel(Messages.getInstance().getString("MatrixPanel_ActionPerformed_PercentLb_JLabel_Text"));
 
305
          JLabel percent2Lb = new JLabel(Messages.getInstance().getString("MatrixPanel_ActionPerformed_Percent2Lb_JLabel_Text"));
306
306
          final JTextField percentTxt = new JTextField(5);
307
307
          percentTxt.setText( m_resamplePercent.getText() );
308
 
          JButton doneBt = new JButton("Done");
 
308
          JButton doneBt = new JButton(Messages.getInstance().getString("MatrixPanel_ActionPerformed_DoneBt_JButton_Text"));
309
309
 
310
310
          final JDialog jd = new JDialog((JFrame) MatrixPanel.this.getTopLevelAncestor(), 
311
 
                                         "Subsample % Panel",
 
311
                          Messages.getInstance().getString("MatrixPanel_ActionPerformed_Jd_JDialog_Text"),
312
312
                                         true) {
313
313
              private static final long serialVersionUID = -269823533147146296L;
314
314
              
365
365
     
366
366
    m_plotLBSizeD = m_plotSizeLb.getPreferredSize();
367
367
    m_pointLBSizeD = m_pointSizeLb.getPreferredSize();
368
 
    m_pointSizeLb.setText("PointSize: [1]");
 
368
    m_pointSizeLb.setText(Messages.getInstance().getString("MatrixPanel_ActionPerformed_PointSizeLb_Text"));
369
369
    m_pointSizeLb.setPreferredSize( m_pointLBSizeD );
370
370
    m_resampleBt.setPreferredSize( m_selAttrib.getPreferredSize() );
371
371
 
380
380
    gbc.weightx=1; gbc.gridwidth = GridBagConstraints.REMAINDER;
381
381
    p4.add(m_pointSize, gbc);
382
382
    gbc.weightx=0; gbc.gridwidth = GridBagConstraints.RELATIVE;
383
 
    p4.add( new JLabel("Jitter: "), gbc);
 
383
    p4.add( new JLabel(Messages.getInstance().getString("MatrixPanel_ActionPerformed_P4_Text")), gbc);
384
384
    gbc.weightx=1; gbc.gridwidth = GridBagConstraints.REMAINDER;
385
385
    p4.add(m_jitter, gbc);
386
386
    p4.add(m_classAttrib, gbc);
398
398
    gbc.gridwidth = GridBagConstraints.REMAINDER;
399
399
    p3.add(m_resamplePercent, gbc);
400
400
    
401
 
    p2.setBorder(BorderFactory.createTitledBorder("Class Colour"));
 
401
    p2.setBorder(BorderFactory.createTitledBorder(Messages.getInstance().getString("MatrixPanel_ActionPerformed_P2_BorderFactoryCreateTitledBorder_Text")));
402
402
    p2.add(m_cp, BorderLayout.SOUTH);
403
403
 
404
404
    gbc.insets = new Insets(8,5,2,5);
438
438
    m_js.setViewportView( m_plotsPanel );
439
439
    m_js.setColumnHeaderView( m_plotsPanel.getColHeader() );
440
440
    m_js.setRowHeaderView( m_plotsPanel.getRowHeader() );
441
 
    final JLabel lb = new JLabel(" Plot Matrix");
 
441
    final JLabel lb = new JLabel(Messages.getInstance().getString("MatrixPanel_ActionPerformed_Lb_JLabel_Text"));
442
442
    lb.setFont(f); lb.setForeground(fontColor);
443
443
    lb.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
444
444
    m_js.setCorner(JScrollPane.UPPER_LEFT_CORNER, lb);
625
625
    for(int i=0; i<tempAttribNames.length; i++) {
626
626
      switch (m_data.attribute(i).type()) {
627
627
      case Attribute.NOMINAL:
628
 
        type = " (Nom)";
 
628
        type = Messages.getInstance().getString("MatrixPanel_SetupAttribLists_Type_AttributeNOMINAL_Text");
629
629
        break;
630
630
      case Attribute.NUMERIC:
631
 
        type = " (Num)";
 
631
        type = Messages.getInstance().getString("MatrixPanel_SetupAttribLists_Type_AttributeNUMERIC_Text");
632
632
        break;
633
633
      case Attribute.STRING:
634
 
        type = " (Str)";
 
634
        type = Messages.getInstance().getString("MatrixPanel_SetupAttribLists_Type_AttributeSTRING_Text");
635
635
        break;
636
636
      case Attribute.DATE:
637
 
        type = " (Dat)";
 
637
        type = Messages.getInstance().getString("MatrixPanel_SetupAttribLists_Type_AttributeDATE_Text");
638
638
        break;
639
639
      case Attribute.RELATIONAL:
640
 
        type = " (Rel)";
 
640
        type = Messages.getInstance().getString("MatrixPanel_SetupAttribLists_Type_AttributeRELATIONAL_Text");
641
641
        break;
642
642
      default:
643
 
        type = " (???)";
 
643
        type = Messages.getInstance().getString("MatrixPanel_SetupAttribLists_Type_AttributeDEFAULT_Text");
644
644
      }
645
 
      tempAttribNames[i] = new String("Colour: "+m_data.attribute(i).name()+" "+type);
 
645
      tempAttribNames[i] = new String(Messages.getInstance().getString("MatrixPanel_SetupAttribLists_Text_First") + m_data.attribute(i).name()+" "+type);
646
646
      m_classAttrib.addItem(tempAttribNames[i]);
647
647
    }
648
648
    if (m_data.classIndex() == -1)
665
665
      m_resamplePercent.setText(""+percnt);
666
666
    }
667
667
    else
668
 
      m_resamplePercent.setText("100");
 
668
      m_resamplePercent.setText(Messages.getInstance().getString("MatrixPanel_SetPercent_Text_First"));
669
669
  }
670
670
 
671
671
 
690
690
     Main method for testing this class
691
691
  */
692
692
  public static void main(String [] args)  {
693
 
    final JFrame jf = new JFrame("Weka Explorer: MatrixPanel");
694
 
    final JButton setBt = new JButton("Set Instances");
 
693
    final JFrame jf = new JFrame(Messages.getInstance().getString("MatrixPanel_Main_JFRame_Text"));
 
694
    final JButton setBt = new JButton(Messages.getInstance().getString("MatrixPanel_Main_SetBt_JButton_Text"));
695
695
    Instances data = null;
696
696
    try {
697
697
      if(args.length==1)
698
698
        data = new Instances( new BufferedReader( new FileReader(args[0])) ); 
699
699
      else {
700
 
        System.out.println("Usage: MatrixPanel <arff file>"); 
 
700
        System.out.println(Messages.getInstance().getString("MatrixPanel_Main_Text")); 
701
701
        System.exit(-1);
702
702
      }
703
703
    } catch(IOException ex) { ex.printStackTrace(); System.exit(-1); }
707
707
    setBt.addActionListener( new ActionListener() {
708
708
        public void actionPerformed(ActionEvent e) {
709
709
          JFileChooser chooser = new JFileChooser(new java.io.File(System.getProperty("user.dir")));
710
 
          ExtensionFileFilter myfilter = new ExtensionFileFilter("arff", "Arff data files");
 
710
          ExtensionFileFilter myfilter = new ExtensionFileFilter(Messages.getInstance().getString("MatrixPanel_Main_ActionPerformed_ExtensionFileFilter_Text_First"), Messages.getInstance().getString("MatrixPanel_Main_ActionPerformed_ExtensionFileFilter_Text_Second"));
711
711
          chooser.setFileFilter(myfilter);
712
712
          int returnVal = chooser.showOpenDialog(jf);
713
713
                  
714
714
          if(returnVal == JFileChooser.APPROVE_OPTION)
715
715
            {
716
716
              try{
717
 
                System.out.println("You chose to open this file: " +chooser.getSelectedFile().getName());
 
717
                System.out.println(Messages.getInstance().getString("MatrixPanel_Main_ActionPerformed_Text_First") + chooser.getSelectedFile().getName());
718
718
                Instances in = new Instances ( new FileReader(chooser.getSelectedFile().getAbsolutePath()) );
719
719
                mp.setInstances(in);
720
720
              }
762
762
     */
763
763
    public Plot() {
764
764
      super();
765
 
      this.setToolTipText("blah");
 
765
      this.setToolTipText(Messages.getInstance().getString("MatrixPanel_Plot_SetToolTipText_Text"));
766
766
      this.addMouseMotionListener( this );
767
767
      this.addMouseListener( this );
768
768
      initialize();
911
911
      if(found==0)
912
912
        return;
913
913
 
914
 
      JFrame jf = new JFrame("Weka Explorer: Visualizing "+m_data.relationName() );
 
914
      JFrame jf = new JFrame(Messages.getInstance().getString("MatrixPanel_Plot_JFrame_Text") + m_data.relationName() );
915
915
      VisualizePanel vp = new VisualizePanel();
916
916
      try {
917
917
        PlotData2D pd = new PlotData2D(m_data);
918
 
        pd.setPlotName("Master Plot");
 
918
        pd.setPlotName(Messages.getInstance().getString("MatrixPanel_Plot_Pd_SetPlotName_Text"));
919
919
        vp.setMasterPlot(pd);
920
920
        //System.out.println("x: "+i+" y: "+j);
921
921
        vp.setXIndex(m_selectedAttribs[i]);
956
956
        for(int i=0; i<m_selectedAttribs.length; i++) {
957
957
          if(event.getX()>=xpos && event.getX()<=xpos+cellSize+extpad)
958
958
            if(event.getY()>=ypos && event.getY()<=ypos+cellSize+extpad)
959
 
              return("X: "+m_data.attribute(m_selectedAttribs[i]).name()+
960
 
                     " Y: "+m_data.attribute(m_selectedAttribs[j]).name()+
961
 
                     " (click to enlarge)");
 
959
              return(Messages.getInstance().getString("MatrixPanel_Plot_GetToolTipText_Text_First") + m_data.attribute(m_selectedAttribs[i]).name()+
 
960
                     Messages.getInstance().getString("MatrixPanel_Plot_GetToolTipText_Text_Second") + m_data.attribute(m_selectedAttribs[j]).name()+
 
961
                     Messages.getInstance().getString("MatrixPanel_Plot_GetToolTipText_Text_Third"));
962
962
          xpos+=cellSize+extpad;
963
963
        }
964
964
        xpos=extpad;
965
965
        ypos+=cellSize+extpad;
966
966
      }
967
 
      return ("Matrix Panel");
 
967
      return (Messages.getInstance().getString("MatrixPanel_Plot_GetToolTipText_Text_Fourth"));
968
968
    }
969
969
 
970
970
    /**  Paints a single Plot at xpos, ypos. and xattrib and yattrib on X and