[bulletgrapherator~bullet-grapherator-repository:24] Implemented variably-numbered text lines in the Label.

  • From: ChrisGerrard@kenai.com
  • To: commits@bulletgrapherator.kenai.com
  • Subject: [bulletgrapherator~bullet-grapherator-repository:24] Implemented variably-numbered text lines in the Label.
  • Date: Mon, 2 Nov 2009 22:10:17 +0000

Project:    bulletgrapherator
Repository: bullet-grapherator-repository
Revision:   24
Author:     ChrisGerrard
Date:       2009-11-02 22:10:14 UTC
Link:       

Log Message:
------------
Implemented variably-numbered text lines in the Label.
Previous implementation was restricted to two lines only.
Console needs to be updated, as does assignment of formats to the individual 
Label lines.


Revisions:
----------
24


Modified Paths:
---------------
BulletGrapherator/src/bulletgraph/examples/SingleGraphToFile.java
BulletGrapherator/src/bulletgraph/BulletGraphText.java
BulletGrapherator/src/bulletgraph/BulletGraphConsole.java
BulletGrapherator/src/bulletgraph/render/BulletGraphRenderer.java
BulletGrapherator/src/bulletgraph/BulletGraphLabel.java
BulletGrapherator/src/bulletgraph/BulletGraph.java


Diffs:
------
Index: BulletGrapherator/src/bulletgraph/render/BulletGraphRenderer.java
===================================================================
--- BulletGrapherator/src/bulletgraph/render/BulletGraphRenderer.java   
(revision 23)
+++ BulletGrapherator/src/bulletgraph/render/BulletGraphRenderer.java   
(revision 24)
@@ -298,12 +298,12 @@
         Font font = null;
 
         // populate Label Line One
-        line = graph.getLabelLineOne();
+        line = graph.getLabel().getLabelLine(1);
         font = new Font("Serif", Font.PLAIN, 16);
         lines.add(line, font, frc);
 
-        // populate Label Line One
-        line = graph.getLabelLineTwo();
+        // populate Label Line Two
+        line = graph.getLabel().getLabelLine(2);
         font = new Font("SansSerif", Font.PLAIN, 12);
         lines.add(line, font, frc);
 
@@ -384,12 +384,12 @@
         Font font = null;
 
         // populate Label Line One
-        line = bg.getLabelLineOne();
+        line = bg.getLabel().getLabelLine(1);
         font = new Font("Serif", Font.PLAIN, 16);
         lines.add(line, font, frc);
 
-        // populate Label Line One
-        line = bg.getLabelLineTwo();
+        // populate Label Line Two
+        line = bg.getLabel().getLabelLine(2);
         font = new Font("SansSerif", Font.PLAIN, 12);
         lines.add(line, font, frc);
 
Index: BulletGrapherator/src/bulletgraph/BulletGraph.java
===================================================================
--- BulletGrapherator/src/bulletgraph/BulletGraph.java  (revision 23)
+++ BulletGrapherator/src/bulletgraph/BulletGraph.java  (revision 24)
@@ -65,7 +65,7 @@
     float graphWidth  = 0;
 
     // Label Properties
-    String labelLineOne = "Revenue 2005 YTD";
+    String labelLineOne = "Revenue 2005 YTD (class)";
     String labelLineTwo = "(U.S. $ in thousands)";
     float labelHeight   = 0;
     private float labelWidth    = 0;
@@ -88,7 +88,7 @@
     int   tickCount = 6;
 
     // Components
-    BulletGraphLabel label = new BulletGraphLabel(labelLineOne, 
labelLineTwo);
+    BulletGraphLabel label = new BulletGraphLabel(labelLineOne +"\n" + 
labelLineTwo);
     BulletGraphCore  core = new BulletGraphCore();
     BulletGraphScale scale = new BulletGraphScale();
 
@@ -276,43 +276,47 @@
         return scale;
     }
 
-    /**
-     * @param lineOne the Label's first line
-     */
-    public void setLabelLineOne(String lineOne) {
-        this.labelLineOne = lineOne;
-        setLabel(labelLineOne, labelLineTwo);
-        if (userLoading) {
-            userSetObjects.add("labelLineOne");
-        }
-    }
+//    /**
+//     * @param lineOne the Label's first line
+//     */
+//    public void setLabelLineOne(String lineOne) {
+//        this.labelLineOne = lineOne;
+//        setLabel(labelLineOne + "\n" + labelLineTwo);
+//        if (userLoading) {
+//            userSetObjects.add("labelLineOne");
+//        }
+//    }
 
