From ff4cb91aed4f6736ae2b1f20dfa6819a4842da3b Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Mon, 30 Nov 2015 22:16:29 +0100 Subject: [PATCH] 6: Add Load/Save state functionality Task-Url: https://github.com/eyck/txviewer/issues/issue/6 --- .../database/swt/internal/WaveformViewer.java | 85 +++++++++--------- .../Application.e4xmi | 16 +++- .../icons/folder_page.png | Bin 0 -> 688 bytes .../icons/script_save.png | Bin 0 -> 804 bytes .../handlers/LoadStoreSettingsHandler.java | 57 ++++++++++++ .../e4/application/handlers/OpenHandler.java | 8 +- .../e4/application/parts/WaveformViewer.java | 39 ++++++++ 7 files changed, 159 insertions(+), 46 deletions(-) create mode 100644 com.minres.scviewer.e4.application/icons/folder_page.png create mode 100644 com.minres.scviewer.e4.application/icons/script_save.png create mode 100644 com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/handlers/LoadStoreSettingsHandler.java diff --git a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java index d6f365f..9565c14 100644 --- a/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java +++ b/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/swt/internal/WaveformViewer.java @@ -20,6 +20,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map.Entry; import java.util.NavigableMap; +import java.util.NoSuchElementException; import java.util.TreeMap; import org.eclipse.core.runtime.ListenerList; @@ -772,52 +773,56 @@ public class WaveformViewer implements IWaveformViewer { protected void paintNames(GC gc, Rectangle rect) { if (streams.size() > 0) { - Integer firstKey = trackVerticalOffset.floorKey(rect.y); - if (firstKey == null) - firstKey = trackVerticalOffset.firstKey(); - Integer lastKey = trackVerticalOffset.floorKey(rect.y + rect.height); - Rectangle subArea = new Rectangle(rect.x, 0, rect.width, waveformCanvas.getTrackHeight()); - if (lastKey == firstKey) { - TrackEntry trackEntry=trackVerticalOffset.get(firstKey); - IWaveform w = trackEntry.waveform; - if (w instanceof ITxStream) - subArea.height *= ((ITxStream) w).getMaxConcurrency(); - drawTextFormat(gc, subArea, firstKey, w.getFullName(), trackEntry.selected); - } else { - for (Entry entry : trackVerticalOffset.subMap(firstKey, true, lastKey, true).entrySet()) { - IWaveform w = entry.getValue().waveform; - subArea.height = waveformCanvas.getTrackHeight(); + try { + Integer firstKey = trackVerticalOffset.floorKey(rect.y); + if (firstKey == null) + firstKey = trackVerticalOffset.firstKey(); + Integer lastKey = trackVerticalOffset.floorKey(rect.y + rect.height); + Rectangle subArea = new Rectangle(rect.x, 0, rect.width, waveformCanvas.getTrackHeight()); + if (lastKey == firstKey) { + TrackEntry trackEntry=trackVerticalOffset.get(firstKey); + IWaveform w = trackEntry.waveform; if (w instanceof ITxStream) subArea.height *= ((ITxStream) w).getMaxConcurrency(); - drawTextFormat(gc, subArea, entry.getKey(), w.getFullName(), entry.getValue().selected); + drawTextFormat(gc, subArea, firstKey, w.getFullName(), trackEntry.selected); + } else { + for (Entry entry : trackVerticalOffset.subMap(firstKey, true, lastKey, true).entrySet()) { + IWaveform w = entry.getValue().waveform; + subArea.height = waveformCanvas.getTrackHeight(); + if (w instanceof ITxStream) + subArea.height *= ((ITxStream) w).getMaxConcurrency(); + drawTextFormat(gc, subArea, entry.getKey(), w.getFullName(), entry.getValue().selected); + } } - } + }catch(NoSuchElementException e){} } } protected void paintValues(GC gc, Rectangle rect) { if (streams.size() > 0) { - Integer firstKey = trackVerticalOffset.floorKey(rect.y); - if (firstKey == null) - firstKey = trackVerticalOffset.firstKey(); - Integer lastKey = trackVerticalOffset.floorKey(rect.y + rect.height); - Rectangle subArea = new Rectangle(rect.x, 0, rect.width, waveformCanvas.getTrackHeight()); - if (lastKey == firstKey) { - TrackEntry trackEntry=trackVerticalOffset.get(firstKey); - IWaveform w = trackEntry.waveform; - if (w instanceof ITxStream) - subArea.height *= ((ITxStream) w).getMaxConcurrency(); - drawValue(gc, subArea, firstKey, actualValues.get(w), trackEntry.selected); - } else { - for (Entry entry : trackVerticalOffset.subMap(firstKey, true, lastKey, true) - .entrySet()) { - IWaveform w = entry.getValue().waveform; - subArea.height = waveformCanvas.getTrackHeight(); + try { + Integer firstKey = trackVerticalOffset.floorKey(rect.y); + if (firstKey == null) + firstKey = trackVerticalOffset.firstKey(); + Integer lastKey = trackVerticalOffset.floorKey(rect.y + rect.height); + Rectangle subArea = new Rectangle(rect.x, 0, rect.width, waveformCanvas.getTrackHeight()); + if (lastKey == firstKey) { + TrackEntry trackEntry=trackVerticalOffset.get(firstKey); + IWaveform w = trackEntry.waveform; if (w instanceof ITxStream) subArea.height *= ((ITxStream) w).getMaxConcurrency(); - drawValue(gc, subArea, entry.getKey(), actualValues.get(w), entry.getValue().selected); + drawValue(gc, subArea, firstKey, actualValues.get(w), trackEntry.selected); + } else { + for (Entry entry : trackVerticalOffset.subMap(firstKey, true, lastKey, true) + .entrySet()) { + IWaveform w = entry.getValue().waveform; + subArea.height = waveformCanvas.getTrackHeight(); + if (w instanceof ITxStream) + subArea.height *= ((ITxStream) w).getMaxConcurrency(); + drawValue(gc, subArea, entry.getKey(), actualValues.get(w), entry.getValue().selected); + } } - } + }catch(NoSuchElementException e){} } } @@ -846,11 +851,11 @@ public class WaveformViewer implements IWaveformViewer { gc.drawText(value, subArea.x + 5, subArea.y + yOffset + (waveformCanvas.getTrackHeight() - size.y) / 2, true); } - - public void setHighliteRelation(RelationType relationType){ - this.waveformCanvas.setHighliteRelation(relationType); - } - + + public void setHighliteRelation(RelationType relationType){ + this.waveformCanvas.setHighliteRelation(relationType); + } + /* (non-Javadoc) * @see com.minres.scviewer.database.swt.IWaveformPanel#getMaxTime() */ diff --git a/com.minres.scviewer.e4.application/Application.e4xmi b/com.minres.scviewer.e4.application/Application.e4xmi index 55e48fa..35149e6 100644 --- a/com.minres.scviewer.e4.application/Application.e4xmi +++ b/com.minres.scviewer.e4.application/Application.e4xmi @@ -34,8 +34,13 @@ - - + + + + + + + @@ -77,6 +82,9 @@ + + + @@ -145,6 +153,7 @@ + @@ -226,6 +235,9 @@ + + + diff --git a/com.minres.scviewer.e4.application/icons/folder_page.png b/com.minres.scviewer.e4.application/icons/folder_page.png new file mode 100644 index 0000000000000000000000000000000000000000..1ef6e11438f3226f88bdc457f55d677d1f2f8409 GIT binary patch literal 688 zcmV;h0#E&kP)CVGc zN?Hxg{(SJp>2>GN9JetoZ(aZH;Ije%0FdZ{S!LRVX%}YG;=d8L^N!mJkCd*SBx($jgG)S}+Le)f;q=GIn30YFNh3ZW|nh}2rL)`=3ju9K*d z<&~Gte>sT=5|RjR+}A(|O&3gS5t&*G5h0Um$c5IgEgxJl_8nzY#B+YU^|Fhvzo-^U z6fNn3(lBMcl9{Silx)4RpURdFw}1BZ?>}8S&h8fk5`hjKW@sP$LJL*otPOMf+jp$? zcC^*PiL>vkTOZln=wuc^%A^$j`TU&aa3ETVYE{(r=bgN835`stIePGw{uwD`7K9Y) z=4)VDHnkl3YL%JeLce6>Uubzae&kQ4(W!a4mwm4 z9lAtNv=ALSSd<+NDwVaw^{3sLb!X=Ld%vD1v~3H{e06ITmmVL?oETThxJs&&OzJem zHtwUrCLZ83e4hiPx_{6!^k(M?jGkMpCU#xpD+L1R^b^O%J&(6Mk`UL>+ z=KDX%bR-j>Tz%V8|BxWMH@@Yq=Prq6jEhpgV{ iMhatptY3F`RQVr(hfH%Uc-uk%0000 persistedState = new HashMap<>(); + persistedState.put(DATABASE_FILE + "S", Integer.toString(filesToLoad.size())); + Integer index = 0; + for (File file : filesToLoad) { + persistedState.put(DATABASE_FILE + index, file.getAbsolutePath()); + index++; + } + saveWaveformViewerState(persistedState); + Properties props = new Properties(); + props.putAll(persistedState); + try { + FileOutputStream out = new FileOutputStream(fileName); + props.store(out, "Written by SCViewer"); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void loadState(String fileName){ + Properties props = new Properties(); + try { + FileInputStream in = new FileInputStream(fileName); + props.load(in); + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + HashMap propMap = new HashMap((Map) props); + restoreWaveformViewerState(propMap); + } + /** * Save waveform viewer state. *