/** * Set the bean to be edited * * @param object an <code>Object</code> value */ public void setObject(Object object) { if (m_classValuePicker != (ClassValuePicker) object) { // remove ourselves as a listener from the old ClassvaluePicker (if necessary) /* if (m_classValuePicker != null) { m_classValuePicker.removeDataFormatListener(this); } */ m_classValuePicker = (ClassValuePicker) object; // add ourselves as a data format listener // m_classValuePicker.addDataFormatListener(this); if (m_classValuePicker.getConnectedFormat() != null) { setUpValueSelection(m_classValuePicker.getConnectedFormat()); } m_backup = m_classValuePicker.getClassValue(); } }
private void setupTextBoxSelection() { m_textBoxEntryMode = true; JPanel holderPanel = new JPanel(); holderPanel.setLayout(new BorderLayout()); holderPanel.setBorder(BorderFactory.createTitledBorder("Specify class label")); JLabel label = new JLabel("Class label ", SwingConstants.RIGHT); holderPanel.add(label, BorderLayout.WEST); m_valueTextBox = new JTextField(15); m_valueTextBox.setToolTipText( "Class label. /first, /last and /<num> " + "can be used to specify the first, last or specific index " + "of the label to use respectively."); holderPanel.add(m_valueTextBox, BorderLayout.CENTER); JPanel holder2 = new JPanel(); holder2.setLayout(new BorderLayout()); holder2.add(holderPanel, BorderLayout.NORTH); add(holder2, BorderLayout.CENTER); String existingClassVal = m_classValuePicker.getClassValue(); if (existingClassVal != null) { m_valueTextBox.setText(existingClassVal); } }
private void setUpValueSelection(Instances format) { if (format.classIndex() < 0 || format.classAttribute().isNumeric()) { // cant do anything in this case m_messageLabel.setText( (format.classIndex() < 0) ? "EROR: no class attribute set" : "ERROR: class is numeric"); return; } if (m_displayValNames == false) { remove(m_messageLabel); } m_textBoxEntryMode = false; if (format.classAttribute().numValues() == 0) { // loader may not be able to give us the set of legal // values for a nominal attribute until it has read // the data (e.g. database loader or csv loader). // In this case we'll use a text box and the user // can enter the class value. setupTextBoxSelection(); validate(); repaint(); return; } String existingClassVal = m_classValuePicker.getClassValue(); if (existingClassVal == null) { existingClassVal = ""; } int classValIndex = format.classAttribute().indexOfValue(existingClassVal); // do we have a special (last, first or number) if (existingClassVal.startsWith("/")) { existingClassVal = existingClassVal.substring(1); if (existingClassVal.equalsIgnoreCase("first")) { classValIndex = 0; } else if (existingClassVal.equalsIgnoreCase("last")) { classValIndex = format.classAttribute().numValues() - 1; } else { // try and parse as a number classValIndex = Integer.parseInt(existingClassVal); classValIndex--; } } if (classValIndex < 0) { classValIndex = 0; } String[] attribValNames = new String[format.classAttribute().numValues()]; for (int i = 0; i < attribValNames.length; i++) { attribValNames[i] = format.classAttribute().value(i); } m_ClassValueCombo.setModel(new DefaultComboBoxModel(attribValNames)); if (attribValNames.length > 0) { // if (existingClassVal < attribValNames.length) { m_ClassValueCombo.setSelectedIndex(classValIndex); // } } if (m_displayValNames == false) { add(m_holderP, BorderLayout.CENTER); m_displayValNames = true; } validate(); repaint(); }