1 package twitter.gui.component;
4 import java.awt.Component;
5 import java.awt.Desktop;
7 import java.awt.event.MouseEvent;
8 import java.awt.event.MouseListener;
9 import java.awt.event.MouseMotionListener;
12 import javax.swing.BorderFactory;
13 import javax.swing.JEditorPane;
14 import javax.swing.JTable;
15 import javax.swing.table.TableCellRenderer;
16 import javax.swing.text.Style;
17 import javax.swing.text.StyleConstants;
18 import javax.swing.text.html.HTMLDocument;
19 import javax.swing.text.html.StyleSheet;
20 import twitter.gui.action.TweetMainAction;
27 public class TweetCommentRenderer extends JEditorPane implements
28 TableCellRenderer, MouseListener, MouseMotionListener {
33 private int newTableRow = -1;
35 private TweetMainAction mainAction = null;
40 public TweetCommentRenderer(TweetMainAction mainAction) {
42 this.mainAction = mainAction;
44 setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
45 // HTMLコードをそのまま表示できるようにする
46 super.setEditable(false);
47 this.setContentType("text/html");
51 public Component getTableCellRendererComponent(JTable table, Object value,
52 boolean isSelected, boolean hasFocus, int row, int column) {
54 * if (isSelected) { setForeground(table.getSelectionForeground());
55 * setBackground(table.getSelectionBackground()); } else {
56 * setForeground(table.getForeground());
57 * setBackground(table.getBackground()); }
62 //TODO: ここも後で色を変更できるようにする
64 setBackground(new Color(240,240,255));
66 setBackground(Color.white);
69 // TODO: あとでここのカラーを変える
72 if (this.newTableRow >= 0 && row < this.newTableRow) {
73 setBackground(this.mainAction.getNewTableColor());
75 setBackground(Color.white);
80 setFont(table.getFont());
83 HTMLDocument doc = (HTMLDocument) getDocument();
84 StyleSheet[] style = doc.getStyleSheet().getStyleSheets();
85 for (int i = style.length - 1; i >= 0; i--) {
86 Style body = style[i].getStyle("body");
88 StyleConstants.setFontFamily(body, table.getFont()
90 StyleConstants.setFontSize(body, table.getFont().getSize());
93 } catch (Exception e) {
97 setText((value == null) ? "" : value.toString());
99 if (!table.isEditing() && this.row == row && this.col == column) {
100 setText("<html><u><font color='blue'>" + value.toString());
101 } else if (hasFocus) {
102 setText("<html><font color='blue'>" + value.toString());
104 setText(value.toString());
110 * 何行目までのセルを新しいセルとしてnewTableColorで塗りつぶすか
113 * 0以上の値で新しいセルとして指定した行を塗りつぶす
115 public void updateNewCellRow(int row) {
116 this.newTableRow = row;
120 * マウスがある位置のセルをrepaint
122 public void mouseMoved(MouseEvent e) {
123 //この部分は処理が重いのでカットすることとした
124 /*JTable table = (JTable) e.getSource();
125 Point pt = e.getPoint();
126 row = table.rowAtPoint(pt);
127 col = table.columnAtPoint(pt);
128 if (row < 0 || col < 0) {
138 public void mouseExited(MouseEvent e) {
139 JTable table = (JTable) e.getSource();
148 public void mouseClicked(MouseEvent e) {
149 JTable table = (JTable) e.getSource();
150 Point pt = e.getPoint();
151 int crow = table.rowAtPoint(pt);
152 int ccol = table.columnAtPoint(pt);
153 // if(table.convertColumnIndexToModel(ccol) == 2)
154 if (table.getColumnClass(ccol).equals(URL.class)) {
155 URL url = (URL) table.getValueAt(crow, ccol);
156 System.out.println(url);
159 Desktop.getDesktop().browse(url.toURI());
160 } catch (Exception ex) {
161 ex.printStackTrace();
166 public void mouseDragged(MouseEvent e) {
169 public void mouseEntered(MouseEvent e) {
172 public void mousePressed(MouseEvent e) {
176 public void mouseReleased(MouseEvent e) {