[Jlatexmath] Patch: Make basic examples use builder interface

classic Classic list List threaded Threaded
1 message Options
Felix Natter Felix Natter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Jlatexmath] Patch: Make basic examples use builder interface

hi,

I attached a patch which makes examples/Basic/Examples<i>.java use the
new builder interface for creating TeXIcons.

Is the indentation wrong? If so, what indentation setup do you use in
eclipse?

Best Regards,
--
Felix Natter

diff --git a/examples/Basic/Example1.java b/examples/Basic/Example1.java
index dbe514a..926fc1f 100644
--- a/examples/Basic/Example1.java
+++ b/examples/Basic/Example1.java
@@ -69,7 +69,12 @@ public class Example1 {
  latex += "\\end{array}";
 
  TeXFormula formula = new TeXFormula(latex);
- TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 20);
+
+ // Note: Old interface for creating icons:
+ //TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 20);
+ // Note: New interface using builder pattern (inner class):
+ TeXIcon icon = formula.new TeXIconBuilder().setStyle(TeXConstants.STYLE_DISPLAY).setSize(20).build();
+
  icon.setInsets(new Insets(5, 5, 5, 5));
 
  BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
diff --git a/examples/Basic/Example2.java b/examples/Basic/Example2.java
index 1c33b7e..f338207 100644
--- a/examples/Basic/Example2.java
+++ b/examples/Basic/Example2.java
@@ -62,7 +62,10 @@ public class Example2 {
  latex += "\\end{array}";
 
  TeXFormula formula = new TeXFormula(latex);
- TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 20);
+ // Note: Old interface for creating icons:
+ //TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 20);
+ // Note: New interface using builder pattern (inner class):
+ TeXIcon icon = formula.new TeXIconBuilder().setStyle(TeXConstants.STYLE_DISPLAY).setSize(20).build();
  icon.setInsets(new Insets(5, 5, 5, 5));
 
  BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
diff --git a/examples/Basic/Example3.java b/examples/Basic/Example3.java
index 347a6e1..4730060 100644
--- a/examples/Basic/Example3.java
+++ b/examples/Basic/Example3.java
@@ -43,6 +43,7 @@ import javax.swing.JLabel;
 import org.scilab.forge.jlatexmath.TeXConstants;
 import org.scilab.forge.jlatexmath.TeXFormula;
 import org.scilab.forge.jlatexmath.TeXIcon;
+import org.scilab.forge.jlatexmath.TeXFormula.TeXIconBuilder;
 
 /**
  * A class to test LaTeX rendering.
@@ -72,7 +73,11 @@ public class Example3 {
         latex += "\\end{array}";
 
         TeXFormula formula = new TeXFormula(latex);
-        TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 20);
+     // Note: Old interface for creating icons:
+        //TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 20);
+     // Note: New interface using builder pattern (inner class):
+     TeXIcon icon = formula.new TeXIconBuilder().setStyle(TeXConstants.STYLE_DISPLAY).setSize(20).build();
+        
         icon.setInsets(new Insets(5, 5, 5, 5));
         
         BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
diff --git a/examples/Basic/Example4.java b/examples/Basic/Example4.java
index 8727eb6..b2a619e 100644
--- a/examples/Basic/Example4.java
+++ b/examples/Basic/Example4.java
@@ -43,6 +43,7 @@ import javax.swing.JLabel;
 import org.scilab.forge.jlatexmath.TeXConstants;
 import org.scilab.forge.jlatexmath.TeXFormula;
 import org.scilab.forge.jlatexmath.TeXIcon;
+import org.scilab.forge.jlatexmath.TeXFormula.TeXIconBuilder;
 
 /**
  * A class to test LaTeX rendering.
@@ -60,7 +61,11 @@ public class Example4 {
  latex += "\\end{array}\n";
 
  TeXFormula formula = new TeXFormula(latex);
- TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 10);
+ // Note: Old interface for creating icons:
+ //TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 10);
+ // Note: New interface using builder pattern (inner class):
+ TeXIcon icon = formula.new TeXIconBuilder().setStyle(TeXConstants.STYLE_DISPLAY).setSize(10).build();
+
  icon.setInsets(new Insets(5, 5, 5, 5));
 
  BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
diff --git a/examples/Basic/Example6.java b/examples/Basic/Example6.java
index a677603..0460b34 100644
--- a/examples/Basic/Example6.java
+++ b/examples/Basic/Example6.java
@@ -48,27 +48,30 @@ import org.scilab.forge.jlatexmath.TeXIcon;
  * A class to test LaTeX rendering.
  **/
 public class Example6 {
-    public static void main(String[] args) {
-        
-        String latex = "\\begin{array}{cc}";
- latex += "\\fbox{\\text{A framed box with \\textdbend}}&\\shadowbox{\\text{A shadowed box}}\\cr";
- latex += "\\doublebox{\\text{A double framed box}}&\\ovalbox{\\text{An oval framed box}}\\cr";
- latex += "\\end{array}";
+ public static void main(String[] args) {
 
-        TeXFormula formula = new TeXFormula(latex);
-        TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 30);
-        icon.setInsets(new Insets(5, 5, 5, 5));
-        
-        BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
-        Graphics2D g2 = image.createGraphics();
-        g2.setColor(Color.white);
-        g2.fillRect(0,0,icon.getIconWidth(),icon.getIconHeight());
-        JLabel jl = new JLabel();
-        jl.setForeground(new Color(0, 0, 0));
-        icon.paintIcon(jl, g2, 0, 0);
-        File file = new File("Example6.png");
-        try {
-            ImageIO.write(image, "png", file.getAbsoluteFile());
-        } catch (IOException ex) {}
-    }    
+ String latex = "\\begin{array}{cc}";
+ latex += "\\fbox{\\text{A framed box with \\textdbend}}&\\shadowbox{\\text{A shadowed box}}\\cr";
+ latex += "\\doublebox{\\text{A double framed box}}&\\ovalbox{\\text{An oval framed box}}\\cr";
+ latex += "\\end{array}";
+
+ TeXFormula formula = new TeXFormula(latex);
+ // Note: Old interface for creating icons:
+ //TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 30);
+ // Note: New interface using builder pattern (inner class):
+ TeXIcon icon = formula.new TeXIconBuilder().setStyle(TeXConstants.STYLE_DISPLAY).setSize(30).build();
+ icon.setInsets(new Insets(5, 5, 5, 5));
+
+ BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
+ Graphics2D g2 = image.createGraphics();
+ g2.setColor(Color.white);
+ g2.fillRect(0,0,icon.getIconWidth(),icon.getIconHeight());
+ JLabel jl = new JLabel();
+ jl.setForeground(new Color(0, 0, 0));
+ icon.paintIcon(jl, g2, 0, 0);
+ File file = new File("Example6.png");
+ try {
+ ImageIO.write(image, "png", file.getAbsoluteFile());
+ } catch (IOException ex) {}
+ }    
 }
