📄 buttonpanel.java
字号:
// You can redistribute this software and/or modify it under the terms of
// the Ozone Library License version 1 published by ozone-db.org.
//
// The original code and portions created by SMB are
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
//
package org.ozoneDB.adminGui.widget;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.event.EventListenerList;
//#############################################################################
/**
* This class creates the button panel that can control up to 4 account defined
* buttons. Usually used at the bottom of the forms.
*
* @author <p align=center>Ibsen Ramos-Bonilla
* <br>Copyright © 1997-@year@ by SMB GmbH. All Rights Reserved.</p>
*
* @version 1.0
*/
//#############################################################################
public class ButtonPanel extends JPanel {
/** The listener list. */
protected EventListenerList listenerList = new EventListenerList();
/**
* Default constructor not used.
*/
private ButtonPanel() {
}
/**
* Overloaded constructor creates the panel buttons.
*
* @param buttonName - an array of button names.
*/
public ButtonPanel(String[] buttonName) {
super();
//init
if (buttonName != null)
init(buttonName);
}
/**
* This method initializes the button panel.
*
* @param buttonName - an array of button names.
*/
private void init(final String[] buttonName) {
//add buttons
this.setLayout(new GridBagLayout());
//create the buttons
JButton[] button = new JButton[buttonName.length];
//set buttons
for (int i = 0; i < buttonName.length; i++) {
final String name = buttonName[i].toString();
button[i] = new JButton(name);
button[i].setPreferredSize(new Dimension(80, 27));
button[i].setDefaultCapable(true);
button[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fireExecute(name);
}
});
this.add(button[i],
new GridBagConstraints(i, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(10, 10, 15, 10), 0, 0));
}
}
/**
* This method allows classes to register for connection events.
*
* @param listener - a connection listener.
*/
public void addConnectionListener(ButtonPanelListener listener) {
listenerList.add(ButtonPanelListener.class, listener);
}
/**
* This method allows classes to unregister from connection events.
*
* @param listener - a connection listener.
*/
public void removeConnectionListener(ButtonPanelListener listener) {
listenerList.remove(ButtonPanelListener.class, listener);
}
/**
* This method notifies all when the login process is fired.
*
* @param buttonName - the name associated with the button.
*/
private void fireExecute(String buttonName) {
Object[] listeners = listenerList.getListenerList();
//each listener occupies two elements - the first is the listener
//class, and the second is the listener instance
for (int i = 0; i < listeners.length; i += 2) {
if (listeners[i] == ButtonPanelListener.class) {
((ButtonPanelListener) listeners[i + 1]).buttonExecute(buttonName);
}
}
}
} //--------------------------------- E O F -----------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -