FileDocCategorySizeDatePackage
Messages.javaAPI DocAzureus 3.0.3.410765Mon Jun 25 16:48:32 BST 2007org.gudy.azureus2.ui.swt

Messages

public class Messages extends Object
author
Arbeiten

Fields Summary
private static final boolean
SWTBUG_COLUMN
private static final Pattern
HIG_ELLIP_EXP
Constructors Summary
private Messages()

 // rec. hig style on some platforms

      
    

    // TODO Auto-generated constructor stub
  
Methods Summary
public static voidsetLanguageText(Widget widget, java.lang.String key)

    setLanguageText(widget, key, false);
  
public static voidsetLanguageText(Widget widget, java.lang.String key, java.lang.String[] params)

    setLanguageText(widget, key, params, false);
  
public static voidsetLanguageText(Widget widget, java.lang.String key, boolean setTooltipOnly)

  	setLanguageText( widget, key, null, setTooltipOnly );
  
private static voidsetLanguageText(Widget widget, java.lang.String key, java.lang.String[] params, boolean setTooltipOnly)

  	widget.setData(key);
  	if(!setTooltipOnly)
      updateLanguageFromData(widget, params);
  	updateToolTipFromData(widget);
  
public static voidsetLanguageTooltip(Widget widget, java.lang.String key)

  	if (widget == null || widget.isDisposed()) {
  		return;
  	}

  	widget.setData(key);
    updateTooltipLanguageFromData(widget);
  
public static voidupdateLanguageForControl(Widget widget)

    if (widget == null || widget.isDisposed())
      return;

    updateLanguageFromData(widget,null);	// OK, so we loose parameters on language change...
    updateToolTipFromData(widget);

    if (widget instanceof CTabFolder) {
      CTabFolder folder = (CTabFolder) widget;
      CTabItem[] items = folder.getItems();
      for (int i = 0; i < items.length; i++) {
        updateLanguageForControl(items[i]);
        updateLanguageForControl(items[i].getControl());
      }
    } else if (widget instanceof TabFolder) {
      TabFolder folder = (TabFolder) widget;
      TabItem[] items = folder.getItems();
      for (int i = 0; i < items.length; i++) {
        updateLanguageForControl(items[i]);
        updateLanguageForControl(items[i].getControl());
      }
    }
    else if(widget instanceof CoolBar) {
      CoolItem[] items = ((CoolBar)widget).getItems();
      for(int i = 0 ; i < items.length ; i++) {
        Control control = items[i].getControl();
        updateLanguageForControl(control);
      }
    }
    else if(widget instanceof ToolBar) {
      ToolItem[] items = ((ToolBar)widget).getItems();
      for(int i = 0 ; i < items.length ; i++) {
        updateLanguageForControl(items[i]);
      }
    }
    else if (widget instanceof Composite) {
      Composite group = (Composite) widget;
      Control[] controls = group.getChildren();
      for (int i = 0; i < controls.length; i++) {
        updateLanguageForControl(controls[i]);
      }
      if (widget instanceof Table) {
        Table table = (Table) widget;
        TableColumn[] columns = table.getColumns();
        for (int i = 0; i < columns.length; i++) {
          updateLanguageFromData(columns[i], null);
        }
        updateLanguageForControl(table.getMenu());
        
        // XXX We could (should?) send this event for all widget types
        // XXX Would it better to have a custom event type?
        if (SWT.getVersion() > 3200) {
	        Event event = new Event();
	    		// SWT 3.2 only.  Code Ok -- Only called in SWT 3.2 mode
	        event.type = SWT.Settings;
	        event.widget = widget;
	        widget.notifyListeners(SWT.Settings, event);
        }
      }
      else if (widget instanceof Tree) {
        Tree tree = (Tree) widget;
        TreeItem[] treeitems = tree.getItems();
        for (int i = 0; i < treeitems.length; i++) {
          updateLanguageForControl(treeitems[i]);
        }
      }
      else if (widget instanceof TreeItem) {
        TreeItem treeItem = (TreeItem) widget;
        TreeItem[] treeitems = treeItem.getItems();
        for (int i = 0; i < treeitems.length; i++) {
          updateLanguageForControl(treeitems[i]);
        }
      }
        
      group.layout();
    }
    else if (widget instanceof MenuItem) {
      MenuItem menuItem = (MenuItem) widget;
      updateLanguageForControl(menuItem.getMenu());
    }
    else if (widget instanceof Menu) {
      Menu menu = (Menu) widget;
      if (menu.getStyle() == SWT.POP_UP)
        System.out.println("POP_UP");

      MenuItem[] items = menu.getItems();
      for (int i = 0; i < items.length; i++) {
        updateLanguageForControl(items[i]);
      }
    }
    else if (widget instanceof TreeItem) {
      TreeItem treeitem = (TreeItem) widget;
      TreeItem[] treeitems = treeitem.getItems();
      for (int i = 0; i < treeitems.length; i++) {
        updateLanguageFromData(treeitems[i], null);
      }
    }
    
  
