OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * 
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
 * 
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
 * language governing permissions and limitations under the License.
 * 
 * When distributing the software, include this License Header Notice in each file.
 */
 
 package org.openconcerto.ui.grid;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.JPanel;

public class TwoYearsHeaderPanel extends JPanel {
    private int year;
    private String[] months = new String[] { "Janv.", "Fév.", "Mars", "Avr.", "Mai", "Juin", "Juil.", "Août", "Sept.", "Oct.", "Nov.", "Déc." };

    public TwoYearsHeaderPanel(int year) {
        this.year = year;
        this.setBackground(Color.white);
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setFont(g.getFont().deriveFont(Font.BOLD));

        int x1 = this.getWidth() / 4;
        int x2 = (3 * this.getWidth()) / 4;
        String str1 = String.valueOf(this.year);
        int w1 = g.getFontMetrics().stringWidth(str1);
        g.drawString(str1, x1 - w1 / 2, 16);

        String str2 = String.valueOf(this.year + 1);
        int w2 = g.getFontMetrics().stringWidth(str2);
        g.drawString(str2, x2 - w2 / 2, 16);
        int gw = (this.getWidth()) / 24;
        g.setColor(Color.LIGHT_GRAY);
        for (int x = 0; x < this.getWidth(); x += gw * 3) {
            g.drawLine(x, 36, x, this.getHeight());

        }
        g.setColor(Color.GRAY);
        for (int x = 0; x < this.getWidth(); x += gw * 6) {
            g.drawLine(x, 24, x, this.getHeight());

        }

        g.setColor(Color.BLACK);
        for (int x = 0; x < this.getWidth(); x += gw * 12) {
            g.drawLine(x, 0, x, this.getHeight());

        }

        g.setFont(g.getFont().deriveFont(Font.PLAIN));
        int delta = this.getWidth() / 2;
        for (int i = 0; i < 12; i++) {

            final String str = this.months[i];
            int w = g.getFontMetrics().stringWidth(str2);
            int x = i * gw + gw / 2 - w / 2;
            g.drawString(str, x, 40);
            x = x + delta;
            g.drawString(str, x, 40);
        }
    }

    @Override
    public Dimension getMinimumSize() {
        return new Dimension(getPreferredSize().width, 48);
    }

}