Ticket #125: LapView-Problem Patch.patch
File LapView-Problem Patch.patch, 11.2 KB (added by , 16 years ago) |
---|
-
src/de/jacavi/appl/track/CarPosition.java
1 1 package de.jacavi.appl.track; 2 2 3 import org.apache.log4j.Logger; 4 3 5 import de.jacavi.appl.ContextLoader; 4 6 import de.jacavi.appl.racelogic.Player; 5 7 import de.jacavi.appl.racelogic.RaceStatisticsManager; … … 10 12 * Represents the position of a car during a race. 11 13 */ 12 14 public class CarPosition { 15 16 /** Logger for this class */ 17 private static final Logger logger = Logger.getLogger(CarPosition.class); 18 13 19 /** The section of the track the car is currently at. */ 14 20 public int trackSectionIndex; 15 21 … … 60 66 this.stepsOnTile = stepsInTile; 61 67 if(incrementLaps) { 62 68 lap++; 69 logger.debug("trigger lap completed (setPosition)!"); 63 70 raceStatisticsManager.fireLapCompleted(player); 64 71 } 65 72 } … … 132 139 if(trackSectionIndex == track.getSections().size()) { 133 140 trackSectionIndex = 0; 134 141 lap++; 142 logger.debug("trigger lap completed (moveSteps)!"); 135 143 raceStatisticsManager.fireLapCompleted(player); 136 144 } 137 145 } -
src/de/jacavi/rcp/widgets/TrackWidget.java
260 260 261 261 private boolean isTrackBoundingBoxDirty = true; 262 262 263 public static boolean redrawActive; 264 263 265 private class ClickEventRepetitionHandler extends TimerTask { 264 266 private final InnerControlID heldControl; 265 267 … … 1017 1019 */ 1018 1020 @Override 1019 1021 public void paint(Control control, Graphics2D g2d) { 1022 redrawActive = true; 1023 1020 1024 Point size = control.getSize(); 1021 1025 1022 1026 // update the frame counter … … 1054 1058 g2d.setFont(widgetFont); 1055 1059 g2d.setColor(Color.BLACK); 1056 1060 g2d.drawString(lastFrameCount + "fps", 10, 20); 1061 1062 redrawActive = false; 1057 1063 } 1058 1064 1059 1065 /** -
src/de/jacavi/rcp/views/LapView.java
4 4 import java.util.ArrayList; 5 5 import java.util.Date; 6 6 7 import org.apache.log4j.Logger; 7 8 import org.eclipse.jface.viewers.ILabelProviderListener; 8 9 import org.eclipse.jface.viewers.ITableLabelProvider; 9 10 import org.eclipse.jface.viewers.TableViewer; … … 30 31 import de.jacavi.appl.racelogic.RaceStatisticsManager; 31 32 import de.jacavi.rcp.dlg.provider.PlayerContentProvider; 32 33 33 public class LapView extends ViewPart implements LapCompletionListener, 34 IPerspectiveListener { 35 public static final String ID = "JACAVI.lapView"; //$NON-NLS-1$ 34 35 36 public class LapView extends ViewPart implements LapCompletionListener, IPerspectiveListener { 37 public static final String ID = "JACAVI.lapView"; //$NON-NLS-1$ 38 39 /** Logger for this class */ 40 private static final Logger logger = Logger.getLogger(LapView.class); 36 41 37 private final ArrayList<Player> players; 38 private TableViewer tableViewer; 42 private final ArrayList<Player> players; 39 43 40 @SuppressWarnings("unchecked") 41 public LapView() { 42 players = (ArrayList<Player>) ContextLoader.getBean("playersBean"); 43 addListenerObject(this); 44 ((RaceStatisticsManager) ContextLoader 45 .getBean("statisticsRegistryBean")).addListener(this); 46 PlatformUI.getWorkbench().getActiveWorkbenchWindow() 47 .addPerspectiveListener(this); 48 } 44 private TableViewer tableViewer; 49 45 50 @Override 51 public void createPartControl(Composite parent) { 46 @SuppressWarnings("unchecked") 47 public LapView() { 48 players = (ArrayList<Player>) ContextLoader.getBean("playersBean"); 49 addListenerObject(this); 50 ((RaceStatisticsManager) ContextLoader.getBean("statisticsRegistryBean")).addListener(this); 51 PlatformUI.getWorkbench().getActiveWorkbenchWindow().addPerspectiveListener(this); 52 } 52 53 53 final Text text = new Text(parent, SWT.BORDER); 54 text.setBounds(25, 240, 220, 25); 54 @Override 55 public void createPartControl(Composite parent) { 55 56 56 String[] colNames = Messages.getStringArray("LapView.columns"); 57 tableViewer = new TableViewer(parent, SWT.SINGLE | SWT.BORDER 58 | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION 59 | SWT.HIDE_SELECTION); 60 // // Set up the table 61 final Table playerTable = tableViewer.getTable(); 62 playerTable.setLayoutData(new GridData(GridData.FILL_BOTH)); 57 final Text text = new Text(parent, SWT.BORDER); 58 text.setBounds(25, 240, 220, 25); 63 59 64 playerTable.setHeaderVisible(true);65 playerTable.setLinesVisible(true); 66 tableViewer.setColumnProperties(colNames);67 tableViewer.setLabelProvider(new LapLabelProvider()); 68 tableViewer.setContentProvider(new PlayerContentProvider());69 tableViewer.setInput(players);60 String[] colNames = Messages.getStringArray("LapView.columns"); 61 tableViewer = new TableViewer(parent, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL 62 | SWT.FULL_SELECTION | SWT.HIDE_SELECTION); 63 // // Set up the table 64 final Table playerTable = tableViewer.getTable(); 65 playerTable.setLayoutData(new GridData(GridData.FILL_BOTH)); 70 66 71 TableColumn tc = null; 72 for (String colName : colNames) { 73 tc = new TableColumn(playerTable, SWT.LEFT); 74 tc.setText(colName); 75 tc.setWidth(100); 76 } 77 tableViewer.refresh(); 67 playerTable.setHeaderVisible(true); 68 playerTable.setLinesVisible(true); 69 tableViewer.setColumnProperties(colNames); 70 tableViewer.setLabelProvider(new LapLabelProvider()); 71 tableViewer.setContentProvider(new PlayerContentProvider()); 72 tableViewer.setInput(players); 78 73 79 // 80 playerTable.addListener(SWT.Selection, new Listener() { 81 public void handleEvent(Event event) { 82 if (event.detail == SWT.CHECK) { 83 text.setText("You checked " + event.item); //$NON-NLS-1$ 84 } else { 85 text.setText("You selected " + event.item); //$NON-NLS-1$ 86 } 87 ; 88 } 89 }); 74 TableColumn tc = null; 75 for(String colName: colNames) { 76 tc = new TableColumn(playerTable, SWT.LEFT); 77 tc.setText(colName); 78 tc.setWidth(100); 79 } 80 tableViewer.refresh(); 90 81 91 } 82 // 83 playerTable.addListener(SWT.Selection, new Listener() { 84 public void handleEvent(Event event) { 85 if(event.detail == SWT.CHECK) { 86 text.setText("You checked " + event.item); //$NON-NLS-1$ 87 } else { 88 text.setText("You selected " + event.item); //$NON-NLS-1$ 89 } 90 ; 91 } 92 }); 92 93 93 @Override 94 public void setFocus() { 95 } 94 } 96 95 97 private class LapLabelProvider implements ITableLabelProvider { 96 @Override 97 public void setFocus() {} 98 98 99 private final SimpleDateFormat formatter; 99 private class LapLabelProvider implements ITableLabelProvider { 100 100 101 public LapLabelProvider() { 102 formatter = new SimpleDateFormat("mm:ss:SSS"); 103 } 101 private final SimpleDateFormat formatter; 104 102 105 @Override 106 public Image getColumnImage(Object arg0, int arg1) { 107 return null; 108 } 103 public LapLabelProvider() { 104 formatter = new SimpleDateFormat("mm:ss:SSS"); 105 } 109 106 110 @Override 111 public String getColumnText(Object element, int columnIndex) { 112 Player p = (Player) element; 107 @Override 108 public Image getColumnImage(Object arg0, int arg1) { 109 return null; 110 } 113 111 114 String result = ""; 115 switch (columnIndex) { 116 case 0: 117 if (p.getName() != null) { 118 result = p.getName(); 119 } 120 break; 121 case 1: 122 result = formatter.format(new Date(p.getRaceStatistic() 123 .getLastLap())); 124 break; 125 case 2: 126 result = formatter.format(new Date(p.getRaceStatistic() 127 .getBestLap())); 128 break; 129 case 3: 130 result = p.getPosition().lap + ""; 131 break; 132 default: 133 result = "UNKNOWN"; 134 break; 135 } 136 return result; 137 } 112 @Override 113 public String getColumnText(Object element, int columnIndex) { 114 Player p = (Player) element; 138 115 139 @Override 140 public void addListener(ILabelProviderListener arg0) { 141 } 116 String result = ""; 117 switch(columnIndex) { 118 case 0: 119 if(p.getName() != null) { 120 result = p.getName(); 121 } 122 break; 123 case 1: 124 result = formatter.format(new Date(p.getRaceStatistic().getLastLap())); 125 break; 126 case 2: 127 result = formatter.format(new Date(p.getRaceStatistic().getBestLap())); 128 break; 129 case 3: 130 result = p.getPosition().lap + ""; 131 break; 132 default: 133 result = "UNKNOWN"; 134 break; 135 } 136 return result; 137 } 142 138 143 @Override 144 public void dispose() { 145 } 139 @Override 140 public void addListener(ILabelProviderListener arg0) {} 146 141 147 @Override 148 public boolean isLabelProperty(Object arg0, String arg1) { 149 return false; 150 } 142 @Override 143 public void dispose() {} 151 144 152 @Override 153 public void removeListener(ILabelProviderListener arg0) { 154 } 145 @Override 146 public boolean isLabelProperty(Object arg0, String arg1) { 147 return false; 148 } 155 149 156 } 150 @Override 151 public void removeListener(ILabelProviderListener arg0) {} 157 152 158 /* 159 * (non-Javadoc) 160 * 161 * @see 162 * de.jacavi.rcp.views.LapCompletionListener#onLapCompleted(de.jacavi.appl 163 * .racelogic.Player) 164 */ 165 public void onLapCompleted(final Player p) { 166 Display.getDefault().asyncExec(new Runnable() { 167 @Override 168 public void run() { 169 tableViewer.refresh(p); 170 } 171 }); 172 } 153 } 173 154 174 @Override 175 public void perspectiveActivated(IWorkbenchPage arg0, 176 IPerspectiveDescriptor arg1) { 177 tableViewer.refresh(); 178 } 155 /* 156 * (non-Javadoc) 157 * @see de.jacavi.rcp.views.LapCompletionListener#onLapCompleted(de.jacavi.appl .racelogic.Player) 158 */ 159 public void onLapCompleted(final Player p) { 160 logger.debug("lap completed!"); 161 Display.getDefault().asyncExec(new Runnable() { 162 @Override 163 public void run() { 164 logger.debug("refreshing lap count"); 165 tableViewer.refresh(p); 166 } 167 }); 168 } 179 169 180 @Override 181 public void perspectiveChanged(IWorkbenchPage arg0, 182 IPerspectiveDescriptor arg1, String arg2) { 183 } 170 @Override 171 public void perspectiveActivated(IWorkbenchPage arg0, IPerspectiveDescriptor arg1) { 172 tableViewer.refresh(); 173 } 174 175 @Override 176 public void perspectiveChanged(IWorkbenchPage arg0, IPerspectiveDescriptor arg1, String arg2) {} 184 177 185 178 } 179 No newline at end of file