Ejemplo n.º 1
2
 /**
  * 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();
 }
Ejemplo n.º 2
0
 protected RichText.Part text(PState s, String text, Map<? extends Attribute, ?> attrs)
     throws IOException {
   RichText.Part ret = null;
   int p = 0;
   while (true) {
     Matcher m = urlpat.matcher(text);
     if (!m.find(p)) break;
     URL url;
     try {
       String su = text.substring(m.start(), m.end());
       if (su.indexOf(':') < 0) su = "http://" + su;
       url = new URL(su);
     } catch (java.net.MalformedURLException e) {
       p = m.end();
       continue;
     }
     RichText.Part lead = new RichText.TextPart(text.substring(0, m.start()), attrs);
     if (ret == null) ret = lead;
     else ret.append(lead);
     Map<Attribute, Object> na = new HashMap<Attribute, Object>(attrs);
     na.putAll(urlstyle);
     na.put(ChatAttribute.HYPERLINK, new FuckMeGentlyWithAChainsaw(url));
     ret.append(new RichText.TextPart(text.substring(m.start(), m.end()), na));
     p = m.end();
   }
   if (ret == null) ret = new RichText.TextPart(text, attrs);
   else ret.append(new RichText.TextPart(text.substring(p), attrs));
   return (ret);
 }
Ejemplo n.º 3
0
  @Override
  public Image getIcon(final int iconType) {
    Image icon = img.get(iconType);
    if (icon != null) return icon;

    // try to get a special icon
    icon = BeanSupport.getBeanIcon(component.getBeanClass(), iconType);
    if (icon == null) {
      final String className = component.getBeanClass().getName();
      final String classDetails =
          (String) component.getAuxValue(RADComponent.AUX_VALUE_CLASS_DETAILS);
      if (!iconsInitialized) {
        // getIconForClass invokes getNodes(true) which cannot be called in Mutex
        EventQueue.invokeLater(
            new Runnable() {
              @Override
              public void run() {
                Image icon = PaletteUtils.getIconForClass(className, classDetails, iconType, true);
                iconsInitialized = true;
                if (icon != null) {
                  img.put(iconType, icon);
                  fireIconChange();
                }
              }
            });
      } else {
        icon = PaletteUtils.getIconForClass(className, classDetails, iconType, false);
      }

      if (icon == null) {
        // get icon from BeanInfo
        java.beans.BeanInfo bi = component.getBeanInfo();
        if (bi != null) {
          icon = bi.getIcon(iconType);
        }

        if (icon == null) {
          // use default icon
          icon = super.getIcon(iconType);
        }
      }
    }
    img.put(iconType, icon);
    return icon;
  }
Ejemplo n.º 4
0
 /**
  * Adds a single row to the {@link #reviewPanel}.
  *
  * @param gbl The layout to add the row to.
  * @param gbc The layout constraints to use.
  * @param title The title of the top-level project.
  * @param hours The amount of hours spent on the project.
  */
 private void addRow(GridBagLayout gbl, GridBagConstraints gbc, String title, double hours) {
   Row row = new Row();
   addLeftLabel(gbl, gbc, title);
   addMiddleField(gbl, gbc, row, hours);
   addRightLabel(gbl, gbc);
   addPercentLabel(gbl, gbc, row);
   rows.put(title, row);
   gbc.gridy++;
 }
Ejemplo n.º 5
0
 /**
  * This function re-computes the total number of hours for the selected period. It is ran every
  * time the user edits a text field specifying the number of hours for a particular top-level
  * project. Percentage labels are also updated.
  */
 private void recomputeTotal() {
   double total = 0;
   for (Row row : rows.values()) {
     try {
       row.hours = Double.parseDouble(row.hoursTF.getText());
       total += row.hours;
       row.hoursTF.setForeground(normalColour);
     } catch (NumberFormatException e) {
       row.hoursTF.setForeground(errorColour);
       totalLabel.setText("ERROR");
       totalLabel.setForeground(errorColour);
       return;
     }
   }
   totalLabel.setText(decimalFormat.format(total));
   totalLabel.setForeground(normalColour);
   for (Row row : rows.values()) {
     String percentS = decimalFormat.format(total == 0 ? 0 : 100 * row.hours / total);
     row.percentL.setText("(" + percentS + "%)");
   }
   pack();
 }
