You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AliasManagerDialog.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (c) 2006-2015 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.ui_swing.dialogs.aliases;
  23. import com.dmdirc.addons.ui_swing.UIUtilities;
  24. import com.dmdirc.addons.ui_swing.components.IconManager;
  25. import com.dmdirc.addons.ui_swing.components.text.TextLabel;
  26. import com.dmdirc.addons.ui_swing.components.validating.ValidationFactory;
  27. import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
  28. import com.dmdirc.addons.ui_swing.injection.MainWindow;
  29. import com.dmdirc.commandparser.aliases.Alias;
  30. import com.dmdirc.interfaces.ui.AliasDialogModel;
  31. import com.dmdirc.util.validators.NotEmptyValidator;
  32. import java.awt.Dimension;
  33. import java.awt.Window;
  34. import javax.inject.Inject;
  35. import javax.swing.JButton;
  36. import javax.swing.JLabel;
  37. import javax.swing.JList;
  38. import javax.swing.JScrollPane;
  39. import javax.swing.JSpinner;
  40. import javax.swing.JTextArea;
  41. import javax.swing.JTextField;
  42. import net.miginfocom.swing.MigLayout;
  43. /**
  44. * Dialog to list and change command aliases.
  45. */
  46. public class AliasManagerDialog extends StandardDialog {
  47. private static final long serialVersionUID = 1;
  48. private final AliasDialogModel model;
  49. private final IconManager iconManager;
  50. private JList<Alias> aliasList;
  51. private JTextField command;
  52. private JSpinner argumentsNumber;
  53. private JTextArea response;
  54. private JButton addAlias;
  55. private JButton deleteAlias;
  56. private JScrollPane responseScroll;
  57. @Inject
  58. public AliasManagerDialog(@MainWindow final Window mainFrame, final AliasDialogModel model,
  59. final IconManager iconManager) {
  60. super(mainFrame, ModalityType.DOCUMENT_MODAL);
  61. this.model = model;
  62. this.iconManager = iconManager;
  63. initComponents();
  64. layoutComponents();
  65. }
  66. @Override
  67. public void display() {
  68. final AliasManagerLinker linker = new AliasManagerLinker(model, this, iconManager);
  69. UIUtilities.addUndoManager(response);
  70. linker.bindCommandList(aliasList);
  71. linker.bindCommand(command);
  72. linker.bindArgumentsNumber(argumentsNumber);
  73. linker.bindResponse(response, responseScroll);
  74. linker.bindAddAlias(addAlias);
  75. linker.bindDeleteAlias(deleteAlias);
  76. linker.bindOKButton(getOkButton());
  77. linker.bindCancelButton(getCancelButton());
  78. linker.init();
  79. model.loadModel();
  80. super.display();
  81. }
  82. private void initComponents() {
  83. setTitle("Alias Manager");
  84. aliasList = new JList<>();
  85. command = new JTextField();
  86. argumentsNumber = new JSpinner();
  87. response = new JTextArea();
  88. addAlias = new JButton("Add Alias");
  89. deleteAlias = new JButton("Delete Alias");
  90. responseScroll = new JScrollPane(response);
  91. }
  92. private void layoutComponents() {
  93. setMinimumSize(new Dimension(800, 400));
  94. setPreferredSize(new Dimension(800, 400));
  95. setLayout(new MigLayout("flowy, fill", "[][][grow]", "[][][][grow][]"));
  96. add(new TextLabel("Aliases allow you to rename commands, to aggregate multiple commands "
  97. + "into a single command, or to make shortcuts to common commands."), "spanx, pushy");
  98. add(new JScrollPane(aliasList),
  99. "growy, pushy, spany 3, split 3, wmin 200, wmax 200");
  100. add(addAlias, "growx");
  101. add(deleteAlias, "growx, wrap");
  102. add(new JLabel("Command: "), "align label, sgx label");
  103. add(new JLabel("Minimum Arguments: "), "align label, sgx label");
  104. add(new JLabel("Response: "), "align label, sgx label, wrap");
  105. add(ValidationFactory.getValidatorPanel(command, model.getCommandValidator(), iconManager),
  106. "growx, pushx");
  107. add(argumentsNumber, "growx, pushx");
  108. add(ValidationFactory.getValidatorPanel(responseScroll, response,
  109. new NotEmptyValidator(), iconManager), "spanx 2, grow, push");
  110. add(getLeftButton(), "flowx, split 3, right, sg button");
  111. add(getRightButton(), "sg button");
  112. }
  113. }