List of usage examples for javax.swing DefaultListModel getSize
public int getSize()
From source file:gtu._work.ui.RegexReplacer.java
private void scheduleExecuteActionPerformed(ActionEvent evt) { String replaceText = null;// w w w. ja va2 s. c o m Validate.notEmpty((replaceText = replaceArea.getText()), "source can't empty"); DefaultListModel model = (DefaultListModel) templateList.getModel(); for (int ii = 0; ii < model.getSize(); ii++) { PropConfigHandler.Config entry = (PropConfigHandler.Config) model.getElementAt(ii); replaceText = replacer(entry.fromVal, entry.toVal, replaceText); } resultArea.setText(replaceText); }
From source file:io.neocdtv.simpleplayer.ui.PlaylistTransferHandler.java
protected void importString(JComponent c, String str) { JList target = (JList) c; DefaultListModel listModel = (DefaultListModel) target.getModel(); int index = target.getSelectedIndex(); //Prevent the user from dropping data back on itself. //For example, if the user is moving items #4,#5,#6 and #7 and //attempts to insert the items after item #5, this would //be problematic when removing the original items. //So this is not allowed. if (indices != null && index >= indices[0] - 1 && index <= indices[indices.length - 1]) { indices = null;/* w w w. j av a 2 s . c o m*/ return; } int max = listModel.getSize(); if (index < 0) { index = max; } else { index++; if (index > max) { index = max; } } addIndex = index; String[] values = str.split("\n"); addCount = values.length; for (String value : values) { listModel.add(index++, value); } }
From source file:gtu._work.ui.ObnfInsertCreaterUI.java
private void dbFieldListMousePreformd(MouseEvent evt) { if (JMouseEventUtil.buttonLeftClick(1, evt)) { KeyValue kv = (KeyValue) dbFieldList.getSelectedValue(); if (kv != null) { dbFieldText.setText(kv.key); dbValue.setText(kv.value);// w ww . ja va2s. c om pkCheckBox.setSelected(kv.pk); } } if (JMouseEventUtil.buttonRightClick(1, evt)) { JPopupMenuUtil.newInstance(dbFieldList).addJMenuItem("/?", new ActionListener() { public void actionPerformed(ActionEvent e) { List<KeyValue> list = new ArrayList<KeyValue>(); DefaultListModel model = (DefaultListModel) dbFieldList.getModel(); for (int ii = 0; ii < model.getSize(); ii++) { KeyValue kv = (KeyValue) model.get(ii); list.add(kv); } Collections.sort(list, new Comparator<KeyValue>() { @Override public int compare(KeyValue o1, KeyValue o2) { return o1.key.compareTo(o2.key); } }); DefaultListModel model1 = new DefaultListModel(); for (KeyValue kv : list) { model1.addElement(kv); } dbFieldList.setModel(model1); } }).addJMenuItem("/?PK", new ActionListener() { public void actionPerformed(ActionEvent e) { Object[] values = dbFieldList.getSelectedValues(); if (values != null) { for (Object v : values) { KeyValue kv = (KeyValue) v; kv.pk = !kv.pk; } } } }).applyEvent(evt).show(); } }
From source file:com.neurotec.samples.panels.EnrollFromScanner.java
public void updateScannerList() { DefaultListModel model = (DefaultListModel) scannerList.getModel(); model.clear();// w ww .ja v a 2 s .c o m for (NDevice device : deviceManager.getDevices()) { model.addElement(device); } NFingerScanner scanner = (NFingerScanner) FingersTools.getInstance().getClient().getFingerScanner(); if ((scanner == null) && (model.getSize() > 0)) { scannerList.setSelectedIndex(0); } else if (scanner != null) { scannerList.setSelectedValue(scanner, true); } }
From source file:DropDemo.java
protected void importString(JComponent c, String str) { JList target = (JList) c; DefaultListModel listModel = (DefaultListModel) target.getModel(); int index = target.getSelectedIndex(); // Prevent the user from dropping data back on itself. // For example, if the user is moving items #4,#5,#6 and #7 and // attempts to insert the items after item #5, this would // be problematic when removing the original items. // So this is not allowed. if (indices != null && index >= indices[0] - 1 && index <= indices[indices.length - 1]) { indices = null;/* w w w .j a va 2 s. co m*/ return; } int max = listModel.getSize(); if (index < 0) { index = max; } else { index++; if (index > max) { index = max; } } addIndex = index; String[] values = str.split("\n"); addCount = values.length; for (int i = 0; i < values.length; i++) { listModel.add(index++, values[i]); } }
From source file:imageuploader.ImgWindow.java
private void jB_uploadMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jB_uploadMouseClicked try {//from w w w .jav a2 s. c o m // TODO add your handling code here: DefaultListModel mod = (DefaultListModel) jL_Info.getModel(); if (jTF_StyleCode.getText().length() <= 0 || jCB_Colors.getModel().getSize() <= 1 || mod.getSize() <= 0) { JOptionPane.showMessageDialog(rootPane, "Please insert the Stle Code and select the color"); } else if (jCHB_CA.isSelected() || jCHBox_MY.isSelected()) { if (FtpCredentials.getInstancia().getUser() == null) { JOptionPane.showMessageDialog(rootPane, "Please add the FTP Credentials"); } else { showDialog(0); File[] files = jFC_Images.getSelectedFiles(); if (files.length == 0) { JOptionPane.showMessageDialog(rootPane, "Please select one image"); } else { generatedImages(jTF_StyleCode.getText(), files); } } } else { showDialog(0); File[] files = jFC_Images.getSelectedFiles(); if (files.length == 0) { JOptionPane.showMessageDialog(rootPane, "Please select one image"); } else { generatedImages(jTF_StyleCode.getText(), files); } } } catch (IOException ex) { Logger.getLogger(ImgWindow.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalStateException ex) { Logger.getLogger(ImgWindow.class.getName()).log(Level.SEVERE, null, ex); } catch (FTPIllegalReplyException ex) { Logger.getLogger(ImgWindow.class.getName()).log(Level.SEVERE, null, ex); } catch (FTPException ex) { Logger.getLogger(ImgWindow.class.getName()).log(Level.SEVERE, null, ex); } catch (FtpException ex) { Logger.getLogger(ImgWindow.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ExtendedDnDDemo.java
protected void importString(JComponent c, String str) { JList target = (JList) c; DefaultListModel listModel = (DefaultListModel) target.getModel(); int index = target.getSelectedIndex(); //Prevent the user from dropping data back on itself. //For example, if the user is moving items #4,#5,#6 and #7 and //attempts to insert the items after item #5, this would //be problematic when removing the original items. //So this is not allowed. if (indices != null && index >= indices[0] - 1 && index <= indices[indices.length - 1]) { indices = null;//from w ww . j a va 2s . c om return; } int max = listModel.getSize(); if (index < 0) { index = max; } else { index++; if (index > max) { index = max; } } addIndex = index; String[] values = str.split("\n"); addCount = values.length; for (int i = 0; i < values.length; i++) { listModel.add(index++, values[i]); } }
From source file:de.tor.tribes.ui.algo.AttackTimePanel.java
public List<TimeSpan> getTimeSpans() { List<TimeSpan> timeSpans = new LinkedList<>(); //add time frames DefaultListModel model = (DefaultListModel) jTimeFrameList.getModel(); for (int i = 0; i < model.getSize(); i++) { TimeSpan span = (TimeSpan) model.getElementAt(i); try {// w ww . j a v a2 s. c om timeSpans.add(span.clone()); } catch (CloneNotSupportedException cnse) { //its the divider } } return timeSpans; }
From source file:edu.ku.brc.specify.tasks.subpane.VisualQueryPanel.java
/** * @return the RecordSet of chosen items. *///from www . j a v a 2 s . c o m private RecordSetIFace createRecordSet() { RecordSetIFace rs = null; DefaultListModel model = (DefaultListModel) recSetList.getModel(); if (model.getSize() > 0) { rs = RecordSetFactory.getInstance().createRecordSet(); rs.setDbTableId(TABLE_IDS[typeCBX.getSelectedIndex()]); for (int i = 0; i < model.getSize(); i++) { LatLonPoint llp = (LatLonPoint) model.get(i); rs.addItem(llp.getLocId()); } } return rs; }
From source file:de.tor.tribes.ui.algo.AttackTimePanel.java
/** * Try to add a new timespan. Before it is checked for intersection * * @param s The new timespan/*from w w w . j a v a 2 s .co m*/ */ protected void addTimeSpan(TimeSpan s) { if (s == null) { JOptionPaneHelper.showWarningBox(this, "Der angegebene Zeitrahmen ist ungltig", "Warnung"); return; } //check if timeframe exists or intersects with other existing frame int intersection = -1; DefaultListModel model = (DefaultListModel) jTimeFrameList.getModel(); int entryId = 0; for (int i = 0; i < model.getSize(); i++) { TimeSpan existingSpan = (TimeSpan) model.getElementAt(i); if (!existingSpan.getDirection().equals(TimeSpan.DIRECTION.NONE)) { //not for divider! if (s.intersects(existingSpan)) { intersection = entryId + 1; break; } entryId++; } } if (intersection == -1) { //add span if (s.getDirection().equals(TimeSpan.DIRECTION.SEND)) { ((DefaultListModel) jTimeFrameList.getModel()).add(0, s); } else { ((DefaultListModel) jTimeFrameList.getModel()).add(jTimeFrameList.getModel().getSize(), s); } List<TimeSpan> spans = new LinkedList<>(); for (int i = 0; i < model.getSize(); i++) { spans.add((TimeSpan) model.getElementAt(i)); } Collections.sort(spans); model = new DefaultListModel(); for (TimeSpan span : spans) { model.addElement(span); } jTimeFrameList.setModel(model); } else { JOptionPaneHelper.showWarningBox(this, "Das gewhlte Zeitfenster berschneidet sich mit dem " + intersection + ". Eintrag.\n" + "Bitte whle die Zeitfenster so, dass es zu keinen berschneidungen kommt.", "Warnung"); return; } fireTimeFrameChangedEvent(); }