private static voidupdateLanguageFromData(Widget widget, java.lang.String[] params)

  	if (widget == null || widget.isDisposed()) {
  		return;
  	}

      if (widget.getData() != null) {
        String key = null;
        try {
          key = (String) widget.getData();
        } catch(ClassCastException e) {
        }
        
        if(key == null) return;        
        if(key.endsWith(".tooltip")) return;
        
        String	message;
        
        if ( params == null ){
        	
        	message = MessageText.getString((String) widget.getData());
        }else{
        	
           	message = MessageText.getString((String) widget.getData(), params);         	
        }        
        
        if (widget instanceof MenuItem) {
            final MenuItem menuItem = ((MenuItem) widget);
            boolean indent = (menuItem.getData("IndentItem") != null);

            if(Constants.isOSX)
                message = HIG_ELLIP_EXP.matcher(message).replaceAll("\u2026"); // hig style - ellipsis

            menuItem.setText(indent ? "  " + message : message);

            if(menuItem.getAccelerator() != 0) // opt-in only for now; remove this conditional check to allow accelerators for arbitrary MenuItem objects
                KeyBindings.setAccelerator(menuItem, (String)menuItem.getData()); // update keybinding
        }
        else if (widget instanceof TableColumn) {
        	TableColumn tc = ((TableColumn) widget);
        	if (SWTBUG_COLUMN && tc.getAlignment() == SWT.RIGHT) {
        		// this still sucks.. it bleeds the column text into the column to the left
        		message = " " + message + "  ";
        	}
          tc.setText(message);
        } else if (widget instanceof Label)
        	// Disable Mnemonic when & is before a space.  Otherwise, it's most
        	// likely meant to be a Mnemonic
          ((Label) widget).setText(message.replaceAll("& ", "&& "));
        else if (widget instanceof CLabel)
          ((CLabel) widget).setText(message.replaceAll("& ", "&& "));
        else if (widget instanceof Group)
           ((Group) widget).setText(message);
        else if (widget instanceof Button)
           ((Button) widget).setText(message);
        else if (widget instanceof CTabItem)
           ((CTabItem) widget).setText(message);
        else if (widget instanceof TabItem)
           ((TabItem) widget).setText(message);
        else if (widget instanceof TreeItem)
          ((TreeItem) widget).setText(message);
        else if(widget instanceof Shell) 
          ((Shell) widget).setText(message);
        else if(widget instanceof ToolItem) 
            ((ToolItem) widget).setText(message);
        else{
          Debug.out( "No cast for " + widget.getClass().getName());
        }
      } 
  
private static voidupdateToolTipFromData(Widget widget)

    if(widget instanceof Control) {
      String key = (String) widget.getData();
      if(key != null) {
        if(!key.endsWith(".tooltip"))
          key += ".tooltip";
        String toolTip = MessageText.getString(key);
        if(!toolTip.equals('!" + key + '!")) {
          ((Control)widget).setToolTipText(toolTip);
        }
      }
    } else if(widget instanceof ToolItem) {
      String key = (String) widget.getData();
      if(key != null) {
        if(!key.endsWith(".tooltip"))
          key += ".tooltip";
        String toolTip = MessageText.getString(key);
        if(!toolTip.equals('!" + key + '!")) {
          ((ToolItem) widget).setToolTipText(toolTip.replaceAll("Meta\\+",
							Constants.isOSX ? "Cmd+" : "Ctrl+"));
        }
      }
    } else if (widget instanceof TableColumn) {
      String key = (String) widget.getData();
			if (key != null) {
				if (!key.endsWith(".info"))
					key += ".info";
				String toolTip = MessageText.getString(key, (String) null);
				if (toolTip == null)
					toolTip = MessageText.getString(key.substring(0, key.length() - 5),
							(String) null);
				if (toolTip != null) {
					try {
						((TableColumn) widget).setToolTipText(toolTip);
					} catch (NoSuchMethodError e) {
						// Pre SWT 3.2
					}
				}
			}
    }
  
public static voidupdateTooltipLanguageFromData(Widget widget)

  	if (widget == null || widget.isDisposed()) {
  		return;
  	}
		if (widget.getData() != null) {
			String sToolTip = MessageText.getString((String) widget.getData());
			if (widget instanceof CLabel)
				((CLabel) widget).setToolTipText(sToolTip);
			else if (widget instanceof Label)
				((Label) widget).setToolTipText(sToolTip);
			else if (widget instanceof Text)
				((Text) widget).setToolTipText(sToolTip);
			else
				System.out.println("No cast for " + widget.getClass().getName());
		}