Ejemplo n.º 6
0
 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();
 }
Ejemplo n.º 7
0
  /**
   * Read a line from the <i>in</i> {@link InputStream}, and return the line (without any trailing
   * newlines).
   *
   * @param prompt the prompt to issue to the console, may be null.
   * @return a line that is read from the terminal, or null if there was null input (e.g.,
   *     <i>CTRL-D</i> was pressed).
   */
  public String readLine(final String prompt, final Character mask) throws IOException {
    this.mask = mask;
    if (prompt != null) this.prompt = prompt;

    try {
      terminal.beforeReadLine(this, this.prompt, mask);

      if ((this.prompt != null) && (this.prompt.length() > 0)) {
        out.write(this.prompt);
        out.flush();
      }

      // if the terminal is unsupported, just use plain-java reading
      if (!terminal.isSupported()) {
        return readLine(in);
      }

      while (true) {
        int[] next = readBinding();

        if (next == null) {
          return null;
        }

        int c = next[0];
        int code = next[1];

        if (c == -1) {
          return null;
        }

        boolean success = true;

        switch (code) {
          case EXIT: // ctrl-d
            if (buf.buffer.length() == 0) {
              return null;
            }

          case COMPLETE: // tab
            success = complete();
            break;

          case MOVE_TO_BEG:
            success = setCursorPosition(0);
            break;

          case KILL_LINE: // CTRL-K
            success = killLine();
            break;

          case CLEAR_SCREEN: // CTRL-L
            success = clearScreen();
            break;

          case KILL_LINE_PREV: // CTRL-U
            success = resetLine();
            break;

          case NEWLINE: // enter
            moveToEnd();
            printNewline(); // output newline
            return finishBuffer();

          case DELETE_PREV_CHAR: // backspace
            success = backspace();
            break;

          case DELETE_NEXT_CHAR: // delete
            success = deleteCurrentCharacter();
            break;

          case MOVE_TO_END:
            success = moveToEnd();
            break;

          case PREV_CHAR:
            success = moveCursor(-1) != 0;
            break;

          case NEXT_CHAR:
            success = moveCursor(1) != 0;
            break;

          case NEXT_HISTORY:
            success = moveHistory(true);
            break;

          case PREV_HISTORY:
            success = moveHistory(false);
            break;

          case REDISPLAY:
            break;

          case PASTE:
            success = paste();
            break;

          case DELETE_PREV_WORD:
            success = deletePreviousWord();
            break;

          case PREV_WORD:
            success = previousWord();
            break;

          case NEXT_WORD:
            success = nextWord();
            break;

          case START_OF_HISTORY:
            success = history.moveToFirstEntry();
            if (success) setBuffer(history.current());
            break;

          case END_OF_HISTORY:
            success = history.moveToLastEntry();
            if (success) setBuffer(history.current());
            break;

          case CLEAR_LINE:
            moveInternal(-(buf.buffer.length()));
            killLine();
            break;

          case INSERT:
            buf.setOvertyping(!buf.isOvertyping());
            break;

          case UNKNOWN:
          default:
            if (c != 0) { // ignore null chars
              ActionListener action =
                  (ActionListener) triggeredActions.get(new Character((char) c));
              if (action != null) action.actionPerformed(null);
              else putChar(c, true);
            } else success = false;
        }

        if (!(success)) {
          beep();
        }

        flushConsole();
      }
    } finally {
      terminal.afterReadLine(this, this.prompt, mask);
    }
  }
