Beispiel #1
0
        private static double PaintTree(Tree t, Point2D start, Graphics2D g2, FontMetrics fM)
        {
            if (t == null)
            {
                return(0.0);
            }
            string nodeStr    = NodeToString(t);
            double nodeWidth  = fM.StringWidth(nodeStr);
            double nodeHeight = fM.GetHeight();
            double nodeAscent = fM.GetAscent();

            TreeJPanel.WidthResult wr = WidthResult(t, fM);
            double treeWidth          = wr.width;
            double nodeTab            = wr.nodeTab;
            double childTab           = wr.childTab;
            double nodeCenter         = wr.nodeCenter;

            //double treeHeight = height(t, fM);
            // draw root
            g2.DrawString(nodeStr, (float)(nodeTab + start.GetX()), (float)(start.GetY() + nodeAscent));
            if (t.IsLeaf())
            {
                return(nodeWidth);
            }
            double layerMultiplier = (1.0 + belowLineSkip + aboveLineSkip + parentSkip);
            double layerHeight     = nodeHeight * layerMultiplier;
            double childStartX     = start.GetX() + childTab;
            double childStartY     = start.GetY() + layerHeight;
            double lineStartX      = start.GetX() + nodeCenter;
            double lineStartY      = start.GetY() + nodeHeight * (1.0 + belowLineSkip);
            double lineEndY        = lineStartY + nodeHeight * parentSkip;

            // recursively draw children
            for (int i = 0; i < t.Children().Length; i++)
            {
                Tree   child  = t.Children()[i];
                double cWidth = PaintTree(child, new Point2D.Double(childStartX, childStartY), g2, fM);
                // draw connectors
                wr = WidthResult(child, fM);
                double lineEndX = childStartX + wr.nodeCenter;
                g2.Draw(new Line2D.Double(lineStartX, lineStartY, lineEndX, lineEndY));
                childStartX += cWidth;
                if (i < t.Children().Length - 1)
                {
                    childStartX += sisterSkip * fM.StringWidth(" ");
                }
            }
            return(treeWidth);
        }
Beispiel #2
0
        /// <summary>
        /// {@inheritDoc}
        /// </summary>
        public override void Draw(Graphics2D graphics, float x, float y)
        {
            // translating graphics to draw Shape !!!
            graphics.Translate((int)x, (int)y);

            try
            {
                if (FStroke == STROKE)
                {
                    // REMIND: set stroke to correct size
                    graphics.Draw(FShape);
                }
                else
                {
                    graphics.Fill(FShape);
                }
            }
            finally
            {
                graphics.Translate(-(int)x, -(int)y);
            }
        }
Beispiel #3
0
    public static void paint(SimpleShape shape, Graphics2D graphics){
        Rectangle2D anchor = shape.GetLogicalAnchor2D();
        java.awt.Shape outline = shape.GetOutline();

        //flip vertical
        if(shape.GetFlipVertical()){
            graphics.translate(anchor.GetX(), anchor.GetY() + anchor.Height);
            graphics.scale(1, -1);
            graphics.translate(-anchor.GetX(), -anchor.GetY());
        }
        //flip horizontal
        if(shape.GetFlipHorizontal()){
            graphics.translate(anchor.GetX() + anchor.Width, anchor.GetY());
            graphics.scale(-1, 1);
            graphics.translate(-anchor.GetX() , -anchor.GetY());
        }

        //rotate transform
        double angle = shape.GetRotation();

        if(angle != 0){
            double centerX = anchor.GetX() + anchor.Width/2;
            double centerY = anchor.GetY() + anchor.Height/2;

            graphics.translate(centerX, centerY);
            graphics.rotate(Math.ToRadians(angle));
            graphics.translate(-centerX, -centerY);
        }

        //fill
        Color FillColor = shape.GetFill().GetForegroundColor();
        if (FillColor != null) {
            //TODO: implement gradient and texture fill patterns
            graphics.SetPaint(FillColor);
            graphics.Fill(outline);
        }

        //border
        Color lineColor = shape.GetLineColor();
        if (lineColor != null){
            graphics.SetPaint(lineColor);
            float width = (float)shape.GetLineWidth();

            int dashing = shape.GetLineDashing();
            //TODO: implement more dashing styles
            float[] dashptrn = null;
            switch(dashing){
                case Line.PEN_SOLID:
                    dashptrn = null;
                    break;
                case Line.PEN_PS_DASH:
                    dashptrn = new float[]{width, width};
                    break;
                case Line.PEN_DOTGEL:
                    dashptrn = new float[]{width*4, width*3};
                    break;
               default:
                    logger.log(POILogger.WARN, "unsupported dashing: " + dashing);
                    dashptrn = new float[]{width, width};
                    break;
            }

            Stroke stroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashptrn, 0.0f);
            graphics.SetStroke(stroke);
            graphics.Draw(outline);
        }
    }