テキストの各行をキーと値に分離し、複数テキストファイルを読み込み、キーを突き合わせ照合し、その結果を表示するGUIユーテリティです。
リビジョン | 56a1f7d5b6b43d1736a44c3343206d03143197ee (tree) |
---|---|
日時 | 2011-10-18 03:04:51 |
作者 | seraphy <seraphy@192....> |
コミッター | seraphy |
・テーブルの偶数行の背景色対応
@@ -82,7 +82,7 @@ run.classpath=\ | ||
82 | 82 | # Space-separated list of JVM arguments used when running the project |
83 | 83 | # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value |
84 | 84 | # or test-sys-prop.name=value to set system properties for unit tests): |
85 | -run.jvmargs= | |
85 | +run.jvmargs=-ea | |
86 | 86 | run.test.classpath=\ |
87 | 87 | ${javac.test.classpath}:\ |
88 | 88 | ${build.test.classes.dir} |
@@ -42,11 +42,17 @@ public class KeyMatchedRowView extends AbstractTableModel { | ||
42 | 42 | */ |
43 | 43 | private final int rowNumber; |
44 | 44 | |
45 | + /** | |
46 | + * キーごとの連番 | |
47 | + */ | |
48 | + private final int rowGroupSerialNo; | |
49 | + | |
45 | 50 | |
46 | - public RowNumMap(RowKey rowKey, RowValues rowValues, int rowNumber) { | |
51 | + public RowNumMap(RowKey rowKey, RowValues rowValues, int rowNumber, int rowGroupSerialNo) { | |
47 | 52 | this.rowKey = rowKey; |
48 | 53 | this.rowValues = rowValues; |
49 | 54 | this.rowNumber = rowNumber; |
55 | + this.rowGroupSerialNo = rowGroupSerialNo; | |
50 | 56 | } |
51 | 57 | |
52 | 58 | public RowKey getRowKey() { |
@@ -60,6 +66,10 @@ public class KeyMatchedRowView extends AbstractTableModel { | ||
60 | 66 | public int getRowNumber() { |
61 | 67 | return rowNumber; |
62 | 68 | } |
69 | + | |
70 | + public int getRowGroupSerialNo() { | |
71 | + return rowGroupSerialNo; | |
72 | + } | |
63 | 73 | } |
64 | 74 | |
65 | 75 |
@@ -113,6 +123,19 @@ public class KeyMatchedRowView extends AbstractTableModel { | ||
113 | 123 | } |
114 | 124 | |
115 | 125 | /** |
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 | + /** | |
116 | 139 | * 第一列をキー、それ以降をデータ列として1つのテーブルのカラムとしてアクセスする.<br> |
117 | 140 | * @param rowIndex 行 |
118 | 141 | * @param columnIndex 列、0はキー、それ以降はデータ列 |
@@ -161,6 +184,7 @@ public class KeyMatchedRowView extends AbstractTableModel { | ||
161 | 184 | |
162 | 185 | int numOfMaxColumns = 0; |
163 | 186 | ArrayList<RowNumMap> rows = new ArrayList<RowNumMap>(); |
187 | + int rowGroupSerialNo = 0; | |
164 | 188 | for (Map.Entry<RowKey, RowValues> entry : dataMap.entrySet()) { |
165 | 189 | RowKey rowKey = entry.getKey(); |
166 | 190 | RowValues rowValues = entry.getValue(); |
@@ -177,8 +201,11 @@ public class KeyMatchedRowView extends AbstractTableModel { | ||
177 | 201 | |
178 | 202 | // 行数分だけ同じキーを繰り返す. |
179 | 203 | for (int rowNumber = 0; rowNumber < numOfRows; rowNumber++) { |
180 | - rows.add(new RowNumMap(rowKey, rowValues, rowNumber)); | |
204 | + rows.add(new RowNumMap(rowKey, rowValues, rowNumber, rowGroupSerialNo)); | |
181 | 205 | } |
206 | + | |
207 | + // キーごとのシリアル番号をインクリメント | |
208 | + rowGroupSerialNo++; | |
182 | 209 | } |
183 | 210 | |
184 | 211 | this.rowNumMaps = rows; |
@@ -27,14 +27,14 @@ | ||
27 | 27 | |
28 | 28 | <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> |
29 | 29 | <SubComponents> |
30 | - <Component class="javax.swing.JTable" name="dateViewTable"> | |
30 | + <Component class="javax.swing.JTable" name="dataViewTable"> | |
31 | 31 | <Properties> |
32 | 32 | <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> |
33 | 33 | <Connection component="dataViewTableModel" type="bean"/> |
34 | 34 | </Property> |
35 | 35 | <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"/> | |
38 | 38 | <Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor"> |
39 | 39 | <TableHeader reorderingAllowed="true" resizingAllowed="true"/> |
40 | 40 | </Property> |
@@ -6,6 +6,8 @@ package textkeymatcher.ui; | ||
6 | 6 | |
7 | 7 | import com.apple.eawt.AboutHandler; |
8 | 8 | import com.apple.eawt.AppEvent.AboutEvent; |
9 | +import java.awt.Color; | |
10 | +import java.awt.Component; | |
9 | 11 | import org.apache.commons.lang3.StringUtils; |
10 | 12 | import org.jdesktop.application.Task; |
11 | 13 | import org.jdesktop.application.Action; |
@@ -29,7 +31,9 @@ import javax.swing.JFileChooser; | ||
29 | 31 | import javax.swing.JFrame; |
30 | 32 | import javax.swing.JOptionPane; |
31 | 33 | import javax.swing.JRootPane; |
34 | +import javax.swing.JTable; | |
32 | 35 | import javax.swing.KeyStroke; |
36 | +import javax.swing.table.DefaultTableCellRenderer; | |
33 | 37 | import org.jdesktop.application.Application; |
34 | 38 | import textkeymatcher.TextKeyMatcherApp; |
35 | 39 | import textkeymatcher.io.DocArchive; |
@@ -50,6 +54,11 @@ public class TextKeyMatcherView extends FrameView { | ||
50 | 54 | */ |
51 | 55 | private static final Logger logger = Logger.getLogger(TextKeyMatcherView.class.getName()); |
52 | 56 | |
57 | + /** | |
58 | + * テーブルの偶数行のカラー | |
59 | + */ | |
60 | + private Color evenColor = new Color(240, 240, 255); | |
61 | + | |
53 | 62 | |
54 | 63 | public TextKeyMatcherView(SingleFrameApplication app) { |
55 | 64 | super(app); |
@@ -147,8 +156,59 @@ public class TextKeyMatcherView extends FrameView { | ||
147 | 156 | } |
148 | 157 | }); |
149 | 158 | } |
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); | |
150 | 186 | } |
151 | 187 | |
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 | + */ | |
152 | 212 | @Action |
153 | 213 | public void showAboutBox() { |
154 | 214 | if (aboutBox == null) { |
@@ -171,7 +231,7 @@ public class TextKeyMatcherView extends FrameView { | ||
171 | 231 | |
172 | 232 | mainPanel = new javax.swing.JPanel(); |
173 | 233 | dataViewTableSP = new javax.swing.JScrollPane(); |
174 | - dateViewTable = new javax.swing.JTable(); | |
234 | + dataViewTable = new javax.swing.JTable(); | |
175 | 235 | menuBar = new javax.swing.JMenuBar(); |
176 | 236 | javax.swing.JMenu fileMenu = new javax.swing.JMenu(); |
177 | 237 | newMenuItem = new javax.swing.JMenuItem(); |
@@ -209,12 +269,12 @@ public class TextKeyMatcherView extends FrameView { | ||
209 | 269 | |
210 | 270 | dataViewTableSP.setName("dataViewTableSP"); // NOI18N |
211 | 271 | |
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); | |
214 | 274 | 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); | |
218 | 278 | |
219 | 279 | javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); |
220 | 280 | mainPanel.setLayout(mainPanelLayout); |
@@ -410,6 +470,10 @@ public class TextKeyMatcherView extends FrameView { | ||
410 | 470 | bindingGroup.bind(); |
411 | 471 | }// </editor-fold>//GEN-END:initComponents |
412 | 472 | |
473 | + /** | |
474 | + * インポート設定ダイアログのモデル.<br> | |
475 | + * 再表示時に前回使用したモデルが再利用される.<br> | |
476 | + */ | |
413 | 477 | private ImportDataDialogModel importDataDialogModel; |
414 | 478 | |
415 | 479 | /** |
@@ -654,9 +718,9 @@ public class TextKeyMatcherView extends FrameView { | ||
654 | 718 | // Variables declaration - do not modify//GEN-BEGIN:variables |
655 | 719 | private javax.swing.JRadioButtonMenuItem allRadioButtonMenuItem; |
656 | 720 | private javax.swing.JMenu dataMenu; |
721 | + private javax.swing.JTable dataViewTable; | |
657 | 722 | private textkeymatcher.ui.model.DataViewTableModel dataViewTableModel; |
658 | 723 | private javax.swing.JScrollPane dataViewTableSP; |
659 | - private javax.swing.JTable dateViewTable; | |
660 | 724 | private javax.swing.JRadioButtonMenuItem existsLeftRadioButtonMenuItem; |
661 | 725 | private javax.swing.JMenu helpMenu; |
662 | 726 | private javax.swing.JPopupMenu.Separator jSeparator1; |
@@ -52,8 +52,6 @@ onImportData.BlockingDialog.optionPane.message=wait a moment | ||
52 | 52 | onImportData.Action.accelerator=shortcut I |
53 | 53 | onImportData.Action.shortDescription=import data |
54 | 54 | onImportData.Action.text= |
55 | -#NOI18N | |
56 | -dateViewTable.gridColor=153, 153, 153 | |
57 | 55 | onSave.Action.text= |
58 | 56 | onSave.Action.shortDescription= |
59 | 57 | onLoad.Action.text= |
@@ -66,3 +64,4 @@ onNew.Action.accelerator=shortcut N | ||
66 | 64 | onLoad.Action.accelerator=shortcut O |
67 | 65 | onSave.Action.accelerator=shortcut S |
68 | 66 | aboutMenuItem.text=\u30d0\u30fc\u30b8\u30e7\u30f3\u60c5\u5831...(A) |
67 | +dataViewTable.gridColor=153, 153, 153 |
@@ -23,7 +23,6 @@ onImportData.BlockingDialog.title=\u30ed\u30fc\u30c9\u4e2d | ||
23 | 23 | onImportData.BlockingDialog.optionPane.message=\u3057\u3070\u3089\u304f\u304a\u5f85\u3061\u304f\u3060\u3055\u3044 |
24 | 24 | onImportData.Action.accelerator=shortcut I |
25 | 25 | onImportData.Action.shortDescription=\u30a4\u30f3\u30dd\u30fc\u30c8 |
26 | -dateViewTable.gridColor=153, 153, 153 | |
27 | 26 | showAboutBox.Action.text=\u30d0\u30fc\u30b8\u30e7\u30f3\u60c5\u5831(&A)... |
28 | 27 | showAboutBox.Action.shortDescription=\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u60c5\u5831\u3092\u958b\u304f |
29 | 28 | StatusBar.messageTimeout=5000 |
@@ -56,3 +55,4 @@ onNew.Action.accelerator=shortcut N | ||
56 | 55 | onLoad.Action.accelerator=shortcut O |
57 | 56 | onSave.Action.accelerator=shortcut S |
58 | 57 | aboutMenuItem.text=\u30d0\u30fc\u30b8\u30e7\u30f3\u60c5\u5831...(A) |
58 | +dataViewTable.gridColor=153, 153, 153 |
@@ -52,8 +52,6 @@ onImportData.BlockingDialog.optionPane.message=\u3057\u3070\u3089\u304f\u304a\u5 | ||
52 | 52 | onImportData.Action.accelerator=shortcut I |
53 | 53 | onImportData.Action.shortDescription=\u30a4\u30f3\u30dd\u30fc\u30c8 |
54 | 54 | onImportData.Action.text= |
55 | -#NOI18N | |
56 | -dateViewTable.gridColor=153, 153, 153 | |
57 | 55 | onSave.Action.text= |
58 | 56 | onSave.Action.shortDescription= |
59 | 57 | onLoad.Action.text= |