📄 attributesdialog.java
字号:
/*
* AttributeDialog.java - Dialog for inputting attributes
* Mark Bryan Yu
* jimagemapper.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package cn.dxm.client;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
public class AttributesDialog extends JDialog {
private String[] labels = {"HREF: ", "ALT: "};
private JTextField[] textFields;
private int numPairs = labels.length;
private boolean isClosed = true;
private AttributeBean attributes;
private JFrame parent;
public AttributesDialog(JFrame owner) {
super(owner, "Attributes", true);
this.parent = owner;
initComponents();
setVisible(true);
}
public AttributesDialog(JFrame owner, AttributeBean bean) {
super(owner, "Attributes", true);
this.parent = owner;
initComponents();
setAttributes(bean);
setVisible(true);
}
private void setAttributes(AttributeBean bean) {
textFields[0].setText(bean.getHref());
textFields[1].setText(bean.getAlt());
}
private void initComponents() {
JPanel p = new JPanel(new SpringLayout());
textFields = new JTextField[numPairs];
for (int i = 0; i < numPairs; i++) {
JLabel l = new JLabel(labels[i], JLabel.TRAILING);
p.add(l);
textFields[i] = new JTextField(10);
l.setLabelFor(textFields[i]);
p.add(textFields[i]);
}
JButton add = new JButton("Ok");
add.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
isClosed = false;
attributes = new AttributeBean();
attributes.setHref(textFields[0].getText());
attributes.setAlt(textFields[1].getText());
dispose();
}
});
p.add(add);
JButton cancel = new JButton("Cancel");
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
isClosed = true;
dispose();
}
});
p.add(cancel);
SpringUtilities.makeCompactGrid(p,
numPairs + 1, 2, //rows, cols
6, 6, //initX, initY
6, 6); //xPad, yPad
setContentPane(p);
setResizable(false);
setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
Point point = parent.getLocation();
setLocation(point.x + (parent.getWidth() - getWidth()) / 2, point.y + (parent.getHeight() - getHeight()) / 2);
pack();
}
public boolean isClosed() {
return isClosed;
}
public AttributeBean getAttributes() {
return attributes;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -