001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: JDialogError.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.swing;
009:
010: import javax.swing.*;
011:
012: import com.uwyn.rife.config.RifeConfig;
013: import com.uwyn.rife.tools.Localization;
014: import java.awt.Color;
015: import java.awt.FlowLayout;
016: import java.awt.GridBagConstraints;
017: import java.awt.GridBagLayout;
018: import java.awt.event.ActionEvent;
019: import java.awt.event.ActionListener;
020:
021: public class JDialogError extends JDialog implements ActionListener,
022: DefaultFocused {
023: private static final long serialVersionUID = -8662064050538600090L;
024:
025: private GridBagConstraints mConstraints = null;
026:
027: private JPanel mContentPane = null;
028: private JLabel mErrorIcon = null;
029: private JPanel mErrorIconPanel = null;
030: private JComponent mErrorMessage = null;
031: private JButton mOkButton = null;
032: private JPanel mButtonsPanel = null;
033:
034: public JDialogError(JFrame frame, String text) {
035: this (frame, Localization.getString("rife.dialog.error.title"),
036: text);
037: }
038:
039: public JDialogError(JFrame frame, String title, String text) {
040: this (frame, title, new JLabel(text));
041: }
042:
043: public JDialogError(JFrame frame, String title,
044: JComponent messageComponent) {
045: super (frame, title, true);
046: ImageIcon icon = null;
047: if (Images.hasRepInstance()) {
048: icon = Images.getRepInstance().getImageIcon(
049: RifeConfig.Swing.getIconErrorPath());
050: }
051: if (null == icon) {
052: icon = new ImageIcon(JDialogError.class.getClassLoader()
053: .getResource(RifeConfig.Swing.getIconErrorPath()));
054: }
055: mErrorIcon = new JLabel(icon);
056: mErrorIcon.setBorder(BorderFactory.createMatteBorder(10, 10,
057: 10, 10, (Color) null));
058: mErrorIcon.setBackground(Colors.ERROR_BACKGROUND);
059: mErrorIcon.setOpaque(true);
060: mErrorIconPanel = new JPanel();
061: mErrorIconPanel.setBackground(Colors.ERROR_BACKGROUND);
062: mErrorIconPanel.add(mErrorIcon);
063: mErrorMessage = messageComponent;
064: mErrorMessage.setBorder(BorderFactory.createMatteBorder(10, 10,
065: 10, 10, (Color) null));
066: mOkButton = new JButton(Localization
067: .getString("rife.dialog.error.okbutton"));
068: mOkButton.setMnemonic(Localization
069: .getChar("rife.dialog.error.okbutton.mnemonic"));
070: mOkButton.addActionListener(this );
071: mButtonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
072: mButtonsPanel.add(mOkButton);
073:
074: mContentPane = new JPanel(new GridBagLayout());
075: mContentPane.setBackground(Color.white);
076: setContentPane(mContentPane);
077: mConstraints = new GridBagConstraints();
078: mConstraints.gridx = 0;
079: mConstraints.gridy = 0;
080: mConstraints.gridwidth = 1;
081: mConstraints.gridheight = 1;
082: mConstraints.weightx = 0;
083: mConstraints.weighty = 1;
084: mConstraints.anchor = GridBagConstraints.CENTER;
085: mConstraints.fill = GridBagConstraints.BOTH;
086: mContentPane.add(mErrorIconPanel, mConstraints);
087: mConstraints.gridx = 1;
088: mConstraints.weightx = 1;
089: mConstraints.anchor = GridBagConstraints.NORTHWEST;
090: mConstraints.fill = GridBagConstraints.HORIZONTAL;
091: mContentPane.add(mErrorMessage, mConstraints);
092:
093: mConstraints.gridx = 0;
094: mConstraints.gridy = 1;
095: mConstraints.weightx = 1;
096: mConstraints.weighty = 0;
097: mConstraints.gridwidth = 2;
098: mContentPane.add(new JSeparator(JSeparator.HORIZONTAL),
099: mConstraints);
100:
101: mConstraints.gridy = 2;
102: mContentPane.add(mButtonsPanel, mConstraints);
103:
104: mContentPane.setVisible(true);
105: pack();
106:
107: setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
108: if (null != frame) {
109: setLocationRelativeTo(frame);
110: }
111:
112: new DefaultFocusSetter(this );
113: }
114:
115: public JComponent getDefaultFocus() {
116: return mOkButton;
117: }
118:
119: public void actionPerformed(ActionEvent event) {
120: Object source = event.getSource();
121:
122: if (mOkButton == source) {
123: dispose();
124: }
125: }
126: }
|