예제 #1
0
  /** Invoked when removing selected reading list is required. */
  private void onRemoveReadingList() {
    int[] rows = tblReadingLists.getSelectedRows();
    boolean haveFeeds = false;
    for (int i = 0; !haveFeeds && i < rows.length; i++) {
      int row = rows[i];
      haveFeeds = readingListsModel.getLists()[row].getFeeds().length > 0;
    }

    boolean delete = true;
    if (haveFeeds) {
      String msg =
          rows.length == 1
              ? Strings.message("guide.dialog.readinglists.has.feeds")
              : Strings.message("guide.dialog.readinglists.have.feeds");

      delete =
          JOptionPane.showConfirmDialog(
                  this,
                  msg,
                  Strings.message("guide.dialog.delete.readinglist"),
                  JOptionPane.YES_NO_OPTION)
              == JOptionPane.YES_OPTION;
    }

    if (delete) readingListsModel.removeRows(rows);
  }
예제 #2
0
  /**
   * Validates the publishing information entered.
   *
   * @return error message or <code>NULL</code> if everything is OK.
   */
  protected String validatePublishing() {
    String msg = null;

    if (isPublishingEnabled()) {
      String publishingTitle = getPublishingTitle();
      if (StringUtils.isEmpty(publishingTitle)) {
        msg = Strings.message("guide.dialog.validation.publishing.empty.title");
      } else if (StringUtils.indexOfAny(publishingTitle, new String[] {"/", "\""}) > -1) {
        msg = Strings.message("guide.dialog.validation.publishing.invalid.title");
      } else {
        IGuide currentGuide = getGuide();
        IGuide otherGuide = guidesSet.getGuideByPublishingTitle(publishingTitle);

        if (currentGuide == null
            ? otherGuide != null
            : otherGuide != null && otherGuide != currentGuide) {
          msg =
              MessageFormat.format(
                  Strings.message("guide.dialog.validation.publishing.existing.title"),
                  getPublishingTitle());
        }
      }
    }

    return msg;
  }
예제 #3
0
    /**
     * Converts timestamp into some string representation.
     *
     * @param aTime time to convert.
     * @return string.
     */
    private String pollTimeToString(long aTime) {
      String timeS;

      if (aTime == -1) {
        timeS = Strings.message("guide.dialog.readinglists.table.latest.never");
      } else {
        TimeRange range = findTimeRange(aTime);
        if (range == TimeRange.TR_FUTURE) {
          timeS = Strings.message("guide.dialog.readinglists.table.latest.never");
        } else if (range == TimeRange.TR_TODAY) {
          DateFormat fmt = DateFormat.getTimeInstance(DateFormat.SHORT);
          timeS =
              MessageFormat.format(
                  Strings.message("guide.dialog.readinglists.table.latest.today.0"),
                  fmt.format(new Date(aTime)));
        } else if (range == TimeRange.TR_YESTERDAY) {
          DateFormat fmt = DateFormat.getTimeInstance(DateFormat.SHORT);
          timeS =
              MessageFormat.format(
                  Strings.message("guide.dialog.readinglists.table.latest.yesterday.0"),
                  fmt.format(new Date(aTime)));
        } else {
          timeS = DATE_FORMAT.format(new Date(aTime));
        }
      }

      return timeS;
    }
예제 #4
0
  /**
   * Creates component.
   *
   * @param collection collection to show.
   * @param treeMode <code>TRUE</code> to set tree mode by default.
   * @param readingLists <code>TRUE</code> if showing reading lists.
   */
  public CListTree(Collection collection, boolean treeMode, boolean readingLists) {
    this.collection = collection;
    this.readingLists = readingLists;

    itemListener = new CItemListener();

    setLayout(new BorderLayout());
    setTreeMode(treeMode);

    BBFormBuilder builder = new BBFormBuilder("p, 2dlu, p, 0:grow");

    JComboBox cbViewMode =
        new JComboBox(
            new Object[] {
              Strings.message("collections.viewmode.tree"),
              Strings.message("collections.viewmode.list")
            });
    cbViewMode.setSelectedIndex(treeMode ? 0 : 1);
    cbViewMode.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            JComboBox box = (JComboBox) e.getSource();
            boolean isTree = box.getSelectedIndex() == 0;
            setTreeMode(isTree);
          }
        });

    builder.append(Strings.message("collections.viewmode"), cbViewMode);
    builder.appendRelatedComponentsGapRow(2);

    add(builder.getPanel(), BorderLayout.NORTH);

    // Description area
    taDescription = new JEditorPane();
    Color back = taDescription.getBackground();
    taDescription.setEditable(false);
    taDescription.setBackground(back);
    taDescription.setEditorKit(new CustomHTMLEditorKit());

    HTMLDocument doc = (HTMLDocument) taDescription.getDocument();
    Style def = doc.getStyle("default");
    Font font = UIManager.getFont("TextArea.font");
    if (SystemUtils.IS_OS_MAC) font = UifUtilities.applyFontBias(font, -2);
    UifUtilities.setFontAttributes(doc.addStyle(TEXT_STYLE, def), font);

    builder = new BBFormBuilder("0:grow");
    builder.appendUnrelatedComponentsGapRow(2);
    builder.appendRow("p");

    builder.append(Strings.message("collections.description"), 1);
    builder.appendRelatedComponentsGapRow(2);
    builder.appendRow("50px");
    builder.append(taDescription, 1, CellConstraints.FILL, CellConstraints.FILL);

    add(builder.getPanel(), BorderLayout.SOUTH);
  }
