From ce541e4ec7e6f100cc544af5844ac0be4e6b7825 Mon Sep 17 00:00:00 2001 From: hansonr Date: Mon, 4 Feb 2019 08:49:12 -0600 Subject: [PATCH] adds protype size to JTextArea hack for nonexistent SwingJS editable combo box --- src/jalview/io/cache/JvCacheableInputBox.java | 52 ++++++++++++++++--------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/src/jalview/io/cache/JvCacheableInputBox.java b/src/jalview/io/cache/JvCacheableInputBox.java index cf21c62..934ba9e 100644 --- a/src/jalview/io/cache/JvCacheableInputBox.java +++ b/src/jalview/io/cache/JvCacheableInputBox.java @@ -24,6 +24,7 @@ import jalview.bin.Cache; import jalview.util.MessageManager; import jalview.util.Platform; +import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusListener; @@ -76,6 +77,10 @@ public class JvCacheableInputBox volatile boolean enterWasPressed = false; +private String prototypeDisplayValue; + +private boolean isJS; + /** * @return flag indicating if the most recent keypress was enter */ @@ -92,9 +97,18 @@ public class JvCacheableInputBox public JvCacheableInputBox(String newCacheKey) { super(); - if (Platform.isJS()) + isJS = true;//Platform.isJS(); + this.prototypeDisplayValue = + "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + if (isJS) { - textField = new JTextField(); + textField = new JTextField() { + public Dimension getPreferredSize() { + return super.getPreferredSize(); +// FontMetrics fm = getFontMetrics(getFont()); +// return new Dimension(fm.stringWidth(prototypeDisplayValue), fm.getHeight()); + } + }; return; } @@ -114,8 +128,7 @@ public class JvCacheableInputBox // let event bubble up } }); - comboBox.setPrototypeDisplayValue( - "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); + comboBox.setPrototypeDisplayValue(prototypeDisplayValue); appCache = AppCache.getInstance(); initCachePopupMenu(); initCache(newCacheKey); @@ -202,7 +215,7 @@ public class JvCacheableInputBox */ public void updateCache() { - if (Platform.isJS()) + if (isJS) { return; } @@ -278,7 +291,7 @@ public class JvCacheableInputBox */ public void persistCache() { - if (!Platform.isJS()) + if (!isJS) { appCache.persistCache(cacheKey); } @@ -291,7 +304,7 @@ public class JvCacheableInputBox */ public String getUserInput() { - if (Platform.isJS()) + if (isJS) { return textField.getText().trim(); } @@ -301,12 +314,12 @@ public class JvCacheableInputBox public JComponent getComponent() { - return Platform.isJS() ? textField : comboBox; + return isJS ? textField : comboBox; } public void addActionListener(ActionListener actionListener) { - if (Platform.isJS()) + if (isJS) { textField.addActionListener(actionListener); } @@ -318,7 +331,7 @@ public class JvCacheableInputBox public void addDocumentListener(DocumentListener listener) { - if (!Platform.isJS()) + if (!isJS) { ((JTextComponent) comboBox.getEditor().getEditorComponent()) .getDocument().addDocumentListener(listener); @@ -327,7 +340,7 @@ public class JvCacheableInputBox public void addFocusListener(FocusListener focusListener) { - if (Platform.isJS()) + if (isJS) { textField.addFocusListener(focusListener); } @@ -339,7 +352,7 @@ public class JvCacheableInputBox public void addKeyListener(KeyListener kl) { - if (!Platform.isJS()) + if (!isJS) { comboBox.getEditor().getEditorComponent().addKeyListener(kl); } @@ -347,7 +360,7 @@ public class JvCacheableInputBox public void setEditable(boolean b) { - if (!Platform.isJS()) + if (!isJS) { comboBox.setEditable(b); } @@ -355,15 +368,16 @@ public class JvCacheableInputBox public void setPrototypeDisplayValue(String string) { - if (!Platform.isJS()) + this.prototypeDisplayValue = string; + if (!isJS) { comboBox.setPrototypeDisplayValue(string); - } + } } public void setSelectedItem(String userInput) { - if (!Platform.isJS()) + if (!isJS) { comboBox.setSelectedItem(userInput); } @@ -371,7 +385,7 @@ public class JvCacheableInputBox public boolean isPopupVisible() { - if (!Platform.isJS()) + if (!isJS) { return comboBox.isPopupVisible(); } @@ -380,7 +394,7 @@ public class JvCacheableInputBox public void addCaretListener(CaretListener caretListener) { - if (!Platform.isJS()) + if (!isJS) { ((JTextComponent) comboBox.getEditor().getEditorComponent()) .addCaretListener(caretListener); @@ -389,7 +403,7 @@ public class JvCacheableInputBox public void addItem(String item) { - if (!Platform.isJS()) + if (!isJS) { comboBox.addItem(item); } -- 1.7.10.2