Java Code Examples for javax.swing.DefaultListModel#getElementAt()

The following examples show how to use javax.swing.DefaultListModel#getElementAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodeCompletionPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void updateExcluder(JList list) {
    DefaultListModel model = (DefaultListModel) list.getModel();
    StringBuilder builder = new StringBuilder();
    for (int i = 0 ; i < model.size() ; i++) {
        String entry = (String) model.getElementAt(i);
        if (builder.length() > 0) {
            builder.append(","); //NOI18N
        }
        builder.append(entry);
    }
    String pref;
    if (list == javaCompletionExcludeJlist)
        pref = JAVA_COMPLETION_BLACKLIST;
    else if (list == javaCompletionIncludeJlist)
        pref = JAVA_COMPLETION_WHITELIST;
    else
        throw new RuntimeException(list.getName());

    preferences.put(pref, builder.toString());
}
 
Example 2
Source File: ListSelectionPanel.java    From nextreports-designer with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void sort(DefaultListModel model) {
	// we need a List for sorting
	int size = model.getSize();
	ArrayList list = new ArrayList();
	for (int x = 0; x < size; ++x) {
		Object o = model.get(x);
		list.add(o);
	}

	if (comp != null) {
	   Collections.sort(list, comp);
	} else {
	   Collections.sort(list);
	}
	// update the model with a sorted List
	for (int x = 0; x < size; ++x) {
		Object obj = list.get(x);			
		if ((model.getElementAt(x) != null) && !model.getElementAt(x).equals(obj)) {
			model.set(x, obj);
		}
	}
}
 
Example 3
Source File: CheckListBox.java    From nextreports-designer with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public List getSelectedObjects(boolean onlyEnabled) {
    DefaultListModel model = (DefaultListModel) this.getModel();
    List selectedObjects = new ArrayList();
    for (int i = 0; i < model.size(); i++) {
        CheckListItem item = (CheckListItem) model.getElementAt(i);
        if (item.isSelected()) {
            if (!onlyEnabled) {
                selectedObjects.add(item.getObject());
            } else if (item.isEnabled()) {
                selectedObjects.add(item.getObject());
            }
        }
    }

    return selectedObjects;
}
 
Example 4
Source File: StringSetPropertyEditorPanel.java    From openAGV with Apache License 2.0 6 votes vote down vote up
/**
 * Bewegt den aktuellen Eintrag nach unten.
 *
 * @param evt das auslösende Ereignis
 */
private void moveDownButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveDownButtonActionPerformed
  int index = itemsList.getSelectedIndex();

  if (index == -1) {
    return;
  }

  DefaultListModel<String> model = (DefaultListModel<String>) itemsList.getModel();

  if (index == model.size() - 1) {
    return;
  }

  String value = model.getElementAt(index);
  model.removeElementAt(index);
  model.insertElementAt(value, index + 1);
  itemsList.setSelectedIndex(index + 1);
}
 
Example 5
Source File: ClassPathUiSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static void edit(DefaultListModel listModel, int[] selectedIndices, AntProjectHelper helper) {
    ClassPathSupport.Item item = (ClassPathSupport.Item) listModel.getElementAt(selectedIndices[0]);
    if (item.getType() == ClassPathSupport.Item.TYPE_JAR) {
        EditJarSupport.Item eji = new EditJarSupport.Item();
        eji.setJarFile(item.getVariableBasedProperty() != null ? item.getVariableBasedProperty() : item.getFilePath());
        eji.setSourceFile(item.getSourceFilePath());
        eji.setJavadocFile(item.getJavadocFilePath());
        eji = EditJarSupport.showEditDialog(helper, eji);
        if (eji != null) {
            item.setJavadocFilePath(eji.getJavadocFile());
            item.setSourceFilePath(eji.getSourceFile());
        }
    }
    if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) {
        if (item.getLibrary() != null) {
            LibrariesCustomizer.showSingleLibraryCustomizer(item.getLibrary());
        }
    }
}
 
Example 6
Source File: FrmAppsManager.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void checkBoxList_PluginMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_checkBoxList_PluginMouseClicked
    // TODO add your handling code here:
    DefaultListModel listModel = (DefaultListModel) this.checkBoxList_Plugin.getModel();
    int idx = this.checkBoxList_Plugin.getSelectedIndex();
    CheckBoxListEntry item = (CheckBoxListEntry) listModel.getElementAt(idx);
    Application plugin = (Application) item.getValue();
    if (item.isSelected()) {
        parent.loadApplication(plugin);
        parent.validate();
    } else {
        parent.unloadApplication(plugin);
        parent.validate();
    }

    String detailStr = "Name: " + plugin.getName()
            + System.getProperty("line.separator") + "Author: " + plugin.getAuthor()
            + System.getProperty("line.separator") + "Version: " + plugin.getVersion()
            + System.getProperty("line.separator") + "Description: " + plugin.getDescription()
            + System.getProperty("line.separator") + "Jar Path: " + plugin.getJarPath()
            + System.getProperty("line.separator") + "Class Name: " + plugin.getClassName();
    this.jTextArea_PluginDetails.setText(detailStr);
}
 
