KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > gui > SectionNameLabel


1 package jimm.datavision.gui;
2 import java.awt.Font JavaDoc;
3 import java.awt.Color JavaDoc;
4 import java.awt.event.MouseAdapter JavaDoc;
5 import java.awt.event.MouseEvent JavaDoc;
6 import javax.swing.*;
7
8 /**
9  * A section name label displays the name of a section, for example "Report
10  * Header (a)". A popup menu holds command affecting the section widget
11  * with which this label is associated.
12  *
13  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
14  */

15 class SectionNameLabel extends JLabel {
16
17 protected static Font JavaDoc DEFAULT_FONT = new Font JavaDoc("Serif", Font.PLAIN, 10);
18
19 protected SectionWidget sectionWidget;
20
21 /**
22  * An inner class that handles display of the popup menu.
23  */

24 class PopupListener extends MouseAdapter JavaDoc {
25 public void mousePressed(MouseEvent JavaDoc e) { maybeShowPopup(e); }
26 public void mouseReleased(MouseEvent JavaDoc e) { maybeShowPopup(e); }
27 private void maybeShowPopup(MouseEvent JavaDoc e) {
28     if (sectionWidget.designer.isPlacingNewTextField())
29     sectionWidget.designer.rejectNewTextField();
30     else if (e.isPopupTrigger())
31     sectionWidget.showPopup(e);
32 }
33 }
34
35 /**
36  * Constructor.
37  *
38  * @param name the section's name
39  * @param sw the section widget we are labeling and controlling via a popup
40  * menu
41  */

42 SectionNameLabel(String JavaDoc name, SectionWidget sw) {
43     super(name);
44     sectionWidget = sw;
45     setHorizontalAlignment(JLabel.CENTER);
46     setVerticalAlignment(JLabel.TOP);
47     setFont(DEFAULT_FONT);
48     setForeground(Color.black);
49
50     addMouseListener(new PopupListener());
51 }
52
53 }
54
Popular Tags