Changeset 12113
- Timestamp:
- 2006-07-10T14:15:33+12:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/Dictionary.java
r10668 r12113 37 37 package org.greenstone.gatherer; 38 38 39 import java.awt.*; 40 import java.io.*; 41 import java.util.*; 42 import javax.swing.*; 43 import javax.swing.plaf.*; 44 import javax.swing.text.*; 45 import javax.swing.tree.*; 39 import javax.swing.plaf.FontUIResource; 40 import java.util.HashMap; 41 import java.util.Locale; 42 import java.util.ResourceBundle; 43 46 44 47 45 /** Extends the ResourceBundle class to allow for the automatic insertion of arguments.<BR> … … 194 192 } 195 193 194 } 196 195 197 static public void registerBoth(Component component, String text_key, String tooltip_key)198 {199 setText(component, text_key);200 setTooltip(component, tooltip_key);201 }202 203 204 static public void registerText(Component component, String text_key)205 {206 setText(component, text_key);207 }208 209 210 static public void registerText(Component component, String text_key, String[] args)211 {212 setText(component, text_key, args);213 }214 215 216 static public void registerTooltip(Component component, String tooltip_key)217 {218 setTooltip(component, tooltip_key);219 }220 221 222 static public void registerTooltipText(Component component, String tooltip)223 {224 setTooltipText(component, tooltip);225 }226 227 228 static public void setBoth(Component component, String text_key, String tooltip_key)229 {230 setText(component, text_key);231 setTooltip(component, tooltip_key);232 }233 234 235 static public void setText(Component component, String text_key)236 {237 setText(component, text_key, null);238 }239 240 241 static public void setText(Component component, String text_key, String[] args)242 {243 if (component != null) {244 // Update the component using the AWTEvent queue245 SwingUtilities.invokeLater(new ComponentUpdateTask(component, get(text_key, args), null));246 }247 }248 249 250 static public void setTooltip(Component component, String tooltip_key)251 {252 if (component != null) {253 // Update the component using the AWTEvent queue254 SwingUtilities.invokeLater(new ComponentUpdateTask(component, null, get(tooltip_key)));255 }256 }257 258 259 static public void setTooltipText(Component component, String tooltip)260 {261 if (component != null) {262 // Update the component using the AWTEvent queue263 SwingUtilities.invokeLater(new ComponentUpdateTask(component, null, tooltip));264 }265 }266 267 268 static private class ComponentUpdateTask269 implements Runnable {270 271 private Component component = null;272 private String text = null;273 private String tooltip = null;274 275 276 public ComponentUpdateTask(Component component, String text, String tooltip)277 {278 this.component = component;279 this.text = text;280 this.tooltip = tooltip;281 }282 283 284 public void run()285 {286 // If the component has text287 if (text != null) {288 if (component instanceof AbstractButton) {289 ((AbstractButton) component).setText(text);290 }291 else if (component instanceof Frame) {292 ((Frame) component).setTitle(text);293 }294 else if (component instanceof JDialog) {295 ((JDialog) component).setTitle(text);296 }297 else if (component instanceof JLabel) {298 ((JLabel) component).setText(text);299 }300 else if (component instanceof JProgressBar) {301 ((JProgressBar) component).setString(text);302 }303 else if (component instanceof JTextComponent) {304 ((JTextComponent) component).setText(text);305 ((JTextComponent) component).setCaretPosition(0);306 }307 else {308 System.err.println("Unhandled component: " + component.getClass());309 }310 }311 312 // If the component has a tooltip313 if (tooltip != null) {314 if (component instanceof JComponent) {315 ((JComponent) component).setToolTipText(tooltip);316 }317 }318 }319 }320 321 322 /**323 * Register a tab pane component. This will be deprecated eventually. */324 static public void register(JTabbedPane component)325 {326 if (component != null) {327 String[] args = new String[component.getTabCount()];328 329 // Iterate through the tabbed panes tabs, updating values and recording the original key of each item in args.330 for (int i = 0; i < args.length; i++) {331 if (args[i] == null) {332 args[i] = component.getTitleAt(i);333 }334 String value = get(args[i], (String[]) null);335 String tooltip = get(args[i] + "_Tooltip", (String[]) null);336 JTabbedPaneChangeTask task = new JTabbedPaneChangeTask(component, i, value, tooltip);337 SwingUtilities.invokeLater(task);338 }339 }340 }341 342 343 /** Updates a tabbed panes tab title and tooltip. */344 static private class JTabbedPaneChangeTask345 implements Runnable {346 347 private JTabbedPane component;348 private int index;349 private String value;350 private String tooltip;351 352 public JTabbedPaneChangeTask(JTabbedPane component, int index, String value, String tooltip) {353 this.component = component;354 this.index = index;355 this.value = value;356 this.tooltip = tooltip;357 }358 359 public void run() {360 component.setTitleAt(index, value);361 component.setToolTipTextAt(index, tooltip);362 }363 }364 }
Note:
See TracChangeset
for help on using the changeset viewer.