java.awt.FontMetrics fm = a.getFontMetrics(a.getFont());
  public MatrixPanel() {    m_rseed.setText("1");    origDist.setSelected(true);    distGroup.add(origDist);    distGroup.add(unifDist);     /** Setting up GUI **/    m_selAttrib.addActionListener( new ActionListener() {	public void actionPerformed(ActionEvent ae) {	  final JDialog jd = new JDialog((JFrame) MatrixPanel.this.getTopLevelAncestor(), 					 "Attribute Selection Panel",					 true);	  JPanel jp = new JPanel();	  JScrollPane js = new JScrollPane(m_attribList);	  JButton okBt = new JButton("OK");	  JButton cancelBt = new JButton("Cancel");	  final int [] savedSelection = m_attribList.getSelectedIndices();						  okBt.addActionListener( new ActionListener() {		      public void actionPerformed(ActionEvent e) {		jd.dispose(); }	    } );	  cancelBt.addActionListener( new ActionListener() {	      public void actionPerformed(ActionEvent e) {		m_attribList.setSelectedIndices(savedSelection);		jd.dispose();}	    });	  jd.addWindowListener( new WindowAdapter() {	      public void windowClosing(WindowEvent e) {		m_attribList.setSelectedIndices(savedSelection);		jd.dispose();}	    });	  jp.add(okBt);	  jp.add(cancelBt);	  jd.getContentPane().add(js, BorderLayout.CENTER); 	  jd.getContentPane().add(jp, BorderLayout.SOUTH);	  if(js.getPreferredSize().width < 200)	    jd.setSize( 250, 250 );	  else	    jd.setSize( (int) js.getPreferredSize().width+10, 250);						  jd.setLocation( m_selAttrib.getLocationOnScreen().x,			  m_selAttrib.getLocationOnScreen().y-jd.getHeight() );	  jd.show();	}      });          m_updateBt.addActionListener( new ActionListener() {	public void actionPerformed(ActionEvent e) {	  m_selectedAttribs = m_attribList.getSelectedIndices();	  initInternalFields();						  Plot a = m_plotsPanel;	  java.awt.FontMetrics fm = a.getFontMetrics(a.getFont());	  a.setCellSize( m_plotSize.getValue() );						  Dimension d = new Dimension((m_selectedAttribs.length)*(a.cellSize+a.extpad)+100, 				      (m_selectedAttribs.length)*(a.cellSize+a.extpad)				      +2*fm.getHeight()+a.extpad);	  //System.out.println("Size: "+a.cellSize+" Extpad: "+	  //		   a.extpad+" selected: "+	  //		   m_selectedAttribs.length+' '+d); 	  a.setPreferredSize(d);	  a.setSize( a.getPreferredSize() );	  a.setJitter( m_jitter.getValue() );						  m_js.revalidate();	  m_cp.setColours(m_colorList);	  m_cp.setCindex(m_classIndex);						  repaint();	}      });    m_updateBt.setPreferredSize( m_selAttrib.getPreferredSize() );          m_plotSize.addChangeListener( new ChangeListener() {	public void stateChanged(ChangeEvent ce) {	  m_plotSizeLb.setText("PlotSize: ["+m_plotSize.getValue()+"]");	  m_plotSizeLb.setPreferredSize( m_plotLBSizeD );	  m_jitter.setMaximum( m_plotSize.getValue()/5 ); //20% of cell Size	}      });     m_pointSize.addChangeListener( new ChangeListener() {	public void stateChanged(ChangeEvent ce) {	  m_pointSizeLb.setText("PointSize: ["+m_pointSize.getValue()+"]");	  m_pointSizeLb.setPreferredSize( m_pointLBSizeD );	  datapointSize = m_pointSize.getValue();	}      });     m_resampleBt.addActionListener( new ActionListener() { 	public void actionPerformed(ActionEvent e) {	  JLabel rseedLb = new JLabel("Random Seed: ");	  JTextField rseedTxt = m_rseed;	  JLabel percentLb = new JLabel("Subsample as");	  JLabel percent2Lb = new JLabel("% of input: ");	  final JTextField percentTxt = new JTextField(5);	  percentTxt.setText( m_resamplePercent.getText() );	  JButton doneBt = new JButton("Done");	  final JDialog jd = new JDialog((JFrame) MatrixPanel.this.getTopLevelAncestor(), 					 "Attribute Selection Panel",					 true) {	      public void dispose() { 		m_resamplePercent.setText(percentTxt.getText());		super.dispose();	      } 	    };	  jd.setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE );			       	  doneBt.addActionListener( new ActionListener(){ 	      public void actionPerformed(ActionEvent ae) {		jd.dispose();  	      }	    });	  GridBagLayout gbl = new GridBagLayout();	  GridBagConstraints gbc = new GridBagConstraints();	  JPanel p1 = new JPanel( gbl );			  gbc.anchor = gbc.WEST; gbc.fill = gbc.HORIZONTAL;	  gbc.insets = new Insets(0,2,2,2);	  gbc.gridwidth = gbc.RELATIVE;	  p1.add(rseedLb, gbc); gbc.weightx = 0;	  gbc.gridwidth = gbc.REMAINDER; gbc.weightx=1;	  p1.add(rseedTxt, gbc);	  gbc.insets = new Insets(8,2,0,2); gbc.weightx=0;	  p1.add(percentLb, gbc);	  gbc.insets = new Insets(0,2,2,2); gbc.gridwidth = gbc.RELATIVE;	  p1.add(percent2Lb, gbc);	  gbc.gridwidth = gbc.REMAINDER; gbc.weightx=1;	  p1.add(percentTxt, gbc);	  gbc.insets = new Insets(8,2,2,2);	  if(m_data.attribute(m_classAttrib.getSelectedIndex()).isNominal()) {	    JPanel p2 = new JPanel( gbl );	    p2.add(origDist, gbc);	    p2.add(unifDist, gbc);	    p2.setBorder( BorderFactory.createTitledBorder("Class Distribution") );	    p1.add(p2, gbc);	  }					  JPanel p3 = new JPanel( gbl );	  gbc.fill = gbc.HORIZONTAL; gbc.gridwidth = gbc.REMAINDER;	  gbc.weightx = 1;  gbc.weighty = 0;	  p3.add(p1, gbc);	  gbc.insets = new Insets(8,4,8,4);	  p3.add(doneBt, gbc);					   	  jd.getContentPane().setLayout( new BorderLayout() );	  jd.getContentPane().add(p3, BorderLayout.NORTH);	  jd.pack();	  jd.setLocation( m_resampleBt.getLocationOnScreen().x,			  m_resampleBt.getLocationOnScreen().y-jd.getHeight() );	  jd.show();	}      });    optionsPanel = new JPanel( new GridBagLayout() ); //all the rest of the panels are in here.    final JPanel p2 = new JPanel( new BorderLayout() );  //this has class colour panel    final JPanel p3 = new JPanel( new GridBagLayout() ); //this has update and select buttons    final JPanel p4 = new JPanel( new GridBagLayout() ); //this has the slider bars and combobox    GridBagConstraints gbc = new GridBagConstraints();         m_plotLBSizeD = m_plotSizeLb.getPreferredSize();    m_pointLBSizeD = m_pointSizeLb.getPreferredSize();    m_pointSizeLb.setText("PointSize: [1]");    m_pointSizeLb.setPreferredSize( m_pointLBSizeD );    m_resampleBt.setPreferredSize( m_selAttrib.getPreferredSize() );    gbc.fill = gbc.HORIZONTAL;    gbc.anchor = gbc.NORTHWEST;    gbc.insets = new Insets(2,2,2,2);    p4.add(m_plotSizeLb, gbc);    gbc.weightx=1; gbc.gridwidth = gbc.REMAINDER;    p4.add(m_plotSize, gbc);    gbc.weightx=0; gbc.gridwidth = gbc.RELATIVE;    p4.add(m_pointSizeLb, gbc);    gbc.weightx=1; gbc.gridwidth = gbc.REMAINDER;    p4.add(m_pointSize, gbc);    gbc.weightx=0; gbc.gridwidth = gbc.RELATIVE;    p4.add( new JLabel("Jitter: "), gbc);    gbc.weightx=1; gbc.gridwidth = gbc.REMAINDER;    p4.add(m_jitter, gbc);    p4.add(m_classAttrib, gbc);          gbc.gridwidth = gbc.REMAINDER;    gbc.weightx=1;    gbc.fill = gbc.NONE;    p3.add(m_updateBt, gbc);    p3.add(m_selAttrib, gbc);    gbc.gridwidth = gbc.RELATIVE;    gbc.weightx = 0;    gbc.fill = gbc.VERTICAL;    gbc.anchor = gbc.WEST;    p3.add(m_resampleBt, gbc);    gbc.gridwidth = gbc.REMAINDER;    p3.add(m_resamplePercent, gbc);        p2.setBorder(BorderFactory.createTitledBorder("Class Colour"));    p2.add(m_cp, BorderLayout.SOUTH);    gbc.insets = new Insets(8,5,2,5);    gbc.anchor = gbc.SOUTHWEST; gbc.fill = gbc.HORIZONTAL; gbc.weightx=1;    gbc.gridwidth = gbc.RELATIVE;    optionsPanel.add(p4, gbc);    gbc.gridwidth = gbc.REMAINDER;    optionsPanel.add(p3, gbc);    optionsPanel.add(p2, gbc);    this.addComponentListener( new ComponentAdapter() {	public void componentResized(ComponentEvent cv) {	  m_js.setMinimumSize( new Dimension(MatrixPanel.this.getWidth(),					     MatrixPanel.this.getHeight()					     -optionsPanel.getPreferredSize().height-10));	  jp.setDividerLocation( MatrixPanel.this.getHeight()-optionsPanel.getPreferredSize().height-10 );	}      });    optionsPanel.setMinimumSize( new Dimension(0,0) );    jp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, m_js, optionsPanel);    jp.setOneTouchExpandable(true);    jp.setResizeWeight(1);    this.setLayout( new BorderLayout() );    this.add(jp, BorderLayout.CENTER);    /** Setting up the initial color list **/    for(int i=0; i<m_defaultColors.length-1; i++)      m_colorList.addElement(m_defaultColors[i]);          /** Initializing internal fields and components **/    m_plotsPanel = new Plot();    m_plotsPanel.setLayout(null);    m_plotsPanel.setFont( new java.awt.Font("Dialog", java.awt.Font.BOLD, 11) );    m_js.getHorizontalScrollBar().setUnitIncrement( 10 );    m_js.getVerticalScrollBar().setUnitIncrement( 10 );     m_js.setViewportView( m_plotsPanel );    m_cp.setInstances(m_data);    m_cp.setBorder(BorderFactory.createEmptyBorder(15,10,10,10));    m_cp.addRepaintNotify(m_plotsPanel);    //m_updateBt.doClick(); //not until setting up the instances  }