00001 /* 00002 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 00003 * Copyright (C) 2007 - INRIA - Jean-Baptiste Silvy 00004 * desc : Matrix of string which van be drawn using JOGL 00005 * 00006 * This file must be used under the terms of the CeCILL. 00007 * This source file is licensed as described in the file COPYING, which 00008 * you should have received as part of this distribution. The terms 00009 * are also available at 00010 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt 00011 * 00012 */ 00013 00014 00015 package org.scilab.modules.renderer.textDrawing; 00016 00017 import java.awt.geom.Rectangle2D; 00018 00019 import org.scilab.modules.renderer.utils.textRendering.SciTextRenderer; 00020 00025 public class StringMatrixGL extends StringMatrix { 00026 00027 private double[] widestStrings; 00028 private double tallestString; 00030 private double[][] width; 00032 private double[][] height; 00033 00037 public StringMatrixGL() { 00038 super(); 00039 } 00040 00044 public double getTallestString() { 00045 return tallestString; 00046 } 00047 00051 public double[] getLongestStrings() { 00052 return widestStrings; 00053 } 00054 00061 @Override 00062 public void setData(String[] text, int nbRow, int nbCol) { 00063 super.setData(text, nbRow, nbCol); 00064 widestStrings = new double[nbCol]; 00065 width = new double[nbRow][nbCol]; 00066 height = new double[nbRow][nbCol]; 00067 } 00068 00075 public double getStringWidth(int numRow, int numCol) { 00076 return width[numRow][numCol]; 00077 } 00078 00085 public double getStringHeight(int numRow, int numCol) { 00086 return height[numRow][numCol]; 00087 } 00088 00095 public void scale(double factor) { 00096 int nbCol = getNbCol(); 00097 int nbRow = getNbRow(); 00098 // apply factor on all data 00099 for (int j = 0; j < nbCol; j++) { 00100 for (int i = 0; i < nbRow; i++) { 00101 width[i][j] *= factor; 00102 height[i][j] *= factor; 00103 } 00104 widestStrings[j] *= factor; 00105 } 00106 tallestString *= factor; 00107 } 00108 00113 public void update(SciTextRenderer renderer) { 00114 int nbCol = getNbCol(); 00115 int nbRow = getNbRow(); 00116 String[][] data = getData(); 00117 00118 tallestString = 0.0; 00119 for (int j = 0; j < nbCol; j++) { 00120 double maxWidth = 0.0; 00121 for (int i = 0; i < nbRow; i++) { 00122 00123 // get current size 00124 Rectangle2D curRect = renderer.getBounds(data[i][j]); 00125 width[i][j] = curRect.getWidth(); 00126 height[i][j] = curRect.getHeight(); 00127 00128 // update width 00129 if (width[i][j] > maxWidth) { 00130 maxWidth = width[i][j]; 00131 } 00132 // update height 00133 if (height[i][j] > tallestString) { 00134 tallestString = height[i][j]; 00135 } 00136 } 00137 widestStrings[j] = maxWidth; 00138 } 00139 } 00140 00141 }
1.5.5