Ejemplo n.º 1
0
        public void actionPerformed(ActionEvent evt) {

          // clear selection
          list.getListComponent().clearSelection();

          int from = fromSpinnerModel.getNumber().intValue();
          int to = toSpinnerModel.getNumber().intValue();

          try {
            ExpressionFormat format = new ExpressionFormat(textField.getText());

            // pad episode numbers with zeros (e.g. %02d) so all numbers have the same number of
            // digits
            NumberFormat numberFormat = NumberFormat.getIntegerInstance();
            numberFormat.setMinimumIntegerDigits(max(2, Integer.toString(max(from, to)).length()));
            numberFormat.setGroupingUsed(false);

            List<String> names = new ArrayList<String>();

            int min = min(from, to);
            int max = max(from, to);

            for (int i = min; i <= max; i++) {
              Bindings bindings = new SimpleBindings();

              // strings
              bindings.put("i", numberFormat.format(i));

              // numbers
              bindings.put("index", i);
              bindings.put("from", from);
              bindings.put("to", to);

              names.add(format.format(bindings, new StringBuffer()).toString());
            }

            if (signum(to - from) < 0) {
              Collections.reverse(names);
            }

            // try to match title from the first five names
            Collection<String> title =
                new SeriesNameMatcher()
                    .matchAll(
                        (names.size() < 5 ? names : names.subList(0, 4)).toArray(new String[0]));

            list.setTitle(title.isEmpty() ? "List" : title.iterator().next());

            list.getModel().clear();
            list.getModel().addAll(names);
          } catch (Exception e) {
            UILogger.log(Level.WARNING, ExceptionUtilities.getMessage(e), e);
          }
        }