作業部屋の使い方を試しています。
[作業途中]クラスSearchData内で複数データ保持するように変更
| @@ -22,12 +22,16 @@ | ||
| 22 | 22 | |
| 23 | 23 | package webScraping.core; |
| 24 | 24 | |
| 25 | +import java.util.ArrayList; | |
| 26 | + | |
| 25 | 27 | /** |
| 26 | - * 検索データ. | |
| 28 | + * タグ検索データ. | |
| 27 | 29 | * @author kgto |
| 28 | 30 | */ |
| 29 | 31 | public class SearchData { |
| 30 | - | |
| 32 | + /* ---------------------------------------------------------------------- * | |
| 33 | + * フィールド | |
| 34 | + * ---------------------------------------------------------------------- */ | |
| 31 | 35 | private String item; |
| 32 | 36 | private String htmltag; |
| 33 | 37 | private String htmlid; |
| @@ -35,6 +39,83 @@ | ||
| 35 | 39 | private String around; |
| 36 | 40 | private String regexp; |
| 37 | 41 | |
| 42 | + /* ---------------------------------------------------------------------- * | |
| 43 | + * static 処理 | |
| 44 | + * ---------------------------------------------------------------------- */ | |
| 45 | + /** | |
| 46 | + * データ属性 情報. | |
| 47 | + */ | |
| 48 | + public static String[] columnName = { | |
| 49 | + /* 0 */ "項目名", | |
| 50 | + /* 1 */ "タグ", | |
| 51 | + /* 2 */ "ID", | |
| 52 | + /* 3 */ "クラス", | |
| 53 | + /* 4 */ "位置", | |
| 54 | + /* 5 */ "抽出条件" | |
| 55 | + }; | |
| 56 | + | |
| 57 | + public static Class[] columnClass = { | |
| 58 | + /* 0 */ String.class, | |
| 59 | + /* 1 */ String.class, | |
| 60 | + /* 2 */ String.class, | |
| 61 | + /* 3 */ String.class, | |
| 62 | + /* 4 */ String.class, | |
| 63 | + /* 5 */ String.class | |
| 64 | + }; | |
| 65 | + | |
| 66 | + /* ---------------------------------------------------------------------- */ | |
| 67 | + private static ArrayList<SearchData> slist = new ArrayList<>(); | |
| 68 | + | |
| 69 | + public static void addSearchData( | |
| 70 | + String item, String htmltag, String htmlid, | |
| 71 | + String htmlclass, String around, String regexp) { | |
| 72 | + SearchData sdat = new SearchData(); | |
| 73 | + sdat.setitem(item); | |
| 74 | + sdat.setHtmltag(htmltag); | |
| 75 | + sdat.setHtmlid(htmlid); | |
| 76 | + sdat.setHtmlclass(htmlclass); | |
| 77 | + sdat.setaround(around); | |
| 78 | + sdat.setregexp(regexp); | |
| 79 | + | |
| 80 | + slist.add(sdat); | |
| 81 | + } | |
| 82 | + | |
| 83 | + public static void add(SearchData sdat) { | |
| 84 | + slist.add(sdat); | |
| 85 | + } | |
| 86 | + | |
| 87 | + public static SearchData get(int i) { | |
| 88 | + return slist.get(i); | |
| 89 | + } | |
| 90 | + | |
| 91 | + public static Object[] getObjData(int i) { | |
| 92 | + SearchData sdat = get(i); | |
| 93 | + Object[] obj = new Object[] { | |
| 94 | + sdat.getitem(), | |
| 95 | + sdat.getHtmltag(), | |
| 96 | + sdat.getHtmlid(), | |
| 97 | + sdat.getHtmlclass(), | |
| 98 | + sdat.getaround(), | |
| 99 | + sdat.getregexp() | |
| 100 | + }; | |
| 101 | + return obj; | |
| 102 | + } | |
| 103 | + | |
| 104 | + public static int size() { | |
| 105 | + return slist.size(); | |
| 106 | + } | |
| 107 | + | |
| 108 | + public static SearchData remove(int index) { | |
| 109 | + return slist.remove(index); | |
| 110 | + } | |
| 111 | + | |
| 112 | + public static void clear() { | |
| 113 | + slist.clear(); | |
| 114 | + } | |
| 115 | + | |
| 116 | + /* ---------------------------------------------------------------------- * | |
| 117 | + * コンストラクタ | |
| 118 | + * ---------------------------------------------------------------------- */ | |
| 38 | 119 | public SearchData() { |
| 39 | 120 | initialize(); |
| 40 | 121 | } |
| @@ -48,19 +129,9 @@ | ||
| 48 | 129 | this.regexp = dat.getregexp(); |
| 49 | 130 | } |
| 50 | 131 | |
| 51 | - /** | |
| 52 | - * データ初期化. | |
| 53 | - */ | |
| 54 | - public final void initialize() { | |
| 55 | - this.item = ""; | |
| 56 | - this.htmltag = ""; | |
| 57 | - this.htmlid = ""; | |
| 58 | - this.htmlclass = ""; | |
| 59 | - this.around = ""; | |
| 60 | - this.regexp = ""; | |
| 61 | - } | |
| 62 | - | |
| 63 | - // Setter | |
| 132 | + /* ---------------------------------------------------------------------- * | |
| 133 | + * Setter | |
| 134 | + * ---------------------------------------------------------------------- */ | |
| 64 | 135 | public void setitem(String item) { |
| 65 | 136 | this.item = item; |
| 66 | 137 | } |
| @@ -85,7 +156,9 @@ | ||
| 85 | 156 | this.regexp = regexp; |
| 86 | 157 | } |
| 87 | 158 | |
| 88 | - // Getter | |
| 159 | + /* ---------------------------------------------------------------------- * | |
| 160 | + * Getter | |
| 161 | + * ---------------------------------------------------------------------- */ | |
| 89 | 162 | public String getitem() { |
| 90 | 163 | return item; |
| 91 | 164 | } |
| @@ -110,4 +183,19 @@ | ||
| 110 | 183 | return regexp; |
| 111 | 184 | } |
| 112 | 185 | |
| 186 | + /* ---------------------------------------------------------------------- * | |
| 187 | + * メソッド | |
| 188 | + * ---------------------------------------------------------------------- */ | |
| 189 | + /** | |
| 190 | + * データ初期化. | |
| 191 | + */ | |
| 192 | + public final void initialize() { | |
| 193 | + this.item = ""; | |
| 194 | + this.htmltag = ""; | |
| 195 | + this.htmlid = ""; | |
| 196 | + this.htmlclass = ""; | |
| 197 | + this.around = ""; | |
| 198 | + this.regexp = ""; | |
| 199 | + } | |
| 200 | + | |
| 113 | 201 | } |
| @@ -352,7 +352,7 @@ | ||
| 352 | 352 | return urladdress; |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - ArrayList<SearchData> loadSearchList() { | |
| 355 | + public ArrayList<SearchData> loadSearchList() { | |
| 356 | 356 | ArrayList<SearchData> sdatlst = new ArrayList<>(); |
| 357 | 357 | |
| 358 | 358 | NodeList nodelist = root.getElementsByTagName("searchlist"); |
| @@ -410,7 +410,7 @@ | ||
| 410 | 410 | return sdatlst; |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | - String loadMsg404() { | |
| 413 | + public String loadMsg404() { | |
| 414 | 414 | StringBuilder strbuf = new StringBuilder(); |
| 415 | 415 | NodeList nodelist = root.getElementsByTagName("msg404"); |
| 416 | 416 | for(int i = 0; i < nodelist.getLength(); i++) { |
| @@ -34,6 +34,7 @@ | ||
| 34 | 34 | import javax.swing.JFileChooser; |
| 35 | 35 | import javax.swing.filechooser.FileFilter; |
| 36 | 36 | import javax.swing.filechooser.FileNameExtensionFilter; |
| 37 | +import javax.swing.table.DefaultTableModel; | |
| 37 | 38 | import org.jdesktop.observablecollections.ObservableCollections; |
| 38 | 39 | |
| 39 | 40 | /** |
| @@ -46,10 +47,14 @@ | ||
| 46 | 47 | private ArrayList slist = new ArrayList(); |
| 47 | 48 | private List serachDataList = ObservableCollections.observableList(slist); |
| 48 | 49 | |
| 50 | + SearchDataTableModel model; | |
| 51 | + | |
| 49 | 52 | /** |
| 50 | 53 | * Creates new form Frame1 |
| 51 | 54 | */ |
| 52 | 55 | public HtmlSearch() { |
| 56 | + model = new SearchDataTableModel(); | |
| 57 | + | |
| 53 | 58 | initComponents(); |
| 54 | 59 | |
| 55 | 60 | // カレントディレクトリ取得 |
| @@ -445,6 +450,13 @@ | ||
| 445 | 450 | jTxtRtn.setCaretPosition(0); |
| 446 | 451 | } |
| 447 | 452 | |
| 453 | + private void list2model() { | |
| 454 | + model.setRowCount(0); | |
| 455 | + for(int i = 0; i < SearchData.size(); i++) { | |
| 456 | + model.addRow(SearchData.getObjData(i)); | |
| 457 | + } | |
| 458 | + } | |
| 459 | + | |
| 448 | 460 | /** |
| 449 | 461 | * @param args the command line arguments |
| 450 | 462 | */ |
| @@ -509,3 +521,22 @@ | ||
| 509 | 521 | private org.jdesktop.beansbinding.BindingGroup bindingGroup; |
| 510 | 522 | // End of variables declaration//GEN-END:variables |
| 511 | 523 | } |
| 524 | + | |
| 525 | +class SearchDataTableModel extends DefaultTableModel { | |
| 526 | + | |
| 527 | + @Override | |
| 528 | + public String getColumnName(int modelIndex) { | |
| 529 | + return SearchData.columnName[modelIndex]; | |
| 530 | + } | |
| 531 | + | |
| 532 | + @Override | |
| 533 | + public Class<?> getColumnClass(int modelIndex) { | |
| 534 | + return SearchData.columnClass[modelIndex]; | |
| 535 | + } | |
| 536 | + | |
| 537 | + @Override | |
| 538 | + public int getColumnCount() { | |
| 539 | + return SearchData.columnName.length; | |
| 540 | + } | |
| 541 | + | |
| 542 | +} | |
| \ No newline at end of file |