PageRenderTime 71ms CodeModel.GetById 52ms app.highlight 12ms RepoModel.GetById 3ms app.codeStats 0ms

/bundles/plugins-trunk/WincryptCipher/src/wincrypt/WincryptCipherAdditionalInformationRequester.java

#
Java | 129 lines | 50 code | 18 blank | 61 comment | 0 complexity | fe0d115d3498a1f69f61043948f590e5 MD5 | raw file
  1/*
  2 * WincryptCipherPlugin - A jEdit plugin as wincrypt cipher implementation for the CipherPlugin
  3 * :tabSize=4:indentSize=4:noTabs=true:
  4 *
  5 * Copyright (C) 2007 Björn "Vampire" Kautler
  6 *
  7 * This program is free software; you can redistribute it and/or
  8 * modify it under the terms of the GNU General Public License
  9 * as published by the Free Software Foundation; either version 2
 10 * of the License, or (at your option) any later version.
 11 *
 12 * This program is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15 * GNU General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU General Public License
 18 * along with this program; if not, write to the Free Software
 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 20 */
 21
 22package wincrypt;
 23
 24import java.awt.Component;
 25import java.awt.Insets;
 26
 27import javax.swing.JLabel;
 28import javax.swing.JPanel;
 29import javax.swing.JScrollPane;
 30import javax.swing.JTextArea;
 31
 32import cipher.AdditionalInformationRequester;
 33
 34import edu.umd.cs.findbugs.annotations.CheckForNull;
 35import edu.umd.cs.findbugs.annotations.CheckReturnValue;
 36import edu.umd.cs.findbugs.annotations.NonNull;
 37import edu.umd.cs.findbugs.annotations.SuppressWarnings;
 38
 39import net.jcip.annotations.GuardedBy;
 40
 41import org.gjt.sp.jedit.jEdit;
 42
 43import org.gjt.sp.jedit.gui.ExtendedGridLayout;
 44import org.gjt.sp.jedit.gui.ExtendedGridLayoutConstraints;
 45
 46/**
 47 * The content for the additional information dialog
 48 * where you can enter the description for an encrypting
 49 * or decrypting process.
 50 * 
 51 * @author Björn "Vampire" Kautler
 52 * @since WincryptCipherPlugin 0.1
 53 */
 54public class WincryptCipherAdditionalInformationRequester extends JPanel implements AdditionalInformationRequester {
 55    @GuardedBy("this") private Object[] additionalInformation;
 56    
 57    private JLabel descriptionLabel;
 58    private JTextArea descriptionTextArea;
 59    private JScrollPane descriptionScrollPane;
 60    
 61    /**
 62     * Constructs a new {@code WincryptCipherAdditionalInformationRequester}.
 63     */
 64    public WincryptCipherAdditionalInformationRequester() {
 65        descriptionLabel = new JLabel(jEdit.getProperty("options.wincrypt.description.label"));
 66        
 67        descriptionTextArea = new JTextArea();
 68        descriptionTextArea.setLineWrap(true);
 69        descriptionTextArea.setWrapStyleWord(true);
 70        descriptionLabel.setLabelFor(descriptionTextArea);
 71        
 72        descriptionScrollPane = new JScrollPane(descriptionTextArea);
 73        
 74        setLayout(new ExtendedGridLayout(5,5,new Insets(0,0,0,0)));
 75        add(descriptionLabel,null);
 76        add(descriptionScrollPane,new ExtendedGridLayoutConstraints(1,descriptionScrollPane));
 77    }
 78    
 79    /**
 80     * <p>This method is called before the dialog is displayed.
 81     * Any creation of non-static inner classes should go here
 82     * to not let the {@code this} reference escape during construction.</p>
 83     * 
 84     * @see cipher.AdditionalInformationRequester#init()
 85     */
 86    public void init() {
 87    }
 88    
 89    /**
 90     * <p>Returns the {@code Component} that should be displayed
 91     * for this additional information requester.
 92     * The return value must not be {@code null}. If no additional
 93     * information is needed, then no additional information requester
 94     * is needed either.</p>
 95     * 
 96     * @return The {@code Component} that should be displayed for this additional information requester
 97     * @see cipher.AdditionalInformationRequester#getComponent()
 98     * @see cipher.Cipher#getAdditionalInformationRequester()
 99     */
100    @NonNull
101    @CheckReturnValue(explanation = "If the component got requested it should be used")
102    public Component getComponent() {
103        return this;
104    }
105    
106    /**
107     * <p>Called when the dialogs &quot;OK&quot; button is clicked.</p>
108     * 
109     * @see #getAdditionalInformation()
110     * @see cipher.AdditionalInformationRequester#save()
111     */
112    public synchronized void save() {
113        additionalInformation = new Object[] { descriptionTextArea.getText() };
114    }
115    
116    /**
117     * <p>Returns the additional information entered by the user,
118     * or {@code null} if the user discarded the dialog.</p>
119     * 
120     * @return The addtional information entered by the user or {@code null} if the dialog got discarded
121     */
122    @SuppressWarnings(value = "EI_EXPOSE_REP",
123                      justification = "This field is only used to give the information out")
124    @CheckForNull
125    @CheckReturnValue(explanation = "If the additional information got requested it should be used")
126    public synchronized Object[] getAdditionalInformation() {
127        return additionalInformation;
128    }
129}