/** * This function is used to re-run the analyser, and re-create the rows corresponding the its * results. */ private void refreshReviewTable() { reviewPanel.removeAll(); rows.clear(); GridBagLayout gbl = new GridBagLayout(); reviewPanel.setLayout(gbl); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridy = 0; try { Map<String, Long> sums = analyser.processLogFile(config.getLogFilename(), fromDate.getDate(), toDate.getDate()); for (Entry<String, Long> entry : sums.entrySet()) { String project = entry.getKey(); double hours = 1.0 * entry.getValue() / (1000 * 3600); addRow(gbl, gbc, project, hours); } for (String project : main.getProjectsTree().getTopLevelProjects()) if (!rows.containsKey(project)) addRow(gbl, gbc, project, 0); gbc.insets = new Insets(10, 0, 0, 0); addLeftLabel(gbl, gbc, "TOTAL"); gbc.gridx = 1; gbc.weightx = 1; totalLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 3)); gbl.setConstraints(totalLabel, gbc); reviewPanel.add(totalLabel); gbc.weightx = 0; addRightLabel(gbl, gbc); } catch (IOException e) { e.printStackTrace(); } recomputeTotal(); pack(); }
/** * Copies the key/value mappings in <tt>map</tt> into this map. Note that this will be a * <b>deep</b> copy, as storage is by primitive value. * * @param map a <code>Map</code> value */ public void putAll(Map<? extends Character, ? extends Double> map) { Iterator<? extends Entry<? extends Character, ? extends Double>> it = map.entrySet().iterator(); for (int i = map.size(); i-- > 0; ) { Entry<? extends Character, ? extends Double> e = it.next(); this.put(e.getKey(), e.getValue()); } }
/** Code completion. */ private void complete() { if (selected()) return; // find first character final int caret = editor.pos(), startPos = editor.completionStart(); final String prefix = string(substring(editor.text(), startPos, caret)); if (prefix.isEmpty()) return; // find insertion candidates final TreeMap<String, String> tmp = new TreeMap<>(); for (final Entry<String, String> entry : REPLACE.entrySet()) { final String key = entry.getKey(); if (key.startsWith(prefix)) tmp.put(key, entry.getValue()); } if (tmp.size() == 1) { // insert single candidate complete(tmp.values().iterator().next(), startPos); } else if (!tmp.isEmpty()) { // show popup menu final JPopupMenu pm = new JPopupMenu(); final ActionListener al = new ActionListener() { @Override public void actionPerformed(final ActionEvent ae) { complete(ae.getActionCommand().replaceAll("^.*?\\] ", ""), startPos); } }; for (final Entry<String, String> entry : tmp.entrySet()) { final JMenuItem mi = new JMenuItem("[" + entry.getKey() + "] " + entry.getValue()); pm.add(mi); mi.addActionListener(al); } pm.addSeparator(); final JMenuItem mi = new JMenuItem(Text.INPUT + Text.COLS + prefix); mi.setEnabled(false); pm.add(mi); final int[] cursor = rend.cursor(); pm.show(this, cursor[0], cursor[1]); // highlight first entry final MenuElement[] me = {pm, (JMenuItem) pm.getComponent(0)}; MenuSelectionManager.defaultManager().setSelectedPath(me); } }
/** Format: mapType, num, (key, value) pairs */ private void writeObject(ObjectOutputStream out) throws IOException { out.writeObject(mapType); out.writeInt(num); for (Entry e : this) { out.writeObject(e.getKey()); out.writeDouble(e.getValue()); } }
/** ** Adds an entry ({@link Entry}) to <code>RTKey</code> */ public static void addRuntimeEntry(Entry dftEntry) { if (dftEntry != null) { String rtKey = dftEntry.getKey(); if (rtKey != null) { RTKey.getRuntimeEntryMap().put(rtKey, dftEntry); defaultProperties = null; } } }
private String generateOverviewText() throws InsufficientDataException { StringBuilder sb = new StringBuilder(); final String team = config.getTeam(); double total = checkTotal(); final String nl = System.getProperty("line.separator"); for (Entry<String, Row> entry : rows.entrySet()) { double hours = Double.parseDouble(entry.getValue().hoursTF.getText()); double fraction = hours / total; if (fraction < 0.004) continue; String line = team + ", " + decimalFormat.format(fraction) + ", " + entry.getKey(); sb.append(line + nl); } return sb.toString(); }
/** * ** Gets all the ddefault properties in <code>RTKey</code> represented ** as an {@link * RTProperties} instance ** @return The <code>RTProperties</code> instance */ public static RTProperties getDefaultProperties() { if (defaultProperties == null) { RTProperties rtp = new RTProperties(); for (Iterator<Entry> v = RTKey.getRuntimeEntryMap().values().iterator(); v.hasNext(); ) { Entry rtk = v.next(); if (!rtk.isHelp()) { String key = rtk.getKey(); Object val = rtk.getDefault(); rtp.setProperty(key, val); } } defaultProperties = rtp; } return defaultProperties; }
/** * ** Prints all the default values from <code>RTKey</code> and {@link RTConfig} ** to the * specified <code>PrintStream</code>. Used for debugging/testing ** @param out The <code> * PrintStream</code> */ public static void printDefaults(PrintStream out) { /* print standard runtime entries */ Set<String> keyList = new OrderedSet<String>(); String keyGrp = null; for (Iterator<Entry> v = RTKey.getRuntimeEntryMap().values().iterator(); v.hasNext(); ) { Entry rtk = v.next(); if (rtk.isHelp()) { out.println(""); out.println("# ===== " + rtk.getHelp()); } else { Object dft = rtk.getDefault(); out.println("# --- " + rtk.getHelp()); out.println("# " + rtk.toString(dft)); String key = rtk.getKey(); keyList.add(key); if (!key.equals(CONFIG_FILE) && RTConfig.hasProperty(key)) { String val = RTConfig.getString(key, null); // if ((val != null) && ((dft == null) || !val.equals(dft.toString()))) { out.println(rtk.toString(val)); // } } } } /* orphaned entries */ RTProperties cmdLineProps = RTConfig.getConfigFileProperties(); if (cmdLineProps != null) { boolean orphanHeader = false; for (Iterator i = cmdLineProps.keyIterator(); i.hasNext(); ) { Object k = i.next(); if (!k.equals(COMMAND_LINE_CONF) && !keyList.contains(k)) { if (!orphanHeader) { out.println(""); out.println("# ===== Other entries"); orphanHeader = true; } Object v = cmdLineProps.getProperty(k, null); out.println(k + "=" + ((v != null) ? v : NULL_VALUE)); } } } /* final blank line */ out.println(""); }