List of usage examples for javax.swing DefaultListModel addElement
public void addElement(E element)
From source file:gtu._work.ui.RegexDirReplacer.java
private void exeucteActionPerformed(ActionEvent evt) { try {/*w w w .j a v a 2 s. com*/ String fromPattern = null; String toFormat = repToText.getText(); Validate.notEmpty((fromPattern = repFromText.getText()), "replace regex can't empty"); DefaultListModel model = (DefaultListModel) srcList.getModel(); DefaultListModel rmodel = new DefaultListModel(); errMsg = new StringBuilder(); successMsg = new StringBuilder(); String replaceText = null; String bakupReplaceText = null; File newFile = null; File oldFile = null; OldNewFile oldNewFile = null; for (int ii = 0; ii < model.getSize(); ii++) { oldFile = (File) model.getElementAt(ii); replaceText = FileUtil.loadFromFile(oldFile, getCharset()); bakupReplaceText = replaceText.toString(); replaceText = replacer(fromPattern, toFormat, replaceText, oldFile); if (!bakupReplaceText.equals(replaceText)) { if (replaceOldFileChkbox.isSelected()) { oldFile.renameTo(new File(oldFile.getParentFile(), oldFile.getName() + ".bak")); } newFile = oldFile; FileUtil.saveToFile(newFile, replaceText, getCharset()); successMsg.append(newFile.getName() + "\n"); oldNewFile = new OldNewFile(); oldNewFile.oldFile = oldFile; oldNewFile.newFile = newFile; rmodel.addElement(oldNewFile); successMsg.append(oldFile.getName() + "\n"); } } newRepList.setModel(rmodel); JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog(String.format(MESSAGE, successMsg, errMsg), getTitle()); } catch (Exception ex) { JCommonUtil.handleException(ex); } }
From source file:gtu._work.ui.ExecuteOpener.java
void reloadExecListProperties(Properties prop) throws FileNotFoundException, IOException { DefaultListModel execListModel = new DefaultListModel(); List<String> keys = ListUtil.getList(prop.keySet(), String.class); Collections.sort(keys);//from w w w. j a v a 2s . c o m for (Object obj : keys) { execListModel.addElement((String) obj); } execList.setModel(execListModel); }
From source file:forms.frDados.java
/** * L todos os usurios cadastrados no banco e * coloca no listbox de usurios./* w w w . j ava 2 s.c o m*/ */ private void carregarListaUsers() { try { ArrayList<String> users = ControleAcesso.getUsers(); DefaultListModel dfm = new DefaultListModel(); for (String user : users) dfm.addElement(user); lstUsers.setModel(dfm); } catch (Exception erro) { Util.ExibirMensagem(Util.EnumTipoMensagem.Erro, erro.getMessage()); } }
From source file:de.tor.tribes.ui.views.DSWorkbenchReTimerFrame.java
private void fireComandDataChangedEvent(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_fireComandDataChangedEvent parsedAttack = new Attack(); List<Village> villages = PluginManager.getSingleton().executeVillageParser(jCommandArea.getText()); if (villages == null || villages.isEmpty() || villages.size() < 2) { parsedAttack = null;/* w w w . j a va2 s . c o m*/ } else { Village source = villages.get(0); Village target = villages.get(1); if (jCommandArea.getText() .indexOf(PluginManager.getSingleton().getVariableValue("sos.arrive.time")) > -1) { //change village order for SOS requests source = villages.get(1); target = villages.get(0); } parsedAttack.setSource(source); parsedAttack.setTarget(target); Date arriveDate = null; try { String text = jCommandArea.getText(); String arrive = null; String arriveLine = null; if (text.indexOf(PluginManager.getSingleton().getVariableValue("attack.arrive.time")) > -1) { String searchString = PluginManager.getSingleton().getVariableValue("attack.arrive.time"); arriveLine = text.substring( text.indexOf(PluginManager.getSingleton().getVariableValue("attack.arrive.time")) + searchString.length()); } else { String searchString = PluginManager.getSingleton().getVariableValue("sos.arrive.time"); arriveLine = text.substring( text.indexOf(PluginManager.getSingleton().getVariableValue("sos.arrive.time")) + searchString.length()); } StringTokenizer tokenizer = new StringTokenizer(arriveLine, "\n"); String date = tokenizer.nextToken(); arrive = date.trim();//arriveLine.trim();//date.trim() + " " + time.trim(); SimpleDateFormat f = null; if (!ServerSettings.getSingleton().isMillisArrival()) { f = new SimpleDateFormat(PluginManager.getSingleton().getVariableValue("sos.date.format")); } else { f = new SimpleDateFormat(PluginManager.getSingleton().getVariableValue("sos.date.format.ms")); } arriveDate = f.parse(arrive); parsedAttack.setArriveTime(arriveDate); if (arriveDate == null) { throw new Exception("Invalid arrive"); } } catch (Exception ignored) { parsedAttack = null; } //calc possible units double dist = DSCalculator.calculateDistance(source, target); String[] units = new String[] { "axe", "sword", "spy", "light", "heavy", "ram", "knight", "snob" }; DefaultListModel model = new DefaultListModel(); for (String unit : units) { UnitHolder unitHolder = DataHolder.getSingleton().getUnitByPlainName(unit); if (unit != null) { long dur = (long) Math.floor(dist * unitHolder.getSpeed() * 60000.0); if (arriveDate.getTime() - dur <= System.currentTimeMillis()) { model.addElement(unitHolder); } } } if (model.isEmpty()) { //no element parsedAttack = null; } jPossibleUnits.setModel(model); UnitHolder ram = DataHolder.getSingleton().getUnitByPlainName("ram"); UnitHolder axe = DataHolder.getSingleton().getUnitByPlainName("axe"); UnitHolder spy = DataHolder.getSingleton().getUnitByPlainName("spy"); if (model.contains(ram)) { jPossibleUnits.setSelectedValue(ram, true); } else if (model.contains(axe)) { jPossibleUnits.setSelectedValue(axe, true); } else { jPossibleUnits.setSelectedValue(spy, true); } } updateAttackBBView(); }
From source file:edu.ku.brc.specify.tools.StrLocalizerApp.java
/** * @param newSrc/* ww w. j a v a 2 s . co m*/ */ protected void newSrcFile(final StrLocaleFile newSrc) { termList.clearSelection(); newTermList.clearSelection(); srcFile = newSrc; // re-create and reload the dest file to clear unsaved changes and/or states int destInx = getLocaleFileInxBySrcPath(destFiles, srcFile.getPath()); StrLocaleFile oldDest = destFiles.get(destInx); destFile = new StrLocaleFile(oldDest.getPath(), oldDest.getSrcPath(), true); destFiles.set(destInx, destFile); newKeyList.clear(); mergeToSrc(srcFile, destFile); ItemModel termsModel = new ItemModel(srcFile); termList.setModel(termsModel); DefaultListModel itemModel = new DefaultListModel(); itemModel.clear(); for (String str : newKeyList) { itemModel.addElement(str); } newTermList.setModel(itemModel); rsController.setLength(srcFile.getNumberOfKeys()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { fileLbl.setText(destFile.getPath()); } }); searchable = new LocalizerSearchHelper(baseDir, "props-index"); searchable.indexProps(srcFile.getItems()); }
From source file:stockit.Manager.java
private void searchTraderBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchTraderBtnActionPerformed // TODO add your handling code here: if (listOfTraders.isSelectionEmpty()) { JOptionPane.showMessageDialog(getContentPane(), "Please Select a Trader", "Error", JOptionPane.ERROR_MESSAGE); } else {/* w w w .java 2 s. c o m*/ String selectedTrader = listOfTraders.getSelectedValue(); System.out.println(selectedTrader); try { DefaultListModel demoList = new DefaultListModel(); DBConnection dbcon = new DBConnection(); dbcon.establishConnection(); Statement stmt = dbcon.con.createStatement(); ResultSet rs = stmt.executeQuery("SELECT C.Name" + " FROM client as C, trader as t, trader_account as tc, account as a" + " WHERE C.Client_SSN = a.Client_SSN AND " + " tc.Trader_SSN = t.Trader_SSN " + " AND a.Trader_SSN = t.Trader_SSN " + " AND tc.username = \"" + selectedTrader + "\""); while (rs.next()) { demoList.addElement(rs.getString("Name")); } dbcon.con.close(); listOfClients = new JList(demoList); jScrollPane5.setViewportView(listOfClients); } catch (Exception ex) { Logger.getLogger(clientLogin.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:gtu._work.ui.ExecuteOpener.java
void reloadCurrentDirPropertiesList() { DefaultListModel model = new DefaultListModel(); for (File file : jarPositionDir.listFiles(new FileFilter() { public boolean accept(File paramFile) { if (paramFile.getName().toLowerCase().endsWith(".properties")) { return true; }//from ww w .j a v a 2 s . co m return false; } })) { model.addElement(file); } propertiesList.setModel(model); }
From source file:gtu._work.ui.RegexDirReplacer.java
private void scheduleExecuteActionPerformed(ActionEvent evt) { try {/* w w w . ja va 2 s . c o m*/ DefaultListModel model = (DefaultListModel) srcList.getModel(); DefaultListModel rmodel = new DefaultListModel(); DefaultListModel pmodel = (DefaultListModel) templateList.getModel(); errMsg = new StringBuilder(); successMsg = new StringBuilder(); String replaceText = null; String bakupReplaceText = null; File newFile = null; File oldFile = null; OldNewFile oldNewFile = null; for (int ii = 0; ii < model.getSize(); ii++) { oldFile = (File) model.getElementAt(ii); replaceText = FileUtil.loadFromFile(oldFile, getCharset()); bakupReplaceText = replaceText.toString(); for (int jj = 0; jj < pmodel.getSize(); jj++) { Entry<Object, Object> entry = (Entry<Object, Object>) pmodel.getElementAt(jj); replaceText = replacer((String) entry.getKey(), (String) entry.getValue(), replaceText, oldFile); } if (!bakupReplaceText.equals(replaceText)) { newFile = new File(oldFile.getParent(), oldFile.getName() + ".replace"); FileUtil.saveToFile(newFile, replaceText, getCharset()); successMsg.append(newFile.getName() + "\n"); oldNewFile = new OldNewFile(); oldNewFile.oldFile = oldFile; oldNewFile.newFile = newFile; rmodel.addElement(oldNewFile); } } newRepList.setModel(rmodel); JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog(String.format(MESSAGE, successMsg, errMsg), getTitle()); } catch (Exception ex) { JCommonUtil.handleException(ex); } }
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//w ww .ja v a2 s . com */ 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(); }
From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java
/** * /* ww w .j a v a 2 s. co m*/ */ protected void viewSelected() { selectedView = null; selectedViewDef = null; selectedAltView = null; viewDefsList.clearSelection(); DefaultListModel model = (DefaultListModel) altViewsList.getModel(); model.clear(); ((DefaultTreeModel) tree.getModel()).setRoot(null); if (viewsList.getSelectedIndex() > -1) { if (selectedViewSet != null) { String viewName = (String) viewsList.getSelectedValue(); if (viewName != null) { selectedView = selectedViewSet.getViews().get(viewName); for (AltViewIFace altView : selectedView.getAltViews()) { model.addElement(altView.getName()); } } altViewControlPanel.getAddBtn().setEnabled(true); viewControlPanel.getDelBtn().setEnabled(true); } } else { altViewControlPanel.getAddBtn().setEnabled(false); viewControlPanel.getDelBtn().setEnabled(false); } }