OSDN Git Service

進捗バーのレンダリング
authoryukihane <yukihane.feather@gmail.com>
Mon, 29 Aug 2011 09:49:38 +0000 (18:49 +0900)
committeryukihane <yukihane.feather@gmail.com>
Mon, 29 Aug 2011 09:49:38 +0000 (18:49 +0900)
frontend/src/saccubus/worker/impl/MessageReportable.java [new file with mode: 0644]
frontend/src/yukihane/inqubus/gui/MainFrame.java
frontend/src/yukihane/inqubus/model/Progress.java
frontend/src/yukihane/inqubus/model/Target.java
frontend/src/yukihane/inqubus/model/TargetsColumnModel.java [new file with mode: 0644]

diff --git a/frontend/src/saccubus/worker/impl/MessageReportable.java b/frontend/src/saccubus/worker/impl/MessageReportable.java
new file mode 100644 (file)
index 0000000..c9513da
--- /dev/null
@@ -0,0 +1,9 @@
+package saccubus.worker.impl;
+
+/**
+ *
+ * @author yuki
+ */
+public interface MessageReportable {
+    String getMessage();
+}
index 4fd93b2..3f80597 100644 (file)
@@ -72,6 +72,7 @@ import yukihane.inqubus.manager.TaskManage;
 import yukihane.inqubus.manager.TaskManageListener;
 import yukihane.inqubus.manager.TaskStatus;
 import yukihane.inqubus.model.Target;
+import yukihane.inqubus.model.TargetsColumnModel;
 import yukihane.inqubus.model.TargetsTableModel;
 
 /**
@@ -106,7 +107,7 @@ public class MainFrame extends JFrame {
 
         final JPanel pnlMain = new JPanel();
         final JScrollPane scrDisplay = new JScrollPane();
-        tblDisplay = new MainTable();
+        tblDisplay = new JTable(targetModel, new TargetsColumnModel());
         final JPanel pnlButton = new JPanel();
         btnStart = new JButton();
         btnStop = new JButton();
@@ -150,7 +151,6 @@ public class MainFrame extends JFrame {
 
         pnlMain.setBorder(BorderFactory.createEtchedBorder());
 
-        tblDisplay.setModel(targetModel);
         tblDisplay.setDropMode(DropMode.INSERT_ROWS);
         scrDisplay.setViewportView(tblDisplay);
 
index 61d6f9b..8060d24 100644 (file)
@@ -14,7 +14,7 @@ public class Progress {
     }
 
     public Progress(String text) {
-        this(100.0, text);
+        this(-1.0, text);
     }
 
     public Progress(double percent, String text) {
index fccd90d..f4aad5a 100644 (file)
@@ -11,6 +11,7 @@ public class Target {
 
     public Target(RequestProcess rp) {
         this.requestProcess = rp;
+        this.progress = new Progress("待機中");
     }
 
     public int getRowId() {
diff --git a/frontend/src/yukihane/inqubus/model/TargetsColumnModel.java b/frontend/src/yukihane/inqubus/model/TargetsColumnModel.java
new file mode 100644 (file)
index 0000000..9112452
--- /dev/null
@@ -0,0 +1,66 @@
+package yukihane.inqubus.model;
+
+import java.awt.Color;
+import java.awt.Component;
+import javax.swing.JProgressBar;
+import javax.swing.JTable;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.DefaultTableColumnModel;
+import javax.swing.table.TableCellRenderer;
+import javax.swing.table.TableColumn;
+import javax.swing.table.TableModel;
+
+/**
+ *
+ * @author yuki
+ */
+public class TargetsColumnModel extends DefaultTableColumnModel {
+
+    private static final long serialVersionUID = 1L;
+    private final String[] columnNames = new String[]{"ID", "動画", "コメ", "変換", "状態"};
+
+    public TargetsColumnModel() {
+        super();
+        for (int i = 0; i < columnNames.length; i++) {
+            final TableColumn tc = new TableColumn(i);
+            tc.setHeaderValue(columnNames[i]);
+            addColumn(tc);
+        }
+
+        final TableColumn tc = getColumn(4);
+        tc.setCellRenderer(new ProgressRenderer());
+    }
+}
+
+class ProgressRenderer extends DefaultTableCellRenderer {
+
+    private static final long serialVersionUID = 1L;
+    private final JProgressBar progressBar;
+
+    public ProgressRenderer() {
+        progressBar = new JProgressBar(0, 100);
+        progressBar.setStringPainted(true);
+    }
+
+    @Override
+    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
+            int row, int column) {
+        if (isSelected) {
+            progressBar.setForeground(table.getSelectionForeground());
+            progressBar.setBackground(table.getSelectionBackground());
+        }
+
+        if (value == null) {
+            return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
+        }
+
+        final Progress p = (Progress) value;
+        int percent = (int) p.getPercent();
+        if (percent < 0 || percent > 100) {
+            return super.getTableCellRendererComponent(table, p.getText(), isSelected, hasFocus, row, column);
+        }
+        progressBar.setValue(percent);
+        progressBar.setString(p.getText());
+        return progressBar;
+    }
+}