OSDN Git Service

リファクタリング tags/release_20090111@27 tags/release_20090524@27
authoryuki <yuki@bdf3b611-c98c-6041-8292-703d9c9adbe7>
Sat, 23 Feb 2008 09:49:03 +0000 (09:49 +0000)
committeryuki <yuki@bdf3b611-c98c-6041-8292-703d9c9adbe7>
Sat, 23 Feb 2008 09:49:03 +0000 (09:49 +0000)
git-svn-id: http://192.168.11.7/svn/repository/NicoBrowser@25 bdf3b611-c98c-6041-8292-703d9c9adbe7

src/nicobrowser/MainWindow.java

index 477566d..b4c41fe 100644 (file)
@@ -9,12 +9,12 @@ package nicobrowser;
 import java.awt.Component;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Vector;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import javax.swing.ImageIcon;
-import javax.swing.ImageIcon;
 import javax.swing.JButton;
 import javax.swing.JTable;
 import javax.swing.JTextArea;
@@ -30,6 +30,28 @@ import javax.swing.table.TableColumn;
  */
 public class MainWindow extends javax.swing.JFrame {
 
+    private void setContents(List<NicoContent> contList) {
+        int rowHeight = -1;
+        for (NicoContent cont : contList) {
+            Vector<Object> v = new Vector<Object>();
+            ImageIcon icon = new ImageIcon();
+            try {
+                icon = new ImageIcon(new URL(cont.getImageLink()));
+                if (rowHeight < 0) {
+                    rowHeight = icon.getIconHeight();
+                    jTable1.setRowHeight(rowHeight);
+                }
+            } catch (MalformedURLException ex) {
+                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, "画像未取得" + cont.getTitle());
+            }
+            v.add(icon);
+            v.add(cont.getTitle());
+            v.add(cont.getDescription());
+            v.add(cont.getPageLink());
+            tableModel.addRow(v);
+        }
+    }
+
     private class MyTableModel extends DefaultTableModel {
 
         private MyTableModel(String[] COLUMN_NAMES, int i) {
@@ -317,25 +339,7 @@ public class MainWindow extends javax.swing.JFrame {
             return;
         }
         List<NicoContent> contList = NicoHttpClient.getInstance().loadMyList(no);
-        int rowHeight = -1;
-        for (NicoContent cont : contList) {
-            Vector<Object> v = new Vector<Object>();
-            ImageIcon icon = new ImageIcon();
-            try {
-                icon = new ImageIcon(new URL(cont.getImageLink()));
-                if (rowHeight < 0) {
-                    rowHeight = icon.getIconHeight();
-                }
-            } catch (MalformedURLException ex) {
-                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
-            }
-            v.add(icon);
-            v.add(cont.getTitle());
-            v.add(cont.getDescription());
-            v.add(cont.getPageLink());
-            tableModel.addRow(v);
-        }
-        jTable1.setRowHeight(rowHeight);
+        setContents(contList);
 }//GEN-LAST:event_listLoadButtonActionPerformed
 
     private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginButtonActionPerformed
@@ -361,47 +365,14 @@ public class MainWindow extends javax.swing.JFrame {
             return;
         }
         NicoContent cont = NicoHttpClient.getInstance().loadMyMovie(no);
-        int rowHeight = -1;
-        Vector<Object> v = new Vector<Object>();
-        ImageIcon icon = new ImageIcon();
-        try {
-            icon = new ImageIcon(new URL(cont.getImageLink()));
-            if (rowHeight < 0) {
-                rowHeight = icon.getIconHeight();
-            }
-        } catch (MalformedURLException ex) {
-            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
-        }
-        v.add(icon);
-        v.add(cont.getTitle());
-        v.add(cont.getDescription());
-        v.add(cont.getPageLink());
-        tableModel.addRow(v);
-        jTable1.setRowHeight(rowHeight);
-
+        List<NicoContent> list = new ArrayList<NicoContent>();
+        list.add(cont);
+        setContents(list);
 }//GEN-LAST:event_unitLoadButtonActionPerformed
 
     private void loadDailyListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadDailyListButtonActionPerformed
         List<NicoContent> contList = NicoHttpClient.getInstance().loadMyListDaily();
-        int rowHeight = -1;
-        for (NicoContent cont : contList) {
-            Vector<Object> v = new Vector<Object>();
-            ImageIcon icon = new ImageIcon();
-            try {
-                icon = new ImageIcon(new URL(cont.getImageLink()));
-                if (rowHeight < 0) {
-                    rowHeight = icon.getIconHeight();
-                }
-            } catch (MalformedURLException ex) {
-                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
-            }
-            v.add(icon);
-            v.add(cont.getTitle());
-            v.add(cont.getDescription());
-            v.add(cont.getPageLink());
-            tableModel.addRow(v);
-        }
-        jTable1.setRowHeight(rowHeight);
+        setContents(contList);
 
 }//GEN-LAST:event_loadDailyListButtonActionPerformed