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