- super();
- this.cacheKey = newCacheKey;
- setEditable(true);
- setPrototypeDisplayValue(
- "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
- appCache = AppCache.getInstance();
- initCachePopupMenu();
- initCache(newCacheKey);
- updateCache();
+ // super();
+ cacheKey = newCacheKey;
+ prototypeDisplayValue = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
+ if (length > 0)
+ {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < length; i++)
+ {
+ sb.append("X");
+ }
+ setPrototypeDisplayValue(sb.toString());
+ }
+ boolean useTextField = Platform.isJS();
+ // BH 2019.03 only switch for JavaScript here
+ // SwingJS TODO implement editable combo box
+ if (useTextField)
+ {
+ appCache = null;
+ textComponent = textField = new JTextField();
+ FontMetrics fm = textField.getFontMetrics(textField.getFont());
+ textField.setPreferredSize(new Dimension(
+ fm.stringWidth(prototypeDisplayValue), fm.getHeight() + 4));
+ // {
+ // @Override
+ // public Dimension getPreferredSize() {
+ // return super.getPreferredSize();
+ //// FontMetrics fm = getFontMetrics(getFont());
+ //// return new Dimension(fm.stringWidth(prototypeDisplayValue),
+ // fm.getHeight());
+ // }
+ // };
+ }
+ else
+ {
+ appCache = AppCache.getInstance();
+ comboBox = new JComboBox<>();
+ textComponent = (JTextComponent) comboBox.getEditor()
+ .getEditorComponent();
+ comboBox.setEditable(true);
+ comboBox.addKeyListener(new KeyAdapter()
+ {
+ @Override
+ public void keyTyped(KeyEvent e)
+ {
+ enterWasPressed = false;
+ if (e.getKeyCode() == KeyEvent.VK_ENTER)
+ {
+ enterWasPressed = true;
+ }
+ // let event bubble up
+ }
+ });
+ comboBox.setPrototypeDisplayValue(prototypeDisplayValue);
+ initCachePopupMenu();
+ initCache(newCacheKey);
+ updateCache();
+ }