PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/bundles/plugins-trunk/CommonControls/common/gui/OkCancelButtons.java

#
Java | 106 lines | 56 code | 16 blank | 34 comment | 6 complexity | 0bad56222507565adf07477c66e41f0e 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. * OkCancelButtons.java - a button pane for EnhancedDialog instances.
  3. * Copyright (c) 2005 Marcelo Vanzin
  4. *
  5. * :tabSize=4:indentSize=4:noTabs=false:
  6. * :folding=explicit:collapseFolds=1:
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package common.gui;
  23. //{{{ Imports
  24. import java.awt.Dimension;
  25. import java.awt.FlowLayout;
  26. import java.awt.event.ActionEvent;
  27. import java.awt.event.ActionListener;
  28. import java.io.File;
  29. import javax.swing.JButton;
  30. import javax.swing.JPanel;
  31. import org.gjt.sp.jedit.gui.EnhancedDialog;
  32. import org.gjt.sp.jedit.jEdit;
  33. //}}}
  34. /**
  35. * A pair of buttons (OK/Cancel) to be added to instances of
  36. * EnhancedDialog. Calls <code>ok()</code> when OK is pressed, and
  37. * <code>cancel()</code> when Cancel is pressed.
  38. *
  39. * <p>Copied from the same class that belonged to the ProjectViewer plugin.</p>
  40. *
  41. * @author Marcelo Vanzin
  42. * @version $Id: OkCancelButtons.java 1350 2005-12-12 04:26:01Z vanza $
  43. * @since CC 0.9.0
  44. */
  45. public class OkCancelButtons extends JPanel
  46. implements ActionListener
  47. {
  48. private EnhancedDialog target;
  49. private JButton cancel;
  50. private JButton ok;
  51. public OkCancelButtons(EnhancedDialog target)
  52. {
  53. super(new FlowLayout());
  54. this.target = target;
  55. cancel = new JButton(jEdit.getProperty("common.cancel"));
  56. ok = new JButton(jEdit.getProperty("common.ok"));
  57. ok.setPreferredSize(cancel.getPreferredSize());
  58. ok.addActionListener(this);
  59. cancel.addActionListener(this);
  60. add(ok);
  61. add(cancel);
  62. resizeButtons();
  63. }
  64. public void setOkText(String text)
  65. {
  66. ok.setText(text);
  67. resizeButtons();
  68. }
  69. public void setCancelText(String text)
  70. {
  71. cancel.setText(text);
  72. resizeButtons();
  73. }
  74. public void actionPerformed(ActionEvent ae)
  75. {
  76. if (ae.getSource() == cancel)
  77. target.cancel();
  78. else if (ae.getSource() == ok)
  79. target.ok();
  80. }
  81. private void resizeButtons()
  82. {
  83. Dimension d1 = ok.getPreferredSize();
  84. Dimension d2 = cancel.getPreferredSize();
  85. if (d1.getWidth() > d2.getWidth())
  86. cancel.setPreferredSize(d1);
  87. else
  88. ok.setPreferredSize(d2);
  89. }
  90. }