001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.common.authentication;
027:
028: import com.sshtools.common.ui.IconWrapperPanel;
029: import com.sshtools.common.ui.ResourceIcon;
030: import com.sshtools.common.ui.UIUtil;
031:
032: import java.awt.BorderLayout;
033: import java.awt.Component;
034: import java.awt.Dialog;
035: import java.awt.FlowLayout;
036: import java.awt.Font;
037: import java.awt.Frame;
038: import java.awt.Window;
039: import java.awt.event.ActionEvent;
040: import java.awt.event.ActionListener;
041:
042: import javax.swing.BorderFactory;
043: import javax.swing.JButton;
044: import javax.swing.JDialog;
045: import javax.swing.JPanel;
046: import javax.swing.JScrollPane;
047: import javax.swing.JTextArea;
048: import javax.swing.SwingConstants;
049: import javax.swing.SwingUtilities;
050:
051: /**
052: *
053: *
054: * @author $author$
055: * @version $Revision: 1.15 $
056: */
057: public class BannerDialog extends JDialog {
058: // Statics
059: final static String BANNER_ICON = "largebanner.png";
060:
061: // Private instance variables
062: private JTextArea text;
063:
064: /**
065: * Creates a new BannerDialog object.
066: *
067: * @param bannerText
068: */
069: public BannerDialog(String bannerText) {
070: super ((Frame) null, "SSH Authentication - Banner Message", true);
071: init(bannerText);
072: }
073:
074: /**
075: * Creates a new BannerDialog object.
076: *
077: * @param parent
078: * @param bannerText
079: */
080: public BannerDialog(Frame parent, String bannerText) {
081: super (parent, "SSH Authentication - Banner Message", true);
082: init(bannerText);
083: }
084:
085: /**
086: * Creates a new BannerDialog object.
087: *
088: * @param parent
089: * @param bannerText
090: */
091: public BannerDialog(Dialog parent, String bannerText) {
092: super (parent, "SSH Authentication - Banner Message", true);
093: init(bannerText);
094: }
095:
096: void init(String bannerText) {
097: try {
098: jbInit();
099: } catch (Exception e) {
100: e.printStackTrace();
101: }
102:
103: //
104: setText(bannerText);
105: }
106:
107: /**
108: *
109: *
110: * @param parent
111: * @param bannerText
112: */
113: public static void showBannerDialog(Component parent,
114: String bannerText) {
115: Window w = (Window) SwingUtilities.getAncestorOfClass(
116: Window.class, parent);
117: BannerDialog dialog = null;
118:
119: if (w instanceof Frame) {
120: dialog = new BannerDialog((Frame) w, bannerText);
121: } else if (w instanceof Dialog) {
122: dialog = new BannerDialog((Dialog) w, bannerText);
123: } else {
124: dialog = new BannerDialog(bannerText);
125: }
126:
127: UIUtil.positionComponent(SwingConstants.CENTER, dialog);
128: dialog.toFront();
129: dialog.setVisible(true);
130: }
131:
132: /**
133: *
134: *
135: * @param text
136: */
137: public void setText(String text) {
138: this .text.setText(text);
139: this .repaint();
140: }
141:
142: void jbInit() throws Exception {
143: setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
144:
145: // Create the component to display the banner text
146: text = new JTextArea();
147: text.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
148:
149: // text.setLineWrap(true);
150: text.setEditable(false);
151:
152: Font f = new Font("MonoSpaced", text.getFont().getStyle(), text
153: .getFont().getSize());
154: text.setFont(f);
155:
156: JScrollPane textScroller = new JScrollPane(text);
157:
158: // Create the center banner panel
159: IconWrapperPanel centerPanel = new IconWrapperPanel(
160: new ResourceIcon(BannerDialog.class, BANNER_ICON),
161: textScroller);
162: centerPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4,
163: 4));
164:
165: // Create the south button panel
166: JButton ok = new JButton("Ok");
167: ok.setMnemonic('o');
168: ok.setDefaultCapable(true);
169: ok.addActionListener(new ActionListener() {
170: public void actionPerformed(ActionEvent evt) {
171: // I presume this component is not reused?
172: dispose();
173: }
174: });
175:
176: JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
177: southPanel.add(ok);
178: getRootPane().setDefaultButton(ok);
179:
180: // Build the main panel
181: getContentPane().setLayout(new BorderLayout());
182: getContentPane().add(centerPanel, BorderLayout.CENTER);
183: getContentPane().add(southPanel, BorderLayout.SOUTH);
184:
185: //
186: setSize(500, 245);
187: setResizable(false);
188: }
189: }
|