⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 visualizepanel.java

📁 wekaUT是 university texas austin 开发的基于weka的半指导学习(semi supervised learning)的分类器
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	String xcolKey = thisClass+"."+relationName+".XDimension";	String ycolKey = thisClass+"."+relationName+".YDimension";	String ccolKey = thisClass+"."+relationName+".ColourDimension";      	m_preferredXDimension = VisualizeUtils.VISUALIZE_PROPERTIES.	  getProperty(xcolKey);	if (m_preferredXDimension == null) {	  System.err.println("No preferred X dimension found in "			     +VisualizeUtils.PROPERTY_FILE			     +" for "+xcolKey);	} else {	  System.err.println("Setting preferred X dimension to "			     +m_preferredXDimension);	}	m_preferredYDimension = VisualizeUtils.VISUALIZE_PROPERTIES.	  getProperty(ycolKey);	if (m_preferredYDimension == null) {	  System.err.println("No preferred Y dimension found in "			     +VisualizeUtils.PROPERTY_FILE			     +" for "+ycolKey);	} else {	  System.err.println("Setting preferred dimension Y to "			     +m_preferredYDimension);	}	m_preferredColourDimension = VisualizeUtils.VISUALIZE_PROPERTIES.	  getProperty(ccolKey);	if (m_preferredColourDimension == null) {	  System.err.println("No preferred Colour dimension found in "			     +VisualizeUtils.PROPERTY_FILE			     +" for "+ycolKey);	} else {	  System.err.println("Setting preferred Colour dimension to "			     +m_preferredColourDimension);	}      }    }  }  /**   * Constructor   */  public VisualizePanel() {    setProperties(null);    m_FileChooser.setFileFilter(m_ArffFilter);    m_FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);    m_XCombo.setToolTipText("Select the attribute for the x axis");    m_YCombo.setToolTipText("Select the attribute for the y axis");    m_ColourCombo.setToolTipText("Select the attribute to colour on");    m_ShapeCombo.setToolTipText("Select the shape to use for data selection");     m_XCombo.setPreferredSize(COMBO_SIZE);    m_YCombo.setPreferredSize(COMBO_SIZE);    m_ColourCombo.setPreferredSize(COMBO_SIZE);    m_ShapeCombo.setPreferredSize(COMBO_SIZE);    m_XCombo.setMaximumSize(COMBO_SIZE);    m_YCombo.setMaximumSize(COMBO_SIZE);    m_ColourCombo.setMaximumSize(COMBO_SIZE);    m_ShapeCombo.setMaximumSize(COMBO_SIZE);        m_XCombo.setMinimumSize(COMBO_SIZE);    m_YCombo.setMinimumSize(COMBO_SIZE);    m_ColourCombo.setMinimumSize(COMBO_SIZE);    m_ShapeCombo.setMinimumSize(COMBO_SIZE);    //////////    m_XCombo.setEnabled(false);    m_YCombo.setEnabled(false);    m_ColourCombo.setEnabled(false);    m_ShapeCombo.setEnabled(false);    // tell the class panel and the legend panel that we want to know when     // colours change    m_classPanel.addRepaintNotify(this);    m_legendPanel.addRepaintNotify(this);    m_colorList = new FastVector(10);    for (int noa = m_colorList.size(); noa < 10; noa++) {      Color pc = m_DefaultColors[noa % 10];      int ija =  noa / 10;      ija *= 2;       for (int j=0;j<ija;j++) {	pc = pc.darker();      }            m_colorList.addElement(pc);    }    m_plot.setColours(m_colorList);    m_classPanel.setColours(m_colorList);    m_attrib.setColours(m_colorList);    m_attrib.addAttributePanelListener(new AttributePanelListener() {	public void attributeSelectionChange(AttributePanelEvent e) {	  if (e.m_xChange) {	    m_XCombo.setSelectedIndex(e.m_indexVal);	  } else {	    m_YCombo.setSelectedIndex(e.m_indexVal);	  }	}      });        m_XCombo.addActionListener(new ActionListener() {	public void actionPerformed(ActionEvent e) {	  int selected = m_XCombo.getSelectedIndex();	  if (selected < 0) {	    selected = 0;	  }	  m_plot.setXindex(selected);	 	  // try sending on the event if anyone is listening	  if (listener != null) {	    listener.actionPerformed(e);	  }	}      });    m_YCombo.addActionListener(new ActionListener() {	public void actionPerformed(ActionEvent e) {	  int selected = m_YCombo.getSelectedIndex();	  if (selected < 0) {	    selected = 0;	  }	  m_plot.setYindex(selected);	 	  // try sending on the event if anyone is listening	  if (listener != null) {	    listener.actionPerformed(e);	  }	}      });    m_ColourCombo.addActionListener(new ActionListener() {	public void actionPerformed(ActionEvent e) {	  int selected = m_ColourCombo.getSelectedIndex();	  if (selected < 0) {	    selected = 0;	  }	  m_plot.setCindex(selected);	  if (listener != null) {	    listener.actionPerformed(e);	  }	}      });        ///////    m_ShapeCombo.addActionListener(new ActionListener() {	public void actionPerformed(ActionEvent e) {	  int selected = m_ShapeCombo.getSelectedIndex();	  if (selected < 0) {	    selected = 0;	  }	  m_plot.setSindex(selected);	  // try sending on the event if anyone is listening	  if (listener != null) {	    listener.actionPerformed(e);	  }	}      });    ///////////////////////////////////////    m_Jitter.addChangeListener(new ChangeListener() {	public void stateChanged(ChangeEvent e) {	  m_plot.setJitter(m_Jitter.getValue());	}      });    m_saveBut.setEnabled(false);    m_saveBut.setToolTipText("Save the visible instances to a file");    m_saveBut.addActionListener(new ActionListener() {	public void actionPerformed(ActionEvent e) {	  saveVisibleInstances();	}      });        JPanel combos = new JPanel();    GridBagLayout gb = new GridBagLayout();    GridBagConstraints constraints = new GridBagConstraints();    m_XCombo.setLightWeightPopupEnabled(false);    m_YCombo.setLightWeightPopupEnabled(false);    m_ColourCombo.setLightWeightPopupEnabled(false);    m_ShapeCombo.setLightWeightPopupEnabled(false);    combos.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));    combos.setLayout(gb);    constraints.gridx=0;constraints.gridy=0;constraints.weightx=5;    constraints.fill = GridBagConstraints.HORIZONTAL;    constraints.gridwidth=2;constraints.gridheight=1;    constraints.insets = new Insets(0,2,0,2);    combos.add(m_XCombo,constraints);    constraints.gridx=2;constraints.gridy=0;constraints.weightx=5;    constraints.gridwidth=2;constraints.gridheight=1;    combos.add(m_YCombo,constraints);    constraints.gridx=0;constraints.gridy=1;constraints.weightx=5;    constraints.gridwidth=2;constraints.gridheight=1;    combos.add(m_ColourCombo,constraints);    //    constraints.gridx=2;constraints.gridy=1;constraints.weightx=5;    constraints.gridwidth=2;constraints.gridheight=1;    combos.add(m_ShapeCombo,constraints);       JPanel mbts = new JPanel();    mbts.setLayout(new GridLayout(1,3));    mbts.add(m_submit); mbts.add(m_cancel); mbts.add(m_saveBut);    constraints.gridx=0;constraints.gridy=2;constraints.weightx=5;    constraints.gridwidth=2;constraints.gridheight=1;    combos.add(mbts, constraints);    ////////////////////////////////    constraints.gridx=2;constraints.gridy=2;constraints.weightx=5;    constraints.gridwidth=1;constraints.gridheight=1;    constraints.insets = new Insets(10,0,0,5);    combos.add(m_JitterLab,constraints);    constraints.gridx=3;constraints.gridy=2;    constraints.weightx=5;    constraints.insets = new Insets(10,0,0,0);    combos.add(m_Jitter,constraints);    m_classSurround = new JPanel();    m_classSurround.      setBorder(BorderFactory.createTitledBorder("Class colour"));     m_classSurround.setLayout(new BorderLayout());    m_classPanel.setBorder(BorderFactory.createEmptyBorder(15,10,10,10));    m_classSurround.add(m_classPanel, BorderLayout.CENTER);    GridBagLayout gb2 = new GridBagLayout();    m_plotSurround.setBorder(BorderFactory.createTitledBorder("Plot"));    m_plotSurround.setLayout(gb2);    constraints.fill = constraints.BOTH;    constraints.insets = new Insets(0, 0, 0, 10);    constraints.gridx=0;constraints.gridy=0;constraints.weightx=3;    constraints.gridwidth=4;constraints.gridheight=1;constraints.weighty=5;    m_plotSurround.add(m_plot, constraints);        if (m_showAttBars) {      constraints.insets = new Insets(0, 0, 0, 0);      constraints.gridx=4;constraints.gridy=0;constraints.weightx=1;      constraints.gridwidth=1;constraints.gridheight=1;constraints.weighty=5;      m_plotSurround.add(m_attrib, constraints);    }    setLayout(new BorderLayout());    add(combos, BorderLayout.NORTH);    add(m_plotSurround, BorderLayout.CENTER);    add(m_classSurround, BorderLayout.SOUTH);        String [] SNames = new String [4];    SNames[0] = "Select Instance";    SNames[1] = "Rectangle";    SNames[2] = "Polygon";    SNames[3] = "Polyline";    m_ShapeCombo.setModel(new DefaultComboBoxModel(SNames));    m_ShapeCombo.setEnabled(true);  }  /**   * Save the currently visible set of instances to a file   */  private void saveVisibleInstances() {    FastVector plots = m_plot.m_plot2D.getPlots();    if (plots != null) {      PlotData2D master = (PlotData2D)plots.elementAt(0);      Instances saveInsts = new Instances(master.getPlotInstances());      for (int i = 1; i < plots.size(); i++) {	PlotData2D temp = (PlotData2D)plots.elementAt(i);	Instances addInsts = temp.getPlotInstances();	for (int j = 0; j < addInsts.numInstances(); j++) {	  saveInsts.add(addInsts.instance(j));	}      }      try {	int returnVal = m_FileChooser.showSaveDialog(this);	if (returnVal == JFileChooser.APPROVE_OPTION) {	  File sFile = m_FileChooser.getSelectedFile();	  if (!sFile.getName().toLowerCase().	      endsWith(Instances.FILE_EXTENSION)) {	    sFile = new File(sFile.getParent(), sFile.getName() 			     + Instances.FILE_EXTENSION);	  }	  File selected = sFile;	  Writer w = new BufferedWriter(new FileWriter(selected));	  w.write(saveInsts.toString());	  w.close();	}      } catch (Exception ex) {	ex.printStackTrace();      }    }  }  /**   * Sets the index used for colouring. If this method is called then   * the supplied index is used and the combo box for selecting colouring   * attribute is disabled.   * @param index the index of the attribute to use for colouring   */  public void setColourIndex(int index) {    if (index >= 0) {      m_ColourCombo.setSelectedIndex(index);    } else {      m_ColourCombo.setSelectedIndex(0);    }    m_ColourCombo.setEnabled(false);  }      /**   * Set the index of the attribute for the x axis    * @param index the index for the x axis   * @exception Exception if index is out of range.   */  public void setXIndex(int index) throws Exception {    if (index >= 0 && index < m_XCombo.getItemCount()) {      m_XCombo.setSelectedIndex(index);    } else {      throw new Exception("x index is out of range!");    }  }  /**   * Get the index of the attribute on the x axis   * @return the index of the attribute on the x axis   */  public int getXIndex() {    return m_XCombo.getSelectedIndex();  }  /**   * Set the index of the attribute for the y axis    * @param index the index for the y axis   * @exception Exception if index is out of range.   */  public void setYIndex(int index) throws Exception {    if (index >= 0 && index < m_YCombo.getItemCount()) {      m_YCombo.setSelectedIndex(index);    } else {      throw new Exception("y index is out of range!");    }  }    /**   * Get the index of the attribute on the y axis   * @return the index of the attribute on the x axis   */  public int getYIndex() {    return m_YCombo.getSelectedIndex();  }  /**   * Get the index of the attribute selected for coloring   * @return the index of the attribute on the x axis   */  public int getCIndex() {    return m_ColourCombo.getSelectedIndex();  }  /**   * Get the index of the shape selected for creating splits.   * @return The index of the shape.   */  public int getSIndex() {    return m_ShapeCombo.getSelectedIndex();  }    /**    * Set the shape for creating splits.   * @param index The index of the shape.   * @exception Exception if index is out of range.   */  public void setSIndex(int index) throws Exception {    if (index >= 0 && index < m_ShapeCombo.getItemCount()) {      m_ShapeCombo.setSelectedIndex(index);    }    else {      throw new Exception("s index is out of range!");    }  }  /**   * Add a listener for this visualize panel   * @param act an ActionListener   */  public void addActionListener(ActionListener act) {    listener = act;  }  /**   * Set a name for this plot   * @param plotName the name for the plot   */  public void setName(String plotName) {    m_plotName = plotName;  }  /**   * Returns the name associated with this plot. "" is returned if no   * name is set.   * @return the name of the plot   */  public String getName() {    return m_plotName;  }  /**   * Get the master plot's instances   * @return the master plot's instances   */  public Instances getInstances() {    return m_plot.m_plotInstances;  }  /**   * Sets the Colors in use for a different attrib   * if it is not a nominal attrib and or does not have   * more possible va

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -