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.

TitlePanel.java 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. *
  3. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. package com.dmdirc.addons.ui_swing.components;
  24. import java.awt.Color;
  25. import javax.swing.BorderFactory;
  26. import javax.swing.JLabel;
  27. import javax.swing.JPanel;
  28. import javax.swing.border.Border;
  29. import net.miginfocom.swing.MigLayout;
  30. /**
  31. * Displays a title panel.
  32. */
  33. public class TitlePanel extends JPanel {
  34. /**
  35. * A version number for this class. It should be changed whenever the
  36. * class structure is changed (or anything else that would prevent
  37. * serialized objects being unserialized with the new class).
  38. */
  39. private static final long serialVersionUID = -4026633984970698130L;
  40. /** Title label. */
  41. private JLabel title;
  42. /** Title border. */
  43. final Border border;
  44. /**
  45. * Instantiates a new title panel.
  46. *
  47. * @param border Border to use for the panel
  48. */
  49. public TitlePanel(final Border border) {
  50. this(border, "");
  51. }
  52. /**
  53. * Instantiates a new title panel.
  54. *
  55. * @param text Initial text
  56. */
  57. public TitlePanel(final String text) {
  58. this(BorderFactory.createLineBorder(Color.BLACK), text);
  59. }
  60. /**
  61. * Instantiates a new title panel.
  62. *
  63. * @param border Border to use for the panel
  64. * @param text Initial text
  65. */
  66. public TitlePanel(final Border border, final String text) {
  67. super(new MigLayout());
  68. this.border = border;
  69. title = new JLabel(text);
  70. title.setFont(title.getFont().deriveFont((float) (title.getFont().
  71. getSize() * 1.5)));
  72. add(title, "grow, push");
  73. setBorder(border);
  74. setBackground(Color.WHITE);
  75. }
  76. /**
  77. * Sets the text of this title panel.
  78. *
  79. * @param text New title text.
  80. */
  81. public void setText(final String text) {
  82. title.setText(text);
  83. }
  84. }