org.eclipse.jst.jsf.common.ui_1.2.100.v201104061711

 {
        int index = restString.indexOf(",");
        String tmpString;
        if (index > 0)
        {
          String tmpString = restString.substring(0, index);
          restString = restString.substring(index + 1);
        }
        else
        {
          tmpString = restString;
          
          restString = null;
        }
        theValue[ii] = Integer.valueOf(tmpString).intValue();
      }
    }
    catch (Exception localException) {}
    return new Rectangle(theValue[0], theValue[1], theValue[2], theValue[3]);
  }
  
  public static String encodeBounds(Rectangle rBounds)
  {
    return 
      x + "," + y + "," + width + "," + height;
  }
  
  public static Properties getPropertiesFromString(String thePropertyString)
    throws IOException
  {
    if (thePropertyString == null) {
      return null;
    }
    ByteArrayInputStream in = new ByteArrayInputStream(thePropertyString
      .getBytes());
    
    Properties props = new Properties();
    props.load(in);
    in = null;
    return props;
  }
  
  public static Properties getPropertiesFromEncodedString(String theEncodedPropertyString)
    throws IOException
  {
    if (theEncodedPropertyString == null) {
      return null;
    }
    return getPropertiesFromString(decodeName(theEncodedPropertyString));
  }
  
  public static Properties encodedStringToProperties(String theEncodedPropertyString)
  {
    try
    {
      return getPropertiesFromEncodedString(theEncodedPropertyString);
    }
    catch (IOException localIOException) {}
    return null;
  }
  
  public static String savePropertiesToString(Properties props, String comment)
    throws IOException
  {
    if (props == null) {
      return null;
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    props.store(out, comment);
    String tmpString = out.toString();
    out = null;
    return tmpString;
  }
  
  public static String savePropertiesToEncodedString(Properties props, String comment)
    throws IOException
  {
    if (props == null) {
      return null;
    }
    return encodeName(savePropertiesToString(props, comment));
  }
  
  public static String propertiesToEncodedString(Properties props)
  {
    try
    {
      return savePropertiesToEncodedString(props, "");
    }
    catch (IOException ee)
    {
      JSFUICommonPlugin.getLogger(PropertyUtils.class).error("saving properties", ee);
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.jsf.common.ui.internal.utils.PropertyUtils
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.jsf.common.ui.internal.utils;

import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.jst.jsf.common.ui.JSFUICommonPlugin;
import org.eclipse.jst.jsf.common.ui.internal.guiutils.Alerts;
import org.eclipse.jst.jsf.common.ui.internal.logging.Logger;

public abstract class ResourceUtils
{
  private static final String LOG_RESOURCE_UTILS_MSG_KEY = "log.ResourceUtils";
  private static Logger _log = JSFUICommonPlugin.getLogger(ResourceUtils.class);
  protected ResourceBundle _resources;
  
  protected void setBundle(ResourceBundle resource, String bundleLocation)
  {
    _resources = resource;
    if (_resources == null)
    {
      _log.error("log.ResourceUtils", bundleLocation);
      
      JSFUICommonPlugin.getAlerts().error("pluginName", "log.ResourceUtils", 
        bundleLocation);
    }
  }
  
  public int getValue(String key, int defaultValue)
  {
    String stringValue = getString(key);
    if (stringValue != null) {
      try
      {
        return Integer.parseInt(stringValue);
      }
      catch (NumberFormatException localNumberFormatException) {}
    }
    return defaultValue;
  }
  
  public long getValue(String key, long defaultValue)
  {
    String stringValue = getString(key);
    if (stringValue != null) {
      try
      {
        return Long.parseLong(stringValue);
      }
      catch (NumberFormatException localNumberFormatException) {}
    }
    return defaultValue;
  }
  
  public boolean isResource(String key)
  {
    return getString(key).equals("true");
  }
  
  public String getString(String key)
  {
    try
    {
      return _resources.getString(key);
    }
    catch (MissingResourceException localMissingResourceException) {}
    return key;
  }
  
  public String getString(String key, Object arg0)
  {
    Object[] args = new Object[1];
    args[0] = arg0;
    
    MessageFormat formatter = new MessageFormat(getString(key));
    return formatter.format(args);
  }
  
  public String getString(String key, Object arg0, Object arg1)
  {
    Object[] args = new Object[2];
    args[0] = arg0;
    args[1] = arg1;
    
    MessageFormat formatter = new MessageFormat(getString(key));
    return formatter.format(args);
  }
  
  public String getString(String key, Object arg0, Object arg1, Object arg2)
  {
    Object[] args = new Object[3];
    args[0] = arg0;
    args[1] = arg1;
    args[2] = arg2;
    
    MessageFormat formatter = new MessageFormat(getString(key));
    return formatter.format(args);
  }
  
  public String getString(String key, Object arg0, Object arg1, Object arg2, Object arg3)
  {
    Object[] args = new Object[4];
    args[0] = arg0;
    args[1] = arg1;
    args[2] = arg2;
    args[3] = arg3;
    
    MessageFormat formatter = new MessageFormat(getString(key));
    return formatter.format(args);
  }
  
  public String getString(String key, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4)
  {
    Object[] args = new Object[5];
    args[0] = arg0;
    args[1] = arg1;
    args[2] = arg2;
    args[3] = arg3;
    args[4] = arg4;
    
    MessageFormat formatter = new MessageFormat(getString(key));
    return formatter.format(args);
  }
  
  public String getString(String key, Object[] args)
  {
    MessageFormat formatter = new MessageFormat(getString(key));
    return formatter.format(args);
  }
  
  public static void ensureClosed(InputStream inputStream)
  {
    if (inputStream != null) {
      try
      {
        inputStream.close();
      }
      catch (IOException localIOException) {}
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.jsf.common.ui.internal.utils.ResourceUtils
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.jsf.common.ui.internal.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil
{
  private static final Pattern htmlToNewline = Pattern.compile("</p>|<br>");
  private static final Pattern removeHTMLTags = Pattern.compile("<[/?\\w\\s=\"\\.\\#]+>");
  private static final Pattern trimInteriorWhitespace = Pattern.compile("[ ]+");
  
  public static String splitVariable(String variable)
  {
    StringBuffer output = new StringBuffer("");
    boolean isCapitalLeading = false;
    boolean isLastSpace = false;
    
    int i = 0;
    for (int n = variable.length(); i < n; i++)
    {
      char letter = variable.charAt(i);
      if ((letter == '_') || (letter == '$'))
      {
        output.append(" ");
        isCapitalLeading = false;
        isLastSpace = true;
      }
      else
      {
        if (Character.isLowerCase(letter))
        {
          int nextIndex = i + 1;
          if (nextIndex < n)
          {
            char nextLetter = variable.charAt(nextIndex);
            if (Character.isUpperCase(nextLetter))
            {
              if (isCapitalLeading)
              {
                output.append(letter);
                isLastSpace = false;
              }
              else
              {
                output.append(Character.toUpperCase(letter));
                isLastSpace = false;
              }
              if (!isLastSpace)
              {
                output.append(' ');
                isLastSpace = true;
              }
              isCapitalLeading = false;
              continue;
            }
          }
        }
        if (Character.isUpperCase(letter))
        {
          int nextIndex = i + 1;
          if (nextIndex < n)
          {
            char nextLetter = variable.charAt(nextIndex);
            if (Character.isLowerCase(nextLetter))
            {
              if (!isLastSpace)
              {
                output.append(' ');
                isLastSpace = true;
              }
              output.append(letter);
              isCapitalLeading = true;
              isLastSpace = false;
              continue;
            }
          }
        }
        if (isCapitalLeading)
        {
          output.append(letter);
          isLastSpace = false;
        }
        else
        {
          output.append(Character.toUpperCase(letter));
          isCapitalLeading = true;
          isLastSpace = false;
        }
      }
    }
    return output.toString().trim();
  }
  
  public static boolean isSameString(String str1, String str2)
  {
    if (str1 == null) {
      return str2 == null;
    }
    return str1.equals(str2);
  }
  
  public static String filterConvertString(String text)
  {
    if (text == null) {
      return "";
    }
    String result = htmlToNewline.matcher(text).replaceAll("\n");
    result = removeHTMLTags.matcher(result).replaceAll("");
    result = trimInteriorWhitespace.matcher(result).replaceAll(" ");
    
    return result;
  }
  
  public static boolean isEmptyString(String str)
  {
    if ((str == null) || (str.length() == 0)) {
      return true;
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.jsf.common.ui.internal.utils.StringUtil
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.jsf.common.ui.internal.utils;

import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

class StyleCombo$1
  implements Listener
{
  StyleCombo$1(StyleCombo paramStyleCombo) {}
  
  public void handleEvent(Event event)
  {
    if (this$0.popup == widget)
    {
      this$0.popupEvent(event);
      return;
    }
    if (this$0.text == widget)
    {
      this$0.textEvent(event);
      return;
    }
    if (this$0.table == widget)
    {
      this$0.tableEvent(event);
      return;
    }
    if (this$0.arrow == widget)
    {
      this$0.arrowEvent(event);
      return;
    }
    if (this$0 == widget)
    {
      this$0.comboEvent(event);
      return;
    }
    if (this$0.getShell() == widget) {
      this$0.handleFocus(16);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.jsf.common.ui.internal.utils.StyleCombo.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.jsf.common.ui.internal.utils;

import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

class StyleCombo$2
  implements Listener
{
  StyleCombo$2(StyleCombo paramStyleCombo) {}
  
  public void handleEvent(Event event)
  {
    Shell shell = ((Control)widget).getShell();
    if (shell == this$0.getShell()) {
      this$0.handleFocus(16);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.jsf.common.ui.internal.utils.StyleCombo.2
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.jsf.common.ui.internal.utils;

import org.eclipse.swt.accessibility.AccessibleAdapter;
import org.eclipse.swt.accessibility.AccessibleEvent;
import org.eclipse.swt.widgets.Label;

class StyleCombo$3
  extends AccessibleAdapter
{
  StyleCombo$3(StyleCombo paramStyleCombo) {}
  
  public void getName(AccessibleEvent e)
  {
    String name = null;
    Label label = this$0.getAssociatedLabel();
    if (label != null) {
      name = this$0.stripMnemonic(label.getText());
    }
    result = name;
  }
  
  public void getKeyboardShortcut(AccessibleEvent e)
  {
    String shortcut = null;
    Label label = this$0.getAssociatedLabel();
    if (label != null)
    {
      String text1 = label.getText();
      if (text1 != null)
      {
        char mnemonic = this$0.getMnemonic(text1);
        if (mnemonic != 0) {
          shortcut = "Alt+" + mnemonic;
        }
      }
    }
    result = shortcut;
  }
  
  public void getHelp(AccessibleEvent e)
  {
    result = this$0.getToolTipText();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.jsf.common.ui.internal.utils.StyleCombo.3
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.jsf.common.ui.internal.utils;

import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.AccessibleAdapter;
import org.eclipse.swt.accessibility.AccessibleEvent;

class StyleCombo$4
  extends AccessibleAdapter
{
  StyleCombo$4(StyleCombo paramStyleCombo) {}
  
  public void getName(AccessibleEvent e)
  {
    result = (this$0.isDropped() ? SWT.getMessage("SWT_Close") : SWT.getMessage("SWT_Open"));
  }
  
  public void getKeyboardShortcut(AccessibleEvent e)
  {
    result = "Alt+Down Arrow";
  }
  
  public void getHelp(AccessibleEvent e)
  {
    result = this$0.getToolTipText();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.jsf.common.ui.internal.utils.StyleCombo.4
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.jsf.common.ui.internal.utils;

import org.eclipse.swt.accessibility.AccessibleTextAdapter;
import org.eclipse.swt.accessibility.AccessibleTextEvent;
import org.eclipse.swt.widgets.Text;

class StyleCombo$5
  extends AccessibleTextAdapter
{
  StyleCombo$5(StyleCombo paramStyleCombo) {}
  
  public void getCaretOffset(AccessibleTextEvent e)
  {
    offset = this$0.text.getCaretPosition();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.jsf.common.ui.internal.utils.StyleCombo.5
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.jsf.common.ui.internal.utils;

import org.eclipse.swt.accessibility.AccessibleControlAdapter;
import org.eclipse.swt.accessibility.AccessibleControlEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;

class StyleCombo$6
  extends AccessibleControlAdapter
{
  StyleCombo$6(StyleCombo paramStyleCombo) {}
  
  public void getChildAtPoint(AccessibleControlEvent e)
  {
    Point testPoint = this$0.toControl(x, y);
    if (this$0.getBounds().contains(testPoint)) {
      childID = -1;
    }
  }
  
  public void getLocation(AccessibleControlEvent e)
  {
    Rectangle location = this$0.getBounds();
    Point pt = this$0.toDisplay(x, y);
    x = x;
    y = y;
    width = width;
    height = height;
  }
  
  public void getChildCount(AccessibleControlEvent e)
  {
    detail = 0;
  }
  
  public void getRole(AccessibleControlEvent e)
  {
    detail = 46;
  }
  
  public void getState(AccessibleControlEvent e)
  {
    detail = 0;
  }
  
  public void getValue(AccessibleControlEvent e)
  {
    result = this$0.getText();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.jsf.common.ui.internal.utils.StyleCombo.6
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.jsf.common.ui.internal.utils;

import org.eclipse.swt.accessibility.AccessibleControlAdapter;
import org.eclipse.swt.accessibility.AccessibleControlEvent;
import org.eclipse.swt.widgets.Text;

class StyleCombo$7
  extends AccessibleControlAdapter
{
  StyleCombo$7(StyleCombo paramStyleCombo) {}
  
  public void getRole(AccessibleControlEvent e)
  {
    detail = (this$0.text.getEditable() ? 42 : 
      41);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.jsf.common.ui.internal.utils.StyleCombo.7
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.jsf.common.ui.internal.utils;

import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.AccessibleControlAdapter;
import org.eclipse.swt.accessibility.AccessibleControlEvent;

class StyleCombo$8
  extends AccessibleControlAdapter
{
  StyleCombo$8(StyleCombo paramStyleCombo) {}
  
  public void getDefaultAction(AccessibleControlEvent e)
  {
    result = (this$0.isDropped() ? SWT.getMessage("SWT_Close") : SWT.getMessage("SWT_Open"));
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.jsf.common.ui.internal.utils.StyleCombo.8
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.jsf.common.ui.internal.utils;

import java.util.Arrays;
import java.util.List;
import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.Accessible;
import org.eclipse.swt.accessibility.AccessibleAdapter;
import org.eclipse.swt.accessibility.AccessibleControlAdapter;
import org.eclipse.swt.accessibility.AccessibleControlEvent;
import org.eclipse.swt.accessibility.AccessibleEvent;
import org.eclipse.swt.accessibility.AccessibleTextAdapter;
import org.eclipse.swt.accessibility.AccessibleTextEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.TypedListener;

public final class StyleCombo
  extends Composite
{
  Text text;
  Table table;
  int visibleItemCount = 4;
  Shell popup;
  Button arrow;
  boolean hasFocus;
  Listener listener;
  Listener filter;
  Color foreground;
  Color background;
  Font font;
  String defaultValue;
  
  public StyleCombo(Composite parent, int style)
  {
    super(parent, style = checkStyle(style));
    
    listener = new Listener()
    {
      public void handleEvent(Event event)
      {
        if (popup == widget)
        {
          popupEvent(event);
          return;
        }
        if (text == widget)
        {
          textEvent(event);
          return;
        }
        if (table == widget)
        {
          tableEvent(event);
          return;
        }
        if (arrow == widget)
        {
          arrowEvent(event);
          return;
        }
        if (StyleCombo.this == widget)
        {
          comboEvent(event);
          return;
        }
        if (getShell() == widget) {
          handleFocus(16);
        }
      }
    };
    filter = new Listener()
    {
      public void handleEvent(Event event)
      {
        Shell shell = ((Control)widget).getShell();
        if (shell == getShell()) {
          handleFocus(16);
        }
      }
    };
    int[] comboEvents = { 12, 10, 11 };
    for (int i = 0; i < comboEvents.length; i++) {
      addListener(comboEvents[i], listener);
    }
    createText(style);
    createArrow(style);
    
    createPopup(null, -1);
    initAccessible();
  }
  
  private void createArrow(int style)
  {
    int arrowStyle = 1028;
    if ((style & 0x800000) != 0) {
      arrowStyle |= 0x800000;
    }
    arrow = new Button(this, arrowStyle);
    int[] arrowEvents = { 13, 15 };
    for (int i = 0; i < arrowEvents.length; i++) {
      arrow.addListener(arrowEvents[i], listener);
    }
  }
  
  private void createText(int style)
  {
    int textStyle = 4;
    if ((style & 0x8) != 0) {
      textStyle |= 0x8;
    }
    if ((style & 0x800000) != 0) {
      textStyle |= 0x800000;
    }
    text = new Text(this, textStyle);
    int[] textEvents = { 1, 2, 24, 3, 
      4, 31, 15 };
    for (int i = 0; i < textEvents.length; i++) {
      text.addListener(textEvents[i], listener);
    }
  }
  
  static int checkStyle(int style)
  {
    int mask = 109053960;
    
    return style & mask;
  }
  
  public void add(String string)
  {
    checkWidget();
    if (string == null) {
      SWT.error(4);
    }
    TableItem item = new TableItem(table, 0);
    item.setText(0, string);
  }
  
  public void add(String string, int index)
  {
    checkWidget();
    if (string == null) {
      SWT.error(4);
    }
    TableItem item = new TableItem(table, 0, index);
    item.setText(0, string);
  }
  
  public void addModifyListener(ModifyListener listener1)
  {
    checkWidget();
    if (listener1 == null) {
      SWT.error(4);
    }
    TypedListener typedListener = new TypedListener(listener1);
    addListener(24, typedListener);
  }
  
  public void addSelectionListener(SelectionListener listener1)
  {
    checkWidget();
    if (listener1 == null) {
      SWT.error(4);
    }
    TypedListener typedListener = new TypedListener(listener1);
    addListener(13, typedListener);
    addListener(14, typedListener);
  }
  
  void arrowEvent(Event event)
  {
    switch (type)
    {
    case 15: 
      handleFocus(15);
      break;
    case 13: 
      dropDown(!isDropped());
    }
  }
  
  public void clearSelection()
  {
    checkWidget();
    text.clearSelection();
    table.deselectAll();
  }
  
  void comboEvent(Event event)
  {
    switch (type)
    {
    case 12: 
      if ((popup != null) && (!popup.isDisposed()))
      {
        table.removeListener(12, listener);
        popup.dispose();
      }
      Shell shell = getShell();
      shell.removeListener(27, listener);
      Display display = getDisplay();
      display.removeFilter(15, filter);
      popup = null;
      text = null;
      table = null;
      arrow = null;
      break;
    case 10: 
      dropDown(false);
      break;
    case 11: 
      internalLayout(false);
    }
  }
  
  private String[] getTableItems()
  {
    TableItem[] items = table.getItems();
    String[] values = new String[items.length];
    for (int i = 0; i < items.length; i++) {
      values[i] = items[i].getText(0);
    }
    return values;
  }
  
  public Point computeSize(int wHint, int hHint, boolean changed)
  {
    checkWidget();
    int width = 0;int height = 0;
    String[] items = getTableItems();
    int textWidth = 0;
    GC gc = new GC(text);
    int spacer = stringExtent" "x;
    for (int i = 0; i < items.length; i++) {
      textWidth = Math.max(stringExtentx, textWidth);
    }
    gc.dispose();
    Point textSize = text.computeSize(-1, -1, changed);
    Point arrowSize = arrow.computeSize(-1, -1, changed);
    Point listSize = table.computeSize(wHint, -1, changed);
    int borderWidth = getBorderWidth();
    
    height = Math.max(hHint, Math.max(y, y) + 2 * 
      borderWidth);
    width = Math.max(wHint, Math.max(textWidth + 2 * spacer + x + 
      2 * borderWidth, x));
    return new Point(width, height);
  }
  
  void createPopup(String[] items, int selectionIndex)
  {
    popup = new Shell(getShell(), 16392);
    table = new Table(popup, 66052);
    new TableColumn(table, 16384);
    if (font != null) {
      table.setFont(font);
    }
    if (foreground != null) {
      table.setForeground(foreground);
    }
    if (background != null) {
      table.setBackground(background);
    }
    int[] popupEvents = { 21, 9, 27 };
    for (int i = 0; i < popupEvents.length; i++) {
      popup.addListener(popupEvents[i], listener);
    }
    int[] listEvents = { 4, 13, 31, 
      1, 2, 15, 16, 12 };
    for (int i = 0; i < listEvents.length; i++) {
      table.addListener(listEvents[i], listener);
    }
    if (items != null) {
      setItems(items);
    }
    if (selectionIndex != -1) {
      select(selectionIndex);
    }
  }
  
  public void deselect(int index)
  {
    checkWidget();
    table.deselect(index);
  }
  
  public void deselectAll()
  {
    checkWidget();
    table.deselectAll();
  }
  
  void dropDown(boolean drop)
  {
    if (drop == isDropped()) {
      return;
    }
    if (!drop)
    {
      popup.setVisible(false);
      table.getColumns()[0].setWidth(0);
      if ((!isDisposed()) && (arrow.isFocusControl())) {
        text.setFocus();
      }
      return;
    }
    if (getShell() != popup.getParent())
    {
      String[] items = getTableItems();
      int selectionIndex = table.getSelectionIndex();
      table.removeListener(12, listener);
      popup.dispose();
      popup = null;
      table = null;
      createPopup(items, selectionIndex);
    }
    Point size = getSize();
    int itemCount = table.getItemCount();
    itemCount = itemCount == 0 ? visibleItemCount : Math.min(
      visibleItemCount, itemCount);
    int itemHeight = table.getItemHeight() * itemCount;
    Point tableSize = table.computeSize(-1, itemHeight, false);
    
    table.setBounds(1, 1, Math.max(x - 2, x), y - 
      table.getHorizontalBar().getSize().y + 2);
    
    int index = table.getSelectionIndex();
    if (index != -1) {
      table.setTopIndex(index);
    }
    Display display = getDisplay();
    Rectangle tableRect = table.getBounds();
    Rectangle parentRect = display.map(getParent(), null, getBounds());
    Point comboSize = getSize();
    Rectangle displayRect = getMonitor().getClientArea();
    int width = Math.max(x, width + 2);
    int height = height + 2;
    int x = x;
    int y = y + y;
    if (y + height > y + height) {
      y = y - height;
    }
    popup.setBounds(x, y, width, height);
    popup.setVisible(true);
    if (table.getItemCount() > visibleItemCount) {
      table.getColumns()[0].setWidth(text.getSize().x - 2);
    } else {
      table.getColumns()[0].setWidth(table.getClientArea().width);
    }
    table.setFocus();
  }
  
  Label getAssociatedLabel()
  {
    Control[] siblings = getParent().getChildren();
    for (int i = 0; i < siblings.length; i++) {
      if ((siblings[i] == this) && 
        (i > 0) && ((siblings[(i - 1)] instanceof Label))) {
        return (Label)siblings[(i - 1)];
      }
    }
    return null;
  }
  
  public Control[] getChildren()
  {
    checkWidget();
    return new Control[0];
  }
  
  public boolean getEditable()
  {
    checkWidget();
    return text.getEditable();
  }
  
  public String getItem(int index)
  {
    checkWidget();
    return table.getItem(index).getText(0);
  }
  
  public int getItemCount()
  {
    checkWidget();
    return table.getItemCount();
  }
  
  public int getItemHeight()
  {
    checkWidget();
    return table.getItemHeight();
  }
  
  public String[] getItems()
  {
    checkWidget();
    return getTableItems();
  }
  
  char getMnemonic(String string)
  {
    int index = 0;
    int length = string.length();
    do
    {
      while ((index < length) && (string.charAt(index) != '&')) {
        index++;
      }
      index++;
      if (index >= length) {
        return '\000';
      }
      if (string.charAt(index) != '&') {
        return string.charAt(index);
      }
      index++;
    } while (index < length);
    return '\000';
  }
  
  public Point getSelection()
  {
    checkWidget();
    return text.getSelection();
  }
  
  public int getSelectionIndex()
  {
    checkWidget();
    return table.getSelectionIndex();
  }
  
  public int getStyle()
  {
    int style = super.getStyle();
    style &= 0xFFFFFFF7;
    if (!text.getEditable()) {
      style |= 0x8;
    }
    return style;
  }
  
  public String getText()
  {
    checkWidget();
    return text.getText();
  }
  
  public int getTextHeight()
  {
    checkWidget();
    return text.getLineHeight();
  }
  
  public int getTextLimit()
  {
    checkWidget();
    return text.getTextLimit();
  }
  
  public int getVisibleItemCount()
  {
    checkWidget();
    return visibleItemCount;
  }
  
  void handleFocus(int type)
  {
    if (isDisposed()) {
      return;
    }
    switch (type)
    {
    case 15: 
      if (hasFocus) {
        return;
      }
      if (getEditable()) {
        text.selectAll();
      }
      hasFocus = true;
      Shell shell = getShell();
      shell.removeListener(27, listener);
      shell.addListener(27, listener);
      Display display = getDisplay();
      display.removeFilter(15, filter);
      display.addFilter(15, filter);
      Event e = new Event();
      notifyListeners(15, e);
      break;
    case 16: 
      if (!hasFocus) {
        return;
      }
      Control focusControl = getDisplay().getFocusControl();
      if ((focusControl == arrow) || (focusControl == table) || 
        (focusControl == text)) {
        return;
      }
      hasFocus = false;
      Shell shell = getShell();
      shell.removeListener(27, listener);
      Display display = getDisplay();
      display.removeFilter(15, filter);
      Event e = new Event();
      notifyListeners(16, e);
    }
  }
  
  public int indexOf(String string)
  {
    checkWidget();
    if (string == null) {
      SWT.error(4);
    }
    return Arrays.asList(getTableItems()).indexOf(string);
  }
  
  public int indexOf(String string, int start)
  {
    checkWidget();
    if (string == null) {
      SWT.error(4);
    }
    String[] items = getTableItems();
    for (int i = start; i < items.length; i++) {
      if (items[i].equals(string)) {
        return i;
      }
    }
    return -1;
  }
  
  void initAccessible()
  {
    AccessibleAdapter accessibleAdapter = new AccessibleAdapter()
    {
      public void getName(AccessibleEvent e)
      {
        String name = null;
        Label label = getAssociatedLabel();
        if (label != null) {
          name = stripMnemonic(label.getText());
        }
        result = name;
      }
      
      public void getKeyboardShortcut(AccessibleEvent e)
      {
        String shortcut = null;
        Label label = getAssociatedLabel();
        if (label != null)
        {
          String text1 = label.getText();
          if (text1 != null)
          {
            char mnemonic = getMnemonic(text1);
            if (mnemonic != 0) {
              shortcut = "Alt+" + mnemonic;
            }
          }
        }
        result = shortcut;
      }
      
      public void getHelp(AccessibleEvent e)
      {
        result = getToolTipText();
      }
    };
    getAccessible().addAccessibleListener(accessibleAdapter);
    text.getAccessible().addAccessibleListener(accessibleAdapter);
    table.getAccessible().addAccessibleListener(accessibleAdapter);
    
    arrow.getAccessible().addAccessibleListener(new AccessibleAdapter()
    {
      public void getName(AccessibleEvent e)
      {
        result = (isDropped() ? SWT.getMessage("SWT_Close") : SWT.getMessage("SWT_Open"));
      }
      
      public void getKeyboardShortcut(AccessibleEvent e)
      {
        result = "Alt+Down Arrow";
      }
      
      public void getHelp(AccessibleEvent e)
      {
        result = getToolTipText();
      }
    });
    getAccessible().addAccessibleTextListener(new AccessibleTextAdapter()
    {
      public void getCaretOffset(AccessibleTextEvent e)
      {
        offset = text.getCaretPosition();
      }
    });
    getAccessible().addAccessibleControlListener(
      new AccessibleControlAdapter()
      {
        public void getChildAtPoint(AccessibleControlEvent e)
        {
          Point testPoint = toControl(x, y);
          if (getBounds().contains(testPoint)) {
            childID = -1;
          }
        }
        
        public void getLocation(AccessibleControlEvent e)
        {
          Rectangle location = getBounds();
          Point pt = toDisplay(x, y);
          x = x;
          y = y;
          width = width;
          height = height;
        }
        
        public void getChildCount(AccessibleControlEvent e)
        {
          detail = 0;
        }
        
        public void getRole(AccessibleControlEvent e)
        {
          detail = 46;
        }
        
        public void getState(AccessibleControlEvent e)
        {
          detail = 0;
        }
        
        public void getValue(AccessibleControlEvent e)
        {
          result = getText();
        }
      });
    text.getAccessible().addAccessibleControlListener(
      new AccessibleControlAdapter()
      {
        public void getRole(AccessibleControlEvent e)
        {
          detail = (text.getEditable() ? 42 : 
            41);
        }
      });
    arrow.getAccessible().addAccessibleControlListener(
      new AccessibleControlAdapter()
      {
        public void getDefaultAction(AccessibleControlEvent e)
        {
          result = (isDropped() ? SWT.getMessage("SWT_Close") : SWT.getMessage("SWT_Open"));
        }
      });
  }
  
  boolean isDropped()
  {
    return popup.getVisible();
  }
  
  public boolean isFocusControl()
  {
    checkWidget();
    if ((text.isFocusControl()) || (arrow.isFocusControl()) || 
      (table.isFocusControl()) || (popup.isFocusControl())) {
      return true;
    }
    return super.isFocusControl();
  }
  
  void internalLayout(boolean changed)
  {
    if (isDropped()) {
      dropDown(false);
    }
    Rectangle rect = getClientArea();
    int width = width;
    int height = height;
    Point arrowSize = arrow.computeSize(-1, height, changed);
    text.setBounds(0, 0, width - x, height);
    arrow.setBounds(width - x, 0, x, y);
  }
  
  void tableEvent(Event event)
  {
    switch (type)
    {
    case 12: 
      if (getShell() != popup.getParent())
      {
        String[] items = getTableItems();
        int selectionIndex = table.getSelectionIndex();
        popup = null;
        table = null;
        createPopup(items, selectionIndex);
      }
      break;
    case 15: 
      handleFocus(15);
      break;
    case 4: 
      if (button != 1) {
        return;
      }
      dropDown(false);
      break;
    case 13: 
      int index = table.getSelectionIndex();
      if (index == -1) {
        return;
      }
      text.setText(table.getItem(index).getText());
      text.selectAll();
      table.setSelection(index);
      Event e = new Event();
      time = time;
      stateMask = stateMask;
      doit = doit;
      notifyListeners(13, e);
      doit = doit;
      break;
    case 31: 
      switch (detail)
      {
      case 2: 
      case 4: 
      case 32: 
      case 64: 
        doit = false;
      }
      Event e = new Event();
      time = time;
      detail = detail;
      doit = doit;
      character = character;
      keyCode = keyCode;
      notifyListeners(31, e);
      doit = doit;
      detail = detail;
      break;
    case 2: 
      Event e = new Event();
      time = time;
      character = character;
      keyCode = keyCode;
      stateMask = stateMask;
      notifyListeners(2, e);
      break;
    case 1: 
      if (character == '\033') {
        dropDown(false);
      }
      if (((stateMask & 0x10000) != 0) && (
        (keyCode == 16777217) || (keyCode == 16777218))) {
        dropDown(false);
      }
      if (character == '\r')
      {
        dropDown(false);
        Event e = new Event();
        time = time;
        stateMask = stateMask;
        notifyListeners(14, e);
      }
      if (!isDisposed())
      {
        Event e = new Event();
        time = time;
        character = character;
        keyCode = keyCode;
        stateMask = stateMask;
        notifyListeners(1, e);
      }
      break;
    }
  }
  
  void popupEvent(Event event)
  {
    switch (type)
    {
    case 9: 
      Rectangle listRect = table.getBounds();
      Color black = getDisplay().getSystemColor(2);
      gc.setForeground(black);
      gc.drawRectangle(0, 0, width + 1, 
        height + 1);
      break;
    case 21: 
      doit = false;
      dropDown(false);
      break;
    case 27: 
      dropDown(false);
    }
  }
  
  public void redraw()
  {
    super.redraw();
    text.redraw();
    arrow.redraw();
    if (popup.isVisible()) {
      table.redraw();
    }
  }
  
  public void redraw(int x, int y, int width, int height, boolean all)
  {
    super.redraw(x, y, width, height, true);
  }
  
  public void remove(int index)
  {
    checkWidget();
    table.remove(index);
  }
  
  public void remove(int start, int end)
  {
    checkWidget();
    table.remove(start, end);
  }
  
  public void remove(String string)
  {
    checkWidget();
    if (string == null) {
      SWT.error(4);
    }
    int index = Arrays.asList(getTableItems()).indexOf(string);
    table.remove(index);
  }
  
  public void removeAll()
  {
    checkWidget();
    text.setText("");
    table.removeAll();
  }
  
  public void removeModifyListener(ModifyListener listener1)
  {
    checkWidget();
    if (listener1 == null) {
      SWT.error(4);
    }
    removeListener(24, listener1);
  }
  
  public void removeSelectionListener(SelectionListener listener1)
  {
    checkWidget();
    if (listener1 == null) {
      SWT.error(4);
    }
    removeListener(13, listener1);
    removeListener(14, listener1);
  }
  
  public void select(int index)
  {
    checkWidget();
    if (index == -1)
    {
      table.deselectAll();
      text.setText("");
      return;
    }
    if ((index >= 0) && (index < table.getItemCount()) && 
      (index != getSelectionIndex()))
    {
      text.setText(table.getItem(index).getText());
      text.selectAll();
      table.select(index);
      table.showSelection();
    }
  }
  
  public void setBackground(Color color)
  {
    super.setBackground(color);
    background = color;
    if (text != null) {
      text.setBackground(color);
    }
    if (table != null) {
      table.setBackground(color);
    }
    if (arrow != null) {
      arrow.setBackground(color);
    }
  }
  
  public void setEditable(boolean editable)
  {
    checkWidget();
    text.setEditable(editable);
  }
  
  public void setEnabled(boolean enabled)
  {
    super.setEnabled(enabled);
    if (popup != null) {
      popup.setVisible(false);
    }
    if (text != null) {
      text.setEnabled(enabled);
    }
    if (arrow != null) {
      arrow.setEnabled(enabled);
    }
  }
  
  public boolean setFocus()
  {
    checkWidget();
    return text.setFocus();
  }
  
  public void setFont(Font font)
  {
    super.setFont(font);
    this.font = font;
    text.setFont(font);
    table.setFont(font);
    internalLayout(true);
  }
  
  public void setForeground(Color color)
  {
    super.setForeground(color);
    foreground = color;
    if (text != null) {
      text.setForeground(color);
    }
    if (table != null) {
      table.setForeground(color);
    }
    if (arrow != null) {
      arrow.setForeground(color);
    }
  }
  
  public void setItem(int index, String string)
  {
    checkWidget();
    table.getItem(index).setText(0, string);
  }
  
  public void setItems(String[] items)
  {
    checkWidget();
    if (items == null) {
      SWT.error(4);
    }
    for (int i = 0; i < items.length; i++)
    {
      TableItem item = new TableItem(table, 0);
      if (items[i].equals(defaultValue)) {
        item.setFont(JFaceResources.getFontRegistry().getBold(
          "org.eclipse.jface.defaultfont"));
      }
      item.setText(0, items[i]);
    }
  }
  
  public void setLayout(Layout layout)
  {
    checkWidget();
  }
  
  public void setSelection(Point selection)
  {
    checkWidget();
    if (selection == null) {
      SWT.error(4);
    }
    text.setSelection(x, y);
  }
  
  public void setText(String string)
  {
    checkWidget();
    if (string == null) {
      SWT.error(4);
    }
    int index = Arrays.asList(getTableItems()).indexOf(string);
    if (index == -1)
    {
      table.deselectAll();
      text.setText(string);
      return;
    }
    text.setText(string);
    text.selectAll();
    table.setSelection(index);
    table.showSelection();
  }
  
  public void setTextLimit(int limit)
  {
    checkWidget();
    text.setTextLimit(limit);
  }
  
  public void setToolTipText(String string)
  {
    checkWidget();
    super.setToolTipText(string);
    arrow.s
1 2 3 4 5 6 7 8 9 10 11

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd