1 package com.acmemail.judah.cartesian_plane;
2
3 import java.awt.BasicStroke;
4 import java.awt.Color;
5 import java.awt.Dimension;
6 import java.awt.Font;
7 import java.awt.Graphics;
8 import java.awt.Graphics2D;
9 import java.awt.Shape;
10 import java.awt.font.FontRenderContext;
11 import java.awt.font.TextLayout;
12 import java.awt.geom.Line2D;
13 import java.awt.geom.Rectangle2D;
14 import java.beans.PropertyChangeEvent;
15 import java.beans.PropertyChangeListener;
16 import java.util.Iterator;
17 import java.util.function.Supplier;
18 import java.util.stream.Stream;
19 import java.util.stream.StreamSupport;
20
21 import javax.swing.JPanel;
22
23 /**
24 * This class encapsulates the display of a Cartesian plane.
25 * The plane consists of the following components,
26 +--372 lines: * each of which is customizable by the user.----------------------
398 * </table>
399 *
400 * @author Jack Straub
401 */
402 @SuppressWarnings("serial")
403 public class CartesianPlane
404 extends JPanel implements PropertyChangeListener
---------------------------------------------------------------------------
405 {
406 /**
407 * This declaration is just for convenience; it saves
408 * having to write "PropertyManager.INSTANCE" over and over.
409 */
410 private static final PropertyManager pmgr = PropertyManager.INSTANCE;
411 +-- 38 lines: private static final int mainWindowWidthDV =-----------------
449 pmgr.asColor( CPConstants.MARGIN_BOTTOM_BG_COLOR_PN );
450 private float marginLeftWidth =
451 pmgr.asFloat( CPConstants.MARGIN_LEFT_WIDTH_PN );
452 private Color marginLeftBGColor =
453 pmgr.asColor( CPConstants.MARGIN_LEFT_BG_COLOR_PN );
454
455 /////////////////////////////////////////////////
456 // Tic mark properties
457 /////////////////////////////////////////////////
458 private Color ticMinorColor =
459 pmgr.asColor( CPConstants.TIC_MINOR_COLOR_PN );
460 private float ticMinorWeight =
461 pmgr.asFloat( CPConstants.TIC_MINOR_WEIGHT_PN );
462 private float ticMinorLen =
463 pmgr.asFloat( CPConstants.TIC_MINOR_LEN_PN );
464 private float ticMinorMPU =
465 pmgr.asFloat( CPConstants.TIC_MINOR_MPU_PN );
466 private boolean ticMinorDraw =
467 pmgr.asBoolean( CPConstants.TIC_MINOR_DRAW_PN );
468 private Color ticMajorColor =
469 pmgr.asColor( CPConstants.TIC_MAJOR_COLOR_PN );
470 private float ticMajorWeight =
471 pmgr.asFloat( CPConstants.TIC_MAJOR_WEIGHT_PN );
472 private float ticMajorLen =
473 pmgr.asFloat( CPConstants.TIC_MAJOR_LEN_PN );
474 private float ticMajorMPU =
475 pmgr.asFloat( CPConstants.TIC_MAJOR_MPU_PN );
476 private boolean ticMajorDraw =
477 pmgr.asBoolean( CPConstants.TIC_MAJOR_DRAW_PN );
478
479 /////////////////////////////////////////////////
480 // Grid line properties
481 /////////////////////////////////////////////////
482 private Color gridLineColor =
483 pmgr.asColor( CPConstants.GRID_LINE_COLOR_PN );
484 private float gridLineWeight =
485 pmgr.asFloat( CPConstants.GRID_LINE_WEIGHT_PN );
486 private float gridLineLPU =
487 pmgr.asFloat( CPConstants.GRID_LINE_LPU_PN );
488 private boolean gridLineDraw =
489 pmgr.asBoolean( CPConstants.GRID_LINE_DRAW_PN );
490
491 /////////////////////////////////////////////////
492 // Axis properties
493 /////////////////////////////////////////////////
494 private Color axisColor =
495 pmgr.asColor( CPConstants.AXIS_COLOR_PN );
496 private float axisWeight =
497 pmgr.asFloat( CPConstants.AXIS_WEIGHT_PN );
498
499 /////////////////////////////////////////////////
500 // Label properties (these are the labels that
501 // go on the x- and y-axes, e.g., 1.1, 1.2)
502 /////////////////////////////////////////////////
503 private Color labelFontColor =
504 pmgr.asColor( CPConstants.LABEL_FONT_COLOR_PN );
505 private String labelFontName =
506 pmgr.asString( CPConstants.LABEL_FONT_NAME_PN );
507 private int labelFontStyle =
508 pmgr.asFontStyle( CPConstants.LABEL_FONT_STYLE_PN );
509 private float labelFontSize =
510 pmgr.asFloat( CPConstants.LABEL_FONT_SIZE_PN );
511 private boolean labelDraw =
512 pmgr.asBoolean( CPConstants.LABEL_DRAW_PN );
513
514 /**
515 * Supplier, set by the user,
516 * to obtain a stream of PlotCommands.
517 */
518 private Supplier<Stream<PlotCommand>> streamSupplier =
519 () -> Stream.empty();
520 +-- 2 lines: ///////////////////////////////////////////////-------------------
522 // Plot properties (properties to use
523 // when plotting a point on the grid)
524 /////////////////////////////////////////////////
525 private Color plotColor =
526 pmgr.asColor( CPConstants.PLOT_COLOR_PN );
527 private PlotShape plotShape = new PointShape();
---------------------------------------------------------------------------
---------------------------------------------------------------------------
528
529 ///////////////////////////////////////////////////////
530 //
531 // The following values are recalculated every time
532 // paintComponent is invoked.
533 //
534 ///////////////////////////////////////////////////////
535 private int currWidth;
536 private int currHeight;
537 private Graphics2D gtx;
538 private Rectangle2D gridRect;
539 private Font labelFont;
540 private FontRenderContext labelFRC;
541 private PlotShape currPlotShape;
542 private double xOffset;
543 private double yOffset;
544
545 /**
546 * Constructor.
547 +-- 19 lines: * Builds a CartesianPlane with a default width and height.--------
566
567 // Register listener for redraw notifications
568 NotificationManager.INSTANCE.addNotificationListener(
569 CPConstants.REDRAW_NP,
570 e -> repaint()
571 );
---------------------------------------------------------------------------
---------------------------------------------------------------------------
572 }
573
574 /**
575 * This method is where you do all your drawing.
576 * Note the the window must be COMPLETELY redrawn
577 * every time this method is called;
578 +-- 9 lines: * Java does not remember anything you previously drew.------------
587 currWidth = getWidth();
588 currHeight = getHeight();
589 gtx = (Graphics2D)graphics.create();
590 gtx.setColor( mwBGColor );
591 gtx.fillRect( 0, 0, currWidth, currHeight );
592 // end boilerplate
593
594 // set up the label font
595 // round font size to nearest int
596 int fontSize = (int)(labelFontSize + .5);
597 labelFont = new Font( labelFontName, labelFontStyle, fontSize );
598 gtx.setFont( labelFont );
599 labelFRC = gtx.getFontRenderContext();
600
601 // Describe the rectangle containing the grid
602 float gridWidth = currWidth - marginLeftWidth - marginRightWidth;
603 float minXco = marginLeftWidth;
604 float gridHeight = currHeight - marginTopWidth - marginBottomWidth;
605 float minYco = marginTopWidth;
606 +-- 12 lines: gridRect = -------------------------------------------------------
618 // change the values but they will only be in effect
619 // for the duration of one paintComponent execute; with
620 // the next paintComponent execution they will return
621 // to their default values.
622 currPlotShape = plotShape;
623
624 // Values to use in mapping Cartesian coordinates to pixel coordinates
---------------------------------------------------------------------------
625 xOffset = gridRect.getX() + (gridRect.getWidth() - 1) / 2;
626 yOffset = gridRect.getY() + (gridRect.getHeight() - 1) / 2;
627
628 drawGridLines();
629 drawMinorTics();
630 drawMajorTics();
631 drawAxes();
632 drawUserPlot();
633
634 gtx.setClip( origClip );
635
636 if ( labelDraw )
637 {
638 gtx.setColor( labelFontColor );
639 drawHorizontalLabels();
640 drawVerticalLabels();
641 }
642 paintMargins();
643
644 // begin boilerplate
645 gtx.dispose();
646 // end boilerplate
647 }
648 +-- 29 lines: public void plotPoint( float userXco, float userYco )-------------
677 }
678
679 public void propertyChange( PropertyChangeEvent evt )
680 {
681 String pName = evt.getPropertyName();
682 String newVal = (String)evt.getNewValue();
---------------------------------------------------------------------------
683 switch ( pName )
684 {
685 case CPConstants.GRID_UNIT_PN:
686 gridUnit = CPConstants.asFloat( newVal );
687 repaint();
688 break;
689 case CPConstants.MW_BG_COLOR_PN:
690 mwBGColor = CPConstants.asColor( newVal );
691 repaint();
692 break;
693 case CPConstants.MARGIN_TOP_WIDTH_PN:
694 marginTopWidth = CPConstants.asFloat( newVal );
695 repaint();
696 break;
697 case CPConstants.MARGIN_TOP_BG_COLOR_PN:
698 marginTopBGColor = CPConstants.asColor( newVal );
699 repaint();
700 break;
701 case CPConstants.MARGIN_RIGHT_WIDTH_PN:
702 marginRightWidth = CPConstants.asFloat( newVal );
703 repaint();
704 break;
705 case CPConstants.MARGIN_RIGHT_BG_COLOR_PN:
706 marginRightBGColor = CPConstants.asColor( newVal );
707 repaint();
708 break;
709 case CPConstants.MARGIN_BOTTOM_WIDTH_PN:
710 marginBottomWidth = CPConstants.asFloat( newVal );
711 repaint();
712 break;
713 case CPConstants.MARGIN_BOTTOM_BG_COLOR_PN:
714 marginBottomBGColor = CPConstants.asColor( newVal );
715 repaint();
716 break;
717 case CPConstants.MARGIN_LEFT_WIDTH_PN:
718 marginLeftWidth = CPConstants.asFloat( newVal );
719 repaint();
720 break;
721 case CPConstants.MARGIN_LEFT_BG_COLOR_PN:
722 marginLeftBGColor = CPConstants.asColor( newVal );
723 repaint();
724 break;
725 case CPConstants.TIC_MINOR_COLOR_PN:
726 ticMinorColor = CPConstants.asColor( newVal );
727 repaint();
728 break;
729 case CPConstants.TIC_MINOR_WEIGHT_PN:
730 ticMinorWeight = CPConstants.asFloat( newVal );
731 repaint();
732 break;
733 case CPConstants.TIC_MINOR_LEN_PN:
734 ticMinorLen = CPConstants.asFloat( newVal );
735 repaint();
736 break;
737 case CPConstants.TIC_MINOR_MPU_PN:
738 ticMinorMPU = CPConstants.asFloat( newVal );
739 repaint();
740 break;
741 case CPConstants.TIC_MINOR_DRAW_PN:
742 ticMinorDraw = CPConstants.asBoolean( newVal );
743 repaint();
744 break;
745 case CPConstants.TIC_MAJOR_COLOR_PN:
746 ticMajorColor = CPConstants.asColor( newVal );
747 repaint();
748 break;
749 case CPConstants.TIC_MAJOR_WEIGHT_PN:
750 ticMajorWeight = CPConstants.asFloat( newVal );
751 repaint();
752 break;
753 case CPConstants.TIC_MAJOR_LEN_PN:
754 ticMajorLen = CPConstants.asFloat( newVal );
755 repaint();
756 break;
757 case CPConstants.TIC_MAJOR_MPU_PN:
758 ticMajorMPU = CPConstants.asFloat( newVal );
759 repaint();
760 break;
761 case CPConstants.TIC_MAJOR_DRAW_PN:
762 ticMajorDraw = CPConstants.asBoolean( newVal );
763 repaint();
764 break;
765 case CPConstants.GRID_LINE_COLOR_PN:
766 gridLineColor = CPConstants.asColor( newVal );
767 repaint();
768 break;
769 case CPConstants.GRID_LINE_WEIGHT_PN:
770 gridLineWeight = CPConstants.asFloat( newVal );
771 repaint();
772 break;
773 case CPConstants.GRID_LINE_LPU_PN:
774 gridLineLPU = CPConstants.asFloat( newVal );
775 repaint();
776 break;
777 case CPConstants.GRID_LINE_DRAW_PN:
778 gridLineDraw = CPConstants.asBoolean( newVal );
779 repaint();
780 break;
781 case CPConstants.AXIS_COLOR_PN:
782 axisColor = CPConstants.asColor( newVal );
783 repaint();
784 break;
785 case CPConstants.AXIS_WEIGHT_PN:
786 axisWeight = CPConstants.asFloat( newVal );
787 repaint();
788 break;
789 case CPConstants.LABEL_FONT_COLOR_PN:
790 labelFontColor = CPConstants.asColor( newVal );
791 repaint();
792 break;
793 case CPConstants.LABEL_FONT_NAME_PN:
794 labelFontName = newVal;
795 repaint();
796 break;
797 case CPConstants.LABEL_FONT_STYLE_PN:
798 labelFontStyle = CPConstants.asFontStyle( newVal );
799 repaint();
800 break;
801 case CPConstants.LABEL_FONT_SIZE_PN:
802 labelFontSize = CPConstants.asFloat( newVal );
803 repaint();
804 break;
805 case CPConstants.LABEL_DRAW_PN:
806 labelDraw = CPConstants.asBoolean( newVal );
807 repaint();
808 break;
809 }
---------------------------------------------------------------------------
---------------------------------------------------------------------------
---------------------------------------------------------------------------
---------------------------------------------------------------------------
---------------------------------------------------------------------------
---------------------------------------------------------------------------
810 }
811
812 /**
813 * Sets the supplier
814 * that will fetch a stream
815 * to deliver commands
816 +-- 15 lines: * for plotting a curve.-------------------------------------------
831 private void drawUserPlot()
832 {
833 gtx.setColor( plotColor );
834 streamSupplier.get().forEach( c -> c.execute() );
835 }
836
837 /**
838 * Draws the x- and y-axes on the graph.
839 */
840 private void drawAxes()
841 {
842 gtx.setColor( axisColor );
843 gtx.setStroke( new BasicStroke( axisWeight ) );
844
845 Iterator<Line2D> axes =
846 LineGenerator.axesIterator( gridRect );
847 gtx.draw( axes.next() );
848 gtx.draw( axes.next() );
849 }
850
851 /**
852 * Draws the grid lines on the graph.
853 */
854 private void drawGridLines()
855 {
856 if ( gridLineDraw )
857 {
858 LineGenerator lineGen =
859 new LineGenerator( gridRect, gridUnit, gridLineLPU );
860 gtx.setStroke( new BasicStroke( gridLineWeight ) );
861 gtx.setColor( gridLineColor );
862 lineGen.forEach( gtx::draw );
863 }
864 }
865
866 /**
867 * Draws the minor tics on the graph.
868 */
869 private void drawMinorTics()
870 {
871 if ( ticMinorDraw )
872 {
873 LineGenerator lineGen =
874 new LineGenerator(
875 gridRect,
876 gridUnit,
877 ticMinorMPU,
878 ticMinorLen,
879 LineGenerator.BOTH
880 );
881 gtx.setStroke( new BasicStroke( ticMinorWeight ) );
882 gtx.setColor( ticMinorColor );
883 StreamSupport
884 .stream( lineGen.spliterator(), false )
885 .forEach( gtx:: draw );
886 }
887 }
888
889 /**
890 * Draws the major tics on the graph.
891 */
892 private void drawMajorTics()
893 {
894 if ( ticMajorDraw )
895 {
896 LineGenerator lineGen =
897 new LineGenerator(
898 gridRect,
899 gridUnit,
900 ticMajorMPU,
901 ticMajorLen,
902 LineGenerator.BOTH
903 );
904 gtx.setStroke( new BasicStroke( ticMajorWeight ) );
905 gtx.setColor( ticMajorColor );
906 StreamSupport
907 .stream( lineGen.spliterator(), false )
908 .forEach( gtx::draw );
909 }
910 }
911
912 /**
913 * Draw the labels on the horizontal tic marks
914 * (top to bottom of y-axis).
915 */
916 private void drawHorizontalLabels()
917 {
918 // padding between tic mark and label
919 final int labelPadding = 3;
920
921 LineGenerator lineGen =
922 new LineGenerator(
923 gridRect,
924 gridUnit,
925 ticMajorMPU,
926 ticMajorLen,
927 LineGenerator.HORIZONTAL
928 );
929 float spacing = gridUnit / ticMajorMPU;
930 float labelIncr = 1 / ticMajorMPU;
931 float originYco = (float)gridRect.getCenterY();
932 for ( Line2D line : lineGen )
933 {
934 float xco2 = (float)line.getX2();
935 float yco1 = (float)line.getY1();
936 int dist = (int)((originYco - yco1) / spacing);
937 float next = dist * labelIncr;
938 String label = String.format( "%3.2f", next );
939 TextLayout layout =
940 new TextLayout( label, labelFont, labelFRC );
941 Rectangle2D bounds = layout.getBounds();
942 float yOffset = (float)(bounds.getHeight() / 2);
943 float xco = xco2 + labelPadding;
944 float yco = yco1 + yOffset;
945 layout.draw( gtx, xco, yco );
946 }
947 }
948
949 /**
950 * Draw the labels on the vertical tic marks
951 * (left to right on x-axis).
952 */
953 private void drawVerticalLabels()
954 {
955 // padding between tic mark and label
956 final int labelPadding = 3;
957
958 LineGenerator lineGen =
959 new LineGenerator(
960 gridRect,
961 gridUnit,
962 ticMajorMPU,
963 ticMajorLen,
964 LineGenerator.VERTICAL
965 );
966 float spacing = gridUnit / ticMajorMPU;
967 float labelIncr = 1 / ticMajorMPU;
968 float originXco = (float)gridRect.getCenterX();
969 for ( Line2D line : lineGen )
970 {
971 float xco1 = (float)line.getX2();
972 int dist = (int)((xco1 - originXco) / spacing);
973 float next = dist * labelIncr;
974 String label = String.format( "%3.2f", next );
975
976 TextLayout layout =
977 new TextLayout( label, labelFont, labelFRC );
978 Rectangle2D bounds = layout.getBounds();
979 float yOffset =
980 (float)(bounds.getHeight() + labelPadding);
981 float xOffset = (float)(bounds.getWidth() / 2);
982 float xco = xco1 - xOffset;
983 float yco = (float)line.getY2() + yOffset;
984 layout.draw( gtx, xco, yco );
985 }
986 }
987
988 private void paintMargins()
989 {
990 Rectangle2D rect = new Rectangle2D.Float();
991
992 // top margin
993 rect.setRect( 0, 0, currWidth, marginTopWidth );
994 +-- 21 lines: gtx.setColor( marginTopBGColor );---------------------------------
|
1 package com.acmemail.judah.cartesian_plane;
2
----------------------------------------------------------------------------
3 import java.awt.Color;
4 import java.awt.Dimension;
----------------------------------------------------------------------------
5 import java.awt.Graphics;
6 import java.awt.Graphics2D;
7 import java.awt.Shape;
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
8 import java.awt.geom.Rectangle2D;
9 import java.beans.PropertyChangeEvent;
10 import java.beans.PropertyChangeListener;
----------------------------------------------------------------------------
11 import java.util.function.Supplier;
12 import java.util.stream.Stream;
----------------------------------------------------------------------------
13
14 import javax.swing.JPanel;
15
16 /**
17 * This class encapsulates the display of a Cartesian plane.
18 * The plane consists of the following components,
19 +--372 lines: * each of which is customizable by the user.----------------------
391 * </table>
392 *
393 * @author Jack Straub
394 */
395 @SuppressWarnings("serial")
396 public class CartesianPlane
397 extends JPanel
398 implements PropertyChangeListener
399 {
400 /**
401 * This declaration is just for convenience; it saves
402 * having to write "PropertyManager.INSTANCE" over and over.
403 */
404 private static final PropertyManager pmgr = PropertyManager.INSTANCE;
405 +-- 38 lines: private static final int mainWindowWidthDV =-----------------
443 pmgr.asColor( CPConstants.MARGIN_BOTTOM_BG_COLOR_PN );
444 private float marginLeftWidth =
445 pmgr.asFloat( CPConstants.MARGIN_LEFT_WIDTH_PN );
446 private Color marginLeftBGColor =
447 pmgr.asColor( CPConstants.MARGIN_LEFT_BG_COLOR_PN );
448
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
449 /**
450 * Supplier, set by the user,
451 * to obtain a stream of PlotCommands.
452 */
453 private Supplier<Stream<PlotCommand>> streamSupplier =
454 () -> Stream.empty();
455 +-- 2 lines: ///////////////////////////////////////////////-------------------
457 // Plot properties (properties to use
458 // when plotting a point on the grid)
459 /////////////////////////////////////////////////
460 private Color plotColor =
461 pmgr.asColor( CPConstants.PLOT_COLOR_PN );
462 private PlotShape plotShape = new PointShape();
463
464 private GraphManager graphMgr;
465
466 ///////////////////////////////////////////////////////
467 //
468 // The following values are recalculated every time
469 // paintComponent is invoked.
470 //
471 ///////////////////////////////////////////////////////
472 private int currWidth;
473 private int currHeight;
474 private Graphics2D gtx;
475 private Rectangle2D gridRect;
----------------------------------------------------------------------------
----------------------------------------------------------------------------
476 private PlotShape currPlotShape;
477 private double xOffset;
478 private double yOffset;
479
480 /**
481 * Constructor.
482 +-- 19 lines: * Builds a CartesianPlane with a default width and height.--------
501
502 // Register listener for redraw notifications
503 NotificationManager.INSTANCE.addNotificationListener(
504 CPConstants.REDRAW_NP,
505 e -> repaint()
506 );
507
508 graphMgr = new GraphManager( gridRect, new Profile() );
509 }
510
511 /**
512 * This method is where you do all your drawing.
513 * Note the the window must be COMPLETELY redrawn
514 * every time this method is called;
515 +-- 9 lines: * Java does not remember anything you previously drew.------------
524 currWidth = getWidth();
525 currHeight = getHeight();
526 gtx = (Graphics2D)graphics.create();
527 gtx.setColor( mwBGColor );
528 gtx.fillRect( 0, 0, currWidth, currHeight );
529 // end boilerplate
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
530
531 // Describe the rectangle containing the grid
532 float gridWidth = currWidth - marginLeftWidth - marginRightWidth;
533 float minXco = marginLeftWidth;
534 float gridHeight = currHeight - marginTopWidth - marginBottomWidth;
535 float minYco = marginTopWidth;
536 +-- 12 lines: gridRect = -------------------------------------------------------
548 // change the values but they will only be in effect
549 // for the duration of one paintComponent execute; with
550 // the next paintComponent execution they will return
551 // to their default values.
552 currPlotShape = plotShape;
553
554 // Values to use in mapping Cartesian coordinates
555 // to pixel coordinates
556 xOffset = gridRect.getX() + (gridRect.getWidth() - 1) / 2;
557 yOffset = gridRect.getY() + (gridRect.getHeight() - 1) / 2;
558
559 graphMgr.refresh( gtx, gridRect );
560 graphMgr.drawAll();
----------------------------------------------------------------------------
----------------------------------------------------------------------------
561 drawUserPlot();
562
563 gtx.setClip( origClip );
564
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
565 paintMargins();
566
567 // begin boilerplate
568 gtx.dispose();
569 // end boilerplate
570 }
571 +-- 29 lines: public void plotPoint( float userXco, float userYco )-------------
600 }
601
602 public void propertyChange( PropertyChangeEvent evt )
603 {
604 String pName = evt.getPropertyName();
605 String newVal = (String)evt.getNewValue();
606 boolean update = false;
607 switch ( pName )
608 {
609 case CPConstants.GRID_UNIT_PN:
610 gridUnit = CPConstants.asFloat( newVal );
611 update = true;
612 break;
613 case CPConstants.MW_BG_COLOR_PN:
614 mwBGColor = CPConstants.asColor( newVal );
615 update = true;
616 break;
617 case CPConstants.MARGIN_TOP_WIDTH_PN:
618 marginTopWidth = CPConstants.asFloat( newVal );
619 update = true;
620 break;
621 case CPConstants.MARGIN_TOP_BG_COLOR_PN:
622 marginTopBGColor = CPConstants.asColor( newVal );
623 update = true;
624 break;
625 case CPConstants.MARGIN_RIGHT_WIDTH_PN:
626 marginRightWidth = CPConstants.asFloat( newVal );
627 update = true;
628 break;
629 case CPConstants.MARGIN_RIGHT_BG_COLOR_PN:
630 marginRightBGColor = CPConstants.asColor( newVal );
631 update = true;
632 break;
633 case CPConstants.MARGIN_BOTTOM_WIDTH_PN:
634 marginBottomWidth = CPConstants.asFloat( newVal );
635 update = true;
636 break;
637 case CPConstants.MARGIN_BOTTOM_BG_COLOR_PN:
638 marginBottomBGColor = CPConstants.asColor( newVal );
639 update = true;
640 break;
641 case CPConstants.MARGIN_LEFT_WIDTH_PN:
642 marginLeftWidth = CPConstants.asFloat( newVal );
643 update = true;
644 break;
645 case CPConstants.MARGIN_LEFT_BG_COLOR_PN:
646 marginLeftBGColor = CPConstants.asColor( newVal );
647 update = true;
648 break;
649 case CPConstants.TIC_MINOR_COLOR_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
650 case CPConstants.TIC_MINOR_WEIGHT_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
651 case CPConstants.TIC_MINOR_LEN_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
652 case CPConstants.TIC_MINOR_MPU_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
653 case CPConstants.TIC_MINOR_DRAW_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
654 case CPConstants.TIC_MAJOR_COLOR_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
655 case CPConstants.TIC_MAJOR_WEIGHT_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
656 case CPConstants.TIC_MAJOR_LEN_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
657 case CPConstants.TIC_MAJOR_MPU_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
658 case CPConstants.TIC_MAJOR_DRAW_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
659 case CPConstants.GRID_LINE_COLOR_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
660 case CPConstants.GRID_LINE_WEIGHT_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
661 case CPConstants.GRID_LINE_LPU_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
662 case CPConstants.GRID_LINE_DRAW_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
663 case CPConstants.AXIS_COLOR_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
664 case CPConstants.AXIS_WEIGHT_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
665 case CPConstants.LABEL_FONT_COLOR_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
666 case CPConstants.LABEL_FONT_NAME_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
667 case CPConstants.LABEL_FONT_STYLE_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
668 case CPConstants.LABEL_FONT_SIZE_PN:
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
669 case CPConstants.LABEL_DRAW_PN:
670 update = true;
----------------------------------------------------------------------------
671 break;
672 }
673
674 if ( update )
675 {
676 graphMgr.resetProfile();
677 repaint();
678 }
679 }
680
681 /**
682 * Sets the supplier
683 * that will fetch a stream
684 * to deliver commands
685 +-- 15 lines: * for plotting a curve.-------------------------------------------
700 private void drawUserPlot()
701 {
702 gtx.setColor( plotColor );
703 streamSupplier.get().forEach( c -> c.execute() );
704 }
705
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
706 private void paintMargins()
707 {
708 Rectangle2D rect = new Rectangle2D.Float();
709
710 // top margin
711 rect.setRect( 0, 0, currWidth, marginTopWidth );
712 +-- 21 lines: gtx.setColor( marginTopBGColor );---------------------------------
|