-    /**
-     * @param lineTwo the Label's second line
-     */
-    public void setLabelLineTwo(String lineTwo) {
-        this.labelLineTwo = lineTwo;
-        setLabel(labelLineOne, labelLineTwo);
-        if (userLoading) {
-            userSetObjects.add("labelLineTwo");
-        }
-    }
+//    /**
+//     * @param lineTwo the Label's second line
+//     */
+//    public void setLabelLineTwo(String lineTwo) {
+//        this.labelLineTwo = lineTwo;
+//        setLabel(labelLineOne + "\n" + labelLineTwo);
+//        if (userLoading) {
+//            userSetObjects.add("labelLineTwo");
+//        }
+//    }
 
     /**
      *
-     * @param lineOne
-     * @param lineTwo
+     * @param linesStr String containing Label Lines, delimited with "\n"
      */
-    public void setLabel(String lineOne, String lineTwo) {
-        if (lineOne == null) {
+    public void setLabel(String linesStr) {
+        if (linesStr == null) {
             return;  // no point in trying to set a Label with no values
         }
-        label = new BulletGraphLabel(lineOne, lineTwo);
+        label = new BulletGraphLabel(linesStr);
         if (userLoading) {
             userSetObjects.add("label");
         }
     }
 
+    public void setLabelLines(String linesStr) {
+        System.out.println("Bullet Graph.setLabelLines(" + linesStr +")");
+        label.setLines(linesStr);
+    }
+
     /**
      * @param coreHeight the coreHeight to set
      */
@@ -418,14 +422,14 @@
      * @return the labelLineOne
      */
     public String getLabelLineOne() {
-        return labelLineOne;
+        return label.getLabelLine(1);
     }
 
     /**
      * @return the labelLineTwo
      */
     public String getLabelLineTwo() {
-        return labelLineTwo;
+        return label.getLabelLine(2);
     }
 
     /**
Index: BulletGrapherator/src/bulletgraph/BulletGraphLabel.java
===================================================================
--- BulletGrapherator/src/bulletgraph/BulletGraphLabel.java     (revision 23)
+++ BulletGrapherator/src/bulletgraph/BulletGraphLabel.java     (revision 24)
@@ -23,18 +23,27 @@
 
     private ArrayList<BulletGraphText> lines = new 
ArrayList<BulletGraphText>();
     private ArrayList<Integer> fontSizes = null; //new ArrayList<Integer>;
+    private int defaultFontSize = 6;
 
-    public BulletGraphLabel(String lineOne, String lineTwo) {
-        BulletGraphText textOne = new BulletGraphText(lineOne);
-        BulletGraphText textTwo = new BulletGraphText(lineTwo);
-//      ...
-        textOne.setFontSize("12px");
-        textTwo.setFontSize("8px");
-//      ...
-        lines.add(textOne);
-        lines.add(textTwo);
+    /**
+     * Initialize the Label, using the "\n"-delimited String for the Label's 
lines.
+     * @param inputLines
+     */
+    public BulletGraphLabel(String inputLines) {
+        setLines(inputLines);
     }
 
+//    public BulletGraphLabel(String lineOne, String lineTwo) {
+//        BulletGraphText textOne = new BulletGraphText(lineOne);
+//        BulletGraphText textTwo = new BulletGraphText(lineTwo);
+////      ...
+//        textOne.setFontSize("12px");
+//        textTwo.setFontSize("8px");
+////      ...
+//        lines.add(textOne);
+//        lines.add(textTwo);
+//    }
+
     /**
      * The BulletGraphLabel needs to be as wide as the widest line of text 
and
      * as high as the sums of the lines of text.
@@ -42,11 +51,13 @@
     @Override
     public void normalize() {
         this.height = 0;
+        int ord = 0;
         for (BulletGraphText line : lines) {
+            line.setFontSize(getFontSize(ord));
             line.normalize();
             float lineHeight = line.getHeight();
             this.height += lineHeight;
-            line.setHeight(getHeight());
+            line.setHeight(this.height);
             float lineWidth = line.getWidth();
             this.width = Math.max(getWidth(), lineWidth);
             line.setWidth(getWidth());
@@ -57,16 +68,79 @@
         }
     }
 
+    private int getFontSize(int ord) {
+//        int cntSizes = fontSizes.size();
+        int size = (fontSizes == null)      ? defaultFontSize
+                 : (ord > fontSizes.size()) ? defaultFontSize
+                                            : fontSizes.get(ord + 1);
+        return size;
+    }
+
     public ArrayList<BulletGraphText> getLines() {
         return lines;
     }
 
     /**
-     * Sets the font sizes for the Label lines using a comma-delimited 
string with integer fontsizes.
-     * e.g. "16,12,8,6" identifies the four sizes as shown.
+     * Sets the lines for the Label lines using a newline-delimited string, 
e.g. "line one \n line two"
+     * <br/>
+     * Blanks at the ends on the input lines are trimmed, i.e. the input 
Strings
+     * <ul>
+     *    <li>"line one\nline two"</li>
+     *    <li>"line one&nbsp;\n&nbsp;line two"</li>
+     *    <li>"&nbsp;line one&nbsp;&nbsp;\n&nbsp;line two"</li>
+     *    <li>"&nbsp;&nbsp;&nbsp;line one\n line 
two&nbsp;&nbsp;&nbsp;&nbsp;"</li>
+     * </ul>
+     * all resolve to the Label Lines
+     * <ul>
+     *    <li>"line one"</li>
+     *    <li>"line two"</li>
+     * </ul>
+     *
+     * Invalid lines are swallowed. It's expected that these will be 
exceedingly scarce.<br/>
+     * The order of the lines provided is material: the first line in the 
input string is the first/top
+     * line in the label, the second input line becomes the second label 
line,
+     * and so on and so forth and such like.
+     *
+     * @param linesString
+     */
+    public void setLines(String linesString) {
+        System.out.println("Label setting lines: '" + linesString + "'");
+        String[] inputlines = linesString.trim().split("[ ]*\n[ ]*");
+        if (inputlines.length > 0) {
+            lines = new ArrayList<BulletGraphText>(inputlines.length);
+            for (String line : inputlines) {
+                lines.add(new BulletGraphText(line));
+            }
+        }
+    }
+
+    public void setLabelLines(String linesStr) {
+        System.out.println("Label.setLabelLines(): " + linesStr );
+        setLines(linesStr);
+    }
+
+    public void setText(String linesString) {
+        System.out.println("Label.setText(): " + linesString );
+        String[] inputlines = linesString.trim().split("[ ]*\n[ ]*");
+        if (inputlines.length > 0) {
+            lines = new ArrayList<BulletGraphText>(inputlines.length);
+            for (String line : inputlines) {
+                lines.add(new BulletGraphText(line));
+            }
+        }
+    }
+
+    public void setStuff(String stuff) {
+        System.out.println("Label.setStuff(): " + stuff );
+    }
+
+
+    /**
+     * Sets the font lines for the Label lines using a comma-delimited 
string with integer fontsizes.
+     * e.g. "16,12,8,6" identifies the four lines as shown.
      * Blanks in the string are tolerated.
-     * Invalid font sizes, i.e. non-integers, are swallowed.
-     * The order of the font sizes is material; first size for first (top) 
line, 2nd for 2nd, etc.
+     * Invalid font lines, i.e. non-integers, are swallowed.
+     * The order of the font lines is material; first size for first (top) 
line, 2nd for 2nd, etc.
      *
      * @param sizesString
      */
@@ -84,4 +158,17 @@
             }
         }
     }
