|
| 1 | +package grafica; |
| 2 | + |
| 3 | +import java.awt.BorderLayout; |
| 4 | +import java.awt.Component; |
| 5 | +import java.awt.Font; |
| 6 | +import java.awt.event.ActionEvent; |
| 7 | +import java.awt.event.ActionListener; |
| 8 | +import java.io.IOException; |
| 9 | +import java.util.ArrayList; |
| 10 | + |
| 11 | +import javax.swing.ImageIcon; |
| 12 | +import javax.swing.JComboBox; |
| 13 | +import javax.swing.JPanel; |
| 14 | +import javax.swing.JScrollPane; |
| 15 | +import javax.swing.JTable; |
| 16 | +import javax.swing.JTextArea; |
| 17 | +import javax.swing.ScrollPaneConstants; |
| 18 | +import javax.swing.table.DefaultTableColumnModel; |
| 19 | +import javax.swing.table.DefaultTableModel; |
| 20 | +import javax.swing.table.TableCellRenderer; |
| 21 | +import javax.swing.table.TableColumn; |
| 22 | + |
| 23 | +import loader.DBWriter; |
| 24 | +import risorse.ZC6603; |
| 25 | +import checkVersion.FWCheckVersion; |
| 26 | + |
| 27 | +@SuppressWarnings("serial") |
| 28 | +public class APannello extends JPanel{ |
| 29 | + |
| 30 | + JTextArea areaText = new JTextArea(); |
| 31 | + JTable table; |
| 32 | + FWCheckVersion check; |
| 33 | + Object[][] rowData; |
| 34 | + Object[][] checkData; |
| 35 | + DefaultTableModel model; |
| 36 | + DefaultTableModel model1; |
| 37 | + DefaultTableModel model2; |
| 38 | + ArrayList<ZC6603> phoneC6603; |
| 39 | + public APannello(final BPannello p2) throws IOException{ |
| 40 | + |
| 41 | + final Object[] columnNames = {"X/V","Nation","Brand","Serial","Version","New Version"}; |
| 42 | + model = new DefaultTableModel(rowData, columnNames); |
| 43 | + |
| 44 | + table = new JTable(model){ |
| 45 | + @SuppressWarnings({ "unchecked", "rawtypes" }) |
| 46 | + public Class getColumnClass(int column){ |
| 47 | + return getValueAt(0, column).getClass(); |
| 48 | + } |
| 49 | + }; |
| 50 | + |
| 51 | + p2.bLoad.addActionListener(new ActionListener() { |
| 52 | + |
| 53 | + @Override |
| 54 | + public void actionPerformed(ActionEvent arg0) { |
| 55 | + check = new FWCheckVersion(); |
| 56 | + phoneC6603 = check.phC6603; |
| 57 | + rowData = new Object[phoneC6603.size()][6]; |
| 58 | + for(int i=0; i<phoneC6603.size();i++){ |
| 59 | + |
| 60 | + rowData[i][0] = new ImageIcon(getClass().getResource(phoneC6603.get(i).getState())); |
| 61 | + rowData[i][1] = phoneC6603.get(i).getNation(); |
| 62 | + rowData[i][2] = phoneC6603.get(i).getBrand(); |
| 63 | + rowData[i][3] = phoneC6603.get(i).getSerial(); |
| 64 | + rowData[i][4] = phoneC6603.get(i).getVersion(); |
| 65 | + rowData[i][5] = phoneC6603.get(i).getNewVersion(); |
| 66 | + |
| 67 | + } |
| 68 | + model1 = new DefaultTableModel(rowData, columnNames); |
| 69 | + table.setModel(model1); |
| 70 | + ((DefaultTableModel)table.getModel()).fireTableDataChanged(); |
| 71 | + /*INIZIO BARBATRUCCO*/ |
| 72 | + for (int i = 0; i < table.getColumnCount(); i++) { |
| 73 | + DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel(); |
| 74 | + TableColumn col = colModel.getColumn(i); |
| 75 | + int width = 0; |
| 76 | + |
| 77 | + TableCellRenderer renderer = col.getHeaderRenderer(); |
| 78 | + for (int r = 0; r < table.getRowCount(); r++) { |
| 79 | + renderer = table.getCellRenderer(r, i); |
| 80 | + Component comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, i),false, false, r, i); |
| 81 | + width = Math.max(width, comp.getPreferredSize().width); |
| 82 | + } |
| 83 | + col.setPreferredWidth(width + 2); |
| 84 | + } |
| 85 | + /*FINE BARBATRUCCO*/ |
| 86 | + p2.bUpdate.setVisible(true); |
| 87 | + p2.box.setVisible(true); |
| 88 | + } |
| 89 | + }); |
| 90 | + p2.bUpdate.addActionListener(new ActionListener() { |
| 91 | + |
| 92 | + @Override |
| 93 | + public void actionPerformed(ActionEvent e) { |
| 94 | + new DBWriter(phoneC6603); |
| 95 | + } |
| 96 | + }); |
| 97 | + |
| 98 | + p2.box.addActionListener(new ActionListener() { |
| 99 | + |
| 100 | + @SuppressWarnings({ "unchecked" }) |
| 101 | + @Override |
| 102 | + public void actionPerformed(ActionEvent arg0) { |
| 103 | + JComboBox<String> combo; |
| 104 | + combo = p2.box; |
| 105 | + combo = (JComboBox<String>) arg0.getSource(); |
| 106 | + if(combo.getSelectedItem().equals("ALL Version")){ |
| 107 | + rowData = new Object[phoneC6603.size()][6]; |
| 108 | + for(int i=0; i<phoneC6603.size();i++){ |
| 109 | + |
| 110 | + rowData[i][0] = new ImageIcon(getClass().getResource(phoneC6603.get(i).getState())); |
| 111 | + rowData[i][1] = phoneC6603.get(i).getNation(); |
| 112 | + rowData[i][2] = phoneC6603.get(i).getBrand(); |
| 113 | + rowData[i][3] = phoneC6603.get(i).getSerial(); |
| 114 | + rowData[i][4] = phoneC6603.get(i).getVersion(); |
| 115 | + rowData[i][5] = phoneC6603.get(i).getNewVersion(); |
| 116 | + } |
| 117 | + validate(); |
| 118 | + model1 = new DefaultTableModel(rowData, columnNames); |
| 119 | + table.setModel(model1); |
| 120 | + ((DefaultTableModel)table.getModel()).fireTableDataChanged(); |
| 121 | + } |
| 122 | + |
| 123 | + if(combo.getSelectedItem().equals("Only Update")){ |
| 124 | + |
| 125 | + rowData = new Object[phoneC6603.size()][6]; |
| 126 | + int counter = 0; |
| 127 | + ArrayList<Integer> stack = new ArrayList<>(); |
| 128 | + for(int i=0; i<phoneC6603.size();i++){ |
| 129 | + if(phoneC6603.get(i).getState().equals("/img/check.png")){ |
| 130 | + stack.add(i); |
| 131 | + counter++; |
| 132 | + } |
| 133 | + } |
| 134 | + checkData = new Object[counter][6]; |
| 135 | + for(int i=0; i<counter;i++){ |
| 136 | + checkData[i][0] = new ImageIcon(getClass().getResource(phoneC6603.get(stack.get(i)).getState())); |
| 137 | + checkData[i][1] = phoneC6603.get(stack.get(i)).getNation(); |
| 138 | + checkData[i][2] = phoneC6603.get(stack.get(i)).getBrand(); |
| 139 | + checkData[i][3] = phoneC6603.get(stack.get(i)).getSerial(); |
| 140 | + checkData[i][4] = phoneC6603.get(stack.get(i)).getVersion(); |
| 141 | + checkData[i][5] = phoneC6603.get(stack.get(i)).getNewVersion(); |
| 142 | + } |
| 143 | + validate(); |
| 144 | + model2 = new DefaultTableModel(checkData, columnNames); |
| 145 | + table.setModel(model2); |
| 146 | + ((DefaultTableModel)table.getModel()).fireTableDataChanged(); |
| 147 | + } |
| 148 | + |
| 149 | + /*INIZIO BARBATRUCCO*/ |
| 150 | + for (int i = 0; i < table.getColumnCount(); i++) { |
| 151 | + DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel(); |
| 152 | + TableColumn col = colModel.getColumn(i); |
| 153 | + int width = 0; |
| 154 | + |
| 155 | + TableCellRenderer renderer = col.getHeaderRenderer(); |
| 156 | + for (int r = 0; r < table.getRowCount(); r++) { |
| 157 | + renderer = table.getCellRenderer(r, i); |
| 158 | + Component comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, i),false, false, r, i); |
| 159 | + width = Math.max(width, comp.getPreferredSize().width); |
| 160 | + } |
| 161 | + col.setPreferredWidth(width + 2); |
| 162 | + } |
| 163 | + /*FINE BARBATRUCCO*/ |
| 164 | + } |
| 165 | + }); |
| 166 | + table.setFont(new Font("monospaced", Font.PLAIN, 12)); |
| 167 | + JScrollPane scroller = new JScrollPane(); |
| 168 | + scroller.getViewport().add(table); |
| 169 | + scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); |
| 170 | + scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); |
| 171 | + setLayout(new BorderLayout()); |
| 172 | + validate(); |
| 173 | + add(scroller, BorderLayout.CENTER); |
| 174 | + } |
| 175 | + |
| 176 | + |
| 177 | +} |
0 commit comments