Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/virtuosotechnologies/asaph/standardgui/RenderSettings.java


1   /*
2   ================================================================================
3   
4     FILE:  RenderSettings.java
5     
6     PROJECT:
7     
8       Asaph
9     
10    CONTENTS:
11    
12      Rendering settings for the song viewer
13    
14    PROGRAMMERS:
15    
16      Daniel Azuma (DA)  <dazuma@kagi.com>
17    
18    COPYRIGHT:
19    
20      Copyright (C) 2003  Daniel Azuma  (dazuma@kagi.com)
21      
22      This program is free software; you can redistribute it and/or
23      modify it under the terms of the GNU General Public License as
24      published by the Free Software Foundation; either version 2
25      of the License, or (at your option) any later version.
26      
27      This program is distributed in the hope that it will be useful,
28      but WITHOUT ANY WARRANTY; without even the implied warranty of
29      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30      GNU General Public License for more details.
31      
32      You should have received a copy of the GNU General Public
33      License along with this program; if not, write to
34        Free Software Foundation, Inc.
35        59 Temple Place, Suite 330
36        Boston, MA 02111-1307 USA
37  
38  ================================================================================
39  */
40  
41  
42  package com.virtuosotechnologies.asaph.standardgui;
43  
44  
45  import java.awt.Font;
46  import java.io.InputStream;
47  import java.io.OutputStream;
48  import java.io.IOException;
49  import java.util.Map;
50  import java.util.HashMap;
51  import java.util.prefs.Preferences;
52  import java.util.prefs.InvalidPreferencesFormatException;
53  import java.util.prefs.BackingStoreException;
54  
55  import com.virtuosotechnologies.lib.base.BasicEnumeratedType;
56  import com.virtuosotechnologies.lib.util.PrefsUtils;
57  
58  
59  /**
60   * Rendering settings for the song viewer
61   */
62  /*package*/ class RenderSettings
63  {
64    private static Map positionStrings_ = new HashMap();
65    
66    /*package*/ static final class HeaderPositionsType
67    extends BasicEnumeratedType
68    {
69      private HeaderPositionsType(
70        String str)
71      {
72        super(str);
73        positionStrings_.put(str, this);
74      }
75    }
76    
77    /*package*/ static final HeaderPositionsType CREDITS_TOP_COPYRIGHT_TOP =
78      new HeaderPositionsType("credits_top,copyright_top");
79    /*package*/ static final HeaderPositionsType CREDITS_TOP_COPYRIGHT_BOTTOM =
80      new HeaderPositionsType("credits_top,copyright_bottom");
81    /*package*/ static final HeaderPositionsType CREDITS_BOTTOM_COPYRIGHT_BOTTOM =
82      new HeaderPositionsType("credits_bottom,copyright_bottom");
83    
84    
85    private boolean curShowComments_;
86    private boolean curShowKeySignature_;
87    private boolean curShowVariation_;
88    private float curZoom_;
89    private float curIndentWidth_;
90    private float curLineSpacing_;
91    private float curBlockSpacing_;
92    private float curChordSpacing_;
93    private boolean curCompressNarrowLines_;
94    private Font curChordFont_;
95    private Font curTextFont_;
96    private Font curCommentFont_;
97    private Font curTitleFont_;
98    private Font curCreditsFont_;
99    private Font curCopyrightFont_;
100   private Font curChordSetFont_;
101   private float belowTitleSpacing_;
102   private float interHeaderSpacing_;
103   private float belowHeaderSpacing_;
104   private float belowChordSetSpacing_;
105   private HeaderPositionsType headerPositionsType_;
106   
107   private static Preferences prefs_;
108   private static Preferences tempPrefs_;
109   static
110   {
111     Preferences rootPrefs = Preferences.userNodeForPackage(RenderSettings.class);
112     prefs_ = rootPrefs.node("renderSettings");
113     tempPrefs_ = rootPrefs.node("savedSettings");
114   }
115   
116   private static final String SHOW_COMMENTS_PREF = "showComments";
117   private static final String SHOW_KEYSIGNATURE_PREF = "showKeySignature";
118   private static final String SHOW_VARIATION_PREF = "showVariation";
119   private static final String ZOOM_PREF = "zoom";
120   private static final String INDENT_WIDTH_POINTS_PREF = "indentWidthPoints";
121   private static final String LINE_SPACING_POINTS_PREF = "lineSpacingPoints";
122   private static final String BLOCK_SPACING_POINTS_PREF = "blockSpacingPoints";
123   private static final String CHORD_SPACING_POINTS_PREF = "chordSpacingPoints";
124   private static final String COMPRESS_NARROW_LINES_PREF = "compressNarrowLines";
125   private static final String CHORD_FONT_PREF = "chordFont";
126   private static final String TEXT_FONT_PREF = "textFont";
127   private static final String COMMENT_FONT_PREF = "commentFont";
128   private static final String TITLE_FONT_PREF = "titleFont";
129   private static final String CREDITS_FONT_PREF = "creditsFont";
130   private static final String COPYRIGHT_FONT_PREF = "copyrightFont";
131   private static final String CHORDSET_FONT_PREF = "chordSystemFont";
132   private static final String BELOWTITLE_SPACING_POINTS_PREF = "belowTitleSpacingPoints";
133   private static final String INTERHEADER_SPACING_POINTS_PREF = "interHeaderSpacingPoints";
134   private static final String BELOWHEADER_SPACING_POINTS_PREF = "belowHeaderSpacingPoints";
135   private static final String BELOWCHORDSET_SPACING_POINTS_PREF = "belowChordSystemSpacingPoints";
136   private static final String HEADER_POSITIONS_TYPE_PREF = "headerPositionType";
137   
138   
139   /**
140    * Constructor with default settings
141    */
142   /*package*/ RenderSettings()
143   {
144     init(prefs_);
145   }
146   
147   
148   /**
149    * Constructor from an input stream
150    */
151   /*package*/ RenderSettings(
152     InputStream stream)
153   throws
154     IOException,
155     InvalidPreferencesFormatException
156   {
157     loadFromStream(stream);
158   }
159   
160   
161   /**
162    * Reload from an input stream
163    */
164   /*package*/ void loadFromStream(
165     InputStream stream)
166   throws
167     IOException,
168     InvalidPreferencesFormatException
169   {
170     synchronized(tempPrefs_)
171     {
172       Preferences.importPreferences(stream);
173       init(tempPrefs_);
174     }
175   }
176   
177   
178   /**
179    * Setup method
180    */
181   private void init(
182     Preferences prefs)
183   {
184     curShowComments_ = prefs.getBoolean(SHOW_COMMENTS_PREF, true);
185     curShowKeySignature_ = prefs.getBoolean(SHOW_KEYSIGNATURE_PREF, true);
186     curShowVariation_ = prefs.getBoolean(SHOW_VARIATION_PREF, true);
187     curZoom_ = prefs.getFloat(ZOOM_PREF, 1.0f);
188     curIndentWidth_ = prefs.getFloat(INDENT_WIDTH_POINTS_PREF, 20.0f);
189     curLineSpacing_ = prefs.getFloat(LINE_SPACING_POINTS_PREF, 3.0f);
190     curBlockSpacing_ = prefs.getFloat(BLOCK_SPACING_POINTS_PREF, 15.0f);
191     curChordSpacing_ = prefs.getFloat(CHORD_SPACING_POINTS_PREF, 0.0f);
192     curCompressNarrowLines_ = prefs.getBoolean(COMPRESS_NARROW_LINES_PREF, true);
193     curChordFont_ = PrefsUtils.getFontPref(prefs, CHORD_FONT_PREF,
194       new Font("SansSerif", Font.BOLD, 8));
195     curTextFont_ = PrefsUtils.getFontPref(prefs, TEXT_FONT_PREF,
196       new Font("Serif", Font.PLAIN, 10));
197     curCommentFont_ = PrefsUtils.getFontPref(prefs, COMMENT_FONT_PREF,
198       new Font("Serif", Font.ITALIC, 10));
199     curTitleFont_ = PrefsUtils.getFontPref(prefs, TITLE_FONT_PREF,
200       new Font("SansSerif", Font.BOLD, 12));
201     curCreditsFont_ = PrefsUtils.getFontPref(prefs, CREDITS_FONT_PREF,
202       new Font("SansSerif", Font.PLAIN, 7));
203     curCopyrightFont_ = PrefsUtils.getFontPref(prefs, COPYRIGHT_FONT_PREF,
204       new Font("SansSerif", Font.PLAIN, 7));
205     curChordSetFont_ = PrefsUtils.getFontPref(prefs, CHORDSET_FONT_PREF,
206       new Font("SansSerif", Font.ITALIC, 8));
207     belowTitleSpacing_ = prefs.getFloat(BELOWTITLE_SPACING_POINTS_PREF, 10.0f);
208     interHeaderSpacing_ = prefs.getFloat(INTERHEADER_SPACING_POINTS_PREF, 3.0f);
209     belowHeaderSpacing_ = prefs.getFloat(BELOWHEADER_SPACING_POINTS_PREF, 10.0f);
210     belowChordSetSpacing_ = prefs.getFloat(BELOWCHORDSET_SPACING_POINTS_PREF, 10.0f);
211     headerPositionsType_ = (HeaderPositionsType)positionStrings_.get(
212       prefs.get(HEADER_POSITIONS_TYPE_PREF, CREDITS_TOP_COPYRIGHT_TOP.toString()));
213     if (headerPositionsType_ == null)
214     {
215       headerPositionsType_ = CREDITS_TOP_COPYRIGHT_TOP;
216     }
217   }
218   
219   
220   /*package*/ void saveAsDefaults()
221   {
222     writeToPrefs(prefs_);
223   }
224   
225   
226   /*package*/ void saveToStream(
227     OutputStream stream)
228   throws
229     IOException,
230     BackingStoreException
231   {
232     synchronized(tempPrefs_)
233     {
234       writeToPrefs(tempPrefs_);
235       tempPrefs_.exportNode(stream);
236     }
237   }
238   
239   
240   /*package*/ void writeToPrefs(
241     Preferences prefs)
242   {
243     prefs.putBoolean(SHOW_COMMENTS_PREF, curShowComments_);
244     prefs.putBoolean(SHOW_KEYSIGNATURE_PREF, curShowKeySignature_);
245     prefs.putBoolean(SHOW_VARIATION_PREF, curShowVariation_);
246     prefs.putFloat(ZOOM_PREF, curZoom_);
247     prefs.putFloat(INDENT_WIDTH_POINTS_PREF, curIndentWidth_);
248     prefs.putFloat(LINE_SPACING_POINTS_PREF, curLineSpacing_);
249     prefs.putFloat(BLOCK_SPACING_POINTS_PREF, curBlockSpacing_);
250     prefs.putFloat(CHORD_SPACING_POINTS_PREF, curChordSpacing_);
251     prefs.putBoolean(COMPRESS_NARROW_LINES_PREF, curCompressNarrowLines_);
252     PrefsUtils.putFontPref(prefs, CHORD_FONT_PREF, curChordFont_);
253     PrefsUtils.putFontPref(prefs, TEXT_FONT_PREF, curTextFont_);
254     PrefsUtils.putFontPref(prefs, COMMENT_FONT_PREF, curCommentFont_);
255     PrefsUtils.putFontPref(prefs, TITLE_FONT_PREF, curTitleFont_);
256     PrefsUtils.putFontPref(prefs, CREDITS_FONT_PREF, curCreditsFont_);
257     PrefsUtils.putFontPref(prefs, COPYRIGHT_FONT_PREF, curCopyrightFont_);
258     PrefsUtils.putFontPref(prefs, CHORDSET_FONT_PREF, curChordSetFont_);
259     prefs.putFloat(BELOWTITLE_SPACING_POINTS_PREF, belowTitleSpacing_);
260     prefs.putFloat(INTERHEADER_SPACING_POINTS_PREF, interHeaderSpacing_);
261     prefs.putFloat(BELOWHEADER_SPACING_POINTS_PREF, belowHeaderSpacing_);
262     prefs.putFloat(BELOWCHORDSET_SPACING_POINTS_PREF, belowChordSetSpacing_);
263     prefs.put(HEADER_POSITIONS_TYPE_PREF, headerPositionsType_.toString());
264   }
265   
266   
267   //-------------------------------------------------------------------------
268   // Accessors
269   //-------------------------------------------------------------------------
270   
271   /*package*/ boolean getShowComments()
272   {
273     return curShowComments_;
274   }
275   
276   
277   /*package*/ boolean getShowKeySignature()
278   {
279     return curShowKeySignature_;
280   }
281   
282   
283   /*package*/ boolean getShowVariation()
284   {
285     return curShowVariation_;
286   }
287   
288   
289   /*package*/ float getZoom()
290   {
291     return curZoom_;
292   }
293   
294   
295   /*package*/ float getIndentWidth()
296   {
297     return curIndentWidth_;
298   }
299   
300   
301   /*package*/ float getLineSpacing()
302   {
303     return curLineSpacing_;
304   }
305   
306   
307   /*package*/ float getBlockSpacing()
308   {
309     return curBlockSpacing_;
310   }
311   
312   
313   /*package*/ float getChordSpacing()
314   {
315     return curChordSpacing_;
316   }
317   
318   
319   /*package*/ boolean getCompressNarrowLines()
320   {
321     return curCompressNarrowLines_;
322   }
323   
324   
325   /*package*/ Font getChordFont()
326   {
327     return curChordFont_;
328   }
329   
330   
331   /*package*/ Font getTextFont()
332   {
333     return curTextFont_;
334   }
335   
336   
337   /*package*/ Font getCommentFont()
338   {
339     return curCommentFont_;
340   }
341   
342   
343   /*package*/ Font getTitleFont()
344   {
345     return curTitleFont_;
346   }
347   
348   
349   /*package*/ Font getCreditsFont()
350   {
351     return curCreditsFont_;
352   }
353   
354   
355   /*package*/ Font getCopyrightFont()
356   {
357     return curCopyrightFont_;
358   }
359   
360   
361   /*package*/ Font getChordSetFont()
362   {
363     return curChordSetFont_;
364   }
365   
366   
367   /*package*/ float getBelowTitleSpacing()
368   {
369     return belowTitleSpacing_;
370   }
371   
372   
373   /*package*/ float getInterHeaderSpacing()
374   {
375     return interHeaderSpacing_;
376   }
377   
378   
379   /*package*/ float getBelowHeaderSpacing()
380   {
381     return belowHeaderSpacing_;
382   }
383   
384   
385   /*package*/ float getBelowChordSetSpacing()
386   {
387     return belowChordSetSpacing_;
388   }
389   
390   
391   /*package*/ HeaderPositionsType getHeaderPositionsType()
392   {
393     return headerPositionsType_;
394   }
395   
396   
397   //-------------------------------------------------------------------------
398   // Mutators
399   //-------------------------------------------------------------------------
400   
401   /*package*/ boolean setShowComments(
402     boolean value)
403   {
404     if (curShowComments_ == value)
405     {
406       return false;
407     }
408     curShowComments_ = value;
409     return true;
410   }
411   
412   
413   /*package*/ boolean setShowKeySignature(
414     boolean value)
415   {
416     if (curShowKeySignature_ == value)
417     {
418       return false;
419     }
420     curShowKeySignature_ = value;
421     return true;
422   }
423   
424   
425   /*package*/ boolean setShowVariation(
426     boolean value)
427   {
428     if (curShowVariation_ == value)
429     {
430       return false;
431     }
432     curShowVariation_ = value;
433     return true;
434   }
435   
436   
437   /*package*/ boolean setZoom(
438     float value)
439   {
440     if (curZoom_ == value)
441     {
442       return false;
443     }
444     curZoom_ = value;
445     return true;
446   }
447   
448   
449   /*package*/ boolean setIndentWidth(
450     float value)
451   {
452     if (curIndentWidth_ == value)
453     {
454       return false;
455     }
456     curIndentWidth_ = value;
457     return true;
458   }
459   
460   
461   /*package*/ boolean setLineSpacing(
462     float value)
463   {
464     if (curLineSpacing_ == value)
465     {
466       return false;
467     }
468     curLineSpacing_ = value;
469     return true;
470   }
471   
472   
473   /*package*/ boolean setBlockSpacing(
474     float value)
475   {
476     if (curBlockSpacing_ == value)
477     {
478       return false;
479     }
480     curBlockSpacing_ = value;
481     return true;
482   }
483   
484   
485   /*package*/ boolean setChordSpacing(
486     float value)
487   {
488     if (curChordSpacing_ == value)
489     {
490       return false;
491     }
492     curChordSpacing_ = value;
493     return true;
494   }
495   
496   
497   /*package*/ boolean setCompressNarrowLines(
498     boolean value)
499   {
500     if (curCompressNarrowLines_ == value)
501     {
502       return false;
503     }
504     curCompressNarrowLines_ = value;
505     return true;
506   }
507   
508   
509   /*package*/ boolean setChordFont(
510     Font value)
511   {
512     if (curChordFont_.equals(value))
513     {
514       return false;
515     }
516     curChordFont_ = value;
517     return true;
518   }
519   
520   
521   /*package*/ boolean setTextFont(
522     Font value)
523   {
524     if (curTextFont_.equals(value))
525     {
526       return false;
527     }
528     curTextFont_ = value;
529     return true;
530   }
531   
532   
533   /*package*/ boolean setCommentFont(
534     Font value)
535   {
536     if (curCommentFont_.equals(value))
537     {
538       return false;
539     }
540     curCommentFont_ = value;
541     return true;
542   }
543   
544   
545   /*package*/ boolean setTitleFont(
546     Font value)
547   {
548     if (curTitleFont_.equals(value))
549     {
550       return false;
551     }
552     curTitleFont_ = value;
553     return true;
554   }
555   
556   
557   /*package*/ boolean setCreditsFont(
558     Font value)
559   {
560     if (curCreditsFont_.equals(value))
561     {
562       return false;
563     }
564     curCreditsFont_ = value;
565     return true;
566   }
567   
568   
569   /*package*/ boolean setCopyrightFont(
570     Font value)
571   {
572     if (curCopyrightFont_.equals(value))
573     {
574       return false;
575     }
576     curCopyrightFont_ = value;
577     return true;
578   }
579   
580   
581   /*package*/ boolean setChordSetFont(
582     Font value)
583   {
584     if (curChordSetFont_.equals(value))
585     {
586       return false;
587     }
588     curChordSetFont_ = value;
589     return true;
590   }
591   
592   
593   /*package*/ boolean setBelowTitleSpacing(
594     float value)
595   {
596     if (belowTitleSpacing_ == value)
597     {
598       return false;
599     }
600     belowTitleSpacing_ = value;
601     return true;
602   }
603   
604   
605   /*package*/ boolean setInterHeaderSpacing(
606     float value)
607   {
608     if (interHeaderSpacing_ == value)
609     {
610       return false;
611     }
612     interHeaderSpacing_ = value;
613     return true;
614   }
615   
616   
617   /*package*/ boolean setBelowHeaderSpacing(
618     float value)
619   {
620     if (belowHeaderSpacing_ == value)
621     {
622       return false;
623     }
624     belowHeaderSpacing_ = value;
625     return true;
626   }
627   
628   
629   /*package*/ boolean setBelowChordSetSpacing(
630     float value)
631   {
632     if (belowChordSetSpacing_ == value)
633     {
634       return false;
635     }
636     belowChordSetSpacing_ = value;
637     return true;
638   }
639   
640   
641   /*package*/ boolean setHeaderPositionsType(
642     HeaderPositionsType value)
643   {
644     if (headerPositionsType_ == value)
645     {
646       return false;
647     }
648     headerPositionsType_ = value;
649     return true;
650   }
651 }