001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028: package org.netbeans.modules.sun.manager.jbi.util;
029:
030: import java.awt.BorderLayout;
031: import java.awt.Component;
032: import javax.swing.JCheckBox;
033: import javax.swing.JLabel;
034: import javax.swing.JPanel;
035: import javax.swing.border.EmptyBorder;
036: import org.openide.NotifyDescriptor;
037: import org.openide.util.NbBundle;
038:
039: /**
040: * Notification message with do-not-show-again option.
041: *
042: * @author jqian
043: */
044: public class DoNotShowAgainMessage extends NotifyDescriptor.Message {
045:
046: private JCheckBox checkbox;
047: private String checkboxText;
048:
049: /**
050: * Create an informational report about the results of a command.
051: *
052: * @param message the message object
053: * @see NotifyDescriptor#NotifyDescriptor
054: */
055: public DoNotShowAgainMessage(Object message) {
056: this (message, INFORMATION_MESSAGE);
057: }
058:
059: /**
060: * Create an informational report about the results of a command.
061: *
062: * @param message the message object
063: * @see NotifyDescriptor#NotifyDescriptor
064: */
065: public DoNotShowAgainMessage(Object message, int messageType) {
066: this (message, messageType, null);
067: }
068:
069: /**
070: * Create a report about the results of a command.
071: *
072: * @param message the message object
073: * @param messageType the type of message to be displayed
074: * @param checkboxText text for the do-not-show-again checkbox,
075: * null for the default message
076: * @see NotifyDescriptor#NotifyDescriptor
077: */
078: public DoNotShowAgainMessage(Object message, int messageType,
079: String checkboxText) {
080: super (message, messageType);
081:
082: this .checkboxText = checkboxText;
083: setMessage(createDesign());
084: }
085:
086: /**
087: * Get the do-not-show-again state.
088: * @return the state whether the user wants to see this message again.
089: */
090: public boolean getDoNotShowAgain() {
091: return checkbox.isSelected();
092: }
093:
094: private Component createDesign() {
095: JPanel panel = new JPanel();
096: panel.setLayout(new BorderLayout());
097: panel.setBorder(new EmptyBorder(11, 0, 1, 11));
098:
099: Object msg = getMessage();
100: if (msg instanceof Component) {
101: panel.add((Component) msg, BorderLayout.NORTH);
102: } else {
103: JLabel label = new JLabel(super .getMessage().toString());
104: panel.add(label, BorderLayout.NORTH);
105: }
106:
107: if (checkboxText == null) {
108: checkboxText = NbBundle.getMessage(
109: DoNotShowAgainMessage.class,
110: "LBL_DO_NOT_SHOW_MESSAGE_AGAIN"); // NOI18N
111: }
112: checkbox = new JCheckBox(checkboxText);
113:
114: panel.add(checkbox, BorderLayout.SOUTH);
115: panel.requestFocus();
116:
117: return panel;
118: }
119: }
|