+
+    public String getLabelLine(int lineNum) {
+        if (lines == null) {
+            return "";
+        }
+        int numLines = lines.size();
+//        System.out.println("looking for line#: " + lineNum);
+//        System.out.println("    # label lines: " + numLines);
+        return  (lines.size() >= lineNum) ? lines.get(lineNum-1).getText()
+                                           : "";
+    }
+
+
 }
Index: BulletGrapherator/src/bulletgraph/BulletGraphText.java
===================================================================
--- BulletGrapherator/src/bulletgraph/BulletGraphText.java      (revision 23)
+++ BulletGrapherator/src/bulletgraph/BulletGraphText.java      (revision 24)
@@ -121,6 +121,16 @@
      * Also need to set the Y-pos in SVG coordinate space to match height of 
text
      * @param fontSize the fontSize to set
      */
+    public void setFontSize(int fontSize) {
+        this.fontSize  = String.valueOf(fontSize) + "px";
+        setY(fontSize);
+    }
+
+    /**
+     * Set the String declaring the font of the text.
+     * Also need to set the Y-pos in SVG coordinate space to match height of 
text
+     * @param fontSize the fontSize to set
+     */
     public void setFontSize(String fontSize) {
         this.fontSize  = fontSize;
         setY(getSizeOfFont(fontSize));
Index: BulletGrapherator/src/bulletgraph/BulletGraphConsole.java
===================================================================
--- BulletGrapherator/src/bulletgraph/BulletGraphConsole.java   (revision 23)
+++ BulletGrapherator/src/bulletgraph/BulletGraphConsole.java   (revision 24)
@@ -106,9 +106,10 @@
         BulletGraphCore core = bg.getCore();
         BulletGraphLabel label = bg.getLabel();
 
-        labelLineOneField.setText(bg.getLabelLineOne());
-        loadTemplateNameField(bg.getLabelLineOne());
-        labelLineTwoField.setText(bg.getLabelLineTwo());
+        String firstLabelLine = bg.getLabel().getLabelLine(1);
+        labelLineOneField.setText(firstLabelLine);
+        loadTemplateNameField(firstLabelLine);
+        labelLineTwoField.setText(bg.getLabel().getLabelLine(2));
         float labelWidth = label.getWidth();
         labelWidthLabel.setText("Label Width: " + Math.round(labelWidth));
         labelWidthSlider.setValue(Math.round(labelWidth));
@@ -1218,10 +1219,22 @@
         component.setBorder(border);
     }
 
