@@ -76,7 +76,6 @@ public class BoxSettingsImpl implements IBoxSettings {
7676 private transient Color [] highlightColors ;
7777
7878
79-
8079 public void copyFrom (IBoxSettings other ) {
8180 BoxSettingsImpl o = (BoxSettingsImpl ) other ;
8281 name = o .getName ();
@@ -140,38 +139,6 @@ protected Color setColorCopy(Color old, Color newColor) {
140139 return newColor == null ? null : new Color (null , newColor .getRGB ());
141140 }
142141
143- public String export () {
144- return new StringExternalization ().export (this );
145- }
146-
147- public void load (String string ) {
148- StringExternalization ext = new StringExternalization ();
149- boolean error = false ;
150- if (string != null )
151- try {
152- ext .load (string , this );
153- } catch (Exception e ) {
154- EditBox .logError (this , "Cannot load EditBox settings from string: " +string , e );
155- error = true ;
156- }
157- if (error || string == null ) {
158- this .copyFrom (DEFAULT );
159- }
160- notifyChange (PropertiesKeys .ALL .name (), null , null );
161- }
162-
163- public void export (OutputStream stream ) throws Exception {
164- new StringExternalization ().export (stream ,this );
165- }
166-
167- public void load (InputStream stream ) throws Exception {
168- if (stream ==null )
169- load ((String )null );
170- else
171- new StringExternalization ().load (stream ,this );
172- notifyChange (PropertiesKeys .ALL .name (), null , null );
173- }
174-
175142 public boolean getEnabled () {
176143 return enabled ;
177144 }
@@ -533,34 +500,86 @@ public int getFillKeyModifierSWTInt(){
533500 return SWT .SHIFT ;
534501 return 0 ;
535502 }
503+
504+ //save/restore related {
505+ private StringExternalization ext = new StringExternalization ();
506+
507+ public String export () {
508+ return ext .exportToString (this );
509+ }
510+ public void export (OutputStream stream ) throws Exception {
511+ ext .export (stream ,this );
512+ }
536513
514+ public void load (String string ) {
515+ //StringExternalization ext = new StringExternalization();
516+ boolean error = false ;
517+ if (string != null ){
518+ try {
519+ ext .loadFromString (string , this );
520+ } catch (Exception e ) {
521+ EditBox .logError (this , "Cannot load EditBox settings from string: " +string , e );
522+ error = true ;
523+ }
524+ }
525+ if (error || string == null ) {
526+ this .copyFrom (DEFAULT );
527+ }
528+ notifyChange (PropertiesKeys .ALL .name (), null , null );
529+ }
530+ public void load (InputStream stream ) throws Exception {
531+ if (stream ==null )
532+ load ((String )null );
533+ else
534+ ext .loadFromStream (stream ,this );
535+ notifyChange (PropertiesKeys .ALL .name (), null , null );
536+ }
537+
538+ // could have all methods static, but it just has too many methods to change
539+ /**
540+ * using Properties store and load methods
541+ */
537542 class StringExternalization {
538543
539544 private static final String COMMENT = "Editbox Eclipse Plugin Settings" ;
540545
541- public String export (BoxSettingsImpl b ) {
546+ public void export (OutputStream stream , BoxSettingsImpl b ) throws Exception {
542547 Properties p = toProperies (b );
543- return propertiesToString ( p );
548+ p . store ( stream , COMMENT );
544549 }
545-
546- public void load (InputStream stream , BoxSettingsImpl b ) throws Exception {
550+ public String exportToString (BoxSettingsImpl b ) {
551+ Properties p = toProperies (b );
552+ // return exportPropertiesToString(p);
553+ // }
554+ // private String exportPropertiesToString(Properties p) {
555+ try {
556+ ByteArrayOutputStream bo = new ByteArrayOutputStream ();
557+ p .store (bo , "COMMENT" );
558+ return bo .toString ();
559+ } catch (IOException e ) {
560+ EditBox .logError (this , "Cannot convert propeties to sring" , e );
561+ }
562+ return "" ;
563+ }
564+ // private Properties loadProperties(String s) throws IOException {
565+ // Properties p = new Properties();
566+ // p.load(new StringBufferInputStream(s));
567+ // return p;
568+ // }
569+ public void loadFromString (String s , BoxSettingsImpl b ) throws Exception {
570+ //Properties p = loadProperties(s);
547571 Properties p = new Properties ();
548- p .load (stream );
549- load (p ,b );
572+ p .load (new StringBufferInputStream ( s ));
573+ fromProperties (p ,b );
550574 }
551-
552- public void export (OutputStream stream , BoxSettingsImpl b ) throws Exception {
553- Properties p = toProperies (b );
554- p .store (stream , COMMENT );
555-
575+ public void loadFromStream (InputStream stream , BoxSettingsImpl b ) throws Exception {
576+ Properties p = new Properties ();
577+ p .load (stream );
578+ fromProperties (p ,b );
556579 }
557580
558- public void load (String s , BoxSettingsImpl b ) throws Exception {
559- Properties p = loadProperties (s );
560- load (p ,b );
561- }
562581
563- private void load (Properties p , BoxSettingsImpl b ) {
582+ private void fromProperties (Properties p , BoxSettingsImpl b ) {
564583 b .name = parseString (p .get (PropertiesKeys .Name .name ()));
565584 b .borderColor = parseColor (p .get (PropertiesKeys .BorderColor .name ()));
566585 b .highlightColor = parseColor (p .get (PropertiesKeys .HighlightColor .name ()));
@@ -618,23 +637,6 @@ private Properties toProperies(BoxSettingsImpl b) {
618637 return p ;
619638 }
620639
621- private Properties loadProperties (String s ) throws IOException {
622- Properties p = new Properties ();
623- p .load (new StringBufferInputStream (s ));
624- return p ;
625- }
626-
627- private String propertiesToString (Properties p ) {
628- try {
629- ByteArrayOutputStream bo = new ByteArrayOutputStream ();
630- p .store (bo , "COMMENT" );
631- return bo .toString ();
632- } catch (IOException e ) {
633- EditBox .logError (this , "Cannot convert propeties to sring" , e );
634- }
635- return "" ;
636- }
637-
638640
639641 private Color [] parseColorsArray (Object o ) {
640642 if (o == null || o .equals ("null" ))
@@ -717,7 +719,9 @@ private String toS(String s) {
717719 return s == null ? "null" : s ;
718720 }
719721 }
720-
722+ //}
723+
724+ //{
721725 public void addPropertyChangeListener (IPropertyChangeListener listener ) {
722726 if (listeners == null )
723727 listeners = new ArrayList <IPropertyChangeListener >();
@@ -735,6 +739,7 @@ protected void notifyChange(String propertyName, Object oldValue, Object newValu
735739 listener .propertyChange (e );
736740 }
737741 }
742+ //}
738743
739744 public void setBorderLineStyle (int selectionIndex ) {
740745 this .borderLineStyle = selectionIndex ;
0 commit comments