• R/O
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

作業部屋の使い方を試しています。


Commit MetaInfo

Revision100 (tree)
Time2014-11-27 19:37:08
Authortuna_p

Log Message

(empty log message)

Change Summary

Incremental Difference

--- branches/b1-swing/src/package01/TestTable01.java (revision 99)
+++ branches/b1-swing/src/package01/TestTable01.java (revision 100)
@@ -17,7 +17,7 @@
1717 */
1818 public class TestTable01 extends javax.swing.JFrame {
1919
20- TestTableCellRenderer renderer;
20+ TestTableCellRenderer tblRenderer;
2121 /**
2222 * Creates new form TestTable01
2323 */
@@ -24,8 +24,8 @@
2424 public TestTable01() {
2525 initComponents();
2626
27- renderer = new TestTableCellRenderer();
28- jTable1.setDefaultRenderer(Object.class, renderer);
27+ tblRenderer = new TestTableCellRenderer();
28+ jTable1.setDefaultRenderer(Object.class, tblRenderer);
2929
3030 }
3131
@@ -115,9 +115,11 @@
115115 }// </editor-fold>//GEN-END:initComponents
116116
117117 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
118- renderer.addRowColumn(1, 1);
119- renderer.addRowColumn(2, 0);
120- renderer.addRowColumn(2, 2);
118+ tblRenderer.setBackgroundColor(1, 1, Color.RED);
119+ tblRenderer.setBackgroundColor(2, 0, Color.GREEN); // 重複
120+ tblRenderer.setBackgroundColor(2, 0, Color.CYAN);
121+ tblRenderer.setBackgroundColor(2, 2, Color.BLUE);
122+ tblRenderer.setBackgroundColor(3, 3, Color.YELLOW);
121123 jTable1.repaint();
122124 }//GEN-LAST:event_jButton1ActionPerformed
123125
@@ -168,9 +170,11 @@
168170 }
169171
170172 class TestTableCellRenderer extends DefaultTableCellRenderer {
173+ ArrayList<CellAttribute> arrayCellAttribute = new ArrayList<>();
174+ // ワーク変数
175+ CellAttribute currentCellAttr;
176+ Color backgroundColor;
171177
172- ArrayList<RowColumn> arrayRowColumn = new ArrayList<>();
173-
174178 TestTableCellRenderer() {
175179 super();
176180 }
@@ -181,7 +185,7 @@
181185
182186 Color color = table.getBackground();
183187 if(chkRowColumn(row, column)) {
184- color = Color.red;
188+ color = backgroundColor;
185189 }
186190 c.setBackground(color);
187191
@@ -188,23 +192,32 @@
188192 return c;
189193 }
190194
191- void addRowColumn(int row, int column) {
192- RowColumn inRowColumn = new RowColumn();
193- inRowColumn.row = row;
194- inRowColumn.column = column;
195-
196- arrayRowColumn.add(inRowColumn);
195+ /**
196+ * セルの背景色を設定.
197+ * @param row 指定するセルの行
198+ * @param column 指定するセルの列
199+ * @param color 指定するセルの背景色
200+ */
201+ public void setBackgroundColor(int row, int column, Color color) {
202+ // 重複時削除
203+ if(chkRowColumn(row, column)) {
204+ arrayCellAttribute.remove(currentCellAttr);
205+ }
206+ // 属性設定
207+ CellAttribute cellattr = new CellAttribute();
208+ cellattr.row = row;
209+ cellattr.column = column;
210+ cellattr.backgroundColor = color;
211+ // 登録
212+ arrayCellAttribute.add(cellattr);
197213 }
198214
199- boolean chkRowColumn(int row, int column) {
215+ private boolean chkRowColumn(int row, int column) {
200216 boolean ans = false;
201-
202- RowColumn inRowColumn = new RowColumn();
203- inRowColumn.row = row;
204- inRowColumn.column = column;
205-
206- for (RowColumn rowcolumn : arrayRowColumn) {
207- if((rowcolumn.row == inRowColumn.row) && (rowcolumn.column == inRowColumn.column)) {
217+ for (CellAttribute cellattr : arrayCellAttribute) {
218+ if((cellattr.row == row) && (cellattr.column == column)) {
219+ currentCellAttr = cellattr;
220+ backgroundColor = cellattr.backgroundColor;
208221 ans = true;
209222 break;
210223 }
@@ -211,11 +224,13 @@
211224 }
212225 return ans;
213226 }
214-
215- class RowColumn {
216- int row;
217- int column;
227+ /**
228+ * セル属性.
229+ */
230+ class CellAttribute {
231+ int row;
232+ int column;
233+ Color backgroundColor;
218234 }
219-
220235 }
221236