Source code: org/mitre/cvw/CommentDialog.java
1 /*
2 * Copyright (c) 1996-2000. The MITRE Corporation (http://www.mitre.org/).
3 * All rights reserved.
4 * CVW comes with ABSOLUTELY NO WARRANTY. See license for details.
5 */
6
7 package org.mitre.cvw;
8
9 import javax.swing.*;
10 import java.awt.*;
11 import java.awt.event.*;
12
13 /**
14 * This is a dialog that is used to submit comments
15 *
16 * @version 1.0
17 * @author Deb Ercolini
18 */
19 public class CommentDialog extends CVWDialog {
20 protected JLabel label;
21 protected JLabel mLabel[] = new JLabel[10];
22 protected JTextField commentField;
23 protected GridBagLayout gridbag = new GridBagLayout();
24 protected Font bold;
25 protected JButton okButton;
26 protected JButton cancelButton;
27 Integer docID;
28 String objNum;
29 String docName;
30
31 public boolean cancel = true;
32 public String comment;
33
34 /**
35 * Constructor
36 *
37 * @param appletFrame The frame to display the dialog in.
38 * @param msg The message to display in the dialog
39 */
40 CommentDialog(Frame appletFrame, String msg) {
41 super(appletFrame, "CVW - Comment", true);
42 Rectangle rect = getParent().getBounds();
43 setLocation(rect.x + (int)(rect.width/3), rect.y + (int)(rect.height/3));
44
45 setContentsLayout(gridbag);
46 bold = new Font("Helvetica", Font.BOLD, 12);
47 commentField = new JTextField(45);
48 // dage 5/25/99 1.1
49 commentField.addActionListener(new ActionListener() {
50 public void actionPerformed(ActionEvent e) {
51 ok();
52 }
53 });
54
55
56 // create buttons
57 okButton = new JButton("OK");
58 okButton.setFont(bold);
59 // srj 3/3/99 1.1
60 okButton.addActionListener(new ActionListener() {
61 public void actionPerformed(ActionEvent e) {
62 ok();
63 }
64 });
65
66 cancelButton = new JButton("Cancel");
67 cancelButton.addActionListener(new ActionListener() {
68 public void actionPerformed(ActionEvent e) {
69 cancel();
70 }
71 });
72
73 JPanel btnPanel = new JPanel();
74 btnPanel.setLayout(new GridLayout(1,0,5,5));
75 btnPanel.add(okButton);
76 btnPanel.add(cancelButton);
77
78 /* 4/11/97 dage - stole this multi line label code from GAB -- OkCancelDialog.
79 */
80 // parse thru msg 60 letter max per line
81 int length = msg.length();
82 length = length/60 + 1;
83
84 // System.err.println("GAB - The lines are " + length + " " + length);
85
86 String subString[] = new String[10];
87 int endIndex = 0;
88 int lastIndex = 0;
89 int lastSpaceSeen = 0;
90 int i;
91
92 for(i=0;i<length-1;i++) {
93 endIndex = lastIndex+60;
94 // System.err.println("endIndex = " + endIndex);
95 subString[i] = msg.substring(lastIndex,endIndex);
96 // System.err.println("substring = " + subString[i] + " " + lastIndex + " " + endIndex);
97 lastSpaceSeen = lastIndex + subString[i].lastIndexOf(" ");
98 // System.err.println("lastSpaceSeen = " + lastSpaceSeen);
99 subString[i] = msg.substring(lastIndex,lastSpaceSeen);
100 // System.err.println("new substring = " + subString[i] + " " + lastIndex + " " + lastSpaceSeen);
101 lastIndex = lastSpaceSeen;
102 }
103 subString[i] = msg.substring(lastIndex);
104
105 for(i=0;i<length;i++) {
106 mLabel[i] = new JLabel(subString[i]);
107 }
108
109 String file = NPDocServer.getSystemDir("images/Warning.gif");
110 Image icon = Toolkit.getDefaultToolkit().getImage(file);
111 JLabel iconPanel = new JLabel(new ImageIcon(icon));
112
113 constrain(this, iconPanel, gridbag, 0,0,1,GridBagConstraints.RELATIVE,
114 GridBagConstraints.NONE,
115 GridBagConstraints.NORTH, 0.0, 1.0, 0, 5, 0, 5, 0, 0);
116
117 for(i=0;i<length;i++) {
118 constrain(this, mLabel[i], gridbag, 1,(i+1),GridBagConstraints.REMAINDER,1, GridBagConstraints.NONE,
119 GridBagConstraints.WEST, 0.0, 0.0, 0, 5, 0, 5, 0, 0);
120 }
121
122 constrain(this, commentField, gridbag, 0,i+1,GridBagConstraints.REMAINDER,1, GridBagConstraints.HORIZONTAL,
123 GridBagConstraints.WEST, 0.0, 0.0, 10, 5, 5, 5, 0, 0);
124 constrain(this, btnPanel, gridbag, 0,(i+2),GridBagConstraints.REMAINDER,1,
125 GridBagConstraints.NONE,
126 GridBagConstraints.CENTER, 0.0, 0.0, 10, 5, 10, 5, 8, 0);
127
128 }
129
130 /**
131 * Handles the ok button event
132 */
133 public void ok() {
134 comment = commentField.getText();
135 cancel = false;
136 this.dispose();
137 }
138
139 /**
140 * Handles the cancel button event
141 */
142 public void cancel() {
143 cancel = true;
144 this.dispose();
145 }
146
147 /**
148 * Displays/hides the dialog depending on the boolean parameter
149 * @param b if <code>true</code> shows the dialog requesting focus at the text field
150 */
151 public void setVisible(boolean b) {
152 if (b)
153 commentField.requestFocus();
154 super.setVisible(b);
155 }
156 }