Example #1
0
 /**
  * Unlocks a book with the given key. The key is trimmed of any leading or trailing whitespace.
  *
  * @param unlockKey the key to try
  * @return true if the unlock key worked.
  */
 public boolean unlock(String unlockKey) {
   String tmpKey = unlockKey;
   if (tmpKey != null) {
     tmpKey = tmpKey.trim();
   }
   add(ConfigEntryType.CIPHER_KEY, tmpKey);
   if (configFile != null) {
     try {
       save();
     } catch (IOException e) {
       // TRANSLATOR: Common error condition: The user supplied unlock key could not be saved.
       Reporter.informUser(this, JSMsg.gettext("Unable to save the book's unlock key."));
     }
   }
   return true;
 }
  /**
   * Customize something to display the Passage component
   *
   * @return The customized component
   */
  public Component getListCellRendererComponent(
      JList list, Object value, int index, boolean selected, boolean focus) {
    if (selected) {
      label.setBackground(list.getSelectionBackground());
      label.setForeground(list.getSelectionForeground());
    } else {
      label.setBackground(list.getBackground());
      label.setForeground(list.getForeground());
    }

    if (value instanceof VerseRange) {
      try {
        VerseRange range = (VerseRange) value;
        String text = (String) hash.get(range);

        if (text == null) {
          BookData bdata = new BookData(bible, range);
          String simple = OSISUtil.getCanonicalText(bdata.getOsisFragment());
          text = "<html><b>" + range.getName() + "</b> " + simple;
          hash.put(range, text);
        }

        label.setText(text);
      } catch (Exception ex) {
        Reporter.informUser(this, ex);
        // TRANSLATOR: Unexpected error condition.
        label.setText(Msg.gettext("Error"));
      }
    } else {
      label.setText((value == null) ? "" : value.toString());
    }

    label.setEnabled(list.isEnabled());
    label.setFont(list.getFont());
    label.setBorder(focus ? UIManager.getBorder("List.focusCellHighlightBorder") : border);

    return label;
  }
  /** JSword calls back to this listener in the event of some types of error */
  public static void installJSwordErrorReportListener() {
    Reporter.addReporterListener(
        new ReporterListener() {
          @Override
          public void reportException(final ReporterEvent ev) {
            showMsg(ev);
          }

          @Override
          public void reportMessage(final ReporterEvent ev) {
            showMsg(ev);
          }

          private void showMsg(ReporterEvent ev) {
            final String msg = "Doh! Something's gone wrong, sorry about this :(";

            //				if (ev==null) {
            //					msg = "Doh! Something's gone wrong, sorry about this :(";
            //				} //else if (!StringUtils.isEmpty(ev.getMessage())) {
            //					msg = ev.getMessage();
            //				} else if (ev.getException()!=null &&
            // StringUtils.isEmpty(ev.getException().getMessage())) {
            //					msg = ev.getException().getMessage();
            //				} else
            //				{
            //					msg = "Doh! Something's gone wrong, sorry about this :(";
            //				}

            Log.d("Install Reporter", msg);

            //			    	new AlertDialog.Builder(context)
            //					   .setMessage(msg)
            //				       .setCancelable(false)
            //				       .show();
          }
        });
  }
 private static void clearListeners() {
   if (listener != null) {
     Reporter.removeReporterListener(listener);
   }
 }