예제 #5
0
  /**
   * Checks if title is valid.
   *
   * @return error message or NULL.
   */
  protected String validateTitle() {
    String message = null;

    final String title = tfTitle.getText();
    if (title == null || title.trim().length() == 0) {
      message = Strings.message("guide.dialog.validation.empty.title");
    } else if (CommonUtils.areDifferent(originalTitle, title) && presentTitles.contains(title)) {
      message = Strings.message("guide.dialog.validation.already.present");
    }
    return message;
  }
예제 #6
0
  /**
   * Builds reading lists tab.
   *
   * @return component.
   */
  protected JComponent buildReadingListsTab() {
    // Wording
    JComponent wording = msg(Strings.message("guide.dialog.readinglists.wording"));

    // Buttons
    Dimension btnSize = new Dimension(20, 20);
    btnAddReadingList.setPreferredSize(btnSize);
    btnRemoveList.setPreferredSize(btnSize);
    FlowLayout layout = new FlowLayout(FlowLayout.LEFT);
    JPanel bbar = new JPanel(layout);
    bbar.add(btnAddReadingList);
    bbar.add(btnRemoveList);
    layout.setHgap(0);
    layout.setVgap(0);

    // Panel
    BBFormBuilder builder = new BBFormBuilder("0:grow");
    builder.setDefaultDialogBorder();

    builder.append(wording);
    builder.appendUnrelatedComponentsGapRow(2);
    builder.appendRow("min:grow");
    builder.append(new JScrollPane(tblReadingLists), 1, CellConstraints.FILL, CellConstraints.FILL);
    builder.append(bbar);

    return builder.getPanel();
  }
예제 #7
0
    /**
     * Builds main part.
     *
     * @return main part.
     */
    protected JComponent buildMain() {
      BBFormBuilder builder = new BBFormBuilder("pref, 4dlu, max(pref;200px):grow, 4dlu, p");
      builder.setDefaultDialogBorder();

      JComponent wording =
          ComponentsFactory.createWrappedMultilineLabel(
              Strings.message("guide.dialog.readinglists.add.wording"));

      builder.append(wording, 3);
      builder.appendUnrelatedComponentsGapRow(2);

      builder.append(Strings.message("guide.dialog.readinglists.add.address"), tfAddress);
      builder.append(btnSuggest);
      builder.append(Strings.message("guide.dialog.readinglists.add.status"), lbStatus);

      return builder.getPanel();
    }
예제 #8
0
  /**
   * Builds the panel for publishing tab when too many guides are already published.
   *
   * @param wording wording to put on the page.
   * @return component.
   */
  private JPanel buildPublishingTabLimitReached(JComponent wording) {
    BBFormBuilder builder = new BBFormBuilder("0:grow");
    builder.setDefaultDialogBorder();

    builder.append(wording);
    builder.appendUnrelatedComponentsGapRow(2);

    builder.append(
        ComponentsFactory.createWrappedMultilineLabel(
            MessageFormat.format(
                Strings.message("guide.dialog.publishing.limit.reached"), publishingLimit)));
    builder.appendUnrelatedComponentsGapRow(2);

    LinkLabel link =
        new LinkLabel(Strings.message("guide.dialog.publishing.limit.reached.link"), SERVICE_LINK);
    builder.append(link);

    return builder.getPanel();
  }
