summaryrefslogtreecommitdiffstats
path: root/pki/base/console/src/com/netscape/admin/certsrv/CMSBasePanel.java
blob: 3430a74d9006f67d2fad22136ad6e40e0a92cf5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.admin.certsrv;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.text.*;
import com.netscape.management.client.util.*;
import com.netscape.management.nmclf.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;

/**
 * Netscape Certificate Server 4.0 Default Base Panel
 *
 * @author Jack Pan-Chen
 * @version $Revision$, $Date$
 */
public class CMSBasePanel extends JPanel 
    implements  ActionListener, DocumentListener,
                ItemListener, ListSelectionListener
{
    /*==========================================================
     * variables
     *==========================================================*/
    public static Insets DEFAULT_CENTER_INSETS = new Insets(0,0,0,0);      
    public static Insets EMPTY_INSETS = new Insets(0,0,0,0);
    public static final int COMPONENT_SPACE = SuiLookAndFeel.COMPONENT_SPACE;
    public static final int SEPARATED_COMPONENT_SPACE = 
                                    SuiLookAndFeel.SEPARATED_COMPONENT_SPACE;
    public static final int DIFFERENT_COMPONENT_SPACE = 
                                    SuiLookAndFeel.DIFFERENT_COMPONENT_SPACE;
    
    protected static final int WARNING_MESSAGE = JOptionPane.WARNING_MESSAGE;
    protected static final int ERROR_MESSAGE = JOptionPane.ERROR_MESSAGE;
    protected static final int INFORMATION_MESSAGE = JOptionPane.INFORMATION_MESSAGE;
    
    protected String mPanelName;            // panel name (UPPERCASE IDENTIFIER)
    protected ResourceBundle mResource;     // resource boundle
    public static int mNonWaitCursor = -1;
    public static Cursor mCursor = null;
    protected JDialog mParent;
    protected JFrame mAdminFrame;

	/*==========================================================
     * constructors
     *==========================================================*/
    public CMSBasePanel(String panelName) {
        this(panelName, ResourceBundle.getBundle(CMSAdminResources.class.getName()));
    }

    public CMSBasePanel(String panelName, ResourceBundle rb) {
        super();
        mPanelName = panelName;
        mResource = rb;
    }
  
    /*==========================================================
	 * public methods
     *==========================================================*/
     
	/**
	 * Set Panel name
	 * @param name panel name
	 */
    public void setPanelName(String name) {
        mPanelName = name;  
    }
    
    /*==========================================================
	 * EVNET HANDLER METHODS
     *==========================================================*/     
     
    //=== ACTIONLISTENER =====================
    public void actionPerformed(ActionEvent e) {
    }

    //== DocumentListener ==
    public void insertUpdate(DocumentEvent e) {
    }
    
    public void removeUpdate(DocumentEvent e){
    }
    
    public void changedUpdate(DocumentEvent e){
    }

    //== ItemListener ==
    public void itemStateChanged(ItemEvent e){
    }

    //== ListSelectionListener ==
    public void valueChanged(ListSelectionEvent e){
    }
     
    /*==========================================================
	 * protected methods
     *==========================================================*/
     
    //create string using formated resource string
    //the string format
    protected String getLocalizedString(String keyword, Object param) {
        return CMSAdminUtil.getLocalizedString(mResource, keyword, param);
    }
    
    protected String getLocalizedString(String keyword, Object [] params) {
        return CMSAdminUtil.getLocalizedString(mResource, keyword, params);
    }    
    
    
    //=== DIALOG MESSAGE =====================
    
    protected void showMessageDialog(String keyword, int messageType ) {
        CMSAdminUtil.showMessageDialog(mResource, mPanelName, keyword, messageType);
    }
    
    protected void showMessageDialog(String keyword) {
        showMessageDialog(keyword, ERROR_MESSAGE);
    }
    
    protected int showConfirmDialog(String keyword, int messageType ) {
        return CMSAdminUtil.showConfirmDialog(mResource, mPanelName, keyword, messageType);
    }    
    
    protected int showConfirmDialog(String keyword, String[] params, int messageType ) {
        return CMSAdminUtil.showConfirmDialog(mResource, mPanelName, keyword, params, messageType);
    }    
    
    protected int showConfirmDialog(String keyword) {
        return showConfirmDialog(keyword, WARNING_MESSAGE);
    }
    
    protected int showConfirmDialog(String keyword, String[] params) {
        return showConfirmDialog(keyword, params, WARNING_MESSAGE);
    }
    
    /**
     * Display Error Message dialog
     *
     * @param message - message to be displayed
     */
    protected void showErrorDialog(String message) {
        CMSAdminUtil.showErrorDialog(mResource, message, ERROR_MESSAGE);
    }
    
    //=== TITLED BORDER ======================
    protected Border makeTitledBorder(String keyword) {
        String label;
        try {
            label = mResource.getString(mPanelName+"_BORDER_"+keyword+"_LABEL");
        } catch (MissingResourceException e) {
            label = "Missing Label";
        }
        TitledBorder border = BorderFactory.createTitledBorder(label);
        Border margin = new EmptyBorder(-3,
                            0,
                            DIFFERENT_COMPONENT_SPACE,
                            0);
        /*
        Border margin = new EmptyBorder(0,
                            DIFFERENT_COMPONENT_SPACE-COMPONENT_SPACE,
                            DIFFERENT_COMPONENT_SPACE,
                            DIFFERENT_COMPONENT_SPACE-COMPONENT_SPACE);
        */
        return new CompoundBorder(border, margin);
    }
    
    //=== LABEL CREATION ====================
    protected JLabel makeJLabel(Icon i, String s, int a) {
        JLabel label = new JLabel();
        if (i != null)
            label.setIcon(i);
        if (s != null)
            label.setText(s);
        if (a != -1)
            label.setHorizontalAlignment(a);
        return label;
      }

    protected JLabel makeJLabel() {
        return makeJLabel((Icon)null, null, -1);
    }

    protected JLabel makeJLabel(String keyword) {
        return makeJLabel(keyword, (Icon) null, -1);
    }
    
    protected JLabel makeJLabel(String keyword, Icon i, int a) {
        return CMSAdminUtil.makeJLabel(mResource, mPanelName, keyword, i, a);
    }

    //===== TEXT FIELD CREATION ================
    protected JTextField makeJTextField(Document d, String s, int len) {
        return CMSAdminUtil.makeJTextField(d, s,len, this);
    }
    
    protected JTextField makeJTextField() {
        return makeJTextField(null, null, -1);
    }

    protected JTextField makeJTextField(int len) {
        return makeJTextField(null, null, len);
    }

    protected JTextField makeJTextField(String s) {
        return makeJTextField(null, s, -1);
    }

    protected JTextField makeJTextField(String s, int len) {
        return makeJTextField(null, s, len);
    }

    //==== PASSWORD FIELD CREATION ======================
    protected JPasswordField makeJPasswordField() {
        return makeJPasswordField(null, null, -1);
    }

    protected JPasswordField makeJPasswordField(Document d, String s, int len) {
        return CMSAdminUtil.makeJPasswordField(d, s,len, this);
    }

    protected JPasswordField makeJPasswordField(int len) {
        return makeJPasswordField(null, null, len);
    }

    protected JPasswordField makeJPasswordField(String s) {
        return makeJPasswordField(null, s, -1);
    }

    protected JPasswordField makeJPasswordField(String s, int len) {
        return makeJPasswordField(null, s, len);
    }

    //====== BUTTON CREATION ===========================
    protected JButton makeJButton(Icon i, String s) {
        JButton button = new JButton();
        if (s != null)
            button.setText(s);
        if (i != null)
            button.setIcon(i);

        button.addActionListener(this);
        return button;
    }

    protected JButton makeJButton() {
        return makeJButton((Icon)null, null);
    }

    protected JButton makeJButton(Icon i) {
        return makeJButton(i, null);
    }

    protected JButton makeJButton(String keyword) {
        return makeJButton(keyword, (Icon)null);
    }
    
    protected JButton makeJButton(String keyword, ActionListener listener) {
        return makeJButton(keyword, (Icon)null, listener);
    }
    
    protected JButton makeJButton(String keyword, Icon i) {
        return makeJButton(keyword, i, this);
    }    
    
    protected JButton makeJButton(String keyword, Icon i, ActionListener listener) {
        return CMSAdminUtil.makeJButton(mResource, mPanelName, keyword, i, listener);
    }

    //===== CHECKBOX CREATION ========================
    protected JCheckBox makeJCheckBox(Icon i, String s, boolean b) {
        JCheckBox cb = new JCheckBox();
        if (s != null)
            cb.setText(s);
        if (i != null)
            cb.setIcon(i);
        cb.setSelected(b);
        cb.addActionListener(this);

        return cb;
    }

    protected JCheckBox makeJCheckBox() {
        return makeJCheckBox((Icon)null, null, false);
    }

    protected JCheckBox makeJCheckBox(Icon i) {
        return makeJCheckBox(i, null, false);
    }

    protected JCheckBox makeJCheckBox(Icon i, boolean b) {
        return makeJCheckBox(i, null, b);
    }

    protected JCheckBox makeJCheckBox(String keyword) {
        return makeJCheckBox(keyword, (Icon)null, false);
    }
    
    protected JCheckBox makeJCheckBox(String keyword, boolean b) {
        return makeJCheckBox(keyword, (Icon)null, b);
    }

    protected JCheckBox makeJCheckBox(String keyword, Icon i) {
        return makeJCheckBox(keyword, i, false);
    }

    protected JCheckBox makeJCheckBox(String keyword, Icon i, boolean val) {
        return CMSAdminUtil.makeJCheckBox(mResource, mPanelName, keyword, i, val, this);
    }

    //====== COMBOBOX CREATION ==========================
    protected JComboBox makeJComboBox(ComboBoxModel cbm) {
        JComboBox cb = new JComboBox();
        if (cbm != null)
            cb.setModel(cbm);
        cb.addItemListener(this);
        return cb;
    }

    protected JComboBox makeJComboBox() {
        return makeJComboBox((ComboBoxModel)null);
    }

    protected JComboBox makeJComboBox(String keyword) {
        String value = null;
        try {
            value = mResource.getString(mPanelName+"_COMBOBOX_"+keyword+"_DEFAULT");
        } catch (MissingResourceException e) {
        }
        JComboBox jcb = makeJComboBox((ComboBoxModel)null);
        String val = null;
        int ii = 0;
        do {
            try {
                val = mResource.getString(mPanelName+"_COMBOBOX_"+keyword+"_VALUE_"+ii);
                if (val != null) {
                    jcb.addItem(val);
                }
                ++ii;
            } catch (MissingResourceException e) {
                val = null;
            }   
        } while (val != null);
        
        if (value != null)
            jcb.setSelectedItem(value);
        return jcb;
    }


    //==== LIST CREATION ============================
    
    protected JList makeJList(DefaultListModel listModel, int visibleCount) {
        return CMSAdminUtil.makeJList(listModel, visibleCount);
    }
    
    //===== RADIO BUTTON CREATION =======================
    protected JRadioButton makeJRadioButton(Icon i, String s, boolean b) {
        JRadioButton rb = new JRadioButton();
        if (s != null)
            rb.setText(s);
        if (i != null)
            rb.setIcon(i);
        rb.setSelected(b);
        rb.addActionListener(this);

        return rb;
    }

    protected JRadioButton makeJRadioButton() {
        return makeJRadioButton((Icon)null, null, false);
    }

    protected JRadioButton makeJRadioButton(Icon i) {
        return makeJRadioButton(i, null, false);
    }

    protected JRadioButton makeJRadioButton(Icon i, boolean b) {
        return makeJRadioButton(i, null, b);
    }

    protected JRadioButton makeJRadioButton(String keyword) {
        return makeJRadioButton(keyword, (Icon)null, false);
    }

    protected JRadioButton makeJRadioButton(String keyword, boolean b) {
        return makeJRadioButton(keyword, (Icon)null, b);
    }

    protected JRadioButton makeJRadioButton(String keyword, Icon i, boolean b) {
        return CMSAdminUtil.makeJRadioButton(mResource, mPanelName, keyword, i, b, this);
    }
    
    /**
	 * Create a panel with horizontally arranged, equally sized buttons
	 * The buttons are aligned to the right in the panel (if it is
	 * stretched beyond the length of the buttons)
	 *
	 * @param buttons An array of buttons for the panel
	 *
	 * @return A panel containing the buttons
	 */
    public static JPanel makeJButtonPanel( JButton[] buttons ) {
        return CMSAdminUtil.makeJButtonPanel(buttons);
	}
	
	public static JPanel makeJButtonPanel( JButton[] buttons, boolean isHelp) {
        return CMSAdminUtil.makeJButtonPanel(buttons, isHelp);
	}

	public static JPanel makeJButtonPanel( JButton[] buttons, boolean isHelp, boolean isConfig) {
        return CMSAdminUtil.makeJButtonPanel(buttons, isHelp, isConfig);
	}
	
    protected void startProgressStatus() {
        if (mNonWaitCursor == -1) {
            mCursor = mParent.getCursor();
            mNonWaitCursor = mCursor.getType();
        }
        mCursor = new Cursor(Cursor.WAIT_CURSOR);
        mParent.setCursor(mCursor);
        if (mAdminFrame != null)
            mAdminFrame.setCursor(mCursor);
        //UtilConsoleGlobals.getActivatedFrame().setCursor(mCursor);
    }

    protected void endProgressStatus() {
       if (mNonWaitCursor == -1)
           mNonWaitCursor = 0;
       mCursor = new Cursor(mNonWaitCursor);
       mParent.setCursor(mCursor);
        if (mAdminFrame != null)
           mAdminFrame.setCursor(mCursor);
       //UtilConsoleGlobals.getActivatedFrame().setCursor(mCursor);
    }

    /*==========================================================
	 * private methods
     *==========================================================*/
    private void setToolTip(String compKeyword, JComponent w) {
        CMSAdminUtil.setToolTip(mResource, mPanelName, compKeyword, w);  
    }
}