Source code: javatools/swing/MoreSwingUtilities.java
1 /*
2 * MoreSwingUtilities.java
3 *
4 * Created on 4 gennaio 2003, 12.00
5 Javatools (modified version) - Some useful general classes.
6 Copyright (C) 2002-2003 Chris Bitmead (original) Antonio Petrelli (modified)
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 Contact me at: brenmcguire@users.sourceforge.net
23
24 * -- Additional notice --
25 * Method "centerWindow" contains code from class:
26 * "SplashScreen" - Copyright (C) Andrea Carboni.
27 * -- End of additional notice --
28 */
29
30 package javatools.swing;
31
32 import java.awt.Toolkit;
33 import javatools.db.DbRow;
34 import javatools.util.*;
35 import javatools.awt.event.*;
36
37 /** Additional static methods for Swing components.
38 * @author Antonio Petrelli
39 * @version 0.1.8
40 */
41 public class MoreSwingUtilities {
42
43 /** Creates a new instance of MoreSwingUtilities */
44 public MoreSwingUtilities() {
45 }
46
47 /** Calls a <CODE>wakeUp</CODE> method of a <CODE>RunningRunnable</CODE> object when
48 * the event queue dispatches it.
49 * @param runnable The object to use.
50 */
51 public static void invokeWakingUp(RunningRunnable runnable) {
52 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
53 new WakingEvent(Toolkit.getDefaultToolkit(), runnable));
54 }
55
56 /** Reloads a tree in a thread-safe way.
57 * @param tree The tree to be reloaded.
58 */
59 public static void reloadTree(javax.swing.JTree tree) {
60 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
61 new TreeReloadEvent(Toolkit.getDefaultToolkit(), tree));
62 }
63
64 /** Reloads a tree in a thread-safe way.
65 * @param tree The tree to be reloaded.
66 * @param node The node to be reloaded.
67 */
68 public static void reloadTree(javax.swing.JTree tree, javax.swing.tree.TreeNode node) {
69 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
70 new TreeReloadEvent(Toolkit.getDefaultToolkit(), tree, node));
71 }
72
73 /** Expands a node in a thread-safe way.
74 * @param tree The tree to be expanded.
75 * @param node The node to be expanded.
76 */
77 public static void expandLater(javax.swing.JTree tree, javax.swing.tree.TreeNode node) {
78 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
79 new TreeExpansionEvent(Toolkit.getDefaultToolkit(), tree, node));
80 }
81
82 /** Resizes a table in a thread-safe way.
83 * @param table The table to be resized.
84 * @param sizes The array of sizes. Each index corresponds to each column's index of the table.
85 */
86 public static void resizeTable(javax.swing.JTable table, int[] sizes) {
87 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
88 new TableResizeEvent(Toolkit.getDefaultToolkit(), table, sizes));
89 }
90
91 /** Disable all tabs of a JTabbedPane.
92 * @param tab The tabbed pane to be used.
93 */
94 public static void disableTabs(javax.swing.JTabbedPane tab) {
95 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
96 new TabDisableEvent(Toolkit.getDefaultToolkit(), tab));
97 }
98
99 /** Enables a tab of a JTabbedPane.
100 * @param tab The tabbed pane to use.
101 * @param index The index of the tab to be enabled.
102 */
103 public static void enableTab(javax.swing.JTabbedPane tab, int index) {
104 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
105 new TabEnableEvent(Toolkit.getDefaultToolkit(), tab, index));
106 }
107
108 /** Calls the <CODE>use</CODE> method of a <CODE>DbRowUser</CODE> object in a
109 * thread-safe way.
110 * @param user The object that contains the method.
111 * @param row The row to use.
112 */
113 public static void useDbRow(DbRowUser user, DbRow row) {
114 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
115 new DbRowUseEvent(Toolkit.getDefaultToolkit(), user, row));
116 }
117
118 /** Sets a label's text in a thread-safe way.
119 * @param label The label to use.
120 * @param text The text to put.
121 */
122 public static void setTextLater(javax.swing.JLabel label, String text) {
123 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
124 new SetTextEvent(Toolkit.getDefaultToolkit(), label, text));
125 }
126 }