+    private void pullLabelLinesFromConsole() {
+        String labelLines = labelLineOneField.getText() + " \n "
+                          + labelLineTwoField.getText();
+        graph.setLabel(labelLines);
+    }
+
     private void populateBulletGraphFromConsole() {
-        graph.setLabelLineOne(labelLineOneField.getText());
-        graph.setLabelLineTwo(labelLineTwoField.getText());
+//        graph.setLabelLineOne(labelLineOneField.getText());
+//        graph.setLabelLineTwo(labelLineTwoField.getText());
 
+//        graph.setLabel( labelLineOneField.getText()
+//                      + " \n "
+//                      + labelLineTwoField.getText()
+//                      );
+        pullLabelLinesFromConsole();
+
         BulletGraphCore core = graph.getCore();
 
         Float value = 0f;
@@ -1284,8 +1297,6 @@
         Rectangle labelRect = new Rectangle(0, 0);
         int labelRowGap = graph.getLabelRowGap();
 
-        String labelOne = bg.getLabelLineOne();
-        String labelTwo = bg.getLabelLineTwo();
         Point2D anchor = new Point2D.Float(x, y);
         g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, 
RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
 
@@ -1298,6 +1309,7 @@
         g2.setColor(Color.black);  // Text will be rendered in black, 
explicitly
 
         // render Label Line One
+        String labelOne = bg.getLabel().getLabelLine(1);
         font = new Font("Serif", Font.PLAIN, 16);
         layout = new TextLayout(labelOne, font, frc);
         lBounds = layout.getBounds();
@@ -1307,6 +1319,7 @@
         layout.draw(g2, x, (float) ly);
 
         // render Label Line Two
+        String labelTwo = bg.getLabel().getLabelLine(2);
         font = new Font("SansSerif", Font.PLAIN, 12);
         layout = new TextLayout(labelTwo, font, frc);
         lBounds = layout.getBounds();
@@ -1698,10 +1711,11 @@
 
     private void labelLineOneFieldFocusLost(java.awt.event.FocusEvent evt) 
{//GEN-FIRST:event_labelLineOneFieldFocusLost
         String text = labelLineOneField.getText();
-        if (text != null) {
-            loadTemplateNameField(text);
-        }
-        graph.setLabelLineOne(text);
+//        if (text != null) {
+//            loadTemplateNameField(text);
+//        }
+//        graph.setLabelLineOne(text);
+        pullLabelLinesFromConsole();
         renderBulletGraphInConsole();
     }//GEN-LAST:event_labelLineOneFieldFocusLost
 
@@ -1741,7 +1755,8 @@
 
     private void labelLineTwoFieldFocusLost(java.awt.event.FocusEvent evt) 
{//GEN-FIRST:event_labelLineTwoFieldFocusLost
         String text = ((JTextField)evt.getSource()).getText();
-        graph.setLabelLineTwo(text);
+//        graph.setLabelLineTwo(text);
+        pullLabelLinesFromConsole();
         renderBulletGraphInConsole();
     }//GEN-LAST:event_labelLineTwoFieldFocusLost
 
Index: BulletGrapherator/src/bulletgraph/examples/SingleGraphToFile.java
===================================================================
--- BulletGrapherator/src/bulletgraph/examples/SingleGraphToFile.java   
(revision 23)
+++ BulletGrapherator/src/bulletgraph/examples/SingleGraphToFile.java   
(revision 24)
@@ -38,8 +38,9 @@
     }
 
     private static void setupGraph(BulletGraph graph) {
-        graph.setLabelLineOne("Label text for Sample Bullet Graph");
-        graph.setLabelLineTwo("secondary text for the label");
+        graph.setLabel("Label text for Sample Bullet Graph \n secondary text 
for the label");
+        graph.setPerformance(277);
+        graph.setComparison(255);
     }
 
 }





[bulletgrapherator~bullet-grapherator-repository:24] Implemented variably-numbered text lines in the Label.

ChrisGerrard 11/02/2009
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close