01: package jimm.datavision.gui;
02:
03: import java.awt.Font;
04: import java.awt.Color;
05: import java.awt.event.MouseAdapter;
06: import java.awt.event.MouseEvent;
07: import javax.swing.*;
08:
09: /**
10: * A section name label displays the name of a section, for example "Report
11: * Header (a)". A popup menu holds command affecting the section widget
12: * with which this label is associated.
13: *
14: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
15: */
16: class SectionNameLabel extends JLabel {
17:
18: protected static Font DEFAULT_FONT = new Font("Serif", Font.PLAIN,
19: 10);
20:
21: protected SectionWidget sectionWidget;
22:
23: /**
24: * An inner class that handles display of the popup menu.
25: */
26: class PopupListener extends MouseAdapter {
27: public void mousePressed(MouseEvent e) {
28: maybeShowPopup(e);
29: }
30:
31: public void mouseReleased(MouseEvent e) {
32: maybeShowPopup(e);
33: }
34:
35: private void maybeShowPopup(MouseEvent e) {
36: if (sectionWidget.designer.isPlacingNewTextField())
37: sectionWidget.designer.rejectNewTextField();
38: else if (e.isPopupTrigger())
39: sectionWidget.showPopup(e);
40: }
41: }
42:
43: /**
44: * Constructor.
45: *
46: * @param name the section's name
47: * @param sw the section widget we are labeling and controlling via a popup
48: * menu
49: */
50: SectionNameLabel(String name, SectionWidget sw) {
51: super (name);
52: sectionWidget = sw;
53: setHorizontalAlignment(JLabel.CENTER);
54: setVerticalAlignment(JLabel.TOP);
55: setFont(DEFAULT_FONT);
56: setForeground(Color.black);
57:
58: addMouseListener(new PopupListener());
59: }
60:
61: }
|