/**
  * Gets the next token from a tokenizer and converts it to a name.
  *
  * @param origin The origin to append to relative names.
  * @return The next token in the stream, as a name.
  * @throws TextParseException The input was invalid or not a valid name.
  * @throws IOException An I/O error occurred.
  * @throws RelativeNameException The parsed name was relative, even with the origin.
  * @see Name
  */
 public Name getName(Name origin) throws IOException {
   String next = _getIdentifier("a name");
   try {
     Name name = Name.fromString(next, origin);
     if (!name.isAbsolute()) throw new RelativeNameException(name);
     return name;
   } catch (TextParseException e) {
     throw exception(e.getMessage());
   }
 }
Ejemplo n.º 2
0
  /**
   * Specifies the domains which will be appended to unqualified names before beginning the lookup
   * process. If this is not set, FindServer will be used. Unlike the Lookup setSearchPath function,
   * this will silently ignore invalid names.
   *
   * @see FindServer
   */
  public static synchronized void setSearchPath(String[] domains) {
    if (domains == null || domains.length == 0) {
      Lookup.setDefaultSearchPath((Name[]) null);
      return;
    }

    List l = new ArrayList();
    for (int i = 0; i < domains.length; i++) {
      try {
        l.add(Name.fromString(domains[i], Name.root));
      } catch (TextParseException e) {
      }
    }
    searchPath = (Name[]) l.toArray(new Name[l.size()]);
    Lookup.setDefaultSearchPath(searchPath);
  }
Ejemplo n.º 3
0
  /**
   * Renders a table cell in the main JTable. As a TableCellRenderer, we have to implement this
   * method, but we use it to colour different types of matches in different ways. Remember that
   * this is run every time a cell is displayed on the screen, so it needs to be as fast as can be.
   *
   * @param table The table which needs rendering.
   * @param value The object which needs rendering. For now, this can only be a Name object, but
   *     later on we might colour different types of cells in different ways.
   * @param isSelected Is this cell selected, i.e. is the row selected?
   * @param hasFocus Is this cell focused, i.e. is this individual cell selected?
   * @param row The row coordinate of this cell.
   * @param column The column coordinate of this cell.
   * @return A component representing this cell.
   */
  @Override
  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    // TODO: Check if we can get a saving out of this by just rendering a JLabel/JTextField
    // directly.
    Component c =
        defTableCellRenderer.getTableCellRendererComponent(
            table, value, isSelected, hasFocus, row, column);

    // Set all backgrounds to white.
    c.setBackground(Color.WHITE);

    if (value == null) {
      // Null values look null-ish.
      c.setBackground(COLOR_NULL);
      return c;

    } else if (hasFocus) {
      // ANY cell with focus should look focussed.
      c.setBackground(COLOR_FOCUS);
      return c;

    } else if (Name.class.isAssignableFrom(value.getClass())) {
      // Aha, a Name! Color it special.
      Name name = (Name) value;
      int str_length = name.toString().length();

      if (currentMatch == null) {
        // No current match? Then just colour blank cells blank,
        // and unmatched name colours special so people know that
        // they have been recognized as names.

        if (str_length == 0) {
          c.setBackground(COLOR_BLANK_CELL);
        } else {
          c.setBackground(COLOR_NAME_UNMATCHED);
        }
      } else {
        // So which RowIndex is the match against?
        RowIndex against = currentMatch.getAgainst();

        // System.err.println("Checking against: " + against);

        if (str_length == 0) {
          // Mark blank cells as such.
          c.setBackground(COLOR_BLANK_CELL);
        } else if (against.hasName(name)) {
          // Perfect match!
          c.setBackground(COLOR_NAME_FULL_MATCH);
        } else if (against.hasName(name.getGenus())) {
          // Genus-match.
          c.setBackground(COLOR_NAME_GENUS_MATCH);
        } else {
          // No match!
          c.setBackground(COLOR_NAME_NO_MATCH);
        }
      }

    } else {
      // Not a name? Note that Strings will NOT make it here: we don't
      // push Strings through this. So this is really just for later.
      c.setBackground(COLOR_NULL);
    }

    // If the row is selected, make it darker.
    if (isSelected) c.setBackground(c.getBackground().darker());

    return c;
  }