List of usage examples for javax.swing DefaultListModel getElementAt
public E getElementAt(int index)
From source file:misc.TextBatchPrintingDemo.java
/** * Print all selected pages in separate threads, one thread per page. */// w w w. j ava 2 s.c o m void printSelectedPages() { DefaultListModel pages = (DefaultListModel) selectedPages.getModel(); int n = pages.getSize(); if (n < 1) { messageArea.setText("No pages selected"); return; } if (printService == null) { messageArea.setText("No print service"); return; } for (int i = 0; i < n; i++) { final PageItem item = (PageItem) pages.getElementAt(i); // This method is called from EDT. Printing is a time-consuming // task, so it should be done outside EDT, in a separate thread. Runnable printTask = new Runnable() { public void run() { try { item.print( // Two "false" args mean "no print dialog" and // "non-interactive" (ie, batch-mode printing). null, null, false, printService, null, false); } catch (PrinterException pe) { JOptionPane.showMessageDialog(null, "Error printing " + item.getPage() + "\n" + pe, "Print Error", JOptionPane.WARNING_MESSAGE); } } }; new Thread(printTask).start(); } pages.removeAllElements(); messageArea.setText(n + (n > 1 ? " pages" : " page") + " printed"); }
From source file:net.sf.xmm.moviemanager.gui.DialogIMDbMultiAdd.java
/** * Gets info.../*from w w w. ja va2 s . com*/ **/ public void executeCommandSelect() { int index = getMoviesList().getSelectedIndex(); /* * When adding the file info the an existing movie, a new ModelMovieInfo object is created. * When done, the old ModelMovieInfo object created in the * MovieManagerCommandAddMultipleMovies object needs not to save the file as a new movie, * therefore setCAncel method with true is called at the end of the if scoop. */ DefaultListModel listModel = (DefaultListModel) getMoviesList().getModel(); if (index == -1 || index > listModel.size()) return; if (addInfoToExistingMovie) { ModelMovie model = ((ModelMovie) listModel.getElementAt(index)); if (model.getKey() == -1) return; if (!model.getHasAdditionalInfoData()) { model.updateAdditionalInfoData(); } ModelMovieInfo modelInfoTmp = new ModelMovieInfo(model, false); /* Need to set the hasReadProperties variable because when normally calling the getfileinfo the first time it replaces the old additional values with the new ones Then the second time it plusses the time and size to match. When multiadding the next file info should be directly added to the old, not replace it */ modelInfoTmp._hasReadProperties = true; try { modelInfoTmp.getFileInfo(new File[] { multiAddFile.getFile() }); } catch (Exception e) { log.error("Error occured while retrieving file info.", e); //$NON-NLS-1$ } try { modelInfoTmp.saveToDatabase(null); } catch (Exception e) { log.error("Saving to database failed.", e); //$NON-NLS-1$ } setCanceled(true); dispose(); } else { ModelIMDbSearchHit model = ((ModelIMDbSearchHit) listModel.getElementAt(index)); if (model.getUrlID() == null) return; if (getUrlKeyOnly) { modelEntry.setUrlKey(model.getUrlID()); dispose(); return; } if (multiAddSelectOption == ImdbImportOption.selectFirst && imdbId != null && !imdbId.equals("")) //$NON-NLS-1$ // Use previously fetched imdb id getIMDbInfo(modelEntry, imdbId); else getIMDbInfo(modelEntry, model.getUrlID()); ModelMovieInfo.executeTitleModification(modelEntry); dispose(); } }
From source file:br.upe.ecomp.dosa.view.wizard.WizardAction.java
private void pickListRemoveAllAction(final JList availableList, final JList selectedList) { final DefaultListModel availableListModel = (DefaultListModel) availableList.getModel(); final DefaultListModel selectedListModel = (DefaultListModel) selectedList.getModel(); int size = selectedList.getModel().getSize(); for (int i = 0; i < size; i++) { availableListModel.addElement(selectedListModel.getElementAt(i)); }/*from w w w . ja v a2 s . com*/ selectedListModel.clear(); }
From source file:br.upe.ecomp.dosa.view.wizard.WizardAction.java
private Algorithm getAlgorithm() { Algorithm algorithm = (Algorithm) algorithmComboBox.getSelectedItem(); algorithm.setProblem((Problem) problemComboBox.getSelectedItem()); List<StopCondition> stopConditionList = new ArrayList<StopCondition>(); DefaultListModel selectedListModel = (DefaultListModel) stopConditionSelectedList.getModel(); int size = stopConditionSelectedList.getModel().getSize(); for (int i = 0; i < size; i++) { stopConditionList.add((StopCondition) selectedListModel.getElementAt(i)); }// www . ja v a2s .co m algorithm.setStopConditions(stopConditionList); List<Measurement> measurementList = new ArrayList<Measurement>(); selectedListModel = (DefaultListModel) measurementSelectedList.getModel(); size = measurementSelectedList.getModel().getSize(); for (int i = 0; i < size; i++) { measurementList.add((Measurement) selectedListModel.getElementAt(i)); } algorithm.setMeasurements(measurementList); return algorithm; }
From source file:gtu._work.ui.JarFinderUI.java
private void initGUI() { try {//w w w . j a v a 2s . co m BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); this.setTitle("Jar finder"); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("src dir", null, jPanel1, null); { openDir = new JButton(); jPanel1.add(openDir, BorderLayout.NORTH); openDir.setText("open dir"); openDir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jButton1ActionPerformed(evt); } }); } { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(406, 255)); { DefaultListModel jList1Model = new DefaultListModel(); try { prop.load(new FileInputStream(CONFIG_FILE)); for (Enumeration<?> enu = prop.keys(); enu.hasMoreElements();) { File val = new File((String) enu.nextElement()); jList1Model.addElement(val); } } catch (Exception ex) { JCommonUtil.handleException("??:" + CONFIG_FILE, ex); } jarFileDirs = new JList(); jScrollPane1.setViewportView(jarFileDirs); jarFileDirs.setModel(jList1Model); jarFileDirs.setPreferredSize(new java.awt.Dimension(406, 221)); jarFileDirs.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (!JListUtil.newInstance(jarFileDirs).isCorrectMouseClick(evt)) { return; } File file = (File) JListUtil.getLeadSelectionObject(jarFileDirs); try { Desktop.getDesktop().open(file); } catch (IOException e) { JCommonUtil.handleException(e); } } }); jarFileDirs.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(jarFileDirs).defaultJListKeyPressed(evt); } }); } } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("result", null, jPanel2, null); { jPanel3 = new JPanel(); BorderLayout jPanel3Layout = new BorderLayout(); jPanel3.setLayout(jPanel3Layout); jPanel2.add(jPanel3, BorderLayout.NORTH); jPanel3.setPreferredSize(new java.awt.Dimension(406, 26)); { searchText = new JTextField(); jPanel3.add(searchText, BorderLayout.WEST); searchText.setPreferredSize(new java.awt.Dimension(326, 26)); } { search = new JButton(); jPanel3.add(search, BorderLayout.CENTER); search.setText("search"); search.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jButton2ActionPerformed(evt); } }); } } { jScrollPane2 = new JScrollPane(); jPanel2.add(jScrollPane2, BorderLayout.CENTER); jScrollPane2.setPreferredSize(new java.awt.Dimension(406, 231)); { ListModel searchResultModel = new DefaultListModel(); searchResult = new JList(); jScrollPane2.setViewportView(searchResult); searchResult.setModel(searchResultModel); searchResult.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { jList1MouseClicked(evt); } }); searchResult.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(searchResult).defaultJListKeyPressed(evt); } }); } } { resetFinder = new JButton(); jPanel2.add(resetFinder, BorderLayout.SOUTH); resetFinder.setText("reset finder"); resetFinder.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jarfinder.clear(); } }); } } { jPanel4 = new JPanel(); BorderLayout jPanel4Layout = new BorderLayout(); jPanel4.setLayout(jPanel4Layout); jTabbedPane1.addTab("copy to", null, jPanel4, null); { copyToBtn = new JButton(); jPanel4.add(copyToBtn, BorderLayout.NORTH); copyToBtn.setText("copy to"); copyToBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog() .getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("copy to dir undefined!", getTitle()); return; } else { copyToFile = file; } } }); } { jScrollPane3 = new JScrollPane(); jPanel4.add(jScrollPane3, BorderLayout.CENTER); { DefaultListModel copyToListModel = new DefaultListModel(); copyToList = new JList(); jScrollPane3.setViewportView(copyToList); copyToList.setModel(copyToListModel); { panel = new JPanel(); jTabbedPane1.addTab("config", null, panel, null); panel.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), }, new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, })); { lblNewLabel = new JLabel("JD Gui"); panel.add(lblNewLabel, "2, 2, right, default"); } { jdGuiText = new JTextField(); JCommonUtil.jTextFieldSetFilePathMouseEvent(jdGuiText, false); panel.add(jdGuiText, "4, 2, fill, default"); jdGuiText.setColumns(10); } { saveConfigBtn = new JButton(""); saveConfigBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { configBean.reflectSetConfig(JarFinderUI.this); configBean.store(); JCommonUtil._jOptionPane_showMessageDialog_info("?!"); } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); panel.add(saveConfigBtn, "2, 24"); } } copyToList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { // copyToFile if (evt.getClickCount() != 2) { return; } if (copyToList.getLeadSelectionIndex() == -1) { return; } if (copyToFile == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("copy to dir undefined!", getTitle()); return; } DefaultListModel model = (DefaultListModel) copyToList.getModel(); Object val = model.getElementAt(copyToList.getLeadSelectionIndex()); StringBuilder sb = new StringBuilder(); sb.append("?\n"); sb.append("file : " + val + "\n"); sb.append("copy to dir : " + copyToFile + "\n"); ComfirmDialogResult result = JOptionPaneUtil.newInstance().confirmButtonYesNo() .showConfirmDialog(sb, getTitle()); File srcFile = new File((String) val); if (!srcFile.exists()) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog(srcFile + " not found!", getTitle()); return; } File copyDestFile = new File(copyToFile, srcFile.getName()); switch (result) { case YES_OK_OPTION: System.out.println("yes.."); try { FileUtil.copyFile(srcFile, copyDestFile); } catch (IOException e) { JCommonUtil.handleException(e.toString(), e); } if (srcFile != null && // copyDestFile != null && // srcFile.length() == copyDestFile.length()) { JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("success!\n" + copyDestFile, getTitle()); } else { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("failed!\n" + copyDestFile, getTitle()); } break; case NO_OPTION: System.out.println("no.."); break; } } }); } } } jTabbedPane1.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { copyToList.setModel(searchResult.getModel()); } }); } this.setSize(562, 407); JCommonUtil.frameCloseDo(this, new WindowAdapter() { public void windowClosing(WindowEvent paramWindowEvent) { if (CONFIG_FILE.exists()) { DefaultListModel model = (DefaultListModel) jarFileDirs.getModel(); for (Enumeration<?> enu = model.elements(); enu.hasMoreElements();) { Object obj = enu.nextElement(); prop.setProperty(((File) obj).getAbsolutePath(), ""); } try { prop.store(new FileOutputStream(CONFIG_FILE), "testtesttesttest"); } catch (Exception e) { JCommonUtil.handleException("", e); } } setVisible(false); dispose(); } }); { configBean.reflectInit(this); } } catch (Exception e) { e.printStackTrace(); } }
From source file:gtu._work.ui.RegexReplacer.java
private void scheduleExecuteActionPerformed(ActionEvent evt) { String replaceText = null;//from w w w. j ava 2s . co 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:net.sf.xmm.moviemanager.gui.DialogIMDB.java
/** * Takes the current selected element, retrieves the IMDb info and disposes. **///from ww w.j av a 2 s. c o m public void executeCommandSelect() { int index = getMoviesList().getSelectedIndex(); DefaultListModel listModel = (DefaultListModel) getMoviesList().getModel(); if (index == -1 || index > listModel.size()) return; ModelIMDbSearchHit model = ((ModelIMDbSearchHit) listModel.getElementAt(index)); if (model.getUrlID() == null) return; getIMDbInfo(modelEntry, model.getUrlID()); ModelMovieInfo.executeTitleModification(modelEntry); dispose(); }
From source file:br.upe.ecomp.dosa.view.wizard.WizardAction.java
private void pickListAddAllAction(final JList sourceList, final JList destinationList) { final DefaultListModel availableListModel = (DefaultListModel) sourceList.getModel(); final DefaultListModel selectedListModel = (DefaultListModel) destinationList.getModel(); int size = sourceList.getModel().getSize(); for (int i = 0; i < size; i++) { selectedListModel.addElement(availableListModel.getElementAt(i)); }//from ww w . j ava 2 s. co m availableListModel.clear(); }
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 {/*ww w .j a va2 s .co m*/ timeSpans.add(span.clone()); } catch (CloneNotSupportedException cnse) { //its the divider } } return timeSpans; }
From source file:de.tor.tribes.ui.algo.AttackTimePanel.java
/** * Get the entire timeframe based on the panel settings * * @return TimeFrame The timeframe//from w ww .ja v a 2s.c o m */ public TimeFrame getTimeFrame() { Date correctedArrive = DateUtils.addDays(maxArriveTimeField.getSelectedDate(), 1); correctedArrive = DateUtils.addSeconds(correctedArrive, -1); maxArriveTimeField.setDate(correctedArrive); TimeFrame frame = new TimeFrame(minSendTimeField.getSelectedDate(), minSendTimeField.getSelectedDate(), correctedArrive, correctedArrive); DefaultListModel model = (DefaultListModel) jTimeFrameList.getModel(); for (int i = 0; i < jTimeFrameList.getModel().getSize(); i++) { TimeSpan s = (TimeSpan) model.getElementAt(i); if (s.getDirection().equals(TimeSpan.DIRECTION.SEND)) { frame.addStartTimeSpan(s); } else if (s.getDirection().equals(TimeSpan.DIRECTION.ARRIVE)) { frame.addArriveTimeSpan(s); } } return frame; }