예제 #9
0
  /**
   * Creates Publishing tab.
   *
   * @return component.
   */
  protected JComponent buildPublishingTab() {
    JComponent wording =
        ComponentsFactory.createWrappedMultilineLabel(
            Strings.message("guide.dialog.publishing.publish"));

    return publishingAvailable
        ? (isReachedPublishingLimit()
            ? buildPublishingTabLimitReached(wording)
            : buildPublishingTabAvailable(wording))
        : buildPublishingTabUnavailable(wording);
  }
예제 #10
0
 /** Called when user confirms the information. */
 public void doAccept() {
   String validationMessage = validateInformation();
   if (validationMessage == null) {
     super.doAccept();
   } else {
     JOptionPane.showMessageDialog(
         this,
         validationMessage,
         Strings.message("guide.dialog.error"),
         JOptionPane.ERROR_MESSAGE);
   }
 }
예제 #11
0
  /**
   * Creates notifications panel.
   *
   * @return panel.
   */
  protected JComponent buildNotificationsTab() {
    // Wording
    JComponent wording = msg(Strings.message("guide.dialog.notifications.wording"));

    // Panel
    BBFormBuilder builder = new BBFormBuilder("0:grow");
    builder.setDefaultDialogBorder();

    builder.append(wording);
    builder.appendUnrelatedComponentsGapRow(2);
    builder.append(chAllowNotifications);

    return builder.getPanel();
  }
예제 #12
0
  /**
   * Builds panel for publishing tab when publishing is unavailable.
   *
   * @param aWording wording to put on the page.
   * @return component.
   */
  private JPanel buildPublishingTabUnavailable(JComponent aWording) {
    // Panel
    BBFormBuilder builder = new BBFormBuilder("0:grow");
    builder.setDefaultDialogBorder();

    builder.append(aWording);
    builder.appendUnrelatedComponentsGapRow(2);

    builder.append(
        ComponentsFactory.createWrappedMultilineLabel(
            Strings.message("guide.dialog.publishing.you.need.bbservice.account")));

    return builder.getPanel();
  }
예제 #13
0
  /**
   * Builds panel for publishing tab when publishing is available.
   *
   * @param aWording wording to put on the page.
   * @return component.
   */
  private JPanel buildPublishingTabAvailable(JComponent aWording) {
    JPanel sscPanel = new JPanel(new BorderLayout());
    sscPanel.add(sscPublishingRating, BorderLayout.WEST);

    // Panel
    BBFormBuilder builder = new BBFormBuilder("7dlu, p, 2dlu, 100dlu, 0:grow, 2dlu, p");
    builder.setDefaultDialogBorder();

    builder.append(aWording, 7);
    builder.appendUnrelatedComponentsGapRow(2);

    builder.append(chPublishingEnabled, 7);
    builder.setLeadingColumnOffset(1);
    builder.append(lbPublishingTitle, tfPublishingTitle);
    builder.nextLine();
    builder.append(lbPublishingTags, tfPublishingTags);
    builder.nextLine();
    builder.append(lbPublishingPublic, chPublishingPublic);
    builder.nextLine();
    builder.append(lbPublishingRating, sscPanel);
    builder.appendUnrelatedComponentsGapRow(2);

    builder.append(lbPublishingURL);
    builder.append(lnkPublishingURL, 2);
    builder.append(btnCopyToClipboard);
    builder.append(lbLastPublishingDate, tfLastPublishingDate);

    builder.setLeadingColumnOffset(0);
    builder.appendUnrelatedComponentsGapRow(2);
    builder.appendRow("min:grow");

    JComponent instructionsBox =
        ComponentsFactory.createInstructionsBox(
            Strings.message("guide.dialog.publishing.instructions"));
    builder.append(instructionsBox, 7, CellConstraints.FILL, CellConstraints.FILL);

    return builder.getPanel();
  }
예제 #14
0
    /**
     * Creates dialog.
     *
     * @param parent parent dialog.
     */
    public NewReadingListDialog(Dialog parent) {
      super(parent, Strings.message("guide.dialog.add.readinglist"));

      btnSuggest = new JButton(new SuggestAction());
      enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    }
예제 #15
0
 /**
  * Builds and answers the preference's header.
  *
  * @return JComponent header of dialog box
  */
 protected JComponent buildHeader() {
   return new HeaderPanelExt(
       Strings.message("blogstarz.settings.dialog.title"),
       Strings.message("blogstarz.settings.dialog.header"),
       IconSource.getIcon(ResourceID.ICON_PREFERENCES));
 }
