001: /*
002: * This file is part of the GeOxygene project source files.
003: *
004: * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
005: * the development and deployment of geographic (GIS) applications. It is a open source
006: * contribution of the COGIT laboratory at the Institut Géographique National (the French
007: * National Mapping Agency).
008: *
009: * See: http://oxygene-project.sourceforge.net
010: *
011: * Copyright (C) 2005 Institut Géographique National
012: *
013: * This library is free software; you can redistribute it and/or modify it under the terms
014: * of the GNU Lesser General Public License as published by the Free Software Foundation;
015: * either version 2.1 of the License, or any later version.
016: *
017: * This library is distributed in the hope that it will be useful, but WITHOUT ANY
018: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
019: * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser General Public License along with
022: * this library (see file LICENSE if present); if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024: *
025: */
026:
027: package fr.ign.cogit.geoxygene.util.browser;
028:
029: import java.awt.Color;
030: import java.awt.Dimension;
031: import java.awt.Font;
032: import java.awt.Graphics;
033: import java.awt.Rectangle;
034:
035: import javax.swing.JComponent;
036:
037: /**
038: * Cette classe définit un nouveau composant graphique Swing permettant l'affichage des numéros
039: * d'index des objets contenus dans un attribut de type Array ou Collection.
040: *
041: * @author Thierry Badard & Arnaud Braun
042: * @version 1.0
043: *
044: */
045:
046: public class ObjectBrowserListRuler extends JComponent {
047:
048: /** Famille de la police de caractères par défaut. */
049: public static final String FONT_FAMILY = "SansSerif";
050: /** Taille de la police de caractères par défaut. */
051: public static final int FONT_SIZE = 10;
052: /** Couleur de fond du composant graphique. */
053: public static final Color RULER_COLOR = new Color(255, 255, 255);
054: /** Nombre d'éléments contenus dans l'attribut à représenter. */
055: private int nb_elements;
056: /** Taille horizontale du composant graphique, calculée en fonction du nombre d'éléments et
057: * de la taille de la police de caractères. */
058: private int size;
059: /** Espacement vertical calculé entre les numéros d'index représentant les rangs des objets
060: * constituants la collection ou le tableau à représenter. */
061: private double gap;
062:
063: /**
064: * Constructeur principal du ObjectBrowserListRuler.
065: *
066: * @param nbElements nombre d'éléments contenus dans l'attribut à représenter.
067: * @param height hauteur souhaitée en pixel du composant graphique.
068: */
069: public ObjectBrowserListRuler(int nbElements, double height) {
070: nb_elements = nbElements;
071: size = FONT_SIZE + 7
072: * ((Integer.toString(nbElements)).length() - 1);
073: gap = height / nbElements;
074:
075: }
076:
077: /**
078: * Fixe la hauteur souhaitée en pixel du composant graphique.
079: *
080: * @param ph la hauteur souhaitée en pixel du composant graphique.
081: */
082: public void setPreferredHeight(int ph) {
083: setPreferredSize(new Dimension(size, ph));
084: }
085:
086: public void paintComponent(Graphics g) {
087: Rectangle drawHere = g.getClipBounds();
088:
089: g.setColor(RULER_COLOR);
090: g.fillRect(drawHere.x, drawHere.y, drawHere.width,
091: drawHere.height);
092:
093: g.setFont(new Font(FONT_FAMILY, Font.PLAIN, FONT_SIZE));
094: g.setColor(Color.black);
095:
096: for (int i = 0; i < nb_elements; i++) {
097: g.drawString(Integer.toString(i), 2, (int) (i * gap + gap
098: / 2 + 1));
099: }
100:
101: }
102:
103: }
|