1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.netbeans.modules.office.utils; 25 26 import java.awt.BorderLayout; 27 import java.awt.Dimension; 28 29 import javax.swing.JPanel; 30 import javax.swing.JOptionPane; 31 import javax.swing.JCheckBox; 32 import javax.swing.border.EmptyBorder; 33 34 import org.openide.TopManager; 35 import org.openide.NotifyDescriptor; 36 37 public class NagDialog { 38 39 private NotifyDescriptor descriptor; 40 private JPanel panel; 41 private JCheckBox checkbox; 42 NagDialog(String message, String prompt, boolean initialState, int type)43 private NagDialog(String message, String prompt, boolean initialState, 44 int type) { 45 initUI(message, prompt, initialState, type); 46 } 47 createInformationDialog( String message, String prompt, boolean initialState)48 public static NagDialog createInformationDialog( 49 String message, String prompt, boolean initialState) { 50 NagDialog result = new NagDialog( 51 message, prompt, initialState, JOptionPane.INFORMATION_MESSAGE); 52 53 result.setDescriptor(new NotifyDescriptor.Message(result.getPanel(), 54 NotifyDescriptor.PLAIN_MESSAGE)); 55 56 return result; 57 } 58 createConfirmationDialog( String message, String prompt, boolean initialState)59 public static NagDialog createConfirmationDialog( 60 String message, String prompt, boolean initialState) { 61 NagDialog result = new NagDialog( 62 message, prompt, initialState, JOptionPane.QUESTION_MESSAGE); 63 64 result.setDescriptor(new NotifyDescriptor.Confirmation( 65 result.getPanel(), NotifyDescriptor.OK_CANCEL_OPTION, 66 NotifyDescriptor.PLAIN_MESSAGE)); 67 68 return result; 69 } 70 show()71 public boolean show() { 72 TopManager.getDefault().notify(descriptor); 73 74 if (descriptor.getValue() == NotifyDescriptor.OK_OPTION) 75 return true; 76 else 77 return false; 78 } 79 getState()80 public boolean getState() { 81 return checkbox.isSelected(); 82 } 83 getPanel()84 private JPanel getPanel() { 85 return this.panel; 86 } 87 setDescriptor(NotifyDescriptor descriptor)88 private void setDescriptor(NotifyDescriptor descriptor) { 89 this.descriptor = descriptor; 90 } 91 initUI(String message, String prompt, boolean initialState, int type)92 private void initUI(String message, String prompt, boolean initialState, 93 int type) { 94 95 this.panel = new JPanel(); 96 JOptionPane optionPane = new JOptionPane(message, type, 0, null, 97 new Object[0], null) 98 { 99 public int getMaxCharactersPerLineCount() { 100 return 100; 101 } 102 }; 103 optionPane.setUI(new javax.swing.plaf.basic.BasicOptionPaneUI() { 104 public Dimension getMinimumOptionPaneSize() { 105 if (minimumSize == null) { 106 return new Dimension(MinimumWidth, 50); 107 } 108 return new Dimension(minimumSize.width, 50); 109 } 110 }); 111 optionPane.setWantsInput(false); 112 113 JPanel checkPanel = new JPanel(); 114 checkbox = new JCheckBox(prompt, initialState); 115 checkPanel.setLayout(new BorderLayout()); 116 checkPanel.setBorder(new EmptyBorder(0, 20, 0, 0)); 117 checkPanel.add(checkbox, BorderLayout.WEST); 118 119 this.panel.setLayout(new BorderLayout()); 120 this.panel.add(optionPane, BorderLayout.CENTER); 121 this.panel.add(checkPanel, BorderLayout.SOUTH); 122 } 123 } 124