예제 #16
0
  /** Reading lists table model. */
  private static class ReadingListsTableModel extends DefaultTableModel {
    // Format for dates
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("EEE MMM dd, yy");

    /** List name. */
    public static final int COL_NAME = 0;
    /** List URL. */
    public static final int COL_URL = 1;
    /** List latest update time. */
    public static final int COL_LATEST = 2;

    private static final String[] COLUMNS = {
      Strings.message("guide.dialog.readinglists.table.name"),
      Strings.message("guide.dialog.readinglists.table.url"),
      Strings.message("guide.dialog.readinglists.table.latest")
    };
    private static final Class[] CLASSES = {String.class, String.class, String.class};

    private ReadingList[] lists;

    /**
     * Returns current version of reading lists.
     *
     * @return current version.
     */
    public ReadingList[] getLists() {
      return lists;
    }

    /**
     * Sets the version of reading lists.
     *
     * @param aLists lists.
     */
    public void setLists(ReadingList[] aLists) {
      lists = aLists;
      fireTableDataChanged();
    }

    /**
     * Returns number of columns in this table.
     *
     * @return columns
     */
    public int getColumnCount() {
      return COLUMNS.length;
    }

    /**
     * Returns number of rows in the table.
     *
     * @return rows.
     */
    public int getRowCount() {
      return lists == null ? 0 : lists.length;
    }

    /**
     * Returns value of a cell.
     *
     * @param row row.
     * @param column column.
     * @return value.
     */
    public Object getValueAt(int row, int column) {
      Object value;
      ReadingList list = lists[row];

      switch (column) {
        case COL_NAME:
          value = list.getTitle();
          break;
        case COL_URL:
          value = list.getURL().toString();
          break;
        case COL_LATEST:
          long lastPollTime = list.getLastPollTime();
          value = pollTimeToString(lastPollTime);
          break;
        default:
          value = null;
      }
      return value;
    }

    /**
     * Converts timestamp into some string representation.
     *
     * @param aTime time to convert.
     * @return string.
     */
    private String pollTimeToString(long aTime) {
      String timeS;

      if (aTime == -1) {
        timeS = Strings.message("guide.dialog.readinglists.table.latest.never");
      } else {
        TimeRange range = findTimeRange(aTime);
        if (range == TimeRange.TR_FUTURE) {
          timeS = Strings.message("guide.dialog.readinglists.table.latest.never");
        } else if (range == TimeRange.TR_TODAY) {
          DateFormat fmt = DateFormat.getTimeInstance(DateFormat.SHORT);
          timeS =
              MessageFormat.format(
                  Strings.message("guide.dialog.readinglists.table.latest.today.0"),
                  fmt.format(new Date(aTime)));
        } else if (range == TimeRange.TR_YESTERDAY) {
          DateFormat fmt = DateFormat.getTimeInstance(DateFormat.SHORT);
          timeS =
              MessageFormat.format(
                  Strings.message("guide.dialog.readinglists.table.latest.yesterday.0"),
                  fmt.format(new Date(aTime)));
        } else {
          timeS = DATE_FORMAT.format(new Date(aTime));
        }
      }

      return timeS;
    }

    /**
     * Finds range matching this time.
     *
     * @param aTime time.
     * @return range.
     */
    private TimeRange findTimeRange(long aTime) {
      TimeRange range = null;

      for (int i = 0; range == null && i < TimeRange.TIME_RANGES.length; i++) {
        TimeRange timeRange = TimeRange.TIME_RANGES[i];
        if (timeRange.isInRange(aTime)) range = timeRange;
      }

      return range;
    }

    /**
     * None of the cells editable.
     *
     * @param row row.
     * @param column column.
     * @return <code>FALSE</code>.
     */
    public boolean isCellEditable(int row, int column) {
      return false;
    }

    /**
     * Returns the title of the column.
     *
     * @param column column.
     * @return title.
     */
    public String getColumnName(int column) {
      return COLUMNS[column];
    }

    /**
     * Returns data class of the column.
     *
     * @param column column.
     * @return class.
     */
    public Class getColumnClass(int column) {
      return CLASSES[column];
    }

    /**
     * Removes specific rows from the list of reading lists.
     *
     * @param aRows rows to remove.
     */
    public void removeRows(int[] aRows) {
      Arrays.sort(aRows);

      java.util.List<ReadingList> newLists = new ArrayList<ReadingList>(Arrays.asList(lists));
      for (int i = aRows.length - 1; i >= 0; i--) {
        newLists.remove(aRows[i]);
      }

      setLists(newLists.toArray(new ReadingList[newLists.size()]));
    }

    /**
     * Adds new reading list URL.
     *
     * @param aNewListURL new reading list.
     */
    public void addList(URL aNewListURL) {
      ReadingList[] newList = new ReadingList[lists.length + 1];
      System.arraycopy(lists, 0, newList, 0, lists.length);
      newList[lists.length] = new ReadingList(aNewListURL);

      setLists(newList);
    }
  }
