1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * ident "%Z%%M% %I% %E% SMI" 24*7c478bd9Sstevel@tonic-gate * 25*7c478bd9Sstevel@tonic-gate * Copyright (c) 1999-2000 by Sun Microsystems, Inc. 26*7c478bd9Sstevel@tonic-gate * All rights reserved. 27*7c478bd9Sstevel@tonic-gate */ 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate import java.awt.*; 30*7c478bd9Sstevel@tonic-gate import java.awt.event.*; 31*7c478bd9Sstevel@tonic-gate import java.util.StringTokenizer; 32*7c478bd9Sstevel@tonic-gate import java.util.ResourceBundle; 33*7c478bd9Sstevel@tonic-gate import java.util.MissingResourceException; 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate /** 36*7c478bd9Sstevel@tonic-gate * Dialog box for diaplaying Help 37*7c478bd9Sstevel@tonic-gate * 38*7c478bd9Sstevel@tonic-gate */ 39*7c478bd9Sstevel@tonic-gate public class HelpDialog extends Dialog { 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate protected Button b; 42*7c478bd9Sstevel@tonic-gate protected TextArea t; 43*7c478bd9Sstevel@tonic-gate private Frame parent; 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate public static int NUM_ROWS = 10; 46*7c478bd9Sstevel@tonic-gate public static int NUM_COLS = 45; 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate // For I18N 49*7c478bd9Sstevel@tonic-gate private static ResourceBundle rb = 50*7c478bd9Sstevel@tonic-gate ResourceBundle.getBundle("GuiResource" /* NOI18N */); 51*7c478bd9Sstevel@tonic-gate HelpDialog(Frame parent, String title, boolean mode)52*7c478bd9Sstevel@tonic-gate public HelpDialog(Frame parent, String title, boolean mode) { 53*7c478bd9Sstevel@tonic-gate this(parent, title, mode, NUM_ROWS, NUM_COLS); 54*7c478bd9Sstevel@tonic-gate } 55*7c478bd9Sstevel@tonic-gate HelpDialog(Frame parent, String title, boolean mode, int numRows, int numCols)56*7c478bd9Sstevel@tonic-gate public HelpDialog(Frame parent, String title, boolean mode, int numRows, 57*7c478bd9Sstevel@tonic-gate int numCols) { 58*7c478bd9Sstevel@tonic-gate super(parent, title, mode); 59*7c478bd9Sstevel@tonic-gate this.parent = parent; 60*7c478bd9Sstevel@tonic-gate setBackground(parent.getBackground()); 61*7c478bd9Sstevel@tonic-gate setForeground(parent.getForeground()); 62*7c478bd9Sstevel@tonic-gate addButtonAndTextArea(numRows, numCols); 63*7c478bd9Sstevel@tonic-gate addWindowListener(new WindowAdapter() { 64*7c478bd9Sstevel@tonic-gate public void windowClosing(WindowEvent e) { 65*7c478bd9Sstevel@tonic-gate quit(); 66*7c478bd9Sstevel@tonic-gate } 67*7c478bd9Sstevel@tonic-gate }); 68*7c478bd9Sstevel@tonic-gate } 69*7c478bd9Sstevel@tonic-gate quit()70*7c478bd9Sstevel@tonic-gate protected void quit() { 71*7c478bd9Sstevel@tonic-gate dispose(); 72*7c478bd9Sstevel@tonic-gate } 73*7c478bd9Sstevel@tonic-gate addButtonAndTextArea(int numRows, int numCols)74*7c478bd9Sstevel@tonic-gate private void addButtonAndTextArea(int numRows, int numCols) { 75*7c478bd9Sstevel@tonic-gate t = new TextArea(null, numRows, numCols, 76*7c478bd9Sstevel@tonic-gate TextArea.SCROLLBARS_VERTICAL_ONLY); 77*7c478bd9Sstevel@tonic-gate t.setEditable(false); 78*7c478bd9Sstevel@tonic-gate b = new Button(getString("Dismiss")); 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate setLayout(new GridBagLayout()); 81*7c478bd9Sstevel@tonic-gate GridBagConstraints gbc = new GridBagConstraints(); 82*7c478bd9Sstevel@tonic-gate gbc.weightx = gbc.weighty = 1; 83*7c478bd9Sstevel@tonic-gate gbc.fill = GridBagConstraints.BOTH; 84*7c478bd9Sstevel@tonic-gate gbc.gridwidth = GridBagConstraints.REMAINDER; 85*7c478bd9Sstevel@tonic-gate add(t, gbc); 86*7c478bd9Sstevel@tonic-gate gbc.fill = GridBagConstraints.NONE; 87*7c478bd9Sstevel@tonic-gate add(b, gbc); 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate pack(); 90*7c478bd9Sstevel@tonic-gate setResizable(false); 91*7c478bd9Sstevel@tonic-gate setLocationBesideParent(parent); 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate b.addActionListener(new ActionListener() { 94*7c478bd9Sstevel@tonic-gate public void actionPerformed(ActionEvent e) { 95*7c478bd9Sstevel@tonic-gate quit(); 96*7c478bd9Sstevel@tonic-gate } 97*7c478bd9Sstevel@tonic-gate }); 98*7c478bd9Sstevel@tonic-gate } 99*7c478bd9Sstevel@tonic-gate setLocationBesideParent(Frame parent)100*7c478bd9Sstevel@tonic-gate private void setLocationBesideParent(Frame parent) { 101*7c478bd9Sstevel@tonic-gate Point p = parent.getLocationOnScreen(); 102*7c478bd9Sstevel@tonic-gate Dimension parentSize = parent.getSize(); 103*7c478bd9Sstevel@tonic-gate Dimension mySize = getSize(); 104*7c478bd9Sstevel@tonic-gate p.x += parentSize.width; 105*7c478bd9Sstevel@tonic-gate p.y += parentSize.height/2 - mySize.height/2; 106*7c478bd9Sstevel@tonic-gate setLocation(p.x, p.y); 107*7c478bd9Sstevel@tonic-gate } 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate setText(String text)110*7c478bd9Sstevel@tonic-gate public void setText(String text) { 111*7c478bd9Sstevel@tonic-gate t.setText(text); 112*7c478bd9Sstevel@tonic-gate } 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate /** 115*7c478bd9Sstevel@tonic-gate * Call rb.getString(), but catch exception and return English 116*7c478bd9Sstevel@tonic-gate * key so that small spelling errors don't cripple the GUI 117*7c478bd9Sstevel@tonic-gate * 118*7c478bd9Sstevel@tonic-gate */ getString(String key)119*7c478bd9Sstevel@tonic-gate private static final String getString(String key) { 120*7c478bd9Sstevel@tonic-gate try { 121*7c478bd9Sstevel@tonic-gate String res = rb.getString(key); 122*7c478bd9Sstevel@tonic-gate return res; 123*7c478bd9Sstevel@tonic-gate } catch (MissingResourceException e) { 124*7c478bd9Sstevel@tonic-gate System.out.println("Missing resource "+key+", using English."); 125*7c478bd9Sstevel@tonic-gate return key; 126*7c478bd9Sstevel@tonic-gate } 127*7c478bd9Sstevel@tonic-gate } 128*7c478bd9Sstevel@tonic-gate 129*7c478bd9Sstevel@tonic-gate /* 130*7c478bd9Sstevel@tonic-gate public static void main(String args[]) { 131*7c478bd9Sstevel@tonic-gate Frame f = new Frame(); 132*7c478bd9Sstevel@tonic-gate f.setVisible(true); 133*7c478bd9Sstevel@tonic-gate HelpDialog hd = new HelpDialog(f, "Test HelpDialog", false); 134*7c478bd9Sstevel@tonic-gate hd.setVisible(true); 135*7c478bd9Sstevel@tonic-gate } 136*7c478bd9Sstevel@tonic-gate */ 137*7c478bd9Sstevel@tonic-gate } 138