Thread: [Ejtools-cvs] libraries/graph/src/main/org/ejtools/graph/renderer AbstractGraphRenderer.java,1.4,1.5
Brought to you by:
letiemble
|
From: <let...@us...> - 2003-09-15 22:02:57
|
Update of /cvsroot/ejtools/libraries/graph/src/main/org/ejtools/graph/renderer In directory sc8-pr-cvs1:/tmp/cvs-serv15147/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: Change Eclipse project and classpath definition Add export as Image and Text functions Index: AbstractGraphRenderer.java =================================================================== RCS file: /cvsroot/ejtools/libraries/graph/src/main/org/ejtools/graph/renderer/AbstractGraphRenderer.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AbstractGraphRenderer.java 8 Jan 2003 21:14:28 -0000 1.4 --- AbstractGraphRenderer.java 15 Sep 2003 22:02:50 -0000 1.5 *************** *** 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.Graphics; ! ! import javax.swing.JComponent; ! ! import org.ejtools.graph.GraphElement; ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author <a href="mailto:let...@us...">Laurent Etiemble</a> ! * @created 31 octobre 2002 ! * @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,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.Graphics; ! ! import javax.swing.JComponent; ! ! import org.ejtools.graph.GraphElement; ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author <a href="mailto:let...@us...">Laurent Etiemble</a> ! * @created 31 octobre 2002 ! * @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.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** BorderLayoutRenderer.java 21 Dec 2002 22:07:45 -0000 1.3 --- BorderLayoutRenderer.java 15 Sep 2003 22:02:50 -0000 1.4 *************** *** 1,45 **** ! /* ! * 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 <a href="mailto:let...@us...">Laurent Etiemble</a> ! * @created 31 octobre 2002 ! * @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,45 ---- ! /* ! * 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 <a href="mailto:let...@us...">Laurent Etiemble</a> ! * @created 31 octobre 2002 ! * @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.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DefaultGraphRenderer.java 8 Jan 2003 21:14:26 -0000 1.5 --- DefaultGraphRenderer.java 15 Sep 2003 22:02:50 -0000 1.6 *************** *** 1,63 **** ! /* ! * 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 <a href="mailto:let...@us...">Laurent Etiemble</a> ! * @created 31 octobre 2002 ! * @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,63 ---- ! /* ! * 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 <a href="mailto:let...@us...">Laurent Etiemble</a> ! * @created 31 octobre 2002 ! * @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.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GridBagLayoutRenderer.java 21 Dec 2002 22:07:45 -0000 1.3 --- GridBagLayoutRenderer.java 15 Sep 2003 22:02:50 -0000 1.4 *************** *** 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.GridBagConstraints; ! import java.awt.GridBagLayout; ! ! import javax.swing.JComponent; ! ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author <a href="mailto:let...@us...">Laurent Etiemble</a> ! * @created 31 octobre 2002 ! * @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,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.GridBagConstraints; ! import java.awt.GridBagLayout; ! ! import javax.swing.JComponent; ! ! import org.ejtools.graph.GraphRenderer; ! ! /** ! * @author <a href="mailto:let...@us...">Laurent Etiemble</a> ! * @created 31 octobre 2002 ! * @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.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GridGraphRenderer.java 8 Jan 2003 21:14:26 -0000 1.4 --- GridGraphRenderer.java 15 Sep 2003 22:02:50 -0000 1.5 *************** *** 1,138 **** ! /* ! * 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 <a href="mailto:let...@us...">Laurent Etiemble</a> ! * @created 31 octobre 2002 ! * @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,138 ---- ! /* ! * 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 <a href="mailto:let...@us...">Laurent Etiemble</a> ! * @created 31 octobre 2002 ! * @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.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** HorizontalAxis.java 21 Dec 2002 22:07:45 -0000 1.4 --- HorizontalAxis.java 15 Sep 2003 22:02:50 -0000 1.5 *************** *** 1,131 **** ! /* ! * 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 <a href="mailto:let...@us...">Laurent Etiemble</a> ! * @created 31 octobre 2002 ! * @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,131 ---- ! /* ! * 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 <a href="mailto:let...@us...">Laurent Etiemble</a> ! * @created 31 octobre 2002 ! * @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 = ele... [truncated message content] |