Esempio n. 1
0
    public void Draw(Graphics2D graphics) {
        Fill f = GetFill();
        Dimension pg = Sheet.GetSlideShow().GetPageSize();
        Rectangle anchor = new Rectangle(0, 0, pg.width, pg.height);
        switch (f.GetFillType()) {
            case Fill.FILL_SOLID:
                Color color = f.GetForegroundColor();
                graphics.SetPaint(color);
                graphics.Fill(anchor);
                break;
            case Fill.FILL_PICTURE:
                PictureData data = f.GetPictureData();
                if (data is Bitmap) {
                    BufferedImage img = null;
                    try {
                        img = ImageIO.Read(new MemoryStream(data.Data));
                    } catch (Exception e) {
                        logger.log(POILogger.WARN, "ImageIO failed to create image. image.type: " + data.GetType());
                        return;
                    }
                    Image scaledImg = img.GetScaledInstance(anchor.width, anchor.height, Image.SCALE_SMOOTH);
                    graphics.DrawImage(scaledImg, anchor.x, anchor.y, null);

                }
                break;
            default:
                logger.log(POILogger.WARN, "unsuported fill type: " + f.GetFillType());
                break;
        }
    }
                public virtual void OnMouseOver(Graphics2D g2d, Rectangle cell, U guess, U gold)
                {
                    // Compute values
                    int x = (int)(cell.GetLocation().x + cell.GetWidth() / 5.0);
                    int y = (int)(cell.GetLocation().y + cell.GetHeight() / 5.0);
                    // Compute the text
                    int value = this._enclosing._enclosing.confTable[Pair.MakePair(guess, gold)];

                    if (value == null)
                    {
                        value = 0;
                    }
                    string text = "Guess: " + guess.ToString() + "\n" + "Gold: " + gold.ToString() + "\n" + "Value: " + value;
                    // Set the font
                    Font bak = g2d.GetFont();

                    g2d.SetFont(bak.DeriveFont(bak.GetSize() * 2.0f));
                    // Render
                    g2d.SetColor(Color.White);
                    g2d.Fill(cell);
                    g2d.SetColor(Color.Black);
                    foreach (string line in text.Split("\n"))
                    {
                        g2d.DrawString(line, x, y += g2d.GetFontMetrics().GetHeight());
                    }
                    // Reset
                    g2d.SetFont(bak);
                }
Esempio n. 3
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);
            }
        }
                protected override void PaintComponent(Graphics g)
                {
                    base.PaintComponent(g);
                    // Dimensions
                    Graphics2D g2d = (Graphics2D)g.Create();

                    g.SetFont(new Font("Arial", Font.Plain, 10));
                    int width      = this.GetWidth();
                    int height     = this.GetHeight();
                    int cellWidth  = width / this.columnCount;
                    int cellHeight = height / this.rowCount;
                    int xOffset    = (width - (this.columnCount * cellWidth)) / 2;
                    int yOffset    = (height - (this.rowCount * cellHeight)) / 2;
                    // Get label index
                    IList <U> labels = this._enclosing._enclosing.UniqueLabels().Stream().Collect(Collectors.ToList());
                    // Get color gradient
                    int maxDiag    = 0;
                    int maxOffdiag = 0;

                    foreach (KeyValuePair <Pair <U, U>, int> entry in this._enclosing._enclosing.confTable)
                    {
                        if (entry.Key.first == entry.Key.second)
                        {
                            maxDiag = Math.Max(maxDiag, entry.Value);
                        }
                        else
                        {
                            maxOffdiag = Math.Max(maxOffdiag, entry.Value);
                        }
                    }
                    // Render the grid
                    float[] hsb = new float[3];
                    for (int row = 0; row < this.rowCount; row++)
                    {
                        for (int col = 0; col < this.columnCount; col++)
                        {
                            // Position
                            int   x       = xOffset + (col * cellWidth);
                            int   y       = yOffset + (row * cellHeight);
                            float xCenter = xOffset + (col * cellWidth) + cellWidth / 3.0f;
                            float yCenter = yOffset + (row * cellHeight) + cellHeight / 2.0f;
                            // Get text + Color
                            string text;
                            Color  bg = Color.White;
                            if (row == 0 && col == 0)
                            {
                                text = "V guess | gold >";
                            }
                            else
                            {
                                if (row == 0)
                                {
                                    text = labels[col - 1].ToString();
                                }
                                else
                                {
                                    if (col == 0)
                                    {
                                        text = labels[row - 1].ToString();
                                    }
                                    else
                                    {
                                        // Set value
                                        int count = this._enclosing._enclosing.confTable[Pair.MakePair(labels[row - 1], labels[col - 1])];
                                        if (count == null)
                                        {
                                            count = 0;
                                        }
                                        text = string.Empty + count;
                                        // Get color
                                        if (row == col)
                                        {
                                            double percentGood = ((double)count) / ((double)maxDiag);
                                            hsb = Color.RGBtoHSB((int)(255 - (255.0 * percentGood)), (int)(255 - (255.0 * percentGood / 2.0)), (int)(255 - (255.0 * percentGood)), hsb);
                                            bg  = Color.GetHSBColor(hsb[0], hsb[1], hsb[2]);
                                        }
                                        else
                                        {
                                            double percentBad = ((double)count) / ((double)maxOffdiag);
                                            hsb = Color.RGBtoHSB((int)(255 - (255.0 * percentBad / 2.0)), (int)(255 - (255.0 * percentBad)), (int)(255 - (255.0 * percentBad)), hsb);
                                            bg  = Color.GetHSBColor(hsb[0], hsb[1], hsb[2]);
                                        }
                                    }
                                }
                            }
                            // Draw
                            Rectangle cell = new Rectangle(x, y, cellWidth, cellHeight);
                            g2d.SetColor(bg);
                            g2d.Fill(cell);
                            g2d.SetColor(Color.Black);
                            g2d.DrawString(text, xCenter, yCenter);
                            this.cells.Add(cell);
                        }
                    }
                    // Mouse over
                    if (this.selectedCell != null && this.selectedCell.x > 0 && this.selectedCell.y > 0)
                    {
                        int       index = this.selectedCell.x + (this.selectedCell.y * this.columnCount);
                        Rectangle cell  = this.cells[index];
                        this.OnMouseOver(g2d, cell, labels[this.selectedCell.y - 1], labels[this.selectedCell.x - 1]);
                    }
                    // Clean up
                    g2d.Dispose();
                }
Esempio n. 5
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);
        }
    }