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 DoNotShowAgainConfirmation extends
045: NotifyDescriptor.Confirmation {
046:
047: private JCheckBox checkbox;
048: private String checkboxText;
049:
050: /**
051: * Create a yes/no/cancel question with default title.
052: *
053: * @param message the message object
054: * @see NotifyDescriptor#NotifyDescriptor
055: */
056: public DoNotShowAgainConfirmation(Object message) {
057: this (message, YES_NO_CANCEL_OPTION);
058: }
059:
060: /**
061: * Create a yes/no/cancel question.
062: *
063: * @param message the message object
064: * @param title the dialog title
065: * @see NotifyDescriptor#NotifyDescriptor
066: */
067: public DoNotShowAgainConfirmation(Object message, String title) {
068: this (message, title, YES_NO_CANCEL_OPTION);
069: }
070:
071: /**
072: * Create a question with default title.
073: *
074: * @param message the message object
075: * @param optionType the type of options to display to the user
076: * @see NotifyDescriptor#NotifyDescriptor
077: */
078: public DoNotShowAgainConfirmation(Object message, int optionType) {
079: this (message, optionType, QUESTION_MESSAGE);
080: }
081:
082: /**
083: * Create a question.
084: *
085: * @param message the message object
086: * @param title the dialog title
087: * @param optionType the type of options to display to the user
088: * @see NotifyDescriptor#NotifyDescriptor
089: */
090: public DoNotShowAgainConfirmation(Object message, String title,
091: int optionType) {
092: this (message, title, optionType, QUESTION_MESSAGE);
093: }
094:
095: /**
096: * Create a confirmation with default title.
097: *
098: * @param message the message object
099: * @param optionType the type of options to display to the user
100: * @param messageType the type of message to use
101: * @see NotifyDescriptor#NotifyDescriptor
102: */
103: public DoNotShowAgainConfirmation(Object message, int optionType,
104: int messageType) {
105: super (message, optionType, messageType);
106:
107: setMessage(createDesign());
108: }
109:
110: /**
111: * Create a confirmation.
112: *
113: * @param message the message object
114: * @param title the dialog title
115: * @param optionType the type of options to display to the user
116: * @param messageType the type of message to use
117: * @see NotifyDescriptor#NotifyDescriptor
118: */
119: public DoNotShowAgainConfirmation(Object message, String title,
120: int optionType, int messageType) {
121: super (message, title, optionType, messageType);
122:
123: setMessage(createDesign());
124: }
125:
126: /**
127: * Get the do-not-show-again state.
128: * @return the state whether the user wants to see this message again.
129: */
130: public boolean getDoNotShowAgain() {
131: return checkbox.isSelected();
132: }
133:
134: private Component createDesign() {
135: JPanel panel = new JPanel();
136: panel.setLayout(new BorderLayout());
137: panel.setBorder(new EmptyBorder(11, 0, 1, 11));
138:
139: Object msg = getMessage();
140: if (msg instanceof Component) {
141: panel.add((Component) msg, BorderLayout.NORTH);
142: } else {
143: JLabel label = new JLabel(super .getMessage().toString());
144: panel.add(label, BorderLayout.NORTH);
145: }
146:
147: if (checkboxText == null) {
148: checkboxText = NbBundle.getMessage(
149: DoNotShowAgainConfirmation.class,
150: "LBL_DO_NOT_ASK_FOR_CONFIRMATION_AGAIN"); // NOI18N
151: }
152:
153: checkbox = new JCheckBox(checkboxText);
154:
155: panel.add(checkbox, BorderLayout.SOUTH);
156: panel.requestFocus();
157:
158: return panel;
159: }
160: }
|