List of usage examples for javax.swing DefaultListModel DefaultListModel
DefaultListModel
From source file:com.openbravo.pos.sales.JRetailPanelTakeAway.java
public void populateTaxList() throws BasicException { try {/* ww w . j ava 2 s . co m*/ System.out.println("populating tax list"); taxeslogic.calculateTakeAwayTaxes(m_oTicket); } catch (TaxesException ex) { logger.info("exception in populateTaxList " + ex.getMessage()); Logger.getLogger(JRetailPanelTakeAway.class.getName()).log(Level.SEVERE, null, ex); } taxModel = new DefaultListModel(); m_jTaxList.setModel(taxModel); empty = BorderFactory.createEmptyBorder(); m_jTaxList.setBorder(empty); //added newly to calcuate taxes based on erp tax category by Shilpa consolidateTaxes(m_oTicket); int i = 0; for (Map.Entry<String, NameTaxMapInfo> entry : m_oTicket.getNametaxMap().entrySet()) { String taxName = entry.getValue().getName(); String taxValue = String.format("%.2f", entry.getValue().getTaxValue()); String taxEntry = "<html>" + "<style type=\\\"text/css\\\">" + "body { margin: 0px auto; }\\n" + "td { " + "padding: 0px;" + "margin: 0px;" + "}" + "</style>" + "<body>" + " <table style=\"width:150px\">" + " <tr bgcolor=grey>" + " <td width=\"120px\" align=\"left\">" + taxName + "</td>" + " <td width=\"30px\" align=\"right\">" + taxValue + "</td>" + " </tr> " + " </table>" + "<body>" + "</html>"; taxModel.add(i, taxEntry); i = i + 1; } // for (int i = 0; i < m_oTicket.getTaxes().size(); i++) { // System.out.println("getPercentage " + m_oTicket.getTaxes().get(i).getRetailTax()); // //Name of the tax // String taxName =m_oTicket.getTaxes().get(i).getTaxInfo().getName(); // //decimal value of tax with two significant digits // String taxValue = String.format("%.2f",m_oTicket.getTaxes().get(i).getRetailTax()); // //String variable holding HTML code to render two strings, in a table row within two columns. // String taxEntry = "<html>"+ // "<style type=\\\"text/css\\\">"+ // "body { margin: 0px auto; }\\n"+ // "td { "+ // "padding: 0px;"+ // "margin: 0px;"+ // "}"+ // "</style>"+ // "<body>"+ // " <table style=\"width:150px\">"+ // " <tr bgcolor=grey>"+ // " <td width=\"120px\" align=\"left\">"+taxName+"</td>"+ // " <td width=\"30px\" align=\"right\">"+taxValue+"</td>"+ // " </tr> "+ // " </table>"+ // "<body>"+ // "</html>"; // // taxModel.add(i, taxEntry); // } }
From source file:com.peterbochs.PeterBochsDebugger.java
private void updateStack() { try {//from w w w . ja v a 2s . co m jStatusLabel.setText("Updating stack"); // commandReceiver.setCommandNoOfLine(512); commandReceiver.clearBuffer(); commandReceiver.shouldShow = false; sendCommand("print-stack 40"); String result = commandReceiver.getCommandResultUntilHaveLines(40); String[] lines = result.split("\n"); registerPanel.jStackList.removeAll(); jStatusProgressBar.setMaximum(lines.length - 1); DefaultListModel model = new DefaultListModel(); for (int y = 1; y < lines.length; y++) { try { jStatusProgressBar.setValue(y); String[] b = lines[y].split("[\\[\\]]"); model.addElement(b[1]); jStatusLabel.setText("Updating stack " + y + "/" + (lines.length - 1)); } catch (Exception ex2) { } } registerPanel.jStackList.setModel(model); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java
/** Builds the parameter list on the gui from the <code>parameters</code> list. */ private void createDefaultParameterList(final List<ParameterInfo> parameters) { final DefaultListModel model = new DefaultListModel(); for (final ParameterInfo parameterInfo : parameters) model.addElement(new AvailableParameter(parameterInfo, currentModelHandler.getModelClass())); parameterList.setModel(model);//w w w . j a v a 2 s . c o m }
From source file:de.main.sessioncreator.DesktopApplication1View.java
public void getAreasBacgroundW(File f) { fileHelper.getAreas(f);//from w w w. jav a2 s . co m Iterator<Map.Entry<String, List>> it = fileHelper.areaMap.entrySet().iterator(); while (it.hasNext()) { DefaultListModel dlm = new DefaultListModel(); JList list = new JList(dlm); list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); JScrollPane scrollPane = new JScrollPane(list); scrollPane.getViewport().setView(list); Map.Entry en = it.next(); wizardtabpAreas.addTab(en.getKey().toString().substring(3), scrollPane); for (Object o : fileHelper.areaMap.get(en.getKey().toString())) { dlm.addElement(o); } MouseListener mouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent mouseEvent) { JList tabList = (JList) mouseEvent.getSource(); if (mouseEvent.getClickCount() == 2) { int index = tabList.locationToIndex(mouseEvent.getPoint()); if (index >= 0) { Object o = tabList.getModel().getElementAt(index); wizardtaChoosenAreas.append(o.toString() + "\n"); } } } }; list.addMouseListener(mouseListener); ListSelectionListener listListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { JList list = (JList) e.getSource(); if (e.getValueIsAdjusting() == false) { if (list.getSelectedIndex() == -1) { //No selection, disable add button. wizardbtnAddAreas.setEnabled(false); } else { //Selection, enable the add button. wizardbtnAddAreas.setEnabled(true); } } } }; list.addListSelectionListener(listListener); } }
From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java
private void fireTargetAllyFilterChangedEvent(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_fireTargetAllyFilterChangedEvent Ally[] allies = AllyUtils.getAlliesByFilter(jTargetAllyFilter.getText(), Ally.CASE_INSENSITIVE_ORDER); DefaultListModel targetAllyModel = new DefaultListModel(); for (Ally a : allies) { targetAllyModel.addElement(a);/*from ww w. j a va 2 s.c o m*/ } jTargetAllyList.setModel(targetAllyModel); }
From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java
/** * @param parentList/*from www . j a v a2 s.c om*/ */ protected void fillNextList(final JList parentList) { if (processingLists) { return; } processingLists = true; final int curInx = listBoxList.indexOf(parentList); if (curInx > -1) { int startSize = listBoxPanel.getComponentCount(); for (int i = curInx + 1; i < listBoxList.size(); i++) { listBoxPanel.remove(spList.get(i)); } int removed = startSize - listBoxPanel.getComponentCount(); for (int i = 0; i < removed; i++) { tableTreeList.remove(tableTreeList.size() - 1); } } else { listBoxPanel.removeAll(); tableTreeList.clear(); } QryListRendererIFace item = (QryListRendererIFace) parentList.getSelectedValue(); if (item instanceof ExpandableQRI) { JList newList; DefaultListModel model; JScrollPane sp; if (curInx == listBoxList.size() - 1) { newList = new JList(model = new DefaultListModel()); newList.addMouseListener(new MouseAdapter() { /* (non-Javadoc) * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) */ @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { if (currentInx != -1) { JList list = (JList) e.getSource(); QryListRendererIFace qriFace = (QryListRendererIFace) list.getSelectedValue(); if (BaseQRI.class.isAssignableFrom(qriFace.getClass())) { BaseQRI qri = (BaseQRI) qriFace; if (qri.isInUse()) { //remove the field for (QueryFieldPanel qfp : QueryBldrPane.this.queryFieldItems) { FieldQRI fqri = qfp.getFieldQRI(); if (fqri == qri || (fqri instanceof RelQRI && fqri.getTable() == qri)) { boolean clearIt = qfp.getSchemaItem() != null; QueryBldrPane.this.removeQueryFieldItem(qfp); if (clearIt) { qfp.setField(null, null); } break; } } } else { // add the field try { FieldQRI fieldQRI = buildFieldQRI(qri); if (fieldQRI == null) { throw new Exception("null FieldQRI"); } SpQueryField qf = new SpQueryField(); qf.initialize(); qf.setFieldName(fieldQRI.getFieldName()); qf.setStringId(fieldQRI.getStringId()); query.addReference(qf, "fields"); if (!isExportMapping) { addQueryFieldItem(fieldQRI, qf, false); } else { addNewMapping(fieldQRI, qf, null, false); } } catch (Exception ex) { log.error(ex); UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance() .capture(QueryBldrPane.class, ex); return; } } } } } } }); newList.setCellRenderer(qryRenderer); listBoxList.add(newList); sp = new JScrollPane(newList, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); JLabel colHeader = UIHelper.createLabel(item.getTitle()); colHeader.setHorizontalAlignment(SwingConstants.CENTER); colHeader.setBackground(listBoxPanel.getBackground()); colHeader.setOpaque(true); sp.setColumnHeaderView(colHeader); spList.add(sp); newList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { fillNextList(listBoxList.get(curInx + 1)); } } }); } else { newList = listBoxList.get(curInx + 1); model = (DefaultListModel) newList.getModel(); sp = spList.get(curInx + 1); JLabel colHeaderLbl = (JLabel) sp.getColumnHeader().getComponent(0); if (item instanceof TableQRI) { colHeaderLbl.setText(((TableQRI) item).getTitle()); } else { colHeaderLbl.setText(getResourceString("QueryBldrPane.QueryFields")); } } createNewList((TableQRI) item, model); listBoxPanel.remove(addBtn); listBoxPanel.add(sp); tableTreeList.add(((ExpandableQRI) item).getTableTree()); listBoxPanel.add(addBtn); currentInx = -1; } else { listBoxPanel.add(addBtn); } SwingUtilities.invokeLater(new Runnable() { public void run() { updateAddBtnState(); // Is all this really necessary listBoxPanel.validate(); listBoxPanel.repaint(); scrollPane.validate(); scrollPane.invalidate(); scrollPane.doLayout(); scrollPane.repaint(); validate(); invalidate(); doLayout(); repaint(); UIRegistry.forceTopFrameRepaint(); } }); processingLists = false; currentInx = curInx; }
From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java
/** * Filter source lists by selected groups *//*from w w w .ja va 2s . c om*/ private void fireFilterSourceVillagesByGroupEvent() { List<Village> villageList = getGroupFilteredSourceVillages(); String[] continents = VillageUtils.getContinents(villageList.toArray(new Village[villageList.size()])); DefaultListModel contModel = new DefaultListModel(); for (String cont : continents) { contModel.addElement(cont); } //set continents list -> village list updates automatically via continent list listener jSourceContinentList.setModel(contModel); if (continents.length > 0) { jSourceContinentList.getSelectionModel().setSelectionInterval(0, continents.length - 1); } }
From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java
/** * Filter target lists by selected allies */// w w w. j a v a 2 s . c om private void fireFilterTargetByAllyEvent() { Ally a = (Ally) jTargetAllyList.getSelectedValue(); Tribe[] tribes = AllyUtils.getTribes(a, Tribe.CASE_INSENSITIVE_ORDER); DefaultListModel model = new DefaultListModel(); for (Tribe t : tribes) { model.addElement(t); } jTargetTribeList.setModel(model); jTargetTribeList.setSelectedIndex(0); }
From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java
/** * Filter target lists by selected tribes *//* ww w . ja v a2 s . c o m*/ private void fireFilterTargetByTribeEvent() { Tribe t = (Tribe) jTargetTribeList.getSelectedValue(); String[] continents = VillageUtils.getContinents(t); DefaultListModel contModel = new DefaultListModel(); for (String cont : continents) { contModel.addElement(cont); } jTargetContinentList.setModel(contModel); if (continents.length > 0) { jTargetContinentList.getSelectionModel().setSelectionInterval(0, continents.length - 1); } }
From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java
/** * Filter source list by selected continents *///from w w w.ja va2s .c o m private void fireFilterSourceContinentEvent() { Object[] conts = jSourceContinentList.getSelectedValues(); //build list of allowed continents List<Integer> allowedContinents = new LinkedList<Integer>(); for (Object cont : conts) { int contId = Integer.parseInt(((String) cont).replaceAll("K", "")); allowedContinents.add(contId); } List<Village> villageList = getGroupFilteredSourceVillages(); Village[] filtered = VillageUtils.getVillagesByContinent( villageList.toArray(new Village[villageList.size()]), allowedContinents.toArray(new Integer[allowedContinents.size()]), Village.CASE_INSENSITIVE_ORDER); DefaultListModel villageModel = new DefaultListModel(); for (Village v : filtered) { villageModel.addElement(v); } jSourceVillageList.setModel(villageModel); }