Permalink
Browse files

Initial checkin

  • Loading branch information...
1 parent ce5f7b9 commit eed1638fcc578521b1144adaf2397e225a7e01e7 @ronnyroeller committed Sep 29, 2012
@@ -0,0 +1,59 @@
+package com.sport.client.panel.spielplan;
+
+import java.awt.Color;
+import java.awt.Component;
+
+import javax.swing.JTable;
+import javax.swing.table.DefaultTableCellRenderer;
+
+import com.sport.core.bo.SpielplanTableEntryBO;
+import com.sport.core.bo.SportMatch;
+
+/**
+ * Renders a cell in the color of the group of the match that it represents
+ *
+ * @author Ronny
+ *
+ */
+public class ColorTableCellRender extends DefaultTableCellRenderer {
+
+ private static final long serialVersionUID = 5817071841157726787L;
+
+ @Override
+ public Component getTableCellRendererComponent(JTable table, Object value,
+ boolean isSelected, boolean hasFocus, int row, int column) {
+
+ super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
+ row, column);
+
+ if (isSelected && (column == table.getSelectedColumn())) {
+ return this;
+ }
+
+ int col = table.convertColumnIndexToModel(column);
+ if ((col % 2 == 1) && (col > 0)) {
+ SpieleTableModel dataModel = ((SpielplanTable) table).dataModel;
+ SpielplanTableEntryBO tableEntry = (SpielplanTableEntryBO) dataModel
+ .getData().get(row);
+
+ SportMatch spielBO = tableEntry.getSpiel((col - 1) / 2);
+ String color = "#ffffff"; //$NON-NLS-1$
+ if (spielBO != null) {
+ color = spielBO.getGroup().getColor();
+ }
+
+ // Zerlegen der HTML-Farbangabe
+ int[] part = new int[3];
+ part[0] = Integer.parseInt(color.substring(1, 3), 16);
+ part[1] = Integer.parseInt(color.substring(3, 5), 16);
+ part[2] = Integer.parseInt(color.substring(5, 7), 16);
+
+ setBackground(new Color(part[0], part[1], part[2]));
+ } else {
+ setBackground(Color.white);
+ setForeground(Color.black);
+ }
+ return this;
+ }
+
+}
@@ -0,0 +1,217 @@
+package com.sport.client.panel.spielplan;
+
+import java.awt.BorderLayout;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.util.Vector;
+
+import javax.swing.BorderFactory;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+
+
+import org.apache.log4j.Logger;
+
+import com.sport.client.VolleyFrame;
+import com.sport.client.panel.VolleyPanel;
+import com.sport.core.bo.Field;
+import com.sport.core.bo.SpielplanTableEntryBO;
+import com.sport.core.bo.SportMatch;
+import com.sport.core.bo.Tournament;
+import com.sport.server.remote.TurnierRemote;
+
+/**
+ * @author ronny
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class ErgebnissePanel extends VolleyPanel {
+
+ private static final Logger LOG = Logger.getLogger(ErgebnissePanel.class);
+
+ private static final long serialVersionUID = -278743311325514535L;
+
+ protected SpielplanTable spielplanTable;
+ private SaetzeTable saetzeTable = null;
+ private JScrollPane saetzeTableContainer = new JScrollPane();
+
+ public ErgebnissePanel(VolleyFrame parentFrame) {
+ super(parentFrame);
+
+ spielplanTable = new SpielplanTable(this, true, null, new Listener(),
+ new SpielplanSelectionListener());
+ spielplanTable.setDragEnabled(false);
+
+ JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
+ splitPane.setBorder(BorderFactory.createEmptyBorder());
+ splitPane.setContinuousLayout(true);
+ splitPane.setOneTouchExpandable(true);
+ splitPane.setDividerLocation(200);
+
+ splitPane.add(new JScrollPane(spielplanTable));
+ splitPane.add(saetzeTableContainer);
+
+ mainPanel.setLayout(new BorderLayout());
+ mainPanel.add(splitPane, BorderLayout.CENTER);
+ }
+
+ public void loadData(Tournament aTurnierBO) {
+ this.turnierBO = aTurnierBO;
+ dirty = false;
+
+ try {
+ Vector<SpielplanTableEntryBO> spielplanTableEntries = TurnierRemote
+ .getSpielplanTableEntrysByTurnierBO(aTurnierBO);
+ spielplanTable.dataModel.setData(spielplanTableEntries);
+
+ // M�gliche Spielplaetze setzen
+ Vector<Field> spielplaetze = TurnierRemote
+ .getSpielplaetzeByTurnierid(aTurnierBO.getId());
+ spielplanTable.setSpielplaetze(spielplaetze);
+
+ spielplanTable.updateUI(); // f�r Reset!
+ spielplanTable.clearSelection();
+ updateErgebnisEditPanel();
+ } catch (Exception e) {
+ LOG.error("Can't read results from server.", e);
+ }
+ }
+
+ public void save() {
+ dirty = false;
+
+ // Spiele aus TableEntry nach Vector umspeichern
+ Vector<SportMatch> data = new Vector<SportMatch>();
+
+ // alle Zeilen
+ for (SpielplanTableEntryBO tableEntry : spielplanTable.dataModel
+ .getData()) {
+ // alle Spalten
+ for (SportMatch spielBO : tableEntry.getSpiele()) {
+
+ if (spielBO != null)
+ data.add(spielBO);
+ }
+ }
+
+ try {
+ TurnierRemote.setSpieleByTurnierid(turnierBO.getId(), data
+ .toArray());
+ } catch (Exception e) {
+ LOG.error("Can't save results to server.", e);
+ }
+ }
+
+ /**
+ * Aktuallisiert die Detail-Ansicht f�r Spiel
+ *
+ */
+ public void updateErgebnisEditPanel() {
+ int row = spielplanTable.getSelectedRow();
+ int col = spielplanTable.getSelectedColumn();
+
+ // ggf. Reste speichern
+ if (saetzeTable != null) {
+ if (saetzeTable.getEditingRow() > -1) {
+ saetzeTable.getCellEditor(saetzeTable.getEditingRow(),
+ saetzeTable.getEditingColumn()).stopCellEditing();
+ }
+ saetzeTableContainer.setViewportView(new JPanel());
+ spielplanTable.repaint();
+ }
+
+ saetzeTable = null;
+ SportMatch spielBO = null;
+
+ if (col > -1
+ && (row < spielplanTable.dataModel.getData().size() && (col > 0))) {
+ SpielplanTableEntryBO tableEntry = (SpielplanTableEntryBO) spielplanTable.dataModel
+ .getData().get(row);
+
+ spielBO = tableEntry.getSpiel((col - 1) / 2);
+ if (spielBO != null) {
+ saetzeTable = new SaetzeTable(this, spielBO);
+ saetzeTableContainer.setViewportView(saetzeTable);
+ }
+ }
+
+ }
+
+ class Listener implements KeyListener {
+ // Select row in the saetzeTable
+ private boolean selectLastRowSaetze() {
+ // for matches -> jump to sets
+ if (spielplanTable.getSelectedColumn() > 0) {
+ int rowCount = saetzeTable.getRowCount();
+ if (rowCount > 0) {
+ saetzeTable.requestFocusInWindow();
+ saetzeTable.changeSelection(rowCount - 1,
+ SaetzeTableModel.COL_PUNKTE1, false, false);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void keyPressed(KeyEvent e) {
+ if (e.getKeyCode() == KeyEvent.VK_INSERT) {
+ saetzeTable.addSatz();
+ selectLastRowSaetze();
+ } else if (e.getKeyCode() == KeyEvent.VK_TAB) {
+ if (selectLastRowSaetze()) {
+ // reverse the effect of the implicit tab
+ int row = spielplanTable.getSelectedRow();
+ int col = spielplanTable.getSelectedColumn();
+ spielplanTable.changeSelection(row, col - 1, false, false);
+ }
+ }
+ }
+
+ public void keyTyped(KeyEvent e) {
+ }
+
+ public void keyReleased(KeyEvent e) {
+ updateErgebnisEditPanel();
+ }
+ }
+
+ /**
+ * Wird ausgef�hrt, wenn Nutzer einen anderen Spiel-Eintrag aus der Tabelle
+ * w�hlt
+ *
+ * @author ronny
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+ class SpielplanSelectionListener implements ListSelectionListener,
+ MouseListener {
+
+ public void valueChanged(ListSelectionEvent e) {
+ }
+
+ public void mouseClicked(MouseEvent e) {
+ updateErgebnisEditPanel();
+ }
+
+ public void mouseEntered(MouseEvent e) {
+ }
+
+ public void mouseExited(MouseEvent e) {
+ }
+
+ public void mousePressed(MouseEvent e) {
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ }
+
+ }
+
+}
@@ -0,0 +1,34 @@
+package com.sport.client.panel.spielplan;
+
+import com.sport.analyzer.impl.MannschaftAnalyzerImpl;
+import com.sport.core.bo.SportMatch;
+
+
+/**
+ * Entry for combo box of matches. Provides correct rendering of the match name,
+ * which relies on the analyzer.
+ *
+ * @author Ronny
+ *
+ */
+public class MatchComboEntry {
+
+ private SportMatch match;
+
+ public MatchComboEntry(SportMatch match) {
+ this.match = match;
+ }
+
+ public SportMatch getMatch() {
+ return match;
+ }
+
+ @Override
+ public String toString() {
+ return MannschaftAnalyzerImpl.getInstance().getName(match.getTeam1())
+ + " - "
+ + MannschaftAnalyzerImpl.getInstance()
+ .getName(match.getTeam2());
+ }
+
+}
Oops, something went wrong.

0 comments on commit eed1638

Please sign in to comment.