\ No newline at end of file
diff --git a/examples/Basic/Example7.java b/examples/Basic/Example7.java
index b3bc0a8..8d68924 100644
--- a/examples/Basic/Example7.java
+++ b/examples/Basic/Example7.java
@@ -48,24 +48,35 @@ import org.scilab.forge.jlatexmath.TeXIcon;
  * A class to test LaTeX rendering.
  **/
 public class Example7 {
-    public static void main(String[] args) {
-        
-        String latex = "\\mbox{abc abc abc abc abc abc abc abc abc abc abc abc abc abc\\\\abc abc abc abc abc abc abc\\\\abc abc abc abc abc abc abc}\\\\1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1";
- TeXFormula formula = new TeXFormula(latex);
- formula.setDEBUG(true);
-        TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 30, TeXConstants.UNIT_CM, 4, TeXConstants.ALIGN_LEFT, TeXConstants.UNIT_CM, 0.5f);
-        icon.setInsets(new Insets(5, 5, 5, 5));
-        
-        BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
-        Graphics2D g2 = image.createGraphics();
-        g2.setColor(Color.white);
-        g2.fillRect(0,0,icon.getIconWidth(),icon.getIconHeight());
-        JLabel jl = new JLabel();
-        jl.setForeground(new Color(0, 0, 0));
-        icon.paintIcon(jl, g2, 0, 0);
-        File file = new File("Example7.png");
-        try {
-            ImageIO.write(image, "png", file.getAbsoluteFile());
-        } catch (IOException ex) {}
-    }    
+ public static void main(String[] args) {
+
+ String latex = "\\mbox{abc abc abc abc abc abc abc abc abc abc abc abc abc abc\\\\abc abc abc abc abc abc abc\\\\abc abc abc abc abc abc abc}\\\\1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1";
+ TeXFormula formula = new TeXFormula(latex);
+ formula.setDEBUG(true);
+
+ // Note: Old interface for creating icons:
+ //TeXIcon icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 30, TeXConstants.UNIT_CM, 4, TeXConstants.ALIGN_LEFT, TeXConstants.UNIT_CM, 0.5f);
+ // Note: New interface using builder pattern (inner class):
+ TeXIcon icon = formula.new TeXIconBuilder()
+ .setStyle(TeXConstants.STYLE_DISPLAY)
+ .setSize(30)
+ .setWidth(TeXConstants.UNIT_CM, 4, TeXConstants.ALIGN_LEFT)
+ .setInterLineSpacing(TeXConstants.UNIT_CM, 0.5f)
+ .build();
+
+
+ icon.setInsets(new Insets(5, 5, 5, 5));
+
+ BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
+ Graphics2D g2 = image.createGraphics();
+ g2.setColor(Color.white);
+ g2.fillRect(0,0,icon.getIconWidth(),icon.getIconHeight());
+ JLabel jl = new JLabel();
+ jl.setForeground(new Color(0, 0, 0));
+ icon.paintIcon(jl, g2, 0, 0);
+ File file = new File("Example7.png");
+ try {
+ ImageIO.write(image, "png", file.getAbsoluteFile());
+ } catch (IOException ex) {}
+ }    
 }
\ No newline at end of file

_______________________________________________
jlatexmath mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/jlatexmath
Loading...