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: JDialogInfo.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 JDialogInfo extends JDialog implements ActionListener,
022: DefaultFocused {
023: private static final long serialVersionUID = 1114295526679645482L;
024:
025: protected GridBagConstraints mConstraints = null;
026:
027: protected JPanel mContentPane = null;
028: protected JLabel mInfoIcon = null;
029: protected JPanel mInfoIconPanel = null;
030: protected JComponent mInfoMessage = null;
031: protected JButton mOkButton = null;
032: protected JPanel mButtonsPanel = null;
033:
034: public JDialogInfo(JFrame frame, String text) {
035: this (frame, Localization.getString("rife.dialog.info.title"),
036: text);
037: }
038:
039: public JDialogInfo(JFrame frame, String title, String text) {
040: this (frame, title, new JLabel(text));
041: }
042:
043: public JDialogInfo(JFrame frame, String title,
044: JComponent messageComponent) {
045: super (frame, title, true);
046:
047: ImageIcon icon = null;
048: if (Images.hasRepInstance()) {
049: icon = Images.getRepInstance().getImageIcon(
050: RifeConfig.Swing.getIconInfoPath());
051: }
052: if (null == icon) {
053: icon = new ImageIcon(JDialogError.class.getClassLoader()
054: .getResource(RifeConfig.Swing.getIconInfoPath()));
055: }
056: mInfoIcon = new JLabel(icon);
057: mInfoIcon.setBorder(BorderFactory.createMatteBorder(10, 10, 10,
058: 10, (Color) null));
059: mInfoIcon.setBackground(Colors.INFO_BACKGROUND);
060: mInfoIcon.setOpaque(true);
061: mInfoIconPanel = new JPanel();
062: mInfoIconPanel.setBackground(Colors.INFO_BACKGROUND);
063: mInfoIconPanel.add(mInfoIcon);
064: mInfoMessage = messageComponent;
065: mInfoMessage.setBorder(BorderFactory.createMatteBorder(10, 10,
066: 10, 10, (Color) null));
067:
068: mOkButton = new JButton(Localization
069: .getString("rife.dialog.info.okbutton"));
070: mOkButton.setMnemonic(Localization
071: .getChar("rife.dialog.info.okbutton.mnemonic"));
072: mOkButton.addActionListener(this );
073: mButtonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
074: mButtonsPanel.add(mOkButton);
075:
076: mContentPane = new JPanel(new GridBagLayout());
077: mContentPane.setBackground(Color.white);
078: setContentPane(mContentPane);
079: mConstraints = new GridBagConstraints();
080: mConstraints.gridx = 0;
081: mConstraints.gridy = 0;
082: mConstraints.gridwidth = 1;
083: mConstraints.gridheight = 1;
084: mConstraints.weightx = 0;
085: mConstraints.weighty = 1;
086: mConstraints.anchor = GridBagConstraints.CENTER;
087: mConstraints.fill = GridBagConstraints.BOTH;
088: mContentPane.add(mInfoIconPanel, mConstraints);
089: mConstraints.gridx = 1;
090: mConstraints.weightx = 1;
091: mConstraints.anchor = GridBagConstraints.NORTHWEST;
092: mConstraints.fill = GridBagConstraints.HORIZONTAL;
093: mContentPane.add(mInfoMessage, mConstraints);
094:
095: mConstraints.gridx = 0;
096: mConstraints.gridy = 1;
097: mConstraints.weightx = 1;
098: mConstraints.weighty = 0;
099: mConstraints.gridwidth = 2;
100: mContentPane.add(new JSeparator(JSeparator.HORIZONTAL),
101: mConstraints);
102:
103: mConstraints.gridy = 2;
104: mContentPane.add(mButtonsPanel, mConstraints);
105:
106: mContentPane.setVisible(true);
107: pack();
108:
109: setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
110: if (null != frame) {
111: setLocationRelativeTo(frame);
112: }
113:
114: new DefaultFocusSetter(this );
115: }
116:
117: public JComponent getDefaultFocus() {
118: return mOkButton;
119: }
120:
121: public void actionPerformed(ActionEvent event) {
122: Object source = event.getSource();
123:
124: if (mOkButton == source) {
125: dispose();
126: }
127: }
128:
129: public void safeShow() {
130: SwingUtilities.invokeLater(new DialogShowThread(this ));
131: }
132:
133: public class DialogShowThread extends Thread {
134: JDialog mDialog = null;
135:
136: public DialogShowThread(JDialog dialog) {
137: mDialog = dialog;
138: }
139:
140: public void run() {
141: mDialog.setVisible(true);
142: }
143: }
144: }
|