/* * @(#)ListWriters.java * * This file is part of webCDwriter - Network CD/DVD Writing. * * Copyright (C) 2005-2006 Jörg P. M. Haeger * * webCDwriter is free software. See CDcreator.java for details. */ import javax.swing.JComboBox; import javax.swing.JOptionPane; import javax.swing.table.AbstractTableModel; class ListWriters extends Command { JComboBox comboBox; static WritersTableModel tableModel = new WritersTableModel(); ListWriters(JComboBox comboBox) { this.comboBox = comboBox; tableModel = new WritersTableModel(); } int getDialogDelay() { return 2000; } void processHint(String str) { comboBox.addItem(str); int no = 0; int i = 0; while (i < str.length() && str.charAt(i) != ' ') { no = 10 * no + str.charAt(i) - '0'; i++; } tableModel.numbers[tableModel.counter] = no; tableModel.models[tableModel.counter] = str.substring(i); tableModel.progress[tableModel.counter] = 0; tableModel.states[tableModel.counter] = ""; tableModel.cancelButtons[tableModel.counter] = false; tableModel.counter++; } public void run() { JOptionPane pane = new JOptionPane( i18n("OptionsDialog.writer"), JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, okOption); showCentered(pane, ""); execCommand("listWriters"); super.run(); } static class WritersTableModel extends AbstractTableModel { int[] numbers = new int[20]; String[] models = new String[20]; int[] progress = new int[20]; int[] limits = new int[20]; String[] states = new String[20]; boolean[] cancelButtons = new boolean[20]; int counter = 0; public WritersTableModel() { for (int i = 0; i < limits.length; i++) limits[i] = 0; } public Class getColumnClass(int c) { return getValueAt(0, c).getClass(); } public int getColumnCount() { return 5; } public String getColumnName(int col) { switch (col) { case 0: return CDcreator.i18n("Burn.No"); case 1: return CDcreator.i18n("Burn.Writer"); case 2: return CDcreator.i18n("Burn.Status"); default: return ""; } } public int getRowCount() { return counter; } public Object getValueAt(int row, int col) { switch (col) { case 0: return new Integer(numbers[row]); case 1: return models[row]; case 2: return states[row]; case 3: if (limits[row] <= 0) return new Integer(-1); return new Integer(100 * progress[row] / limits[row]); case 4: if (cancelButtons[row]) return new Boolean(true); else return ""; default: return ""; } } public boolean isCellEditable(int row, int col) { return col == 4; } void setCancelButton(int no, boolean on) { if (no > 0) { int i = no - 1; cancelButtons[i] = on; fireTableCellUpdated(i, 4); } } void setProgress(int no, int value) { /* for (int i = 0; i < counter; i++) if (numbers[i] == no) { progress[i] = value; fireTableCellUpdated(i, 2); } */ if (no > 0) { int i = no - 1; progress[i] = value; fireTableCellUpdated(i, 3); } } void setRange(int no, int max) { if (no > 0) { int i = no - 1; if (max != limits[i]) { limits[i] = max; fireTableCellUpdated(i, 3); } } } void setState(int no, String state) { if (no > 0) { int i = no - 1; states[i] = state; fireTableCellUpdated(i, 2); } } } }