[Ejtools-cvs] libraries/graph/src/main/org/ejtools/graph/renderer AbstractGraphRenderer.java,1.6,1.7
Brought to you by:
letiemble
From: <let...@us...> - 2003-12-14 10:50:09
|
Update of /cvsroot/ejtools/libraries/graph/src/main/org/ejtools/graph/renderer In directory sc8-pr-cvs1:/tmp/cvs-serv18699/graph/src/main/org/ejtools/graph/renderer Modified Files: AbstractGraphRenderer.java BorderLayoutRenderer.java DefaultGraphRenderer.java GridBagLayoutRenderer.java GridGraphRenderer.java HorizontalAxis.java JPanelGraphRenderer.java TriAxisLayoutRenderer.java VerticalAxis.java Log Message: Add more javadocs. Adjust text export. Index: AbstractGraphRenderer.java =================================================================== RCS file: /cvsroot/ejtools/libraries/graph/src/main/org/ejtools/graph/renderer/AbstractGraphRenderer.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** AbstractGraphRenderer.java 15 Sep 2003 22:11:22 -0000 1.6 --- AbstractGraphRenderer.java 13 Dec 2003 21:26:47 -0000 1.7 *************** *** 1,88 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.Graphics; ! ! import javax.swing.JComponent; ! ! import org.ejtools.graph.GraphElement; ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public abstract class AbstractGraphRenderer extends JComponent implements GraphRenderer ! { ! /** Description of the Field */ ! protected GraphElement element = null; ! /** Description of the Field */ ! protected double horizontalScale = 1.0d; ! /** Description of the Field */ ! protected int horizontalScaling = ALIGN_RIGHT; ! /** Description of the Field */ ! protected double verticalScale = 1.0d; ! /** Description of the Field */ ! protected int verticalScaling = BOUNDED; ! ! ! /** Constructor for TrackRenderer. */ ! public AbstractGraphRenderer() ! { ! super(); ! } ! ! ! /** ! * @param element The new graphElement value ! */ ! public void setGraphElement(GraphElement element) ! { ! this.element = element; ! } ! ! ! /** ! * @param multiplier The new horizontalScale value ! */ ! public void setHorizontalScale(double multiplier) ! { ! this.horizontalScale = multiplier; ! } ! ! ! /** ! * @param type The new horizontalScaling value ! */ ! public void setHorizontalScaling(int type) ! { ! this.horizontalScaling = type; ! } ! ! ! /** ! * @param multiplier The new verticalScale value ! */ ! public void setVerticalScale(double multiplier) ! { ! this.verticalScale = multiplier; ! } ! ! ! /** ! * @param type The new verticalScaling value ! */ ! public void setVerticalScaling(int type) { } ! ! ! /** ! * @param graphics Description of the Parameter ! */ ! protected abstract void paintComponent(Graphics graphics); ! } --- 1,88 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.Graphics; ! ! import javax.swing.JComponent; ! ! import org.ejtools.graph.GraphElement; ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public abstract class AbstractGraphRenderer extends JComponent implements GraphRenderer ! { ! /** Description of the Field */ ! protected GraphElement element = null; ! /** Description of the Field */ ! protected double horizontalScale = 1.0d; ! /** Description of the Field */ ! protected int horizontalScaling = ALIGN_RIGHT; ! /** Description of the Field */ ! protected double verticalScale = 1.0d; ! /** Description of the Field */ ! protected int verticalScaling = BOUNDED; ! ! ! /** Constructor for TrackRenderer. */ ! public AbstractGraphRenderer() ! { ! super(); ! } ! ! ! /** ! * @param element The new graphElement value ! */ ! public void setGraphElement(GraphElement element) ! { ! this.element = element; ! } ! ! ! /** ! * @param multiplier The new horizontalScale value ! */ ! public void setHorizontalScale(double multiplier) ! { ! this.horizontalScale = multiplier; ! } ! ! ! /** ! * @param type The new horizontalScaling value ! */ ! public void setHorizontalScaling(int type) ! { ! this.horizontalScaling = type; ! } ! ! ! /** ! * @param multiplier The new verticalScale value ! */ ! public void setVerticalScale(double multiplier) ! { ! this.verticalScale = multiplier; ! } ! ! ! /** ! * @param type The new verticalScaling value ! */ ! public void setVerticalScaling(int type) { } ! ! ! /** ! * @param graphics Description of the Parameter ! */ ! protected abstract void paintComponent(Graphics graphics); ! } Index: BorderLayoutRenderer.java =================================================================== RCS file: /cvsroot/ejtools/libraries/graph/src/main/org/ejtools/graph/renderer/BorderLayoutRenderer.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** BorderLayoutRenderer.java 15 Sep 2003 22:11:22 -0000 1.5 --- BorderLayoutRenderer.java 13 Dec 2003 21:26:47 -0000 1.6 *************** *** 1,44 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.BorderLayout; ! ! import javax.swing.JComponent; ! ! import org.ejtools.graph.DefaultGraphElement; ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class BorderLayoutRenderer extends JPanelGraphRenderer ! { ! /** Constructor for Graph. */ ! public BorderLayoutRenderer() ! { ! super(new BorderLayout()); ! this.element = new DefaultGraphElement(); ! } ! ! ! /** ! * Sets the renderer attribute of the Graph object ! * ! * @param renderer The new renderer value ! * @param position The feature to be added to the Renderer attribute ! */ ! public void addRenderer(GraphRenderer renderer, String position) ! { ! renderer.setGraphElement(this.element); ! this.renderers.add(renderer); ! this.add((JComponent) renderer, position); ! } ! ! } --- 1,44 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.BorderLayout; ! ! import javax.swing.JComponent; ! ! import org.ejtools.graph.DefaultGraphElement; ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class BorderLayoutRenderer extends JPanelGraphRenderer ! { ! /** Constructor for Graph. */ ! public BorderLayoutRenderer() ! { ! super(new BorderLayout()); ! this.element = new DefaultGraphElement(); ! } ! ! ! /** ! * Sets the renderer attribute of the Graph object ! * ! * @param renderer The new renderer value ! * @param position The feature to be added to the Renderer attribute ! */ ! public void addRenderer(GraphRenderer renderer, String position) ! { ! renderer.setGraphElement(this.element); ! this.renderers.add(renderer); ! this.add((JComponent) renderer, position); ! } ! ! } Index: DefaultGraphRenderer.java =================================================================== RCS file: /cvsroot/ejtools/libraries/graph/src/main/org/ejtools/graph/renderer/DefaultGraphRenderer.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DefaultGraphRenderer.java 15 Sep 2003 22:11:22 -0000 1.7 --- DefaultGraphRenderer.java 13 Dec 2003 21:26:47 -0000 1.8 *************** *** 1,62 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.Graphics; ! import java.awt.Insets; ! ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class DefaultGraphRenderer extends AbstractGraphRenderer ! { ! /** Constructor for TrackRenderer. */ ! public DefaultGraphRenderer() ! { ! super(); ! } ! ! ! /** ! * @param graphics Description of the Parameter ! */ ! protected void paintComponent(Graphics graphics) ! { ! double minX = element.getXRange().getMin(); ! double maxX = element.getXRange().getMax(); ! double minY = element.getYRange().getMin(); ! double maxY = element.getYRange().getMax(); ! ! Insets insets = this.getInsets(); ! int x = insets.left; ! int y = insets.top; ! double width = (double) this.getWidth() - 1 - insets.left - insets.right; ! double height = (double) this.getHeight() - 1 - insets.top - insets.bottom; ! ! double scaleX = width / (maxX - minX); ! double scaleY = -height / (maxY - minY); ! double offsetX = x - scaleX * minX; ! double offsetY = y - scaleY * maxY; ! ! if (this.horizontalScaling == GraphRenderer.ALIGN_LEFT) ! { ! scaleX = 1.0d; ! offsetX = -minX; ! } ! if (this.horizontalScaling == GraphRenderer.ALIGN_RIGHT) ! { ! scaleX = 1.0d; ! offsetX = width - maxX; ! } ! ! this.element.draw(graphics, scaleX, offsetX, scaleY, offsetY); ! } ! } --- 1,62 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.Graphics; ! import java.awt.Insets; ! ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class DefaultGraphRenderer extends AbstractGraphRenderer ! { ! /** Constructor for TrackRenderer. */ ! public DefaultGraphRenderer() ! { ! super(); ! } ! ! ! /** ! * @param graphics Description of the Parameter ! */ ! protected void paintComponent(Graphics graphics) ! { ! double minX = element.getXRange().getMin(); ! double maxX = element.getXRange().getMax(); ! double minY = element.getYRange().getMin(); ! double maxY = element.getYRange().getMax(); ! ! Insets insets = this.getInsets(); ! int x = insets.left; ! int y = insets.top; ! double width = (double) this.getWidth() - 1 - insets.left - insets.right; ! double height = (double) this.getHeight() - 1 - insets.top - insets.bottom; ! ! double scaleX = width / (maxX - minX); ! double scaleY = -height / (maxY - minY); ! double offsetX = x - scaleX * minX; ! double offsetY = y - scaleY * maxY; ! ! if (this.horizontalScaling == GraphRenderer.ALIGN_LEFT) ! { ! scaleX = 1.0d; ! offsetX = -minX; ! } ! if (this.horizontalScaling == GraphRenderer.ALIGN_RIGHT) ! { ! scaleX = 1.0d; ! offsetX = width - maxX; ! } ! ! this.element.draw(graphics, scaleX, offsetX, scaleY, offsetY); ! } ! } Index: GridBagLayoutRenderer.java =================================================================== RCS file: /cvsroot/ejtools/libraries/graph/src/main/org/ejtools/graph/renderer/GridBagLayoutRenderer.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** GridBagLayoutRenderer.java 15 Sep 2003 22:11:22 -0000 1.5 --- GridBagLayoutRenderer.java 13 Dec 2003 21:26:47 -0000 1.6 *************** *** 1,43 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.GridBagConstraints; ! import java.awt.GridBagLayout; ! ! import javax.swing.JComponent; ! ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class GridBagLayoutRenderer extends JPanelGraphRenderer ! { ! /** Constructor for Graph. */ ! public GridBagLayoutRenderer() ! { ! super(new GridBagLayout()); ! } ! ! ! /** ! * Sets the renderer attribute of the Graph object ! * ! * @param renderer The new renderer value ! * @param constraints The feature to be added to the Renderer attribute ! */ ! public void addRenderer(GraphRenderer renderer, GridBagConstraints constraints) ! { ! renderer.setGraphElement(this.element); ! this.renderers.add(renderer); ! this.add((JComponent) renderer, constraints); ! } ! ! } --- 1,43 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.GridBagConstraints; ! import java.awt.GridBagLayout; ! ! import javax.swing.JComponent; ! ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class GridBagLayoutRenderer extends JPanelGraphRenderer ! { ! /** Constructor for Graph. */ ! public GridBagLayoutRenderer() ! { ! super(new GridBagLayout()); ! } ! ! ! /** ! * Sets the renderer attribute of the Graph object ! * ! * @param renderer The new renderer value ! * @param constraints The feature to be added to the Renderer attribute ! */ ! public void addRenderer(GraphRenderer renderer, GridBagConstraints constraints) ! { ! renderer.setGraphElement(this.element); ! this.renderers.add(renderer); ! this.add((JComponent) renderer, constraints); ! } ! ! } Index: GridGraphRenderer.java =================================================================== RCS file: /cvsroot/ejtools/libraries/graph/src/main/org/ejtools/graph/renderer/GridGraphRenderer.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** GridGraphRenderer.java 15 Sep 2003 22:11:22 -0000 1.6 --- GridGraphRenderer.java 13 Dec 2003 21:26:47 -0000 1.7 *************** *** 1,137 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.Color; ! import java.awt.FontMetrics; ! import java.awt.Graphics; ! import java.awt.Insets; ! import java.awt.geom.Rectangle2D; ! import java.text.Format; ! ! import org.ejtools.graph.Axis; ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class GridGraphRenderer extends Axis ! { ! /** Description of the Field */ ! protected Format horizontalFormat = null; ! /** Description of the Field */ ! protected Format verticalFormat = null; ! ! ! /** ! *Constructor for the GridRenderer object ! * ! * @param horizontalFormat Description of the Parameter ! * @param verticalFormat Description of the Parameter ! */ ! public GridGraphRenderer(Format horizontalFormat, Format verticalFormat) ! { ! this.format = horizontalFormat; ! this.horizontalFormat = horizontalFormat; ! this.verticalFormat = verticalFormat; ! } ! ! ! /** ! * @param graphics Description of the Parameter ! */ ! protected void paintComponent(Graphics graphics) ! { ! double multiplier = 0.0d; ! ! graphics.setFont(FONT); ! FontMetrics metrics = graphics.getFontMetrics(); ! graphics.setColor(Color.lightGray); ! ! double minX = element.getXRange().getMin(); ! double maxX = element.getXRange().getMax(); ! double minY = element.getYRange().getMin(); ! double maxY = element.getYRange().getMax(); ! ! Insets insets = this.getInsets(); ! int x = insets.left; ! int y = insets.top; ! double width = (double) this.getWidth() - 1 - insets.left - insets.right; ! double height = (double) this.getHeight() - 1 - insets.top - insets.bottom; ! ! double scaleX = width / (maxX - minX); ! double scaleY = -height / (maxY - minY); ! double offsetX = x - scaleX * minX; ! double offsetY = y - scaleY * maxY; ! ! if (this.horizontalScaling == GraphRenderer.ALIGN_LEFT) ! { ! scaleX = 1.0d; ! offsetX = -minX; ! } ! if (this.horizontalScaling == GraphRenderer.ALIGN_RIGHT) ! { ! scaleX = 1.0d * this.horizontalScale; ! offsetX = width - maxX * this.horizontalScale; ! } ! ! // Render horizontal lines ! minX = (x - offsetX) / scaleX; ! this.format = this.horizontalFormat; ! ! String minText = this.getFormated(minX); ! Rectangle2D minBounds = metrics.getStringBounds(minText, graphics); ! String maxText = this.getFormated(maxX); ! Rectangle2D maxBounds = metrics.getStringBounds(maxText, graphics); ! ! // Horizontal drawing ! double bound = Math.max(minBounds.getWidth() * 4.0d, maxBounds.getWidth() * 4.0d); ! ! // Specified the number of lines ! int ticks = 1; ! while ((width / ticks) > bound) ! { ! ticks = ticks * 2; ! } ! ! // Draw the divisions ! multiplier = width / ticks / 2; ! for (int i = 0; i <= (2 * ticks); i++) ! { ! graphics.drawLine((int) (i * multiplier), 0, (int) (i * multiplier), (int) height); ! } ! ! // Render horizontal lines ! this.format = this.verticalFormat; ! ! minText = this.getFormated(minY); ! minBounds = metrics.getStringBounds(minText, graphics); ! maxText = this.getFormated(maxY); ! maxBounds = metrics.getStringBounds(maxText, graphics); ! ! // Vertical drawing ! bound = Math.max(minBounds.getHeight() * 4.0d, maxBounds.getHeight() * 4.0d); ! ! // Specified the number of texts ! ticks = 1; ! while ((height / ticks) > bound) ! { ! ticks = ticks * 2; ! } ! ! // Draw the divisions ! multiplier = height / ticks / 2; ! for (int i = 0; i <= (2 * ticks); i++) ! { ! graphics.drawLine(0, (int) (i * multiplier), (int) width, (int) (i * multiplier)); ! } ! ! this.element.draw(graphics, scaleX, offsetX, scaleY, offsetY); ! } ! } --- 1,137 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.Color; ! import java.awt.FontMetrics; ! import java.awt.Graphics; ! import java.awt.Insets; ! import java.awt.geom.Rectangle2D; ! import java.text.Format; ! ! import org.ejtools.graph.Axis; ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class GridGraphRenderer extends Axis ! { ! /** Description of the Field */ ! protected Format horizontalFormat = null; ! /** Description of the Field */ ! protected Format verticalFormat = null; ! ! ! /** ! *Constructor for the GridRenderer object ! * ! * @param horizontalFormat Description of the Parameter ! * @param verticalFormat Description of the Parameter ! */ ! public GridGraphRenderer(Format horizontalFormat, Format verticalFormat) ! { ! this.format = horizontalFormat; ! this.horizontalFormat = horizontalFormat; ! this.verticalFormat = verticalFormat; ! } ! ! ! /** ! * @param graphics Description of the Parameter ! */ ! protected void paintComponent(Graphics graphics) ! { ! double multiplier = 0.0d; ! ! graphics.setFont(FONT); ! FontMetrics metrics = graphics.getFontMetrics(); ! graphics.setColor(Color.lightGray); ! ! double minX = element.getXRange().getMin(); ! double maxX = element.getXRange().getMax(); ! double minY = element.getYRange().getMin(); ! double maxY = element.getYRange().getMax(); ! ! Insets insets = this.getInsets(); ! int x = insets.left; ! int y = insets.top; ! double width = (double) this.getWidth() - 1 - insets.left - insets.right; ! double height = (double) this.getHeight() - 1 - insets.top - insets.bottom; ! ! double scaleX = width / (maxX - minX); ! double scaleY = -height / (maxY - minY); ! double offsetX = x - scaleX * minX; ! double offsetY = y - scaleY * maxY; ! ! if (this.horizontalScaling == GraphRenderer.ALIGN_LEFT) ! { ! scaleX = 1.0d; ! offsetX = -minX; ! } ! if (this.horizontalScaling == GraphRenderer.ALIGN_RIGHT) ! { ! scaleX = 1.0d * this.horizontalScale; ! offsetX = width - maxX * this.horizontalScale; ! } ! ! // Render horizontal lines ! minX = (x - offsetX) / scaleX; ! this.format = this.horizontalFormat; ! ! String minText = this.getFormated(minX); ! Rectangle2D minBounds = metrics.getStringBounds(minText, graphics); ! String maxText = this.getFormated(maxX); ! Rectangle2D maxBounds = metrics.getStringBounds(maxText, graphics); ! ! // Horizontal drawing ! double bound = Math.max(minBounds.getWidth() * 4.0d, maxBounds.getWidth() * 4.0d); ! ! // Specified the number of lines ! int ticks = 1; ! while ((width / ticks) > bound) ! { ! ticks = ticks * 2; ! } ! ! // Draw the divisions ! multiplier = width / ticks / 2; ! for (int i = 0; i <= (2 * ticks); i++) ! { ! graphics.drawLine((int) (i * multiplier), 0, (int) (i * multiplier), (int) height); ! } ! ! // Render horizontal lines ! this.format = this.verticalFormat; ! ! minText = this.getFormated(minY); ! minBounds = metrics.getStringBounds(minText, graphics); ! maxText = this.getFormated(maxY); ! maxBounds = metrics.getStringBounds(maxText, graphics); ! ! // Vertical drawing ! bound = Math.max(minBounds.getHeight() * 4.0d, maxBounds.getHeight() * 4.0d); ! ! // Specified the number of texts ! ticks = 1; ! while ((height / ticks) > bound) ! { ! ticks = ticks * 2; ! } ! ! // Draw the divisions ! multiplier = height / ticks / 2; ! for (int i = 0; i <= (2 * ticks); i++) ! { ! graphics.drawLine(0, (int) (i * multiplier), (int) width, (int) (i * multiplier)); ! } ! ! this.element.draw(graphics, scaleX, offsetX, scaleY, offsetY); ! } ! } Index: HorizontalAxis.java =================================================================== RCS file: /cvsroot/ejtools/libraries/graph/src/main/org/ejtools/graph/renderer/HorizontalAxis.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** HorizontalAxis.java 15 Sep 2003 22:11:22 -0000 1.6 --- HorizontalAxis.java 13 Dec 2003 21:26:47 -0000 1.7 *************** *** 1,130 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.Color; ! import java.awt.FontMetrics; ! import java.awt.Graphics; ! import java.awt.Insets; ! import java.awt.geom.Rectangle2D; ! import java.text.Format; ! ! import org.ejtools.graph.Axis; ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class HorizontalAxis extends Axis ! { ! /** ! * Constructor for VerticalAxis. ! * ! * @param format Description of the Parameter ! * @param position Description of the Parameter ! */ ! public HorizontalAxis(Format format, int position) ! { ! this.format = format; ! this.orientation = HORIZONTAL; ! this.position = position; ! } ! ! ! /** ! * Description of the Method ! * ! * @param graphics Description of the Parameter ! */ ! public void paintComponent(Graphics graphics) ! { ! String display; ! double multiplier = 0.0d; ! ! graphics.setFont(FONT); ! FontMetrics metrics = graphics.getFontMetrics(); ! ! Insets insets = this.getInsets(); ! int x = insets.left; ! // int y = insets.top; ! double width = (double) this.getWidth() - 1 - insets.left - insets.right; ! double height = (double) this.getHeight() - 1 - insets.top - insets.bottom; ! ! double min = element.getXRange().getMin(); ! double max = element.getXRange().getMax(); ! ! double scaleX = width / (max - min); ! double offsetX = x - scaleX * min; ! ! if (this.horizontalScaling == GraphRenderer.ALIGN_LEFT) ! { ! scaleX = 1.0d; ! offsetX = -min; ! } ! if (this.horizontalScaling == GraphRenderer.ALIGN_RIGHT) ! { ! scaleX = 1.0d * this.horizontalScale; ! offsetX = width - max * this.horizontalScale; ! } ! ! min = (x - offsetX) / scaleX; ! ! String minText = this.getFormated(min); ! Rectangle2D minBounds = metrics.getStringBounds(minText, graphics); ! String maxText = this.getFormated(max); ! Rectangle2D maxBounds = metrics.getStringBounds(maxText, graphics); ! ! // Horizontal drawing ! double bound = Math.max(minBounds.getWidth() * 4.0d, maxBounds.getWidth() * 4.0d); ! ! // Specified the number of texts ! int ticks = 1; ! while ((width / ticks) > bound) ! { ! ticks = ticks * 2; ! } ! ! // Draw the baseline ! graphics.drawLine(0, 0, (int) width, 0); ! ! // Draw the divisions ! multiplier = width / ticks / 2; ! graphics.setColor(Color.black); ! for (int i = 0; i <= (2 * ticks); i++) ! { ! int j = (int) (i * multiplier); ! graphics.drawLine(j, 0, j, FONT.getSize() / 2); ! } ! ! // Draw the ticks ! multiplier = width / ticks; ! ! // Draw first tick ! graphics.drawLine(0, 0, 0, FONT.getSize() - metrics.getDescent()); ! graphics.drawString(minText, 0, (int) (height - metrics.getDescent())); ! ! // Draw others ticks ! for (int i = 1; i < ticks; i++) ! { ! int j = (int) (i * multiplier); ! graphics.drawLine(j, 0, j, FONT.getSize() - metrics.getDescent()); ! ! display = this.getFormated(min + i * (max - min) / ticks); ! Rectangle2D middleBounds = metrics.getStringBounds(display, graphics); ! ! j = j - (int) (middleBounds.getWidth() / 2); ! ! graphics.drawString(display, j, (int) (height - metrics.getDescent())); ! } ! ! // Draw last tick ! graphics.drawLine((int) width, 0, (int) width, FONT.getSize() - metrics.getDescent()); ! graphics.drawString(maxText, (int) (width - maxBounds.getWidth()), (int) (height - metrics.getDescent())); ! } ! } --- 1,130 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.Color; ! import java.awt.FontMetrics; ! import java.awt.Graphics; ! import java.awt.Insets; ! import java.awt.geom.Rectangle2D; ! import java.text.Format; ! ! import org.ejtools.graph.Axis; ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class HorizontalAxis extends Axis ! { ! /** ! * Constructor for VerticalAxis. ! * ! * @param format Description of the Parameter ! * @param position Description of the Parameter ! */ ! public HorizontalAxis(Format format, int position) ! { ! this.format = format; ! this.orientation = HORIZONTAL; ! this.position = position; ! } ! ! ! /** ! * Description of the Method ! * ! * @param graphics Description of the Parameter ! */ ! public void paintComponent(Graphics graphics) ! { ! String display; ! double multiplier = 0.0d; ! ! graphics.setFont(FONT); ! FontMetrics metrics = graphics.getFontMetrics(); ! ! Insets insets = this.getInsets(); ! int x = insets.left; ! // int y = insets.top; ! double width = (double) this.getWidth() - 1 - insets.left - insets.right; ! double height = (double) this.getHeight() - 1 - insets.top - insets.bottom; ! ! double min = element.getXRange().getMin(); ! double max = element.getXRange().getMax(); ! ! double scaleX = width / (max - min); ! double offsetX = x - scaleX * min; ! ! if (this.horizontalScaling == GraphRenderer.ALIGN_LEFT) ! { ! scaleX = 1.0d; ! offsetX = -min; ! } ! if (this.horizontalScaling == GraphRenderer.ALIGN_RIGHT) ! { ! scaleX = 1.0d * this.horizontalScale; ! offsetX = width - max * this.horizontalScale; ! } ! ! min = (x - offsetX) / scaleX; ! ! String minText = this.getFormated(min); ! Rectangle2D minBounds = metrics.getStringBounds(minText, graphics); ! String maxText = this.getFormated(max); ! Rectangle2D maxBounds = metrics.getStringBounds(maxText, graphics); ! ! // Horizontal drawing ! double bound = Math.max(minBounds.getWidth() * 4.0d, maxBounds.getWidth() * 4.0d); ! ! // Specified the number of texts ! int ticks = 1; ! while ((width / ticks) > bound) ! { ! ticks = ticks * 2; ! } ! ! // Draw the baseline ! graphics.drawLine(0, 0, (int) width, 0); ! ! // Draw the divisions ! multiplier = width / ticks / 2; ! graphics.setColor(Color.black); ! for (int i = 0; i <= (2 * ticks); i++) ! { ! int j = (int) (i * multiplier); ! graphics.drawLine(j, 0, j, FONT.getSize() / 2); ! } ! ! // Draw the ticks ! multiplier = width / ticks; ! ! // Draw first tick ! graphics.drawLine(0, 0, 0, FONT.getSize() - metrics.getDescent()); ! graphics.drawString(minText, 0, (int) (height - metrics.getDescent())); ! ! // Draw others ticks ! for (int i = 1; i < ticks; i++) ! { ! int j = (int) (i * multiplier); ! graphics.drawLine(j, 0, j, FONT.getSize() - metrics.getDescent()); ! ! display = this.getFormated(min + i * (max - min) / ticks); ! Rectangle2D middleBounds = metrics.getStringBounds(display, graphics); ! ! j = j - (int) (middleBounds.getWidth() / 2); ! ! graphics.drawString(display, j, (int) (height - metrics.getDescent())); ! } ! ! // Draw last tick ! graphics.drawLine((int) width, 0, (int) width, FONT.getSize() - metrics.getDescent()); ! graphics.drawString(maxText, (int) (width - maxBounds.getWidth()), (int) (height - metrics.getDescent())); ! } ! } Index: JPanelGraphRenderer.java =================================================================== RCS file: /cvsroot/ejtools/libraries/graph/src/main/org/ejtools/graph/renderer/JPanelGraphRenderer.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** JPanelGraphRenderer.java 15 Sep 2003 22:11:22 -0000 1.6 --- JPanelGraphRenderer.java 13 Dec 2003 21:26:47 -0000 1.7 *************** *** 1,125 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.BorderLayout; ! import java.awt.LayoutManager; ! import java.util.Iterator; ! import java.util.Vector; ! ! import javax.swing.JComponent; ! import javax.swing.JPanel; ! ! import org.ejtools.graph.DefaultGraphElement; ! import org.ejtools.graph.GraphElement; ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class JPanelGraphRenderer extends JPanel implements GraphRenderer ! { ! /** Description of the Field */ ! protected GraphElement element = null; ! /** Description of the Field */ ! protected Vector renderers = new Vector(); ! ! ! /** ! * Constructor for JPanelGraph. ! * ! * @param layout ! */ ! public JPanelGraphRenderer(LayoutManager layout) ! { ! super(layout); ! this.element = new DefaultGraphElement(); ! } ! ! ! /** Constructor for Graph. */ ! public JPanelGraphRenderer() ! { ! this(new BorderLayout()); ! } ! ! ! /** ! * Sets the renderer attribute of the Graph object ! * ! * @param renderer The new renderer value ! */ ! public void addRenderer(GraphRenderer renderer) ! { ! renderer.setGraphElement(this.element); ! this.renderers.add(renderer); ! this.add((JComponent) renderer); ! } ! ! ! /** ! * @param element The new graphElement value ! */ ! public void setGraphElement(GraphElement element) ! { ! this.element = element; ! for (Iterator it = this.renderers.iterator(); it.hasNext(); ) ! { ! ((GraphRenderer) it.next()).setGraphElement(this.element); ! } ! } ! ! ! /** ! * @param multiplier The new horizontalScale value ! */ ! public void setHorizontalScale(double multiplier) ! { ! for (Iterator it = this.renderers.iterator(); it.hasNext(); ) ! { ! ((GraphRenderer) it.next()).setHorizontalScale(multiplier); ! } ! } ! ! ! /** ! * @param type The new horizontalScaling value ! */ ! public void setHorizontalScaling(int type) ! { ! for (Iterator it = this.renderers.iterator(); it.hasNext(); ) ! { ! ((GraphRenderer) it.next()).setHorizontalScaling(type); ! } ! } ! ! ! /** ! * @param multiplier The new verticalScale value ! */ ! public void setVerticalScale(double multiplier) ! { ! for (Iterator it = this.renderers.iterator(); it.hasNext(); ) ! { ! ((GraphRenderer) it.next()).setVerticalScale(multiplier); ! } ! } ! ! ! /** ! * @param type The new verticalScaling value ! */ ! public void setVerticalScaling(int type) ! { ! for (Iterator it = this.renderers.iterator(); it.hasNext(); ) ! { ! ((GraphRenderer) it.next()).setVerticalScaling(type); ! } ! } ! } --- 1,125 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.BorderLayout; ! import java.awt.LayoutManager; ! import java.util.Iterator; ! import java.util.Vector; ! ! import javax.swing.JComponent; ! import javax.swing.JPanel; ! ! import org.ejtools.graph.DefaultGraphElement; ! import org.ejtools.graph.GraphElement; ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class JPanelGraphRenderer extends JPanel implements GraphRenderer ! { ! /** Description of the Field */ ! protected GraphElement element = null; ! /** Description of the Field */ ! protected Vector renderers = new Vector(); ! ! ! /** ! * Constructor for JPanelGraph. ! * ! * @param layout ! */ ! public JPanelGraphRenderer(LayoutManager layout) ! { ! super(layout); ! this.element = new DefaultGraphElement(); ! } ! ! ! /** Constructor for Graph. */ ! public JPanelGraphRenderer() ! { ! this(new BorderLayout()); ! } ! ! ! /** ! * Sets the renderer attribute of the Graph object ! * ! * @param renderer The new renderer value ! */ ! public void addRenderer(GraphRenderer renderer) ! { ! renderer.setGraphElement(this.element); ! this.renderers.add(renderer); ! this.add((JComponent) renderer); ! } ! ! ! /** ! * @param element The new graphElement value ! */ ! public void setGraphElement(GraphElement element) ! { ! this.element = element; ! for (Iterator it = this.renderers.iterator(); it.hasNext(); ) ! { ! ((GraphRenderer) it.next()).setGraphElement(this.element); ! } ! } ! ! ! /** ! * @param multiplier The new horizontalScale value ! */ ! public void setHorizontalScale(double multiplier) ! { ! for (Iterator it = this.renderers.iterator(); it.hasNext(); ) ! { ! ((GraphRenderer) it.next()).setHorizontalScale(multiplier); ! } ! } ! ! ! /** ! * @param type The new horizontalScaling value ! */ ! public void setHorizontalScaling(int type) ! { ! for (Iterator it = this.renderers.iterator(); it.hasNext(); ) ! { ! ((GraphRenderer) it.next()).setHorizontalScaling(type); ! } ! } ! ! ! /** ! * @param multiplier The new verticalScale value ! */ ! public void setVerticalScale(double multiplier) ! { ! for (Iterator it = this.renderers.iterator(); it.hasNext(); ) ! { ! ((GraphRenderer) it.next()).setVerticalScale(multiplier); ! } ! } ! ! ! /** ! * @param type The new verticalScaling value ! */ ! public void setVerticalScaling(int type) ! { ! for (Iterator it = this.renderers.iterator(); it.hasNext(); ) ! { ! ((GraphRenderer) it.next()).setVerticalScaling(type); ! } ! } ! } Index: TriAxisLayoutRenderer.java =================================================================== RCS file: /cvsroot/ejtools/libraries/graph/src/main/org/ejtools/graph/renderer/TriAxisLayoutRenderer.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TriAxisLayoutRenderer.java 15 Sep 2003 22:11:22 -0000 1.7 --- TriAxisLayoutRenderer.java 13 Dec 2003 21:26:47 -0000 1.8 *************** *** 1,89 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.GridBagConstraints; ! import java.text.DecimalFormat; ! import java.text.SimpleDateFormat; ! ! import javax.swing.JComponent; ! ! import org.ejtools.graph.Axis; ! import org.ejtools.graph.GraphElement; ! import org.ejtools.graph.GraphRenderer; ! import org.ejtools.graph.LabelElement; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class TriAxisLayoutRenderer extends GridBagLayoutRenderer ! { ! /** Constructor for TriAxisGraph. */ ! public TriAxisLayoutRenderer() ! { ! super(); ! ! GridBagConstraints constraints = new GridBagConstraints(); ! ! GraphRenderer rd = new GridGraphRenderer(new SimpleDateFormat("HH:mm:ss"), new DecimalFormat("0")); ! constraints.gridx = 1; ! constraints.gridy = 1; ! constraints.fill = GridBagConstraints.BOTH; ! constraints.weightx = 1.0; ! constraints.weighty = 1.0; ! this.addRenderer(rd, constraints); ! ! Axis axis = new HorizontalAxis(new SimpleDateFormat("HH:mm:ss"), Axis.BOTTOM); ! constraints.gridx = 1; ! constraints.gridy = 2; ! constraints.fill = GridBagConstraints.HORIZONTAL; ! constraints.weightx = 0.0; ! constraints.weighty = 0.0; ! this.addRenderer(axis, constraints); ! ! axis = new VerticalAxis(new DecimalFormat("0"), Axis.LEFT); ! constraints.gridx = 0; ! constraints.gridy = 1; ! constraints.fill = GridBagConstraints.VERTICAL; ! constraints.weightx = 0.0; ! constraints.weighty = 0.0; ! this.addRenderer(axis, constraints); ! ! axis = new VerticalAxis(new DecimalFormat("0"), Axis.RIGHT); ! constraints.gridx = 2; ! constraints.gridy = 1; ! constraints.fill = GridBagConstraints.VERTICAL; ! constraints.weightx = 0.0; ! constraints.weighty = 0.0; ! this.addRenderer(axis, constraints); ! } ! ! ! /** ! * @param element The new graphElement value ! */ ! public void setGraphElement(GraphElement element) ! { ! super.setGraphElement(element); ! ! if (element instanceof LabelElement) ! { ! JComponent component = ((LabelElement) this.element).getComponent(); ! ! GridBagConstraints constraints = new GridBagConstraints(); ! constraints.gridx = 0; ! constraints.gridy = 0; ! constraints.gridwidth = 3; ! constraints.fill = GridBagConstraints.HORIZONTAL; ! constraints.weightx = 0.0; ! constraints.weighty = 0.0; ! this.add(component, constraints); ! } ! } ! } --- 1,89 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.GridBagConstraints; ! import java.text.DecimalFormat; ! import java.text.SimpleDateFormat; ! ! import javax.swing.JComponent; ! ! import org.ejtools.graph.Axis; ! import org.ejtools.graph.GraphElement; ! import org.ejtools.graph.GraphRenderer; ! import org.ejtools.graph.LabelElement; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class TriAxisLayoutRenderer extends GridBagLayoutRenderer ! { ! /** Constructor for TriAxisGraph. */ ! public TriAxisLayoutRenderer() ! { ! super(); ! ! GridBagConstraints constraints = new GridBagConstraints(); ! ! GraphRenderer rd = new GridGraphRenderer(new SimpleDateFormat("HH:mm:ss"), new DecimalFormat("0")); ! constraints.gridx = 1; ! constraints.gridy = 1; ! constraints.fill = GridBagConstraints.BOTH; ! constraints.weightx = 1.0; ! constraints.weighty = 1.0; ! this.addRenderer(rd, constraints); ! ! Axis axis = new HorizontalAxis(new SimpleDateFormat("HH:mm:ss"), Axis.BOTTOM); ! constraints.gridx = 1; ! constraints.gridy = 2; ! constraints.fill = GridBagConstraints.HORIZONTAL; ! constraints.weightx = 0.0; ! constraints.weighty = 0.0; ! this.addRenderer(axis, constraints); ! ! axis = new VerticalAxis(new DecimalFormat("0"), Axis.LEFT); ! constraints.gridx = 0; ! constraints.gridy = 1; ! constraints.fill = GridBagConstraints.VERTICAL; ! constraints.weightx = 0.0; ! constraints.weighty = 0.0; ! this.addRenderer(axis, constraints); ! ! axis = new VerticalAxis(new DecimalFormat("0"), Axis.RIGHT); ! constraints.gridx = 2; ! constraints.gridy = 1; ! constraints.fill = GridBagConstraints.VERTICAL; ! constraints.weightx = 0.0; ! constraints.weighty = 0.0; ! this.addRenderer(axis, constraints); ! } ! ! ! /** ! * @param element The new graphElement value ! */ ! public void setGraphElement(GraphElement element) ! { ! super.setGraphElement(element); ! ! if (element instanceof LabelElement) ! { ! JComponent component = ((LabelElement) this.element).getComponent(); ! ! GridBagConstraints constraints = new GridBagConstraints(); ! constraints.gridx = 0; ! constraints.gridy = 0; ! constraints.gridwidth = 3; ! constraints.fill = GridBagConstraints.HORIZONTAL; ! constraints.weightx = 0.0; ! constraints.weighty = 0.0; ! this.add(component, constraints); ! } ! } ! } Index: VerticalAxis.java =================================================================== RCS file: /cvsroot/ejtools/libraries/graph/src/main/org/ejtools/graph/renderer/VerticalAxis.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** VerticalAxis.java 15 Sep 2003 22:11:22 -0000 1.6 --- VerticalAxis.java 13 Dec 2003 21:26:47 -0000 1.7 *************** *** 1,159 **** ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.Color; ! import java.awt.Dimension; ! import java.awt.FontMetrics; ! import java.awt.Graphics; ! import java.awt.Insets; ! import java.awt.geom.Rectangle2D; ! import java.text.Format; ! ! import org.ejtools.graph.Axis; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class VerticalAxis extends Axis ! { ! /** ! * Constructor for VerticalAxis. ! * ! * @param format Description of the Parameter ! * @param position Description of the Parameter ! */ ! public VerticalAxis(Format format, int position) ! { ! this.format = format; ! this.orientation = VERTICAL; ! this.position = position; ! } ! ! ! /** ! * Description of the Method ! * ! * @param graphics Description of the Parameter ! */ ! public void paintComponent(Graphics graphics) ! { ! String display; ! double multiplier = 0.0d; ! int base; ! int small; ! int middle; ! int correction; ! ! graphics.setFont(FONT); ! FontMetrics metrics = graphics.getFontMetrics(); ! ! Insets insets = this.getInsets(); ! // int x = this.getX() + insets.left; ! // int y = this.getY() + insets.top; ! // double width = (double) this.getWidth() - 1 - insets.left - insets.right; ! double height = (double) this.getHeight() - 1 - insets.top - insets.bottom; ! ! double min = element.getYRange().getMin(); ! double max = element.getYRange().getMax(); ! ! String minText = this.getFormated(min); ! Rectangle2D minBounds = metrics.getStringBounds(minText, graphics); ! String maxText = this.getFormated(max); ! Rectangle2D maxBounds = metrics.getStringBounds(maxText, graphics); ! ! // New dimension ! double newBound = Math.max(minBounds.getWidth(), maxBounds.getWidth()); ! this.dimension = new Dimension((int) (newBound + FONT.getSize()), this.getHeight()); ! this.revalidate(); ! ! // Vertical drawing ! double bound = Math.max(minBounds.getHeight() * 4.0d, maxBounds.getHeight() * 4.0d); ! ! // Specified the number of texts ! int ticks = 1; ! while ((height / ticks) > bound) ! { ! ticks = ticks * 2; ! } ! ! // Set parameters ! if (this.position == LEFT) ! { ! middle = (int) (newBound); ! small = middle + FONT.getSize() / 2 - 1; ! base = middle + FONT.getSize() - 1; ! } ! else ! { ! middle = FONT.getSize() - 2; ! small = FONT.getSize() / 2 - 1; ! base = 0; ! } ! ! // Draw the baseline ! graphics.drawLine(base, 0, base, (int) height); ! ! // Draw the divisions ! multiplier = height / ticks / 2; ! graphics.setColor(Color.black); ! for (int i = 0; i <= (2 * ticks); i++) ! { ! graphics.drawLine(base, (int) (i * multiplier), small, (int) (i * multiplier)); ! } ! ! // draw ticks ! multiplier = height / ticks; ! ! // Draw first tick ! graphics.drawLine(base, (int) height, middle, (int) height); ! if (this.position == LEFT) ! { ! correction = -(int) minBounds.getWidth(); ! } ! else ! { ! correction = 2; ! } ! graphics.drawString(minText, middle + correction, (int) (height - metrics.getDescent())); ! ! // Draw others ticks ! for (int i = 1; i < ticks; i++) ! { ! int j = (int) (height - i * multiplier); ! graphics.drawLine(base, j, middle, j); ! ! display = this.getFormated(min + i * (max - min) / ticks); ! Rectangle2D middleBounds = metrics.getStringBounds(display, graphics); ! ! j = j + (int) (middleBounds.getHeight() / 2); ! if (this.position == LEFT) ! { ! correction = -(int) middleBounds.getWidth(); ! } ! else ! { ! correction = 2; ! } ! graphics.drawString(display, middle + correction, j); ! } ! ! // Draw last tick ! graphics.drawLine(base, 0, middle, 0); ! if (this.position == LEFT) ! { ! correction = -(int) maxBounds.getWidth(); ! } ! else ! { ! correction = 2; ! } ! graphics.drawString(maxText, middle + correction, metrics.getAscent()); ! } ! } --- 1,159 ---- ! /* ! * EJTools, the Enterprise Java Tools ! * ! * Distributable under LGPL license. ! * See terms of license at www.gnu.org. ! */ ! package org.ejtools.graph.renderer; ! ! import java.awt.Color; ! import java.awt.Dimension; ! import java.awt.FontMetrics; ! import java.awt.Graphics; ! import java.awt.Insets; ! import java.awt.geom.Rectangle2D; ! import java.text.Format; ! ! import org.ejtools.graph.Axis; ! ! /** ! * @author Laurent Etiemble ! * @version $Revision$ ! * @todo Javadoc to complete ! */ ! public class VerticalAxis extends Axis ! { ! /** ! * Constructor for VerticalAxis. ! * ! * @param format Description of the Parameter ! * @param position Description of the Parameter ! */ ! public VerticalAxis(Format format, int position) ! { ! this.format = format; ! this.orientation = VERTICAL; ! this.position = position; ! } ! ! ! /** ! * Description of the Method ! * ! * @param graphics Description of the Parameter ! */ ! public void paintComponent(Graphics graphics) ! { ! String display; ! double multiplier = 0.0d; ! int base; ! int small; ! int middle; ! int correction; ! ! graphics.setFont(FONT); ! FontMetrics metrics = graphics.getFontMetrics(); ! ! Insets insets = this.getInsets(); ! // int x = this.getX() + insets.left; ! // int y = this.getY() + insets.top; ! // double width = (double) this.getWidth() - 1 - insets.left - insets.right; ! double height = (double) this.getHeight() - 1 - insets.top - insets.bottom; ! ! double min = element.getYRange().getMin(); ! double max = element.getYRange().getMax(); ! ! String minText = this.getFormated(min); ! Rectangle2D minBounds = metrics.getStringBounds(minText, graphics); ! String maxText = this.getFormated(max); ! Rectangle2D maxBounds = metrics.getStringBounds(maxText, graphics); ! ! // New dimension ! double newBound = Math.max(minBounds.getWidth(), maxBounds.getWidth()); ! this.dimension = new Dimension((int) (newBound + FONT.getSize()), this.getHeight()); ! this.revalidate(); ! ! // Vertical drawing ! double bound = Math.max(minBounds.getHeight() * 4.0d, maxBounds.getHeight() * 4.0d); ! ! // Specified the number of texts ! int ticks = 1; ! while ((height / ticks) > bound) ! { ! ticks = ticks * 2; ! } ! ! // Set parameters ! if (this.position == LEFT) ! { ! middle = (int) (newBound); ! small = middle + FONT.getSize() / 2 - 1; ! base = middle + FONT.getSize() - 1; ! } ! else ! { ! middle = FONT.getSize() - 2; ! small = FONT.getSize() / 2 - 1; ! base = 0; ! } ! ! // Draw the baseline ! graphics.drawLine(base, 0, base, (int) height); ! ! // Draw the divisions ! multiplier = height / ticks / 2; ! graphics.setColor(Color.black); ! for (int i = 0; i <= (2 * ticks); i++) ! { ! graphics.drawLine(base, (int) (i * multiplier), small, (int) (i * multiplier)); ! } ! ! // draw ticks ! multiplier = height / ticks; ! ! // Draw first tick ! graphics.drawLine(base, (int) height, middle, (int) height); ! if (this.position == LEFT) ! { ! correction = -(int) minBounds.getWidth(); ! } ! else ! { ! correction = 2; ! } ! graphics.drawString(minText, middle + correction, (int) (height - metrics.getDescent())); ! ! // Draw others ticks ! for (int i = 1; i < ticks; i++) ! { ! int j = (int) (height - i * multiplier); ! graphics.drawLine(base, j, middle, j); ! ! display = this.getFormated(min + i * (max - min) / ticks); ! Rectangle2D middleBounds = metrics.getStringBounds(display, graphics); ! ! j = j + (int) (middleBounds.getHeight() / 2); ! if (this.position == LEFT) ! { ! correction = -(int) middleBounds.getWidth(); ! } ! else ! { ! correction = 2; ! } ! graphics.drawString(display, middle + correction, j); ! } ! ! // Draw last tick ! graphics.drawLine(base, 0, middle, 0); ! if (this.position == LEFT) ! { ! correction = -(int) maxBounds.getWidth(); ! } ! else ! { ! correction = 2; ! } ! graphics.drawString(maxText, middle + correction, metrics.getAscent()); ! } ! } |