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

Quick Search    Search Deep

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


1   /*
2   ================================================================================
3   
4     FILE:  EditorLineLayout.java
5     
6     PROJECT:
7     
8       Asaph
9     
10    CONTENTS:
11    
12      LineLayout for the standard editor
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  import java.awt.Font;
45  import java.awt.font.FontRenderContext;
46  import java.awt.font.TextLayout;
47  import java.awt.font.TextHitInfo;
48  
49  import com.virtuosotechnologies.asaph.model.SongLine;
50  import com.virtuosotechnologies.asaph.model.ChordSet;
51  import virtuoso.asaph.util.render.Graphics2DLineLayout;
52  
53  
54  /**
55   * LineLayout for standard editor.
56   */
57  /*package*/ class EditorLineLayout
58  extends Graphics2DLineLayout
59  {
60    /**
61     * Constructor
62     */
63    /*package*/ EditorLineLayout(
64      SongLine line,
65      ChordSet chordSet,
66      int blockIndent,
67      FontRenderContext renderContext)
68    {
69      super(EditorConstants.LINE_TOP_MARGIN, line, chordSet, null, true, blockIndent,
70        EditorConstants.INDENT_WIDTH, EditorConstants.CHORD_SPACING, chordSet == null, true,
71        EditorConstants.CHORD_FONT, EditorConstants.TEXT_FONT, EditorConstants.COMMENT_FONT,
72        renderContext);
73    }
74    
75    
76    /**
77     * Special Graphics2DLineLayout method that gets the width of a TextLayout.
78     * This implementation makes room for an oblique caret, if necessary.
79     */
80    protected float getTextLayoutWidth(
81      TextLayout layout)
82    {
83      float ret = layout.getAdvance();
84      TextHitInfo hitInfo = TextHitInfo.trailing(layout.getCharacterCount()-1);
85      float[] info = layout.getCaretInfo(hitInfo);
86      
87      // Hack workaround for Mac OS X bug (radar 3193109)
88      if (info[1] > 0.3f) info[1] = 0.3f;
89      
90      ret += layout.getAscent()*info[1];
91      return ret;
92    }
93    
94    
95    /**
96     * Special Graphics2DLineLayout method that gets the width of zero-length text.
97     * This implementation makes room for an oblique caret, if necessary.
98     */
99    protected float getZeroLengthTextWidth(
100     FontRenderContext renderContext,
101     Font font)
102   {
103     TextLayout layout = new TextLayout(" ", font, renderContext);
104     TextHitInfo hitInfo = TextHitInfo.trailing(0);
105     float[] info = layout.getCaretInfo(hitInfo);
106     
107     // Hack workaround for Mac OS X bug (radar 3193109)
108     if (info[1] > 0.3f) info[1] = 0.3f;
109     
110     return (layout.getAscent()+layout.getDescent())*info[1];
111   }
112   
113   
114   /**
115    * Subclasses may override this to generate filler text
116    */
117   protected String generateFillerString(
118     float width,
119     String lastString)
120   {
121     return "";
122   }
123   
124   
125   /**
126    * Subclasses may override this method to provide a chord placeholder
127    */
128   protected float getChordPlaceholderWidth()
129   {
130     return 2f;
131   }
132   
133   
134   /**
135    * Subclasses may override this method to force spacing between line elements
136    */
137   protected float getLineElementSpacing()
138   {
139     return 4f;
140   }
141   
142   
143   /**
144    * Subclasses may override this method and return true to force "strict chord
145    * placement", which is useful for the editor but doesn't look as nice for rendering.
146    */
147   protected boolean useStrictChordPlacement()
148   {
149     return true;
150   }
151 }