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