• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ

よく使われているワード(クリックで追加)

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

テキストの各行をキーと値に分離し、複数テキストファイルを読み込み、キーを突き合わせ照合し、その結果を表示するGUIユーテリティです。


コミットメタ情報

リビジョン56a1f7d5b6b43d1736a44c3343206d03143197ee (tree)
日時2011-10-18 03:04:51
作者seraphy <seraphy@192....>
コミッターseraphy

ログメッセージ

・テーブルの偶数行の背景色対応

変更サマリ

差分

--- a/nbproject/project.properties
+++ b/nbproject/project.properties
@@ -82,7 +82,7 @@ run.classpath=\
8282 # Space-separated list of JVM arguments used when running the project
8383 # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
8484 # or test-sys-prop.name=value to set system properties for unit tests):
85-run.jvmargs=
85+run.jvmargs=-ea
8686 run.test.classpath=\
8787 ${javac.test.classpath}:\
8888 ${build.test.classes.dir}
--- a/src/textkeymatcher/entity/KeyMatchedRowView.java
+++ b/src/textkeymatcher/entity/KeyMatchedRowView.java
@@ -42,11 +42,17 @@ public class KeyMatchedRowView extends AbstractTableModel {
4242 */
4343 private final int rowNumber;
4444
45+ /**
46+ * キーごとの連番
47+ */
48+ private final int rowGroupSerialNo;
49+
4550
46- public RowNumMap(RowKey rowKey, RowValues rowValues, int rowNumber) {
51+ public RowNumMap(RowKey rowKey, RowValues rowValues, int rowNumber, int rowGroupSerialNo) {
4752 this.rowKey = rowKey;
4853 this.rowValues = rowValues;
4954 this.rowNumber = rowNumber;
55+ this.rowGroupSerialNo = rowGroupSerialNo;
5056 }
5157
5258 public RowKey getRowKey() {
@@ -60,6 +66,10 @@ public class KeyMatchedRowView extends AbstractTableModel {
6066 public int getRowNumber() {
6167 return rowNumber;
6268 }
69+
70+ public int getRowGroupSerialNo() {
71+ return rowGroupSerialNo;
72+ }
6373 }
6474
6575
@@ -113,6 +123,19 @@ public class KeyMatchedRowView extends AbstractTableModel {
113123 }
114124
115125 /**
126+ * 指定した行のキーごとの連番を取得する.
127+ * @param rowIndex 行
128+ * @return キーごとの連番、範囲外の場合は-1
129+ */
130+ public int getRowGroupSerialNo(int rowIndex) {
131+ if (rowIndex < 0 || rowIndex >= rowNumMaps.size()) {
132+ return -1;
133+ }
134+ RowNumMap rowNumMap = rowNumMaps.get(rowIndex);
135+ return rowNumMap.getRowGroupSerialNo();
136+ }
137+
138+ /**
116139 * 第一列をキー、それ以降をデータ列として1つのテーブルのカラムとしてアクセスする.<br>
117140 * @param rowIndex 行
118141 * @param columnIndex 列、0はキー、それ以降はデータ列
@@ -161,6 +184,7 @@ public class KeyMatchedRowView extends AbstractTableModel {
161184
162185 int numOfMaxColumns = 0;
163186 ArrayList<RowNumMap> rows = new ArrayList<RowNumMap>();
187+ int rowGroupSerialNo = 0;
164188 for (Map.Entry<RowKey, RowValues> entry : dataMap.entrySet()) {
165189 RowKey rowKey = entry.getKey();
166190 RowValues rowValues = entry.getValue();
@@ -177,8 +201,11 @@ public class KeyMatchedRowView extends AbstractTableModel {
177201
178202 // 行数分だけ同じキーを繰り返す.
179203 for (int rowNumber = 0; rowNumber < numOfRows; rowNumber++) {
180- rows.add(new RowNumMap(rowKey, rowValues, rowNumber));
204+ rows.add(new RowNumMap(rowKey, rowValues, rowNumber, rowGroupSerialNo));
181205 }
206+
207+ // キーごとのシリアル番号をインクリメント
208+ rowGroupSerialNo++;
182209 }
183210
184211 this.rowNumMaps = rows;
--- a/src/textkeymatcher/ui/TextKeyMatcherView.form
+++ b/src/textkeymatcher/ui/TextKeyMatcherView.form
@@ -27,14 +27,14 @@
2727
2828 <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
2929 <SubComponents>
30- <Component class="javax.swing.JTable" name="dateViewTable">
30+ <Component class="javax.swing.JTable" name="dataViewTable">
3131 <Properties>
3232 <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
3333 <Connection component="dataViewTableModel" type="bean"/>
3434 </Property>
3535 <Property name="autoResizeMode" type="int" value="0"/>
36- <Property name="gridColor" type="java.awt.Color" resourceKey="dateViewTable.gridColor"/>
37- <Property name="name" type="java.lang.String" value="dateViewTable" noResource="true"/>
36+ <Property name="gridColor" type="java.awt.Color" resourceKey="dataViewTable.gridColor"/>
37+ <Property name="name" type="java.lang.String" value="dataViewTable" noResource="true"/>
3838 <Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor">
3939 <TableHeader reorderingAllowed="true" resizingAllowed="true"/>
4040 </Property>
--- a/src/textkeymatcher/ui/TextKeyMatcherView.java
+++ b/src/textkeymatcher/ui/TextKeyMatcherView.java
@@ -6,6 +6,8 @@ package textkeymatcher.ui;
66
77 import com.apple.eawt.AboutHandler;
88 import com.apple.eawt.AppEvent.AboutEvent;
9+import java.awt.Color;
10+import java.awt.Component;
911 import org.apache.commons.lang3.StringUtils;
1012 import org.jdesktop.application.Task;
1113 import org.jdesktop.application.Action;
@@ -29,7 +31,9 @@ import javax.swing.JFileChooser;
2931 import javax.swing.JFrame;
3032 import javax.swing.JOptionPane;
3133 import javax.swing.JRootPane;
34+import javax.swing.JTable;
3235 import javax.swing.KeyStroke;
36+import javax.swing.table.DefaultTableCellRenderer;
3337 import org.jdesktop.application.Application;
3438 import textkeymatcher.TextKeyMatcherApp;
3539 import textkeymatcher.io.DocArchive;
@@ -50,6 +54,11 @@ public class TextKeyMatcherView extends FrameView {
5054 */
5155 private static final Logger logger = Logger.getLogger(TextKeyMatcherView.class.getName());
5256
57+ /**
58+ * テーブルの偶数行のカラー
59+ */
60+ private Color evenColor = new Color(240, 240, 255);
61+
5362
5463 public TextKeyMatcherView(SingleFrameApplication app) {
5564 super(app);
@@ -147,8 +156,59 @@ public class TextKeyMatcherView extends FrameView {
147156 }
148157 });
149158 }
159+
160+ // JTableのセルレンダー
161+ DefaultTableCellRenderer cellRender = new DefaultTableCellRenderer() {
162+
163+ @Override
164+ public Component getTableCellRendererComponent(JTable table, Object value,
165+ boolean isSelected, boolean hasFocus,
166+ int row, int column) {
167+ super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
168+
169+ if (isSelected) {
170+ setForeground(table.getSelectionForeground());
171+ setBackground(table.getSelectionBackground());
172+
173+ } else {
174+ setForeground(table.getForeground());
175+ int serialNo = dataViewTableModel.getRowGroupSerialNo(row);
176+ boolean even = (serialNo % 2 == 0);
177+ setBackground(even ? getEvenColor() : table.getBackground());
178+ }
179+
180+ setHorizontalAlignment((value instanceof Number) ? RIGHT : LEFT);
181+
182+ return this;
183+ }
184+ };
185+ dataViewTable.setDefaultRenderer(Object.class, cellRender);
150186 }
151187
188+ /**
189+ * テーブルの偶数行の背景色を設定する.
190+ * @param evenColor 背景色
191+ */
192+ public void setEvenColor(Color evenColor) {
193+ if (evenColor == null) {
194+ throw new IllegalArgumentException();
195+ }
196+ Color oldValue = this.evenColor;
197+ this.evenColor = evenColor;
198+ firePropertyChange("evenColor", oldValue, evenColor);
199+ }
200+
201+ /**
202+ * テーブルの偶数行の背景色を取得する.
203+ * @return 背景色
204+ */
205+ public Color getEvenColor() {
206+ return this.evenColor;
207+ }
208+
209+ /**
210+ * アプリケーション情報ダイアログを表示する.
211+ */
152212 @Action
153213 public void showAboutBox() {
154214 if (aboutBox == null) {
@@ -171,7 +231,7 @@ public class TextKeyMatcherView extends FrameView {
171231
172232 mainPanel = new javax.swing.JPanel();
173233 dataViewTableSP = new javax.swing.JScrollPane();
174- dateViewTable = new javax.swing.JTable();
234+ dataViewTable = new javax.swing.JTable();
175235 menuBar = new javax.swing.JMenuBar();
176236 javax.swing.JMenu fileMenu = new javax.swing.JMenu();
177237 newMenuItem = new javax.swing.JMenuItem();
@@ -209,12 +269,12 @@ public class TextKeyMatcherView extends FrameView {
209269
210270 dataViewTableSP.setName("dataViewTableSP"); // NOI18N
211271
212- dateViewTable.setModel(dataViewTableModel);
213- dateViewTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
272+ dataViewTable.setModel(dataViewTableModel);
273+ dataViewTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
214274 org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(textkeymatcher.TextKeyMatcherApp.class).getContext().getResourceMap(TextKeyMatcherView.class);
215- dateViewTable.setGridColor(resourceMap.getColor("dateViewTable.gridColor")); // NOI18N
216- dateViewTable.setName("dateViewTable"); // NOI18N
217- dataViewTableSP.setViewportView(dateViewTable);
275+ dataViewTable.setGridColor(resourceMap.getColor("dataViewTable.gridColor")); // NOI18N
276+ dataViewTable.setName("dataViewTable"); // NOI18N
277+ dataViewTableSP.setViewportView(dataViewTable);
218278
219279 javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
220280 mainPanel.setLayout(mainPanelLayout);
@@ -410,6 +470,10 @@ public class TextKeyMatcherView extends FrameView {
410470 bindingGroup.bind();
411471 }// </editor-fold>//GEN-END:initComponents
412472
473+ /**
474+ * インポート設定ダイアログのモデル.<br>
475+ * 再表示時に前回使用したモデルが再利用される.<br>
476+ */
413477 private ImportDataDialogModel importDataDialogModel;
414478
415479 /**
@@ -654,9 +718,9 @@ public class TextKeyMatcherView extends FrameView {
654718 // Variables declaration - do not modify//GEN-BEGIN:variables
655719 private javax.swing.JRadioButtonMenuItem allRadioButtonMenuItem;
656720 private javax.swing.JMenu dataMenu;
721+ private javax.swing.JTable dataViewTable;
657722 private textkeymatcher.ui.model.DataViewTableModel dataViewTableModel;
658723 private javax.swing.JScrollPane dataViewTableSP;
659- private javax.swing.JTable dateViewTable;
660724 private javax.swing.JRadioButtonMenuItem existsLeftRadioButtonMenuItem;
661725 private javax.swing.JMenu helpMenu;
662726 private javax.swing.JPopupMenu.Separator jSeparator1;
--- a/src/textkeymatcher/ui/resources/TextKeyMatcherView.properties
+++ b/src/textkeymatcher/ui/resources/TextKeyMatcherView.properties
@@ -52,8 +52,6 @@ onImportData.BlockingDialog.optionPane.message=wait a moment
5252 onImportData.Action.accelerator=shortcut I
5353 onImportData.Action.shortDescription=import data
5454 onImportData.Action.text=
55-#NOI18N
56-dateViewTable.gridColor=153, 153, 153
5755 onSave.Action.text=
5856 onSave.Action.shortDescription=
5957 onLoad.Action.text=
@@ -66,3 +64,4 @@ onNew.Action.accelerator=shortcut N
6664 onLoad.Action.accelerator=shortcut O
6765 onSave.Action.accelerator=shortcut S
6866 aboutMenuItem.text=\u30d0\u30fc\u30b8\u30e7\u30f3\u60c5\u5831...(A)
67+dataViewTable.gridColor=153, 153, 153
--- a/src/textkeymatcher/ui/resources/TextKeyMatcherView_ja_JP.properties
+++ b/src/textkeymatcher/ui/resources/TextKeyMatcherView_ja_JP.properties
@@ -23,7 +23,6 @@ onImportData.BlockingDialog.title=\u30ed\u30fc\u30c9\u4e2d
2323 onImportData.BlockingDialog.optionPane.message=\u3057\u3070\u3089\u304f\u304a\u5f85\u3061\u304f\u3060\u3055\u3044
2424 onImportData.Action.accelerator=shortcut I
2525 onImportData.Action.shortDescription=\u30a4\u30f3\u30dd\u30fc\u30c8
26-dateViewTable.gridColor=153, 153, 153
2726 showAboutBox.Action.text=\u30d0\u30fc\u30b8\u30e7\u30f3\u60c5\u5831(&A)...
2827 showAboutBox.Action.shortDescription=\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u60c5\u5831\u3092\u958b\u304f
2928 StatusBar.messageTimeout=5000
@@ -56,3 +55,4 @@ onNew.Action.accelerator=shortcut N
5655 onLoad.Action.accelerator=shortcut O
5756 onSave.Action.accelerator=shortcut S
5857 aboutMenuItem.text=\u30d0\u30fc\u30b8\u30e7\u30f3\u60c5\u5831...(A)
58+dataViewTable.gridColor=153, 153, 153
--- a/src/textkeymatcher/ui/resources/TextKeyMatcherView_ja_JP_MAC.properties
+++ b/src/textkeymatcher/ui/resources/TextKeyMatcherView_ja_JP_MAC.properties
@@ -52,8 +52,6 @@ onImportData.BlockingDialog.optionPane.message=\u3057\u3070\u3089\u304f\u304a\u5
5252 onImportData.Action.accelerator=shortcut I
5353 onImportData.Action.shortDescription=\u30a4\u30f3\u30dd\u30fc\u30c8
5454 onImportData.Action.text=
55-#NOI18N
56-dateViewTable.gridColor=153, 153, 153
5755 onSave.Action.text=
5856 onSave.Action.shortDescription=
5957 onLoad.Action.text=