N
NicolasA
Gast
Beim Ziehen der Spalten immer ArrayIndexOutOfBoundsException.....
Code:
package gui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.lang.reflect.InvocationTargetException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Hashtable;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import aktion.AktionsLauscher;
import schnittstellen.DatenbankZugriff;
import module.module.Modul;
import module.module.ModulListe;
import produkte.Produkt;
import produkte.ProduktListe;
public class Oberflaeche extends JFrame implements Runnable {
private ModulListe meModulListe = null;
private ProduktListe meProduktListe = null;
private DatenbankZugriff meDatenbankZugriff = null;
private Vector meModule = null;
private Vector meProdukte = null;
private Vector anzeigeModule = null;
private Font meFont = null;
private JTable meModulTabelle = null;
private JPopupMenu mePop = null;
private JLabel fortschrittLabel = null;
private JLabel produkt = null;
private JComboBox produktBox = null;
private JProgressBar progress = null;
private Produkt aktProdukt = null;
private Thread tabellenUpdate = null;
int sleep = 10000;
private AbstractTableModel ab = null;
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
new Oberflaeche();
}
private Oberflaeche() {
meDatenbankZugriff = new DatenbankZugriff();
meDatenbankZugriff.getProperties();
meDatenbankZugriff.verbindungHerstellen();
meModulListe = new ModulListe();
meProduktListe = new ProduktListe();
meProdukte = meProduktListe.getProduktListe(meDatenbankZugriff);
meFont = new Font("Arial",0,14);
setTitle("Integration Builder 1.0");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setMinimumSize(new Dimension(800,600));
progress = new JProgressBar();
fortschrittLabel = new JLabel();
anzeigeModuleHolen();
komponentenHinzufuegen();
tabellenUpdate = new Thread(this);
tabellenUpdate.start();
setSize(1024,768);
setLocationRelativeTo(null);
setVisible(true);
}
private void komponentenHinzufuegen() {
getContentPane().setLayout(new BorderLayout());
meModulTabelle = new JTable(new AbstractTableModel() {
private static final long serialVersionUID = 1L;
public int getColumnCount() {
return 3;
}
public int getRowCount() {
return anzeigeModule.size();
}
public String getColumnName(int column) {
switch( column ){
case 0: return "modul";
case 1: return "revision";
case 2: return "compilestatus";
default: return null;
}
}
public Object getValueAt(int rowIndex, int columnIndex) {
Modul modul = (Modul)anzeigeModule.get(rowIndex);
switch( columnIndex ){
case 0: return modul.getMeMname();
case 1: return modul.getMeMrevision();
case 2: return modul.getMeCompilestaus();
default: return null;
}
}
public Class getColumnClass(int columnIndex) {
switch( columnIndex ){
case 0: return String.class;
case 1: return String.class;
case 2: return String.class;
default: return null;
}
}
}
)
{
private static final long serialVersionUID = 1L;
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
Component compTabelle = super.prepareRenderer(renderer, row, column);
if (!isRowSelected(row)) {
String type = (String) getModel().getValueAt(row,2);
compTabelle.setBackground(Color.WHITE);
if (type.compareToIgnoreCase("waiting") == 0) {
compTabelle.setBackground(Color.YELLOW);
}
else if(type.compareToIgnoreCase("compiling") == 0) {
compTabelle.setBackground(Color.ORANGE);
}
else if (type.compareToIgnoreCase("compiled") == 0) {
compTabelle.setBackground(Color.GREEN);
}
}
return compTabelle;
}
};
ab = (AbstractTableModel)meModulTabelle.getModel();
meModulTabelle.getTableHeader().setReorderingAllowed(true);
meModulTabelle.setEnabled(false);
meModulTabelle.getTableHeader().setFont(new Font("Arial",0,14));
meModulTabelle.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
meModulTabelle.setFont(meFont);
meModulTabelle.setShowHorizontalLines(true);
meModulTabelle.setShowVerticalLines(false);
TableColumnModel columnModel = meModulTabelle.getColumnModel();
columnModel.getColumn(0).setPreferredWidth(550);
mePop = new JPopupMenu();
JMenuItem item1 = new JMenuItem("show submodulinformation");
mePop.add(item1);
item1.setFont(meFont);
meModulTabelle.add(mePop);
meModulTabelle.setBackground(Color.decode("#ECECEC"));
JScrollPane pane = new JScrollPane(meModulTabelle);
pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);;
pane.setBorder(BorderFactory.createLoweredBevelBorder());
JPanel pnlNorden = new JPanel(new BorderLayout());
pnlNorden.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
JToolBar toolMenu = new JToolBar();
JLabel lblProdukt = new JLabel("product:");
lblProdukt.setFont(meFont);
produktBox = new JComboBox(meProdukte);
produktBox.setToolTipText("choose a product");
produktBox.setFont(meFont);
produktBox.setMaximumSize(new Dimension(200,20));
produktBox.addActionListener(new AktionsLauscher(this));
JButton btnAus = new JButton(new ImageIcon("close_24.gif"));
btnAus.setToolTipText("exit");
btnAus.setActionCommand("ausschalten");
btnAus.addActionListener(new AktionsLauscher(this));
JButton btnDrucken = new JButton(new ImageIcon());
btnDrucken.setToolTipText("print this table");
toolMenu.add(lblProdukt);
toolMenu.addSeparator();
toolMenu.add(produktBox);
toolMenu.addSeparator();
toolMenu.add(btnAus);
toolMenu.setPreferredSize(new Dimension(350,35));
toolMenu.setFloatable(false);
toolMenu.setRollover(true);
toolMenu.setBorderPainted(false);
toolMenu.setOpaque(false);
pnlNorden.add(toolMenu, BorderLayout.EAST);
JPanel northLeft = new JPanel();
northLeft.setBorder(BorderFactory.createEmptyBorder(0,10,0,0));
produkt = new JLabel(produktBox.getSelectedItem().toString());
produkt.setFont(new Font("Arial",0,28));
northLeft.add(produkt);
JPanel pnlWesten = new JPanel(new BorderLayout());
JPanel pnlWestemUnten = new JPanel(new BorderLayout());
pnlWestemUnten.setBorder(new EmptyBorder(10,20,10,20));
progress.setStringPainted(true);
pnlWestemUnten.add(progress);
JPanel leftMiddle = new JPanel();
fortschrittLabel.setFont(meFont);
leftMiddle.add(fortschrittLabel);
JPanel pnlUntenLinks = new JPanel();
pnlUntenLinks.setBorder(BorderFactory.createEmptyBorder(30,0,0,0));
JLabel imgDspace = new JLabel(new ImageIcon("dSPACE.gif"));
pnlUntenLinks.add(imgDspace);
pnlWestemUnten.add(leftMiddle, BorderLayout.NORTH);
pnlWesten.add(pnlWestemUnten, BorderLayout.SOUTH);
pnlNorden.add(northLeft, BorderLayout.WEST);
pnlWestemUnten.add(pnlUntenLinks, BorderLayout.SOUTH);
add(pane, java.awt.BorderLayout.CENTER);
add(pnlNorden, BorderLayout.NORTH);
add(pnlWesten, BorderLayout.WEST);
}
public void produktBoxAktionen () {
aktProdukt = (Produkt) produktBox.getSelectedItem();
produkt.setText(aktProdukt.getMePname());
}
public void btnAusAktionen() {
System.exit(0);
}
public void anzeigeModuleHolen() {
anzeigeModule = new Vector();
meModule = meModulListe.getModulListe(meDatenbankZugriff);
for (int i = 0; i < meModule.size();i++) {
Modul aktModul = (Modul) meModule.get(i);
if ((aktModul.getMeCmnstatus() != 3 && aktModul.getMeIntegrationview().compareTo("") != 0)){
anzeigeModule.add(aktModul);
}
}
}
public void run() {
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
aktProdukt = (Produkt) produktBox.getSelectedItem();
anzeigeModuleHolen();
String sqlBefehl = "SELECT COUNT(mname) AS 'anzahl' FROM Modul_Compile WHERE compilestatus = 'compiled' AND bnr = "
+ aktProdukt.getMePnr();
int anzahlCompilierteModule = 0;
try {
ResultSet sqlResult = meDatenbankZugriff.datenHolen(sqlBefehl);
sqlResult.next();
anzahlCompilierteModule = sqlResult.getInt("anzahl");
} catch (SQLException e1) {
e1.printStackTrace();
}
System.out.println("Tabbelle neuzeichnen");
double fortschritt = (double) anzahlCompilierteModule / (double) anzeigeModule.size() * 100;
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
ab.fireTableDataChanged();
ab.fireTableStructureChanged();
progress.setValue(10);
System.out.println("Neuzeichnen");
}
}
);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//progress.repaint();
}
}
}