KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > adminGui > feature > FeatureButton


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: FeatureButton.java,v 1.2 2003/03/24 08:36:55 per_nyfelt Exp $
8
package org.ozoneDB.adminGui.feature;
9
10 import org.ozoneDB.adminGui.res.Settings;
11 import org.ozoneDB.adminGui.main.AdminGui;
12
13 import javax.swing.*;
14 import java.awt.event.MouseListener JavaDoc;
15 import java.awt.event.ActionListener JavaDoc;
16 import java.awt.event.ActionEvent JavaDoc;
17 import java.awt.event.MouseEvent JavaDoc;
18 import java.awt.*;
19
20 /**
21  * @author Per Nyfelt
22  */

23 public class FeatureButton extends JButton implements MouseListener JavaDoc, ActionListener JavaDoc {
24
25     private static final Dimension BUTTON_SIZE = new Dimension(65, 70);
26     private Feature feature;
27     private Component strut;
28     private String JavaDoc name;
29
30     public FeatureButton(Feature feature, Component strut) {
31         super();
32         this.feature = feature;
33         this.strut = strut;
34         this.name = feature.getName();
35         this.setText(name);
36         this.setIcon(feature.getImage());
37         this.addActionListener(this);
38
39         setButtonColors();
40         setButtonSize();
41         setButtonAlignment();
42
43         this.setBorderPainted(false);
44         this.setFocusPainted(false);
45         this.addMouseListener(this);
46
47         this.setBorder(BorderFactory.createEtchedBorder(Settings.COLOR_COBALT, Color.LIGHT_GRAY));
48     }
49
50     public void setVisible(boolean visible) {
51         super.setVisible(visible);
52         this.strut.setVisible(visible);
53     }
54
55     public String JavaDoc getName() {
56         return this.name;
57     }
58
59     private void setButtonColors() {
60         this.setForeground(Color.BLACK);
61         this.setBackground(Color.WHITE);
62     }
63
64     private void setButtonSize() {
65         this.setPreferredSize(BUTTON_SIZE);
66         this.setMaximumSize(BUTTON_SIZE);
67         this.setMinimumSize(BUTTON_SIZE);
68     }
69
70     private void setButtonAlignment() {
71         this.setVerticalTextPosition(SwingConstants.BOTTOM);
72         this.setHorizontalTextPosition(SwingConstants.CENTER);
73         this.setAlignmentX(JButton.CENTER_ALIGNMENT);
74     }
75
76     public Feature getFeature() {
77         return feature;
78     }
79
80     public void actionPerformed(ActionEvent JavaDoc e) {
81         setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
82         AdminGui.instance().setFeature(feature);
83         setCursor(Cursor.getDefaultCursor());
84     }
85
86     public void mouseClicked(MouseEvent JavaDoc me) {
87     }
88
89     public void mouseEntered(MouseEvent JavaDoc me) {
90         setBorderPainted(true);
91     }
92
93     public void mouseExited(MouseEvent JavaDoc me) {
94         setBorderPainted(false);
95     }
96
97     public void mousePressed(MouseEvent JavaDoc me) {
98     }
99
100     public void mouseReleased(MouseEvent JavaDoc me) {
101     }
102 }
103
Popular Tags