public void actionPerformed(ActionEvent e) { // obtain a HardcopyWriter to do this Roster r = Roster.instance(); String title = "DecoderPro Roster"; String rosterGroup = r.getDefaultRosterGroup(); // rosterGroup may legitimately be null // but getProperty returns null if the property cannot be found, so // we test that the property exists before attempting to get its value if (Beans.hasProperty(wi, RosterGroupSelector.SELECTED_ROSTER_GROUP)) { rosterGroup = (String) Beans.getProperty(wi, RosterGroupSelector.SELECTED_ROSTER_GROUP); } if (rosterGroup == null) { title = title + " All Entries"; } else { title = title + " Group " + rosterGroup + " Entires"; } HardcopyWriter writer = null; try { writer = new HardcopyWriter(mFrame, title, 10, .5, .5, .5, .5, isPreview); } catch (HardcopyWriter.PrintCanceledException ex) { log.debug("Print cancelled"); return; } // add the image ImageIcon icon = new ImageIcon(FileUtil.findURL("resources/decoderpro.gif", FileUtil.Location.INSTALLED)); // we use an ImageIcon because it's guaranteed to have been loaded when ctor is complete writer.write(icon.getImage(), new JLabel(icon)); // Add a number of blank lines, so that the roster entry starts below the decoderpro logo int height = icon.getImage().getHeight(null); int blanks = (height - writer.getLineAscent()) / writer.getLineHeight(); try { for (int i = 0; i < blanks; i++) { String s = "\n"; writer.write(s, 0, s.length()); } } catch (IOException ex) { log.warn("error during printing: " + ex); } // Loop through the Roster, printing as needed List<RosterEntry> l = r.matchingList(null, null, null, null, null, null, null); // take all log.debug("Roster list size: " + l.size()); for (RosterEntry re : l) { if (rosterGroup != null) { if (re.getAttribute(Roster.getRosterGroupProperty(rosterGroup)) != null && re.getAttribute(Roster.getRosterGroupProperty(rosterGroup)).equals("yes")) { re.printEntry(writer); } } else { re.printEntry(writer); } } // and force completion of the printing writer.close(); }
public int getGroupIndex(String group, RosterEntry re) { List<RosterEntry> l = matchingList(null, null, null, null, null, null, null); int num = 0; for (RosterEntry r : l) { if (group != null) { if ((r.getAttribute(getRosterGroupProperty(group)) != null) && r.getAttribute(getRosterGroupProperty(group)).equals("yes")) { // NOI18N if (r == re) { return num; } num++; } } else { if (re == r) { return num; } num++; } } return -1; }
public List<RosterEntry> getEntriesWithAttributeKey(String key) { // slow but effective algorithm ArrayList<RosterEntry> result = new ArrayList<>(); java.util.Iterator<RosterEntry> i = _list.iterator(); while (i.hasNext()) { RosterEntry r = i.next(); if (r.getAttribute(key) != null) { result.add(r); } } return result; }
/** * Get the Nth RosterEntry in the group * * @param group The group being queried. * @param i The index within the group of the requested entry. * @return The specified entry in the group or null if i is larger than the group, or the group * does not exist. */ public RosterEntry getGroupEntry(String group, int i) { List<RosterEntry> l = matchingList(null, null, null, null, null, null, null); int num = 0; for (RosterEntry r : l) { if (group != null) { if ((r.getAttribute(getRosterGroupProperty(group)) != null) && r.getAttribute(getRosterGroupProperty(group)).equals("yes")) { // NOI18N if (num == i) { return r; } num++; } } else { if (num == i) { return r; } num++; } } return null; }
/** * Check if an entry is consistent with specific properties. * * <p>A null String argument always matches. Strings are used for convenience in GUI building. * * @param r the roster entry being checked * @param roadName road name of entry or null for any road name * @param roadNumber road number of entry of null for any number * @param dccAddress address of entry or null for any address * @param mfg manufacturer of entry or null for any manufacturer * @param decoderModel decoder model of entry or null for any model * @param decoderFamily decoder family of entry or null for any family * @param id id of entry or null for any id * @param group group entry is member of or null for any group * @return True if the entry matches */ public boolean checkEntry( RosterEntry r, String roadName, String roadNumber, String dccAddress, String mfg, String decoderModel, String decoderFamily, String id, String group) { if (id != null && !id.equals(r.getId())) { return false; } if (roadName != null && !roadName.equals(r.getRoadName())) { return false; } if (roadNumber != null && !roadNumber.equals(r.getRoadNumber())) { return false; } if (dccAddress != null && !dccAddress.equals(r.getDccAddress())) { return false; } if (mfg != null && !mfg.equals(r.getMfg())) { return false; } if (decoderModel != null && !decoderModel.equals(r.getDecoderModel())) { return false; } if (decoderFamily != null && !decoderFamily.equals(r.getDecoderFamily())) { return false; } if (group != null && !Roster.ALLENTRIES.equals(group) && (r.getAttribute(Roster.getRosterGroupProperty(group)) == null || !r.getAttribute(Roster.getRosterGroupProperty(group)).equals("yes"))) { // NOI18N return false; } return true; }