List of usage examples for javax.swing DefaultListModel addElement
public void addElement(E element)
From source file:de.tor.tribes.ui.views.DSWorkbenchStatsFrame.java
@Override public void resetView() { Ally[] allies = StatManager.getSingleton().getMonitoredAllies(); Arrays.sort(allies);/* www . j a va 2s. c o m*/ DefaultListModel model = new DefaultListModel(); for (Ally a : allies) { model.addElement(a); } jAllyList.setModel(model); jTribeList.setModel(new DefaultListModel()); }
From source file:de.pavloff.spark4knime.jsnippet.ui.JarListPanel.java
private void onJarFileAdd() { DefaultListModel<String> model = (DefaultListModel<String>) m_addJarList.getModel(); Set<String> hash = new HashSet<>(Collections.list(model.elements())); StringHistory history = StringHistory.getInstance("java_snippet_jar_dirs"); if (m_jarFileChooser == null) { File dir = null;/* w w w . ja va2 s . c o m*/ for (String h : history.getHistory()) { File temp = new File(h); if (temp.isDirectory()) { dir = temp; break; } } m_jarFileChooser = new JFileChooser(dir); m_jarFileChooser.setFileFilter(new SimpleFileFilter(".zip", ".jar")); m_jarFileChooser.setMultiSelectionEnabled(true); } int result = m_jarFileChooser.showDialog(m_addJarList, "Select"); if (result == JFileChooser.APPROVE_OPTION) { for (File f : m_jarFileChooser.getSelectedFiles()) { String s = f.getAbsolutePath(); if (hash.add(s)) { model.addElement(s); } } history.add(m_jarFileChooser.getCurrentDirectory().getAbsolutePath()); } }
From source file:edu.ku.brc.specify.tasks.subpane.VisualQueryPanel.java
/** * Moves selected items from one list to the other. * @param srcList//from w ww .j av a 2 s . co m * @param srcHash * @param dstList * @param dstHash */ private void moveItems(final JList srcList, final HashSet<Integer> srcHash, final JList dstList, final HashSet<Integer> dstHash) { int inx = srcList.getSelectedIndex(); if (inx > -1) { DefaultListModel srcModel = (DefaultListModel) srcList.getModel(); DefaultListModel dstModel = (DefaultListModel) dstList.getModel(); int[] indexes = srcList.getSelectedIndices(); ArrayList<LatLonPoint> llpList = new ArrayList<LatLonPoint>(indexes.length); for (int selInx : indexes) { LatLonPoint llp = (LatLonPoint) srcModel.get(selInx); llpList.add(llp); if (!dstHash.contains(llp.getLocId())) { dstModel.addElement(llp); dstHash.add(llp.getLocId()); } } for (LatLonPoint llp : llpList) { srcModel.removeElement(llp); srcHash.remove(llp.getLocId()); } } }
From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowserAdvancedFilter.java
private void shiftValues(JList source, JList destination) { Object[] values = source.getSelectedValues(); DefaultListModel sourceModel = (DefaultListModel) source.getModel(); DefaultListModel destinationModel = (DefaultListModel) destination.getModel(); for (Object value : values) { sourceModel.removeElement(value); destinationModel.addElement(value); }/*w w w .j a v a 2s .co m*/ }
From source file:gtu._work.mvn.MavenRepositoryUI.java
void resetUIStatus() { {/*from w w w.ja va 2 s .com*/ DefaultListModel model = new DefaultListModel(); for (PomFile pom : pomFileList) { model.addElement(pom); } scanList.setModel(model); } { DefaultListModel model = new DefaultListModel(); for (PomFile pom : pomFileJarList) { model.addElement(pom); } scanList2.setModel(model); } { Object[] header = new Object[] { "pom", "lastModified", "jar", "parent", "modelVersion", " groupId", " artifactId", " packaging", " name", " version", " url", " description" }; DefaultTableModel model = new DefaultTableModel(new Object[][] {}, header) { private static final long serialVersionUID = 1L; public boolean isCellEditable(int row, int column) { return false; } }; for (PomFile pom : pomFileList) { model.addRow(new Object[] { // pom, // DateFormatUtils.format(pom.xmlFile.lastModified(), "yyyy/MM/dd HH:mm:ss"), // (pom.jarFile == null ? "" : DateFormatUtils.format(pom.jarFile.lastModified(), "yyyy/MM/dd HH:mm:ss") + "(" + (pom.jarFile.length() / 1024) + ")"), // (pom.pom.parent == null ? "" : "Y"), // pom.pom.modelVersion, // pom.pom.groupId, // pom.pom.artifactId, // pom.pom.packaging, // pom.pom.name, // pom.pom.version, // pom.pom.url, // pom.pom.description // }); } scanTable.setModel(model); } scanText.getDocument().addDocumentListener(getDocumentListener(scanList, pomFileList)); scanText2.getDocument().addDocumentListener(getDocumentListener(scanList2, pomFileJarList)); }
From source file:ca.sqlpower.swingui.enterprise.client.ServerProjectsManagerPanel.java
protected void refreshInfoList() { DefaultListModel model = (DefaultListModel) projects.getModel(); model.removeAllElements();/*from ww w.j av a 2 s . c o m*/ SPServerInfo serviceInfo = getSelectedServerInfo(); if (serviceInfo != null) { try { List<ProjectLocation> projectLocations = getProjectLocations(); // Sorts the project locations alphabetically Collections.sort(projectLocations, new Comparator<ProjectLocation>() { public int compare(ProjectLocation proj1, ProjectLocation proj2) { return proj1.getName().compareToIgnoreCase(proj2.getName()); } }); model.clear(); for (ProjectLocation pl : projectLocations) { model.addElement(pl); } connected = true; } catch (Exception ex) { model.removeAllElements(); model.addElement("Unable to get projects from server"); connected = false; upf.createUserPrompter("Server Unavailable", UserPromptType.MESSAGE, UserPromptOptions.OK, UserPromptResponse.OK, "OK", "OK").promptUser(""); } refreshPanel(); } else { model.addElement("No Server Selected"); connected = false; refreshPanel(); } }
From source file:gtu._work.ui.ObnfInsertCreaterUI.java
private void addFieldBtnAction() { String dbField = dbFieldText.getText(); String dbvalue = StringUtils.defaultString(dbValue.getText()); if (StringUtils.isBlank(dbField)) { JCommonUtil._jOptionPane_showMessageDialog_error("dbField"); return;//w w w. j av a2 s. c o m } DefaultListModel dbFieldListModel = (DefaultListModel) dbFieldList.getModel(); boolean doUpdate = false; for (Enumeration<?> enu = dbFieldListModel.elements(); enu.hasMoreElements();) { KeyValue kv = (KeyValue) enu.nextElement(); if (kv.getKey().equalsIgnoreCase(dbField) && kv.pk == pkCheckBox.isSelected()) { kv.value = dbvalue; doUpdate = true; JCommonUtil._jOptionPane_showMessageDialog_info(":" + kv); break; } } if (!doUpdate) { KeyValue kv = new KeyValue(); kv.key = dbField; kv.value = dbvalue; kv.pk = pkCheckBox.isSelected(); dbFieldListModel.addElement(kv); JCommonUtil._jOptionPane_showMessageDialog_info(":" + kv); } }
From source file:net.rptools.maptool.client.ui.AddResourceDialog.java
private void downloadLibraryList() { if (downloadLibraryListInitiated) { return;// w ww . ja va 2 s. com } // This pattern is safe because it is only called on the EDT downloadLibraryListInitiated = true; new SwingWorker<Object, Object>() { ListModel model; @Override protected Object doInBackground() throws Exception { String result = null; try { WebDownloader downloader = new WebDownloader(new URL(LIBRARY_LIST_URL)); result = downloader.read(); } finally { if (result == null) { model = new MessageListModel(I18N.getText("dialog.addresource.errorDownloading")); return null; } } DefaultListModel listModel = new DefaultListModel(); // Create a list to compare against for dups List<String> libraryNameList = new ArrayList<String>(); for (File file : AppPreferences.getAssetRoots()) { libraryNameList.add(file.getName()); } // Generate the list try { BufferedReader reader = new BufferedReader( new InputStreamReader(new ByteArrayInputStream(result.getBytes()))); String line = null; while ((line = reader.readLine()) != null) { LibraryRow row = new LibraryRow(line); // Don't include if we've already got it if (libraryNameList.contains(row.name)) { continue; } listModel.addElement(row); } model = listModel; } catch (Throwable t) { log.error("unable to parse library list", t); model = new MessageListModel(I18N.getText("dialog.addresource.errorDownloading")); } return null; } @Override protected void done() { getLibraryList().setModel(model); } }.execute(); }
From source file:gtu._work.ui.RegexDirReplacer.java
private void initGUI() { try {/*ww w. ja va 2s .c om*/ { } BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("source", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); { ListModel srcListModel = new DefaultListModel(); srcList = new JList(); jScrollPane1.setViewportView(srcList); srcList.setModel(srcListModel); { panel = new JPanel(); jScrollPane1.setRowHeaderView(panel); panel.setLayout(new FormLayout( new ColumnSpec[] { ColumnSpec.decode("default:grow"), }, new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, })); { childrenDirChkbox = new JCheckBox("??"); childrenDirChkbox.setSelected(true); panel.add(childrenDirChkbox, "1, 1"); } { subFileNameText = new JTextField(); panel.add(subFileNameText, "1, 2, fill, default"); subFileNameText.setColumns(10); subFileNameText.setText("(txt|java)"); } { replaceOldFileChkbox = new JCheckBox(""); replaceOldFileChkbox.setSelected(true); panel.add(replaceOldFileChkbox, "1, 3"); } { charsetText = new JTextField(); panel.add(charsetText, "1, 5, fill, default"); charsetText.setColumns(10); charsetText.setText("UTF8"); } } srcList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { JListUtil.newInstance(srcList).defaultMouseClickOpenFile(evt); JPopupMenuUtil.newInstance(srcList).applyEvent(evt)// .addJMenuItem("load files from clipboard", new ActionListener() { public void actionPerformed(ActionEvent arg0) { String content = ClipboardUtil.getInstance().getContents(); DefaultListModel model = (DefaultListModel) srcList.getModel(); StringTokenizer tok = new StringTokenizer(content, "\t\n\r\f", false); for (; tok.hasMoreElements();) { String val = ((String) tok.nextElement()).trim(); model.addElement(new File(val)); } } }).show(); } }); srcList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(srcList).defaultJListKeyPressed(evt); } }); } } { addDirFiles = new JButton(); jPanel1.add(addDirFiles, BorderLayout.NORTH); addDirFiles.setText("add dir files"); addDirFiles.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog() .getApproveSelectedFile(); if (file == null || !file.isDirectory()) { return; } List<File> fileLst = new ArrayList<File>(); String subName = StringUtils.trimToEmpty(subFileNameText.getText()); if (StringUtils.isBlank(subName)) { subName = ".*"; } String patternStr = ".*\\." + subName; if (childrenDirChkbox.isSelected()) { FileUtil.searchFileMatchs(file, patternStr, fileLst); } else { for (File f : file.listFiles()) { if (f.isFile() && f.getName().matches(patternStr)) { fileLst.add(f); } } } DefaultListModel model = new DefaultListModel(); for (File f : fileLst) { model.addElement(f); } srcList.setModel(model); } }); } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("param", null, jPanel2, null); { exeucte = new JButton(); jPanel2.add(exeucte, BorderLayout.SOUTH); exeucte.setText("exeucte"); exeucte.setPreferredSize(new java.awt.Dimension(491, 125)); exeucte.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { exeucteActionPerformed(evt); } }); } { jPanel3 = new JPanel(); GroupLayout jPanel3Layout = new GroupLayout((JComponent) jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel2.add(jPanel3, BorderLayout.CENTER); { repFromText = new JTextField(); } { repToText = new JTextField(); } jPanel3Layout.setHorizontalGroup(jPanel3Layout.createSequentialGroup() .addContainerGap(25, 25) .addGroup(jPanel3Layout.createParallelGroup() .addGroup(jPanel3Layout.createSequentialGroup().addComponent(repFromText, GroupLayout.PREFERRED_SIZE, 446, GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(repToText, GroupLayout.PREFERRED_SIZE, 446, GroupLayout.PREFERRED_SIZE))) .addContainerGap(20, Short.MAX_VALUE)); jPanel3Layout.setVerticalGroup(jPanel3Layout.createSequentialGroup().addContainerGap() .addComponent(repFromText, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(repToText, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE) .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); } { addToTemplate = new JButton(); jPanel2.add(addToTemplate, BorderLayout.NORTH); addToTemplate.setText("add to template"); addToTemplate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { prop.put(repFromText.getText(), repToText.getText()); reloadTemplateList(); } }); } } { jPanel4 = new JPanel(); BorderLayout jPanel4Layout = new BorderLayout(); jPanel4.setLayout(jPanel4Layout); jTabbedPane1.addTab("result", null, jPanel4, null); { jScrollPane2 = new JScrollPane(); jPanel4.add(jScrollPane2, BorderLayout.CENTER); { ListModel newRepListModel = new DefaultListModel(); newRepList = new JList(); jScrollPane2.setViewportView(newRepList); newRepList.setModel(newRepListModel); newRepList.addMouseListener(new MouseAdapter() { static final String tortoiseMergeExe = "TortoiseMerge.exe"; static final String commandFormat = "cmd /c call \"%s\" /base:\"%s\" /theirs:\"%s\""; public void mouseClicked(MouseEvent evt) { if (!JListUtil.newInstance(newRepList).isCorrectMouseClick(evt)) { return; } OldNewFile oldNewFile = (OldNewFile) JListUtil .getLeadSelectionObject(newRepList); String base = oldNewFile.newFile.getAbsolutePath(); String theirs = oldNewFile.oldFile.getAbsolutePath(); String command = String.format(commandFormat, tortoiseMergeExe, base, theirs); System.out.println(command); try { Runtime.getRuntime().exec(command); } catch (IOException e) { JCommonUtil.handleException(e); } } }); newRepList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { Object[] objects = (Object[]) newRepList.getSelectedValues(); if (objects == null || objects.length == 0) { return; } DefaultListModel model = (DefaultListModel) newRepList.getModel(); int lastIndex = model.getSize() - 1; Object swap = null; StringBuilder dsb = new StringBuilder(); for (Object current : objects) { int index = model.indexOf(current); switch (evt.getKeyCode()) { case 38:// up if (index != 0) { swap = model.getElementAt(index - 1); model.setElementAt(swap, index); model.setElementAt(current, index - 1); } break; case 40:// down if (index != lastIndex) { swap = model.getElementAt(index + 1); model.setElementAt(swap, index); model.setElementAt(current, index + 1); } break; case 127:// del OldNewFile current_ = (OldNewFile) current; dsb.append(current_.newFile.getName() + "\t" + (current_.newFile.delete() ? "T" : "F") + "\n"); current_.newFile.delete(); model.removeElement(current); } } if (dsb.length() > 0) { JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("del result!\n" + dsb, "DELETE"); } } }); } } { replaceOrignFile = new JButton(); jPanel4.add(replaceOrignFile, BorderLayout.SOUTH); replaceOrignFile.setText("replace orign file"); replaceOrignFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { DefaultListModel model = (DefaultListModel) newRepList.getModel(); StringBuilder sb = new StringBuilder(); for (int ii = 0; ii < model.size(); ii++) { OldNewFile file = (OldNewFile) model.getElementAt(ii); boolean delSuccess = false; boolean renameSuccess = false; if (delSuccess = file.oldFile.delete()) { renameSuccess = file.newFile.renameTo(file.oldFile); } sb.append(file.oldFile.getName() + " del:" + (delSuccess ? "T" : "F") + " rename:" + (renameSuccess ? "T" : "F") + "\n"); } JOptionPaneUtil.newInstance().iconInformationMessage().showMessageDialog(sb, getTitle()); } }); } } { jPanel5 = new JPanel(); BorderLayout jPanel5Layout = new BorderLayout(); jPanel5.setLayout(jPanel5Layout); jTabbedPane1.addTab("template", null, jPanel5, null); { jScrollPane3 = new JScrollPane(); jPanel5.add(jScrollPane3, BorderLayout.CENTER); { templateList = new JList(); reloadTemplateList(); jScrollPane3.setViewportView(templateList); templateList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (templateList.getLeadSelectionIndex() == -1) { return; } Entry<Object, Object> entry = (Entry<Object, Object>) JListUtil .getLeadSelectionObject(templateList); repFromText.setText((String) entry.getKey()); repToText.setText((String) entry.getValue()); } }); templateList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(templateList).defaultJListKeyPressed(evt); } }); } } { scheduleExecute = new JButton(); jPanel5.add(scheduleExecute, BorderLayout.SOUTH); scheduleExecute.setText("schedule execute"); scheduleExecute.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { scheduleExecuteActionPerformed(evt); } }); } } } this.setSize(512, 350); JCommonUtil.setFontAll(this.getRootPane()); JCommonUtil.frameCloseDo(this, new WindowAdapter() { public void windowClosing(WindowEvent paramWindowEvent) { if (StringUtils.isNotBlank(repFromText.getText())) { prop.put(repFromText.getText(), repToText.getText()); } try { prop.store(new FileOutputStream(propFile), "regexText"); } catch (Exception e) { JCommonUtil.handleException("properties store error!", e); } setVisible(false); dispose(); } }); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.t3.client.ui.AddResourceDialog.java
private void downloadLibraryList() { if (downloadLibraryListInitiated) { return;/*from w w w . j av a2 s . c o m*/ } // This pattern is safe because it is only called on the EDT downloadLibraryListInitiated = true; new SwingWorker<Object, Object>() { ListModel model; @Override protected Object doInBackground() throws Exception { String result = null; try { WebDownloader downloader = new WebDownloader(new URL(LIBRARY_LIST_URL)); result = downloader.read(); } finally { if (result == null) { model = new MessageListModel(I18N.getText("dialog.addresource.errorDownloading")); return null; } } DefaultListModel<LibraryRow> listModel = new DefaultListModel<LibraryRow>(); // Create a list to compare against for dups List<String> libraryNameList = new ArrayList<String>(); for (File file : AppPreferences.getAssetRoots()) { libraryNameList.add(file.getName()); } // Generate the list try { BufferedReader reader = new BufferedReader( new InputStreamReader(new ByteArrayInputStream(result.getBytes()))); String line = null; while ((line = reader.readLine()) != null) { LibraryRow row = new LibraryRow(line); // Don't include if we've already got it if (libraryNameList.contains(row.name)) { continue; } listModel.addElement(row); } model = listModel; } catch (Throwable t) { log.error("unable to parse library list", t); model = new MessageListModel(I18N.getText("dialog.addresource.errorDownloading")); } return null; } @Override protected void done() { getLibraryList().setModel(model); } }.execute(); }