/** @author Bob Tantlinger */
public class TBTableCellRenderer extends JLabel implements TableCellRenderer {
  /** */
  private static final long serialVersionUID = 1L;

  private DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);

  private Date expireDate = null;

  private Font plainFont = new Font("Dialog", Font.PLAIN, 12);
  private Font boldFont = new Font("Dialog", Font.BOLD, 12);
  private ImageIcon unreadItemIcon = UIUtils.getIcon(UIUtils.MISC, "unread_item.gif");
  private ImageIcon readItemIcon = UIUtils.getIcon(UIUtils.MISC, "read_item.gif");
  private ImageIcon postIcon = UIUtils.getIcon(UIUtils.X16, "post.png");
  private ImageIcon uPostIcon = UIUtils.getIcon(UIUtils.X16, "update_post.png");

  public void setExpireDate(Date d) {
    expireDate = d;
  }

  public Date getExpireDate() {
    return expireDate;
  }

  public Component getTableCellRendererComponent(
      JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    setOpaque(true);
    setFont(plainFont);
    // setBorder(new EmptyBorder(10, 10, 10, 6));

    if (isSelected) {
      setForeground(table.getSelectionForeground());
      setBackground(table.getSelectionBackground());
    } else {
      setForeground(table.getForeground());
      setBackground(table.getBackground());
    }

    if (table.getModel() instanceof FeedTableModel) {
      FeedTableModel rsstm = (FeedTableModel) table.getModel();
      TableColumn col = table.getColumnModel().getColumn(column);
      if (!rsstm.isItemAtRowRead(row)) setFont(boldFont);
      if (col.getHeaderValue() == FeedTableModel.READ) {
        if (rsstm.isItemAtRowRead(row)) setIcon(readItemIcon);
        else setIcon(unreadItemIcon);
      } else setIcon(null);

    } else if (table.getModel() instanceof WeblogTableModel) {
      WeblogTableModel btm = (WeblogTableModel) table.getModel();
      if (column == 0) {
        // is the modified column on the TableModel null?
        if (btm.getValueAt(row, WeblogTableModel.MODIFIED_COL) == null) setIcon(postIcon);
        else setIcon(uPostIcon);
      } else setIcon(null);
    }

    if (value instanceof FeedItem) {
      setText(((FeedItem) value).getTitle());
      return this;
    } else if (value instanceof Boolean) {
      setText("");
      setHorizontalAlignment(SwingConstants.CENTER);
      return this;
    } else if (value instanceof Integer) {
      Integer val = (Integer) value;
      setHorizontalAlignment(SwingConstants.CENTER);
      setText(val.intValue() + "");
      return this;
    } else if (value instanceof Date) {
      Date d = (Date) value;
      setText(df.format(d));
      if ((table.getModel() instanceof WeblogTableModel) && (column == WeblogTableModel.DATE_COL)) {
        if (expireDate != null && d.before(expireDate)) setForeground(Color.red);
      }

      return this;
    }

    setHorizontalAlignment(SwingConstants.LEFT);
    // setToolTipText(value.toString());
    if (value == null) setText("");
    else setText(value.toString());
    return this;
  }
}
Example #2
0
public class HyperlinkDialog extends HTMLOptionDialog {
  /** */
  private static final long serialVersionUID = 1L;

  private static final I18n i18n = I18n.getInstance("net.atlanticbb.tantlinger.ui.text.dialogs");

  private static Icon icon = UIUtils.getIcon(UIUtils.X48, "link.png"); // $NON-NLS-1$
  private String title = i18n.str("hyperlink"); // $NON-NLS-1$
  private String desc = i18n.str("hyperlink_desc"); // $NON-NLS-1$

  private LinkPanel linkPanel;

  public HyperlinkDialog(Frame parent) {
    this(parent, i18n.str("hyperlink"), i18n.str("hyperlink_desc"), icon, true);
  }

  public HyperlinkDialog(Dialog parent) {
    this(parent, i18n.str("hyperlink"), i18n.str("hyperlink_desc"), icon, true);
  }

  public HyperlinkDialog(
      Dialog parent, String title, String desc, Icon ico, boolean urlFieldEnabled) {
    super(parent, title, desc, ico);
    init(urlFieldEnabled);
  }

  public HyperlinkDialog(
      Frame parent, String title, String desc, Icon ico, boolean urlFieldEnabled) {
    super(parent, title, desc, ico);
    init(urlFieldEnabled);
  }

  private void init(boolean urlFieldEnabled) {
    linkPanel = new LinkPanel(urlFieldEnabled);
    linkPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setContentPane(linkPanel);
    setSize(315, 370);
    setResizable(false);
  }

  public Map getAttributes() {
    return linkPanel.getAttributes();
  }

  public void setAttributes(Map attribs) {
    linkPanel.setAttributes(attribs);
  }

  public void setLinkText(String text) {
    linkPanel.setLinkText(text);
  }

  public String getLinkText() {
    return linkPanel.getLinkText();
  }

  public String getHTML() {
    String html = "<a"; // $NON-NLS-1$
    Map ht = getAttributes();
    for (Iterator e = ht.keySet().iterator(); e.hasNext(); ) {
      Object k = e.next();
      html +=
          " " + k + "=" + "\"" + ht.get(k)
              + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    }

    html += ">" + getLinkText() + "</a>"; // $NON-NLS-1$ //$NON-NLS-2$

    return html;
  }
}