Ejemplo n.º 8
0
  static {
    Map names = new TreeMap();

    names.put("MOVE_TO_BEG", new Short(MOVE_TO_BEG));
    names.put("MOVE_TO_END", new Short(MOVE_TO_END));
    names.put("PREV_CHAR", new Short(PREV_CHAR));
    names.put("NEWLINE", new Short(NEWLINE));
    names.put("KILL_LINE", new Short(KILL_LINE));
    names.put("PASTE", new Short(PASTE));
    names.put("CLEAR_SCREEN", new Short(CLEAR_SCREEN));
    names.put("NEXT_HISTORY", new Short(NEXT_HISTORY));
    names.put("PREV_HISTORY", new Short(PREV_HISTORY));
    names.put("START_OF_HISTORY", new Short(START_OF_HISTORY));
    names.put("END_OF_HISTORY", new Short(END_OF_HISTORY));
    names.put("REDISPLAY", new Short(REDISPLAY));
    names.put("KILL_LINE_PREV", new Short(KILL_LINE_PREV));
    names.put("DELETE_PREV_WORD", new Short(DELETE_PREV_WORD));
    names.put("NEXT_CHAR", new Short(NEXT_CHAR));
    names.put("REPEAT_PREV_CHAR", new Short(REPEAT_PREV_CHAR));
    names.put("SEARCH_PREV", new Short(SEARCH_PREV));
    names.put("REPEAT_NEXT_CHAR", new Short(REPEAT_NEXT_CHAR));
    names.put("SEARCH_NEXT", new Short(SEARCH_NEXT));
    names.put("PREV_SPACE_WORD", new Short(PREV_SPACE_WORD));
    names.put("TO_END_WORD", new Short(TO_END_WORD));
    names.put("REPEAT_SEARCH_PREV", new Short(REPEAT_SEARCH_PREV));
    names.put("PASTE_PREV", new Short(PASTE_PREV));
    names.put("REPLACE_MODE", new Short(REPLACE_MODE));
    names.put("SUBSTITUTE_LINE", new Short(SUBSTITUTE_LINE));
    names.put("TO_PREV_CHAR", new Short(TO_PREV_CHAR));
    names.put("NEXT_SPACE_WORD", new Short(NEXT_SPACE_WORD));
    names.put("DELETE_PREV_CHAR", new Short(DELETE_PREV_CHAR));
    names.put("ADD", new Short(ADD));
    names.put("PREV_WORD", new Short(PREV_WORD));
    names.put("CHANGE_META", new Short(CHANGE_META));
    names.put("DELETE_META", new Short(DELETE_META));
    names.put("END_WORD", new Short(END_WORD));
    names.put("NEXT_CHAR", new Short(NEXT_CHAR));
    names.put("INSERT", new Short(INSERT));
    names.put("REPEAT_SEARCH_NEXT", new Short(REPEAT_SEARCH_NEXT));
    names.put("PASTE_NEXT", new Short(PASTE_NEXT));
    names.put("REPLACE_CHAR", new Short(REPLACE_CHAR));
    names.put("SUBSTITUTE_CHAR", new Short(SUBSTITUTE_CHAR));
    names.put("TO_NEXT_CHAR", new Short(TO_NEXT_CHAR));
    names.put("UNDO", new Short(UNDO));
    names.put("NEXT_WORD", new Short(NEXT_WORD));
    names.put("DELETE_NEXT_CHAR", new Short(DELETE_NEXT_CHAR));
    names.put("CHANGE_CASE", new Short(CHANGE_CASE));
    names.put("COMPLETE", new Short(COMPLETE));
    names.put("EXIT", new Short(EXIT));
    names.put("CLEAR_LINE", new Short(CLEAR_LINE));

    KEYMAP_NAMES = new TreeMap(Collections.unmodifiableMap(names));
  }
Ejemplo n.º 9
0
 /**
  * Adding a triggered Action allows to give another curse of action if a character passed the
  * preprocessing.
  *
  * <p>Say you want to close the application if the user enter q. addTriggerAction('q', new
  * ActionListener(){ System.exit(0); }); would do the trick.
  *
  * @param c
  * @param listener
  */
 public void addTriggeredAction(char c, ActionListener listener) {
   triggeredActions.put(new Character(c), listener);
 }