PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package wincrypt;
  22. import java.awt.Component;
  23. import java.awt.Insets;
  24. import javax.swing.JLabel;
  25. import javax.swing.JPanel;
  26. import javax.swing.JScrollPane;
  27. import javax.swing.JTextArea;
  28. import cipher.AdditionalInformationRequester;
  29. import edu.umd.cs.findbugs.annotations.CheckForNull;
  30. import edu.umd.cs.findbugs.annotations.CheckReturnValue;
  31. import edu.umd.cs.findbugs.annotations.NonNull;
  32. import edu.umd.cs.findbugs.annotations.SuppressWarnings;
  33. import net.jcip.annotations.GuardedBy;
  34. import org.gjt.sp.jedit.jEdit;
  35. import org.gjt.sp.jedit.gui.ExtendedGridLayout;
  36. import org.gjt.sp.jedit.gui.ExtendedGridLayoutConstraints;
  37. /**
  38. * The content for the additional information dialog
  39. * where you can enter the description for an encrypting
  40. * or decrypting process.
  41. *
  42. * @author Björn "Vampire" Kautler
  43. * @since WincryptCipherPlugin 0.1
  44. */
  45. public class WincryptCipherAdditionalInformationRequester extends JPanel implements AdditionalInformationRequester {
  46. @GuardedBy("this") private Object[] additionalInformation;
  47. private JLabel descriptionLabel;
  48. private JTextArea descriptionTextArea;
  49. private JScrollPane descriptionScrollPane;
  50. /**
  51. * Constructs a new {@code WincryptCipherAdditionalInformationRequester}.
  52. */
  53. public WincryptCipherAdditionalInformationRequester() {
  54. descriptionLabel = new JLabel(jEdit.getProperty("options.wincrypt.description.label"));
  55. descriptionTextArea = new JTextArea();
  56. descriptionTextArea.setLineWrap(true);
  57. descriptionTextArea.setWrapStyleWord(true);
  58. descriptionLabel.setLabelFor(descriptionTextArea);
  59. descriptionScrollPane = new JScrollPane(descriptionTextArea);
  60. setLayout(new ExtendedGridLayout(5,5,new Insets(0,0,0,0)));
  61. add(descriptionLabel,null);
  62. add(descriptionScrollPane,new ExtendedGridLayoutConstraints(1,descriptionScrollPane));
  63. }
  64. /**
  65. * <p>This method is called before the dialog is displayed.
  66. * Any creation of non-static inner classes should go here
  67. * to not let the {@code this} reference escape during construction.</p>
  68. *
  69. * @see cipher.AdditionalInformationRequester#init()
  70. */
  71. public void init() {
  72. }
  73. /**
  74. * <p>Returns the {@code Component} that should be displayed
  75. * for this additional information requester.
  76. * The return value must not be {@code null}. If no additional
  77. * information is needed, then no additional information requester
  78. * is needed either.</p>
  79. *
  80. * @return The {@code Component} that should be displayed for this additional information requester
  81. * @see cipher.AdditionalInformationRequester#getComponent()
  82. * @see cipher.Cipher#getAdditionalInformationRequester()
  83. */
  84. @NonNull
  85. @CheckReturnValue(explanation = "If the component got requested it should be used")
  86. public Component getComponent() {
  87. return this;
  88. }
  89. /**
  90. * <p>Called when the dialogs &quot;OK&quot; button is clicked.</p>
  91. *
  92. * @see #getAdditionalInformation()
  93. * @see cipher.AdditionalInformationRequester#save()
  94. */
  95. public synchronized void save() {
  96. additionalInformation = new Object[] { descriptionTextArea.getText() };
  97. }
  98. /**
  99. * <p>Returns the additional information entered by the user,
  100. * or {@code null} if the user discarded the dialog.</p>
  101. *
  102. * @return The addtional information entered by the user or {@code null} if the dialog got discarded
  103. */
  104. @SuppressWarnings(value = "EI_EXPOSE_REP",
  105. justification = "This field is only used to give the information out")
  106. @CheckForNull
  107. @CheckReturnValue(explanation = "If the additional information got requested it should be used")
  108. public synchronized Object[] getAdditionalInformation() {
  109. return additionalInformation;
  110. }
  111. }