Example 7
Source File: FrmPluginManager.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void checkBoxList_PluginMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_checkBoxList_PluginMouseClicked
    // TODO add your handling code here:
    DefaultListModel listModel = (DefaultListModel) this.checkBoxList_Plugin.getModel();
    int idx = this.checkBoxList_Plugin.getSelectedIndex();
    CheckBoxListEntry item = (CheckBoxListEntry) listModel.getElementAt(idx);
    Plugin plugin = (Plugin) item.getValue();
    if (item.isSelected()) {
        if (!plugin.isLoad()) {
            _parent.loadPlugin(plugin);
            _parent.validate();
        }
    } else {
        if (plugin.isLoad()) {
            _parent.unloadPlugin(plugin);
            _parent.validate();
        }
    }

    String detailStr = "Name: " + plugin.getName()
            + System.getProperty("line.separator") + "Author: " + plugin.getAuthor()
            + System.getProperty("line.separator") + "Version: " + plugin.getVersion()
            + System.getProperty("line.separator") + "Description: " + plugin.getDescription()
            + System.getProperty("line.separator") + "Jar Path: " + plugin.getJarPath()
            + System.getProperty("line.separator") + "Class Name: " + plugin.getClassName();
    this.jTextArea_PluginDetails.setText(detailStr);
}
 
Example 8
Source File: FrmLayerProperty.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void checkBoxList_FieldsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_checkBoxList_FieldsMouseClicked
    // TODO add your handling code here:
    DefaultListModel listModel = (DefaultListModel) this.checkBoxList_Fields.getModel();
    int idx = this.checkBoxList_Fields.getSelectedIndex();
    CheckBoxListEntry item = (CheckBoxListEntry) listModel.getElementAt(idx);
    String selFieldStr = item.getValue().toString();
    if (item.isSelected()) {
        PolygonBreak aPB = new PolygonBreak();
        aPB.setCaption(selFieldStr);
        aPB.setTag(selFieldStr);
        aPB.setColor(LegendManage.createRandomColors(1)[0]);
        legendView_Chart.getLegendScheme().getLegendBreaks().add(aPB);
    } else {
        for (int i = 0; i < legendView_Chart.getLegendScheme().getBreakNum(); i++) {
            if (legendView_Chart.getLegendScheme().getLegendBreaks().get(i).getTag().equals(selFieldStr)) {
                legendView_Chart.getLegendScheme().getLegendBreaks().remove(i);
                break;
            }
        }
    }
    this.legendView_Chart.repaint();
}
 
Example 9
Source File: StringSetPropertyEditorPanel.java    From openAGV with Apache License 2.0 6 votes vote down vote up
private void moveUpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveUpButtonActionPerformed
  int index = itemsList.getSelectedIndex();

  if (index == -1) {
    return;
  }

  if (index == 0) {
    return;
  }

  DefaultListModel<String> model = (DefaultListModel<String>) itemsList.getModel();
  String value = model.getElementAt(index);
  model.removeElementAt(index);
  model.insertElementAt(value, index - 1);
  itemsList.setSelectedIndex(index - 1);
}
 
Example 10
Source File: CategoryPanelFormatters.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void copyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_copyButtonActionPerformed
        int index = formattersList.getSelectedIndex();
        if (index < 0) return ;
        DefaultListModel model = (DefaultListModel) formattersList.getModel();
        VariablesFormatter f = (VariablesFormatter) model.getElementAt(index);
        VariablesFormatter f2 = f.clone();

        Set<String> formatterNames = getFormatterNames();
        String name = f2.getName();
        while (formatterNames.contains(name)) {
            boolean isCopied = name.contains(COPY1) && name.endsWith(COPY2);
            int nc = 0;
            if (isCopied) {
                int i1 = name.lastIndexOf(COPY1) + COPY1.length();
                int i2 = name.length() - COPY2.length();
                if (i1 == i2) {
                   nc = 1;
                } else {
                    String ncs = name.substring(i1, i2);
                    try {
                        nc = Integer.parseInt(ncs);
                    } catch (NumberFormatException nfex) {
                        isCopied = false;
                    }
                }
            }
            if (isCopied) {
                nc++;
                name = name.substring(0, name.lastIndexOf(COPY1)) + COPY1 + nc + COPY2;
            } else {
                name = name + COPY1 + COPY2;
            }
        }
        f2.setName(name);
        ((DefaultListModel) formattersList.getModel()).insertElementAt(f2, index);
        formattersList.setSelectedValue(f2, true);
        
}
 
Example 11
Source File: CodeCompletionPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void javaCompletionExcluderEditButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_javaCompletionExcluderEditButtonActionPerformed
    JList list = getSelectedExcluderList();
    int index = list.getSelectedIndex();
    if (index == -1)
    return;
    DefaultListModel model = (DefaultListModel) list.getModel();
    javaExcluderEditing = (String) model.getElementAt(index);
    openExcluderEditor();
}
 
Example 12
Source File: CheckListBox.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
public void setEnabledAll(boolean b) {
    DefaultListModel model = (DefaultListModel) this.getModel();
    int size = model.size();
    for (int i = 0; i < size; i++) {
        CheckListItem item = (CheckListItem) model.getElementAt(i);
        item.setEnabled(b);
    }
    repaint();
}
 
