6: Add Load/Save state functionality
Task-Url: https://github.com/eyck/txviewer/issues/issue/6
This commit is contained in:
parent
ff4cb91aed
commit
5c784af74f
|
@ -923,8 +923,8 @@ public class WaveformViewer implements IWaveformViewer {
|
|||
* @see com.minres.scviewer.database.swt.IWaveformPanel#getActMarkerTime()
|
||||
*/
|
||||
@Override
|
||||
public long getSelectedMarkerTime(){
|
||||
return getMarkerTime(selectedMarker);
|
||||
public int getSelectedMarkerId(){
|
||||
return selectedMarker;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1168,4 +1168,16 @@ public class WaveformViewer implements IWaveformViewer {
|
|||
public void setColors(HashMap<WaveformColors, RGB> colourMap) {
|
||||
waveformCanvas.initColors(colourMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBaselineTime() {
|
||||
return -waveformCanvas.getScaleFactorPow10()*waveformCanvas.getOrigin().x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBaselineTime(Long time) {
|
||||
Point origin = waveformCanvas.getOrigin();
|
||||
origin.x=(int) (-time/waveformCanvas.getScaleFactorPow10());
|
||||
waveformCanvas.setOrigin(origin);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public interface IWaveformViewer extends PropertyChangeListener, ISelectionProvi
|
|||
|
||||
public long getCursorTime();
|
||||
|
||||
public long getSelectedMarkerTime();
|
||||
public int getSelectedMarkerId();
|
||||
|
||||
public long getMarkerTime(int index);
|
||||
|
||||
|
@ -96,4 +96,8 @@ public interface IWaveformViewer extends PropertyChangeListener, ISelectionProvi
|
|||
public List<ICursor> getCursorList();
|
||||
|
||||
public void setColors(HashMap<WaveformColors, RGB> colourMap);
|
||||
|
||||
public long getBaselineTime();
|
||||
|
||||
public void setBaselineTime(Long scale);
|
||||
}
|
|
@ -105,6 +105,9 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
/** The Constant ZOOM_LEVEL. */
|
||||
protected static final String ZOOM_LEVEL = "ZOOM_LEVEL";
|
||||
|
||||
/** The Constant BASE_LINE_TIME. */
|
||||
protected static final String BASE_LINE_TIME = "BASE_LINE_TIME";
|
||||
|
||||
/** The Constant FILE_CHECK_INTERVAL. */
|
||||
protected static final long FILE_CHECK_INTERVAL = 60000;
|
||||
|
||||
|
@ -209,7 +212,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
Long time = (Long) evt.getNewValue();
|
||||
eventBroker.post(WaveStatusBarControl.CURSOR_TIME, waveformPane.getScaledTime(time));
|
||||
long marker = waveformPane.getSelectedMarkerTime();
|
||||
long marker = waveformPane.getMarkerTime(waveformPane.getSelectedMarkerId());
|
||||
eventBroker.post(WaveStatusBarControl.MARKER_DIFF, waveformPane.getScaledTime(time - marker));
|
||||
|
||||
}
|
||||
|
@ -486,6 +489,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
index++;
|
||||
}
|
||||
persistedState.put(ZOOM_LEVEL, Integer.toString(waveformPane.getZoomLevel()));
|
||||
persistedState.put(BASE_LINE_TIME, Long.toString(waveformPane.getBaselineTime()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -494,7 +498,6 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
* @param state the state
|
||||
*/
|
||||
protected void restoreWaveformViewerState(Map<String, String> state) {
|
||||
updateAll();
|
||||
Integer waves = state.containsKey(SHOWN_WAVEFORM+"S") ? Integer.parseInt(state.get(SHOWN_WAVEFORM + "S")):0;
|
||||
List<TrackEntry> res = new LinkedList<>();
|
||||
for (int i = 0; i < waves; i++) {
|
||||
|
@ -504,8 +507,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
}
|
||||
if (res.size() > 0)
|
||||
waveformPane.getStreamList().addAll(res);
|
||||
Integer cursorLength = state.containsKey(SHOWN_CURSOR + "S") ? Integer.parseInt(state.get(SHOWN_CURSOR + "S"))
|
||||
: 0;
|
||||
Integer cursorLength = state.containsKey(SHOWN_CURSOR+"S")?Integer.parseInt(state.get(SHOWN_CURSOR + "S")):0;
|
||||
List<ICursor> cursors = waveformPane.getCursorList();
|
||||
if (cursorLength == cursors.size()) {
|
||||
for (int i = 0; i < cursorLength; i++) {
|
||||
|
@ -520,16 +522,24 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
|
|||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
if (state.containsKey(BASE_LINE_TIME)) {
|
||||
try {
|
||||
Long scale = Long.parseLong(state.get(BASE_LINE_TIME));
|
||||
waveformPane.setBaselineTime(scale);
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
updateAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all.
|
||||
* Update all status elements by posting respective events.
|
||||
*/
|
||||
private void updateAll() {
|
||||
eventBroker.post(ACTIVE_WAVEFORMVIEW, this);
|
||||
eventBroker.post(WaveStatusBarControl.ZOOM_LEVEL, zoomLevel[waveformPane.getZoomLevel()]);
|
||||
long cursor = waveformPane.getCursorTime();
|
||||
long marker = waveformPane.getSelectedMarkerTime();
|
||||
long marker = waveformPane.getMarkerTime(waveformPane.getSelectedMarkerId());
|
||||
eventBroker.post(WaveStatusBarControl.CURSOR_TIME, waveformPane.getScaledTime(cursor));
|
||||
eventBroker.post(WaveStatusBarControl.MARKER_TIME, waveformPane.getScaledTime(marker));
|
||||
eventBroker.post(WaveStatusBarControl.MARKER_DIFF, waveformPane.getScaledTime(cursor - marker));
|
||||
|
|
Loading…
Reference in New Issue