View Javadoc

1   /*
2    *  File: TourenGapRenderer.java 
3    *  Copyright (c) 2004-2007  Peter Kliem (Peter.Kliem@jaret.de)
4    *  A commercial license is available, see http://www.jaret.de.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation; either version 2 of the License, or
9    *  (at your option) any later version.
10   *
11   *  This program is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   *  GNU General Public License for more details.
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  package de.jaret.examples.timebars.touren;
21  
22  import java.awt.Color;
23  import java.awt.Graphics;
24  
25  import javax.swing.JComponent;
26  
27  import de.jaret.util.date.Interval;
28  import de.jaret.util.swing.GraphicsHelper;
29  import de.jaret.util.ui.timebars.model.TimeBarRow;
30  import de.jaret.util.ui.timebars.swing.TimeBarViewer;
31  import de.jaret.util.ui.timebars.swing.renderer.TimeBarGapRenderer;
32  
33  /***
34   * @author Peter Kliem
35   * @version $Id: TourenGapRenderer.java 234 2007-02-10 00:22:45Z olk $
36   */
37  public class TourenGapRenderer implements TimeBarGapRenderer {
38      RendererComponent _component;
39  
40      public TourenGapRenderer() {
41          _component = new RendererComponent();
42      }
43  
44      public JComponent getTimeBarGapRendererComponent(TimeBarViewer tbv, TimeBarRow row, Interval interval1,
45              Interval interval2) {
46          _component.setTourElements((TourElement) interval1, (TourElement) interval2);
47          return _component;
48      }
49  
50      public int getMinimumWidth() {
51          return 30;
52      }
53  
54      class RendererComponent extends JComponent {
55          TourElement _te1;
56          TourElement _te2;
57  
58          public RendererComponent() {
59              setLayout(null);
60              setOpaque(false);
61          }
62  
63          public void setTourElements(TourElement te1, TourElement te2) {
64              _te1 = te1;
65              _te2 = te2;
66          }
67  
68          protected void paintComponent(Graphics g) {
69              super.paintComponent(g);
70              int height = getHeight();
71              int width = getWidth();
72  
73              int y = height / 3;
74              int bheight = height / 3;
75              int yEnd = y + bheight;
76  
77              int xcenter = width / 2;
78  
79              g.setColor(Color.BLACK);
80  
81              // minute
82              int minutes = _te1.getEnd().getMinutes();
83              GraphicsHelper.drawStringCentered(g, Integer.toString(minutes), xcenter, y - 2);
84              // endeort
85              GraphicsHelper.drawStringCentered(g, _te1.getEndeOrt(), xcenter, yEnd + 12);
86  
87          }
88      }
89  
90  }