PageRenderTime 38ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mpv5/ui/misc/PanelUtils.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 118 lines | 70 code | 20 blank | 28 comment | 12 complexity | f7cfce9d2c25bdc00de755af61a95d45 MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  1. /*
  2. *
  3. *
  4. */
  5. package mpv5.ui.misc;
  6. //~--- non-JDK imports --------------------------------------------------------
  7. import mpv5.ui.beans.LabeledTextField;
  8. //~--- JDK imports ------------------------------------------------------------
  9. import java.awt.AlphaComposite;
  10. import java.awt.Color;
  11. import java.awt.Font;
  12. import java.awt.Graphics;
  13. import java.awt.Graphics2D;
  14. import java.awt.event.ActionEvent;
  15. import java.awt.event.ActionListener;
  16. import java.beans.PropertyChangeEvent;
  17. import java.beans.PropertyChangeListener;
  18. import javax.swing.*;
  19. /**
  20. *
  21. *
  22. */
  23. public class PanelUtils {
  24. /**
  25. * Cuts the text of a textfield to the given length
  26. * @param jTextField
  27. * @param length
  28. */
  29. public static void cut(JTextField jTextField, int length) {
  30. try {
  31. jTextField.setText(jTextField.getText().substring(0, length));
  32. } catch (Exception exception) {}
  33. }
  34. /**
  35. * Clears the text of the given components'
  36. * JTextfieds, LabeledTextFields, JEditorpanes and JTextareas
  37. * @param panel
  38. */
  39. public static void clearText(JPanel panel) {
  40. JTextField jt = null;
  41. Object p;
  42. JEditorPane ja = null;
  43. JTextArea je = null;
  44. LabeledTextField le = null;
  45. for (int i = 0; i < panel.getComponents().length; i++) {
  46. try {
  47. p = (java.lang.Object) panel.getComponents()[i];
  48. if (p.getClass().isInstance(new JTextField())) {
  49. jt = (JTextField) panel.getComponents()[i];
  50. jt.setText("");
  51. }
  52. if (p.getClass().isInstance(new JEditorPane())) {
  53. ja = (JEditorPane) panel.getComponents()[i];
  54. ja.setText(null);
  55. }
  56. if (p.getClass().isInstance(new JTextArea())) {
  57. je = (JTextArea) panel.getComponents()[i];
  58. je.setText("");
  59. }
  60. if (p.getClass().isInstance(new LabeledTextField())) {
  61. le = (LabeledTextField) panel.getComponents()[i];
  62. le.set_Text("");
  63. }
  64. } catch (Exception exception) {}
  65. }
  66. }
  67. /**
  68. * Enables/disables the subcomponents of a panel entirely (not the panel itself!)
  69. * @param component
  70. * @param state True means enabled, false disabled
  71. */
  72. public static void enableSubComponents(JComponent component, boolean state) {
  73. for (int i = 0; i < component.getComponents().length; i++) {
  74. component.getComponents()[i].setEnabled(state);
  75. }
  76. }
  77. public static void setTitle(JPanel aThis, String cname_) {
  78. if (aThis.getParent() instanceof JViewport || aThis.getParent() instanceof JTabbedPane) {
  79. JTabbedPane jTabbedPane = null;
  80. String title1 = cname_;
  81. //this->viewport->scrollpane->tabbedpane
  82. if (aThis.getParent().getParent().getParent() instanceof JTabbedPane) {
  83. jTabbedPane = (JTabbedPane) aThis.getParent().getParent().getParent();
  84. } else {
  85. try {
  86. jTabbedPane = (JTabbedPane) aThis.getParent();
  87. } catch (Exception e) {
  88. //Free floating window
  89. ((JFrame) aThis.getRootPane().getParent()).setTitle(title1);
  90. }
  91. }
  92. if (jTabbedPane != null) {
  93. jTabbedPane.setTitleAt(jTabbedPane.getSelectedIndex(), title1);
  94. }
  95. }
  96. }
  97. }
  98. //~ Formatted by Jindent --- http://www.jindent.com