예제 #17
0
  /**
   * Creates dialog.
   *
   * @param aFrame parent frame.
   * @param aTitle dialog title.
   * @param aPublishingAvailable <code>TRUE</code> if publishing is available.
   * @param aPublishingLimit the number of guides the user can have published.
   * @param aPublishingLimitReached <code>TRUE</code> if the limit is reached.
   */
  public BasicGuideDialog(
      Frame aFrame,
      String aTitle,
      boolean aPublishingAvailable,
      int aPublishingLimit,
      boolean aPublishingLimitReached) {
    super(aFrame, aTitle);

    publishingAvailable = aPublishingAvailable;
    publishingLimit = aPublishingLimit;
    publishingLimitReached = aPublishingLimitReached;

    presentTitles = Collections.EMPTY_SET;
    model = new GuideIcons.ComboBoxModel();
    renderer = new IconListCellRenderer();
    readingListsModel = new ReadingListsTableModel();

    tblReadingLists = new JTable(readingListsModel);
    tblReadingLists.setDefaultRenderer(
        String.class, new ReadingListsTableCellRenderer(readingListsModel));
    UifUtilities.setTableColWidth(tblReadingLists, 2, 90);

    btnAddReadingList = new JButton(null, ResourceUtils.getIcon("add.icon"));
    btnAddReadingList.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            onAddReadingList();
          }
        });
    btnRemoveList = new JButton(null, ResourceUtils.getIcon("delete.icon"));
    btnRemoveList.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            onRemoveReadingList();
          }
        });

    // Publishing components
    chPublishingEnabled =
        ComponentsFactory.createCheckBox(Strings.message("guide.dialog.enable.publishing"));
    lbPublishingPublic = new JLabel(Strings.message("guide.dialog.public.visibility"));
    chPublishingPublic = new JCheckBox();
    lbPublishingTitle =
        ComponentsFactory.createLabel(Strings.message("guide.dialog.reading.list.title"));
    lbPublishingTags = ComponentsFactory.createLabel(Strings.message("guide.dialog.tags"));
    lbPublishingURL = new JLabel(Strings.message("guide.dialog.publicationurl"));
    lnkPublishingURL = new LinkLabel(Strings.message("guide.dialog.not.published.yet"));
    lbLastPublishingDate = new JLabel(Strings.message("guide.dialog.last.update.date"));
    tfLastPublishingDate = new JLabel(Strings.message("guide.dialog.never.updated"));
    tfPublishingTitle = new JTextField();
    lbPublishingTitle.setLabelFor(tfPublishingTitle);
    tfPublishingTags = new JTextField();
    lbPublishingTags.setLabelFor(tfPublishingTags);

    vhPublishingRating = new ValueHolder(1);
    sscPublishingRating =
        new StarsSelectionComponent(new BoundedRangeAdapter(vhPublishingRating, 0, 1, 5));
    lbPublishingRating = new JLabel(Strings.message("guide.dialog.rating"));

    btnCopyToClipboard = new JButton(Strings.message("guide.dialog.copy"));
    btnCopyToClipboard.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            CommonUtils.copyTextToClipboard(lnkPublishingURL.getText());
          }
        });

    onPublishingEnabled();
    chPublishingEnabled.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            onPublishingEnabled();
          }
        });

    chAllowNotifications =
        ComponentsFactory.createCheckBox(Strings.message("guide.dialog.allow.notifications"));
  }
예제 #18
0
 /**
  * Creates keywords dialog.
  *
  * @param owner owning frame.
  * @param aModel global Model of BlogBridge.
  */
 public BlogStarzDialog(AbstractFrame owner, GlobalModel aModel) {
   super(owner, Strings.message("blogstarz.settings.dialog.title"));
   this.model = aModel;
 }
예제 #19
0
 /**
  * Defines an <code>Action</code> object with a default description string and default icon.
  */
 public SuggestAction() {
   super(Strings.message("guide.dialog.readinglists.add.suggest"));
 }
예제 #20
0
 /**
  * Sets counter and shows/hides label.
  *
  * @param cnt counter.
  */
 public void setCount(int cnt) {
   count = cnt;
   lbMore.setText(
       MessageFormat.format(Strings.message("search.0.more"), Integer.toString(count)));
   updateVisibility();
 }