Example 13
Source File: CheckListBox.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
public void setSelected(boolean b) {
    DefaultListModel model = (DefaultListModel) this.getModel();
    int size = model.size();
    for (int i = 0; i < size; i++) {
        CheckListItem item = (CheckListItem) model.getElementAt(i);
        item.setSelected(b);
    }
    repaint();
}
 
Example 14
Source File: Browser.java    From joshua with Apache License 2.0 5 votes vote down vote up
private static void search(int fromIndex) {
  final String query = searchBox.getText();
  DefaultListModel oneBestListModel = (DefaultListModel) oneBestList.getModel();
  for (int i = fromIndex; i < oneBestListModel.getSize(); i++) {
    String reference = (String) oneBestListModel.getElementAt(i);
    if (reference.contains(query)) {
      // found the query
      oneBestList.setSelectedIndex(i);
      oneBestList.ensureIndexIsVisible(i);
      searchBox.setBackground(Color.white);
      return;
    }
  }
  searchBox.setBackground(Color.red);
}
 
Example 15
Source File: CheckListBox.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
public void setSelected(String label, boolean b) {
    DefaultListModel model = (DefaultListModel) this.getModel();
    for (int i = 0; i < model.size(); i++) {
        CheckListItem item = (CheckListItem) (model.getElementAt(i));
        if (item.getText().equals(label)) {
            setSelected(i, b);
            return;
        }
    }
}
 
Example 16
Source File: CategoryPanelFormatters.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed
    int index = formattersList.getSelectedIndex();
    if (index < 0) return ;
    DefaultListModel model = (DefaultListModel) formattersList.getModel();
    VariablesFormatter f = (VariablesFormatter) model.getElementAt(index);

    VariableFormatterEditPanel fPanel = new VariableFormatterEditPanel();
    fPanel.load(f);

    Set<String> formatterNames = getFormatterNames();
    formatterNames.remove(f.getName());
    fPanel.setFormatterNames(formatterNames);

    DialogDescriptor formatterEditDescriptor = new DialogDescriptor(
            fPanel,
            NbBundle.getMessage(CategoryPanelFormatters.class, "TTL_EditFormatter"),
            true,
            NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.OK_OPTION,
            null);
    NotificationLineSupport notificationSupport = formatterEditDescriptor.createNotificationLineSupport();
    fPanel.setValidityObjects(formatterEditDescriptor, notificationSupport, true);
    //formatterEditDescriptor.setValid(false);
    Dialog dlg = DialogDisplayer.getDefault().createDialog(formatterEditDescriptor);
    Properties p = Properties.getDefault().getProperties("debugger.options.JPDA"); // NOI18N
    int w = p.getInt("VariableFormatters_AddEdit_WIDTH", -1);                      // NOI18N
    int h = p.getInt("VariableFormatters_AddEdit_HEIGHT", -1);                     // NOI18N
    if (w > 0 && h > 0) {
        dlg.setSize(new Dimension(w, h));
    }
    dlg.setVisible(true);
    Dimension dim = dlg.getSize();
    p.setInt("VariableFormatters_AddEdit_WIDTH", dim.width);                       // NOI18N
    p.setInt("VariableFormatters_AddEdit_HEIGHT", dim.height);                     // NOI18N
    if (NotifyDescriptor.OK_OPTION.equals(formatterEditDescriptor.getValue())) {
        fPanel.store(f);
        checkBoxComponents.put(f, new JCheckBox(f.getName(), f.isEnabled()));
        ((DefaultListModel) formattersList.getModel()).setElementAt(f, index);
        //formattersList.repaint();
        formattersList.setSelectedValue(f, true);
        loadSelectedFormatter(f);
    }
}
 
Example 17
Source File: CheckListBox.java    From nextreports-designer with Apache License 2.0 4 votes vote down vote up
public boolean isEnabled(int index) {
    DefaultListModel model = (DefaultListModel) this.getModel();
    CheckListItem item = (CheckListItem) model.getElementAt(index);
    return item.isEnabled();
}
 
Example 18
Source File: CheckListBox.java    From nextreports-designer with Apache License 2.0 4 votes vote down vote up
public void setSelected(int index, boolean b) {
    DefaultListModel model = (DefaultListModel) this.getModel();
    CheckListItem item = (CheckListItem) (model.getElementAt(index));
    item.setSelected(b);
    repaint();
}
 
Example 19
Source File: ColumnsListBox.java    From nextreports-designer with Apache License 2.0 4 votes vote down vote up
public Column getColumn(int index) {
    DefaultListModel model = (DefaultListModel) this.getModel();
    CheckListItem item = (CheckListItem) (model.getElementAt(index));
    return (Column) item.getObject();
}
 
Example 20
Source File: CheckListBox.java    From nextreports-designer with Apache License 2.0 4 votes vote down vote up
public void setObject(Object object, int index) {
    DefaultListModel model = (DefaultListModel) this.getModel();
    CheckListItem item = (CheckListItem) model.getElementAt(index);
    item.setObject(object);
}