Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ColourPickerDialog.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (c) 2006-2014 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.components.colours;
  23. import com.dmdirc.ui.IconManager;
  24. import com.dmdirc.ui.messages.ColourManager;
  25. import java.awt.Component;
  26. import java.awt.Window;
  27. import java.awt.event.ActionListener;
  28. import java.awt.event.WindowAdapter;
  29. import java.awt.event.WindowEvent;
  30. import javax.swing.JDialog;
  31. /**
  32. * Colour picker dialog.
  33. */
  34. public class ColourPickerDialog extends JDialog {
  35. /** Serial version UID. */
  36. private static final long serialVersionUID = 1;
  37. /** Colour chooser panel. */
  38. private final ColourPickerPanel colourChooser;
  39. /** Object to center dialog on. */
  40. private final Component centerObject;
  41. /**
  42. * Creates a new instance of ColourPickerDialog.
  43. *
  44. * @param centerObject Object to center dialog on
  45. * @param colourManager The colour manager to use to parse colours.
  46. * @param iconManager Icon manager
  47. * @param showIRC show irc colours
  48. * @param showHex show hex colours
  49. */
  50. public ColourPickerDialog(final Component centerObject,
  51. final ColourManager colourManager,
  52. final IconManager iconManager,
  53. final boolean showIRC, final boolean showHex) {
  54. this(centerObject, colourManager, iconManager, showIRC, showHex, null);
  55. }
  56. /**
  57. * Creates a new instance of ColourPickerDialog.
  58. *
  59. * @param centerObject Object to center dialog on
  60. * @param colourManager The colour manager to use to parse colours.
  61. * @param iconManager Icon manager
  62. * @param showIRC show irc colours
  63. * @param showHex show hex colours
  64. * @param window Parent window
  65. *
  66. * @since 0.6
  67. */
  68. public ColourPickerDialog(final Component centerObject,
  69. final ColourManager colourManager,
  70. final IconManager iconManager,
  71. final boolean showIRC, final boolean showHex, final Window window) {
  72. super(window, ModalityType.MODELESS);
  73. this.centerObject = centerObject;
  74. setIconImage(iconManager.getImage("icon"));
  75. colourChooser = new ColourPickerPanel(colourManager, showIRC, showHex);
  76. setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
  77. add(colourChooser);
  78. setResizable(false);
  79. setFocusableWindowState(false);
  80. setWindow(window);
  81. }
  82. /**
  83. * Adds an actions listener to this dialog.
  84. *
  85. * @param listener the listener to add
  86. */
  87. public void addActionListener(final ActionListener listener) {
  88. colourChooser.addActionListener(listener);
  89. }
  90. /**
  91. * Sets the Parent window.
  92. *
  93. * @param window Parent window
  94. */
  95. public void setWindow(final Window window) {
  96. if (window != null) {
  97. window.addWindowListener(new WindowAdapter() {
  98. @Override
  99. public void windowClosed(final WindowEvent e) {
  100. dispose();
  101. }
  102. });
  103. }
  104. }
  105. @Override
  106. public void setVisible(final boolean visible) {
  107. super.setVisible(visible);
  108. if (visible) {
  109. setSize(colourChooser.getPreferredSize());
  110. setLocationRelativeTo(centerObject);
  111. }
  112. }
  113. }