/plugins/SVNPlugin/tags/1.2.0/src/ise/plugin/svn/gui/IgnoreDialog.java

# · Java · 172 lines · 113 code · 24 blank · 35 comment · 7 complexity · 27a67f0b8c2e7e28a936587e1176b928 MD5 · raw file

  1. /*
  2. Copyright (c) 2008, Dale Anson
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without modification,
  5. are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright notice,
  9. this list of conditions and the following disclaimer in the documentation
  10. and/or other materials provided with the distribution.
  11. * Neither the name of the author nor the names of its contributors
  12. may be used to endorse or promote products derived from this software without
  13. specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  21. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. package ise.plugin.svn.gui;
  26. import java.awt.event.*;
  27. import java.io.File;
  28. import javax.swing.*;
  29. import javax.swing.border.EmptyBorder;
  30. import javax.swing.event.*;
  31. import org.gjt.sp.jedit.View;
  32. import org.gjt.sp.jedit.jEdit;
  33. import ise.java.awt.KappaLayout;
  34. import ise.java.awt.LambdaLayout;
  35. public class IgnoreDialog extends JDialog {
  36. private String pathfilename = null;
  37. private String path = null;
  38. private String filename = null;
  39. private String pattern = null;
  40. private boolean recursive = false;
  41. private boolean cancelled = false;
  42. /**
  43. * @param view parent frame
  44. * @param pathfilename absolute path of a file or directory
  45. */
  46. public IgnoreDialog( View view, String pathfilename ) {
  47. super( ( JFrame ) view, jEdit.getProperty( "ips.Ignore_title", "Ignore" ), true );
  48. this.pathfilename = pathfilename;
  49. File f = new File( pathfilename );
  50. path = f.getParent();
  51. filename = f.getName();
  52. JPanel panel = new JPanel( new LambdaLayout() );
  53. panel.setBorder( new EmptyBorder( 6, 6, 6, 6 ) );
  54. // choices
  55. ButtonGroup bg = new ButtonGroup();
  56. final JRadioButton this_file_btn = new JRadioButton( jEdit.getProperty( "ips.This_file", "This file" ) );
  57. final JRadioButton this_dir_btn = new JRadioButton( jEdit.getProperty( "ips.This_directory", "This directory" ) );
  58. final JRadioButton this_dir_pattern_btn = new JRadioButton( jEdit.getProperty( "ips.Files_in_this_directory_with_this_pattern>", "Files in this directory with this pattern:" ) );
  59. if (f.isFile()) {
  60. bg.add( this_file_btn );
  61. this_file_btn.setSelected(true);
  62. }
  63. else {
  64. bg.add( this_dir_btn );
  65. this_dir_btn.setSelected(true);
  66. }
  67. bg.add( this_dir_pattern_btn );
  68. final JTextField pattern_field = new JTextField();
  69. pattern_field.setEnabled( false );
  70. final JCheckBox recursive_cb = new JCheckBox( jEdit.getProperty( "ips.Recursive", "Recursive" ), false );
  71. recursive_cb.setEnabled( false );
  72. // buttons
  73. KappaLayout kl = new KappaLayout();
  74. JPanel btn_panel = new JPanel( kl );
  75. JButton ok_btn = new JButton( jEdit.getProperty( "ips.Ok", "Ok" ) );
  76. JButton cancel_btn = new JButton( jEdit.getProperty( "ips.Cancel", "Cancel" ) );
  77. btn_panel.add( "0, 0, 1, 1, 0, w, 3", ok_btn );
  78. btn_panel.add( "1, 0, 1, 1, 0, w, 3", cancel_btn );
  79. kl.makeColumnsSameWidth( 0, 1 );
  80. // actions
  81. this_dir_pattern_btn.addChangeListener(
  82. new ChangeListener() {
  83. public void stateChanged( ChangeEvent ae ) {
  84. AbstractButton btn = ( AbstractButton ) ae.getSource();
  85. pattern_field.setEnabled( btn.isSelected() );
  86. recursive_cb.setEnabled( btn.isSelected() );
  87. }
  88. }
  89. );
  90. ok_btn.addActionListener(
  91. new ActionListener() {
  92. public void actionPerformed( ActionEvent ae ) {
  93. if ( this_dir_pattern_btn.isSelected() ) {
  94. path = IgnoreDialog.this.pathfilename;
  95. }
  96. pattern = pattern_field.getText();
  97. if ( pattern != null && pattern.length() == 0 ) {
  98. pattern = null;
  99. }
  100. recursive = recursive_cb.isSelected();
  101. IgnoreDialog.this.setVisible( false );
  102. IgnoreDialog.this.dispose();
  103. }
  104. }
  105. );
  106. cancel_btn.addActionListener(
  107. new ActionListener() {
  108. public void actionPerformed( ActionEvent ae ) {
  109. cancelled = true;
  110. IgnoreDialog.this.setVisible( false );
  111. IgnoreDialog.this.dispose();
  112. }
  113. }
  114. );
  115. // layout the panel
  116. panel.add( "0, 0, 8, 1, W, wh, 3", new JLabel( "Ignore:" ) );
  117. panel.add( "0, 1, 8, 1, W, wh, 3", f.isFile() ? this_file_btn : this_dir_btn );
  118. panel.add( "0, 2, 8, 1, W, wh, 3", this_dir_pattern_btn );
  119. panel.add( "1, 3, 7, 1, W, wh, 3", pattern_field );
  120. panel.add( "1, 4, 7, 1, W, wh, 3", recursive_cb );
  121. panel.add( "0, 5, 1, 1, 0, , 0", KappaLayout.createVerticalStrut( 11, true ) );
  122. panel.add( "0, 6, 8, 1, E, , 0", btn_panel );
  123. setContentPane( panel );
  124. pack();
  125. }
  126. public String getPath() {
  127. return path;
  128. }
  129. public String getFilename() {
  130. return filename;
  131. }
  132. public String getPattern() {
  133. return pattern;
  134. }
  135. public boolean getRecursive() {
  136. return recursive;
  137. }
  138. public boolean isCancelled() {
  139. return cancelled;
  140. }
  141. public static void main ( String[] args ) {
  142. IgnoreDialog dialog = new IgnoreDialog( null, "/home/danson/tmp/test/FormatTest.java" );
  143. dialog.setVisible( true );
  144. }
  145. }